Jzzhu has invented a kind of sequences, they meet the following property:$f_{1} = x ; f_{2} = y ; \forall i(i \geq 2), f_{i} = f_{i - 1} + f_{i + 1}$

You are given x and y, please calculate f_{n} modulo 1000000007 (10^9 + 7).


-----Input-----

The first line contains two integers x and y (|x|, |y| ≤ 10^9). The second line contains a single integer n (1 ≤ n ≤ 2·10^9).


-----Output-----

Output a single integer representing f_{n} modulo 1000000007 (10^9 + 7).


-----Examples-----
Input
2 3
3

Output
1

Input
0 -1
2

Output
1000000006



-----Note-----

In the first sample, f_2 = f_1 + f_3, 3 = 2 + f_3, f_3 = 1.

In the second sample, f_2 =  - 1;  - 1 modulo (10^9 + 7) equals (10^9 + 6).

Difficulty: EASY

Solutions:
(x, y) = map(int, input().split())
n = int(input())
MOD = 10 ** 9 + 7
rem = n % 6
if rem == 0:
	print((-y + x) % MOD)
elif rem == 1:
	print(x % MOD)
elif rem == 2:
	print(y % MOD)
elif rem == 3:
	print((y - x) % MOD)
elif rem == 4:
	print(-x % MOD)
else:
	print(-y % MOD)


(x, y) = map(int, input().split())
l = [x, y, y - x, -x, -y, x - y]
n = int(input())
n -= 1
n = n % 6
print(l[n] % 1000000007)


in1 = input().split(' ')
for i in range(0, 2):
	in1[i] = int(in1[i])
n = int(input())

def Recur(x, y, n):
	ans = [x, y]
	for i in range(3, 7):
		(x, y) = (y, y - x)
		ans.append(y)
	i = n % 6
	if i == 0:
		i = 6
	return ans[i - 1]
print(Recur(in1[0], in1[1], n) % 1000000007)


xy = list(map(int, input().strip().split()))
x = xy[0]
y = xy[1]
n = int(input().strip())
n = n % 6
if n == 1:
	print(x % (10 ** 9 + 7))
elif n == 2:
	print(y % (10 ** 9 + 7))
elif n == 3:
	print((y - x) % (10 ** 9 + 7))
elif n == 4:
	print(-x % (10 ** 9 + 7))
elif n == 5:
	print(-y % (10 ** 9 + 7))
else:
	print((x - y) % (10 ** 9 + 7))


(a, b) = input().split(' ')
a = int(a)
mod = 10 ** 9 + 7
b = int(b)
c = int(input())
c = c - 1
c = c % 6
if c == 0:
	print(a % mod)
elif c == 1:
	print(b % mod)
elif c == 2:
	print((b - a) % mod)
elif c == 3:
	print(-a % mod)
elif c == 4:
	print(-b % mod)
elif c == 5:
	print((a - b) % mod)


mod = 10 ** 9 + 7
(x, y) = map(int, input().split())
n = int(input())
a = [x - y, x, y, y - x, -x, -y]
print(a[n % 6] % mod)


mod = 10 ** 9 + 7
(f1, f2) = map(int, input().split())
f3 = f2 - f1
k = int(input())
if k % 3 == 0:
	if k % 2 == 0:
		print((f1 - f2) % mod)
	else:
		print((f2 - f1) % mod)
elif k % 3 == 1:
	if (k - 1) % 2 == 1:
		print(-f1 % mod)
	else:
		print(f1 % mod)
elif (k - 2) % 2 == 1:
	print(-f2 % mod)
else:
	print(f2 % mod)


(x, y) = map(int, input().split(' '))
n = int(input())
l = [x, y]
for i in range(4):
	l.append(l[-1] - l[-2])
a = n % 6
print(l[a - 1] % 1000000007)


(x, y) = [int(x) for x in input().split()]
query = int(input())
l = [x, y]
for i in range(2, 6):
	l.append(l[i - 1] - l[i - 2])
query = query % 6 - 1
ans = l[query]
print(ans % 1000000007)


array = list(map(int, input().rstrip().split()))
f1 = array[0]
f2 = array[1]
f3 = f2 - f1
n = int(input())
a1 = n % 3
a2 = n // 3
if a2 % 2 == 0:
	if a1 == 0:
		ans = -1 * f3
	elif a1 == 1:
		ans = f1
	else:
		ans = f2
elif a1 == 0:
	ans = f3
elif a1 == 1:
	ans = -1 * f1
else:
	ans = -1 * f2
print(ans % 1000000007)


(a, b) = map(int, input().split())
n = int(input())
mod = 1000000007
l = [a, b, b - a, -a, -b, a - b]
print((l[(n - 1) % 6] % mod + mod) % mod)


import sys
(x, y) = map(int, input().split())
n = int(input())
l = [x - y, x, y, -x + y, -x, -y]
s = l[n % 6]
print(s % (10 ** 9 + 7))


def solve(x, y, n):
	if x == 0 and y == 0:
		return 0
	first_term = x
	second_term = y
	info = [x, y, y - x, x * -1]
	dummy_x = y - x
	dummy_y = x * -1
	while dummy_x != first_term or dummy_y != second_term:
		last_x = dummy_x
		last_y = dummy_y
		info.append(last_y - last_x)
		info.append(last_x * -1)
		dummy_x = info[-2]
		dummy_y = info[-1]
	info.pop()
	info.pop()
	count = len(info)
	if n % count == 0:
		return info[-1] % (10 ** 9 + 7)
	else:
		index = n % count - 1
		return info[index] % (10 ** 9 + 7)
i = input
(x, y) = map(int, i().split())
n = int(i())
result = solve(x, y, n)
print(result)


(x, y) = input().split()
x = int(x)
y = int(y)
dp = []
dp.append(x)
dp.append(y)
dp.append(y - x)
dp.append(-x)
dp.append(-y)
dp.append(-y + x)
n = int(input())
print(dp[(n - 1) % 6] % 1000000007)


MOD = 1000000007

def negmod(x):
	if x >= 0:
		return x % MOD
	else:
		while x < 0:
			x += MOD
		return x % MOD
(x, y) = map(int, input().split())
n = int(input())
d = [x, y, -x + y, -x, -y, x - y]
print(negmod(d[(n - 1) % 6]))


(x, y) = map(int, input().split())
n = int(input())
l = [x, y, y - x, -x, -y, x - y]
if n <= 6:
	print(l[n - 1] % 1000000007)
else:
	t = n % 6
	if t != 0:
		print(l[t - 1] % 1000000007)
	else:
		print(l[5] % 1000000007)


mod = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
(f1, f2) = f()
n = ii()
l = [f1, f2]
temp = f2
f2 = f2 - f1
f1 = temp
for i in range(4):
	l.append(f2)
	temp = f2
	f2 = f2 - f1
	f1 = temp
print(l[(n - 1) % 6] % mod)


(a, b) = map(int, input().split())

def cp(n):
	if n == 2:
		return b % (10 ** 9 + 7)
	elif n == 1:
		return a % (10 ** 9 + 7)
	else:
		return (cp(n - 1) - cp(n - 2)) % (10 ** 9 + 7)
z = int(input()) % 6
if z == 0:
	print(cp(6))
else:
	print(cp(z))


def solve(arr, n):
	l = [0] * 6
	l[0:1] = arr
	for i in range(2, 6):
		l[i] = l[i - 1] - l[i - 2]
	return l[(n - 1) % 6] % 1000000007
res = solve(list(map(int, input().split())), int(input()))
print(res)


def main():
	k = int(10 ** 9 + 7)
	(x, y) = map(int, input().split())
	n = int(input())
	if n == 1:
		print(x % k)
	elif n == 2:
		print(y % k)
	else:
		n = (n - 3) % 6
		if n == 0:
			print((y - x) % k)
		elif n == 1:
			print(-x % k)
		elif n == 2:
			print(-y % k)
		elif n == 3:
			print((-y + x) % k)
		elif n == 4:
			print(x % k)
		elif n == 5:
			print(y % k)
main()


(x, y) = map(int, input().split())
n = int(input())
z = []
z.append(x)
z.append(y)
for i in range(2, 6):
	z.append(z[i - 1] - z[i - 2])
print(z[n % 6 - 1] % 1000000007)


import sys
import time
import os
from math import sqrt, log, log2, ceil, log10, gcd, floor, pow, sin, cos, tan, pi, inf, factorial
from copy import copy, deepcopy
from sys import exit, stdin, stdout
from collections import Counter, defaultdict, deque
from itertools import permutations
import heapq
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
mod = 1000000007
iinp = lambda : int(sys.stdin.readline())
inp = lambda : sys.stdin.readline().strip()
strl = lambda : list(inp().strip().split(' '))
intl = lambda : list(map(int, inp().split(' ')))
mint = lambda : map(int, inp().split())
flol = lambda : list(map(float, inp().split(' ')))
flush = lambda : stdout.flush()

def solve():
	(x, y) = mint()
	n = iinp()
	f = [0] * 6
	x = (x + mod) % mod
	y = (y + mod) % mod
	f[0] = x
	f[1] = y
	f[2] = (y - x + mod) % mod
	f[3] = (-x + mod) % mod
	f[4] = (-y + mod) % mod
	f[5] = (x - y + mod) % mod
	print(f[(n - 1) % 6])
t = 1
for _ in range(t):
	solve()


from sys import stdin, stdout
(x, y) = map(int, stdin.readline().strip().split())
n = int(stdin.readline().strip())
rem = n % 6
mod = 10 ** 9 + 7
if rem == 1:
	print(x % mod)
elif rem == 2:
	print(y % mod)
elif rem == 3:
	print((y - x) % mod)
elif rem == 4:
	print(-x % mod)
elif rem == 5:
	print(-y % mod)
else:
	print((x - y) % mod)


inp = input().split()
n = int(input())
a = int(inp[0])
b = int(inp[1])
ans = n % 6
if ans == 1:
	ans = a
elif ans == 2:
	ans = b
elif ans == 3:
	ans = b - a
elif ans == 4:
	ans = -a
elif ans == 5:
	ans = -b
else:
	ans = a - b
print(ans % 1000000007)


(x, y) = map(int, input().split())
n = int(input()) - 1
f = [x, y, y - x, -x, -y, x - y]
print(f[n % 6] % 1000000007)


(x, y) = map(int, input().split())
n = int(input())
mod = 10 ** 9 + 7
if n == 1:
	print(x % mod)
	exit()
if n == 2:
	print(y % mod)
	exit()
d = {1: y - x, 2: -x, 3: -y, 4: x - y, 5: x, 0: y}
n -= 2
print(d[n % 6] % mod)


(n, m) = map(int, input().split())
k = int(input())
ls = [n, m, m - n]
mod = 1000000007
if (k - 1) // 3 & 1:
	ls[k % 3 - 1] = -ls[k % 3 - 1]
print(ls[k % 3 - 1] % mod)


mod = 10 ** 9 + 7
(x, y) = [int(x) for x in input().split()]
n = int(input())
n = n % 6
if n == 0:
	print((x - y) % mod)
elif n == 1:
	print(x % mod)
elif n == 2:
	print(y % mod)
elif n == 3:
	print((y - x) % mod)
elif n == 4:
	print(-x % mod)
else:
	print(-y % mod)


(x, y) = map(int, input().split())
n = int(input())
L = [x, y, y - x, -x, -y, x - y]
z = n % 6
print(L[z - 1] % 1000000007)


import os
import sys
from math import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def array():
	return [int(i) for i in input().split()]
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
m = 1000000007
(x, y) = map(int, input().split())
ans = [x, y, y - x, -x, -y, x - y]
n = int(input())
t = (n - 1) % 6
print(ans[t] % m)


(a, b) = [int(i) for i in input().split()]
k = int(input())
m = 1000000007
arr = []
k -= 1
arr.append(a)
arr.append(b)
arr.append(b - a)
u = k % 3
v = k // 3
if v % 2 == 0:
	print(arr[u] % m)
else:
	print(-1 * arr[u] % m)


s = input()
a = s.split(' ')
x = int(a[0])
y = int(a[1])
n = int(input())
j = n % 6
if j == 1:
	ans = x
elif j == 2:
	ans = y
elif j == 3:
	ans = y - x
elif j == 4:
	ans = -x
elif j == 5:
	ans = -y
elif j == 0:
	ans = x - y
print(ans % 1000000007)


MOD = 10 ** 9 + 7
(x, y) = map(int, input().split())
n = int(input())
r = (n - 1) % 6
if r == 0:
	print(x % MOD)
elif r == 1:
	print(y % MOD)
elif r == 2:
	print((y - x) % MOD)
elif r == 3:
	print(-x % MOD)
elif r == 4:
	print(-y % MOD)
elif r == 5:
	print((x - y) % MOD)


def scan(type):
	return list(map(type, input().split()))
(a, b) = scan(int)
(n,) = scan(int)
mod = 10 ** 9 + 7
a %= mod
b %= mod
arr = [a, b]
for i in range(4):
	sz = len(arr)
	arr.append((arr[sz - 1] - arr[sz - 2]) % mod)
n -= 1
print(arr[n % 6])


(x, y) = [int(x) for x in input().split()]
n = int(input())
if n == 1:
	print(x % 1000000007)
elif n == 2:
	print(y % 1000000007)
else:
	a = [x, y]
	for i in range(4):
		a.append(a[-1] - a[-2])
	print(a[n - 1] % 1000000007) if n <= 6 else print(a[n % 6 - 1] % 1000000007)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def fact(x):
	if x == 0:
		return 1
	else:
		return x * fact(x - 1)

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def abs(x):
	return x if x >= 0 else -x

def binary_search(li, val, lb, ub):
	ans = 0
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = 1
			break
	return ans

def sieve_of_eratosthenes(n):
	ans = []
	arr = [1] * (n + 1)
	(arr[0], arr[1], i) = (0, 0, 2)
	while i * i <= n:
		if arr[i] == 1:
			j = i + i
			while j <= n:
				arr[j] = 0
				j += i
		i += 1
	for k in range(n):
		if arr[k] == 1:
			ans.append(k)
	return ans

def nc2(x):
	if x == 1:
		return 0
	else:
		return x * (x - 1) // 2
for _ in range(1):
	(x, y) = map(int, input().split())
	n = int(input())
	li = [x, y]
	for i in range(4):
		li.append(li[-1] - li[-2])
	print(li[n % 6 - 1] % 1000000007)


(x, y) = list(map(int, input().split()))
k = int(input())
m = {1: x, 2: y}
temp = x
for i in range(3, 7):
	temp = m[i - 1] - m[i - 2]
	m[i] = temp
f = k % 6
if f == 0:
	f += 6
	print(m[f] % 1000000007)
else:
	print(m[f] % 1000000007)


(x, y) = map(int, input().split())
n = int(input())
m = 10 ** 9 + 7
val = [x - y, x, y, y - x, -x, -y]
print(val[n % 6] % m)


(x, y) = map(int, input().split())
n = int(input())
m = 1000000007
if n % 6 == 1:
	print(x % m)
elif n % 6 == 2:
	print(y % m)
elif n % 6 == 3:
	print((y % m - x % m) % m)
elif n % 6 == 4:
	print(-x % m)
elif n % 6 == 5:
	print(-y % m)
else:
	print((x % m - y % m) % m)


(x, y) = list(map(int, input().split()))
n = int(input())
seq = [x, y, y - x, -x, -y, x - y]
print(seq[(n - 1) % 6] % 1000000007)


