def solve(n,S): res=0 i=3 while i