#include <bits/stdc++.h>
using namespace std;
int main() {
  long long x, y;
  cin >> x >> y;
  long long n;
  cin >> n;
  n %= 6;
  if (n == 0) n = 6;
  long long data[7];
  data[1] = x;
  data[2] = y;
  for (int i = 3; i <= 6; i++) {
    data[i] = data[i - 1] - data[i - 2];
  }
  for (int i = 1; i <= 6; i++)
    if (data[i] < 0) data[i] += 1000000007;
  if (data[n] < 0) data[n] += 1000000007;
  cout << data[n] % 1000000007 << "\n";
  return 0;
}
