Problem:


Score : 300 points

Problem Statement

Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively.
After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get:

Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result.

However, if the absolute value of the answer exceeds 10^{18}, print Unfair instead.

Constraints

1 \leq A,B,C \leq 10^9

0 \leq K \leq 10^{18}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B C K

Output

Print the integer Takahashi will get minus the integer Nakahashi will get, after repeating the following operation K times.
If the absolute value of the answer exceeds 10^{18}, print Unfair instead.

Sample Input 1

1 2 3 1

Sample Output 1

1

After one operation, Takahashi, Nakahashi and Hikuhashi have 5, 4 and 3, respectively. We should print 5-4=1.

Sample Input 2

2 3 2 0

Sample Output 2

-1

Sample Input 3

1000000000 1000000000 1000000000 1000000000000000000

Sample Output 3

0



Sample input:
1 2 3 1


Sample output:
1

Submission status: Wrong Answer

Solution code:
a = list(map(int,input().split()))

taka = a[0]
naka = a[1]
hiku = a[2]
kaisu = a[3]

def calc(taka, naka, hiku):
  return (naka + hiku, taka + hiku, taka + naka)

result = calc(taka, naka, hiku)

if a[3] !=  0:
    for i in range(1, kaisu + 1):
        result_list = calc(taka, naka, hiku)
    else:
        if abs((result_list[0] - result_list[1])) > 10 ** 18:
            print("Unfair")
        else:
            print(result_list[0] - result_list[1])
else:
    if abs((taka - naka)) > 10 ** 18:
        print("Unfair")
    else:
        print(taka - naka)

Submission status: Wrong Answer

Solution code:
a = list(map(int,input().split()))

taka = a[0]
naka = a[1]
hiku = a[2]
kaisu = a[3]

def calc(taka, naka, hiku):
  return (naka + hiku, taka + hiku, taka + naka)

result = calc(taka, naka, hiku)

if a[3] !=  0:
    for i in range(1, a[3] + 1):
        result_list = calc(taka, naka, hiku)
    else:
        if abs((result_list[0] - result_list[1])) > 10 ** 18:
            print("Unfair")
        else:
            print(result_list[0] - result_list[1])
else:
    if abs((taka - naka)) > 10 ** 18:
        print("Unfair")
    else:
        print(taka - naka)

Submission status: Wrong Answer

Solution code:
A,B,C,K = (int(i) for i in input().split())

if K==0:
    ans = A-B
elif K==1:
    tmpA = A
    tmpB = B
    A = B+C
    B= tmpA + C
    C = tmpA + tmpB
    ans = A-B
else:
    ans = 0

if ans>10**18:
    print("Unfair")
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
a = list(map(int,input().split()))

b = a[0]
c = a[1]
d = a[2]
e = a[3]

def calc(b, c, d):
  return (c + d, b + d, b + c)

result = calc(b, c, d)

if a[3] !=  0:
    for i in range(1, a[3] + 1):
        result_list = calc(b, c, d)
    else:
        if (result_list[0] - result_list[1]) > 10 ** 18:
            print("Unfair")
        else:
            print(result_list[0] - result_list[1])
else:
    if (b - c) > 10 ** 18:
        print("Unfair")
    else:
        print(b - c)

Submission status: Wrong Answer

Solution code:
da = list(map(int,input().split()))
 
m = 0
l = pow(10,18)
 
if da[3] <= 65 and da[0] != da[1]:
  m=1
def aaa(d,a,t):
  k = [0]*3
  k[0] = t + a
  k[1] = d + t
  k[2] = a + d
  return k
 
for i in range(da[3]):
  if da[0] == da[1]:
    break
  da = aaa(da[0],da[1],da[2])
  if abs(da[0] -da[1]) >= l or m == 1:
    break
if da[0] == da[1]:
  print(0)
elif abs(da[0] - da[1]) < l:
  print(da[0] - da[1])
elif abs(da[0] - da[1]) >= l:
  print("Unfair")

Submission status: Wrong Answer

Solution code:
a, b, c, k = map(int, input().split())

if pow(10,18) > abs(b-a):
	print(b-a)
else:
	print("Unfair")

Submission status: Wrong Answer

Solution code:
A,B,C,K = (int(i) for i in input().split())

if K==0:
    ans = B-A
elif K==1:
    tmpA = A
    tmpB = B
    A = B+C
    B= tmpA + C
    C = tmpA + tmpB
    ans = B-A
else:
    ans = 0

print(ans)

Submission status: Wrong Answer

Solution code:
a, b, c, k = map(int, input().split())

if pow(10,18) > b-a:
	print(b-a)
else:
	print("Unfair")

