#include <bits/stdc++.h>
using namespace std;
long long a[3], n;
int main() {
  cin >> a[1] >> a[2] >> n;
  a[0] = a[2] - a[1];
  int t = (n - 1) / 3;
  int tt = n % 3;
  if (t % 2 == 0)
    n = a[tt];
  else
    n = -a[tt];
  if (n < 0)
    if (n >= -1000000007)
      cout << n + 1000000007;
    else
      cout << n + 2000000014;
  else
    cout << n % 1000000007;
  return 0;
}
