#include <bits/stdc++.h>
const int mod = 1000000007;
struct Matrix {
  long long x[2][2];
  Matrix() {}
  Matrix(bool f) {
    memset(x, 0, sizeof(x));
    if (f) {
      x[0][0] = x[1][1] = 1;
    }
  }
  Matrix operator*(Matrix A) {
    Matrix C = Matrix();
    for (int i = 0; i < 2; i++) {
      for (int j = 0; j < 2; j++) {
        long long &T = C.x[i][j];
        T = 0;
        for (int k = 0; k < 2; k++) {
          T = (T + x[i][k] * A.x[k][j]) % mod;
          T = (T + mod) % mod;
        }
      }
    }
    return C;
  }
};
Matrix pow(Matrix A, int p) {
  Matrix S = Matrix(1);
  while (p) {
    if (p & 1) S = S * A;
    A = A * A;
    p >>= 1;
  }
  return S;
}
long long solve(long long x, long long y, int n) {
  if (n == 1) return (x % mod + mod) % mod;
  if (n == 2) return (y % mod + mod) % mod;
  Matrix A = Matrix(0);
  A.x[0][0] = A.x[0][1] = 1;
  A.x[1][0] = mod - 1;
  Matrix S = pow(A, n - 2);
  long long ans = y * S.x[0][0] % mod + x * S.x[1][0] % mod;
  ans = (ans % mod + mod) % mod;
  return ans;
}
int main() {
  long long x, y;
  int n;
  while (~scanf("%I64d %I64d %d", &x, &y, &n)) {
    printf("%I64d\n", solve(x, y, n));
  }
  return 0;
}
