Implement a modified Fibonacci sequence using the following definition:

Given terms $t\left[i\right]$ and $t[i+1]$ where $i\in(1,\infty)$, term $t[i+2]$ is computed as:
  $t_{i+2}=t_{i}+(t_{i+1})^{2}$      

Given three integers, $\mbox{t1}$, $\mbox{t2}$, and $n$, compute and print the $n^{th}$ term of a modified Fibonacci sequence.

Example 

$t1=0$ 

$t2=1$ 

$n=6$

$t3=0+1^2=1$  
$t4=1+1^2=2$  
$t5=1+2^2=5$  
$t6=2+5^2=27$  

Return $27$.  

Function Description  

Complete the fibonacciModified function in the editor below.  It must return the $n^{th}$ number in the sequence.  

fibonacciModified has the following parameter(s):  

int t1: an integer  
int t2: an integer  
int n: the iteration to report  

Returns  

int: the $n^{th}$ number in the sequence  

Note: The value of $t[n]$ may far exceed the range of a $\mbox{64}$-bit integer. Many submission languages have libraries that can handle such large results but, for those that don't (e.g., C++), you will need to compensate for the size of the result.  

Input Format

A single line of three space-separated integers, the values of $\mbox{t1}$, $\mbox{t2}$, and $n$.

Constraints

$0\leq t1,t2\leq2$
$3\leq n\leq20$  
$t_n$ may far exceed the range of a $\mbox{64}$-bit integer. 

Sample Input
0 1 5

Sample Output
5

Explanation

The first two terms of the sequence are $t1=0$ and $t2=1$, which gives us a modified Fibonacci sequence of $\{0,1,1,2,5,27,\ldots\}$.  The $5^{th}$ term is $5$.

Difficulty: MEDIUM

Solutions:
(a, b, n) = [int(x) for x in input().split(' ')]
if n == 0:
	print(a)
if n == 1:
	print(b)
for _ in range(n - 2):
	(a, b) = (b, b * b + a)
print(b)


x = input('').split(' ')
first = int(x[0])
second = int(x[1])
r = int(x[2])
r -= 2
for g in range(r):
	z = first
	zz = second
	second = zz * zz + z
	first = zz
print(second)


lineStr = input().split()
a = int(lineStr[0])
b = int(lineStr[1])
n = int(lineStr[2])
i = 3
ans = 0
while 1:
	ans = a + b ** 2
	a = b
	b = ans
	if i == n:
		break
	else:
		i += 1
print(ans)


(A, B, N) = (int(x) for x in input().split())
N = N - 3

def fibo(a, b, n):
	if n == 0:
		return b ** 2 + a
	return fibo(b, b ** 2 + a, n - 1)
print(fibo(A, B, N))


str = input('')
ints = str.split(' ')
ints[0] = int(ints[0])
ints[1] = int(ints[1])
ints[2] = int(ints[2])
x = 2
y = ints[0]
z = ints[1]
n = ints[2]
num = 0
while x < n:
	temp = num
	num = z ** 2 + y
	y = z
	z = num
	x += 1
print(num)


inp = [int(x) for x in input().split()]
(A, B, N) = (inp[0], inp[1], inp[2])
C = 0
for i in range(3, N + 1):
	C = B * B + A
	A = B
	B = C
print(C)


[a, b, n] = input().split()
n = int(n)
a = int(a)
b = int(b)
c = 0
for i in range(2, n):
	if i != 2:
		b = c
	c = b * b + a
	a = b
print(c)


(A, B, N) = list(map(int, input().split()))

def fib(a, b, n):
	if n == 1:
		return a
	if n == 2:
		return b
	return fib(b, b ** 2 + a, n - 1)
print(fib(A, B, N))


(a, b, n) = map(int, input().split(' '))
solve = [a, b]

def fib(n):
	if len(solve) >= n:
		return solve[n - 1]
	temp = fib(n - 1) ** 2 + fib(n - 2)
	solve.append(temp)
	return temp
print(fib(n))


