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):
    tk = b+c
    nk = c+a
    hk = a+b
    a = tk
    b = nk
    c = hk
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())

def judge(n):
    if abs(n) > 10**18:
        print('Unfair')
    else:
        print(n)

if K == 0:
    judge(A-B)
else:
    if A == B and B == C and C == A :
        print(0)
    else:
        sum = A + B + C
        for i in range(1, K+1):
            sum *= K
            A = sum - A
            B = sum - B
        judge(A-B)

Submission status: Time Limit Exceeded

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

def judge(n):
    if abs(n) > 10**18:
        print('Unfair')
    else:
        print(n)

if K == 0:
    judge(A-B)
else:
    sum = A + B + C
    for i in range(1, K+1):
        sum *= K
        A = sum - A
        B = sum - B
    judge(A-B)

Submission status: Time Limit Exceeded

Solution code:
a, b, c, k = map(int, raw_input().split())
if k == 0:
    print a-b
elif k >= 0:
    for i in xrange(k):
        tmpA = a
        tmpB = b
        tmpC = c
        a = tmpC + tmpB
        b = tmpA + tmpC
        c = tmpC + tmpB
    if a-b <= pow(10,18):
        print a-b
    else:
        print 'Unfair'

Submission status: Time Limit Exceeded

Solution code:
T, N, H, L = (int(a) for a in input().split())

for i in range(int(L)):
	t = T; n = N; h = H
	T = n+h
	N = t+h
	H = t+n
	if t-n == T-N:
		break


ans = T-N
if -10**18 >= ans <= 10**18:
	print('Unfair')
else:
	print(ans)

Submission status: Time Limit Exceeded

Solution code:
T, N, H, L = (int(a) for a in input().split())

if T == N == H:
	L = 0

for i in range(int(L)):
	t = T; n = N; h = H
	T = n+h
	N = t+h
	H = t+n

ans = T-N
if -10**18 >= ans <= 10**18:
	print('Unfair')
else:
	print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
T, N, H, L = (int(a) for a in input().split())

for i in range(int(L)):
	t = T; n = N; h = H
	T = n+h
	N = t+h
	H = t+n

ans = T-N
if -10**18 >= ans <= 10**18:
	print('Unfair')
else:
	print(ans)

Submission status: Time Limit Exceeded

Solution code:
t, n, h, k = map(int, input().split())

if t==n and n==h:
    print(t-n)
elif k==0:
    print(t-n)
else:
    for i in range(k):
        t, n, h = n+h, t+h, t+n
        result = t-n

    if abs(result) > pow(10,18):
        print("Unfair")
    else:
        print(result)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

def execute(a, b, c):
    return b+c, a+c, a+b

a, b, c, k = [int(x) for x in stdin.readline().rstrip().split()]

for i in range(k):
    a, b, c = execute(a, b, c)

if a - b > 10e18:
    print('Unfair')
else:
    print(a-b)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/python
# -*- coding: utf-8 -*-

import copy

hey=[int(i) for i in input().split()]

current=hey[0:3]

for i in range(hey[3]):
    tmp=copy.deepcopy(current)
    current[0]=tmp[1]+tmp[2]
    current[1]=tmp[0]+tmp[2]
    current[2]=tmp[0]+tmp[1]

answer=current[0]-current[1]

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

Submission status: Time Limit Exceeded

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

    dpm = [True for _ in range(k + 1)]
    dpo = [True for _ in range(k + 1)]

    for i in range(k+1):
        if i == 0:
            dpm[i] = 1
            dpo[i] = 0
        elif i == 1:
            dpm[i] = 0
            dpo[i] = 1
        else:
            dpm[i] = dpo[i-1]*2
            dpo[i] = dpm[i-1] + dpo[i-1]

    takahashi = dpm[k]*a + dpo[k]*(b + c)
    nakahashi = dpm[k]*b + dpo[k]*(a + c)

    ans = takahashi - nakahashi
    if abs(ans) > 10**18:
        return 'Unfair'
    else:
        return ans

