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: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

x = A - B
if K&1:
    x *= (-1)
print(x)

Submission status: Accepted

Solution code:
#coding:utf-8
a,b,c,k = map(int,input().split())
if (abs(a-b)>1e+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 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 abs(a-b)>=10**18:
    print("unfair")
elif k%2 == 1:
    print(b-a)
elif k%2 == 0:
    print(a-b)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
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 :
  ret = A - B
else :
  ret = B - A

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import itertools#これは色々使える組み込み関数みたいなやつ
import math#数学的計算はこれでいける。普通に0.5乗しても計算可能
#w=input()
A, B, C, K=input().split()
A=int(A)
B=int(B)
C=int(C)
K=int(K)
i=0
ID_list=[]
ID_sublist=[]
gate_possible_list=[]
A_dummy=0
B_dummy=0
C_dummy=0
#センテンスを暗記するのではなく、まずinput()を書いて、膨らます感じで記述する。すると#思考の流れ通りに書ける。素晴らしい！
#for i in range(K):
# ID_list.append(i+1)
#print(ID_list)
#for i in range(N)
#gate_list =  [list(map(int, input().split(" ")))for i in range(M)]
#センテンスを暗記するのではなく、まずinput()を書いて、膨らます感じで記述する。すると#思考の流れ通りに書ける。素晴らしい！

#x=[]
#y=[]
#t, x, y = [0]*(N+1), [0]*(N+1), [0]*(N+1)#N+1個の空のリストを作成(原点を入れて##るから一つ増える)
#delta_t=0
#delta_x=0
#delta_y=0
#l=0
#t[0],x[0],y[0]=[0, 0, 0]
#とりあえず入力までは完成した．
#for i in range(N):
# t[i+1], x[i+1], y[i+1] = map(int, input().split())
#child_i =  list(map(int, input().split()))
#w_len=len(w)
#w_list=list(w)
#print(len(w_list))
#print(w_list)
#child_il=sorted(child_i)
#print(child_il)#リストの右端のほうが大きい
i=0
if A==B==C:
    print(0)
    sys.exit()
#for i in range(K):
#    A_dummy=B+C
#    B_dummy=A+C
#    C_dummy=A+B
#    A=A_dummy
#    B=B_dummy
#    C=C_dummy

if abs(A-B)>10**18:
    print("Unfair")
    sys.exit()

if K%2==0:
    print(A-B)
    sys.exit()

if K%2==1:
    print(-(A-B))
    sys.exit()

Submission status: Accepted

Solution code:
from sys import stdin

a,b,c,k = [int(x) for x in stdin.readline().rstrip().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())
print(b-a if k%2 else a-b)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def examA():
    A, B, C, K = LI()
    if K%2==0:
        ans = A-B
    else:
        ans = B-A
    print(ans)


import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examA()

Submission status: Accepted

Solution code:
import sys
a, b, c, k = [int(i) for i in sys.stdin.readline().split()]
print((a - b) * (-1) ** k)

Submission status: Accepted

Solution code:
A,B,C,K=map(int,input().split())
import numpy as np
X = np.array([A,B,C])
Y = np.array([1,-1,0])
M = np.matrix('0 1 1; 1 0 1; 1 1 0')

def pow_V(Z,n):
  bin_n = format(n, 'b')
  ans = np.matrix('1 0 0; 0 1 0; 0 0 1')
  for i in range(0,len(bin_n)):
    if i == 0:
      XX = Z
    else:
      XX = XX * XX
    if bin_n[-(i+1)]=='1':
      ans = ans * XX
  return ans
MK = pow_V(M,K)
R = np.inner(Y, (X * MK))[0,0]
print(R)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

a,b,c,k = inpl()
if k%2:
    print(b-a)
else:
    print(a-b)

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())
print((-1)**k*(a-b))

Submission status: Accepted

Solution code:
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


A, B, C, K = list(map(int, sys.stdin.buffer.readline().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 K % 2 == 1:
    print(B-A)
else:
    print(-(B-A))

Submission status: Accepted

Solution code:
# AGC024
over = 10 ** 18
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())

ans = a-b

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

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

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

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]

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

Submission status: Accepted

Solution code:
def main():
    a, b, c, K = (int(i) for i in input().split())
    if K & 1:
        print(b-a)
    else:
        print(a-b)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

    ans = (-1) ** (k % 2) * (a - b)

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
a,b,c,n = [int(i) for i in input().split()]

if n%2 == 1:
    print(b-a if abs(b-a) < 10**18 else 'Unfair')
else:
    print(a-b if abs(a-b) < 10**18 else 'Unfair')

Submission status: Accepted

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
#         if a - b >= 10**18:
#             print("Unfair")
#             exit()
# 
# print(a - b)
if a-b >= 10**18 or b-a >= 10**18:
    print("Unfair")
    exit()

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

Submission status: Accepted

