#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
int main() {
  long long x, y, n, res;
  cin >> x >> y >> n;
  long long ans[6] = {x, y, y - x, -x, -y, x - y};
  res = (ans[(n - 1) % 6]) % MOD;
  if (res < 0) res = (res + MOD) % MOD;
  cout << res << "\n";
}