(a, b) = map(int, input().split())
n = int(input())
f = [0] * 13
f[1] = a
f[2] = b
criteria = n - 6 * ((n - 2) // 6) + 1
for i in range(3, criteria):
	f[i] = f[i - 1] - f[i - 2]
print(f[criteria - 1] % (10 ** 9 + 7))


mod = 1000000007
(a, b) = list(map(int, input().split()))
n = int(input())
c = b - a
if n % 3 == 1:
	if (n - 1) / 3 % 2 == 0:
		print((mod + a) % mod)
	else:
		print((mod - a) % mod)
elif n % 3 == 2:
	if (n - 2) / 3 % 2 == 0:
		print((mod + b) % mod)
	else:
		print((mod - b) % mod)
elif (n - 3) / 3 % 2 == 0:
	print((mod + c) % mod)
else:
	print((mod - c) % mod)


(x, y) = map(int, input().split())
n = int(input())
f = [x, y, y - x]
if n <= 3:
	print(f[n - 1] % (10 ** 9 + 7))
elif n % 3 == 0:
	print((-1) ** (n // 3 - 1) * f[n % 3 - 1] % (10 ** 9 + 7))
else:
	print((-1) ** (n // 3) * f[n % 3 - 1] % (10 ** 9 + 7))


import os.path
from math import gcd, floor, ceil
from collections import *
import sys
mod = 1000000007
INF = float('inf')

def st():
	return list(sys.stdin.readline().strip())

def li():
	return list(map(int, sys.stdin.readline().split()))

def mp():
	return map(int, sys.stdin.readline().split())

def inp():
	return int(sys.stdin.readline())

def pr(n):
	return sys.stdout.write(str(n) + '\n')

def prl(n):
	return sys.stdout.write(str(n) + ' ')
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
(x, y) = mp()
n = inp()
cur = [0] * 6
cur[1] = x % mod
cur[2] = y % mod
for i in range(3, 7):
	cur[i % 6] = (cur[i - 1] - cur[i - 2] + mod) % mod
print(cur[n % 6])


def main():
	from sys import stdin, stdout
	MOD = int(1000000000.0) + 7
	(x, y) = map(int, stdin.readline().split())
	n = (int(stdin.readline()) - 1) % 6
	tup = (x, y, y - x, -x, -y, x - y)
	stdout.write(str(tup[n] % MOD))
main()


(x, y) = map(int, input().split())
n = int(input())
i = 2
e = [x, y]
for i in range(2, 6):
	e.append(e[i - 1] - e[i - 2])
print(e[n % 6 - 1] % (10 ** 9 + 7))


(x, y) = map(int, input().split())
n = int(input())
p = [y - x, x, y, y - x]
print((p[n % 3] * (-1) ** ((n - 1) // 3 & 1) + int(1000000000.0 + 7)) % int(1000000000.0 + 7))


x = input().split(' ')
y = int(x[1])
x = int(x[0])
num = int(input())
no = 2
value = list()
value.append(x)
value.append(y)
for i in range(2, 6):
	val = value[i - 1] - value[i - 2]
	value.append(val)
if num < 6:
	val = value[num - 1]
else:
	val = value[(num - 1) % 6]
print(val % (10 ** 9 + 7))


def main():
	(x, y) = list(map(int, input().split()))
	n = int(input())
	lst = [x, y, y - x, -x, -y, x - y]
	print(lst[(n - 1) % 6] % 1000000007)
t = 1
while t != 0:
	main()
	t -= 1


(x, y) = map(int, input().split())
n = int(input())
m = 10 ** 9 + 7
b = [x, y, y - x, -x, -y, x - y]
print(b[n % 6 - 1] % m)


(x, y) = map(int, input().split())
a = [x, y, y - x, -x, -y, x - y]
n = int(input()) - 1
mm = int(1000000000.0 + 7)
print((a[n % len(a)] + mm) % mm)


seq = []
(x, y) = map(int, input().split())
val = int(input())
seq.append(9999)
seq.append(x)
seq.append(y)
seq.append(y - x)
seq.append(-1 * seq[1])
seq.append(-1 * seq[2])
seq.append(-1 * seq[3])
tmp = val % 6
if tmp == 0:
	print(seq[6] % 1000000007)
else:
	print(seq[tmp] % 1000000007)


mod = int(1000000000.0 + 7)
(x, y) = map(int, input().strip().split())
n = int(input().strip())
arr = [x, y, y - x, -x, -y, x - y]
print(arr[(n - 1) % 6] % mod)


from sys import stdin, stdout
from collections import Counter

def ai():
	return list(map(int, stdin.readline().split()))

def ei():
	return map(int, stdin.readline().split())

def ip():
	return int(stdin.readline().strip())

def op(ans):
	return stdout.write(str(ans) + '\n')
from math import ceil
(x, y) = ei()
n = ip()
f = [x, y, y - x, -x, -y, x - y]
ans = n % 6
print(f[ans - 1] % 1000000007)


(x, y) = map(int, input().split())
n = int(input())
a = [x, y, y - x, -x, -y, x - y]
print(a[(n - 1) % 6] % 1000000007)


from sys import stdin
import math
(x, y) = map(int, stdin.readline().rstrip().split(' '))
n = int(stdin.readline())
cycle = [x, y]
for _ in range(100):
	cycle.append(cycle[-1] - cycle[-2])
print(cycle[(n - 1) % len(cycle)] % 1000000007)


(x, y) = [int(x) for x in input().split()]
n = int(input())
ans = [x, y, y - x, -x, -y, x - y]
print(ans[(n - 1) % 6] % 1000000007)


import array
l = list(map(int, input().split()))
x = l[0]
y = l[1]
n = int(input())
f = array.array('i', [-99, x, y, y - x])
if n <= 3:
	if n == 1:
		print(f[1] % 1000000007)
	elif n == 2:
		print(f[2] % 1000000007)
	else:
		print(f[3] % 1000000007)
elif n % 3 == 0:
	if n % 6 == 0:
		temp = 0 - f[3]
		print(temp % 1000000007)
	else:
		print(f[3] % 1000000007)
elif (n + 1) % 3 == 0:
	if (n + 1) % 6 == 0:
		f[3] = 0 - f[3]
		f[1] = 0 - f[1]
		temp = f[3] + f[1]
		print(temp % 1000000007)
	else:
		f[3] = f[3]
		f[1] = f[1]
		temp = f[3] + f[1]
		print(temp % 1000000007)
elif (n + 2) % 3 == 0:
	if (n + 2) % 6 == 0:
		f[3] = 0 - f[3]
		f[2] = 0 - f[2]
		temp = -f[3] + f[2]
		print(temp % 1000000007)
	else:
		f[3] = f[3]
		f[2] = f[2]
		temp = -f[3] + f[2]
		print(temp % 1000000007)


(x, y) = list(map(int, input().split()))
n = int(input())
r = [x, y, y - x, -x, -y, x - y]
print(r[(n - 1) % len(r)] % 1000000007)


(x, y) = map(int, input().split())
n = int(input())
previous = x
next = y
rem = n % 3
qut = n // 3
arr = []
for i in range(2, 5):
	answer = next - previous
	arr.append(answer)
	previous = next
	next = answer
print(arr[rem] * (-1) ** (qut + 1) % (10 ** 9 + 7))


(x, y) = map(int, input().split())
n = int(input())
m = 1000000007
x = x % m
y = y % m
check = {1: x, 2: y, 3: y - x, 4: -1 * x, 5: -1 * y, 0: x - y}
ans = check[n % 6]
print(ans % m)


(x, y) = map(int, input().split())
n = int(input()) - 1
t = (x, y, y - x)[n % 3]
print((-t if n // 3 & 1 else t) % 1000000007)


s = input().split()
(x, y) = (int(s[0]), int(s[1]))
n = int(input())
if n % 3 == 0:
	if n // 3 % 2 == 0:
		print(-1 * (y % 1000000007 - x % 1000000007) % 1000000007)
	else:
		print((y % 1000000007 - x % 1000000007) % 1000000007)
elif n % 3 == 1:
	if n // 3 % 2 == 0:
		print(x % 1000000007)
	else:
		print(-1 * x % 1000000007)
elif n // 3 % 2 == 0:
	print(y % 1000000007)
else:
	print(-1 * y % 1000000007)


(x, y) = map(int, input().split())
z = int(input())
li = [0] * 6
li[0] = x - y
li[1] = x
li[2] = y
for i in range(3, 6):
	li[i] = li[i - 1] - li[i - 2]
print(li[z % 6] % (10 ** 9 + 7))


(x, y) = map(int, input().split())
n = int(input())
estadio = n % 6
if estadio == 1:
	fn = x
elif estadio == 2:
	fn = y
elif estadio == 3:
	fn = y - x
elif estadio == 4:
	fn = -x
elif estadio == 5:
	fn = -y
else:
	fn = x - y
resultado = fn % (10 ** 9 + 7)
print(int(resultado))


(x, y) = map(int, input().split())
n = int(input())
d = [[1, 0], [0, 1], [-1, 1], [-1, 0], [0, -1], [1, -1]]
k = (n - 1) % 6
print((d[k][0] * x + d[k][1] * y) % (10 ** 9 + 7))


(a, b) = map(int, input().split())
n = int(input())
ans = [a - b, a, b, b - a, -a, -b]
print(ans[n % 6] % (10 ** 9 + 7))


from math import ceil
(x, y) = map(int, input().split())
n = int(input())
z = y - x
m = 10 ** 9 + 7
if n == 1:
	print(x % m)
	exit(0)
if n == 2:
	print(y % m)
	exit(0)
if ceil(n / 3) % 2 == 0:
	if n % 3 == 0:
		print(-1 * z % m)
	elif n % 3 == 1:
		print(-1 * x % m)
	else:
		print(-1 * y % m)
elif n % 3 == 0:
	print(z % m)
elif n % 3 == 1:
	print(x % m)
else:
	print(y % m)


(x, y) = map(int, input().split())
n = int(input())
f = [x, y]
for i in range(2, 6):
	f.append(f[i - 1] - f[i - 2])
n1 = n % 6
if n1 == 0:
	fn = f[5]
else:
	fn = f[n1 - 1]
print(fn % 1000000007)


(a, b) = [int(i) for i in input().split()]
c = b - a
if a < 0:
	a = 1000000007 + a
if b < 0:
	b = 1000000007 + b
if c < 0:
	c = 1000000007 + c
n = int(input())
x = n % 6
if x == 0:
	p = -c % 1000000007
elif x == 1:
	p = a % 1000000007
elif x == 2:
	p = b % 1000000007
elif x == 3:
	p = c % 1000000007
elif x == 4:
	p = -a % 1000000007
else:
	p = -b % 1000000007
print(p)


a = 10 ** 9 + 7
(x, y) = map(int, input().split())
n = int(input())
z = y - x
c = n // 3
n = n % 3
c = c % 2
if abs(n) == 1:
	print(*[x % a if c == 0 else -x % a])
elif abs(n) == 2:
	print(*[y % a if c == 0 else -y % a])
elif abs(n) == 0:
	print(*[z % a if c == 1 else -z % a])


a = [0, 0, 0]
(a[0], a[1]) = map(int, input().split())
n = int(input()) - 1
N = 1000000007
a[2] = a[1] - a[0]
if n // 3 % 2:
	print(-a[n % 3] % N)
else:
	print(a[n % 3] % N)


import math
import itertools
import collections

def getdict(n):
	d = {}
	if type(n) is list:
		for i in n:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
	else:
		for i in range(n):
			t = ii()
			if t in d:
				d[t] += 1
			else:
				d[t] = 1
	return d

def cdiv(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def wr(arr):
	return ' '.join(map(str, arr))

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def revn(n):
	m = 0
	while n > 0:
		m = m * 10 + n % 10
		n = n // 10
	return m
MAX = 10 ** 9 + 7
(x, y) = mi()
n = ii()
d = [x - y, x, y, y - x, -x, -y]
print(d[n % 6] % MAX)


(n, m) = [int(i) for i in input().split()]
a = int(input())
l = [n, m, m - n]
l = l + [-n, -m, n - m]
print(l[a % 6 - 1] % (10 ** 9 + 7))


(x, y) = map(int, input().split())
n = int(input())
arr = [x - y, x, y, y - x, -x, -y]
x = arr[n % 6]
print(x % 1000000007)


(n, m) = map(int, input().split())
k = int(input())
l = m - n
s = [n, m, l]
z = (k - 1) // 3
if z % 2 == 0:
	print(s[k % 3 - 1] % 1000000007)
else:
	print(-1 * s[k % 3 - 1] % 1000000007)


(x, y) = map(int, input().split())
n = int(input())
n = n % 6
ans = 0
if n == 0:
	ans = -y + x
elif n == 1:
	ans = x
elif n == 2:
	ans = y
elif n == 3:
	ans = y - x
elif n == 4:
	ans = -x
else:
	ans = -y
print(ans % 1000000007)


(x, y) = map(int, input().split())
n = int(input())
result = n % 6
if result == 1:
	print(x % 1000000007)
elif result == 2:
	print(y % 1000000007)
elif result == 3:
	print((y - x) % 1000000007)
elif result == 4:
	print(-x % 1000000007)
elif result == 5:
	print(-y % 1000000007)
elif result == 0:
	print((x - y) % 1000000007)


Fn = list(map(int, input().split()))
N = int(input())
for i in range(4):
	Fn.append((Fn[-1] - Fn[-2]) % (10 ** 9 + 7))
print(Fn[(N - 1) % 6] % (10 ** 9 + 7))


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
readint = lambda : int(sys.stdin.readline().rstrip('\r\n'))
readints = lambda : map(int, sys.stdin.readline().rstrip('\r\n').split())
readstr = lambda : sys.stdin.readline().rstrip('\r\n')
readstrs = lambda : map(str, sys.stdin.readline().rstrip('\r\n').split())
readarri = lambda : [int(_) for _ in sys.stdin.readline().rstrip('\r\n').split()]
readarrs = lambda : [str(_) for _ in sys.stdin.readline().rstrip('\r\n').split()]
mod = int(1000000000.0) + 7

def add(val1, val2):
	return (val1 % mod + val2 % mod) % mod

def mult(val1, val2):
	return val1 % mod * val2 % mod % mod

def solve():
	(x, y) = readints()
	n = readint()
	seq = [x % mod, y % mod, add(-x, y), -x % mod, -y % mod, add(x, -y)]
	print(seq[n % 6 - 1])

def main():
	t = 1
	for _ in range(t):
		solve()
main()


try:
	(x, y) = map(int, input().split())
	n = int(input())
	w = [x, y, y - x, -x, -y, x - y]
	print(w[n % 6 - 1] % (10 ** 9 + 7))
except:
	pass


f = [0] * 7
(f[1], f[2]) = [int(x) for x in input().split()]
f[3] = f[2] - f[1]
f[4] = -f[1]
f[5] = -f[2]
f[6] = -f[3]
n = int(input())
t = n % 6
if t == 0:
	t = 6
print(f[t] % 1000000007)


(x, y) = map(int, input().split())
n = int(input()) - 1
ans = 0
arr = [0] * 6
arr[0] = x
arr[1] = y
for i in range(2, 6):
	arr[i] = arr[i - 1] - arr[i - 2]
print((1000000007 + arr[n % 6]) % 1000000007)


(x, y) = list(map(int, input().split()))
n = int(input())
s = n % 6
res = None
if s == 1:
	res = x
elif s == 2:
	res = y
elif s == 3:
	res = y - x
elif s == 4:
	res = -x
elif s == 5:
	res = -y
elif s == 0:
	res = -y + x
print(res % 1000000007)


mod = int(1000000000.0) + 7
(x, y) = map(int, input().split())
n = int(input())
l = [x, y, y - x, -x, -y, x - y]
print(l[n % 6 - 1] % mod)


(f1, f2) = map(int, input().split())
n = int(input())
resp = []
fn1 = f1
fn2 = f2
fn = fn2 - fn1
resp.append(fn % 1000000007)
aux = 0
while aux < 5:
	fn1 = fn2
	fn2 = fn
	fn = fn2 - fn1
	resp.append(fn % 1000000007)
	aux += 1
n -= 3
print(resp[n % 6])


(x, y) = map(int, input().split())
n = int(input())
if n % 6 == 1:
	print(x % int(1000000000.0 + 7))
elif n % 6 == 2:
	print(y % int(1000000000.0 + 7))
elif n % 6 == 3:
	print((y - x) % int(1000000000.0 + 7))
elif n % 6 == 4:
	print(-x % int(1000000000.0 + 7))
elif n % 6 == 5:
	print(-y % int(1000000000.0 + 7))
elif n % 6 == 0:
	print((x - y) % int(1000000000.0 + 7))


(x, y) = map(int, input().split())
n = int(input())
z = y - x
if n == 1:
	print(x % 1000000007)
elif n == 2:
	print(y % 1000000007)
elif n == 3:
	print(z % 1000000007)
else:
	mod = n % 3
	if mod == 0:
		if n // 3 % 2 == 0:
			print(-1 * z % 1000000007)
		else:
			print(z % 1000000007)
	elif mod == 1:
		if n // 3 % 2 == 1:
			print(-1 * x % 1000000007)
		else:
			print(x % 1000000007)
	elif n // 3 % 2 == 1:
		print(-1 * y % 1000000007)
	else:
		print(y % 1000000007)


mod = 10 ** 9 + 7
(x, y) = list(map(int, input().split()))
n = int(input())
v = n % 6
d = {0: x - y, 1: x, 2: y, 3: y - x, 4: -x, 5: -y}
print(d[v] % mod)


from sys import stdin, stdout
from math import gcd, ceil, sqrt
from collections import Counter
from bisect import bisect_left, bisect_right
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
mod = 1000000007
arr = iia()
n = ii1() - 1
for i in range(4):
	arr.append(arr[-1] - arr[-2])
print(arr[n % 6] % mod)


(f1, f2) = map(int, input().split())
n = int(input())
l = [f1, f2, f2 - f1, -f1, -f2, f1 - f2]
print(l[(n - 1) % 6] % 1000000007)


a = [int(x) for x in input().split()]
n = int(input())
a.append(a[1] - a[0])
if (n - 1) % 6 > 2:
	print(-a[(n - 1) % 3] % 1000000007)
else:
	print(a[(n - 1) % 3] % 1000000007)


from sys import stdin, stdout
import math
import bisect
input = stdin.readline

def print(x='', y='', end='\n'):
	if y == '':
		stdout.write(str(x) + end)
	else:
		stdout.write(str(x) + ' ' + str(y) + end)

def solve():
	(x, y) = map(int, input().split())
	n = int(input())
	l = [x, y, y - x, -x, -y, x - y]
	print(l[n % 6 - 1] % (10 ** 9 + 7))
tt = 1
for __ in range(tt):
	solve()


from math import ceil
MOD_NUM = int(1000000000.0 + 7)
(x, y) = map(int, input().split())
n = int(input())
ans = -1
if n % 3 == 1:
	ans = x
elif n % 3 == 2:
	ans = y
elif n % 3 == 0:
	ans = y - x
print(ans % MOD_NUM if ceil(n / 3) & 1 else -ans % MOD_NUM)


def main():
	(x, y) = map(int, input().split())
	n = int(input())
	z = [x, y, y - x, -x, -y, x - y]
	print(z[n % 6 - 1] % (10 ** 9 + 7))
main()


(n, m) = map(int, input().split())
s = m - n
k = int(input())
d = k % 6
if d == 1:
	print(n % 1000000007)
elif d == 2:
	print(m % 1000000007)
elif d == 3:
	print(s % 1000000007)
elif d == 4:
	print(n * -1 % 1000000007)
elif d == 5:
	print(m * -1 % 1000000007)
else:
	print(s * -1 % 1000000007)


(n, m) = map(int, input().split())
l = int(input())
k = (-1) ** ((l - 1) // 3)
l %= 3
if l == 1:
	print(n * k % (10 ** 9 + 7))
elif l == 2:
	print(m * k % (10 ** 9 + 7))
elif l == 0:
	print((m - n) * k % (10 ** 9 + 7))


(x, y) = [int(no) for no in input().split()]
n = int(input())
f = [x, y]
for i in range(4):
	f.append((f[-1] - f[-2]) % 1000000007)
ans = f[(n - 1) % 6] % 1000000007
print(ans)


(x, y) = [int(i) for i in input().split()]
n = int(input())
if n % 6 == 1:
	print(x % 1000000007)
elif n % 6 == 2:
	print(y % 1000000007)
elif n % 6 == 3:
	print((y - x) % 1000000007)
elif n % 6 == 4:
	print(-x % 1000000007)
elif n % 6 == 5:
	print(-y % 1000000007)
elif n % 6 == 0:
	print((x - y) % 1000000007)


string = input()
numbers = string.split()
(a, b, n) = (int(numbers[0]), int(numbers[1]), int(input()))
numbers = [a, b]
for x in range(2, 6):
	numbers.append(numbers[x - 1] - numbers[x - 2])
print(numbers[(n - 1) % 6] % (10 ** 9 + 7))


(x, y) = list(map(int, input().split()))
n = int(input())
mod = 1000000007
arr = []
arr.append(x)
arr.append(y)
arr.append(y - x)
arr.append(-x)
arr.append(-y)
arr.append(x - y)
a = n % 6
print(arr[a - 1] % mod)


mod = 10 ** 9 + 7
(x, y) = list(map(int, input().split()))
n = int(input())
a = [0] * 8
a[0] = x
a[1] = y
for i in range(2, 8):
	a[i] = a[i - 1] - a[i - 2]
print(a[(n - 1) % 6] % mod)


import sys
input = sys.stdin.read()
data = list(map(int, input.split()))
data[2] -= 1
v = [0] * 6
(v[0], v[1]) = (data[0], data[1])
for i in range(1, 5):
	v[i + 1] = v[i] - v[i - 1]
print(int(v[data[2] % 6] % (1000000000.0 + 7)))


(x, y) = map(int, input().split())
n = int(input())
temp = y - x
a = []
a.append(x)
a.append(y)
a.append(temp)
b = []
for i in a:
	if i < 0:
		b.append(abs(i))
	else:
		b.append(-1 * i)
a = a + b
v = n % 6
print(a[v - 1] % (1000000000 + 7))


mod = 1000000007
(x, y) = map(int, input().split())
n = int(input())
A = [x - y, x, y, y - x, -x, -y]
n %= 6
print((A[n] % mod + mod) % mod)


from sys import stdin
MOD = 1000000007
(x, y) = [int(x) for x in stdin.readline().strip().split()]
n = int(stdin.readline().strip())
ans = [x, y, y - x, -x, -y, x - y]
print(ans[(n - 1) % 6] % MOD)


from sys import stdin

def anfel():
	a = stdin.readline().split()
	b = stdin.readline().split()
	c = int(a[0])
	d = int(a[1])
	e = int(b[0])
	f = e % 6
	g = 1000000007
	h = 0
	if f == 0:
		h = (c - d) % g
	if f == 1:
		h = c % g
	if f == 2:
		h = d % g
	if f == 3:
		h = (d - c) % g
	if f == 4:
		h = -c % g
	if f == 5:
		h = -d % g
	print(h)
anfel()


(x, y) = map(int, input().split())
n = int(input())
c = 1000000007
dp = [x, y, y - x, -x, -y, -y + x]
print(dp[(n - 1) % 6] % c)


import sys
sys.setrecursionlimit(10000)
(x, y) = [int(x) for x in sys.stdin.readline().strip().split()]
n = int(sys.stdin.readline())
m = 10 ** 9 + 7
d = {0: x, 1: y, 2: y - x, 3: -x, 4: -y, 5: x - y}
print(d[(n - 1) % 6] % m)


(x, y) = map(int, input().split())
n = int(input())
m = 1000000007
func = [x, y, y - x, -x, -y, x - y]
print(func[n % 6 - 1] % m)


mod = 1000000007

def mult(a, b):
	res = [[0, 0], [0, 0]]
	for i in range(2):
		for j in range(2):
			for k in range(2):
				res[i][j] += a[i][k] * b[k][j]
			res[i][j] %= mod
	return res
(x, y) = [int(x) for x in input().split()]
n = int(input()) - 2
if n == -1:
	print(x % mod)
	exit(0)
m = [[1, -1], [1, 0]]
res = [[1, 0], [0, 1]]
while n:
	if n & 1:
		res = mult(res, m)
	m = mult(m, m)
	n >>= 1
print((res[0][0] * y + res[0][1] * x) % mod)


import math, sys
from collections import defaultdict, Counter, deque
INF = float('inf')
MOD = 1000000007

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def isPrime(n):
	if n <= 1:
		return False
	i = 2
	while i ** 2 <= n:
		if n % i == 0:
			return False
		i += 1
	return True

def primeFactors(n):
	factors = []
	i = 2
	while i ** 2 <= n:
		while n % i == 0:
			factors.append(i)
			n //= i
		i += 1
	if n > 1:
		factors.append(n)
	return factors

def vars():
	return map(int, input().split())

def array():
	return list(map(int, input().split()))

def main():
	(x, y) = vars()
	n = int(input())
	(x, y) = (x % MOD, y % MOD)
	(a, b) = (x, y)
	arr = [x, y]
	x = (y - x) % MOD
	y = (x - y) % MOD
	while (x, y) != (a, b):
		arr.append(x)
		arr.append(y)
		x = (y - x) % MOD
		y = (x - y) % MOD
	print(arr[(n - 1) % len(arr)])
t = 1
for _ in range(t):
	main()


l = list(map(int, input().split()))
n = int(input())
l.append(l[1] - l[0])
l.append(-l[0])
l.append(-l[1])
l.append(-l[2])
print(l[n % 6 - 1] % (10 ** 9 + 7))


(x, y) = map(int, input().split())
print([x, y, y - x, -x, -y, x - y][int(input()) % 6 - 1] % 1000000007)


import math
a = []
(x, y) = map(int, input().split())
a.append(x)
a.append(y)
a.append(y - x)
k = int(input())
if k <= 3:
	print(a[k - 1] % 1000000007)
elif math.ceil(k / 3) % 2 == 0:
	print(-1 * a[(k - 1) % 3] % 1000000007)
else:
	print(a[(k - 1) % 3] % 1000000007)


(x, y) = map(int, input().split())
n = int(input())
if x == y == 0:
	print(0)
else:
	mod = 1000000000.0 + 7
	f = [0] * 6
	f[0] = x
	f[1] = y
	for i in range(2, 6):
		f[i] = int((f[i - 1] - f[i - 2]) % mod)
	print(int(f[(n - 1) % 6] % mod))


from os import path
import sys, time
mod = int(1000000000.0 + 7)
from math import ceil, floor, gcd, log, log2, factorial, sqrt
from collections import defaultdict, Counter, OrderedDict, deque
from itertools import combinations, permutations
from bisect import *
from functools import reduce
from operator import mul
maxx = float('inf')
I = lambda : int(sys.stdin.buffer.readline())
tup = lambda : map(int, sys.stdin.buffer.readline().split())
lint = lambda : [int(x) for x in sys.stdin.buffer.readline().split()]
S = lambda : sys.stdin.readline().strip('\n')
grid = lambda r: [lint() for i in range(r)]
stpr = lambda x: sys.stdout.write(f'{x}' + '\n')
star = lambda x: print(' '.join(map(str, x)))
localsys = 0
start_time = time.time()

def ceill(n, x):
	return (n + x - 1) // x
nCr = lambda n, r: reduce(mul, range(n - r + 1, n + 1), 1) // factorial(r)

def solve():
	(x, y) = tup()
	n = I()
	a = [x, y, y - x, -x, -y, x - y]
	print(a[n % 6 - 1] % mod)

def run():
	if path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
run()
solve()
if localsys:
	print('\n\nTime Elased :', time.time() - start_time, 'seconds')


mod = 10 ** 9 + 7
(x, y) = map(int, input().split())
a = [x, y, y - x, -x, -y, x - y]
n = int(input())
if n % 6 == 0:
	print(a[5] % mod)
else:
	print(a[n % 6 - 1] % mod)


z = list(map(int, input().split()))
for i in range(2):
	z[i] %= 1000000007
z.append((z[-1] - z[-2]) % 1000000007)
for _ in range(3):
	z.append(-z[_] % 1000000007)
print(z[(int(input()) - 1) % 6] % 1000000007)


def main():
	(x, y) = input().split()
	n = int(input())
	f = [int(x), int(y)]
	while len(f) < 6:
		f.append(f[-1] - f[-2])
	print(f[n % 6 - 1] % 1000000007)
main()


(x, y) = map(int, input().split())
n = int(input())
arr = [x, y]
for i in range(2, 6):
	arr.append(arr[i - 1] - arr[i - 2])
if n % 6 == 0:
	print(arr[-1] % 1000000007)
else:
	print(arr[n % 6 - 1] % 1000000007)


(x, y) = map(int, input().split())
n = int(input())
a = [0] * 7
a[0] = x
const = 1000000007
if n == 1:
	print(x % const)
elif n == 2:
	print(y % const)
else:
	a[1] = y
	a[2] = a[1] - a[0]
	for i in range(2, 6):
		a[i + 1] = a[i] - a[i - 1]
	if n > 6:
		print(a[(n - 1) % 6] % const)
	else:
		print(a[n - 1] % const)


(x, y) = map(int, input().split())
m = 10 ** 9 + 7
n = int(input())
arr = [(x + m) % m, (y + m) % m]
for i in range(4):
	arr.append((arr[-1] - arr[-2] + m) % m)
print(arr[(n - 1) % 6])


def solve():
	(x, y) = map(int, input().split())
	n = int(input()) % 6
	if n == 1:
		return (x + 1000000007) % 1000000007
	if n == 2:
		return (y + 1000000007) % 1000000007
	if n == 3:
		return (y - x + 1000000007) % 1000000007
	if n == 4:
		return (-x + 1000000007) % 1000000007
	if n == 5:
		return (-y + 1000000007) % 1000000007
	return (-y + x + 1000000007) % 1000000007
print(solve())


import math
(x, y) = map(int, input().split())
n = int(input())
MOD = 10 ** 9 + 7
d = [x, y, y - x]
t = math.ceil(n / 3)
r = n % 3
print((MOD - d[r - 1]) % MOD) if t % 2 == 0 else print(d[r - 1] % MOD)


(x, y) = map(int, input().split())
n = int(input())
hop = [x, y, y - x, -x, -y, x - y]
n %= 6
print(hop[n - 1] % (10 ** 9 + 7))


(x, y) = [int(i) for i in input().split()]
n = int(input())
a = [x, y, y - x, -x, -y, x - y]
print(a[n % 6 - 1] % (10 ** 9 + 7))


(x, y) = map(int, input().split())
n = int(input()) % 6
f = [x - y, x, y, y - x, -x, -y]
print(f[n] % (10 ** 9 + 7))


(x, y) = input().split()
x = int(x)
y = int(y)
z = y - x
baseElements = []
baseElements.append(x)
baseElements.append(y)
baseElements.append(z)
n = int(input())
group = n // 3
if n % 3 == 0:
	group -= 1
if group % 2 == 0:
	result = baseElements[n % 3 - 1]
else:
	result = 0 - baseElements[n % 3 - 1]
result %= 1000000007
print(result)


(x, y) = map(int, input().split())
a = int(input())
k = [x, y, y - x, -x, -y, x - y]
i = a % 6 - 1
print(k[i] % (10 ** 9 + 7))


arr = [int(x) for x in input().split()]
mod = int(1000000000.0 + 7)
a = arr[0]
b = arr[1]
c = int(input())
c = c % 6
if c == 1:
	print(a % mod)
if c == 2:
	print(b % mod)
if c == 3:
	print((b - a) % mod)
if c == 4:
	print(-a % mod)
if c == 5:
	print(-b % mod)
if c == 0:
	print((a - b) % mod)


(x, y) = [int(x) for x in input().split()]
liss = [x, y, y - x, -x, -y, x - y]
n = int(input())
t = liss[(n - 1) % 6]
print(t % 1000000007)


(x, y) = map(int, input().split())
n = int(input())
ls = [x, y, y - x, -x, -y, x - y]
val = (n - 1) % 6
print(ls[val] % 1000000007)


(x, y) = map(int, input().split())
n = int(input())
n = n - 2
n = n % 6
if n == 1:
	p = x
else:
	p = y
for i in range(n):
	p = y - x
	x = y
	y = p
if p >= 0:
	print(p % 1000000007)
else:
	print((1000000007 - abs(p) % 1000000007) % 1000000007)


import os, sys, time, collections, math, pprint, itertools as it, operator as op, bisect as bs, functools as fn
(maxx, localsys, mod) = (1 << 60, 0, int(1000000000.0 + 7))
nCr = lambda n, r: reduce(mul, range(n - r + 1, n + 1), 1) // factorial(r)
ceil = lambda n, x: (n + x - 1) // x
(osi, oso) = ('/home/priyanshu/Documents/cp/input.txt', '/home/priyanshu/Documents/cp/output.txt')
if os.path.exists(osi):
	sys.stdin = open(osi, 'r')
	sys.stdout = open(oso, 'w')
input = sys.stdin.readline
from functools import reduce

def maps():
	return map(int, input().split())

def Kth_beautiful_string():
	for _ in range(int(input())):
		(n, k) = maps()
		arr = ['a'] * n
		for i in range(n - 1, -1, -1):
			if n - i - 1 >= k:
				arr[i] = arr[i + (n - i - 1) - (k - 1)] = 'b'
				print(''.join(arr))
				break
			k -= n - i - 1
(n, m) = maps()
k = [*maps()][0]
a = [n, m, m - n, -n, -m, n - m]
print(a[(k - 1) % 6] % 1000000007)


(x, y) = map(int, input().split())
n = int(input())
z = y - x
if n % 3 == 1:
	print((-1) ** (n // 3) * x % (10 ** 9 + 7))
elif n % 3 == 2:
	print((-1) ** (n // 3) * y % (10 ** 9 + 7))
elif n % 3 == 0:
	print((-1) ** (n // 3 + 1) * z % (10 ** 9 + 7))


(x, y) = map(int, input().split())
n = int(input())
a = [0] * 6
a[0] = x
a[1] = y
for i in range(2, 6):
	a[i] = a[i - 1] - a[i - 2]
if n <= 6:
	print(a[n - 1] % (10 ** 9 + 7))
else:
	x = (n - 1) % 6
	print(a[x] % (10 ** 9 + 7))


(a, b) = map(int, input().split())
lis = [a, b, b - a, -a, -b, a - b]
inf = 1000000007
n = int(input())
n = n - 1
x = lis[n % 6]
if x < 0:
	x = x + inf
print(x % inf)


(x, y) = [int(i) for i in input().split()]
n = int(input())
a = [x, y, y - x, -x, -y, -y + x]
z = a[(n - 1) % 6]
print(z % 1000000007)


import math
M = 10 ** 9 + 7
(x, y) = map(int, input().split())
n = int(input())
if n % 3 == 0:
	a = y - x
elif n % 3 == 2:
	a = y
else:
	a = x
x = math.ceil(n / 3)
if x & 1 ^ 1:
	a *= -1
a %= M
print(a)


(a, b) = map(int, input().split())
x = int(input())
if x % 6 == 3:
	print((b - a) % 1000000007)
elif x % 6 == 0:
	print((a - b) % 1000000007)
elif x % 6 == 1:
	print(a % 1000000007)
elif x % 6 == 2:
	print(b % 1000000007)
elif x % 6 == 4:
	print(-a % 1000000007)
elif x % 6 == 5:
	print(-b % 1000000007)


(x, y) = [int(i) for i in input().split()]
n = int(input())
a = [x, y]
for i in range(2, 6):
	a.append(a[i - 1] - a[i - 2])

def sequence(k):
	if k <= 6:
		return a[k - 1]
	else:
		i = k % 6
		return a[i - 1]
print(sequence(n) % 1000000007)


line = input()
(x, y) = map(int, line.strip().split())
n = int(input().strip())
n -= 1
result_table = [x, y, y - x, -x, -y, -y + x]
print(result_table[n % 6] % (10 ** 9 + 7))


modulo = 10 ** 9 + 7

def by_modulo(number):
	return (number + 2 * modulo) % modulo

def rec(f1, f2, n):
	a = [f1, f2]
	for i in range(2, (n - 1) % 6 + 1):
		a.append(a[i - 1] - a[i - 2])
	return by_modulo(a[(n - 1) % 6])
(x1, x2) = [int(j) for j in input().split()]
m = int(input())
print(rec(x1, x2, m))


import sys
import math
stdin = sys.stdin
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))
ns = lambda : stdin.readline().rstrip()
(x, y) = map(int, stdin.readline().split())
n = ni()
n -= 1
a = [x, y]
for _ in range(4):
	a.append(a[-1] - a[-2])
print(a[n % len(a)] % (10 ** 9 + 7))


import sys
import math
import collections
import operator as op
from collections import deque
from math import gcd, inf, sqrt, pi, cos, sin, ceil, log2
from bisect import bisect_right, bisect_left
from functools import reduce
from sys import stdin, stdout, setrecursionlimit

def factorial(n):
	if n == 0:
		return 1
	return n * factorial(n - 1)

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def prime_factors(n):
	i = 2
	factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return list(factors)
MOD = 1000000007
PMOD = 998244353
T = 1
for _ in range(T):
	(x, y) = list(map(int, stdin.readline().rstrip().split()))
	n = int(stdin.readline())
	z = y - x
	if n % 3 == 0:
		if ceil(n / 3) % 2 == 0:
			print(-z % MOD)
		else:
			print(z % MOD)
	elif n % 3 == 1:
		if ceil(n / 3) % 2 == 0:
			print(-x % MOD)
		else:
			print(x % MOD)
	elif ceil(n / 3) % 2 == 0:
		print(-y % MOD)
	else:
		print(y % MOD)


(x, y) = map(int, input().split())
n = int(input())
rem = n % 6
m = 1000000007
f = [x - y, x, y, y - x, -x, -y, x - y]
print(f[rem] % m)


import sys

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def rinput():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))
(x, y) = rinput()
n = iinput()
a = [x, y, y - x, -x, -y, x - y]
s = n % 6
if s == 0:
	print(a[-1] % 1000000007)
else:
	print(a[s - 1] % 1000000007)


(x, y) = map(int, input().strip().split())
n = int(input())
mod = 1000000007
milista = [x, y, mod + y - x, mod - x, mod - y, mod + x - y]
print(milista[(n - 1) % 6] % mod)


(x, y) = map(int, input().split())
n = int(input())
MOD = 10 ** 9 + 7
l = [x, y, y - x, -x, -y, x - y]
n = n % 6
if n == 0:
	n = 5
else:
	n = n - 1
print((l[n] + MOD) % MOD)


(x, y) = input().split(' ')
n = int(input())
x = int(x)
y = int(y)
nm6 = n % 6
if nm6 == 1:
	f = lambda x, y: x
if nm6 == 2:
	f = lambda x, y: y
if nm6 == 3:
	f = lambda x, y: y - x
if nm6 == 4:
	f = lambda x, y: -x
if nm6 == 5:
	f = lambda x, y: -y
if nm6 == 0:
	f = lambda x, y: x - y
print(f(x, y) % 1000000007)


(x, y) = map(int, input().split())
n = int(input())
f = {1: x, 2: y, 3: y - x, 4: -1 * x, 5: -1 * y, 0: x - y}
mod = 1000000007
print(f[n % 6] % mod)


nums = [int(i) for i in input().split()]
n = int(input())
for i in range(1, 5):
	nums.append(nums[i] - nums[i - 1])
n = (n - 1) % 6
print(nums[n] % 1000000007)


(x, y) = list(map(int, input().split()))
n = int(input())
l = [x - y, x, y, y - x, -x, -y]
print(l[n % 6] % 1000000007)


(x, y) = map(int, input().split())
n = int(input()) % 6 - 1
mat = [x, y, y - x, -x, -y, -(y - x)]
modn = 1000000007
print(mat[n] % modn)


def jzzhu_seq(n):
	n = n % 6
	if n == 0:
		return x % M
	elif n == 1:
		return y % M
	elif n == 2:
		return (y - x) % M
	elif n == 3:
		return -x % M
	elif n == 4:
		return -y % M
	elif n == 5:
		return (x - y) % M
(x, y) = list(map(int, input().strip().split()))
n = int(input())
M = 10 ** 9 + 7
print(jzzhu_seq(n - 1))


(x, y) = [int(z) for z in input().split()]
n = int(input())
mass = []
mass.append(x)
mass.append(y)
mass.append(-(x - y))
mass.append(-x)
mass.append(-y)
mass.append(x - y)
if n % 6 == 1:
	print(x % 1000000007)
elif n % 6 == 2:
	print(y % 1000000007)
elif n % 6 == 3:
	print(-(x - y) % 1000000007)
elif n % 6 == 4:
	print(-x % 1000000007)
elif n % 6 == 5:
	print(-y % 1000000007)
else:
	print((x - y) % 1000000007)


sa = input().split(' ')
x = int(sa[0])
y = int(sa[1])
n = int(input())

def generate(x, y, n):
	sa = [x, y, y - x, -x, -y, x - y]
	return sa[(n % 6 - 1) % 6]
print(generate(x, y, n) % (10 ** 9 + 7))


import sys
import math
import collections

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()
for t in range(1):
	(x, y) = get_ints()
	n = int(input())
	mod = 10 ** 9 + 7
	arr = [x % mod, y % mod]
	while len(arr) < 6:
		val = arr[-1] - arr[-2]
		arr.append(val % mod)
	rem = n % 6
	print(arr[rem - 1])


MOD = 1000000007
(x, y) = input().split()
(x, y) = (int(x), int(y))
n = int(input())
if n % 6 == 6 or n % 6 == 0:
	print((-y + x) % MOD)
elif n % 6 == 5:
	print(-y % MOD)
elif n % 6 == 4:
	print(-x % MOD)
elif n % 6 == 3:
	print((y - x) % MOD)
elif n % 6 == 2:
	print(y % MOD)
else:
	print(x % MOD)


(x, y) = map(int, input().split())
n = int(input())
mod = 1000000007
arr = [x, y]
for i in range(4):
	arr.append(arr[i + 1] - arr[i])
rem = n % 6
print(arr[rem - 1] % mod)


import sys

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def tinput():
	return input().split()

def rinput():
	return map(int, tinput())

def rlinput():
	return list(rinput())
(x, y) = rinput()
n = iinput()
mod = 10 ** 9 + 7
num = [x, y, y - x, -x, -y, -y + x]
ans = (n - 1) % len(num)
print(num[ans] % mod)


(x, y) = map(int, input().split())
n = int(input())
arr = [x, y, y - x, -x, -y, x - y]
MOD = 10 ** 9 + 7
print(arr[n % 6 - 1] % MOD)


import math
m = 1000000007

def fact(n):
	ans = 1
	for i in range(1, n + 1):
		ans = ans % m * (i % m) % m
	return ans

def power_2(n):
	ans = 1
	for i in range(n):
		ans = ans % m * 2 % m
	return ans

def fun(x, y, n):
	if n == 1:
		return x
	elif n == 2:
		return y
	else:
		return fun(x, y, n - 1) - fun(x, y, n - 2)
(x, y) = map(int, input().split())
n = int(input())
p = int(n / 6)
n -= 6 * p
if n == 0:
	n = 6
print(fun(x, y, n) % m)


(x, y) = map(int, input().split())
n = int(input())
a = [x, y, y - x, -x, -y, x - y]
t = a[n % 6 - 1]
print(t % (10 ** 9 + 7))


nums = list(map(int, input().split()))
upto = int(input())
arr = [nums[0] - nums[1], nums[0], nums[1], nums[1] - nums[0], -nums[0], -nums[1], 0]
print(arr[upto % 6] % (10 ** 9 + 7))


(x, y) = map(int, input().split())
n = int(input())
n = n % 6
M = 1000000007
l = [x - y, x, y, y - x, -x, -y]
print(l[n] % M)


w = input().split(' ')
(x, y) = (int(w[0]), int(w[1]))
n = int(input())
if n % 6 == 0:
	print((x - y) % (7 + 10 ** 9))
if n % 6 == 1:
	print(x % (7 + 10 ** 9))
if n % 6 == 2:
	print(y % (7 + 10 ** 9))
if n % 6 == 3:
	print((y - x) % (7 + 10 ** 9))
if n % 6 == 4:
	print(-x % (7 + 10 ** 9))
if n % 6 == 5:
	print(-y % (7 + 10 ** 9))


from collections import Counter, defaultdict, deque
import heapq as hq
from itertools import count, islice
import math
import sys
input = sys.stdin.readline
mod = 1000000007
(x, y) = [int(x) for x in input().split()]
n = int(input()) - 1
seq = [x, y]
for i in range(4):
	seq.append(seq[-1] - seq[-2])
n %= 6
print(seq[n] % mod)


(a, b) = map(int, input().split())
x = (int(input()) - 1) % 6
v = [a, b]
for i in range(2, 6):
	v.append(v[i - 1] - v[i - 2])
print(v[x] % 1000000007)


(x, y) = map(int, input().split())
n = int(input())
s = [x, y, y - x, -x, -y, x - y]
print(s[n % 6 - 1] % 1000000007)


(x, y) = map(int, input().split())
n = int(input()) % 6 - 1
mn = 10 ** 9 + 7
if x < 0:
	x += mn
else:
	x %= mn
if y < 0:
	y += mn
else:
	y %= mn
arr = [x, y]
for i in range(4):
	arr.append(arr[-1] - arr[-2])
	if arr[-1] < 0:
		arr[-1] += mn
	else:
		arr[-1] %= mn
print(arr[n])


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
import copy
import time
starttime = time.time()
mod = int(pow(10, 9) + 7)
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def L():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
try:
	sys.stdin = open('input.txt', 'r')
except:
	pass
(x, y) = map(int, input().split())
a = int(input())
z = [x, y, y - x, -x, -y, x - y]
print(z[a % 6 - 1] % (10 ** 9 + 7))
endtime = time.time()


(x, y) = map(int, input().split())
n = int(input())
n = n % 6
if n == 0:
	print((x - y) % (10 ** 9 + 7))
elif n == 5:
	print(-y % (10 ** 9 + 7))
elif n == 4:
	print(-x % (10 ** 9 + 7))
elif n == 3:
	print((y - x) % (10 ** 9 + 7))
elif n == 2:
	print(y % (10 ** 9 + 7))
else:
	print(x % (10 ** 9 + 7))


(x, y) = map(int, input().split())
n = int(input())
nQuo = n // 3
nRem = n % 3
if nRem == 0:
	output = x - y
elif nRem == 1:
	output = x
else:
	output = y
if nQuo & 1:
	output = -output
print(output % 1000000007)


import sys
import string
import math
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache
from fractions import Fraction

def mi(s):
	return map(int, s.strip().split())

def lmi(s):
	return list(mi(s))

def tmi(s):
	return tuple(mi(s))

def mf(f, s):
	return map(f, s)

def lmf(f, s):
	return list(mf(f, s))

def js(lst):
	return ' '.join((str(d) for d in lst))

def jsns(lst):
	return ''.join((str(d) for d in lst))

def line():
	return sys.stdin.readline().strip()

def linesp():
	return line().split()

def iline():
	return int(line())

def mat(n):
	matr = []
	for _ in range(n):
		matr.append(linesp())
	return matr

def matns(n):
	mat = []
	for _ in range(n):
		mat.append([c for c in line()])
	return mat

def mati(n):
	mat = []
	for _ in range(n):
		mat.append(lmi(line()))
	return mat

def pmat(mat):
	for row in mat:
		print(js(row))

def main():
	(x, y) = mi(line())
	n = iline()
	m = {0: x, 1: y, 2: y - x, 3: -x, 4: -y, 5: -y + x}
	print(m[(n - 1) % 6] % int(1000000000.0 + 7))
main()


MOD = 1000000007
(x, y) = map(int, input().split())
li = [x, y, y - x, -x, -y, x - y]
n = int(input())
n %= 6
print(li[n - 1] % MOD)


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def dmain():
	sys.setrecursionlimit(1000000)
	threading.stack_size(1024000)
	thread = threading.Thread(target=main)
	thread.start()
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def getKey(item):
	return item[1]

def sort2(l):
	return sorted(l, key=getKey, reverse=True)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def ntl(n):
	return [int(i) for i in str(n)]

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def ceil(x, y):
	if x % y == 0:
		return x // y
	else:
		return x // y + 1

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def main():
	(x, y) = map(int, input().split())
	n = int(input())
	arr = []
	arr.append(x)
	arr.append(y)
	arr.append(y - x)
	arr.append(-x)
	arr.append(-y)
	arr.append(x - y)
	print(arr[(n - 1) % 6] % 1000000007)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from collections import deque, Counter, OrderedDict
from heapq import nsmallest, nlargest
from math import ceil, floor, log, log2, sqrt, gcd, factorial, pow, pi
from bisect import bisect_left, bisect_right

def binNumber(n, size=4):
	return bin(n)[2:].zfill(size)

def iar():
	return list(map(int, input().split()))

def ini():
	return int(input())

def isp():
	return map(int, input().split())

def sti():
	return str(input())

def par(a):
	print(' '.join(list(map(str, a))))

def tdl(outerListSize, innerListSize, defaultValue=0):
	return [[defaultValue] * innerListSize for i in range(outerListSize)]

def sts(s):
	s = list(s)
	s.sort()
	return ''.join(s)

class pair:

	def __init__(self, f, s):
		self.fi = f
		self.se = s

	def __lt__(self, other):
		return (self.fi, self.se) < (other.fi, other.se)
MOD = 10 ** 9 + 7
(f1, f2) = isp()
f3 = f2 - f1
n = ini()
f6 = -1 * f3
if n <= 3:
	if n == 1:
		print(f1 % MOD)
	if n == 2:
		print(f2 % MOD)
	if n == 3:
		print(f3 % MOD)
	quit()
y = n % 6
if y == 0:
	print(f6 % MOD)
else:
	x = y // 3
	y = y % 3
	if x == 1:
		if y == 0:
			print(f3 % MOD)
		if y == 1:
			f1 *= -1
			print(f1 % MOD)
		if y == 2:
			f2 *= -1
			print(f2 % MOD)
	if x == 0:
		if y == 1:
			print(f1 % MOD)
		if y == 2:
			print(f2 % MOD)


import atexit
import io
import sys
import math as m
mod = 1000000007
R = lambda : map(int, input().split())
(x, y) = R()
a = [x, y, y - x, -x, -y, x - y]
print(int(a[(int(input()) - 1) % 6] % mod))


(x, y) = map(int, input().split())
n = int(input())
z = [x, y, y - x, -x, -y, -y + x]
k = (n - 1) % 6
print(z[k] % (10 ** 9 + 7))


import math
mod = int(math.pow(10, 9)) + 7
f = [int(x) for x in input().split()]
f.append(f[1] - f[0])
n = int(input()) - 1
if n // 3 % 2 != 0:
	print(-f[n % 3] % mod)
else:
	print(f[n % 3] % mod)


import math
import string

def main():
	(x, y) = map(int, input().split())
	n = int(input()) - 1
	print([x, y, y - x, -x, -y, -y + x][n % 6] % 1000000007)
main()


(x, y) = map(int, input().split())
n = int(input())
l = [x, y]
for _ in range(5):
	(x, y) = (y, y - x)
	l.append(y)
print(l[(n - 1) % 6] % (7 + 10 ** 9))


def discos():
	x = int()
	y = int
	z = int
	n = int
	ans = list()
	(x, y) = [int(x) for x in input().split()]
	n = int(input())
	ans = [x - y, x, y, y - x, -x, -y]
	z = (ans[n % 6] % 1000000007 + 1000000007) % 1000000007
	print(z)
	return
discos()


(a, b) = map(int, input().split())
n = int(input())
mod = 10 ** 9 + 7
l = [a, b, b - a, -a, -b, a - b]
print(l[(n - 1) % 6] % mod)


(x, y) = [int(x) for x in input().split()]
n = int(input())
tmp = 0
if n % 6 == 1:
	tmp = x
elif n % 6 == 2:
	tmp = y
elif n % 6 == 3:
	tmp = y - x
elif n % 6 == 4:
	tmp = -x
elif n % 6 == 5:
	tmp = -y
elif n % 6 == 0:
	tmp = -y + x
print(tmp % (10 ** 9 + 7))


(x, y) = list(map(int, input().split()))
n = int(input())

def modulo(a):
	if a == 1000000007:
		return 0
	elif a >= 0:
		return int(a % 1000000007)
	elif a % 1000000007 == 0:
		return 0
	else:
		return int(1000000007 - int(-1 * a % 1000000007))
n = n % 6
if n == 1:
	print(modulo(x))
elif n == 2:
	print(modulo(y))
elif n == 3:
	print(modulo(y - x))
elif n == 4:
	print(modulo(-x))
elif n == 5:
	print(modulo(-y))
elif n == 0:
	print(modulo(x - y))


import sys
import math as m

def main():
	pass

def binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def lts(l):
	s = ''.join(map(str, l))
	return s

def stl(s):
	l = list(s)
	return l
mod = int(1000000000.0) + 7

def sinp():
	return sys.stdin.readline().strip()

def iinp():
	return int(input())

def ninp():
	return map(int, sys.stdin.readline().strip().split())

def linp():
	return list(map(int, sys.stdin.readline().strip().split()))

def p(a):
	print(a)

def p2(a, b):
	print(a, b)
(x, y) = ninp()
n = iinp()
l = [0] * 6
l[1] = x
l[2] = y
l[3] = y - x
l[4] = -x
l[5] = -y
l[0] = x - y
print(l[n % 6] % mod)


import math
from decimal import *
import random
mod = int(1000000000.0) + 7
(x, y) = map(int, input().split())
n = int(input())
arr = [0, x, y, y - x, -x, -y, -y + x]
if n % 6 > 0:
	print(arr[n % 6] % mod)
else:
	print(arr[6] % mod)


(f1, f2) = map(int, input().split())
n = int(input())
f3 = f2 - f1
L = [f3, f1, f2]
print((-1) ** ((n - 1) // 3) * L[n % 3] % 1000000007)


import sys
import math
(x, y) = map(int, input().split())
n = int(input())
(f1, f2) = (x, y)
comma = [f1, f2, f2 - f1, -1 * f1, -1 * f2, f1 - f2]
print(comma[(n - 1) % 6] % (pow(10, 9) + 7))


a = [int(x) for x in input().split()]
dp = []
dp.append(a[0])
dp.append(a[1])
dp.append(a[1] - a[0])
dp.append(-a[0])
dp.append(-a[1])
dp.append(-a[1] + a[0])
n = int(input())
print(dp[(n - 1) % 6] % 1000000007)


MOD = 1000000007
arr = [int(x) for x in input().split()]
n = int(input())
for i in range(2, 6):
	arr.append(arr[i - 1] - arr[i - 2])
if n % 6 == 0:
	print(arr[5] % MOD)
else:
	print(arr[n % 6 - 1] % MOD)


(x, y) = map(int, input().split())
n = int(input())
M = 1000000007
f0 = x - y
if n % 3 == 0:
	ans = f0
elif n % 3 == 1:
	ans = x
else:
	ans = y
if n // 3 % 2 == 0:
	print(ans % M)
else:
	print(ans * -1 % M)


(x, y) = map(int, input().rstrip().split())
n = int(input())
for i in range(1, 7):
	if not (n - i) % 6:
		index = i
		if index == 1:
			print(x % 1000000007)
			break
		elif index == 2:
			print(y % 1000000007)
			break
		fn = 3
		for i in range(4):
			next = y - x
			if fn == index:
				print(next % 1000000007)
				break
			(x, y) = (y, next)
			fn += 1
		break


(x, y) = map(int, input().split())
n = int(input())
mm = 10 ** 9 + 7
f1 = x
f2 = y
f3 = f2 - f1
f4 = f3 - f2
f5 = f4 - f3
f6 = f5 - f4
if (n - 1) % 6 == 0:
	print(f1 % mm)
elif (n - 2) % 6 == 0:
	print(f2 % mm)
elif (n - 3) % 6 == 0:
	print(f3 % mm)
elif (n - 4) % 6 == 0:
	print(f4 % mm)
elif (n - 5) % 6 == 0:
	print(f5 % mm)
elif (n - 6) % 6 == 0:
	print(f6 % mm)


(x, y) = map(int, input().split(' '))
n = int(input())
ans = [x, y, y - x, -x, -y, x - y]
print(ans[(n - 1) % 6] % 1000000007)


(x, y) = map(int, input().split())
n = int(input())
A = [x, y, y - x, -x, -y, x - y]
n -= 1
Ind = n % 6
print(A[Ind] % (10 ** 9 + 7))


str1 = list(map(int, input().split()))
x = str1[0]
y = str1[1]
n = int(input())
val = n % 6
mod = 1000000007
if val == 0:
	print((x - y) % mod)
elif val == 1:
	print(x % mod)
elif val == 2:
	print(y % mod)
elif val == 3:
	print((y - x) % mod)
elif val == 4:
	print(-x % mod)
elif val == 5:
	print(-y % mod)


import os
import sys
from io import BytesIO, IOBase
mod = 10 ** 9 + 7

def main():
	(x, y) = map(int, input().split())
	n = int(input())
	dp = [x, y, y - x, -x, -y, x - y]
	n = (n - 1) % 6
	print(dp[n] % mod)

def nouse0():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')

def nouse1():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')

def nouse2():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def nouse3():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')

def nouse4():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')

def nouse5():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')
main()


import sys
inf = float('inf')
(mod, MOD) = (1000000007, 998244353)

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
(f1, f2) = get_ints()
n = int(input())
if n % 3 == 0:
	if n & 1:
		print((f2 % mod - f1 % mod + mod) % mod)
	else:
		print((f1 % mod - f2 % mod + mod) % mod)
elif n % 3 == 2:
	if n & 1:
		print(-f2 % mod)
	else:
		print(f2 % mod)
elif n & 1:
	print(f1 % mod)
else:
	print(-f1 % mod)


a = list(map(int, input().split()))
n = int(input())
if n == 1 or n == 2:
	print(a[n - 1] % 1000000007)
elif n % 3 == 0:
	if n // 3 % 2 != 0:
		print((a[1] - a[0]) % 1000000007)
	else:
		print((a[0] - a[1]) % 1000000007)
elif n % 3 == 1:
	if n // 3 % 2 == 0:
		print(a[0] % 1000000007)
	else:
		print(-a[0] % 1000000007)
elif n // 3 % 2 == 0:
	print(a[1] % 1000000007)
else:
	print(-a[1] % 1000000007)


MOD = 10 ** 9 + 7
(x, y) = map(int, input().split())
lis = [x, y, y - x, -x, -y, x - y]
for i in range(6):
	if lis[i] >= MOD:
		lis[i] = lis[i] % MOD
	elif lis[i] < 0:
		lis[i] = lis[i] + MOD
n = int(input())
cr = lis[n % 6 - 1]
if cr >= MOD:
	cr = cr % MOD
elif cr < 0:
	cr = cr + MOD
print(cr)


(x, y) = map(int, input().split())
n = int(input())
dp = [0] * 6
dp[0] = x
dp[1] = y
if x == 0 and y == 0:
	print(0)
else:
	for i in range(2, 6):
		dp[i] = dp[i - 1] - dp[i - 2]
	x = (n - 1) % 6
	print(int(dp[x] % (1000000000.0 + 7)))


mod = 1000000007
arr = [int(x) for x in input().split(' ')]
k = (int(input()) - 1) % 6
arr.append(arr[-1] - arr[-2])
arr.append(-arr[0])
arr.append(-arr[1])
arr.append(-arr[2])
print(arr[k] % mod)


from sys import *
from math import *
from sys import stdin, stdout
from collections import *
int_arr = lambda : list(map(int, stdin.readline().strip().split()))
str_arr = lambda : list(map(str, stdin.readline().split()))
get_str = lambda : map(str, stdin.readline().strip().split())
get_int = lambda : map(int, stdin.readline().strip().split())
get_float = lambda : map(float, stdin.readline().strip().split())
mod = 1000000007
setrecursionlimit(1000)
arr = int_arr()
n = int(input())
arr.append(arr[1] - arr[0])
arr.append(-1 * arr[0])
arr.append(-1 * arr[1])
arr.append(-1 * arr[2])
print(arr[n % 6 - 1] % mod)


def seq(f1, f2, n):
	x = n // 3
	f3 = f2 - f1
	if x % 2 == 0:
		if n % 3 == 1:
			return f1 % (10 ** 9 + 7)
		elif n % 3 == 2:
			return f2 % (10 ** 9 + 7)
		elif n % 3 == 0:
			return -f3 % (10 ** 9 + 7)
	elif n % 3 == 1:
		return -f1 % (10 ** 9 + 7)
	elif n % 3 == 2:
		return -f2 % (10 ** 9 + 7)
	elif n % 3 == 0:
		return +f3 % (10 ** 9 + 7)
(f1, f2) = list(map(int, input().split(' ')))
n = int(input())
print(seq(f1, f2, n))


(x, y) = map(int, input().split())
n = int(input())
mod = 1000000007
vals = [x, y, y - x, -x, -y, x - y]
print(vals[n % 6 - 1] % mod)


a = list(map(int, input().split()))
n = int(input())
mod = 10 ** 9 + 7
mem = -1
b = 0
if n > 2:
	for i in range(n - 2):
		if b:
			break
		if i > 9:
			break
		next = a[-1] - a[-2]
		a.append(next)
		if len(a) > 5:
			for j in range(len(a) - 5):
				if a[0 + j] == a[-3] and a[1 + j] == a[-2] and (a[2 + j] == a[-1]):
					mem = j
					b = 1
					break
	if len(a) != 3 and mem != -1:
		a = a[mem:-3]
		n -= mem
	l = len(a)
	idex = n % l
	if idex == 0:
		print(a[-1] % mod)
	else:
		print(a[idex - 1] % mod)
else:
	print(a[n - 1] % mod)


(x, y) = list(map(int, input().split()))
z = y - x
a = [-z, x, y, z, -x, -y]
n = int(input())
print(a[n % 6] % (10 ** 9 + 7))


(x, y) = map(int, input().split())
n = int(input())
a = [x, y]
for i in range(4):
	t1 = y - x
	x = y
	y = t1
	a.append(y)
t1 = n % len(a)
print(a[t1 - 1] % 1000000007)


from itertools import *
MOD = 1000000007

def read_ints():
	return map(int, input().strip().split())
(x, y) = read_ints()
(n,) = read_ints()
t = [x, y, y - x] + [-x, -y, -(y - x)]
n0 = n - 1
print(t[n0 % 6] % MOD)


mod = int(1000000000.0 + 7)
arr = list(map(int, input().split()))
n = int(input())
n %= 6
for i in range(4):
	arr.append(arr[-1] - arr[-2])
print(arr[n - 1] % mod)


[x, y] = list(map(int, input().split(' ')))
n = int(input())
t = [[1, -1], [1, 0], [0, 1], [-1, 1], [-1, 0], [0, -1]]
n = n % 6
result = (t[n][0] * x + t[n][1] * y) % (10 ** 9 + 7)
print(result)


I = lambda : map(int, input().split())
(x, y) = I()
n = int(input())
print([x, y, -x + y, -x, -y, x - y][(n - 1) % 6] % 1000000007)


import os
import sys
from io import BytesIO, IOBase

def main():
	(x, y) = map(int, input().split(' '))
	n = int(input()) - 1
	n = n % 6
	mod = int(1000000000.0 + 7)
	if n == 0:
		if x >= 0:
			print(x % mod)
		else:
			print((x + mod) % mod)
	if n == 1:
		if y >= 0:
			print(y % mod)
		else:
			print((y + mod) % mod)
	if n == 2:
		if y - x <= 0:
			print((y - x + mod) % mod)
		else:
			print((y - x) % mod)
	if n == 3:
		if x <= 0:
			print(-x % mod)
		else:
			print((-x + mod) % mod)
	if n == 4:
		if y <= 0:
			print(-y % mod)
		else:
			print((-y + mod) % mod)
	if n == 5:
		if x - y <= 0:
			print((x - y + mod) % mod)
		else:
			print((x - y) % mod)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


x = input().split(' ')
a = int(x[0])
b = int(x[1])
n = int(input())
c = b - a
d = -a
e = -b
f = -c
g = n % 3
h = n // 3
if g != 0:
	h = h + 1
i = 0
if g == 0:
	i = c
elif g == 1:
	i = a
elif g == 2:
	i = b
if h % 2 == 0:
	i = -i
i = i % 1000000007
print(i)


p = input()
(x, y) = map(int, p.split())
n = int(input())
a = n // 3
b = n % 3
if b == 0 and a > 1:
	a -= 1
	c = (-1) ** a * (y - x)
	print(c % 1000000007)
elif b == 1 and a > 0:
	c = (-1) ** a * x
	print(c % 1000000007)
elif b == 2 and a > 0:
	c = (-1) ** a * y
	print(c % 1000000007)
elif b == 0 and a == 1:
	c = y - x
	print(c % 1000000007)
elif b == 1 and a == 0:
	c = x
	print(c % 1000000007)
else:
	c = y
	print(c % 1000000007)


(n, m) = map(int, input().split(' '))
k = int(input())
if k % 3 == 0:
	if k // 3 % 2 == 0:
		print((n - m) % 1000000007)
	else:
		print((m - n) % 1000000007)
elif (k // 3 + 1) % 2 == 0:
	if k % 3 == 1:
		print(-n % 1000000007)
	else:
		print(-m % 1000000007)
elif k % 3 == 1:
	print(n % 1000000007)
else:
	print(m % 1000000007)


M = 1000000007
(a, b) = map(int, input().split())
x = int(input())
array = [0] * 6
array[1] = (a % M + M) % M
array[2] = (b % M + M) % M
for i in range(3, 6):
	array[i] = (array[i - 1] % M - array[i - 2] % M + M) % M
array[0] = (array[5] % M - array[4] % M + M) % M
print(array[x % 6])


(x, y) = map(int, input().split())
n = int(input())
m = 1000000007
a = [x, y]
for i in range(2, 6):
	a.append(a[i - 1] - a[i - 2])
if n % 6 == 0:
	print(a[5] % m)
	exit()
print(a[n % 6 - 1] % m)


(f1, f2) = map(int, input().strip().split())
mod = 1000000007
f3 = f2 - f1
n = int(input().strip())
res = [f1, f2, f3]
(d, m) = divmod(n, 3)
if d & 1:
	if m == 0:
		print((res[2 - m] + mod) % mod)
	else:
		print((-1 * res[m - 1] + mod) % mod)
elif m == 0:
	print((-1 * res[2 - m] + mod) % mod)
else:
	print((res[m - 1] + mod) % mod)


(x, y) = map(int, input().rstrip().split())
n = int(input())
li = [x, y, y - x, -x, -y, x - y]
i = n % 6
print(li[i - 1] % 1000000007)


while True:
	try:

		def solution(x, y, n):
			M = 10 ** 9 + 7
			a = [x - y, x, y, -x + y, -x, -y]
			ans = a[n % 6] % M
			print(ans)

		def read():
			(x, y) = map(int, input().split())
			n = int(input())
			solution(x, y, n)
		if __name__ == '__main__':
			read()
	except EOFError:
		break


MOD = 10 ** 9 + 7
A = [[0 for i in range(2)] for j in range(2)]
A[0][0] = 1
A[0][1] = -1
A[1][0] = 1
Ans = [[0 for i in range(2)] for j in range(2)]
Ans[0][0] = Ans[1][1] = 1
(f1, f2) = map(int, input().split())
n = int(input())

def multiplication(X, Y):
	Z = [[0 for i in range(2)] for j in range(2)]
	for i in range(2):
		for j in range(2):
			Z[i][j] = 0
			for k in range(2):
				Z[i][j] += X[i][k] * Y[k][j]
	return Z
if n - 2 < 0:
	if n == 1:
		while f1 < 0:
			f1 = f1 + MOD
	print(f1 % MOD)
else:
	n = n - 2
	while n != 0:
		if n % 2 == 1:
			n = (n - 1) / 2
			Ans = multiplication(Ans, A)
		else:
			n = n / 2
		A = multiplication(A, A)
	ans = f2 * Ans[0][0] + f1 * Ans[0][1]
	while ans < 0:
		ans = ans + MOD
	print(ans % MOD)


(x, y) = [int(t) for t in input().split(' ')]
n = int(input())
l = [x, y, y - x, -x, -y, x - y]
fn = l[n % 6 - 1]
print(fn % 1000000007)


(x, y) = [int(x) for x in input().split()]
n = int(input())
f1 = x
f2 = y
f3 = f2 - f1
r = n % 3
p = (n - 1) // 3 % 2
if r == 0:
	if p == 1:
		ans = -f3
	else:
		ans = f3
elif r == 1:
	if p == 1:
		ans = -f1
	else:
		ans = f1
elif p == 1:
	ans = -f2
else:
	ans = f2
print(ans % 1000000007)


def fib(n, x, y):
	f = [[1, -1], [1, 0]]
	power(f, n)
	M = 1000000007
	return (y * f[0][0] + x * f[0][1] + M) % M

def multiply(f, m):
	k = 2
	M = 1000000007
	g = [[0 for i in range(2)] for j in range(2)]
	for i in range(2):
		for j in range(2):
			for k in range(2):
				g[i][j] = (g[i][j] + f[i][k] * m[k][j]) % M
	for i in range(2):
		for j in range(2):
			f[i][j] = g[i][j]

def power(f, n):
	m = [[1, -1], [1, 0]]
	if n == 0 or n == 1:
		return
	power(f, n // 2)
	multiply(f, f)
	if n % 2 != 0:
		multiply(f, m)
M = 1000000007

def res():
	(x, y) = map(int, input().split())
	n = int(input())
	if n == 1:
		print((x + M) % M)
	elif n == 2:
		print((y + M) % M)
	else:
		t = fib(n - 2, x, y)
		print(t)
res()


(x, y) = map(int, input().split())
N = int(input())
MOD = int(1000000000.0) + 7
m = (N - 1) % 3
if m == 0:
	ans = x
elif m == 1:
	ans = y
elif m == 2:
	ans = y - x
mm = (N - 1) % 6
if mm >= 3:
	ans = -ans
ans %= MOD
print(ans)


(x, y) = list(map(int, input().split()))
n = int(input())
l = [x, y, y - x, -x, -y, x - y]
t = (n - 1) % 6
print(l[t] % (10 ** 9 + 7))


(f1, f2) = [int(i) for i in input().split()]
n = int(input())
res = 0
if n == 1:
	res = f1
elif n == 2:
	res = f2
elif n % 6 == 0:
	res = f1 - f2
elif n % 6 == 1:
	res = f1
elif n % 6 == 2:
	res = f2
elif n % 6 == 3:
	res = f2 - f1
elif n % 6 == 4:
	res = -f1
elif n % 6 == 5:
	res = -f2
print(res % (10 ** 9 + 7))


mod = pow(10, 9) + 7
(x, y) = map(int, input().split())
n = int(input())
arr = list((mod + x, mod + y, mod + (y - x), mod - x, mod - y, mod + x - y, mod + y - x))
print(arr[(n - 1) % 6] % mod)


(x, y) = map(int, input().split())
n = int(input())
m = 1000000000 + 7
dp = [x, y, y - x, -x, -y, x - y]
print(dp[(n - 1) % 6] % m)


def main():
	(x, y) = map(int, input().split())
	l = []
	for _ in range(6):
		(x, y) = (y, y - x)
		l.append(y)
	print(l[(int(input()) + 3) % 6] % 1000000007)
main()


from sys import stdin, stdout
(a, b) = map(int, stdin.readline().rstrip().split())
n = int(stdin.readline().rstrip())
n = (n - 1) % 6
s = -1 if n > 2 else 1
n = n % 3
c = b - a
x = a if n == 0 else b if n == 1 else c
stdout.write(str(x * s % 1000000007))


(a, b) = map(int, input().split())
n = int(input())
if n == 1:
	print(a % int(1000000000.0 + 7))
	exit()
if n == 2:
	print(b % int(1000000000.0 + 7))
	exit()
r = (n - 1) % 6
if r == 0:
	print(a % int(1000000000.0 + 7))
elif r == 1:
	print(b % int(1000000000.0 + 7))
elif r == 2:
	print((b - a) % int(1000000000.0 + 7))
elif r == 3:
	print(-a % int(1000000000.0 + 7))
elif r == 4:
	print(-b % int(1000000000.0 + 7))
else:
	print((a - b) % int(1000000000.0 + 7))


(x, y) = [int(x) for x in input().split()]
n = int(input())
n = n % 6 - 1
ls = [x, y, 0, 0, 0, 0]
for i in range(2, 6):
	ls[i] = ls[i - 1] - ls[i - 2]
print(int(ls[n] % (1000000000.0 + 7)))


def mat_mult(A, B, MOD):
	(n, m, p) = (len(A), len(A[0]), len(B[0]))
	assert len(B) == m
	C = [[0] * p for _ in range(n)]
	for i in range(n):
		for k in range(m):
			Aik = A[i][k]
			for j in range(p):
				C[i][j] = (C[i][j] + Aik * B[k][j]) % MOD
	return C

def ksm(A, n, MOD):
	if n == 0:
		E = [[0 for i in range(len(A))] for j in range(len(A))]
		for i in range(len(A)):
			E[i][i] = 1
		return E
	if n == 1:
		return A
	k = ksm(A, n // 2, MOD)
	z = mat_mult(k, k, MOD)
	if n & 1:
		return mat_mult(z, A, MOD)
	else:
		return z
mod = 10 ** 9 + 7
(x, y) = map(int, input().split())
n = int(input())
A = [[1, -1], [1, 0]]
if n == 1:
	print(x % mod)
elif n == 2:
	print(y % mod)
else:
	print(mat_mult(ksm(A, n - 2, mod), [[y], [x]], mod)[0][0])


(x, y) = map(int, input().split())
n = int(input())
number = [x, y, y - x, 0 - x, 0 - y, x - y]
fn = number[n % 6 - 1]
print(fn % (10 ** 9 + 7))


(x, y) = map(int, input().split())
n = int(input())
a = x % 1000000007
b = y % 1000000007
c = (y - x) % 1000000007
d = -1 * x % 1000000007
e = -1 * y % 1000000007
f = -1 * (y - x) % 1000000007
n = n % 6
if n == 0:
	print(f)
elif n == 1:
	print(a)
elif n == 2:
	print(b)
elif n == 3:
	print(c)
elif n == 4:
	print(d)
elif n == 5:
	print(e)


(a, b) = map(int, input().split())
n = int(input())
h = [3, 4, 5, 6, 7, 8]
w = [a, b, b - a]
p = [b - a, -a, -b, a - b, a, b]
d = {}
m = 10 ** 9 + 7
if n <= 3:
	print(w[n - 1] % m)
else:
	for i in range(0, len(p)):
		d[i + 3] = p[i]
	for i in h:
		if (n - i) % 6 == 0:
			print(d[i] % m)
			break


import sys
input = lambda : sys.stdin.readline().strip('\r\n')
MOD = 10 ** 9 + 7
(n, m) = map(int, input().split())
k = int(input())
a = [n, m, m - n, -n, -m, n - m]
print(a[(k - 1) % 6] % MOD)


(a, b) = map(int, input().split())
n = int(input())
lol = [a, b]
for i in range(4):
	(a, b) = (b, b - a)
	lol.append(b)
print(lol[(n - 1) % 6] % 1000000007)


(n, m) = map(int, input().split())
k = int(input())
a = [n, m, m - n, -n, -m, n - m]
print(a[(k - 1) % 6] % 1000000007)


(x, y) = map(int, input().split())
for _ in range((int(input()) - 2) % 6):
	(x, y) = (y, y - x)
print(y % 1000000007)


inp = list(map(int, input().split()))
a = inp[0]
b = inp[1]
arr = [0, a, b, b - a, -1 * a, -1 * b, a - b]
v = pow(10, 9) + 7
n = int(input())
n = n % 6
if n == 0:
	n = 6
print(arr[n] % v)


mod = 10 ** 9 + 7
[x, y] = list(map(int, input().split()))
n = int(input())
ans = [x, y, y - x, -x, -y, x - y]
print(ans[(n - 1) % 6] % mod)


(x, y) = map(int, input().split())
lst = [x, y, y - x, -x, -y, -(y - x)]
print(lst[(int(input()) - 1) % 6] % (10 ** 9 + 7))


import math
mo = 1000000000.0 + 7
(f1, f2) = map(int, input().split(' '))
n = int(input())
li = [f1, f2, f2 - f1, -f1, -f2, f1 - f2]
n = math.trunc((n - 1) % 6)
res = li[n] % mo
print(math.trunc(res))


import sys
from functools import reduce
from collections import Counter
import time
import datetime
from math import sqrt, gcd

def ip():
	return int(sys.stdin.readline())

def sip():
	return sys.stdin.readline()

def mip():
	return map(int, sys.stdin.readline().split())

def mips():
	return map(str, sys.stdin.readline().split())

def lip():
	return list(map(int, sys.stdin.readline().split()))

def matip(n, m):
	lst = []
	for i in range(n):
		arr = lip()
		lst.append(arr)
	return lst

def factors(n):
	return list(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def minJumps(arr, n):
	jumps = [0 for i in range(n)]
	if n == 0 or arr[0] == 0:
		return float('inf')
	jumps[0] = 0
	for i in range(1, n):
		jumps[i] = float('inf')
		for j in range(i):
			if i <= j + arr[j] and jumps[j] != float('inf'):
				jumps[i] = min(jumps[i], jumps[j] + 1)
				break
	return jumps[n - 1]

def dic(arr):
	return Counter(arr)

def check_prime(n):
	if n < 2:
		return False
	for i in range(2, int(n ** 0.5) + 1, 2):
		if n % i == 0:
			return False
	return True
(x, y) = mip()
n = ip()
lst = [x - y, x, y, y - x, -x, -y]
print(lst[n % 6] % 1000000007)


(x, y) = map(int, input().split())
z = int(input())
lst = [x, y, y - x, -x, -y, -y + x]
print(lst[(z - 1) % 6] % 1000000007)


mod = 10 ** 9 + 7

def scan():
	a = list(map(int, input().split()))
	return a

def one():
	n = int(input())
	return n

def two():
	(a, b) = map(int, input().split())
	return (a, b)
(a, b) = two()
n = one()
c = b - a
res = 0
if n % 3 == 0:
	res = n // 3
else:
	res = n // 3
	res += 1
if res % 2 == 1:
	k = [a, b, c]
	print(k[n % 3 - 1] % mod)
else:
	k = [-1 * a, -1 * b, -1 * c]
	print(k[n % 3 - 1] % mod)


(a, b) = map(int, input().split())
m = 1000000007
a = a % m
b = b % m
n = int(input())
i = 3
if n == 1:
	print(a)
elif n == 2:
	print(b)
else:
	l = [a, b]
	while i <= 6:
		c = (b - a) % m
		a = b % m
		b = c % m
		i += 1
		l.append(c)
	print(l[(n - 1) % 6])


def solve(x, y, n):
	ans = [x, y, y - x]
	mod = int(1000000000.0) + 7
	for i in range(3):
		ans.append(ans[i] * -1)
	ind = n % 6 - 1
	if ans[ind] < 0:
		print(ans[ind] % mod)
	else:
		print(ans[ind] % mod)
(x, y) = map(int, input().split())
n = int(input())
solve(x, y, n)


(x, y) = [int(x) for x in input().split(' ')]
c = [x, y, y - x, -x, -y, x - y]
n = int(input())
print(c[(n - 1) % 6] % (pow(10, 9) + 7))


from math import *
from sys import stdin, stdout
import itertools
import os
import sys
import threading
from collections import deque, Counter, OrderedDict, defaultdict
from heapq import *
from fractions import Fraction
mod = int(pow(10, 9) + 7)

def ii():
	return int(input())

def si():
	return str(input())

def mi():
	return map(int, input().split())

def li():
	return list(mi())

def fii():
	return int(stdin.readline())

def fsi():
	return str(stdin.readline())

def fmi():
	return map(int, stdin.readline().split())

def fli():
	return list(fmi())
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}

def getKey(item):
	return item[0]

def sort2(l):
	return sorted(l, key=getKey)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def ntl(n):
	return [int(i) for i in str(n)]

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res
graph = defaultdict(list)
visited = [0] * 1000000
col = [-1] * 1000000

def bfs(d, v):
	q = []
	q.append(v)
	visited[v] = 1
	while len(q) != 0:
		x = q[0]
		q.pop(0)
		for i in d[x]:
			if visited[i] != 1:
				visited[i] = 1
				q.append(i)
		print(x)

def make_graph(e):
	d = {}
	for i in range(e):
		(x, y) = mi()
		if x not in d:
			d[x] = [y]
		else:
			d[x].append(y)
		if y not in d:
			d[y] = [x]
		else:
			d[y].append(x)
	return d

def gr2(n):
	d = defaultdict(list)
	for i in range(n):
		(x, y) = mi()
		d[x].append(y)
	return d

def connected_components(graph):
	seen = set()

	def dfs(v):
		vs = set([v])
		component = []
		while vs:
			v = vs.pop()
			seen.add(v)
			vs |= set(graph[v]) - seen
			component.append(v)
		return component
	ans = []
	for v in graph:
		if v not in seen:
			d = dfs(v)
			ans.append(d)
	return ans

def primeFactors(n):
	s = set()
	while n % 2 == 0:
		s.add(2)
		n = n // 2
	for i in range(3, int(sqrt(n)) + 1, 2):
		while n % i == 0:
			s.add(i)
			n = n // i
	if n > 2:
		s.add(n)
	return s

def find_all(a_str, sub):
	start = 0
	while True:
		start = a_str.find(sub, start)
		if start == -1:
			return
		yield start
		start += len(sub)

def SieveOfEratosthenes(n, isPrime):
	isPrime[0] = isPrime[1] = False
	for i in range(2, n):
		isPrime[i] = True
	p = 2
	while p * p <= n:
		if isPrime[p] == True:
			i = p * p
			while i <= n:
				isPrime[i] = False
				i += p
		p += 1
	return isPrime

def dijkstra(edges, f, t):
	g = defaultdict(list)
	for (l, r, c) in edges:
		g[l].append((c, r))
	(q, seen, mins) = ([(0, f, ())], set(), {f: 0})
	while q:
		(cost, v1, path) = heappop(q)
		if v1 not in seen:
			seen.add(v1)
			path = (v1, path)
			if v1 == t:
				return (cost, path)
			for (c, v2) in g.get(v1, ()):
				if v2 in seen:
					continue
				prev = mins.get(v2, None)
				next = cost + c
				if prev is None or next < prev:
					mins[v2] = next
					heappush(q, (next, v2, path))
	return float('inf')

def binsearch(a, l, r, x):
	while l <= r:
		mid = l + (r - 1) // 2
		print(mid)
		if a[mid]:
			return mid
		elif a[mid] > x:
			l = mid - 1
		else:
			r = mid + 1
	return -1
(x, y) = mi()
n = ii()
a = x
b = y
c = y - x
n -= 1
if n % 6 == 0:
	print(a % mod)
if n % 6 == 1:
	print(b % mod)
if n % 6 == 2:
	print(c % mod)
if n % 6 == 3:
	print(-a % mod)
if n % 6 == 4:
	print(-b % mod)
if n % 6 == 5:
	print(-c % mod)


def spfun(x, y, n):
	mod = 10 ** 9 + 7
	if x == 0 and y == 0:
		return 0
	num = n % 6
	if num == 0:
		return (x - y) % mod
	elif num == 1:
		return x % mod
	elif num == 2:
		return y % mod
	elif num == 3:
		return (y - x) % mod
	elif num == 4:
		return -x % mod
	elif num == 5:
		return -y % mod
(x, y) = map(int, input().split())
n = int(input())
print(spfun(x, y, n))


(r, s) = map(int, input().split())
n = int(input())
a = s
b = r
f = 10 ** 9 + 7
if n % 6 == 1:
	print(r % f)
elif n % 6 == 2:
	print(s % f)
elif n % 6 == 3:
	print((s - r) % f)
elif n % 6 == 4:
	print(-r % f)
elif n % 6 == 5:
	print(-s % f)
else:
	print((r - s) % f)


(x, y) = map(int, input().split())
n = int(input())
l = [x, y]
k1 = y - x
l.append(k1)
k2 = k1 - y
l.append(k2)
k3 = k2 - k1
l.append(k3)
k4 = k3 - k2
l.append(k4)
r = n % 6
if r == 0:
	print(l[5] % 1000000007)
else:
	print(l[r - 1] % 1000000007)


import math
(x, y) = list(map(int, input().split()))
n = int(input())
l = [0]
l.append(x)
l.append(y)
l.append(y - x)
f = n // 3
i = n % 3
if i == 0:
	i = 3
	f = f - 1
a = (-1) ** f * l[i]
print(a % (10 ** 9 + 7))


s = input()
l = s.split()
x = int(l[0])
y = int(l[1])
n = int(input())
q = n % 6
if q == 1:
	print(x % (10 ** 9 + 7))
elif q == 2:
	print(y % (10 ** 9 + 7))
elif q == 3:
	print((y - x) % (10 ** 9 + 7))
elif q == 4:
	print(-x % (10 ** 9 + 7))
elif q == 5:
	print(-y % (10 ** 9 + 7))
elif q == 0:
	print((x - y) % (10 ** 9 + 7))


from collections import defaultdict
(x, y) = map(int, input().split())
n = int(input())
a = [x - y, x, y, y - x, -x, -y]
print(a[n % 6] % 1000000007)


(x, y) = input().split(' ')
n = int(input())
x = int(x)
y = int(y)
if n <= 3:
	if n == 1:
		print(x % 1000000007)
	if n == 2:
		print(y % 1000000007)
	if n == 3:
		print((y - x) % 1000000007)
else:
	t = n % 3
	u = n // 3
	ans = int(0)
	if t == 0:
		ans = (-1) ** (u + 1) * (y - x)
	if t == 1:
		ans = (-1) ** u * x
	if t == 2:
		ans = (-1) ** u * y
	print(ans % 1000000007)


(x, y) = map(int, input().split())
n = int(input())
l = [x, y]
for i in range(4):
	a = y - x
	x = y
	y = a
	l.append(y)
j = n % 6 - 1
if j == -1:
	j = 5
print(l[j] % 1000000007)


MOD = 10 ** 9 + 7
(x, y) = [int(i) for i in input().split()]
n = int(input())
f = [x, y, y - x, -x, -y, x - y]
n = pow(n, 1, 6)
print(pow(f[n - 1], 1, MOD))


import sys
(f1, f2) = map(int, sys.stdin.readline().split())
n = int(input())
N = 10 ** 9 + 7

def getApower(m):
	a = 1
	Ai = [[0, 1], [-1, 1]]
	ret = [[1, 0], [0, 1]]
	for i in range(1000):
		if m & a == a:
			ret = [[(ret[0][0] * Ai[0][0] + ret[0][1] * Ai[1][0]) % N, (ret[0][0] * Ai[0][1] + ret[0][1] * Ai[1][1]) % N], [(ret[1][0] * Ai[0][0] + ret[1][1] * Ai[1][0]) % N, (ret[1][0] * Ai[0][1] + ret[1][1] * Ai[1][1]) % N]]
		Ai = [[(Ai[0][0] * Ai[0][0] + Ai[0][1] * Ai[1][0]) % N, (Ai[0][0] * Ai[0][1] + Ai[0][1] * Ai[1][1]) % N], [(Ai[1][0] * Ai[0][0] + Ai[1][1] * Ai[1][0]) % N, (Ai[1][0] * Ai[0][1] + Ai[1][1] * Ai[1][1]) % N]]
		a *= 2
		if m < a:
			break
	return ret
if n == 1:
	print(f1 % N)
elif n == 2:
	print(f2 % N)
else:
	An = getApower(n - 2)
	print((An[1][0] * f1 + An[1][1] * f2) % N)


(x, y) = map(int, input().split())
n = int(input())
f = [x, y, y - x, -x, -y, x - y]
print(f[(n - 1) % len(f)] % 1000000007)


(x, y) = [int(x) for x in input().split()]
n = int(input())
p = int(1000000000.0 + 7)
n1 = n % 6
if n1 == 0:
	ans = (x - y) % p
elif n1 == 1:
	ans = x % p
elif n1 == 2:
	ans = y % p
elif n1 == 3:
	ans = (y - x) % p
elif n1 == 4:
	ans = (p - x) % p
elif n1 == 5:
	ans = (p - y) % p
print(ans)


def main():
	(x, y) = list(map(int, input().split()))
	n = int(input())
	lst = [x, y, y - x, -x, -y, x - y]
	lst = list([a % 1000000007 for a in lst])
	print(lst[(n - 1) % len(lst)])

def __starting_point():
	main()
__starting_point()


(x, y) = map(int, input().split())
f = [0, x, y, y - x]
n = int(input())
r = n % 3
q = n // 3
if r == 0:
	q = q - 1
	if q % 2 == 0:
		print(f[3] % 1000000007)
	else:
		print(-f[3] % 1000000007)
elif q % 2 == 0:
	print(f[r] % 1000000007)
else:
	print(-f[r] % 1000000007)


(x, y) = [int(x) for x in input().split()]
n = int(input())
z = y - x
t = [-z, x, y, z, -x, -y]
print(t[n % 6] % (10 ** 9 + 7))


M = 1000000007

def matrix_mul(a, b):
	c = [[0, 0], [0, 0]]
	for i in range(2):
		for j in range(2):
			for k in range(2):
				c[i][j] = (c[i][j] + a[i][k] * b[k][j] % M) % M
	return c

def matrix_pow(a, k):
	c = [[1, 0], [0, 1]]
	while k:
		if k & 1:
			c = matrix_mul(c, a)
		a = matrix_mul(a, a)
		k = k >> 1
	return c
while True:
	try:
		(x, y) = [int(i) for i in input().split()]
		n = int(input())
	except:
		break
	if n == 1:
		print(x % M)
	elif n == 2:
		print(y % M)
	else:
		c = matrix_pow([[1, -1], [1, 0]], n - 2)
		print((c[0][0] * y + c[0][1] * x) % M)


(x, y) = map(int, input().split())
a = {1: x, 2: y, 3: y - x, 4: -x, 5: -y, 0: x - y}
print(a[int(input()) % 6] % 1000000007)


(x, y) = map(int, input().split())
n = int(input())
INF = 10 ** 9 + 7
if n == 1:
	print(x % INF)
elif n == 2:
	print(y % INF)
else:
	n = n % 6
	a = [x, y, y - x, -x, -y, x - y]
	print(a[n - 1] % INF)


(x, y) = [int(x) for x in input().split()]
n = int(input())
mod = 1000000007
dp = [y - x, -x, -y, x - y, x, y]
print(dp[(n - 3) % 6] % mod)


def main():
	(x, y) = map(int, input().split())
	n = int(input())
	lst = [x, y, y - x, -x, -y, x - y]
	lst = list(map(lambda a: a % 1000000007, lst))
	print(lst[(n - 1) % len(lst)])
main()


import sys
import math
(x, y) = [int(v) for v in sys.stdin.readline().split()]
n = int(sys.stdin.readline())
r = 0
if n == 1:
	r = x
elif n == 2:
	r = y
else:
	t = []
	t.append(y - x)
	t.append(t[0] - y)
	t.append(t[1] - t[0])
	r = t[n % 3]
	if int(n / 3) % 2 == 0:
		r = -r
print(r % 1000000007)


def reverse_fibonacci(a, b, n):
	s = [a, b, b - a, -a, -b, a - b]
	mod = int(1000000000.0 + 7)
	return (s[(n - 1) % 6] % mod + mod) % mod
(x, y) = map(int, input().split())
n = int(input())
print(reverse_fibonacci(x, y, n) % int(1000000000.0 + 7))


(x, y) = map(int, input().split())
(n, l) = (int(input()), [x, y])
for i in range(1, 5):
	l.append(l[i] - l[i - 1])
(q, r) = (l[(n - 1) % 6], 10 ** 9 + 7)
print((r - abs(q) % r) % r if q < 0 else q % r)


import sys
(x, y) = map(int, input().split())
n = list(map(int, input().split()))[0]
a = []
a.append(x)
a.append(y)
for i in range(2, 7):
	a.append((a[i - 1] - a[i - 2]) % 1000000007)
if n == 1:
	print(x % 1000000007)
else:
	n = (n - 1) % 6
	print(a[n] % 1000000007)


(x, y) = map(int, input().split())
m = int(input())
s = [x, y, y - x, -x, -y, x - y]
print(s[(m - 1) % 6] % (10 ** 9 + 7))


(x, y) = map(int, input().split())
n = int(input())
l = [x, y, y - x, -x, -y, x - y]
fl = n % 6
fl -= 1
print(l[fl] % (10 ** 9 + 7))


INT_MAX = 1000000007
inp = list(map(int, input().split()))
x = inp[0]
y = inp[1]
n = int(input().strip())
arr = [x, y]
for _ in range(4):
	(x, y) = (y, y - x)
	arr.append(y)
print(arr[(n - 1) % 6] % INT_MAX)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def main():
	a = LI()
	n = I()
	n %= 6
	for i in range(4):
		a.append(a[-1] - a[-2])
	return a[n - 1] % mod
print(main())


from math import *
(x, y) = map(int, input().split())
mod = 10 ** 9 + 7
a = [x, y, y - x, -x, -y, x - y]
n = int(input())
print(a[(n - 1) % 6] % mod)


(x, y) = tuple(map(int, input().split()))
n = int(input())
answers = [x, y, y - x, -x, -y, -y + x]
print(answers[n % 6 - 1] % (10 ** 9 + 7))


import math
from collections import *
import sys
from functools import reduce
import time
from itertools import groupby

def input():
	return sys.stdin.readline()

def get_ints():
	return map(int, input().strip().split())

def get_list():
	return list(get_ints())

def get_string():
	return list(input().strip().split())

def printxsp(*args):
	return print(*args, end='')

def printsp(*args):
	return print(*args, end=' ')
DIRECTIONS = [(+0, +1), (+0, -1), (+1, +0), (+1, -1)]
NEIGHBOURS = [(-1, -1), (-1, +0), (-1, +1), (+0, -1), (+1, +1), (+1, +0), (+1, -1), (+0, +1)]
CAPS_ALPHABETS = {chr(i + ord('A')): i for i in range(26)}
SMOL_ALPHABETS = {chr(i + ord('a')): i for i in range(26)}
INF = float('inf')
S34t = time.time()
(x, y) = get_ints()
m = int(input())
mod = int(1000000000.0) + 7
arr = [x - y, x, y, y - x, -x, -y]
print(arr[m % 6] % mod)


(x, y) = map(int, input().split())
t = int(input())
ans = 0
if t == 1:
	ans = x
elif t == 2:
	ans = y
elif t % 3 == 0 and t / 3 % 2 == 0:
	ans = x - y
elif t % 3 == 0 and t / 3 % 2 != 0:
	ans = y - x
elif t % 3 == 1 and t // 3 % 2 != 0:
	ans = -x
elif t % 3 == 1 and t // 3 % 2 == 0:
	ans = x
elif t % 3 == 2 and t // 3 % 2 != 0:
	ans = -y
elif t % 3 == 2 and t // 3 % 2 == 0:
	ans = y
print(ans % (7 + 10 ** 9))


m = list(map(int, str.split(input())))
for _ in range(2, 6):
	m.append(m[-1] - m[-2])
print(m[(int(input()) - 1) % 6] % (10 ** 9 + 7))


(x, y) = map(int, input().split())
go = [x, y, y - x, -x, -y, x - y]
n = int(input())
if n <= 6:
	print(go[n - 1] % 1000000007)
else:
	print(go[n % 6 - 1] % 1000000007)


(x, y) = map(int, input().split())
n = int(input())
default_val = 10 ** 9 + 7
ans = [x, y, y - x, -x, -y, x - y]
print(ans[(n - 1) % 6] % default_val)


import math
t = input()
s = input()
temp = t.split()
List = [int(i) for i in temp]
f1 = List[0]
f2 = List[1]
f3 = f2 - f1
f4 = -f1
f5 = -f2
f6 = -f3
n = int(s)
x = math.pow(10, 9) + 7
modulus = n % 6
if modulus == 1:
	fn = f1
elif modulus == 2:
	fn = f2
elif modulus == 3:
	fn = f3
elif modulus == 4:
	fn = f4
elif modulus == 5:
	fn = f5
elif modulus == 0:
	fn = f6
print(int(fn % x))


(x, y) = map(int, input().split())
n = (int(input()) - 1) % 6
refer = [x, y, y - x, -x, -y, x - y]
res = refer[n]
res %= 1000000007
print(res)


ls = list(map(int, input().split()))
n = int(input())
ans = 0
if n % 2 == 0:
	if n % 3 == 0:
		ans = ls[0] - ls[1]
	elif n % 3 == 1:
		ans = ls[0] * -1
	else:
		ans = ls[1]
elif n % 3 == 0:
	ans = ls[1] - ls[0]
elif n % 3 == 1:
	ans = ls[0]
else:
	ans = ls[1] * -1
print(ans % 1000000007)


(x, y) = map(int, input().split(' '))
n = int(input())
l = [x, y, y - x, -x, -y, x - y]

def f(n):
	a = l[n % 6 - 1]
	return a % (10 ** 9 + 7)
print(f(n))


(x, y) = (int(_) for _ in input().split(' '))
n = int(input())
out = [x - y, x, y, y - x, -x, -y]
print(out[n % 6] % (10 ** 9 + 7))


def main():
	(x, y) = [int(i) for i in input().split()]
	n = int(input())
	result = [x, y, y - x, -x, -y, x - y][(n - 1) % 6]
	print(result % 1000000007)
main()


(x, y) = map(int, input().split())
n = int(input())
a1 = x
a2 = y
a3 = y - x
a4 = -a1
a5 = -a2
a6 = -a3
rem = n % 6
if rem == 1:
	print(a1 % 1000000007)
elif rem == 2:
	print(a2 % 1000000007)
elif rem == 3:
	print(a3 % 1000000007)
elif rem == 4:
	print(a4 % 1000000007)
elif rem == 5:
	print(a5 % 1000000007)
elif rem == 0:
	print(a6 % 1000000007)


x = {}
(x[0], x[1]) = map(int, input().split())
num = int(input())
for i in range(2, 6):
	x[i] = x[i - 1] - x[i - 2]
idx = num % 6 - 1
if idx == -1:
	idx = 5
print(x[idx] % 1000000007)


(x, y) = list(map(int, input().split()))
d = [x, y, y - x, -x, -y, x - y]
l = int(input())
print(d[(l - 1) % 6] % (10 ** 9 + 7))


import copy
(x, y) = (int(z) for z in input().split(' '))
n = int(input())
m = 1000000007

class matrix:

	def __init__(self, rows, cols=None, identity_matrix=False, filler_function=None):
		if cols is None:
			cols = rows
		if identity_matrix:
			self.matrix = [[int(row == col) for col in range(cols)] for row in range(rows)]
		elif filler_function is not None:
			self.matrix = [[int(filler_function()) for col in range(cols)] for row in range(rows)]
		else:
			self.matrix = [[0 for _ in range(cols)] for _ in range(rows)]
		self.rows = rows
		self.cols = cols

	def transpose(self):
		self.matrix = [[self[col, row] for col in range(self.cols)] for row in range(self.rows)]
		return self

	def __setitem__(self, coordinates, value):
		(row, col) = coordinates
		self.matrix[row][col] = value

	def __getitem__(self, coordinates):
		(row, col) = coordinates
		return self.matrix[row][col]

	def __mul__(self, B):
		A = self
		C = matrix(A.rows, B.cols)
		Am = A.matrix
		Bm = B.matrix
		Cm = C.matrix
		for i in range(A.rows):
			for j in range(B.cols):
				for k in range(A.cols):
					Cm[i][j] += Am[i][k] % m * (Bm[k][j] % m)
					Cm[i][j] %= m
		return C

	def __pow__(self, power):
		current_power = 1
		power_matrix = copy.deepcopy(self)
		current_matrix = matrix(self.rows, identity_matrix=True)
		while current_power <= power:
			if current_power & power:
				current_matrix = current_matrix * power_matrix
			current_power *= 2
			power_matrix = power_matrix * power_matrix
		return current_matrix

	def __str__(self):
		output = ''
		for row in self.matrix:
			for value in row:
				output += str(value) + ' '
			output += '\n'
		return output.strip()
F = matrix(2, 2)
F[0, 0] = 1
F[0, 1] = -1
F[1, 0] = 1
F[1, 1] = 0
v = matrix(2, 1)
v[0, 0] = y
v[1, 0] = x
print((F ** (n - 1) * v)[1, 0])


m = 1000000000.0 + 7

def mod(p):
	return int(p % m)
(x, y) = [int(xx) for xx in input().split()]
n = int(input())
a = [mod(x - y), mod(x), mod(y), mod(y - x), mod(-x), mod(-y)]
print(a[n % 6])


p = input().split(' ')
a = int(p[0])
b = int(p[1])
n = int(input())
if n == 1:
	print(a % 1000000007)
else:
	MOD = 1000000007
	l = [a, b, b - a, -a, -b, a - b]
	print(l[(n - 1) % 6] % MOD)


k = list(map(int, input().split()))
a = k[0]
b = k[1]
dict = {0: -b + a, 1: a, 2: b, 3: b - a, 4: -a, 5: -b}
n = int(input())
n = n % 6
print(dict[n] % 1000000007)


(x, y) = (int(x) for x in input().split())
n = int(input()) - 1
pattern = [x, y, y - x, -x, -y, x - y]
print(pattern[n % 6] % int(1000000000.0 + 7))


(x, y) = map(int, input().split())
a = int(input())
s = 0
if a % 3 == 0:
	n = a // 3
	s = (-1) ** n * (x - y)
elif a % 3 == 1:
	n = (a - 1) // 3
	s = (-1) ** n * x
else:
	n = (a - 2) // 3
	s = (-1) ** n * y
print(s % (10 ** 9 + 7))


(a, b) = map(int, input().split())
x = int(input())
l = [a, b]
for i in range(2, 6):
	l.append(l[-1] - l[-2])
print(l[(x - 1) % 6] % (10 ** 9 + 7))


(x, y) = [int(x) for x in input().split(' ')]
n = int(input())
d = 1000000007
data = [x, y, y - x, -x, -y, x - y]
print(data[n % 6 - 1] % d)


l1 = [int(x) for x in input().split()]
x = l1[0]
y = l1[1]
n = int(input())
f = [x, y, y - x, -x, -y, x - y]
ind = n % 6
if ind == 0:
	print(f[5] % 1000000007)
else:
	print(f[ind - 1] % 1000000007)


san = list(map(int, input().split()))
n = int(input())
for i in range(2, 6):
	san.append(san[i - 1] - san[i - 2])
f = san[n % 6 - 1]
print(f % (10 ** 9 + 7))


import sys
(f1, f2) = map(int, sys.stdin.readline().split())
n = int(sys.stdin.readline())
f3 = f2 - f1
f4 = -f1
f5 = -f2
f6 = -f3
f = [f6, f1, f2, f3, f4, f5]
print(f[n % 6] % (10 ** 9 + 7))


(x, y) = (int(x) for x in input().split())
f = (x - y, x, y, y - x, -x, -y)
print(f[int(input()) % 6] % 1000000007)


from collections import defaultdict, deque, Counter, OrderedDict
import math

def main():
	(a, b) = [int(i) for i in input().split()]
	n = int(input())
	mod = 1000000007
	c = (b - a + mod) % mod
	n = (n - 1) % 6
	ans = [a, b, c, -a, -b, -c][n]
	print((ans + mod) % mod)
main()


m = 10 ** 9 + 7
(a, b) = map(int, input().split())
n = int(input())
n = n % 6
if n == 1:
	print(a % m)
elif n == 2:
	print(b % m)
elif n == 3:
	print((b - a) % m)
elif n == 4:
	print(-1 * a % m)
elif n == 5:
	print(-1 * b % m)
else:
	print((a - b) % m)


def main():
	(x, y) = map(int, input().split())
	n = int(input())
	if n // 3 % 2:
		if n % 3 == 1:
			print(-x % 1000000007)
		elif n % 3 == 2:
			print(-y % 1000000007)
		else:
			print((y - x) % 1000000007)
	elif n % 3 == 1:
		print(x % 1000000007)
	elif n % 3 == 2:
		print(y % 1000000007)
	else:
		print((x - y) % 1000000007)
main()


a = [int(i) for i in input().split()]
n = int(input())
a.append(a[1] - a[0])
s = n % 3
if n % 3 != 0:
	if (int(n / 3) + 1) % 2 != 0:
		if s == 0:
			print(a[2] % 1000000007)
		elif s == 1:
			print(a[0] % 1000000007)
		else:
			print(a[1] % 1000000007)
	elif s == 0:
		print(a[2] * -1 % 1000000007)
	elif s == 1:
		print(a[0] * -1 % 1000000007)
	else:
		print(a[1] * -1 % 1000000007)
elif int(n / 3) % 2 != 0:
	if s == 0:
		print(a[2] % 1000000007)
	elif s == 1:
		print(a[0] % 1000000007)
	else:
		print(a[1] % 1000000007)
elif s == 0:
	print(a[2] * -1 % 1000000007)
elif s == 1:
	print(a[0] * -1 % 1000000007)
else:
	print(a[1] * -1 % 1000000007)


(x, y) = input().split()
n = int(input())
x = int(x)
y = int(y)
mod1 = 1000000007
if n % 6 == 1:
	print(x % mod1)
if n % 6 == 2:
	print(y % mod1)
if n % 6 == 3:
	print((y - x) % mod1)
if n % 6 == 4:
	print(x * -1 % mod1)
if n % 6 == 5:
	print(-1 * y % mod1)
if n % 6 == 0:
	print((x - y) % mod1)


(x, y) = input().split()
n = input()
x = int(x)
y = int(y)
n = int(n)
n = (n - 1) % 6 + 1
while n > 1:
	n -= 1
	tmp = y - x
	x = y
	y = tmp
while x < 0:
	x += 1000000007
print(x % 1000000007)


def print_result(n):
	mod = 10 ** 9 + 7
	if n == 1:
		print(x % mod)
	elif n == 2:
		print(y % mod)
	elif n == 3:
		print((y - x) % mod)
	elif n == 4:
		print(-1 * x % mod)
	elif n == 5:
		print(-1 * y % mod)
	else:
		print((x - y) % mod)
(x, y) = input().split()
x = int(x)
y = int(y)
n = int(input())
mod = n % 6
if mod == 0:
	mod = 6
print_result(mod)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
(x, y) = invr()
n = inp()
k = 10 ** 9 + 7
if n % 6 == 0:
	print((x - y) % k)
elif n % 6 == 1:
	print(x % k)
elif n % 6 == 2:
	print(y % k)
elif n % 6 == 3:
	print((y - x) % k)
elif n % 6 == 4:
	print(-x % k)
elif n % 6 == 5:
	print(-y % k)


import sys
input = sys.stdin.readline

def gint():
	return int(input())

def gint_arr():
	return list(map(int, input().split()))

def gfloat():
	return float(input())

def gfloat_arr():
	return list(map(float, input().split()))

def pair_int():
	return map(int, input().split())
INF = 1 << 31
dx = [-1, 0, 1, 0]
dy = [0, 1, 0, -1]
(x, y) = gint_arr()
z = y - x
n = gint() % 6
a = [x, y, z, -x, -y, -z]
print(a[n - 1] % 1000000007)


def main():
	(x, y) = map(int, input().split())
	(M, i) = (10 ** 9 + 7, 2)
	ans = [x, y]
	while i < 6:
		n = y - x
		ans.append(n % M)
		x = y
		y = n
		i += 1
	n = int(input())
	print(ans[(n - 1) % 6] % M)
main()


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return s[:len(s) - 1]

def invr():
	return map(int, input().split())
(f1, f2) = invr()
N = inp()

def fn(N, f1, f2, mod):
	if (N - 1) % 6 == 0:
		return f1 % mod
	elif (N - 1) % 6 == 1:
		return f2 % mod
	elif (N - 1) % 6 == 2:
		return (f2 - f1) % mod
	elif (N - 1) % 6 == 3:
		return -f1 % mod
	elif (N - 1) % 6 == 4:
		return -f2 % mod
	elif (N - 1) % 6 == 5:
		return (f1 - f2) % mod
print(fn(N, f1, f2, 1000000007))


(x, y) = map(int, input().split())
n = int(input())
arr = [x, y, y - x, -x, -y, x - y]
print((1000000007 * 100 + arr[(n - 1) % 6]) % 1000000007)


(x, y) = map(int, input().split())
n = int(input())
f3 = y - x
l = [x, y, f3]
a = (n - 1) / 3
if int(a) % 2 == 0:
	print(l[(n - 1) % 3] % 1000000007)
else:
	print(l[(n - 1) % 3] * -1 % 1000000007)


(n, m) = input().split()
n = int(n)
m = int(m)
x = int(input())
s = 0
if x % 3 == 0:
	s = m - n
elif x % 3 == 1:
	s = n
else:
	s = m
if x % 6 == 4 or x % 6 == 5 or x % 6 == 0:
	s = -s
print(s % 1000000007)


xy = list(input().split())
x = int(xy[0])
y = int(xy[1])
n = int(input())
if n % 6 == 0:
	k = x - y
elif n % 6 == 5:
	k = -y
elif n % 6 == 4:
	k = -x
elif n % 6 == 3:
	k = y - x
elif n % 6 == 2:
	k = y
else:
	k = x
print(k % 1000000007)


s1 = input()
n = int(input())
s2 = s1.split()
(x, y) = (int(s2[0]), int(s2[1]))
f1 = x % 1000000007
f2 = y % 1000000007
f3 = (y - x) % 1000000007
ans = -1
if (n - 1) % 3 == 0:
	t = (n - 1) // 3
	ans = (-1) ** t * f1 % 1000000007
elif (n - 2) % 3 == 0:
	t = (n - 2) // 3
	ans = (-1) ** t * f2 % 1000000007
else:
	t = (n - 3) // 3
	ans = (-1) ** t * f3 % 1000000007
print(ans)


I = lambda : map(int, input().split())
(x, y) = I()
n = int(input())
e = 10 ** 9 + 7
a = n % 3
f3 = y - x
if a == 0:
	b = n // 3
	if b % 2 == 0:
		print(-f3 % e)
	else:
		print(f3 % e)
else:
	b = n // 3
	if b % 2 == 0:
		if a == 1:
			print(x % e)
		else:
			print(y % e)
	elif a == 1:
		print(-x % e)
	else:
		print(-y % e)


from sys import stdin, stdout
import math
(x, y) = input().split()
x = int(x)
y = int(y)
f3 = y - x
ans = 0
n = int(input())
if n > 3:
	k = n % 3
	t = int(n / 3)
	if k == 0:
		if t % 2 == 0:
			ans = -f3
		else:
			ans = f3
	elif k == 1:
		if t % 2 == 0:
			ans = x
		else:
			ans = -x
	elif t % 2 == 0:
		ans = y
	else:
		ans = -y
elif n == 1:
	ans = x
elif n == 2:
	ans = y
else:
	ans = f3
while ans < 0:
	ans = ans + 1000000007
else:
	ans = ans % 1000000007
print(ans)


import math
(x, y) = map(int, input().split())
n = int(input())
ans = [x - y, x, y, y - x, 0 - x, 0 - y]
a = n % 6
print(ans[a] % 1000000007)


import sys
import math
(x, y) = map(int, input().split())
n = int(input())
(f1, f2) = (x, y)
comma = [f1, f2, f2 - f1, -1 * f1, -1 * f2, f1 - f2]
print(comma[(n - 1) % 6] % 1000000007)


R1 = lambda : list(map(int, input().split()))
R2 = lambda : int(input())
(x, y) = R1()
n = R2()
a = [0, x, y, y - x, -x, -y, x - y]
r = n % 6 if n % 6 != 0 else 6
print(a[r] % 1000000007)


def main():
	MOD = 1000000007
	(x, y) = map(int, input().split(' '))
	n = int(input())
	out = [x - y, x, y, y - x, -x, -y]
	ret = out[n % 6]
	print(ret % MOD)
main()


(x, y) = map(int, input().split())
num = int(input())
num %= 6
num = num if num != 0 else num + 6
(t, l) = (x, y)
for _ in range(num - 2):
	(x, y) = (y, y - x)
	x %= 10 ** 9 + 7
	y %= 10 ** 9 + 7
if num == 1:
	print(t % (10 ** 9 + 7))
elif num == 2:
	print(l % (10 ** 9 + 7))
else:
	print(y)


import math

def main():
	(x, y) = map(int, input().split())
	n = int(input())
	seq = [x, y, y - x, -x, -y, x - y]
	if n > 6:
		print(seq[(n - 1) % 6] % 1000000007)
	else:
		print(seq[n - 1] % 1000000007)
main()


(x, y) = map(int, input().split())
n = int(input())
l = []
hell = 1000000007
hell = int(hell)
for i in range(1000):
	l.append(0)
l[0] = x
l[1] = y
for i in range(2, 6):
	l[i] = (l[i - 1] % hell - l[i - 2] % hell) % hell
n -= 1
print(l[n % 6] % hell)


def mi():
	return map(int, input().split(' '))
mod = 1000000007
(x, y) = mi()
n = int(input())
d = {}
d[1] = x
d[2] = y
d[3] = y - x
d[4] = -x
d[5] = -y
d[0] = -d[3]
print(d[n % 6] % mod)


def cycle(lst, n):
	lst.append(lst[1] - lst[0])
	s = pow(-1, abs(n - 1) // 3)
	n = (n - 1) % 3
	return lst[n] * s % (pow(10, 9) + 7)
lst = [int(x) for x in input().split()]
n = int(input())
print(cycle(lst, n))


(x, y) = map(int, input().split())
a = [x, y, y - x, -x, -y, x - y]
n = int(input()) - 1
modn = int(1000000000.0 + 7)
print((a[n % 6] + modn) % modn)


(x, y) = [int(i) for i in input().split()]
n = int(input())
a = [x, y]
b = 0
c = 1
for i in range(4):
	k = a[c] - a[b]
	a.append(k)
	c += 1
	b += 1
n = (n - 1) % 6
print(a[n] % (10 ** 9 + 7))