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