#include <bits/stdc++.h>
using namespace std;
int main() {
  long long x, y, n;
  cin >> x >> y >> n;
  long long an = (int)n / 3;
  long long ans = 0;
  if (an % 2 == 0) {
    if (n % 3 == 0) {
      ans = (x - y) % 1000000007;
      if (ans < 0) ans = (ans + 1000000007) % 1000000007;
    } else if (n % 3 == 1) {
      ans = x % 1000000007;
      if (ans < 0) ans = (ans + 1000000007) % 1000000007;
    } else {
      ans = y % 1000000007;
      if (ans < 0) ans = (ans + 1000000007) % 1000000007;
    }
  } else {
    if (n % 3 == 0) {
      ans = (y - x) % 1000000007;
      if (ans < 0) ans = (ans + 1000000007) % 1000000007;
    } else if (n % 3 == 1) {
      ans = (-1 * x) % 1000000007;
      if (ans < 0) ans = (ans + 1000000007) % 1000000007;
    } else {
      ans = (-1 * y) % 1000000007;
      if (ans < 0) ans = (ans + 1000000007) % 1000000007;
    }
  }
  cout << ans << endl;
}
