#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
long long int x, y, n;
int main() {
  cin >> x >> y >> n;
  if (((n - 1) % 6) == 0) {
    long long int t = x;
    while (t >= mod || t < 0) {
      t += (t >= mod) ? -mod : mod;
    }
    cout << t;
  } else if (((n - 1) % 6) == 1) {
    long long int t = y;
    while (t >= mod || t < 0) {
      t += (t >= mod) ? -mod : mod;
    }
    cout << t;
  } else if (((n - 1) % 6) == 2) {
    long long int t = y - x;
    while (t >= mod || t < 0) {
      t += (t >= mod) ? -mod : mod;
    }
    cout << t;
  } else if (((n - 1) % 6) == 3) {
    long long int t = -x;
    while (t >= mod || t < 0) {
      t += (t >= mod) ? -mod : mod;
    }
    cout << t;
  } else if (((n - 1) % 6) == 4) {
    long long int t = -y;
    while (t >= mod || t < 0) {
      t += (t >= mod) ? -mod : mod;
    }
    cout << t;
  } else if (((n - 1) % 6) == 5) {
    long long int t = x - y;
    while (t >= mod || t < 0) {
      t += (t >= mod) ? -mod : mod;
    }
    cout << t;
  }
}
