#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1000000007LL;
long long int a, b, n;
int main() {
  cin >> a >> b >> n;
  n--;
  n = n % 6;
  long long int ans = 0;
  switch (n) {
    case (0): {
      ans = (a + mod) % mod;
      break;
    }
    case (1): {
      ans = (b + mod) % mod;
      break;
    }
    case (2): {
      ans = (b - a + 2 * mod) % mod;
      break;
    }
    case (3): {
      ans = (mod - a) % mod;
      break;
    }
    case (4): {
      ans = (mod - b) % mod;
      break;
    }
    case (5): {
      ans = (a - b + 2 * mod) % mod;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
