#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int x, y, z, n, f1, f2, f3;
  cin >> x >> y >> n;
  f1 = x % 1000000007;
  f2 = y % 1000000007;
  f3 = (y - x) % 1000000007;
  if (n % 3 == 1) {
    if ((n / 3) % 2 != 0)
      cout << ((-f1) % 1000000007 + 1000000007) % 1000000007;
    else
      cout << (f1 % 1000000007 + 1000000007) % 1000000007;
  } else if (n % 3 == 2) {
    if ((n / 3) % 2 != 0)
      cout << ((-f2) % 1000000007 + 1000000007) % 1000000007;
    else
      cout << (f2 % 1000000007 + 1000000007) % 1000000007;
  } else {
    if ((n / 3) % 2 != 0)
      cout << (f3 % 1000000007 + 1000000007) % 1000000007;
    else
      cout << ((-f3) % 1000000007 + 1000000007) % 1000000007;
  }
  return 0;
}
