#include <bits/stdc++.h>
using namespace std;
int main() {
  long x, y;
  cin >> x >> y;
  long mod = 1000000007;
  long arr[6];
  arr[0] = x;
  arr[1] = y;
  arr[2] = y - x;
  arr[3] = -1 * x;
  arr[4] = -1 * y;
  arr[5] = x - y;
  long k;
  cin >> k;
  k--;
  k = k % 6;
  cout << ((arr[k] % mod) + mod) % mod;
}