inputString = input().split()
a = int(inputString[0])
b = int(inputString[1])
c = int(inputString[2])

def recursiveFunction(firstTerm, secondTerm, n):
	if n == 1:
		return firstTerm
	elif n == 2:
		return secondTerm
	else:
		part1 = recursiveFunction(firstTerm, secondTerm, n - 1) ** 2
		part2 = recursiveFunction(firstTerm, secondTerm, n - 2)
		return part1 + part2
print(recursiveFunction(a, b, c))


import math
numbers = input()
x = numbers.split(' ')
a = int(x[0])
b = int(x[1])
n = int(x[2]) - 2
ans = 0
for x in range(0, n):
	ans = b * b + a
	a = b
	b = ans
print(ans)


import sys

def fibonacci_modified(a, b, n):
	if n < 3:
		raise Exception('n < 3')
	c = b * b + a
	if n == 3:
		return c
	else:
		return fibonacci_modified(b, c, n - 1)

def main():
	(a, b, n) = input().strip().split(' ')
	c = fibonacci_modified(int(a), int(b), int(n))
	print(c)
main()


import sys

def txt_read(r):
	s = r.readline()
	if s == '':
		return []
	a = s.split()
	return [int(v) for v in a]

def my_eval(i, j, k):
	count = 2
	while count < k:
		val = j ** 2 + i
		i = j
		j = val
		count += 1
	return val

def this_print(w, i, j, v):
	w.write(str(v) + '\n')

def txt_parser(r, w):
	while True:
		a = txt_read(r)
		if not a:
			return
		(i, j, k) = a
		val = my_eval(i, j, k)
		this_print(w, i, j, val)
		return
txt_parser(sys.stdin, sys.stdout)


(a, b, c) = map(int, input().split(' '))
dp = [a, b] + [0] * 50
for i in range(2, c):
	dp[i] = dp[i - 1] ** 2 + dp[i - 2]
print(dp[c - 1])


import sys
a = sys.stdin.readline().split()
numbers = []
numbers.append(int(a[0]))
numbers.append(int(a[1]))
for i in range(2, int(a[-1])):
	numbers.append(int(numbers[i - 1]) ** 2 + int(numbers[i - 2]))
print(numbers[-1])


import sys
(a, b, n) = sys.stdin.readline().split()
a = int(a)
b = int(b)
n = int(n)
answer = 0
c = 2
while c < n:
	answer = b ** 2 + a
	a = b
	b = answer
	c += 1
print(answer)


import sys

def read(r, w):
	s = r.readline()
	a = s.split()
	x = int(a[0])
	y = int(a[1])
	nth = int(a[2])
	if nth == 1:
		w.write(str(x) + '\n')
	elif nth == 2:
		w.write(str(y) + '\n')
	else:
		nth = nth - 2
		fib = 0
		while nth is not 0:
			fib = y ** 2 + x
			x = y
			y = fib
			nth -= 1
		w.write(str(fib) + '\n')
read(sys.stdin, sys.stdout)


(*terms, n) = map(int, input().split(' '))
while len(terms) < n:
	terms.append(terms[-1] ** 2 + terms[-2])
print(terms[n - 1])


INPUT = input()
[A, B, N] = INPUT.split()
SAVE1 = int(A)
SAVE2 = int(B)
SAVE3 = 0
count = 2
while count < int(N):
	SAVE3 = SAVE2 * SAVE2 + SAVE1
	SAVE1 = SAVE2
	SAVE2 = SAVE3
	count = count + 1
print(SAVE3)


args = [int(i) for i in input().split(' ')]
terms = args[0:2]
while args[2] > len(terms):
	n = len(terms)
	terms.append(terms[n - 1] ** 2 + terms[n - 2])
print(terms[-1])


import math

def fib_mod(a, b, n):
	if n == 1:
		return a
	elif n == 2:
		return b
	else:
		return fib_mod(a, b, n - 1) ** 2 + fib_mod(a, b, n - 2)

