#include <bits/stdc++.h>
namespace taro {
namespace math {
template <typename T>
class Matrix {
 public:
  static Matrix<T> makeUnit(size_t n, T mod = 0) {
    Matrix<T> ret(n, n, mod);
    for (size_t i = 0; i < n; ++i) {
      ret[i][i] = 1;
    }
    return ret;
  }
  Matrix(size_t row_size, size_t col_size, T mod = 0) : mod_(mod) {
    resize(row_size, col_size);
  }
  Matrix(std::initializer_list<std::vector<T>> l) : data_(l.begin(), l.end()) {
    row_size_ = data_.size();
    col_size_ = data_[0].size();
    for (const auto& row : data_) {
      if (row.size() != col_size_) {
        throw std::length_error("Matrix: all col need same size.");
      }
    }
  }
  Matrix(const Matrix<T>& m) = default;
  Matrix(Matrix<T>&& m)
      : mod_(m.mod_),
        row_size_(m.row_size_),
        col_size_(m.col_size_),
        data_(std::move(m.data_)) {}
  Matrix<T>& operator=(const Matrix<T>& m) {
    mod_ = m.mod_;
    row_size_ = m.row_size_;
    col_size_ = m.col_size_;
    data_ = m.data_;
    return *this;
  }
  Matrix<T>& operator=(Matrix<T>&& m) {
    mod_ = m.mod_;
    row_size_ = m.row_size_;
    col_size_ = m.col_size_;
    data_ = std::move(m.data_);
    return *this;
  }
  ~Matrix() = default;
  std::vector<T>& operator[](size_t n) { return data_[n]; }
  const std::vector<T>& operator[](size_t n) const { return data_[n]; }
  Matrix<T> sub(size_t r_start, size_t r_end, size_t l_start,
                size_t l_end) const {
    Matrix<T> ret(r_end - r_start, l_end - l_start, mod_);
    for (size_t r = 0; r < r_end - r_start; ++r) {
      for (size_t l = 0; l < l_end - l_start; ++l) {
        ret[r][l] = data_[r + r_start][l + l_start];
      }
    }
    return ret;
  }
  Matrix<T> operator*(const Matrix<T>& m) const {
    if (colSize() != m.rowSize()) {
      throw std::length_error(
          "Matrix multi: col-size must be equal to row-size.");
    }
    Matrix<T> ret(rowSize(), m.colSize(), mod_);
    for (size_t r = 0; r < rowSize(); ++r) {
      for (size_t c = 0; c < m.colSize(); ++c) {
        for (size_t i = 0; i < m.rowSize(); ++i) {
          if (mod_ != 0) {
            ret[r][c] += data_[r][i] * m[i][c] % mod_;
            ret[r][c] %= mod_;
          } else {
            ret[r][c] += data_[r][i] * m[i][c];
          }
        }
      }
    }
    return ret;
  }
  Matrix<T> operator^(uint64_t n) const {
    if (rowSize() != colSize()) {
      throw std::length_error("Matrix: row_size must be equal to col_size");
    }
    Matrix<T> A = *this;
    Matrix<T> ret = makeUnit(rowSize(), mod_);
    while (n) {
      if (n & 1) ret = ret * A;
      A = A * A;
      n >>= 1;
    }
    return ret;
  }
  void resize(size_t row_size, size_t col_size) {
    row_size_ = row_size;
    col_size_ = col_size;
    data_.resize(row_size);
    for (auto& row : data_) {
      row.resize(col_size, 0);
    }
  }
  void clear() { data_.clear(); }
  void appendRow(const std::vector<T>& vec) {
    if (vec.size() != colSize()) {
      throw std::length_error("Matrix: vec.size() must be equal to col_size");
    }
    data_.push_back(vec);
  }
  void appendCol(const std::vector<T>& vec) {
    if (vec.size() != rowSize()) {
      throw std::length_error("Matrix: vec.size() must be equal to col_size");
    }
    for (size_t i = 0; i < rowSize(); ++i) {
      data_[i].push_back(vec[i]);
    }
  }
  size_t rowSize() const { return row_size_; }
  size_t colSize() const { return col_size_; }
  friend std::ostream& operator<<(std::ostream& out, const Matrix<T>& m) {
    out << "Matrix (" << m.rowSize() << " * " << m.colSize() << ") [\n";
    const static size_t width = 3;
    for (const auto& row : m.data_) {
      for (auto c : row) {
        out << std::setw(width) << c << ", ";
      }
      out << "\n";
    }
    out << "]";
    return out;
  }
  void setMod(T mod) { mod_ = mod; }

 private:
  T mod_ = 0;
  size_t row_size_;
  size_t col_size_;
  std::vector<std::vector<T>> data_;
};
}  // namespace math
}  // namespace taro
int solve(std::istream& cin, std::ostream& cout) {
  int64_t x, y, n;
  const int64_t mod = 1000000007;
  while (cin >> x >> y >> n) {
    if (n == 1) {
      cout << (x + mod) % mod << std::endl;
      continue;
    }
    if (n == 2) {
      cout << (y + mod) % mod << std::endl;
      continue;
    }
    taro::math::Matrix<int64_t> u = {
        {1, -1},
        {1, 0},
    };
    u.setMod(mod);
    taro::math::Matrix<int64_t> s = {
        {y},
        {x},
    };
    s.setMod(mod);
    u = (u ^ (n - 2)) * s;
    cout << (u[0][0] + mod) % mod << std::endl;
  }
  return 0;
}
int main() {
  std::ios_base::sync_with_stdio(false);
  return solve(std::cin, std::cout);
}
