#include <bits/stdc++.h>
using namespace std;
long long solveb(long long i, long long f1, long long f2) {
  if (i == 1) return f1;
  if (i == 2) return (f2);
  return solveb(i - 1, f1, f2) - solveb(i - 2, f1, f2);
}
int main() {
  long long x, y, n;
  cin >> x >> y >> n;
  long long a[] = {x, y, (y - x), (-x), (-y), (x - y)};
  long long ans = a[(n - 1) % 6];
  if (ans >= 0)
    cout << ans % 1000000007;
  else {
    while (ans < 0) ans = (ans + 1000000007);
    cout << ans % 1000000007;
  }
  return 0;
}
