there robot factory Xaxis you give integer array robot roboti position ith robot you give 2D integer array factory factoryj positionj limitj indicate positionj position jth factory jth factory repair limitj robotsThe position robot unique the position factory unique Note robot position factory initiallyall robot initially break move direction the direction negative positive direction Xaxis when robot reach factory reach limit factory repair robot stop movingat moment set initial direction move robot your target minimize total distance travel robotsreturn minimum total distance travel robot the test case generate robot repairedNote thatall robot speedif robot direction collideif robot opposite direction meet point collide they cross otherif robot pass factory reach limit crosse existIf robot move position x position y distance move y x Example 1input robot 046 factory 2262output 4explanation as show figure the robot position 0 move positive direction it repair factory the second robot position 4 move negative direction it repair factory the robot position 6 repair second factory it need moveThe limit factory 2 fix 2 robotsthe limit second factory 2 fix 1 robotthe total distance 2 0 2 4 6 6 4 it show achieve well total distance 4example 2input robot 11 factory 2121output 2explanation as show figure the robot position 1 move positive direction it repair second factory the second robot position 1 move negative direction it repair factoryThe limit factory 1 fix 1 robotthe limit second factory 1 fix 1 robotthe total distance 2 1 2 1 2 it show achieve well total distance 2 constraints1 robotlength factorylength 100factoryjlength 2109 roboti positionj 1090 limitj robotlengththe input generate possible repair robot