Solution code:
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    a, b, c, k = list(map(int, input().rstrip('\n').split()))
    print(a - b if k % 2 == 0 else b - a)


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

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

Submission status: Accepted

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


if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
A,B,C,K=map(int,input().split())

all=A+B+C
"""
if K>=2:
    A+=all*4**(K//2-1)
    B+=all*4**(K//2-1)
    C+=all*4**(K//2-1)
"""
if K%2==1:
    A,B,C=B+C,C+A,A+B

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

Submission status: Accepted

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

for i in range(K%2):
    tmp1 = A+B
    tmp2 = A+C
    tmp3 = B+C

    A = tmp3
    B = tmp2
    C = tmp1
if abs(A-B)>=10**18:
    print("Unfair")
else:
    print(A-B)

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 % 2 == 0:
    print(a-b)
else:
    print(b-a)

Submission status: Accepted

Solution code:
def f(a,b,c):
    return b+c,a+c,a+b
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())
print(b - a if k % 2 else a - b)

Submission status: Accepted

Solution code:
a,b,c,d=map(int,input().split())
if abs(a-b)>100000000000000000:
	print("Unfair")
elif d%2==0 and abs(a-b)<=1000000000000000000:
    print(a-b)
else:
    print(b-a)

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());print((A-B)*(-1)**K)

Submission status: Accepted

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

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

if ans > num:
    print('Unfair')
else:
    print(ans)

Submission status: Accepted

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

if K%2:
  ans=B-A
else:
  ans=A-B
print(ans if abs(ans)<=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("Unfair" if abs(ans) >= 10**18 else ans)

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)

Submission status: Accepted

