main=interact$unlines.f.lines f s=s++[foldl1(#)s] (x:y:z)#(s:t:u)|t>y=a:y:x:b|1>0=x:y:a:b where a:b=z#u x#_=x