#include <bits/stdc++.h>
using namespace std;
int modulo(long long x, int m) {
  while (x < 0) x += m;
  x %= m;
  return x;
}
int f(int n, int x, int y) {
  long long f1, f2, f3;
  if (n == 1) {
    return modulo(x, 1000000007);
  }
  if (n == 2) {
    return modulo(y, 1000000007);
  }
  f1 = x;
  f2 = y;
  for (int i = 3; i <= n; i++) {
    f3 = f2 - f1;
    f3 = modulo(f3, 1000000007);
    f1 = f2;
    f2 = f3;
  }
  return f3;
}
int main(int argc, char **argv) {
  int x, y;
  cin >> x >> y;
  int n;
  cin >> n;
  n %= 6;
  if (n == 0) {
    n = 6;
  }
  cout << f(n, x, y) << endl;
  return 0;
}