def main():
	nums = input().split(' ')
	print(int(fib_mod(int(nums[0]), int(nums[1]), int(nums[2]))))
main()


import sys

def fib():
	line = sys.stdin.readline()
	list = [int(x) for x in line.split()]
	A = list[0]
	B = list[1]
	N = list[2]
	for i in range(3, N + 1):
		C = B * B + A
		A = B
		B = C
	print(B)
fib()


inp = input()
[A, B, N] = [int(x) for x in inp.split()]
if N == 1:
	print(A)
elif N == 2:
	print(B)
else:
	for i in range(N - 2):
		C = B * B + A
		A = B
		B = C
	print(B)


import sys

def modFib(j, k, n):
	if n == 2:
		return k
	else:
		nK = k * k + j
		n -= 1
		return modFib(k, nK, n)
values = sys.stdin.read().split()
A = int(values[0])
B = int(values[1])
N = int(values[2])
print(modFib(A, B, N))


import sys

def mod_fib(first, second, n):
	if n == 1:
		return first
	elif n == 2:
		return second
	return mod_fib(first, second, n - 1) ** 2 + mod_fib(first, second, n - 2)
print(str(mod_fib(*map(int, sys.stdin.read().split()))))


import sys
s = sys.stdin.readline()
(a, b, n) = s.split()
a = int(a)
b = int(b)
n = int(n)
i = 2
while i < n:
	res = b ** 2 + a
	a = b
	b = res
	i += 1
sys.stdout.write(str(res))


no = [0] * 21
(no[0], no[1], N) = map(int, input().split())
for i in range(2, 21):
	no[i] = pow(no[i - 1], 2) + no[i - 2]
print(int(no[N - 1]))


from sys import stdin

def helper(t1, t2, depth):
	t3 = t1 + t2 * t2
	if depth is 3:
		return t3
	else:
		return helper(t2, t3, depth - 1)
input = stdin.readline().split(' ')
input = [int(x) for x in input]
print(int(helper(input[0], input[1], input[2])))


import math
abn = input()
line = abn.split()
tn = int(line[0])
tn1 = int(line[1])
n = int(line[2])
tn2 = 0
count = 3
while count <= n:
	tn2 = tn + tn1 ** 2
	tn = tn1
	tn1 = tn2
	count += 1
print(tn2)


termString = input()
termTuple = tuple(map(int, termString.split()))
assert len(termTuple) == 3
(a, b, n) = termTuple
for i in range(n - 2):
	temp = b
	b = a + b * b
	a = temp
print(b)


ints = input()
array = ints.split(' ')
first = int(array[0])
second = int(array[1])
termtocomp = int(array[2]) - 2
for i in range(termtocomp):
	third = first + second * second
	first = second
	second = third
print(third)


import sys, math
stdin = sys.stdin.read().split()
num1 = int(stdin[0])
num2 = int(stdin[1])
Count = int(stdin[2]) - 3

def fib(num1, num2, times):
	newNum = num2 ** 2 + num1
	if times > 0:
		return fib(num2, newNum, times - 1)
	else:
		return int(newNum)
print(fib(num1, num2, Count))


import re
s = input()
l = re.findall('\\d+', s)
a = int(l[0])
b = int(l[1])
b
n = int(l[2])
n = n - 2
output = b * b + a
while n > 0:
	output = b * b + a
	a = b
	b = output
	n = n - 1
print(output)


import sys

def fib(a, b, c):
	for i in range(2, c):
		result = a + b * b
		a = b
		b = result
	print(result)

def main():
	poop = sys.stdin.read()
	tokens = poop.split()
	a1 = tokens[0]
	b2 = tokens[1]
	c2 = tokens[2]
	a = int(a1)
	b = int(b2)
	c = int(c2)
	fib(a, b, c)
main()


line = input().split()
A = int(line[0])
B = int(line[1])
N = int(line[2])
sum = 0
for i in range(2, N):
	sum = B * B + A
	A = B
	B = sum
print(sum)


import sys

def fib(first, second, number):
	for i in range(2, number):
		temp = first + second * second
		first = second
		second = temp
	print(second)