Submission status: Wrong Answer

Solution code:
a = list(map(int,input().split()))

b = a[0]
c = a[1]
d = a[2]
e = a[3]

if (b == c) and (c == d):
  print("0")

def calc(b, c, d):
  return (c + d, b + d, b + c)

result = calc(b, c, d)

if a[3] !=  0:
    for i in range(1, a[3] + 1):
        result_list = calc(b, c, d)
    else:
        if (result_list[0] - result_list[1]) > 10 ** 18:
            print("Unfair")
        else:
            print(result_list[0] - result_list[1])
else:
    if (b - c) > 10 ** 18:
        print("Unfair")
    else:
        print(b - c)

Submission status: Wrong Answer

Solution code:
A, B, C, K = map(int, input().split())
ans = 0
if K > 0:
    if K%2 == 0:
        ans = A - B
    else:
        ans = B - A
if ans <= 10**18:
    print(ans)
else:
    print('Unfair')

Submission status: Wrong Answer

Solution code:
da = list(map(int,input().split()))
 
m = 0
l = pow(10,18)
 
if da[3] <= 65 and da[0] != da[1]:
  m=1
 
def aaa(d,a,t):
  k = [0]*3
  k[0] = d + a
  k[1] = d + t
  k[2] = a + t
  return k
 
for i in range(da[3]):
  if da[0] == da[1]:
    break
  da = aaa(da[0],da[1],da[2])
  if abs(da[0] -da[1]) >= l or m == 1:
    break
if da[0] == da[1]:
  print("0")
elif abs(da[0] - da[1]) < l:
  print(da[0] - da[1])
elif abs(da[0] - da[1]) >= l:
  print("Unfair")

Submission status: Wrong Answer

Solution code:
a = list(map(int,input().split()))

taka = a[0]
naka = a[1]
hiku = a[2]
kaisu = a[3]

if (taka == naka) and (naka == hiku):
  print("0")

def calc(taka, naka, hiku):
  return (naka + hiku, taka + hiku, taka + naka)

result = calc(taka, naka, hiku)

if a[3] !=  0:
    for i in range(1, a[3] + 1):
        result_list = calc(taka, naka, hiku)
    else:
        if (result_list[0] - result_list[1]) > 10 ** 18:
            print("Unfair")
        else:
            print(result_list[0] - result_list[1])
else:
    if (taka - naka) > 10 ** 18:
        print("Unfair")
    else:
        print(taka - naka)

Submission status: Wrong Answer

Solution code:
a,b,c,k = list(map(int,input().split()))
ans = 0
if k%2 == 0:
    ans = a -b
else:
    if k == 1:
        ans = b-a
    else:
        if int(k/2)%2 == 0:
            ans = -a +b
        else:
            ans = a+b

if abs(ans) > pow(10,18):
    ans = 'Unfair'
print(ans)

Submission status: Wrong Answer

Solution code:
da = list(map(int,input().split()))
 
m = 0
l = pow(10,18)
 
if da[3] <= 65 and da[0] != da[1]:
  m=1
 
def aaa(d,a,t):
  k = [0]*3
  k[0] = d + a
  k[1] = d + t
  k[2] = a + t
  return k
 
for i in range(da[3]):
  if da[0] == da[1]:
    break
  da = aaa(da[0],da[1],da[2])
  if abs(da[0] -da[1]) >= l or m == 1:
    break
if da[0] == da[1]:
  print(0)
 
elif abs(da[0] - da[1]) < l:
  print(da[0] - da[1])
elif abs(da[0] - da[1]) >= l:
  print("Unfair")

Submission status: Wrong Answer

Solution code:
a,b,c,k = list(map(int,input().split()))
ans = 0
if k%2 == 0:
    ans = a -b
else:
    if k == 1:
        ans = b-a
    else:
        if int(k/2)%2 == 0:
            ans = -a +b
        else:
            ans = a+b

if ans > pow(10,18):
    ans = 'Unfair'
print(ans)

Submission status: Wrong Answer

Solution code:
a,b,c,k = list(map(int,input().split()))
ans = 0
print(a,b,c,k)
if k%2 == 0:
    ans = a -b
else:
    if k == 1:
        ans = b-a
    else:
        if int(k/2)%2 == 0:
            ans = -a +b
        else:
            ans = a+b

if ans > pow(10,18):
    ans = 'Unfair'
print(ans)

Submission status: Wrong Answer

Solution code:
da = list(map(int,input().split()))
 
m = 0
l = pow(10,18)

if da[3] <= 65 and da[0] != da[1]:
  m=1
 
def aaa(d,a,t):
  k = [0]*3
  k[0] = d + a
  k[1] = d + t
  k[2] = a + t
  return k
 
