#include <bits/stdc++.h>
using namespace std;
long long M = 1000000000 + 7;
int main() {
  long long int n, x, y, m = 0, k, sm = 0;
  cin >> x >> y >> n;
  x = x % M;
  y = y % M;
  n = n % 6;
  if (n == 1) cout << (x + M) % M;
  if (n == 2) cout << (y + M) % M;
  if (n == 3) cout << ((y - x) % M + M) % M;
  if (n == 4) cout << ((-1) * x + M) % M;
  if (n == 5) cout << ((-1) * y + M) % M;
  if (n == 0) cout << ((x - y) % M + M) % M;
}
