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: Time Limit Exceeded

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

for i in range(K):
  ta = B+C
  tb = A+C
  tc = A+B
  A = ta
  B = tb
  C = tc
  if abs(A-B) > 10**18:
    print('Unfair')
    exit()
print(A-B)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def change(A,B,C):
    move=True
    a=A
    b=B
    c=C
    A=b+c
    B=a+c
    C=a+b
    if B-A==b-a:
        move=False
    return A,B,C,move
A,B,C,K=map(int,input().split())
ans=A-B
for i in range(K):
    A,B,C,move=change(A,B,C)
    ans=A-B
    if abs(ans)>1000000000000000000:
        print("Unfair")
        break
    elif not(move):
        print(ans)
        break
else:
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
def change(A,B,C):
    move=True
    a=A
    b=B
    c=C
    A=b+c
    B=a+c
    C=a+b
    if (a==A)&(b==B)&(c==C):
        move=False
    return A,B,C,move
A,B,C,K=map(int,input().split())
ans=A-B
for i in range(K):
    A,B,C,move=change(A,B,C)
    ans=A-B
    if abs(ans)>1000000000000000000:
        print("Unfair")
        break
    elif not(move):
        print(ans)
        break
    elif A==B:
        print(0)
        break
else:
    print(ans)

Submission status: Time Limit Exceeded

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

t = 1
while t<=K:
    a = B+C
    b = A+C
    C = a+b-2*C
    A = a
    B = b
    t+=1

ans = A - B

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

Submission status: Time Limit Exceeded

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

for i in range(k):
  shifta = b+c; shiftb = a+c; shiftc = a+b
  a=shifta; b=shiftb; c=shiftc
  
  if abs(a-b)>10**18:print("Unfair");exit

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 _ in range(K):
  A,B,C = B+C,A+C,A+B
  ans = abs(A-B)
  if ans > 10**18:
    print('Unfair')
    exit()

print(A-B)

Submission status: Time Limit Exceeded

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

def cal(a,b,c):
  a1 = b+c
  b1 = a+c
  c1 = b+c
  return(a1,b1,c1)
  
  
for i in range(K):
  A,B,C=cal(A,B,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())

for i in range(K):
    tmpA = B + C
    tmpB = A + C
    tmpC = A + B
    A = tmpA
    B = tmpB
    C = tmpC

    if A == B and B == C:
        break

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 == C:
    print(0)
else:
    x = 10**18
    for _ in range(K):
        a = B+C
        b = A+C
        c = A+B
        A=a
        B=b
        C=c
        if A - B > x:
            print("Unfair")
            break
    else:
        print(A-B)

Submission status: Time Limit Exceeded

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

flag = True
for i in range(10**18):
    if k == 0:
        break
    if a == b and b == c:
        break
    A = a
    B = b
    C = c
    a = B + C
    b = A + C
    c = A + B
    if i == k - 1:
        break
    if a - b > 10**18 or a-b < -10**18:
        flag = False
        break
if flag:
    print(a - b)
else:
    print('Unfair')

Submission status: Time Limit Exceeded

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

flag = True
for i in range(10**18):
    if k == 0:
        break
    if a == b and b == c:
        break
    A = a
    B = b
    C = c
    a = B + C
    b = A + C
    c = A + B
    if i == k - 1:
        break
    if abs(a - b) > 10**9:
        flag = False
        break
if flag:
    print(a - b)
else:
    print('Unfair')

Submission status: Time Limit Exceeded

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

flag = True
for i in range(10**18):
    if k == 0:
        break
    if a == b and b == c:
        break
    A = a
    B = b
    C = c
    a = B + C
    b = A + C
    c = A + B
    if i == k - 1:
        break
    if abs(a - b) > 10**18:
        flag = False
        break
if flag:
    print(a - b)
else:
    print('Unfair')

Submission status: Time Limit Exceeded

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

for i in range(10**18):
    if k == 0:
        break
    if a == b and b == c:
        break
    A = a
    B = b
    C = c
    a = B + C
    b = A + C
    c = A + B
    if i == k - 1:
        break
if abs(a - b) <= 10**18:
    print(a - b)