if __name__=='__main__':
  print(solve())

Submission status: Time Limit Exceeded

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

for i in range(K):
    A2 = B+C
    B2 = A+C
    C = A+B
    A = A2
    B = B2

L=pow(10,18)
if (A-B) > L:
    print("Unfair")
else:
    print(A-B)

Submission status: Time Limit Exceeded

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

for i in range(K):
	As = A
	Bs = B
	Cs = C
	A = Bs + Cs
	B = Cs + As
	C = As + Bs

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

Submission status: Time Limit Exceeded

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

if a==b==c:
    print(0)
    quit()
for i in range(k):
    a,b,c = b+c,a+c,a+b
    if a-b >= 10**18:
        print("Unfair")
        quit()
print(a-b)

Submission status: Time Limit Exceeded

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

for i in range(0, 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())
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 (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)
    quit()
for i in range(k):
    d = b+c
    e = a+c
    f = a+b
    a = d
    b = e
    c = f
    if a-b >= 10**18:
        print("Unfair")
        quit()
print(a-b)

Submission status: Time Limit Exceeded

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

# スペース区切りの整数の入力
a, b, c, k = map(int, input().split())

for i in range(k):
    ab = a + b
    bc = b + c
    ca = c + a

    a = bc
    b = ca
    c = ab

result = a - b

if  abs(result) > pow(10, 18):
    print("Unfair")

else:
    print(result)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
l=input().split()
a=int(l[0])
b=int(l[1])
c=int(l[2])
k=int(l[3])
for i in range(k):
	a1=b+c
	b1=a+c
	c1=a+b
	a=a1
	b=b1
	c=c1
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())
nA,nB,nC=0,0,0
for i in range(K):
    nA=B+C
    nB=A+C
    nC=A+B
    A,B,C=nA,nB,nC
ans=A-B
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(" "))
for i in range(k):
	newa = b+c
	newb = a+c
	newc = a+b
	a = newa
	b = newb
	c = newc
if abs(a)>(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 = A+C
    c = A+B
    A = a
    B = b
    C = c
print(A-B)

Submission status: Time Limit Exceeded

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

for i in range(K):
 sum = A + B + C
 A = sum - A
 B = sum - B
 C = sum - C

if A-B > 10e18 or B-A > 10e18:
 print("Unfair")
else:
 print(A-B)

Submission status: Time Limit Exceeded

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:
    print("Unfair")
else:
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = [int(i) for i in input().split()]
A = N[0]
B = N[1]
C = N[2]
K = N[3]

if A == B == C:
    print(0)
else:
    for i in range(K):
        NA = B + C
        NB = A + C
        NC = A + B
        A = NA
        B = NB
        C = NC
    if abs(A-B) > 10 ** 18:
        print('Unfair')
    else:
        print(A-B)

Submission status: Time Limit Exceeded

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

for i in range(k):
  n_a = b+c
  n_b = a+c
  n_c = a+b
  a = n_a
  b = n_b
  c = n_c
  if(a == b and b == c ):
    break

d = a - b
if(abs(d) < 100000000):
  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(1,k+1):
    temp1 = b+c
    temp2 = a+c
    temp3 = a+b
    a = temp1
    b = temp2
    c = temp3
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())
if A == B:
    print(0)
else:
    for i in range(K):
        A_tmp = B + C
        B_tmp = C + A
        C_tmp = A + B

        A = A_tmp
        B = B_tmp
        C = C_tmp
    if A - B >10e18:
        pass
    else:
        print(A-B)

Submission status: Time Limit Exceeded

Solution code:
# https://agc024.contest.atcoder.jp/tasks/agc024_a


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())
for i in range(k):
    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:
s = input().rstrip().split()
a = int(s[0])
b = int(s[1])
c = int(s[2])
k = int(s[3])

for i in range(k):
  n_a = b+c
  n_b = a+c
  n_c = a+b
  a = n_a
  b = n_b
  c = n_c

d = a - b
if(abs(d) < 100000000):
  print(a-b)
else:
  print("Unfair")

