#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
  long long x, y, n, s, m = 1e9 + 7;
  cin >> x >> y >> n;
  n--;
  if (n % 6 == 0)
    s = x;
  else if (n % 6 == 1)
    s = y;
  else if (n % 6 == 2)
    s = y - x;
  else if (n % 6 == 3)
    s = -x;
  else if (n % 6 == 4)
    s = -y;
  else if (n % 6 == 5)
    s = x - y;
  s = (s % m + m) % m;
  cout << s << "\n";
  return 0;
}