else:
    print('Unfair')

Submission status: Time Limit Exceeded

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

for i in range(10**18):
    A = a
    B = b
    C = c
    a = B + C
    b = A + C
    c = A + B
    if i == k - 1:
        break
if abs(a - b) <= 10**18:
    print(a - b)
else:
    print('Unfair')

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=c+b;B=a+c;C=a+b
    a=A;b=B;c=C
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())
MAX = 10**18
for i in range(K):
    temp_a = A
    temp_b = B
    temp_c = C
    A = temp_b + temp_c
    B = temp_a + temp_c
    C = temp_a + temp_b
if abs(A-B) > MAX:
    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:
  ans = 0
else:
  for i in range(K):
    A, B, C = B+C, A+C, A+B
    if abs(A-B)>10**18:
      break
  ans = A-B
  
if abs(ans)>10**18:
  print("Unfair")
else:
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
import copy
A,B,C,k = map(float,input().split())
for _ in range(int(k)):
    a = copy.copy(A)
    b = copy.copy(B)
    c = copy.copy(C)
    A = b + c
    B = c + a
    C = a + b
print(int(A-B))

Submission status: Time Limit Exceeded

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

for i in range(K):
    T = B + C
    N = A + C
    H = A + B
    if (T==N) and (N==H):
        break
    else:
        A = T
        B = N
        C = H

print( A-B if abs(A-B)<= 10**18 else 'Unfair')

Submission status: Time Limit Exceeded

Solution code:
a,b,c,k = map(int,input().split())
if a == b:
    print(0)
    exit()
for i in range(k):
    a_o = a
    b_o = b
    c_o = c
    a = b_o + c_o
    b = a_o + c_o
    c = a_o + b_o
    if abs(a-b) > 10**18:
        print("Unfair")
        break
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_o = a
    b_o = b
    c_o = c
    a = b_o + c_o
    b = a_o + c_o
    c = a_o + b_o
    if abs(a-b) > 10**18:
        print("Unfair")
        break
print(a-b)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
A,B,C,K=map(int,input().split())
if A==B==C:
  print('0')
  exit()
  
else:
  a=A
  b=B
  c=C
  for n in range(K):
    aa=b+c
    bb=a+c
    cc=a+b
    a=aa
    b=bb
    c=cc
    if a-b>10**18:
      print('Unfair')
      exit()
      
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()
  
else:
  a=A
  b=B
  c=C
  for n in range(K):
    aa=b+c
    bb=c+a
    cc=a+b
    a=aa
    b=bb
    c=cc

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())

tmpA = A
tmpB = B
tmpC = C

for i in range(K):
    A = tmpB + tmpC
    B = tmpA + tmpC
    C = tmpA + tmpB
    
    tmpA = A
    tmpB = B
    tmpC = C

if A-B >= 10000000000000000000:
    print('Unfair')
else:
    print(A-B)

Submission status: Time Limit Exceeded

Solution code:
import sys
from functools import lru_cache

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

@lru_cache(maxsize=None)
def operation(A, B, C):
    return(B+C, C+A, A+B)

if (A==B) & (B==C):
    print(0)
    sys.exit()

for _ in range(K):
    A, B, C = operation(A, B, C)
    if A - B > 10**18:
        print("Unfair")
        sys.exit()

print(A - B)

Submission status: Time Limit Exceeded

Solution code:
A,B,C,K=map(int, input().split())
if A==B and A==C:
  print(0)
  exit(0)
for _ in range(K):
  tpm_A=A
  tmp_B=B
  tmp_C=C
  A=tmp_B+tmp_C
  B=tpm_A+tmp_C
  C=tpm_A+tmp_B
if abs(A) > 10**18 or abs(B) > 10**18 or abs(C) > 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 == c:
    print(0)
    exit()
for i in range(k):
    tmp1 = a+b
    tmp2 = b+c
    tmp3 = c+a
    a = tmp2
    b = tmp3
    c = tmp1
    if a-b > 10**18:
        print('Unfair')
        exit()
print(a-b)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3

