#include <bits/stdc++.h>
using namespace std;
void start() {
  long long x, y;
  cin >> x >> y;
  long long n;
  cin >> n;
  n %= 6;
  long long ans = 0;
  if (n == 0)
    ans = x - y;
  else if (n == 1)
    ans = x;
  else if (n == 2)
    ans = y;
  else if (n == 3)
    ans = y - x;
  else if (n == 4)
    ans = -x;
  else
    ans = -y;
  ans %= 1000000007;
  if (ans < 0) ans += 1000000007;
  cout << ans;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  start();
  return 0;
}
