public class Main{ public static void main(String[] args){ java.util.Scanner sc = new java.util.Scanner(System.in); long a = Long.parseLong(sc.next()); long b = Long.parseLong(sc.next()); long n = Long.parseLong(sc.next()); if(n == 0){ System.out.println(2); return; } Matrix x = new Matrix(1, 0, 0, 1); long tmp = (b - a * a % 1000000007) % 1000000007; if(tmp < 0) tmp += 1000000007; Matrix y = new Matrix(a * 2 % 1000000007, tmp, 1, 0); --n; while(n != 0){ if((n & 1) == 1){ x.mul(y); } y.mul(y); n >>= 1; } // System.out.println(x.x00 + " " + x.x01); // System.out.println(x.x10 + " " + x.x11); System.out.println((x.x00 * a * 2 % 1000000007 + x.x01 * 2 % 1000000007) % 1000000007); } } class Matrix{ long x00, x01, x10, x11; public Matrix(long x00, long x01, long x10, long x11){ this.x00 = x00; this.x01 = x01; this.x10 = x10; this.x11 = x11; } public void mul(Matrix a){ long tmp00 = x00; long tmp01 = x01; long tmp10 = x10; long tmp11 = x11; long a00 = a.x00; long a01 = a.x01; long a10 = a.x10; long a11 = a.x11; this.x00 = (tmp00 * a00 % 1000000007 + tmp01 * a10 % 1000000007) % 1000000007; this.x01 = (tmp00 * a01 % 1000000007 + tmp01 * a11 % 1000000007) % 1000000007; this.x10 = (tmp10 * a00 % 1000000007 + tmp11 * a10 % 1000000007) % 1000000007; this.x11 = (tmp10 * a01 % 1000000007 + tmp11 * a11 % 1000000007) % 1000000007; } }