def main():
    A, B, C, K = map(int, open(0).read().split())

    flag = True
    for i in range(0, K):
        if abs(A - B) > 10**18:
            print('Unfair')
            flag = False
            break
        elif A == B == C:
            print(0)
            flag = False
            break
        else:
            tmpA = B + C
            tmpB = A + C
            tmpC = A + B
            A = tmpA
            B = tmpB
            C = tmpC
    if flag:
        print(A - B)


main()

Submission status: Time Limit Exceeded

Solution code:
a,b,c,k=list(map(int,input().split()))
for i in range(k):
    bc=b+c
    ca=c+a
    ab=a+b
    a=bc
    b=ca
    c=ab
print(a-b) if abs(a-b)<10**18 else print('Unfair')

Submission status: Time Limit Exceeded

Solution code:
A,B,C,K = map(int,input().split())
N = [A,B,C]
N2 = N.copy()
if A == B == C:
    print(0)
else:
    for i in range(K):
        N2[0] = N[1] + N[2]
        N2[1] = N[0] + N[2]
        N2[2] = N[0] + N[1]
        N = N2.copy()
    ans = N2[0] - N2[1]
    if abs(ans) > 10**18:
        print('Unfair')
    else:
        print(ans)

Submission status: Time Limit Exceeded

Solution code:
A,B,C,K = map(int,input().split())
N = [A,B,C]
N2 = N.copy()
for i in range(K):
    N2[0] = N[1] + N[2]
    N2[1] = N[0] + N[2]
    N2[2] = N[0] + N[1]
    N = N2.copy()
ans = N2[0] - N2[1]
if abs(ans) > 10**18:
    print('Unfair')
else:
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
a,b,c,k = map(int, input().split())
cheak = 10**18
if a == b == c:
    print(0)
    quit()
while k > 0:
    a_new = b+c
    b_new = a+c
    c_new = a+b

    a = a_new
    b = b_new
    c = c_new

    k -= 1
ans = a-b
if ans > cheak:
    print("Unfair")
else:
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
a,b,c,k=map(int,input().split())
if a==b==c:
    print ('0')
    exit ()
for _ in range(k):
    a,b,c=(b+c),(a+c),(a+b)
ans=a-b
if ans>10**18:
    print ('Unfair')
else:
    print(ans)

Submission status: Time Limit Exceeded

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

sum = (a + b + c) * (2 ** k)

ans = b - a if k % 2 == 1 else a - b

print(ans if ans <= 10**18 else "Unfair")

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):
    nA = B + C
    nB = A + C
    nC = A + B
    A, B, C = nA, nB, nC
    if abs(A - B) >= int(1e18):
        print("Unfair")
        break
else:
    print(A - B)

Submission status: Time Limit Exceeded

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

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,input().split())
for i in range(k):
    x = b+c
    y = a+c
    z = a+b
    a,b,c = x,y,z
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())
a = 0
b = 0
c = 0
for i in range(K):
  a = B + C
  b = A + C
  c = A + B
  A = a
  B = b
  C = c
if (abs(A - B) > 10**18):
  print("Unfair")
else:
  print(str(A - B))

Submission status: Time Limit Exceeded

Solution code:
A = []
A.append(list(map(int,input().split())))
fr = 0
for i in range(A[0][3]):
    if abs(A[i][0]-A[i][1]) > 10**18:
        print('unfair')
        fr += 1
        break
    else:
        A.append([0,0,0])
        A[i+1][0] = A[i][1] + A[i][2]
        A[i+1][1] = A[i][0] + A[i][2]
        A[i+1][2] = A[i][0] + A[i][1]
if fr == 0:
    print(A[-1][0]-A[-1][1])

Submission status: Time Limit Exceeded

Solution code:
a,b,c,k = map(int,input().split())
n = [a,b,c]
for i in range(k):
    t = n[:]
    for i,ind in zip(n,range(3)):
        t[ind] = sum(n)-i
    n=t[:]
print(n[0]-n[1])

Submission status: Time Limit Exceeded

Solution code:
a, b, c, k = map(int,input().split())
for _ in range(k):
  a, b, c = b+c, c+a, a+b
