#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int x, y, n;
  cin >> x >> y;
  cin >> n;
  long long int p = x % 1000000007;
  long long int q = y % 1000000007;
  long long int arr[6] = {(p - q) % 1000000007, p,  q,
                          (q - p) % 1000000007, -p, -q};
  int ans = arr[n % 6];
  if (ans < 0)
    cout << 1000000007 + ans;
  else
    cout << ans;
  return 0;
}
