System.in.eachLine{println~((l=(a=it.split()*.toLong()).size)..l*l).sum{[(a*2)[it%l..