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: Runtime Error

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

itr = k//3
amari = k%3

a *= pow(2,itr)
b *= pow(2,itr)
c *= pow(2,itr)

for i in range(amari):
  newa=b+c
  newb=a+c
  newc=b+c
  a,b,c = newa,newb,newc

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

if abs(a - b) >=th:
    print("Unfair")
elif k == 0:
    print(a - b)
else:
    print(b - a)

Submission status: Runtime Error

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

if result >=th:
    print("Unfair")
elif k == 0:
    print(a - b)
else:
    print(b - a)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#print#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
from collections import Counter
def resolve():
    A,B,C,K=pin()
    for i in range(K):
        x,y,z=B+C,C+A,A+B
        A,B,C=x,y,z
        t=(A-B)
        if abs(t)>10**18:print("Unfair");return
    print(t)
    
#%%submit!    
resolve()

Submission status: Runtime Error

Solution code:
#print#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
from collections import Counter
def resolve():
    A,B,C,K=pin()
    for i in range(K)
        x,y,z=B+C,C+A,A+B
        A,B,C=x,y,z
    t=(A-B)
    if abs(t)>10**18:print("Unfair");return
    print(t)
    
#%%submit!    
resolve()

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
A,B,C,K = map(int,input().split())
N = [A,B,C]
N2 = N[:]
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: Runtime Error

Solution code:
A,B,C,K = map(int,input().split())
N = [A,B,C]
N2 = N[:]
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
print(N2)
ans = N2[0] - N2[1]
if abs(ans) > 10**18:
    print('Unfair')
else:
    print(ans)

Submission status: Runtime Error

Solution code:
N = list(map(int,input().split()))
N2 = N[:-1]
for i in range(N[3]):
    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: Runtime Error

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

Solution code:
A = list(map(int,input().split()))
if A[3] == 0 or A[3]%2 == 0:
    print(A[0]-A{1])
else:
    print(A[1]-A[0])

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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: Runtime Error

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

 if result > 10 **18:
    print("Unfair")
elif k % 2 == 0:
    print(result)
elif l % 2 == 1:
    result = result * -1
    print(result)

Submission status: Runtime Error

Solution code:
def abs(k):
  if k >= 0:
    return k
  else:
    return -k
  
def main():
  a, b, c ,n = list(map(int,input().split()))
  i for i in range(n):
    a = b + c
    b = c + a 
    c = a + b
  res = a - b
  if abs(res) > 10 ** 18:
    print('Unfair')
  else:
    print(res)

Submission status: Runtime Error

Solution code:
def abs(k):
  if k >= 0:
    return k
  else:
    return -k

a, b, c ,n = list(map(int,input().split()))
i for i in range(n):
  a = b + c
  b = c + a 
  c = a + b
res = a - b
if abs(res) > 10 ** 18:
  print('Unfair')
else:
  print(res)

Submission status: Runtime Error

Solution code:
n = int(input())

l = len(str(n))
# if n < 10:
#     ans = n
# else:
ans1 = 9 * (l-1) + int(str(n)[0]) - 1
ans2 = sum([int(x) for x in list(str(n))])
ans = max(ans1, ans2)
# print(ans1, ans2)
print(ans)

Submission status: Runtime Error

Solution code:
inputs = split(input())
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: Runtime Error

Solution code:
def main():
    _, _ = map(int, input().split())
    L = list(map(int, input().split()))
    R = list(map(int, input().split()))
    lcnt = [0] * 31
    rcnt = [0] * 31
    for l in L:
        lcnt[l-10] += 1
    for r in R:
        rcnt[r-10] += 1
    ans = sum(map(min, zip(lcnt, rcnt)))
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

if k==0:
    if abs(a-b)>=10**18:
        print("Unfair")
    else:
        print(a-b)
elif k==1:
    if abs(a-b)>=10**18:
        print("Unfair")
    else:
        print(b-a)
elif abs(a-b)==0:
    print(0)
