#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, x, y;
  long long a[7] = {0};
  while (cin >> x >> y) {
    scanf("%lld", &n);
    a[1] = x;
    a[2] = y;
    a[3] = y - x;
    a[4] = -x;
    a[5] = -y;
    a[0] = -a[3];
    if (a[n % 6] < 0) a[n % 6] += 10000000070;
    printf("%lld\n", a[n % 6] % 1000000007);
  }
  return 0;
}
