#include <bits/stdc++.h>
int main() {
  int n, a, b;
  scanf("%d%d%d", &a, &b, &n);
  n %= 6;
  if (n == 1)
    printf("%d\n", a % 1000000007 + (a % 1000000007 < 0 ? 1000000007 : 0));
  else if (n == 2)
    printf("%d\n", b % 1000000007 + (b % 1000000007 < 0 ? 1000000007 : 0));
  else if (n == 3)
    printf("%d\n",
           (b - a) % 1000000007 + ((b - a) % 1000000007 < 0 ? 1000000007 : 0));
  else if (n == 4)
    printf("%d\n",
           (-a) % 1000000007 + ((-a) % 1000000007 < 0 ? 1000000007 : 0));
  else if (n == 5)
    printf("%d\n",
           (-b) % 1000000007 + ((-b) % 1000000007 < 0 ? 1000000007 : 0));
  else if (n == 0)
    printf("%d\n",
           (a - b) % 1000000007 + ((a - b) % 1000000007 < 0 ? 1000000007 : 0));
  return 0;
}
