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