for i in range(da[3]):
  if da[0] == da[1]:
    break
  da = aaa(da[0],da[1],da[2])
  if abs(da[0] -da[1]) >= l or m == 1:
    break
 
if abs(da[0] - da[1]) < l:
  print(da[0] - da[1])
elif abs(da[0] - da[1]) >= l:
  print("Unfair")

Submission status: Wrong Answer

Solution code:
a = list(map(int,input().split()))

taka = a[0]
naka = a[1]
hiku = a[2]
kaisu = a[3]

if (taka == naka) and (naka == hiku):
  print("0")

def calc(taka, naka, hiku):
  return (naka + hiku, taka + hiku, taka + naka)

result = calc(taka, naka, hiku)

if a[3] !=  0:
    for i in range(1, a[3] + 1):
        result_list = calc(taka, naka, hiku)
        print(result_list)
    else:
        if (result_list[0] - result_list[1]) > 10 ** 18:
            print("Unfair")
        else:
            print(result_list[0] - result_list[1])
else:
    if (taka - naka) > 10 ** 18:
        print("Unfair")
    else:
        print(taka - naka)

Submission status: Wrong Answer

Solution code:
import math
a, b, c, k = map(int, input().split())

print(a - b)

Submission status: Wrong Answer

Solution code:
def mat_mult(a, b):
    c = [[0 for _ in range(3)] for _ in range(3)]
    for i in range(3):
        for j in range(3):
            for k in range(3):
                c[i][j] = a[i][k] * b[k][j]
    return c

