#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
long long solve() {
  long long i, j, k = 0, n, x, y;
  cin >> x >> y;
  cin >> n;
  if (n == 1) return (x + 1000000007) % 1000000007;
  if (n == 2) return (y + 1000000007) % 1000000007;
  if (n == 3) return (y - x + 1000000007 + 1000000007) % 1000000007;
  if ((n - 4) % 6 == 0) return (1000000007 - x) % 1000000007;
  if ((n - 4) % 6 == 1) return (1000000007 - y) % 1000000007;
  if ((n - 4) % 6 == 2) return (1000000007 + x - y + 1000000007) % 1000000007;
  if ((n - 4) % 6 == 3) return (1000000007 + x) % 1000000007;
  if ((n - 4) % 6 == 4) return (1000000007 + y) % 1000000007;
  if ((n - 4) % 6 == 5) return (1000000007 + y - x + 1000000007) % 1000000007;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long t = 1;
  while (t--) {
    cout << solve();
  }
}
