#include <bits/stdc++.h>
using namespace std;
int x, y;
int n;
const int mod = 1000000007;
struct mat {
  long long dt[2][2];
  mat operator*(const mat& b) const {
    mat c;
    for (int i = 0; i < 2; i++)
      for (int j = 0; j < 2; j++) {
        c.dt[i][j] = 0;
        for (int k = 0; k < 2; k++)
          c.dt[i][j] += (dt[i][k] * b.dt[k][j] % mod + mod) % mod;
        c.dt[i][j] = (c.dt[i][j] % mod + mod) % mod;
      }
    return c;
  }
};
mat fpow(mat x, int n) {
  mat ret;
  ret.dt[0][0] = ret.dt[1][1] = 1;
  ret.dt[0][1] = ret.dt[1][0] = 0;
  while (n != 0) {
    if (n % 2) ret = ret * x;
    x = x * x;
    n = n / 2;
  }
  return ret;
}
mat a, b;
int main() {
  a.dt[0][0] = 1;
  a.dt[0][1] = -1;
  a.dt[1][0] = 1;
  a.dt[1][1] = 0;
  while (~scanf("%d%d%d", &x, &y, &n)) {
    if (n == 0) {
      printf("0\n");
      continue;
    }
    if (n == 1) {
      printf("%d\n", (x % mod + mod) % mod);
      continue;
    }
    if (n == 2) {
      printf("%d\n", (y % mod + mod) % mod);
      continue;
    }
    b = fpow(a, n - 2);
    long long ans = b.dt[0][0] * y % mod + b.dt[0][1] * x % mod;
    ans = (ans % mod + mod) % mod;
    printf("%lld\n", ans);
  }
}
