we wooden plank length n unit some ant walk plank ant move speed 1 unit second some ant leave rightwhen ant move different direction meet point change direction continue move Assume change direction additional timewhen ant reach end plank time t fall plank immediatelyGiven integer n integer array leave right position ant move leave right return moment ant fall plank Example 1input n 4 leave 43 right 01output 4explanation in image abovethe ant index 0 name a go rightThe ant index 1 name b go rightThe ant index 3 name C go leftThe ant index 4 name D go leftthe moment ant plank t 4 second after fall immediately plank ie We t 40000000001 ant plankexample 2input n 7 leave right 01234567output 7explanation all ant go right ant index 0 need 7 second fallexample 3input n 7 leave 01234567 right output 7explanation all ant going leave ant index 7 need 7 second fall Constraints1 n 1040 leftlength n 10 lefti n0 rightlength n 10 righti n1 leftlength rightlength n 1all value leave right unique value appear array