# Enter your code here. Read input from STDIN. Print output to STDOUT require 'openssl' def lazy_edv(t, a, b) bn = ((a + b) / 2).to_bn bn.mod_exp(t, (10**9 + 7)).to_i end a, b, t = gets.strip.split(' ').map(&:to_i) puts lazy_edv(t, a, b)