#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void s() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int32_t main() {
  s();
  long long x, y, n;
  cin >> x >> y >> n;
  long long MOD = 1e9 + 7;
  n = n % 6;
  if (x == 0 && y == 0) {
    cout << 0 << "\n";
    return 0;
  }
  if (n == 1) {
    x = (x + MOD) % MOD;
    cout << x << "\n";
    return 0;
  } else if (n == 2) {
    y = (y + MOD) % MOD;
    cout << y << "\n";
    return 0;
  } else if (n == 3) {
    long long ans = (((y + MOD) % MOD - (x + MOD) % MOD) + MOD) % MOD;
    cout << ans << "\n";
    return 0;
  } else if (n == 4) {
    long long ans = ((-1 * x) + MOD) % MOD;
    cout << ans << "\n";
    return 0;
  } else if (n == 5) {
    long long ans = ((-1 * y) + MOD) % MOD;
    cout << ans << "\n";
    return 0;
  } else if (n == 0) {
    long long ans = (((x + MOD) % MOD - (y + MOD) % MOD) + MOD) % MOD;
    cout << ans << "\n";
    return 0;
  }
  return 0;
}
