#include <bits/stdc++.h>
using namespace std;
int main() {
  int x, y;
  while (cin >> x >> y) {
    int n, a[7];
    cin >> n;
    a[1] = x;
    a[2] = y;
    a[3] = y - x;
    a[4] = -a[1];
    a[5] = -a[2], a[6] = -a[3];
    a[0] = a[6];
    a[n] = a[n % 6];
    cout << ((a[n] % 1000000007) + 1000000007) % 1000000007 << endl;
  }
  return 0;
}
