#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops", "no-stack-protector")
using namespace std;
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long test = 1;
  while (test--) {
    long long x, y;
    cin >> x >> y;
    long long n;
    cin >> n;
    long long hash[7];
    hash[0] = 0;
    hash[1] = x;
    hash[2] = y;
    hash[3] = (y - x + 1000000007) % 1000000007;
    hash[4] = (-1 * x + 1000000007) % 1000000007;
    hash[5] = (-1 * y + 1000000007) % 1000000007;
    hash[6] = (x - y + 1000000007) % 1000000007;
    long long rem = (n) % 6;
    if (rem == 0) rem = 6;
    long long ans = hash[rem];
    cout << (ans + 1000000007) % 1000000007;
  }
  cerr << endl
       << "Time: " << (clock() * 1000. / CLOCKS_PER_SEC) << " ms" << endl;
  return 0;
}
