#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
using namespace std;
int main() {
  long long x, y, n, res = 0;
  cin >> x >> y >> n;
  n--;
  n = n % 6;
  if (n == 0)
    res = x;
  else if (n == 1)
    res = y;
  else if (n == 2)
    res = y - x;
  else if (n == 3)
    res = -x;
  else if (n == 4)
    res = -y;
  else if (n == 5)
    res = -y + x;
  res %= MOD;
  if (res < 0) res += MOD;
  cout << res << endl;
  return 0;
}
