#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using vii = vector<ii>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vector<ll>>;
using vs = vector<string>;
using vvs = vector<vs>;
int main() {
  constexpr ll MOD = 1000000007;
  vi v(10, 0);
  ll x, y, n;
  cin >> x >> y >> n;
  v[0] = x;
  v[1] = y;
  for (auto(i) = 2; (i) < (10); ++(i)) v[i] = v[i - 1] - v[i - 2];
  --n;
  cout << (v[n % 6] + MOD * 5) % 1000000007;
  cout << "\n";
  return 0;
}