else:
    if k>=100:
        print("Unfair")
    else:    
        m = int(2(2**(k-1)-(-1)**(k-1))/3)
        n = int((2**k-(-1)**k)/3)
        ans = (a-b)*(m-n)
        if abs(ans)>=10**18:
            print("Unfair")
        else:
            print(ans)

Submission status: Runtime Error

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

if k==0:
    if abs(a-b)>=10**18:
        print("Unfair")
    else:
        print(a-b)
elif k==1:
    if abs(a-b)>=10**18:
        print("Unfair")
    else:
        print(b-a)
elif abs(a-b)==0:
    print("Unfair")
else:
    if k>=100:
        print("Unfair")
    else:    
        m = int(2(2**(k-1)-(-1)**(k-1))/3)
        n = int((2**k-(-1)**k)/3)
        ans = (a-b)*(m-n)
        if abs(ans)>=10**18:
            print("Unfair")
        else:
            print(ans)

Submission status: Runtime Error

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

if k<=1:
    if abs(a-b)>=10**18:
        print("Unfair")
    else:
        print(a-b)
elif k==1:
    if abs(a-b)>=10**18:
        print("Unfair")
    else:
        print(b-a)
else:
    m = int(2(2**(k-1)-(-1)**(k-1))/3)
    n = int((2**k-(-1)**k)/3)
    ans = (a-b)*(m-n)
    if abs(ans)>=10**18:
        print("Unfair")
    else:
        print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
a,b,c,k=(int(i) for i in input().split())
def ans(x):
  if abs(x)>=10e18:
    return 'Unfair'
  else:
    return x
if k==0
  print(ans(a-b))
else:
  print(ans(b-a))

Submission status: Runtime Error

