#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long m = 1000000007;
  long long x, y, n;
  cin >> x >> y >> n;
  long long s = 0, e = 0;
  long long ans = 0;
  if (n == 1) {
    while (x < 0) {
      x += m;
    }
    cout << x % m << endl;
    return 0;
  }
  if ((n - 2) % 6 == 0) {
    e = 0;
  } else if ((n - 3) % 6 == 0) {
    e = 1;
  } else if ((n - 4) % 6 == 0) {
    e = 2;
  } else if ((n - 5) % 6 == 0) {
    e = 3;
  } else if ((n - 6) % 6 == 0) {
    e = 4;
  } else if ((n - 7) % 6 == 0) {
    e = 5;
  }
  long long arr[6] = {y, y - x, -x, -y, x - y, x};
  ans = arr[e];
  while (ans < 0) {
    ans += m;
  }
  cout << ans % m << endl;
}
