#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, cnt, a[4], ans;
  cin >> a[1] >> a[2] >> n;
  a[0] = a[1] - a[2];
  cnt = n / 3;
  n = n % 3;
  if (cnt % 2 == 0)
    ans = a[n];
  else
    ans = -a[n];
  while (ans < 0) ans += 1000000007;
  cout << ans % 1000000007 << endl;
  return 0;
}
