#include <bits/stdc++.h>
using namespace std;
void solve();
bool prime[10000001];
void sieve(long long n) {
  for (int p = 2; p * p <= n; p++) {
    if (prime[p] == true) {
      for (int i = p * p; i <= n; i += p) prime[i] = false;
    }
  }
}
long long fast_exp(long long base, long long power) {
  long long result = 1;
  while (power > 0) {
    if (power % 2 == 1) {
      result = (result * base) % 1000000007;
    }
    base = (base * base) % 1000000007;
    power = power / 2;
  }
  return result % 1000000007;
}
void initialize() {
  for (int i = 0; i <= 100001; i++) {
    prime[i] = true;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  while (t--) {
    solve();
    cout << "\n";
  }
  cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
  return 0;
}
void solve() {
  int x, y;
  cin >> x >> y;
  int n;
  cin >> n;
  map<int, int> mp;
  mp[0] = x;
  mp[1] = y;
  mp[2] = y - x;
  mp[3] = -x;
  mp[4] = -y;
  mp[5] = x - y;
  int r = (n - 1) % 6;
  int pp = mp[r] % 1000000007;
  if (pp < 0)
    cout << 1000000007 + pp;
  else
    cout << mp[r] % 1000000007;
}
