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