Submission status: Accepted

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

Submission status: Accepted

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

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


'''
    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

    answer = a - b
    if answer > 10**18:
        print('Unfair')
    else:
        print(answer)
'''

if __name__ == '__main__':
    main()

Submission status: Accepted

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

MAX = 10 * 18


def solve(A: int, B: int, C: int, K: int):
    ans = A - B
    if K % 2 != 0:
        ans *= -1
    print(ans)

    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(A, B, C, K)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
a, b, c, k = map(int,input().split())
print("Unfair" if abs(a-b) >= 1e18 else a-b if k % 2 == 0 else b-a)

Submission status: Accepted

Solution code:
a,b,c,k = map(int,input().split())
if abs(a-b) > 10 ** 18:
    print("Unfair")
elif k % 2 == 1:
    print(b - a)
else:
    print(a - b)

Submission status: Accepted

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

if K % 2 == 1:
    print(B-A)
elif K % 2 == 0:
    print(A-B)
else:
    print('Unfair')

Submission status: Accepted

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

if K % 2 == 1:
    print(B-A)
elif K % 2 == 0:
    print(A-B)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A, B, C, K = map(int, input().split())
if K % 2 == 0:
  print(A-B)
else:
  print(B-A)

Submission status: Accepted

Solution code:
A, B, C, K = map(int, input().split())
if K%2 == 0:
  print(A-B)
else:
  print(B-A)

Submission status: Accepted

Solution code:
A, B, C, K = [int(x) for x in input().split()]
if(K%2==0):
  ans = A - B
else:
  ans = B - A
if(abs(ans)>10**18):
  print('Unfair')
else:
  print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8

def main():
    A, B, _, K = map(int, input().split())
    ans = A - B if K % 2 == 0 else B - A
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A,B,C,K  = map(int,input().split())
ans = int((A-B)*((-1)**K))
print(ans if abs(ans)< 1e18 else "Unfair")

Submission status: Accepted

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

def main():
    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(b-a) 

if __name__=="__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

t=A-B
if 10**18<t:
    print('Unfair')
elif K%2==0:
    print(t)
else:
    print(-t)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
a, b, c, k = map(int, input().split())
cons = (-1)**k
ans = (a - b) * cons

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

Submission status: Accepted

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

if K%2 == 0:
    if abs(A-B) <= 10**18:
        print(A-B)
    else:
        print("Unfair")
else:
    if abs(B-A) <= 10**18:
        print(B-A)
    else:
        print("Unfair")

Submission status: Accepted

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

if K % 2 == 0:
    if abs(A-B) > 10**18:
        print("Unfair")
    else:
        print(A-B)
        
else:
    if abs(B-A) > 10**18:
        print("Unfair")
    else:
        print(B-A)

Submission status: Accepted

Solution code:
import sys
import copy
import math
import itertools
import numpy as np
l = [int(c) for c in input().split()]
A = l[0]
B = l[1]
C = l[2]
K = l[3]

if K%2==0:
    print(A-B)
else:
    print(B-A)

Submission status: Accepted

Solution code:
# import math
# import statistics
#a=input()
#b,c=int(input()),int(input())
# c=[]
# for i in a:
#    c.append(i)
e1,e2,e3 ,e4= map(int,input().split())
#K = input()
# f = list(map(int,input().split()))
#g = [input() for _ in range(a)]

if e4%2==0 or e4==0:
    print(e1-e2)
elif e4%2==1 :
    print(-(e1-e2))
elif abs(e1-e2)>=10**18:
    print("Unfair")

Submission status: Accepted

Solution code:
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 6)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()

a,b,c,k=I()

if abs(b-a)>10**18:
    print("Unfair")
else:
    if k%2==0:
        print(a-b)
    else:
        print(b-a)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

ans = None
if k % 2 == 0:
    ans = a - b
else:
    ans = b - a

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

Submission status: Accepted

Solution code:
#/usr/bin/env python

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

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:

A, B, C, K = map(int, input().split())
r = K % 2
if r == 0:
    ans = A - B