Solution code:
import copy
A, B, C, K = map(int, input().split())
maxL = 10 ** 18
L = [A, B, C]
for i in xrange(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: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
a, b, _, k = [int(i) for x in input().strip().split(" ")]

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

Submission status: Runtime Error

Solution code:
N = int( input())
A = [ int( input()) for _ in range(N)]
now = 0
ans = 0
if A[0] != 0:
    ans = -1
else:
   for i in range(1,N):
       a = A[i]
       # if a > i:
       #     ans = -1
       #     break
       #el
       if now + 1 == a:
           ans += 1
           now += 1
       elif now >= a:
           ans += a
           now = a
       else:
           ans = -1
           break
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
s=input().split()
print((int(s[0])-int(s[1]))*(-1)**s[3])

Submission status: Runtime Error

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

Submission status: Runtime Error

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

def func():
  global A
  global B
  global C
  bufA=B+C
  bufB=C+A
  bufC=A+B
  A=bufA
  B=bufB
  C=bufC

for i in range(0,K):
  func()

Answer=A-B
if Answer > 1000000000000000000 :
  print("Unfair")
else:
  print(Answer)

Submission status: Runtime Error

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

unfair = 10^18

if k%2 ==0:
	if a-b <= unfair
		print(a-b)
	else:
		print('Unfair')
else:
	if b-a <= unfair
		print(b-a)
	else:
		print('Unfair')

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import xlwt, json, urllib.request

def getDate():
    page = urllib.request.urlopen("http://contests.acmicpc.info/contests.json")
    return page.read().decode()

def getJson(s):
    j = json.loads(s)
    return j

def writeExcel(header, v):
    wb = xlwt.Workbook()
    ws = wb.add_sheet('Sheet1')
    for c in range(len(header)):
        ws.write(0, c, header[c])
        for r in range(len(v)):
            ws.write(r+1, c, v[r][header[c]])
    wb.save('Recent contests.xls')

header = ['oj', 'name', 'link', 'start_time', 'week', 'access']
writeExcel(header, getJson(getDate()))

Submission status: Runtime Error

Solution code:
import sys

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

a_0 = 1
a_1 = 0
a_2 = 0

i = 0
while i < K:
    a_0 = a_1 + a_2
    a_1 = a_0 + a_2
    a_2 = a_0 + a_1
    
    i = i + 1
    
res = (A - B) * (a[0] - a[1])
if res < 10**18:
    print(res)
else:
    print("unfair")

Submission status: Runtime Error

Solution code:
import sys
from sys import stdin, stdout

rem=10**9+7
sys.setrecursionlimit(10 ** 6)
take = lambda: map(int, stdin.readline().split())

n=input()
ans=[1 for i in range(n+1)]
pos={}
for i in range(1,n+1):
    x=take()[0]
    pos[x]=i
for i in range(n-1,0,-1):
    if pos[i]<pos[i+1]:
        ans[i]=ans[i+1]+1
#print(ans)
print n-max(ans)

Submission status: Runtime Error

Solution code:
a = raw_input().split()

if int(a[3]) % 2 == 0:
    return int(a[1]) - int(a[2])
else:
    return -1 * (int(a[1]) - int(a[2]))

Submission status: Runtime Error

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

for i in range(0, k):
  l = [b+c, c+a, a+c]
  a = l[0]
  b = l[1]
  c = l[2]
  
print a - b

Submission status: Runtime Error

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

m = 1000000000000000000

def recursion(a,b,c, k, i):
        if i < k:
                return recursion(b+c, a+c, a+b, k, i+1)
        else:
                return [a,b,c]

result = recursion(a,b,c, k, 0)
output = result[0] - result[1]
if output > m:
        print "Unfair"
else:
        print output

Submission status: Runtime Error

Solution code:
raw = raw_input().split()
a = int(raw[0])
b = int(raw[1])
c = int(raw[2])
k = int(raw[3])
m = 1000000000000000000

for i in range(0,k):
    old_a = a
    old_b = b
    old_c = c
    a = old_b + old_c
    b = old_a + old_c
    c = old_a + old_b

output = a - b
if output > m:
        print "Unfair"
else:
        print output

Submission status: Runtime Error

Solution code:
n=int(input())
p=[]
for i in range (n):
	p.append(int(input()))
pos=0
num=0
n_th = 0
s={}
for i in p:
	if i-1 in s:
		s[i]=s[i-1]+1
	else:
		s[i]=1
print(n-max(s.values()))

Submission status: Runtime Error

Solution code:
n = int(input())
l = [ int(input().rstrip()) for i in range(n)]

s = {}
for i in l:
    if i - 1 in s:
        s[i] = s[i - 1] + 1
        del s[i - 1]
    else:
            s[i] = 1
print(n - max(s.values()))

Submission status: Runtime Error

Solution code:
a,b,c,k = map(int,raw_input())

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
A_prev, B_prev, C_prev, K = map(int, input().split())

for _ in range(K):
  A_cur = B_prev + C_prev
  B_cur = A_prev + C_prev
  C_cur = A_prev + B_prev
  A_prev, B_prev, C_prev = A_cur, B_cur, C_cur
ans = A_cur - B_cur
print(A_cur - B_cur if ans <= 1e18 else 'Unfair')

Submission status: Runtime Error

Solution code:
n = int(input())
p = [int(input()) for _ in range(n)]
q = [0] * (n+1)

for i in range(n):
    q[p[i]] = i
maxl = 1
cnt = 1
last = p[0]
for i in range(1, n):
    if q[i+1] > q[i]:
        cnt += 1
    else:
        maxl = max(maxl, cnt)
        cnt = 1

print(n - maxl)

Submission status: Runtime Error

Solution code:
def a():

Submission status: Runtime Error

Solution code:
def spaceinput():
    return list(map(int,input().split(" ")))
    
from sympy import *
import numpy as np

A = Matrix(([0,1,1],[1,0,1],[1,1,0]))
P,D = A.diagonalize()

ss=spaceinput()

K=ss[3]
a=Matrix([ss[:3]]).T
dg=np.diag(np.array(D))
DD=D.copy()
DD[0,0]=(dg[0]**K)
DD[1,1]=dg[1]**K

ans=((Matrix([1,-1,0]).T)*P *(DD)*(P.inv())*(a))[0]
print(ans)

Submission status: Runtime Error

Solution code:
def spaceinput():
    return list(map(int,input().split(" ")))
    
from sympy import *
A = Matrix(([0,1,1],[1,0,1],[1,1,0]))
P,D = A.diagonalize()

ss=spaceinput()

K=ss[3]
a=Matrix([ss[:3]]).T
dg=np.diag(np.array(D))
DD=D.copy()
DD[0,0]=(dg[0]**K)
DD[1,1]=dg[1]**K

ans=((Matrix([1,-1,0]).T)*P *(DD)*(P.inv())*(a))[0]
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

line = input()

N = int(line)
A = np.array([0]*N)

for i in range(N):
    line = input()
    A[i] = int(line)

    
def IsNotPossible(A):
    foo = 0
    
    if A[0] != 0:
        foo = 1
        return foo
        
    else:
        for i in range(N-1):
            if A[i] + 1 < A[i+1]:
                foo  = 1
                break
        return foo

if IsNotPossible(A):
    print(-1)
    
else:
    count = 0
    for i in range(N-1):
        a = A[N-1-i]
        
        if a == 0:
            continue
        elif a == A[N-2-i] + 1:
            count += 1
        else:
            count += a
            
    print(count)

Submission status: Runtime Error

Solution code:
line = input()

N = int(line)
A = np.array([0]*N)

for i in range(N):
    line = input()
    A[i] = int(line)

    
def IsNotPossible(A):
    foo = 0
    
    if A[0] != 0:
        foo = 1
        return foo
        
    else:
        for i in range(N-1):
            if A[i] + 1 < A[i+1]:
                foo  = 1
                break
        return foo

if IsNotPossible(A):
    print(-1)
    
else:
    count = 0
    for i in range(N-1):
        a = A[N-1-i]
        
        if a == 0:
            continue
        elif a == A[N-2-i] + 1:
            count += 1
        else:
            count += a
            
    print(count)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun May 20 20:55:50 2018
AGC024B
@author: maezawa
"""

n = int(input())
q = [None for _ in range(n)]
for i in range(n):
    p = int(input())
    q[p-1] = i+1

max_cnt = 0
cnt = 1
qpre = q[0]
 
for i in range(1,n):
    if q[i] > qpre:
        cnt += 1
    else:
        if max_cnt < cnt:
            max_cnt = cnt
        cnt = 1
    qpre = q[i]
if max_cnt < cnt:
    max_cnt = cnt

print(n-max_cnt)

Submission status: Runtime Error

Solution code:
n=int(input())
r=0
b=0
for i in range(n):
 t=int(input())
 if i==0!=t or b+1<t:print(-1);exit()
 elif b>=t:r+=b
 b=t
print(r+b)

Submission status: Runtime Error

Solution code:
line = input()

N = int(line)
A = np.array([0]*N)

for i in range(N):
    line = input()
    A[i] = int(line)

def IsNotPossible(A):
    foo = 0
    
    if A[0] != 0:
        foo = 1
        
    else:
        for i in range(N-1):
            if A[i] + 1 < A[i+1]:
                foo  = 1
                break
    
    return foo

if IsNotPossible(A):
    print(-1)
    
else:
    count = 0
    for i in range(N-1):
        a = A[N-1-i]
        
        if a == 0:
            continue
        elif a == A[N-2-i] + 1:
            count += 1
        else:
            count += a
            
    print(count)

Submission status: Runtime Error

Solution code:
import sys;raw_input = sys.stdin.readline
N = int(raw_input())
A = [None]*N
C = [0]*N
for i in xrange(N):
    A[i] = int(raw_input())
b = False
for i in xrange(1, N):
    if A[i] - A[i-1] > 1 :
        b = True
        break
if b or A[0] != 0:
    print -1
else:
    B = [0]*N
    ans = 0
    for i in xrange(1, N):
        val = B[i-1] + 1
        B[i] = val if val <= A[i] else 0
        C[i] = A[i] - B[i]
    for i in xrange(N-1, 0, -1):
        if B[i-1] == B[i]-1 :
            C[i-1] = min(C[i], C[i-1])
    C[0] = 0
    for i in xrange(1, N):
        if B[i] == B[i-1] + 1:
            assert C[i] >= C[i-1]
            C[i] = C[i-1] if A[i-1] + 1 >= B[i] + C[i-1] else min(C[i], A[i-1]-B[i])
            ans += (A[i] - B[i-1] - C[i] if B[i+1] == B[i] + 1 or B[i+1] <= 1 else A[i]) if i < N-1 else A[i] - B[i-1] - C[i]
        else:
            ans += A[i]
    print ans

Submission status: Runtime Error

Solution code:
n = int(input())
seq = []
for i in range(n):
 k=int(input())
 seq.append(k)
i=0
count =0
while i<n:
 k=i+1
 while k<n:
     if seq[k]-seq[i]==k-i:
         count = count + 1
     k=k+1
 i=i+1

print(n-count)

Submission status: Runtime Error

Solution code:
n=int(input())
a=[]
for i in range(n):
  x=int(input())
  a.append(x)
d={}
f=0
maxi=0
for i in range(n):
  if((a[i]-1) in d):
    d[a[i]]=d[a[i]-1]+1
    if(f==0):
      maxi=d[a[i]]
    else:
      if(d[a[i]]>maxi):
        maxi=d[a[i]]
  else:
    d[a[i]]=0
print(n-maxi-1)

Submission status: Runtime Error

Solution code:
n=int(input())
a=[]
for i in range(n):
     a.append([int(input()),i+1])
a=sorted(a,key=lambda x:x[0])

ans=0
count=0
bef=0
for i,j in a:
    if j>bef:
        count+=1
        ans=max(ans,count)
    else:
        count=1
    bef=j
print(n-ans)

Submission status: Runtime Error

Solution code:
N = int(input())

start = int(input())
flag = 0
if start != 0:
 flag = 1
t = 0

for i in range(N-1):
 k = int(input())
 if k == start:
  t += start
 elif k == start + 1:
  t += 1
  start = k
 elif k == 0:
  start = 0
 elif k > start + 1:
  t = -1
  break
 else:
  t += k
  start = k

if flag ==1:
 t = -1
print(t)

Submission status: Runtime Error

Solution code:
da = list(map(int,input().split()))
 
m = 0
l = pow(10,18)
  
if da[3] % 2 == 1:
  k = da[1] -da[0]
else:
  k = da[0] -da[1]

elif abs(da[0] - da[1]) < l:
  print(da[0] - da[1])
elif abs(da[0] - da[1]) >= l:
  print("Unfair")

Submission status: Runtime Error

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

if t==n and n==h:
    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: Runtime Error

Solution code:

n = int(input())
p = [int(input()) for _ in range(n)]


lsi = list(0 for _ in range(n+1))

for i in range(n):
    num = p[i]
    lsi[num] = 1

    for j in range(num):
        if j + lsi[j] == num:
            lsi[j] += 1

print(n - max(lsi))

Submission status: Runtime Error

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

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: Runtime Error

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

for i in range(k):
    t, n, h = n+h, t+h, t+n
    result = t-n

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

for i in range(k):
    t, n, h = n+h, t+h, t+n
    result = t-n
    if result > pow(10,18):
        print("Unfair")

print(result)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

if k > 1100000000000000000:
    print('Unfair')
    
else:
    A = [0]*(k+1)
    B = [0]*(k+1)
    C = [0]*(k+1)
    A[0] = a
    B[0] = b
    C[0] = c

    for i in range(1,k+1):
        A[i] = B[i-1] + C[i-1]
        B[i] = C[i-1] + A[i-1]
        C[i] = A[i-1] + B[i-1]
        
    if abs(A[-1] - B[-1]) > 10**18:
        print('Unfair')

    else: print(A[-1] - B[-1])

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys
da = list(map(int,input().split()))

m = 0

if pow(2,da[3])*(da[0]-da[1]) >= pow(10,18):
  print("Unfair")
  sys.exit()

def aaa(d,a,t):
  k = [0]*3
  k[0] = d + a
  k[1] = d + t
  k[2] = a + t
  return k

for i in range(da[3]):
  if da[0] == da[1] and da[1] == da[2]:
    break
  da = aaa(da[0],da[1],da[2])
  if abs(da[0] -da[1]) >= pow(10,18):
    break
  if abs(2(da[0] -da[1])) < pow(10,18):
    m = 1
    break

if abs(da[0] - da[1]) < pow(10,18):
  print(da[0] - da[1])
elif abs(da[0] - da[1]) >= pow(10,18) or m ==1:
  print("Unfair")

Submission status: Runtime Error

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

if (A-B) ** 2 **0.5 > 10e18:
 print("Unfair")
elif K % 2 == 1:
 print(A-B)
else:
 print(B-A)

Submission status: Runtime Error

Solution code:
import math

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

if k % 2 != 1:
    print(a - b if abs(math.log10(abs(a-b))) <= 18 else "Unfair")
else:
    print(b - a if abs(math.log10(abs(a-b))) <= 18 else "Unfair")

Submission status: Runtime Error

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

m = 0

def aaa(d,a,t):
  k = [0]*3
  k[0] = d + a
  k[1] = d + t
  k[2] = a + t
  return k

for i in range(da[3]):
  if da[0] == da[1] and da[1] == da[2]:
    break
  da = aaa(da[0],da[1],da[2])
  if abs(da[0] -da[1]) >= pow(10,18):
    break
  if abs(2(da[0] -da[1])) < pow(10,18):
    m = 1
    break

if abs(da[0] - da[1]) < pow(10,18):
  print(da[0] - da[1])
elif abs(da[0] - da[1]) >= pow(10,18) or m ==1:
  print("Unfair")

Submission status: Runtime Error

Solution code:
import math

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

if k % 2 != 1:
    print(a - b if abs(math.log10(a-b)) <= 18 else "Unfair")
else:
    print(b - a if abs(math.log10(a-b)) <= 18 else "Unfair")

Submission status: Runtime Error

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

m = 0

def aaa(d,a,t):
  k = [0]*3
  k[0] = d + a
  k[1] = d + t
  k[2] = a + t
  return k


for i in range(da[3]):
  if da[0] == da[1] and da[1] == da[2]:
    break
  da = aaa(da[0],da[1],da[2])
  if abs(da[0] -da[1]) >= pow(10,18):
    break
  if abs(2(da[0] -da[1])) < pow(10,18):
    m = 1
    break

if abs(da[0] - da[1]) < pow(10,18):
  print(da[0] - da[1])
elif abs(da[0] - da[1]) >= pow(10,18) or m ==1:
  print("Unfair")

Submission status: Runtime Error

Solution code:
line = readline()
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: Runtime Error

Solution code:
ine = readline()
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: Runtime Error

Solution code:
#include <bits/stdc++.h>
using std::cout;
using std::endl;
using std::cin;

int main(){
	int a, b, c, k; cin >> a >> b >> c >> k;
	
	if(k == 0) cout << a - b << endl;
	else if(abs(b - a) > 1e18) cout << "Unfair" << endl;
	else cout << b - a << endl;
	return 0;
}

Submission status: Runtime Error

Solution code:
# import bisect
# import heapq
# import math
# import random
# import sys
# from collections import Counter, defaultdict
# from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
# from functools import lru_cache, reduce
# from itertools import combinations, combinations_with_replacement, product


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args, **kwargs):
    print(*args, **kwargs, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


# @mt
def slv(A, B, C, K):
    ans = A - B if K % 2 == 0 else B - A
    if abs(ans) > 1e+18:
        return 'Unfair'
    return ans


def main():
    A, B, C, K = read_int_n()

    print(slv(A, B, C, K))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args, **kwargs):
    print(*args, **kwargs, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


# @mt
def slv(A, B, C, K):
    ans = A - B if K % 2 == 0 else B - A
    if abs(ans) > 1e+18:
        return 'Unfair'
    return ans


def main():
    A, B, C, K = read_int_n()

    print(slv(A, B, C, K))


if __name__ == '__main__':
    main()