def main():
	input = sys.stdin.read()
	(first, second, number) = input.split()
	first = int(first)
	second = int(second)
	number = int(number)
	fib(first, second, number)
main()


(A, B, N) = (int(x) for x in input().split())
while N - 2 > 0:
	(A, B) = (B, B ** 2 + A)
	N = N - 1
print(B)


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

def fib(x):
	if x == 1:
		return a
	elif x == 2:
		return b
	else:
		return fib(x - 1) ** 2 + fib(x - 2)
print(fib(n))


arr = input().split()
t1 = int(arr[0])
t2 = int(arr[1])
for i in range(2, int(arr[2])):
	res = t2 * t2 + t1
	t1 = t2
	t2 = res
print(t2)


mystring = input()
A = int(mystring[0])
B = int(mystring[2])
N = int(mystring[4:])
temp = 0
for x in range(2, N):
	temp = A + B ** 2
	A = B
	B = temp
print(B)


inval = input()
inval = inval.split()
t = int(inval[0])
tplus1 = int(inval[1])
n = int(inval[2])
tplus2 = tplus1 ** 2 + t
i = 3
while i < n:
	t = tplus1
	tplus1 = tplus2
	tplus2 = tplus1 ** 2 + t
	i += 1
print(tplus2)


def modFib(a, b, n):
	if n == 0:
		return b
	return modFib(b, b ** 2 + a, n - 1)
line = input().split()
print(modFib(int(line[0]), int(line[1]), int(line[2]) - 2))


import sys
for line in sys.stdin:
	l = []
	for item in line.split():
		try:
			l.append(int(item))
		except ValueError:
			pass
N = l[0]
NplusONE = l[1]
Nth = l[2]
NplusTWO = NplusONE * NplusONE + N
oldTerm = NplusONE
count = 3
while count < Nth:
	NplusTHREE = NplusTWO * NplusTWO + NplusONE
	NplusONE = NplusTWO
	NplusTWO = NplusTHREE
	nextTerm = NplusTHREE
	count = count + 1
print(round(nextTerm, 0))


import sys
import fileinput
nums = []
for line in fileinput.input():
	for i in line.split():
		try:
			nums.append(int(i))
		except ValueError:
			pass
a = nums[0]
b = nums[1]
temp = 0
index = 2
while index < nums[2]:
	temp = b
	b = b * b + a
	a = temp
	index = index + 1
print(b)


data = input().split()
A = int(data[0])
B = int(data[1])
N = int(data[2])
if N == 1 or N == 2:
	print(A if N == 1 else B)
	exit()
tmp = 0
for i in range(3, N + 1):
	tmp = A
	A = B
	B = tmp + B * B
print(B)


def foo(a, b, c):
	return foo(b, a + b * b, c - 1) if c > 0 else b
nums = list(map(int, input().split()))
print(foo(nums[0], nums[1], nums[2] - 2))


import sys
import string
var = input()
newvar = var.split(' ')
a = int(newvar[0])
b = int(newvar[1])
for i in range(2, int(newvar[2])):
	d = b * b + a
	a = b
	b = d
sys.stdout.write(str(d))


var = input()
newvar = var.split(' ')
tn1 = int(newvar[1])
tn = int(newvar[0])
n = int(newvar[2])
count = 2
i = 0
for i in range(2, n):
	tn2 = tn1 * tn1 + tn
	tn = tn1
	tn1 = tn2
	count = count + 1
	if count == n:
		print(tn2)


var = input()
newvar = var.split(' ')
tn1 = int(newvar[1])
tn = int(newvar[0])
n = int(newvar[2])
count = 2
i = 0
for i in range(2, n):
	tn2 = tn1 * tn1 + tn
	tn = tn1
	tn1 = tn2
	count = count + 1
	if count == n:
		print(tn2)


input_list = input().split(' ')
a = int(input_list[0])
b = int(input_list[1])
n = int(input_list[2])
answer_list = [a, b]
for number in range(2, n):
	answer_list.append(answer_list[number - 1] * answer_list[number - 1] + answer_list[number - 2])
