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