#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios_base::Init i;
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);
  long long int a[6];
  int n;
  cin >> a[0] >> a[1];
  cin >> n;
  a[0] = ((a[0] % 1000000007) + 1000000007) % 1000000007;
  a[1] = ((a[1] % 1000000007) + 1000000007) % 1000000007;
  for (long long int i = 2; i <= 5; i++) {
    a[i] = a[i - 1] - a[i - 2];
    a[i] = ((a[i] % 1000000007) + 1000000007) % 1000000007;
  }
  cout << a[(n - 1) % 6] << endl;
  return 0;
}
