#include <bits/stdc++.h>
int main() {
  long long f[10];
  long long a, b, n;
  while (~scanf("%lld %lld", &a, &b)) {
    scanf("%lld", &n);
    f[1] = a;
    f[2] = b;
    f[3] = b - a;
    f[4] = -a;
    f[5] = -b;
    f[0] = a - b;
    while (f[n % 6] < 0) {
      f[n % 6] += 1000000007;
    }
    while (f[n % 6] > 1000000007) {
      f[n % 6] -= 1000000007;
    }
    printf("%lld\n", f[n % 6]);
  }
}