Solution code:
A, B, C, K = list(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:
A, B, C, K = map(int, input().split())

ans = (-1)**(K % 2) * (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(-(b-a))

Submission status: Accepted

Solution code:
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=list(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 abs(a - b) > 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==0:
    ans=a-b
else:
    ans=b-a
if abs(ans)>=10**18:
    ans="Unfair"
print(ans)

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:
def main():
    A, B, C, K = map(int, input().split())
    if K % 2 == 0:
        print(A-B)
    else:
        print(B-A)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

a,b,c,k = LI()
if k % 2:
    print(b-a)
else:
    print(a-b)

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%2==0:
  ans=A-B
else:
  ans=B-A
if abs(ans)>=1000000000000000000:
  print("Unfair")
else:
  print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
#AGC024A
import sys
#import collections

#n= int(input())
#s= input()
tmp = input().split()
a,b,c,k = list(map(lambda a: int(a), tmp))

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

Submission status: Accepted

Solution code:
inputs = [int(c) for c in input().split()]
ans = inputs[0] - inputs[1] if inputs[3] % 2 == 0 else inputs[1] - inputs[0]
if 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:
        return A - B
    else:
        return B - A

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, fractions, itertools, collections, copy, heapq


def solve(A: int, B: int, C: int, K: int):
    if K % 2 == 0:
        print(A - B)
    else:
        print(B-A)
    return


# Generated by 1.1.4 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())
if k%2==0:
	print(a-b)
else:
	print(b-a)

Submission status: Accepted

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

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

a,b,c,k = LI()
s,t,u = b+c,a+c,a+b
x,y,z = t+u,s+u,s+t
if k % 2:
    print(s-t)
else:
    print(x-y)

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:
def main():
    A, B, C, K = map(int, input().split())
    if K&1 == 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 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
    print(ans) if abs(ans)<10**18 else print("Unfair")
else:
    ans = B-A
    print(ans) if abs(ans)<10**18 else print("Unfair")

Submission status: Accepted

Solution code:
A, B, C, K = [int(s) for s in input().split(' ')]
n = K % 2
ANS = (A-B) * (-1) ** n
print(ANS)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
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 abs(a-b) > 10**18:
    print('Unfair')
    exit()
if k % 2 == 0:
    print(a-b)
else:
    print((a-b)*(-1))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

L = [int(v) for v in input().split()]

if L[3] % 2 == 0:
    print(L[0] - L[1])
else:
    print(L[1] - L[0])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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:
a, b, c, k = map(int, input().split())
if k % 2 == 0:
    ans = a -b 
else:
    ans = b - a

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

print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

"""
a,b,c -> b+c,a+c,a+b
a-b,b-c,c-a -> b-a,c-b,a-c
"""

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b,_,k=map(int,input().split());print((a-b,b-a)[k%2])

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
a,b,c,k=map(int,input().split())
t=-1
if k%2==0:t=1
print(t*(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:
    print(B-A)
else:
    print(A-B)

Submission status: Accepted

Solution code:
# 手を動かしていくつかのabcとkで試したら浮かぶ 
# kが大きいけど最後の文字だけみれば偶奇が分かる

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# AGC024A - Fairness
def main():
    # a - b repeats: a - b (when even), -a + b (odd)
    a, b, c, k = tuple(map(int, input().rstrip().split()))
    ans = a - b if k % 2 == 0 else -a + b
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# AGC024A - Fairness
def main():
    # a - b repeats: a - b (when even), -a + b (odd)
    a, b, c, k = tuple(map(int, input().rstrip().split()))
    ans = a - b if k % 2 == 0 else -a + b
    flg = ans <= 10 ** 18
    print(ans if flg else "Unfair")


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import copy
import sys
import math

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


def listtodict(a):
	b = {}
	for i in a:
		try:
			b[i] += 1
		except:
			b[i] = 1
	return b

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

main()

Submission status: Accepted

Solution code:

if __name__ == "__main__":
    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:
A,B,C,K=map(int,input().split())
if abs(A-B)>10**18:
    print('Unfair')
    exit()
print((A-B)*(-1)**K)

Submission status: Accepted

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

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

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(i) for i in 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:
  print(b - a)
else:
  print(a - b)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
from collections import defaultdict, deque
import math
from math import factorial
import fractions
import re

BIGNUM = 10 ** 9 + 7

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

    if abs(K) > 10 ** 18:
        print("Unfair")
        return

    if 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())
"""
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)
"""
if abs(a-b) >= 10**18:
  print("Unfair")
else:
  if k%2==1:
    print(b-a)
  else:
    print(a-b)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

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

q0 = np.matrix([A, B, C]).T
mat = np.matrix([[0, 1, 1], [1, 0, 1], [1, 1, 0]])

q1 = mat**K * q0
ans = q1[0, 0] - q1[1, 0]
if ans > 1E18:
    print('Unfair')
else:
    print(ans)

Submission status: Accepted

Solution code:
a, b, c, k = [ int(v) for v in 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:n=a-b
else:n=b-a
if n>10**18:print("Unfair")
else:print(n)

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:
    ans=a-b
else:
    ans=b-a
print(ans)

Submission status: Accepted

Solution code:
A,B,C,K = list(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) * ( -1) ** K)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# input
a, b, c, k = map(int, input().split())

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

Submission status: Accepted

Solution code:
from sys import stdin
A, B, C, K = [int(x) for x in stdin.readline().rstrip().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:
#!/usr/bin/env python3
import sys


def solve(A: int, B: int, C: int, K: int):
    if(K%2 == 0):
        print(A-B)
    else:
        print(B-A)
    return


# Generated by 1.1.4 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((-1)**(k%2==0)*(b-a))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a, b, c, k = [int(i) for i in 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())
a,b,c
b+c,a+c,a+b
if k%2!=0:
    print(b-a)
else:
    print(a-b)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import numpy as np

def main():
    A, B, C, K = map(int, input().split())
    if K == 0:
        print(A-B)
        return
    base = np.matrix([[0, 1, 1], [1, 0, 1], [1 ,1 ,0]])
    X = base ** K
    result = np.matrix([[A, B, C]]) \
        .dot(X) \
        .dot(np.matrix([[1], [-1], [0]]))
    ans = result[0, 0]
    if 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())
mod = 1e18
if k % 2 == 1:
    ans = b - a
else:
    ans = a - b
if abs(ans) >= mod:
    print('Unfair')
else:
    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:
import sys
input = sys.stdin.readline

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:
# -*- coding: utf-8 -*-
"""
A - Fairness
https://atcoder.jp/contests/agc024/tasks/agc024_a

"""
import sys


def solve(A, B, C, K):
    if K%2:
        return B-A
    return A-B


def main(args):
    A, B, C, K = map(int, input().split())
    ans = solve(A, B, C, K)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
a,b,c,K=map(int,input().split())
m=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):
  print(b-a)
else:
  print(a-b)

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:
    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
if abs(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)>1e18:
    print('Unfair')
    quit()
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 ans > 10 ** 18:
    ans = 'Unfair'

print(ans)

Submission status: Accepted

Solution code:
# 2019/06/02
# AtCoder Grand Contest 024 - A

# Input
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"

# Output
print(ans)

Submission status: Accepted

Solution code:
num_1 , num_2 , num_3, loops = input().split()
num_1 = int(num_1)
num_2 = int(num_2)
num_3 = int(num_3)
loops = int(loops)

if abs(num_1 - num_2) > (10**18):
    print('Unfair')

elif (loops % 2) == 0:
    print(num_1 - num_2)

elif (loops % 2) == 1:
    print(num_2 - num_1)

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 == 1:
    print(B-A)
else:
    print(A-B)

Submission status: Accepted

Solution code:
a, b, c, k = [int(item) for item in input().split()]
if k % 2 == 0:
    print(a-b)
else:
    print(b-a)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A, B, C, K = map(int, input().split())
  
ans = [A - B, B - A][K%2]
if ans > 1e18:
  print("Unfair")
else:
  print(ans)

Submission status: Accepted

Solution code:
a, b, c, k = map(int, input().split())
if abs((a-b)*(-1)**k) > 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:
	print(A - B)
else:
	print(B - A)

Submission status: Accepted

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