def mat_pow(a, n):
    if n == 0:
        return [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
    elif n == 1:
        return a
    elif n % 2 == 0:
        return mat_pow(mat_mult(a, a), n // 2)
    else:
        return mat_mult(a, mat_pow(mat_mult(a, a), n // 2))

CAP = 1000000000000000000

def main():
    mat = [[0, 1, 1], [1, 0, 1], [1, 1, 0]]
    a, b, c, k = map(int, input().split())
    res = mat_pow(mat, k)
    tak = res[0][0] * a + res[0][1] * b + res[0][2] * c
    nie = res[1][0] * a + res[1][1] * b + res[1][2] * c
    if abs(tak - nie) > CAP:
        print('Unfair')
    else:
        print(tak - nie)

main()

Submission status: Wrong Answer

Solution code:
a, b, c, N = map(int, raw_input().split())

if N % 2 == 0:
    ans = a - b
else:
    ans = b - a

if abs(ans) > 10^18:
    print('Unfair')
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    [a, b, c, k] =[int(x) for x in input().split()]
    overflowk = 10 * 18
    ansk = a - b
    if abs(ansk) > overflowk:
        print("Unfair")
    else:
        if (k % 2 != 0):
            ansk = -ansk
        print(ansk)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def mat_mult(a, b):
    c = [[0 for _ in range(3)] for _ in range(3)]
    for i in range(3):
        for j in range(3):
            for k in range(3):
                c[i][j] = a[i][k] * b[k][j]
    return c

def mat_pow(a, n):
    if n == 0:
        return [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
    elif n == 1:
        return a
    elif n % 2 == 0:
        return mat_pow(mat_mult(a, a), n // 2)
    else:
        return mat_mult(a, mat_pow(mat_mult(a, a), n // 2))

CAP = int(1e18)

def main():
    mat = [[0, 1, 1], [1, 0, 1], [1, 1, 0]]
    a, b, c, k = map(int, input().split())
    res = mat_pow(mat, k)
    tak = res[0][0] * a + res[0][1] * b + res[0][2] * c
    nie = res[1][0] * a + res[1][1] * b + res[1][2] * c
    if abs(tak - nie) >= CAP:
        print('Unfair')
    else:
        print(tak - nie)

main()

Submission status: Wrong Answer

Solution code:
s = input().rstrip().split()
a = int(s[0])
b = int(s[1])
c = int(s[2])
k = int(s[3])

ans = a - b

if(k%2==1):
  ans = -1 * ans

if(abs(ans) < 100000000):
  print(ans)
else:
  print("Unfair")

Submission status: Wrong Answer

Solution code:
a, b, c, k = map(int, input().split())

def sc(k):
	ans = 0
	for c in str(k):
		ans += int(c)
	return ans

if k < 100000:
	for i in range(k):
		na = sc(b) + sc(c)
		nc = sc(b) + sc(a)
		nb = sc(a) + sc(c)

		a = na
		b = nb
		c = nc
else:
	# m = dict()
	# i = 0
	# while (a, b, c) not in m:
	# 	m[(a, b, c)] = i;
	# 	i += 1
	# 	na = sc(b) + sc(c)
	# 	nc = sc(b) + sc(a)
	# 	nb = sc(a) + sc(c)

	# 	a = na
	# 	b = nb
	# 	c = nc

	# # sunt la i si vreau sa ajung la k
	# p = i - m[(a, b, c)];

	# while (k -i) % p != 0:
	# 	i += 1
	# 	na = sc(b) + sc(c)
	# 	nc = sc(b) + sc(a)
	# 	nb = sc(a) + sc(c)

	# 	a = na
	# 	b = nb
	# 	c = nc

	for i in range(100000):
		na = sc(b) + sc(c)
		nc = sc(b) + sc(a)
		nb = sc(a) + sc(c)

		a = na
		b = nb
		c = nc
	if k % 2 == 0:
		print(a - b)
	else:
		print(b - a)
	exit(0)

print(a - b)

Submission status: Wrong Answer

Solution code:
A,B,C,K = (int(i) for i in input().split())

if A==B and B==C:
    print(0)
else:
    for i in range(K):
        tmpA = A
        tmpB = B
        A = tmpB+C
        B = C+tmpA
        C = tmpA + tmpB
        
        ans = A-B
        if abs(ans)>10**18:
            print("Unfair")
            break
        if i == (K-1):
            print(ans)

    
if K==0:
    print(A-B)

Submission status: Wrong Answer

Solution code:
A,B,C,K = (int(i) for i in input().split())

if A==B and B==C:
    print(0)
else:
    for i in range(K):
        tmpA = A
        tmpB = B
        A = tmpB+C
        B = C+tmpA
        C = tmpA + tmpB
        
        ans = A-B
        
        if i == (K-1):
            if abs(ans)>10**8:
                print("Unfair")
            #break
            else:
                print(ans)

    
if K==0:
    print(A-B)

Submission status: Wrong Answer

Solution code:
number = input()
a = number.split()


high=int(a[0])
middle=int(a[1])
low=int(a[2])
k=a[3]
k = int(k)

for i in range(k):
    high2 = middle + low
    #print(high2)
    middle2 = high + low
    #print(middle2)
    low2 = high + low
    if high2 or middle2 or low2 < 10**18:
        high = high2
        print(high)
        middle = middle2
        print(middle)
        low = low2
    else:
        answer = 'Unfair'
        break

answer = high - middle
print(answer)

Submission status: Wrong Answer

Solution code:
A,B,C,K = map(int, input().split())
if abs(A-B) >= 10**8 : 
 print("Unfair")
elif K%2 == 0 :
 print(A-B)
elif K%2 == 1 :
 print(B-A)

Submission status: Wrong Answer

Solution code:
a, b, c, N = map(int, raw_input().split())

if N % 2 == 0:
    ans = a - b
else:
    ans = b - a

if ans > 10^18:
    print('Unfair')
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
# coding: utf-8
# Your code here!
#print(num)

line = input().rstrip().split(" ")
#print(line)
map(int, line)
#print(line)

count = int(line[3])

ans = 0
li0 = int(line[0])
li1 = int(line[1])
li2 = int(line[2])

lia = 0
lib = 0
lic = 0


#print(count)
#if count == 0:
 #   ans = int(line[0]) - int(line[1])
#else:
if count >= 10 ** 18:
    print("Unfair")
else:
    for i in range(count):
        lia = li0
        lib = li1
        lic = li2
        li0 = lib + lic
        li1 = lia + lic
        li2 = lia + lib

    ans = li0 - li1
    print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    A, B, C, K = map(int, input().split())

    # TLE(A, B, C, K)
    f(A, B, C, K)


def f(A, B, C, K):
    """
    1: (A,B,C) = (    B  C,  A     C,  A  B   )
    2: (A,B,C) = (2A  B  C,  A 2B  C,  A  B 2C)
    3: (A,B,C) = (2A 3B 3C, 3A 2B 3C, 3A 3B 2C)
    4: (A,B,C) = (6A 5B 5C, 5A 6B 5C, 5A 5B 6C)
    """
    if A == B == C:
        print(0)
        return

    ans = (B - A) * (-1) ** (K - 1)
    print(ans)


def TLE(A, B, C, K):
    for i in range(K):
        bc = B + C
        ab = A + B
        ac = A + C
        print(A, B, C, bc, ab, ac, sep="\t")
        A = bc
        B = ac
        C = ab

    ans = A - B
    if abs(ans) > 10 ** 18:
        print("Unfair")
    else:
        print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
a, b, c, k = map(int, input().split())

def sc(k):
	ans = 0
	for c in str(k):
		ans += int(c)
	return ans

if k < 10000:
	for i in range(k):
		na = sc(b) + sc(c)
		nc = sc(b) + sc(a)
		nb = sc(a) + sc(c)

		a = na
		b = nb
		c = nc
else:
	m = dict()
	i = 0
	while (a, b, c) not in m:
		m[(a, b, c)] = i;
		i += 1
		na = sc(b) + sc(c)
		nc = sc(b) + sc(a)
		nb = sc(a) + sc(c)

		a = na
		b = nb
		c = nc

	# sunt la i si vreau sa ajung la k
	p = i - m[(a, b, c)];

	while (k -i) % p != 0:
		i += 1
		na = sc(b) + sc(c)
		nc = sc(b) + sc(a)
		nb = sc(a) + sc(c)

		a = na
		b = nb
		c = nc



print(a - b)

Submission status: Wrong Answer

Solution code:
A,B,C,K = (int(i) for i in input().split())

if A==B and B==C:
    print(0)
else:
    for i in range(K):
        tmpA = A
        tmpB = B
        A = tmpB+C
        B = C+tmpA
        C = tmpA + tmpB
        '''
        ans = A-B
        if abs(ans)>10**8:
            print("Unfair")
            break
        if i == (K-1):
            print(ans)
        '''
    
if K==0:
    print(A-B)    

ans = A-B
if abs(ans)>10**8:
    print("Unfair")
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
A,B,C,K = (int(i) for i in input().split())

if A==B and B==C:
    print(0)
else:
    for i in range(K):
        tmpA = A
        tmpB = B
        A = tmpB+C
        B = C+tmpA
        C = tmpA + tmpB
        ans = A-B
        if abs(ans)>10**8:
            print("Unfair")
            break
        if i == (K-1):
            print(ans)
    
if K==0:
    print(A-B)

Submission status: Wrong Answer

Solution code:
s = list(map(int, input().split()))
a, b, c, d = s[0], s[1], s[2], s[3]
if d%2==0:
    x = a-b
else:
    x = b-a

if x<=10**8:
    print(x)
else:
    print('Unfair')

Submission status: Wrong Answer

Solution code:
A,B,C,K = map(int, input().split())

if abs(A-B) > 10**(18):
    print("Unfair")
else:print(A-B)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
def inpl(): return map(int, input().split())
a, b, c, k = inpl()
if k >= 80:
    print("Unfair")
else:
    for _ in range(k):
        a, b, c = b+c, a+c, b+a
    ans = a - b
    if abs(ans) > 10**18:
        print("Unfair")
    else:
        print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
A,B,C,K=input().split()
A=int(A)
B=int(B)
C=int(C)
K=int(K)
if K==0:
    if A-B>10**18:
        print('unfair')
    else:
        print(A-B)
elif K==1:
    if A-B>10**18:
        print('unfair')
    else:
        print(B-A)
else:
    print (0)

Submission status: Wrong Answer

Solution code:
takahashi,nakahashi,hikuhashi,n=map(int,raw_input().split(' '))
t1=(nakahashi+hikuhashi)*n
t2=(takahashi+hikuhashi)*n
if n==0: print takahashi-nakahashi
elif abs(t1-t2)>(10**18): print "Unfair"
else: print t1-t2

Submission status: Wrong Answer

Solution code:
A,B,C,K = (int(i) for i in input().split())

if A==B and B==C:
    print(0)
else:
    for i in range(K):
        tmpA = A
        tmpB = B
        A = tmpB+C
        B = C+tmpA
        C = tmpA + tmpB
        ans = A-B
        if ans>10**8:
            print("Unfair")
            break
        if i == (K-1):
            print(ans)
    
if K==0:
    print(A-B)

Submission status: Wrong Answer

Solution code:
a,b,c,k = list(map(int,input().split()))
ta = tb = tc = 0
s = a+b+c
a = s*(k//4)+a
b = s*(k//4)+b
c = s*(k//4)+c
for i in range(k%4):
    ta = a
    tb = b
    tc = c
    a = tb+tc
    b = ta+tc
    c = ta+tb
print(a-b if abs(a-b) < 10*18 else 'Unfair')

Submission status: Wrong Answer

Solution code:
def main():
    A,B,C,K=[int(x) for x in input().split()]
    if abs(A-B)>10**18:
        print("Unfair")
    else:
        print(A-B)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
def inpl(): return map(int, input().split())
a, b, c, k = inpl()
k += 1
if k >= 70:
    print("Unfair")
else:
    if k%2 == 0:
        x = 2**k // 3 + 0
        y = 2**k // 3 + 1
        takahashi = a*x + b*y + c*y
        nakahashi = a*y + b*x + c*y
        ans = takahashi - nakahashi
        if abs(ans) > 10**18:
            print("Unfair")
        else:
            print(ans)
    else:
        x = 2**k // 3 + 1
        y = 2**k // 3 + 0
        takahashi = a*x + b*y + c*y
        nakahashi = a*y + b*x + c*y
        ans = takahashi - nakahashi
        if abs(ans) > 10**18:
            print("Unfair")
        else:
            print(ans)

Submission status: Wrong Answer

Solution code:
A,B,C,K = (int(i) for i in input().split())

if A==B and B==C:
    print(0)
else:
    for i in range(K):
        tmpA = A
        tmpB = B
        A = B+C
        B = C+tmpA
        C = tmpA + tmpB
        ans = A-B
        if ans>10**8:
            print("Unfair")
            break
        if i == (K-1):
            print(ans)
    
if K==0:
    print(A-B)

Submission status: Wrong Answer

Solution code:
#coding: utf-8

MAX = 1000000000000000000

def do(a,b,c):
    new_a = b + c
    new_b = a + c
    new_c = a + b

    a = new_a
    b = new_b
    c = new_c

    return (a,b,c)

if __name__ == "__main__":
    a,b,c,k = map(int, input().split(" "))
    result = []

    for i in range(k):
        a,b,c = do(a,b,c)
        if abs(a - b) > MAX:
            print("Unfair")
            exit()
        result.append(a-b)
        if len(result) > 10:
            break
    
    if len(result) > 6:
        if abs(result[2]) == abs(result[3]) and abs(result[4]) == abs(result[5]):
            if k % 2 == 0:
                print(result[2])
            if k % 2 == 1:
                print(result[3])
    else:
        print(a-b)

Submission status: Wrong Answer

Solution code:
a,b,c,k = map(int,input().split())
if (k % 2 == 0):
    ans = b-a
else:
    ans = a - b
if (ans > 10**18):
    print('Unfair')
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
A,B,C,K = (int(i) for i in input().split())

if A==B and B==C:
    print(0)
else:
    for i in range(K):
        tmpA = A
        tmpB = B
        A = B+C
        B = C+tmpA
        C = tmpA + tmpB
        ans = A-B
        if ans>10**8:
            break
        if i == (K-1):
            print(ans)
    
if K==0:
    print(A-B)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from sys import stdin


def solve():
    a, b, c, k = map(int, stdin.readline().split())

    if k == 0:
        print(a - b)
        return

    na = b + c
    nb = a + c

    res = na - nb
    res += ((a + a) - (b + b)) * (k - 1)
    print(res if abs(res) <= 1e18 else 'Unfair')


solve()

Submission status: Wrong Answer

Solution code:


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

if k % 2 == 0:
    print(a - b)
else:
    print(b - 1)

Submission status: Wrong Answer

Solution code:
A, B, C, K = map(int, input().split(' '))
if abs(A - B) > 10**18:
    print('Unfair')
elif K % 2 == 0:
    print(A - B)
else:
    print(C - B)

Submission status: Wrong Answer

Solution code:
A,B,C,K = (int(i) for i in input().split())

for i in range(K):
    tmpA = A
    tmpB = B
    A = B+C
    B = C+tmpA
    C = tmpA + tmpB
    ans = A-B
    if ans>10**8:
        break
    if i == (K-1):
        print(ans)
    
if K==0:
    print(A-B)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from sys import stdin


def solve():
    a, b, c, k = map(int, stdin.readline().split())

    if k == 0:
        print(a - b)
        return

    na = b + c
    nb = a + c

    res = na - nb
    res += ((a + a) - (b + b)) * (k - 1)
    print(res if res <= 1e18 else 'Unfair')


solve()

Submission status: Wrong Answer

Solution code:
a,b,c,k = list(map(int,input().split()))

if k%2 == 0:
    if abs(a-b) <= 10**18:
        print(a-b)
    else:
        print('Unfair')
else:
    if abs(c-b) <= 10**18:
        print(c-b)
    else:
        print('Unfair')

Submission status: Wrong Answer

Solution code:
A, B, C, K = map(int, input().split(' '))
if abs(A - B) >= 10**18:
    print('Unfair')
elif K % 2 == 0:
    print(A - B)
else:
    print(C - B)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from sys import stdin


def solve():
    a, b, c, k = map(int, stdin.readline().split())

    if k == 0:
        print(a - b)
        return

    na = b + c
    nb = a + c

    res = na - nb
    res += ((a + a) - (b + b)) * (k - 1)
    print(res if res <= 1e18 else -1)


solve()

Submission status: Wrong Answer

Solution code:
li = input().split()
a = int(li[0])
b = int(li[1])
c = int(li[2])
k = int(li[3])

A = a * (k - 1) + b * k + c * k
B = b * (k - 1) + a * k + c * k

if k == 0:
    print(a - b)
elif abs(A - B) > 10 ** 18:
    print("Unfair")
else:
    print(A - B)

Submission status: Wrong Answer

Solution code:
takahashi,nakahashi,hikuhashi,n=map(int,raw_input().split(' '))
t1=(nakahashi+hikuhashi)*n
t2=(takahashi+hikuhashi)*n
if n==0: print '-1'
elif abs(t1-t2)>(10**18): print "Unfair"
else: print t1-t2

Submission status: Wrong Answer

Solution code:
li = input().split()
a = int(li[0])
b = int(li[1])
c = int(li[2])
k = int(li[3])

A = a * (k - 1) + b * k + c * k
B = b * (k - 1) + a * k + c * k
C = c * (k - 1) + a * k + b * k

if k == 0:
    print(a - b)
elif A - B > 10 ** 18:
    print("Unfair")
else:
    print(A - B)

Submission status: Wrong Answer

Solution code:
'''input
2 3 2 0
'''
a,b,c,k = map(int,input().split())

for _ in range(k):
	s = a + b + c
	a = s - a
	b = s - b 
	c = s - c
	if s>10**25:
		break

print (a-b if a-b<=10**18 else "Unfair")

Submission status: Wrong Answer

Solution code:

# k=0
# a b c
# a-b

# k=1
# b+c c+a a+b
# b+a

# k=2
# 2a+b+c a+2b+c a+b+2c
# a-b
# equivalent to a,b,c

# k=3

import sys
#sys.stdin=open("data.txt")
input=sys.stdin.readline

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

if k%2==0: print(a-b)
else: print(a+b)

Submission status: Time Limit Exceeded

Solution code:
A, B, C, K = map(int, input().split())

if A == B:
    print(0)
else:
    for _ in range(K):
        tmp_A = B + C
        tmp_B = A + C
        C = A + B
        A = tmp_A
        B = tmp_B
        if A - B >= 10 ** 18:
            print(Unfair)
            break
    else:
        print(A-B)

Submission status: Time Limit Exceeded

Solution code:
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main():
    a,b,c,k = map(int,input().split())
    high=a
    middle=b
    low=c
    count=0

    while count<k:
        if abs(high-middle) >10**18:
            print("Unfair")
            exit()
        elif a == b == c:
            print(0)
            exit()
        high = b+c
        middle = a+c
        low = a+b
        a=high
        b=middle
        c=low
        count+=1
    print(high-middle) 
    

if __name__=="__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main():
    a,b,c,k = map(int,input().split())
    high=a
    middle=b
    low=c
    count=0

    while count<k:
        if a == b == c:
            print(0)
            exit()
        high = b+c
        middle = a+c
        low = a+b
        a=high
        b=middle
        c=low
        count+=1
    if abs(high-middle) >10**18:
        print("Unfair")
        exit()
    else:
        print(high-middle) 
    

if __name__=="__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
result = [0] * 3
a,b,c,k = map(int, input().split())

for i in range(k):
	result[0] = b + c
	result[1] = a + c
	result[2] = a + b

	a = result[0]
	b = result[1]
	c = result[2]

print("Unfair") if a-b > 10**18 else print(a-b)

Submission status: Time Limit Exceeded

Solution code:
A, B, C, K = map(int, input().split())
for _ in range(K):
  if A == B == C:
    break
  A, B, C = B + C, A + C, A + B
if abs(A - B) > 10 ** 18:
  print('Unfair')
else:
  print(A-B)

Submission status: Time Limit Exceeded

Solution code:
A, B, C, K = map(int, input().split())
for _ in range(K):
  if A == B == C:
    break
  A, B, C = B + C, A + C, A + B
if A - B > 10 ** 18:
  print('Unfair')
else:
  print(A-B)

Submission status: Time Limit Exceeded

Solution code:
a,b,c,k=map(int,input().split())

if a==b:
  print(0)
elif k==0:
  print(a-b)
else:
  for i in range(k):
    a,b,c = b+c,a+c,a+b
  if abs(a-b)>=10**18:
    print(-1)
  else:
    print(a-b)

Submission status: Time Limit Exceeded

Solution code:
a, b, c, k = map(int,input().split())

if a==b==c:
    print(0)
    exit()
    
for i in range(k):
    a_=b+c
    b_=a+c
    c_=a+b
    if abs(a_-b_) > 10**18:
        print('Unfair')
        exit()
    a=a_
    b=b_
    c=c_

if k==0:
    print(a-b)
else:
    print(a_-b_)

Submission status: Time Limit Exceeded

Solution code:
A,B,C,K = map(int,input().split())

for k in range(K):
  A2 = A
  B2 = B
  C2 = C
  A = B2 + C2
  B = A2 + C2
  C = A2 + B2
  
if abs(A-B) > 10000000000000000000:
  print("Unfair")
else:
  print(A-B)

Submission status: Time Limit Exceeded

Solution code:
a,b,c,K=list(map(int,input().split()))
if a==b and b==c:
  print("0")
  exit()
for i in range(K):
  an=a
  bn=b
  cn=c
  a=bn+cn
  b=an+cn
  c=an+bn
S=a-b
if a-b>=10**18:
  print("Unfair")
  exit()
print(a-b)

Submission status: Time Limit Exceeded

Solution code:
import copy
a,b,c,k = map(int,input().split())

if a == b == c:
    print(0)
    exit()

cnt = 0
while True:
    if cnt >= k:
        print(a - b)
        break
    aa = copy.deepcopy(a)
    bb = copy.deepcopy(b)
    cc = copy.deepcopy(c)

    a = bb + cc
    b = aa+cc
    c = aa + bb
    cnt += 1
    if abs(a-b) >= 10**18:
        print('Unfair')
        break

Submission status: Time Limit Exceeded

Solution code:
import copy
a,b,c,k = map(int,input().split())

if a == b == c:
    print(0)
    exit()

cnt = 0
while True:
    aa = copy.deepcopy(a)
    bb = copy.deepcopy(b)
    cc = copy.deepcopy(c)

    a = bb + cc
    b = aa+cc
    c = aa + bb
    cnt += 1
    if abs(a-b) >= 10**18:
        print('Unfair')
        break
    if cnt == k:
        print(a - b)
        break

Submission status: Time Limit Exceeded

Solution code:
A, B, C, K = map(int,input().split())
ans =  0
if A == B == C:
    ans = 0
    K = 0
while K > 0:
    a = A
    b = B
    c = C
    A = b + c
    B = a + c
    C = a + b
    K -= 1
ans = A - B
if abs(ans) > 10 ** 18:
    ans = 10 ** 18
print(ans)

Submission status: Time Limit Exceeded

Solution code:
A,B,C,K = map(int,input().split())
for i in range(K):
  a = B + C
  b = A + C
  c = A + B
  A = a
  B = b
  C = c
if A - B >= 10**18:
  print("Unfair")
else:
  print(A-B)

Submission status: Time Limit Exceeded

Solution code:
A, B, C, K = input().split(' ')
A = int(A)
B = int(B)
C = int(C)
K = int(K)
while True:
  if A==B==C:
    print(0)
    break

  else:
    for i in range(K):
      a = B + C
      b = A + C
      c = A + B
      A = a
      B = b
      C = c
    if A-B>10**18:
      print('Unfair')
    else:
      print(A-B)

Submission status: Time Limit Exceeded

Solution code:
A,B, C, K = map(int,input().split())
flag = 1
for k in range(K):
  A,B,C = B+C, C+A, A+B
  if abs(A-B) > 10**18:
    print("Unfair")
    flag = 0
    break
if flag:
  print(A-B)

Submission status: Time Limit Exceeded

Solution code:
A,B, C, K = map(int,input().split())
for k in range(K):
  A,B,C = B+C, C+A, A+B
if abs(A-B) > 10**18:
  print("Unfair")
else:
  print(A-B)

Submission status: Time Limit Exceeded

Solution code:
a,b,c,k=map(int,input().split())
if a==b and b==c:
    print(0)
else:
    for i in range(k):
        a,b,c=b+c,a+c,a+b
    if abs(a-b)>10**18:
        print("Unfair")
    else:
        print(a-b)

Submission status: Time Limit Exceeded

Solution code:
a,b,c,k = map(int, open(0).read().split())

if a!=b:
    n,m = 1,0
    for i in range(k):
        n,m = m*2,n+m
    print((a-b)*(n-m))
else:
    print(0)

Submission status: Time Limit Exceeded

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

A, B, C, K = mapint()
for _ in range(K):
    A, B, C = B+C, A+C, A+B
    if abs(A-B)>10**18:
        print('Unfair')
        break
    if A-B==0:
        print(0)
        break
else:
    print(A-B)

Submission status: Time Limit Exceeded

Solution code:
a, b, c, k = map(int, input().split())

for _ in range(1, k+1):
    a, b, c = b+c, a+c, a+b

ans = 'Unfair' if len(str(abs(a-b))) > 18 else a-b
print(ans)