#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e2, mod = 1e9 + 7;
long long a[35];
long long x, y;
int n;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> x >> y >> n;
  a[0] = (x + mod) % mod;
  a[1] = (y + mod) % mod;
  for (int i = 2; i < 6; i++) a[i] = (a[i - 1] - a[i - 2]) % mod;
  cout << (a[((n - 1) % 6)] + mod) % mod;
  return 0;
}