print(answer_list[n - 1])


__author__ = 'omaransari'

def algo():
	a = ''
	b = ''
	c = ''
	recurse = 0
	stuff = input()
	(a, b, c) = stuff.split()
	first = 0
	second = 0
	third = 0
	first = int(a)
	second = int(b)
	third = int(c)
	for x in range(0, third - 2):
		recurse = first + second * second
		first = second
		second = recurse
	return recurse
i = 0
i = algo()
print(int(i))


import sys
import re
for line in sys.stdin:
	inp = line
line = [t for t in re.split('(\\s+[0-9]+)', line)]
line = [t for t in line if not t.isspace() and (not t == '')]
A = int(line[0])
B = int(line[1])
N = int(line[2])
while N > 2:
	temp = B
	B = B ** 2 + A
	A = temp
	N -= 1
print(B)


response = input()
values = response.split()
a = int(values[0])
b = int(values[1])
n = int(values[2])
while n > 2:
	a = a + b * b
	a = a + b
	b = a - b
	a = a - b
	n = n - 1
print(b)


var = input()
var2 = var.split(' ')
a = int(var2[0])
b = int(var2[1])
c = int(var2[2])
for i in range(2, c):
	d = b * b + a
	a = b
	b = d
print(d)


import string, sys
inputString = input()
nums = inputString.split()
A = int(nums[0])
B = int(nums[1])
N = int(nums[2])
for x in range(2, N):
	temp = B
	B = B * B + A
	A = temp
print(B)


inputs = input()
nums = inputs.split()
A = int(nums[0])
B = int(nums[1])
N = int(nums[2])
for i in range(N - 2):
	C = B * B + A
	A = B
	B = C
print(C)


numbers = tuple(map(int, input().split()))
(A, B, N) = numbers

def get_nth(n, n_1, N_counter=3):
	if N == 1:
		return A
	elif N == 2:
		return B
	else:
		n_2 = n_1 ** 2 + n
		if N_counter == N:
			return n_2
		else:
			N_counter += 1
			return get_nth(n_1, n_2, N_counter)
print(get_nth(A, B))


def memoize(f):
	cache = {}
	return lambda *args: cache[args] if args in cache else cache.update({args: f(*args)}) or cache[args]

@memoize
def fib(n):
	return n if n < 2 else pow(fib(n - 1), 2) + fib(n - 2)

def fibonacci(n1, n2):
	return pow(n1, 2) + n2
rawInput = input()
inA = int(rawInput[0])
inB = int(rawInput[2])
inN = int(rawInput[4:])
lastn1 = inB
lastn2 = inA
for i in range(2, inN):
	temp = fibonacci(lastn1, lastn2)
	lastn2 = lastn1
	lastn1 = temp
print(lastn1)


def series(a, b, n):
	for i in range(n - 1):
		(a, b) = (b, b ** 2 + a)
	return a
line = input().split()
x = int(line[0])
y = int(line[1])
z = int(line[2])
print(series(x, y, z))


import sys
import math
(a, b, n) = [int(x) for x in sys.stdin.readline().split(' ')]
f = [a, b]
for i in range(2, n):
	f.append(f[i - 1] * f[i - 1] + f[i - 2])
print(f[n - 1])


def main():
	test = input('')
	items = test.split(' ')
	tn = int(items[0])
	tn1 = int(items[1])
	answer = tn1 * tn1 + tn
	for x in range(2, int(items[2])):
		answer = tn1 * tn1 + tn
		tn = tn1
		tn1 = answer
	print(answer)
main()


a = input().split()
b = int(a[1])
n = int(a[2])
a = int(a[0])
terms = [a, b]
for i in range(2, n):
	terms.append(terms[i - 1] ** 2 + terms[i - 2])
print(terms[n - 1])


import sys