print("Unfair" if a-b>1e16 else a-b)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
A, B, C, K = map(int, input().split())
dp = [[0] * 3 for _ in range(2)]
dp[0][0] = A
dp[0][1] = B
dp[0][2] = C
prev = 0
prev_sum = sum(dp[0])
if A == B == C:
  print('0')
  quit()
for i in range(1, K+1):
  curr = prev^1
  curr_sum = 0
  for j in range(3):
    dp[curr][j] = prev_sum - dp[prev][j]
    curr_sum += dp[curr][j]
  prev = curr
  prev_sum = curr_sum
ans = dp[prev][0] - dp[prev][1]
if abs(ans) > 10 ** 18:
  print('Unfair')
else:
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
A, B, C, K = map(int, input().split())
dp = [[0] * 3 for _ in range(2)]
dp[0][0] = A
dp[0][1] = B
dp[0][2] = C
prev = 0
if A == B == C:
  print('0')
  quit()
for i in range(1, K+1):
  curr = prev^1
  for j in range(3):
    dp[curr][j] = dp[prev][(j+1)%3] + dp[prev][(j+2)%3]
  prev = curr
ans = dp[prev][0] - dp[prev][1]
if abs(ans) > 10 ** 18:
  print('Unfair')
else:
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
a,b,c,k=(int(x) for x in input().split())
count=0
if k==count:
    number=a-b
    

else:
    for count in range(k):
        a_2=b+c
        b_2=a+c
        c_2=a+b
        a=a_2
        b=b_2
        c=c_2
        number=a-b
        count+=1
            
if abs(number)>=10^18:
    print('Unfair')
else:
    print(number)

Submission status: Time Limit Exceeded

Solution code:
a,b,c,k = (map(int, input().split()))
for _ in range(k):
  tmpa = b+c
  tmpb = c+a
  tmpc = a+b
  a = tmpa
  b=tmpb
  c=tmpc
thre = 18
if str(a-b).startswith('-'):
  thre+=1
if len(str(a-b))>thre:
	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):
  tmpa = b+c
  tmpb = c+a
  tmpc = a+b
  a = tmpa
  b=tmpb
  c=tmpc
if a-b>10**18:
  print("Unfair")
else:
  print(a-b)

Submission status: Time Limit Exceeded

Solution code:
a,b,c,k = list(map(int,input().split()))	
a1 = a
b1 = b
c1 = c
for i in range(k):
    a1 = b + c
    b1 = a + c
    c1 = a + b
    a = a1
    b = b1
    c = c1
    
result = a1 - b1
if result > 10 **18:
    print("Unfair")
else:
    print(result)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

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

for i in range(K):
    a = A
    b = B
    c = C

    A = b + c
    B = a + c
    C = a + b

ans = A - B

if ans >= 10**18 or (-1)*ans >= 10**18:
    ans = 'Unfair'


print(ans)

Submission status: Time Limit Exceeded

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

for i in range(K):
    a = A
    b = B
    c = C

    A = b + c
    B = a + c
    C = a + b

ans = A - B

if ans >= 10**8:
    ans = 'Unfair'
elif ans <= -1*10**8:
    ans = 'Unfair'

print(ans)

Submission status: Time Limit Exceeded

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

for i in range(min(K,10**6)):
    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())


for i in range(k):
    a,b,c = (b+c),(a+c),(a+b)
    #print('a:{} b:{} c:{}'.format(a,b,c))
    
print(a-b)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

if a == b == c:
    print(0)
    exit(0)
for i in range(k):
    w_a = b + c
    w_b = a + c
    w_c = a + b
    a = w_a
    b = w_b
    c = w_c
print(a - b)

Submission status: Time Limit Exceeded

Solution code:
li=list(map(int,input().split()))
a=li[0]
b=li[1]
c=li[2]
k=li[3]
for i in range(k):
    d=a
    e=b
    a=b+c
    b=d+c
    c=d+e
print(a-b)

Submission status: Time Limit Exceeded

Solution code:
import sys
a,b,c,n = (int(g) for g in input().split())
if (a == b and a == c):
    print (0)
    sys.exit()
for d in range(n):
    i = b+c
    j = a+c
    k = a+b
    a = i
    b = j
    c = k
    #print (a,b,c)
if (a - b > 1e+18):
    print("Unfair")
