#include <bits/stdc++.h>
using namespace std;
mt19937_64 rang(
    chrono::high_resolution_clock::now().time_since_epoch().count());
long long rng(long long lim) {
  uniform_int_distribution<long long> uid(0, lim - 1);
  return uid(rang);
}
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
long long expo(long long base, long long exp);
const long long mod = 1000000007;
bool perf(long long dis) {
  long long a = sqrt(dis);
  if (a * a == dis) return true;
  return false;
}
long long CIN = false;
void solve() {
  long a, b, n;
  cin >> a >> b >> n;
  n--;
  n = n % 6;
  n++;
  if (n == 1) {
    cout << (a < 0 ? (a + mod) : a);
  } else if (n == 2)
    cout << (b < 0 ? (b + mod) : b);
  else {
    a = a % mod;
    b = b % mod;
    long long counter = 2;
    while (counter != n) {
      long long temp = b % mod;
      b = (b - a) % mod;
      a = temp;
      counter++;
    }
    cout << (b < 0 ? (b + mod) : b);
  }
}
signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  srand(chrono::high_resolution_clock::now().time_since_epoch().count());
  long long t = 1;
  if (CIN) cin >> t;
  while (t--) {
    solve();
    cout << "\n";
  }
  return 0;
}
long long expo(long long base, long long exp) {
  base %= mod;
  long long result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((long long)result * base) % mod;
    base = ((long long)base * base) % mod;
    exp >>= 1;
  }
  return result;
}
