#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int a, b;
  cin >> a >> b;
  long long int n;
  cin >> n;
  if (a == b && a == 0) {
    cout << 0 << endl;
  } else {
    long long int ar[6];
    ar[0] = (a - b) % 1000000007;
    ar[1] = a % 1000000007;
    ar[2] = b % 1000000007;
    ar[3] = (ar[2] - ar[1]) % 1000000007;
    ar[4] = -ar[1] % 1000000007;
    ar[5] = -ar[2] % 1000000007;
    long long int ans;
    ans = ar[n % 6];
    if (ans < 0) {
      ans += 1000000007;
    }
    cout << ans << endl;
  }
}