else:
    print(a-b)

Submission status: Time Limit Exceeded

Solution code:
import sys
a,b,c,n = (int(g) for g in input().split())
if (a == b and a == c):
    print (0)
    sys.exit()
while (n > 0):
    i = b+c
    j = a+c
    k = a+b
    a = i
    b = j
    c = k
    n -= 1
    #print (a,b,c)
if (a - b > 1e+18):
    print("Unfair")
else:
    print(a-b)

Submission status: Time Limit Exceeded

Solution code:
a,b,c,n = (int(g) for g in input().split())
while (n > 0):
    i = a
    j = b
    k = c
    a = j+k
    b = i+k
    c = i+j
    n -= 1
if (a - b > 1e+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):
        tmpA = a
        tmpB = b
        tmpC = c
        a = tmpB + tmpC
        b = tmpA + tmpC
        c = tmpB + tmpA

ans = a - b
if ans != 10**18:
    print(ans)
else:
    print("Unfair")

Submission status: Time Limit Exceeded

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

for i in range(K):
    A, B, C = B+C, A+C, A+B
    if A == B == C:
        print(0)
        exit()

if (A - B) > num:
    print('Unfair')
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)
else:
  for i in range(K):
    A, B, C = B+C, C+A, A+B
  if A-B<=10E+18:
    print(A - B)
  else:
    print("Unfair")

Submission status: Time Limit Exceeded

Solution code:
A, B, C, K = map(int, input().split())
fair = True
for i in range(K):
  A, B, C = B+C, C+A, A+B
  if A > 10E+18 or B > 10E+18 or C > 10E+18:
    fair = False
print(A - B)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
a,b,c,k=map(int,input().split())
n1=1
n2=0
if a==b:print(0);exit()
for i in range(k):
    n1,n2=n2*2,n1+n2
    if (n1-n2)*(a-b)>10**18:print("Unfair");exit()
print((n1-n2)*(a-b))

Submission status: Time Limit Exceeded

Solution code:
a, b, c, k = map(int, input().split())
for i in range(k):
  a2 = b + c
  b2 = c + a
  c2 = a + b
  a = a2
  b = b2
  c = c2
if pow((a-b)**2,1/2) >= 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):
  a, b, c = b + c, a + c, a + b
ans = a - b if a - b <= 10 ** 18 else 'Unfair'
print(ans)

Submission status: Time Limit Exceeded

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

MAX = 10 ** 18

c = [A, B, C]
for n in range(K):
	n = [c[1] + c[2], c[0] + c[2], c[0] + c[1]]
	if MAX < (n[0] - n[1]):
		print("Unfair")
	c = n
print(c[0] - c[1])

Submission status: Time Limit Exceeded

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

for _ in range(K):
  A, B, C = B+C, A+C, A+B

ans = A - B
if ans > 1e18:
  print("Unfair")
else:
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
a,b,c,k = map(int,input().split())
for i in range(k):
  na = b + c
  nb = a + c
  nc = a + b
  a = na
  b = nb
  c = nc
ans = a - b
if ans > 10**18:
  print('Unfair')
else:
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-


a, b, c = [0], [0], [0]
a[0], b[0], c[0], K = map(int,input().split())

for i in range(K):
    a.append(b[i] + c[i])
    b.append(a[i] + c[i])
    c.append(b[i] + a[i])
    
ans = a[K] - b[K]
if ans > 10**18:
    print('Undair')
else:
    print(ans)

Submission status: Time Limit Exceeded

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

limit = pow(10, 18)

ans = 0
unfair = False
for v in range(k):
    if a == b and b == c:
        break
    na = b + c
    nb = a + c
    nc = a + b
    a = na
    b = nb
    c = nc
ans = a - b
if abs(ans) > limit:
    print("Unfair")
else:
    print(ans)

Submission status: Time Limit Exceeded

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

for i in range(K):
  if A == B and B == C:
    break
  next_A = B + C
  next_B = A + C
  next_C = A + B
  A = next_A
  B = next_B
  C = next_C
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:
    ans = 0
