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