#include <bits/stdc++.h>
using namespace std;
int main() {
  long long x, y, n;
  cin >> x >> y >> n;
  long long arr[6];
  arr[0] = x;
  arr[1] = y;
  for (int i = 2; i < 6; i++) {
    arr[i] = arr[i - 1] - arr[i - 2];
  }
  long long index = (n - 1) % 6;
  long long m = pow(10, 9) + 7;
  long long ans = (arr[index] + m) % m;
  while (ans < 0) {
    ans = (ans + m) % m;
  }
  cout << ans << endl;
  return 0;
}
