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