#include <bits/stdc++.h>
using namespace std;
int main() {
  int a[6], n;
  while (scanf("%d%d%d", &a[0], &a[1], &n) != EOF) {
    a[2] = a[1] - a[0];
    for (int i = 0; i < 3; i++) {
      a[i + 3] = -a[i];
    }
    n--;
    int id = n % 6;
    while (a[id] < 0) a[id] += 1000000007;
    printf("%d\n", a[id] % 1000000007);
  }
  return 0;
}
