#include <bits/stdc++.h>
using namespace std;
using namespace std;
int nxt() {
  int x;
  cin >> x;
  return x;
}
const int INF = int(1e9) + 99;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long fact(long long n) {
  long long t = 1;
  if (n == 0 || n == 1) return t;
  for (int i = 2; i <= n; i++) t *= i;
  return t;
}
const int N = int(2e5) + 99;
vector<int> plist;
void SieveOfEratosthenes(int n) {
  bool prime[n + 1];
  memset(prime, true, sizeof(prime));
  for (int p = 2; p * p <= n; p++) {
    if (prime[p] == true) {
      for (int i = p * p; i <= n; i += p) prime[i] = false;
    }
  }
  for (int p = 2; p <= n; p++)
    if (prime[p]) plist.push_back(p);
}
long long power(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  if (x == 0) return 0;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
int _mergeSort(int arr[], int temp[], int left, int right);
int merge(int arr[], int temp[], int left, int mid, int right);
int mergeSort(int arr[], int array_size) {
  int temp[array_size];
  return _mergeSort(arr, temp, 0, array_size - 1);
}
int _mergeSort(int arr[], int temp[], int left, int right) {
  int mid, inv_count = 0;
  if (right > left) {
    mid = (right + left) / 2;
    inv_count += _mergeSort(arr, temp, left, mid);
    inv_count += _mergeSort(arr, temp, mid + 1, right);
    inv_count += merge(arr, temp, left, mid + 1, right);
  }
  return inv_count;
}
int merge(int arr[], int temp[], int left, int mid, int right) {
  int i, j, k;
  int inv_count = 0;
  i = left;
  j = mid;
  k = left;
  while ((i <= mid - 1) && (j <= right)) {
    if (arr[i] <= arr[j]) {
      temp[k++] = arr[i++];
    } else {
      temp[k++] = arr[j++];
      inv_count = inv_count + (mid - i);
    }
  }
  while (i <= mid - 1) temp[k++] = arr[i++];
  while (j <= right) temp[k++] = arr[j++];
  for (i = left; i <= right; i++) arr[i] = temp[i];
  return inv_count;
}
long long binomialCoeff(long long n, long long k) {
  long long res = 1;
  if (k > n - k) k = n - k;
  for (long long i = 0; i < k; ++i) {
    res *= (n - i);
    res /= (i + 1);
  }
  return res;
}
const long long MAXN = 100001;
long long spf[MAXN];
void sieve() {
  spf[1] = 1;
  for (long long i = 2; i < MAXN; i++) spf[i] = i;
  for (long long i = 4; i < MAXN; i += 2) spf[i] = 2;
  for (long long i = 3; i * i < MAXN; i++) {
    if (spf[i] == i) {
      for (long long j = i * i; j < MAXN; j += i)
        if (spf[j] == j) spf[j] = i;
    }
  }
}
map<long long, long long> getFactorization(long long x) {
  map<long long, long long> ret;
  while (x != 1) {
    ret[spf[x]]++;
    x = x / spf[x];
  }
  return ret;
}
vector<int> adj[1000004];
bool check[1000000 + 1];
vector<int> temp;
vector<vector<int>> cc;
void dfs(int r) {
  check[r] = 1;
  temp.push_back(r);
  for (int i = 0; i < adj[r].size(); i++) {
    if (!check[adj[r][i]]) {
      dfs(adj[r][i]);
    }
  }
}
void solve() {
  long long n, d, m, l, a, b, w, x = 1e17 + 8, y = 0, t = 1e9 + 7;
  long long maxi = 1;
  long long sum;
  cin >> a >> b >> n;
  n = n % 6;
  if (n == 1) {
    cout << (a + 2 * t) % t;
    return;
  }
  if (n == 2) {
    cout << (b + 3 * t) % t;
    return;
  }
  if (n == 3) {
    cout << (b - a + 3 * t) % t;
    return;
  }
  if (n == 4) {
    cout << (-a + 3 * t) % t;
    return;
  }
  if (n == 5) {
    cout << (-b + 3 * t) % t;
    return;
  }
  if (n == 0) {
    cout << (a - b + 3 * t) % t;
    return;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  while (t--) {
    solve();
    cout << "\n";
  }
  return 0;
}
