K = 1000000000 L = 1000000007 def pow10(m) a, b = 1, 1 m.times do a = (a * 10) % K b = (b * 10) % L end [a, b] end def num(keta) return [1, 1] unless keta.positive? a, b = pow10((keta - 1) / 2) a = (a * 9) % K b = (b * 9) % K [a, b] end m = gets.chomp head = m[0].to_i tail = m[-1].to_i if m.size == 1 p head p head exit end a, b = 0, 0 c = head > tail ? (head - 1) * (head - 1) : head * head e, f = num(m.size - 2) a = (a + c * e) % K b = (b + c * f) % K (m.size - 1).times do |i| da, db = num(i + 1) a = (a + da) % K b = (b + db) % L end p a p b