#include <bits/stdc++.h>
using namespace std;
vector<long long> ans;
int main() {
  long long x, y, n, mod = 1000000007;
  cin >> x >> y >> n;
  long long m, p, q;
  m = n / 3;
  if (n % 3 == 0 && m % 2 == 0) {
    p = mod + x - y;
    if (p < 0) p = p + mod;
    cout << p % mod << '\n';
    return 0;
  } else if (n % 3 == 0 && m % 2 == 1) {
    p = mod + y - x;
    if (p < 0) p = p + mod;
    cout << p % mod << '\n';
    return 0;
  }
  if (m % 2 == 0) {
    if (n % 3 == 1)
      p = mod + x;
    else
      p = mod + y;
  } else {
    if (n % 3 == 1)
      p = mod - x;
    else
      p = mod - y;
  }
  if (p < 0) p = p + mod;
  cout << p % mod;
}