else:
    ans = B - A

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

Submission status: Accepted

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

    if k % 2 == 0:
        ans = a - b
        if abs(ans) > 10 ** 18:
            print("Unfair")
        else:
            print(ans)
    else:
        ans = b - a
        if abs(ans) > 10 ** 18:
            print("Unfair")
        else:
            print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

if abs(A-B) > 10**18:
    print('unfair')
else:
    if K % 2 == 0:
        print(A-B)
    else:
        print((A-B)*(-1))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A,B,C,K = map(int,input().split())
if K % 2 == 0:
  print(A - B)
else:
  print(B - A)

Submission status: Accepted

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

o = B - A
e = A - B
if K % 2 == 0:
  r = e
else:
  r = o 
print(r)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

if a==b:
  print(0)
else:
  ans_0=a-b
  ans_1=b-a
  if abs(ans_0)>=10**18:
    print("Unfair")
  elif k%2!=0:
    print(ans_1)
  elif k%2==0:
    print(ans_0)

Submission status: Accepted

Solution code:
A, B, C, K = map(int, input().split())
print(A - B if K % 2 == 0 else B - A)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
def solve():
    A, B, _, K = [int(i) for i in input().split()]
    if abs(A - B) > 10 ** 18:
        print('Unfair')
        exit()
    if K % 2 == 0:
        print(A - B)
    else:
        print(B - A)

if __name__ == "__main__":
    solve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A, B, C, K = map(int,input().split())
a = [A, B, C]
if K % 2 == 0:
  print(A - B)
else:
  print(B - A)

Submission status: Accepted

Solution code:
A,B,C,K = map(int,input().split())
if K % 2 == 0:
    ans = A - B
else:
    ans = B - A

if abs(ans) > 1e18:
    print('Unfair')
else:
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def resolve():
    '''
    code here
    '''
    A, B, C, K = [int(item) for item in input().split()]

    if K % 2 == 0:
        res = A- B
    else:
        res = B -A

    print(res)
if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    A, B, C, K = LI()

    ans = (-1) ** (K % 2) * (A - B)
    if abs(ans) > 10 ** 18:
        print('Unfair')
    else:
        print(ans)

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
a, b, c, k = [int(_) for _ in input().split()]
print((-1) ** k * (a - b))

Submission status: Accepted

Solution code:
A,B,C,K=list(map(int, input().split()))
sum=A+B+C
print((A-B)*(-1)**(K%2))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

a,b,c,k=map(int,input().split())
if k%2:
    print(b-a)
else:
    print(a-b)

Submission status: Accepted

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

if a==b==c:
    print(0)
    exit()
    
a_=b+c
b_=a+c
c_=a+b

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

Submission status: Accepted

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

if abs(A-B)>=limit:
    print('Unfair')
else:
    if K%2==0:
        print(A-B)
    else:
        print(B-A)

Submission status: Accepted

Solution code:
A, B, C, K = list(map(int, input().split()))
if K % 2 == 0:
  print(A-B)
else:
  print(B-A)

Submission status: Accepted

Solution code:
'''
Created on 2020/08/17

@author: harurun
'''

import sys
pin=sys.stdin.readline
pout=sys.stdout.write
perr=sys.stderr.write

mod=1000000000000000000
A,B,C,K=map(int,pin().split())
if abs(A-B)>mod:
  print("Unfair")
elif K%2==0:
  print(A-B)
else:
  print(B-A)

Submission status: Accepted

Solution code:
'''
Created on 2020/08/17

@author: harurun
'''

def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write

  mod=1000000000000000000

  A,B,C,K=map(int,pin().split())
  if abs(A-B)>mod:
    print("Unfair")
  elif K%2==0:
    print(A-B)
  else:
    print(B-A)

main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
L=[int(x) for x in input().split()]
A=L[0]
B=L[1]
K=L[3]
if K%2==0:
  d=A-B
else:
  d=B-A
if d>10**18:
  print('Unfair')
else:
  print(d)

Submission status: Accepted

Solution code:

