#include <bits/stdc++.h>
using namespace std;
long long int mod(long long int a, long long int b) { return (a % b + b) % b; }
int main() {
  long long int x, y, res[10], n;
  scanf("%I64d%I64d", &x, &y);
  res[1] = x;
  res[2] = y;
  for (int i = (int)3; i <= (int)6; i++) {
    res[i] = mod(res[i - 1] - res[i - 2], 1000000007);
  }
  scanf("%I64d", &n);
  int idx = n % 6;
  if (idx == 0) idx = 6;
  printf("%I64d\n", mod(res[idx], 1000000007));
  return 0;
}
