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