def line(read, write):
	test = read.readline()
	lst = test.split()
	a = int(lst[0])
	b = int(lst[1])
	n = int(lst[2]) - 2
	fib = 0
	while n != 0:
		fib = b * b + a
		a = b
		b = fib
		n = n - 1
	write.write(str(fib))
line(sys.stdin, sys.stdout)


import sys
argString = sys.stdin.readline()
args = argString.split()
n1 = args[0]
n2 = args[1]
nth = args[2]
n1 = int(float(n1))
n2 = int(float(n2))
nth = int(float(nth))
solutions = []
solutions.append(n1)
solutions.append(n2)
for i in range(2, nth):
	tempSolution = solutions[i - 1] * solutions[i - 1] + solutions[i - 2]
	solutions.append(tempSolution)
finalSolution = solutions[len(solutions) - 1]
print(finalSolution)


s = input().split(' ')
a = int(s[0])
b = int(s[1])
n = int(s[2])
if n == 1:
	print(a)
elif n == 2:
	print(b)
else:
	f = 0
	for x in range(2, n):
		f = a + b * b
		a = b
		b = f
	print(f)


import sys
stored_fib = [-1 for i in range(21)]

def get_fib(N, stored_fib):
	if stored_fib[N] != -1:
		return stored_fib[N]
	stored_fib[N] = get_fib(N - 1, stored_fib) * get_fib(N - 1, stored_fib) + get_fib(N - 2, stored_fib)
	return stored_fib[N]
input_data = sys.stdin.readline()
input_data = input_data.split(' ')
A = int(input_data[0])
B = int(input_data[1])
N = int(input_data[2])
stored_fib[1] = A
stored_fib[2] = B
print(get_fib(N, stored_fib))


(a, b, N) = list(map(int, input().split()))
for i in range(2, N):
	c = b * b + a
	a = b
	b = c
print(b)


args = list(map(int, input().split(' ')))
modFib = [args[0], args[1]]
while len(modFib) < args[2]:
	modFib.append(int(modFib[-1] ** 2) + modFib[-2])
print(modFib[-1])


i1 = input('').split(' ')
last = int(i1[0])
current = int(i1[1])
target = int(i1[2])
it = 2
while it < target:
	newLast = current
	current = current * current + last
	last = newLast
	it = it + 1
print(current)


(a, b, n) = map(int, input().split())
for i in range(2, n):
	(a, b) = (b, b ** 2 + a)
print(b)


(a, b, n) = map(int, input().split())
fib = [a, b]
for i in range(2, n):
	fib.append(fib[i - 2] + fib[i - 1] ** 2)
print(fib[-1])


def series(a, b, n):
	if n == 0:
		return b
	answer = series(b, a + b * b, n - 1)
	return answer
ls = input().split(' ')
(a, b, n) = [int(x) for x in ls]
print(series(a, b, n - 2))


k = input()
g = k.split(' ')
a = int(g[0])
b = int(g[1])
n = int(g[2])
for x in range(3, n + 1):
	temp = b
	b = b * b + a
	a = temp
print(b)


def series(A, B, N):
	if N == 1:
		return A
	if N == 2:
		return B
	if N == 3:
		return A + B * B
	return series(B, A + B * B, N - 1)
args = [int(x) for x in input().split(' ')]
print(series(args[0], args[1], args[2]))


p = input()
r = p.split()
a = int(r[0])
b = int(r[1])
n = int(r[2])
i = 2
while i <= n:
	r.insert(i, int(r[i - 1]) * int(r[i - 1]) + int(r[i - 2]))
	i = i + 1
print(r[n - 1])


(a, b, n) = [int(x) for x in input().split()]
f = []
f.insert(0, a)
f.insert(1, b)
for i in range(2, n):
	f.insert(i, f[i - 2] + f[i - 1] * f[i - 1])
print(f[n - 1])


(A, B, N) = [int(x) for x in input('').split(' ')]
if N == 1:
	print(A)
elif N == 2:
	print(B)
else:
	C = 0
	for k in range(N - 2):
		C = B * B + A
		k += 1
		A = B
		B = C
	print(C)