else:
    dp = [a, b, c]
    for i in range(k):
        if abs(dp[0] - dp[1]) > 10 ** 18:
            ans = 'Unfair'
            break
        else:
            dp[0], dp[1], dp[2] = dp[1] + dp[2], dp[0] + dp[2], dp[0] + dp[1]
    else:
        ans = dp[0] - dp[1]

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import copy
A, B, C, K = map(int, input().split())
maxL = 10 ** 18
L = [A, B, C]
for i in range(K):
    newL = [L[1] + L[2], L[0] + L[2], L[0] + L[1]]
    L = copy.copy(newL)

ans = L[0] - L[1]
if ans >= maxL:
    print("Unfair")
else:
    print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
a, b, c, k = map(int, input().split())
for i in range(k):
  a, b, c = b+c, c+a, a+b
if a-b <= 100000000:
  print(a-b)
else:
  print("Unfair")

Submission status: Time Limit Exceeded

Solution code:
inputs = list(map(int, input().split()))
K = inputs.pop()

if inputs[0] == inputs[1] == inputs[2]:
    print(0)
else:
    for k in range(K):
        total = sum(inputs)
        inputs = [total-inputs[i] for i in range(3)]

        if abs(inputs[0] - inputs[1]) > 10 ** 18:
            print(-1)
            break
    else:
        print(inputs[0] - inputs[1])

Submission status: Time Limit Exceeded

Solution code:
a,b,c,k = (int(x) for x in input().split())

while k:
    a,b,c = b+c,a+c,a+b
    k -= 1

ans = a-b

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

pointH =a
pointM =b
pointL =c

if a ==b and b ==c:
    print(0)
else:
    index =0
    while index<k:
        list2 = [pointM+pointL,pointL+pointH,pointH+pointM]
        pointH = list2[0]
        pointM = list2[1]
        pointL = list2[2]
        index+=1

    if pointH-pointM>10**18:
        print("Unfair")
    else:
        print(pointH-pointM)

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':
    inputList = input().split()

    A = int(inputList[0])
    B = int(inputList[1])
    C = int(inputList[2])
    K = int(inputList[3])
    limit = pow(10, 18)

    for num in range(K):
        _A = B + C
        _B = A + C
        _C = A + B

        A = _A
        B = _B
        C = _C

        if A - B > limit:
            break

    result = A - B

    if result > limit:
        result = "Unfair"

    print(result)

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':
    inputList = input().split()

    A = int(inputList[0])
    B = int(inputList[1])
    C = int(inputList[2])
    K = int(inputList[3])

    for num in range(K):
        _A = B + C
        _B = A + C
        _C = A + B
        A = _A
        B = _B
        C = _C
    result = A - B
    if result > pow(10, 18):
        result = "Unfair"
    print(result)

Submission status: Time Limit Exceeded

Solution code:
import sys

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

a = [1,0,0]
b = [0,1,0]
c = [0,0,1]

i = 0
while i < K:
    a = [sum(x) for x in zip(b, c)]
    b = [a[1],a[0],a[2]]
    c = [b[0],b[2],b[1]]
    
    i = i + 1
res = (A - B) * (a[0] - a[1])
if res < 10**18:
    print(res)
else:
    print("unfair")

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
A, B, C, K = map(int, input().split())
for i in range(K):
	temp_a = A
	temp_b = B
	A = B + C
	B = temp_a + C
	C = temp_a + temp_b
if abs(A - B) <= 10 ** 18:
	print(A - B)
else:
	print("unfair")

Submission status: Time Limit Exceeded

Solution code:
A, B, C, K = map(int, input().split())
for i in range(K):
	temp_a = A
	temp_b = B
	temp_c = C
	A = temp_b + temp_c
	B = temp_a + temp_c
	C = temp_a + temp_b
if abs(A - B) <= 10 ** 18:
	print(A - B)
else:
	print("unfair")

Submission status: Time Limit Exceeded

Solution code:
import math

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

for i in range(k):
  m = b + c
  n = a + c
  o = a + b
  a = m
  b = n
  c = o

if math.fabs(a - b) > 1.0e18:
  print("Unfair")
else:
  print(int(a - b))

Submission status: Time Limit Exceeded

