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