def solve(a, b, n):
	i = 2
	while True:
		(b, a) = (b ** 2 + a, b)
		i += 1
		if i == n:
			break
	return b
(a, b, n) = map(int, input().split())
if a == 0 and b == 0:
	print('0')
else:
	print(solve(a, b, n))


abn = [int(i) for i in input().strip().split()]
a = abn[0]
b = abn[1]
n = abn[2]
if n == 1:
	print(a)
elif n == 2:
	print(b)
else:
	i = 2
	while i < n:
		tmp = a + b ** 2
		a = b
		b = tmp
		i += 1
	print(b)


a = input()
a = [int(x) for x in a.split()]
N = a[-1]
a = a[:-1]
xN = a[1]
xN_1 = a[0]
i = 2
while i < N:
	temp = xN * xN + xN_1
	xN_1 = xN
	xN = temp
	i += 1
print(xN)


(a, b, n) = map(int, input().split())
n = n - 2
while n != 0:
	temp = b
	b = b * b
	b = b + a
	a = temp
	n = n - 1
print(b)


(a, b, n) = map(int, input().split())
x = [0 for i in range(n + 1)]
x[1] = a
x[2] = b
for i in range(3, n + 1):
	x[i] = x[i - 1] ** 2 + x[i - 2]
print(x[n])


str = input()
s = str.split()
a = int(s[0])
b = int(s[1])
n = int(s[2])
for i in range(n - 2):
	result = b * b + a
	temp = b
	b = result
	a = temp
print(result)


line = input()
(a, b, n) = line.split()
a = int(a)
b = int(b)
n = int(n)
i = 3
while i <= n:
	new = b * b + a
	a = b
	b = new
	i = i + 1
print(new)


input_values = list(map(int, input().split()))
a = input_values[0]
b = input_values[1]
n = input_values[2]
output = b
for i in range(2, n):
	output = a + b * b
	a = b
	b = output
print(output)


inStr = input()
inArray = inStr.split()
A = int(inArray[0])
B = int(inArray[1])
N = int(inArray[2])
i = 2
temp1 = A
temp2 = B
result = 0
while i < N:
	result = temp2 ** 2 + temp1
	temp1 = temp2
	temp2 = result
	i += 1
print(result)


(a, b, n) = map(int, input().split())
for i in range(n - 1):
	(a, b) = (b, a + b * b)
print(a)


def fib_modified(A, B, N):
	t0 = A
	t1 = B
	for i in range(2, N):
		t = t1 * t1 + t0
		t0 = t1
		t1 = t
	return t
(A, B, N) = [int(x) for x in input().split()]
print(fib_modified(A, B, N))


import sys
(a, b, n) = [int(s) for s in sys.stdin.readline().strip().split(' ')[:3]]
index = 2
while index < n:
	(a, b) = (b, a + b * b)
	index += 1
print(b)


def get_fibo(n, D):
	if n in D:
		return D[n]
	D[n] = get_fibo(n - 1, D) ** 2 + get_fibo(n - 2, D)
	return D[n]
lst = input().split(' ')
D = {}
D[1] = int(lst[0])
D[2] = int(lst[1])
print(get_fibo(int(lst[2]), D))


def fibs(n, a, b):
	if n == 1:
		return a
	if n == 2:
		return b
	if fib[n] != 0:
		return fib[n]
	fib[n] = fibs(n - 1, a, b) ** 2 + fibs(n - 2, a, b)
	return fib[n]
fib = []
fib = fib + [0] * 21
line = input()
inp = [int(x) for x in line.split(' ')]
res = fibs(inp[2], inp[0], inp[1])
print(res)


v = []

def f(n):
	if v[n - 1] == -1:
		v[n - 1] = f(n - 1) * f(n - 1) + f(n - 2)
	return v[n - 1]
x = input()
mynums = [int(i) for i in x.split()]
v = [-1 for y in range(mynums[2])]
v[0] = mynums[0]
v[1] = mynums[1]
print(f(mynums[2]))