#include <bits/stdc++.h>
using namespace std;
long long n, a[10];
int main() {
  scanf("%I64d%I64d", &a[1], &a[2]);
  scanf("%I64d", &n);
  for (int i = 3; i <= 6; i++) {
    a[i] = a[i - 1] % 1000000007 - a[i - 2] % 1000000007;
    a[i] %= 1000000007;
  }
  n %= 6;
  if (n == 0) n = 6;
  if (a[n] < 0)
    printf("%I64d\n", a[n] + 1000000007);
  else
    printf("%I64d\n", a[n] % 1000000007);
}
