#include <bits/stdc++.h>
const long long N = 1e9 + 7;
using namespace std;
long long a[7];
int main() {
  long long x, y;
  int n;
  while (scanf("%lld%lld%d", &x, &y, &n) != EOF) {
    a[1] = x, a[2] = y;
    for (int i = 3; i <= 6; i++) {
      a[i] = a[i - 1] - a[i - 2];
    }
    n = (n - 1) % 6 + 1;
    while (a[n] < 0) a[n] += N;
    printf("%lld\n", a[n] % N);
  }
  return 0;
}
