#include <bits/stdc++.h>
using namespace std;
const int N = 100001, inf = 0x3f3f3f3f;
inline int read() {
  int date = 0, w = 1;
  char c = 0;
  while (c < '0' || c > '9') {
    if (c == '-') w = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    date = date * 10 + c - '0';
    c = getchar();
  }
  return date * w;
}
int a, b, n;
int f(int x) {
  if (x % 6 == 1) return a;
  if (x % 6 == 2) return b;
  if (x % 6 == 3) return b - a;
  if (x % 6 == 4) return -a;
  if (x % 6 == 5) return -b;
  if (x % 6 == 0) return a - b;
}
int main() {
  a = read(), b = read(), n = read();
  printf("%d", (f(n) % 1000000007 + 1000000007) % 1000000007);
  return 0;
}
