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