Solution code:
A,B,C,K=map(int,input().split())
takahashi=A
nakahashi=B
teihashi=C
takahashi1=0
nakahashi1=0
teihashi1=0

if A==B and B==C:
    print("0")
else:
    for i in range(K):
        takahashi1=nakahashi+teihashi
        nakahashi1=takahashi+teihashi
        teihashi1=takahashi+nakahashi
        takahashi=takahashi1
        nakahashi=nakahashi1
        teihashi=teihashi1
    print(takahashi-nakahashi)

Submission status: Time Limit Exceeded

Solution code:
a,b,c,k = map(int,input().split())
x = 0
y = 0
z = 0
o = 0
for i in range(k):
  x = b + c
  y = c + a
  z = a + b
  a = x
  b = y
  c = z
  
o = a - b
if o > 1000000000000000000 or o < -1000000000000000000:
  print("Unfair")
else:
  print( o )

Submission status: Time Limit Exceeded

Solution code:
import sys

input_nums = raw_input().split(' ')
A = int(input_nums[0])
B = int(input_nums[1])
C = int(input_nums[2])
K = int(input_nums[3])

if A == B and B == C:
    print 0
    sys.exit()

for _ in xrange(K):
    A, B, C = B + C, A + C, A + B
    # if A > 10**18 or B > 10**18 or C > 10**18:
    #     print 'Unfair'
    #     sys.exit()

print A - B

Submission status: Time Limit Exceeded

Solution code:
a,b,c,k =map(int,input().split())
for i in range(k):
	d = c
	c = b+a
	b = a+d
	a = b+c-2*a
r =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 i in range(k):
	e = b+c
	f = a+b
	g = a+c
	a = e
	c = f
	b = g
r =a-b
if abs(a-b)>10^18:
	print('Unfair')
else:
	print(a-b)

Submission status: Time Limit Exceeded

Solution code:
import copy
s=input().split()
num=[int(i) for i in s[:3]]
K=int(s[3])
num_=[0,0,0]
for i in range(K):
	for j in range(3):
		num_[j]=num[(j+1)%3]+num[(j+2)%3]
	num=copy.deepcopy(num_)
	if i%100==0 and abs(num[0]-num[1])>10**18:
		break
if abs(num[0]-num[1])>10**18:
	print("Unfair")
else:
	print(num[0]-num[1])

Submission status: Time Limit Exceeded

Solution code:
import copy
s=input().split()
num=[int(i) for i in s[:3]]
K=int(s[3])
num_=[0,0,0]
for i in range(K):
	for j in range(3):
		num_[j]=num[(j+1)%3]+num[(j+2)%3]
	num=copy.deepcopy(num_)
	if i%1000==0 and abs(num[0]-num[1])>10**18:
		break
if abs(num[0]-num[1])>10**18:
	print("Unfair")
else:
	print(num[0]-num[1])

Submission status: Time Limit Exceeded

Solution code:
import copy
s=input().split()
num=[int(i) for i in s[:3]]
K=int(s[3])
num_=[0,0,0]
for i in range(K):
	for j in range(3):
		num_[j]=num[(j+1)%3]+num[(j+2)%3]
	num=copy.deepcopy(num_)
	if i%10000==0:
		if abs(num[0]-num[1])>10**18:
			print("Unfair")
			break
else:
	print(num[0]-num[1])

Submission status: Time Limit Exceeded

Solution code:
import copy
s=input().split()
num=[int(i) for i in s[:3]]
K=int(s[3])
num_=[0,0,0]
for i in range(K):
  for j in range(3):
    num_[j]=num[(j+1)%3]+num[(j+2)%3]
  num=copy.deepcopy(num_)
if abs(num[0]-num[1])>10**18:
  print("Unfair")
else:
  print(num[0]-num[1])

Submission status: Time Limit Exceeded

Solution code:
import sys

xs = str(sys.stdin.readline()).split(" ")
a,b,c,k = [int(x) for x in xs]

def f(x):
	if (pow(10,18) < x):
		print("UnFair")
		exit()

for i in range(0, k):
	a2,b2,c2 = b+c, a+c, a+b
	a,b,c = a2,b2,c2

x = a - b
f(x)
print(x)