#include <bits/stdc++.h>
using namespace std;
int n, x, y, s[7];
int main() {
  scanf("%d%d", &x, &y);
  scanf("%d", &n);
  n = n % 6;
  s[1] = x, s[2] = y;
  for (int i = 3; i < 6; ++i) s[i] = s[i - 1] - s[i - 2];
  s[0] = s[5] - s[4];
  printf("%d", (s[n] % 1000000007 + 1000000007) % 1000000007);
  return 0;
}
