#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int a, b;
  cin >> a >> b;
  int s[6] = {a, b, b - a, -a, -b, a - b};
  int n;
  cin >> n;
  cout << (s[(n - 1) % 6] % (long long)1000000007 + (long long)1000000007) %
              (long long)1000000007
       << '\n';
  return 0;
}
