#include <bits/stdc++.h>
using namespace std;
long long makeMod(long long n) {
  while (n >= 1000000007) n -= 1000000007;
  while (n < 0) n += 1000000007;
  return n;
}
void Solve() {
  long long x, y, n, ans = 0;
  cin >> x >> y >> n;
  long long tmp[] = {x - y, x, y, y - x, -x, -y};
  cout << makeMod(tmp[n % 6]) << endl;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  Solve();
  return 0;
}
