#include <bits/stdc++.h>
using namespace std;
int main() {
  long long x, y, n, m = 1000000007;
  cin >> x >> y >> n;
  vector<long long> v(7);
  v[1] = (x + m) % m, v[2] = (y + m) % m;
  for (int i = 3; i <= 6; i++) {
    v[i] = (v[i - 1] - v[i - 2] + m) % m;
  }
  if (n % 6 == 0)
    cout << v[6];
  else
    cout << v[n % 6];
  return 0;
}
