#include <bits/stdc++.h>
long long cnt;
using namespace std;
long long dp[10000000];
void solve() {
  long long x, y;
  cin >> x >> y;
  long long n;
  cin >> n;
  long long a[6];
  a[0] = x;
  a[1] = y;
  for (long long i = 2; i < 6; i++) {
    long long t = y;
    y -= x;
    x = t;
    a[i] = y;
  }
  if (a[(n - 1) % 6] >= 0)
    cout << a[(n - 1) % 6] % 1000000007;
  else {
    long long m = -1 * a[(n - 1) % 6];
    cout << ((m % 1000000007) - ((2 * m) % 1000000007) + 1000000007) %
                1000000007;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  solve();
}
