#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:512000000")
using namespace std;
template <class telem>
telem MAX(telem a, telem b) {
  return (a > b) ? a : b;
}
template <class telem>
telem MIN(telem a, telem b) {
  return (a < b) ? a : b;
}
template <class telem>
telem GCD(telem a, telem b) {
  return b ? GCD(b, a % b) : a;
}
template <class telem>
telem LCM(telem a, telem b) {
  return a / GCD(a, b) * b;
}
template <class telem>
telem UNSIGNED(telem a) {
  return (a > 0) ? a : a * (-1);
}
template <class telem>
void bez_swop(telem &a, telem &b) {
  telem c = a;
  a = b;
  b = c;
}
void swop(int &a, int &b) {
  a = a ^ b;
  b = a ^ b;
  a = a ^ b;
}
long long int s[6];
int x, y;
int n;
int main() {
  ios_base::sync_with_stdio(false);
  srand(time(NULL));
  time_t start = clock();
  cin >> x >> y >> n;
  s[0] = x;
  s[1] = y;
  s[2] = y - x;
  s[3] = -x;
  s[4] = -y;
  s[5] = x - y;
  n--;
  n %= 6;
  int mod = 1e9 + 7;
  s[n] %= mod;
  s[n] += mod;
  s[n] %= mod;
  cout << s[n];
  return 0;
}
