#include <bits/stdc++.h>
using namespace std;
int first[4], x, y, n;
long long sol(int k) {
  if (k <= 3) return first[k];
  if ((k - 1) % 3 == 0) {
    int tmp = (k - 1) / 3;
    if (tmp & 1)
      return -first[1];
    else
      return first[1];
  } else if ((k - 2) % 3 == 0) {
    int tmp = (k - 2) / 3;
    if (tmp & 1)
      return -first[2];
    else
      return first[2];
  } else {
    int tmp = (k - 3) / 3;
    if (tmp & 1)
      return -first[3];
    else
      return first[3];
  }
}
int main() {
  cin >> first[1] >> first[2] >> n;
  first[3] = first[2] - first[1];
  long long ret = sol(n);
  cout << (ret % ((long long)1e9 + 7) + ((long long)1e9 + 7)) %
              ((long long)1e9 + 7)
       << endl;
  return 0;
}
