gets as=gets.split(" ").map{|e| e.to_i} m=10**9+7 while as.size>1 do bs=[] as.each_cons(2){|a,b| bs<<(a+b)%m } as=bs.dup end puts as[0]