def resolve():
    import sys
    input = sys.stdin.readline
    # row = [int(x) for x in input().rstrip().split(" ")]
    # n = int(input().rstrip())
    # s = input().rstrip()
    a, b, c, k = [int(x) for x in input().rstrip().split(" ")]

    if abs(a - b) > 10**18:
        print("Unfair")
        return

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

if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

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

Submission status: Accepted

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

if K%2 == 0:
    ans = A - B 
else:
    ans = B - A
print(ans)

Submission status: Accepted

Solution code:
a, b, c, k = map(int, input().split())
print(b-a if k & 1 else a-b)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A,B,C,K = map(int,input().split())
if K & 1:
    print(B-A)
else:
    print(A-B)

Submission status: Accepted

Solution code:
a,b,c,K=list(map(int,input().split()))
print((a-b)*((-1)**K))

Submission status: Accepted

Solution code:
A, B, C, K = map(int, input().split())
print((A-B)*(-1)**(K+2))

Submission status: Accepted

Solution code:
a,b,c,k = map(int,input().split())
if k%2 == 0 and a-b <= 10**18:
    print(a-b)
elif k%2 != 0 and a-b <= 10**18:
    print(b-a)
"""
else:
    print("Unfair")
"""

Submission status: Accepted

Solution code:
a,b,c,k = map(int,input().split())
if k%2 == 0 and a-b <= 10**18:
    print(a-b)
elif k%2 != 0 and a-b <= 10**18:
    print(b-a)
else:
    print("Unfair")

Submission status: Accepted

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

Submission status: Accepted

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

ans = A-B if K % 2 == 0 else B-A

print(ans)

Submission status: Accepted

Solution code:
a,b,c,k=map(int,input().split())
num=a-b
if k%2==1:
    print((-1)*num)
else:
    print(num)

Submission status: Accepted

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

Submission status: Accepted

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

if K%2 == 0:
  if A-B > 10**18:
    print("Unfair")
  else:
    print(A-B)
else:
  if -(A-B) > 10**18:
    print("Unfair")
  else:
    print (-(A-B))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

a, b, c, k = inintm()

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

Submission status: Accepted

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

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

    else:
        if A > B:
            if K % 2 == 0:
                print(d)
            else:
                print(-d)

        elif A < B:
            if K % 2 == 0:
                print(-d)
            else:
                print(d)

        else:
            print("0")

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
a,b,c,k = list(map(int, input().strip().split()))
if ((-1)**(k-1))*(a-b)<=10**18:
    print(((-1)**((k)%2))*(a-b))
else:
    print("Unfair")

Submission status: Accepted

Solution code:
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    a, b, c, k = map(int, input().split())
    if k & 1:
        print(b-a)
    else:
        print(a-b)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math
import sys
import collections
import bisect


def main():
    a, b, c, k = map(int, input().split())
    print((-1) ** k * (a - b))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

# 1回後 A:B+C B:A+C C:A+B   A-B = B-A
# 2回後 A:2A+B+C B:A+2B+C C:A+B+2C    A-B = A-B

if K % 2 == 0:
    print(A - B)
else:
    print(B - A)

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

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

if K % 2 == 0:
    ans = A - B
else:
    ans = B - A

print(ans)

Submission status: Accepted

Solution code:
A,B,C,K = map(int,input().split())
s1 = 0
s2 = 0
for i in range(2):
    a = A + 2 * B
    b = B + 2 * A
    A = a
    B = b
    if i == 0:
        s1 = A - B
    else:
        s2 = A - B
if K % 2 == 1:
    if s1 < 10 ** 18:
        print(s1)
    else:
        print("Unfair")
else:
    if s2 < 10 ** 18:
        print(s2)
    else:
        print("Unfair")

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
a,b,c,k=map(int,input().split())
inf=10**18+1

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

if ans<inf:
    print(ans)
else:
    print('Unfair')

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A,B,C,K = map(int,input().split())
for i in range(K%2):
    A,B,C = B+C,C+A,A+B
print(A-B)