#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve() {
  int x, y, n;
  cin >> x >> y >> n;
  int nums[] = {x - y, x, y, y - x, -x, -y};
  cout << ll(nums[n % 6] + 2 * (1e9 + 7)) % ll(1e9 + 7);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
}
