#include <bits/stdc++.h>
const int s = 10 + 1e5;
using namespace std;
void Ferrari() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int mod = 1e9 + 7;
int main() {
  Ferrari();
  long long x, y;
  cin >> x >> y;
  vector<long long> v(6);
  v[0] = x, v[1] = y;
  for (int i = 2; i < 6; ++i) {
    v[i] = v[i - 1] - v[i - 2];
  }
  int n;
  cin >> n;
  cout << (v[--n % 6] % mod + mod) % mod;
  return 0;
}
