peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
import collections
N = int(input())
A = list(map(int, input().split()))

B = [0 for _ in range(N)]
C = [0 for _ in range(N)]
for i in range(N):
  B[i] = i - A[i]
  C[i] = i + A[i]
lis1 = collections.Counter(B)
lis2 = collections.Counter(C)
count = 0
for key, value in lis1.items():
  if key in lis2:
    count += value * lis2[key]
print(count)
# Judge status: Wrong Answer
def wolfgame(S,W):
    if 1 <= S <= W <= 100:
        print("unsafe")
    elif 1 <= W < S <= 100:
        print("safe")
    else :
        print("invalid")
# Judge status: Accepted
X = int(input())
if X>=0 and X<=10**9:
    a, b = divmod(X, 500)
    if X >= 500:
        c = int(b/5)
        d = int(a*1000) + c*5
        print(d)
    elif X >= 5 and X <500:
        c = int(X/5)*5
        print(c)
    else:
        print(0)
# Judge status: Accepted

def solve():
  n,k = (int(i) for i in input().split())
  r,s,p = (int(i) for i in input().split())
  t = input()
  score = 0
  times = 0
  possible = [False]*n
  for i in range(n):
    if i >= k:
      if t[i-k] == t[i] and possible[i-k]== False:
        possible[i] = True
        continue

    if t[i] == "r":
        score += p
    elif t[i] == "s":
        score += r
    elif t[i] == "p":
        score += s
  print(score)
solve()
# Judge status: Accepted
from collections import defaultdict

N = int(input())
A = list(map(int, input().split()))

d = defaultdict(int)

for a in A:
    d[a+1] += 1
    d[a] += 1
    d[a-1] += 1
    
print(max(d.values()))
# Judge status: Accepted
n = int(input())
l = list(range(111,1000,111))

if n % 111 == 0:
    print(n)
else:
    print(l[n // 111])
# Judge status: Accepted
import numpy as np
N = int(input())
X = np.array(input().split()).astype(int)
P = round(np.average(X))
print(int(np.sum((P-X)**2)))
# Judge status: Accepted
#!/usr/bin/env python3
s = input().replace("/", "")
h = "20190430"
print("Heisei") if s <= h else print("TBD")
# Judge status: Accepted
N, M, X = map(int, input().split())
C = [0]*N
A = [None]*N
for i in range(N):
  C[i], *A[i] = map(int, input().split())

oo = 10**10
ans = oo
for b in range(2**N):
  c = 0
  T = [0]*M
  for i in range(N):
    if b>>i&1:
      c += C[i]
      for j in range(M):
        T[j] += A[i][j]
  ok = True
  for i in range(M):
    if T[i]<X:
      ok = False
  if ok:
    ans = min(ans, c)

print(ans if ans<oo else -1)
# Judge status: Wrong Answer
N, L = map(int,input().split())

l = 0
m = 10000
for i in range(1,N+1):
  l += L+i-1
  m = min(m,abs(L+i-1))

l -= m
print(l)
# Judge status: Accepted
A, B = map(int, input().split())

ans = 0
for i in range(A, B+1):
    if str(i) == str(i)[::-1]:
        ans += 1
print(ans)
# Judge status: Accepted
def main():
    K = int(input())
    S = input()
    if len(S) <= K:
        print(S)
    else:
        s = S[:K]
        print(s + "...")


if __name__ == '__main__':
    main()
# Judge status: Accepted
N = int(input())
works = sorted([list(map(int, input().split())) for _ in range(N)], key=lambda x: x[1])
result = True
cnt = 0
for a, b in works:
    cnt += a
    if cnt > b:
        result = False
        break

print('Yes' if result else 'No')
# Judge status: Accepted
n, x, y = map(int, input().split())
cnt = [0] * n
for i in range(1, n+1):
    for j in range(i+1, n+1):
        cnt[min(j-i, abs(x-i)+1+abs(y-j), abs(y-i)+1+abs(x-j))] += 1

for i in range(1,n):
    print(cnt[i])
# Judge status: Wrong Answer
x, y = map(int, input().split())

low = y//4
high = y//2

if low <= x <= high:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
c = [list(map(int,input().split())) for i in range(3)]
a = [0]*3
b = [0]*3
b[0] = c[0][0]
b[1] = c[0][1]
b[2] = c[0][2]
a[1] = c[1][1]-b[1]
a[2] = c[2][2]-b[2]

for i in range(3):
    for j in range(3):
        if c[i][j] != a[i]+b[j]:
            print("No")
            exit()
print("Yes")
# Judge status: Accepted
n = int(input())
P = [int(x) for x in input().split()]
count = 0

for i in range(n-2):
  if (P[i] < P[i+1]) and (P[i+1] < P[i+2]):
    count += 1
  elif (P[i] > P[i+1]) and (P[i+1] > P[i+2]):
    count += 1

print(count)
# Judge status: Accepted
s=list(input())
k=int(input())
for e,i in enumerate(s):
    c=(123-ord(i))%26
    if k>=c:
        s[e]="a"
        k-=c
    else:s[e]=i
l = chr((ord(s[-1])-97+k)%26+97)
print("".join(s[:-1])+l)
# Judge status: Accepted
x=int(input())
 
p=x//11
q=x%11
q2=q-6
 
if q==0:
  print(2*p)
elif q2<=0:
  print(2*p+1)
else:
  print(2*p+2)
# Judge status: Wrong Answer
a,b=map(int,input().split())
if a<=b:
    print(a)
else:
    print(b)
# Judge status: Accepted
y, m, d = map(int, input().split("/"))
if y * 365 + m * 30 + d > 2019 * 365 + 4 * 30 + 30:
  print("TBD")
else:
  print("Heisei")
# Judge status: Wrong Answer
import sys
X, N = map(int, input().split())
P = list(map(int, input().split()))

if len(P) == 0 or not X in P:
    print(X)
    sys.exit()

flg = 1000
ans = 1000
m = max(P)
itera = list(range(1, m + 1))
itera.reverse()

for i in itera:
    if not i in P and flg > abs(X - i):
        flg = abs(X - i)
        ans = min(ans, i)

if ans == 1000:
    if abs(X - m - 1) <= X:
        ans = m + 1

print(ans)
# Judge status: Accepted
N = int(input())
if N == 1:
    print(1.0)
elif N % 2 == 0:
    print(0.5)
else:
    print((N - (N // 2)) / N)
# Judge status: Accepted
n = int(input())
s = input()

ans = 0
for i in range(1, n):
    temp = len(set(s[:i]) & set(s[i:]))
    if temp > ans:
        ans = temp
print(ans)
# Judge status: Accepted
a,b=map(str,input().split())
c,d=map(int,input().split())
e=input()
if a==e:
    c=c-1
else:
    d=d-1
print(c,d)
# Judge status: Wrong Answer
N = int(input())
ma1 = 0
ma2 = 0
A = list(map(int,input().split()))
a = sorted(A,reverse = True)

hold = 0
count = 0

for i in a:
  if i == hold:
    count += 1
  else:
    if count > 3 and ma1 == 0:
      ma1 = hold
      ma2 = hold
    elif count > 1:
      if ma1 == 0:
        ma1 = hold
      elif ma2 == 0:
        ma2 = hold
    hold = i
    count = 1
    if ma1 != 0 and ma2 != 0:
      break
    

print(ma1*ma2)
# Judge status: Wrong Answer

k = int(input())
if k % 2 == 0:
    print("-1")
    exit()
if k == 1 or k == 7:
    print("-1")
    exit()

seven_i = 7
for i in range(1,10**6):
    seven_i = seven_i*10+7
    seven_mod = seven_i % k

    if seven_mod == 0:
        print(i+1)
        exit()
    seven_i = seven_mod
print("-1")
# Judge status: Wrong Answer
c=input()
if c=='a' or 'i' or 'u' or 'e' or 'o':
    print('vowel')
else:
    print('consonant')
# Judge status: Accepted
S = input()[::-1]
ss = ['maerd', 'remaerd', 'esare', 'resare']

while True:
    for s in ss:
        if S.startswith(s):
            S = S[len(s):]
            break
    else:
        if S != '':
            print('NO')
            break

    if S == '':
        print('YES')
        break
# Judge status: Accepted
n, x = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
for i in range(n):
    if i != 0:
        y = A[i-1]+A[i]
    else:
        y = A[i]
    if y <= x:
        continue
    ans += y-min(x, y)
    A[i] -= y-min(x, y)
print(ans)
# Judge status: Accepted
n = int(input())
ans = 1
for i in range(1, n +1):
    ans*= i
    ans = ans % (10**9 + 7)
print(ans)
# Judge status: Wrong Answer
N = int(input())
sum=1

for i in range(1, N):
    sum = (sum*i)%1000000007

print(sum)
# Judge status: Accepted
N, K = map(int, input().split())
print(0 if N%K==0 else 1)
# Judge status: Accepted
N=int(input())
L=[list(map(int,input().split())) for i in range(N)]
R=[]
for i in range(N):
  a=max(0,L[i][0]-L[i][1])
  b=L[i][0]+L[i][1]
  R.append([b,a])
R.sort()

ans=0
last=0
for i in range(N):
  if last<=R[i][1]:
    ans+=1
    last=R[i][0]
print(ans)
# Judge status: Accepted
n, m = map(int, input().split())
a = list(map(int, input().split()))
b = []
a.sort()
for i in range(m):
    s, t = map(int, input().split())
    if t > a[0]:
        b.append([s, t])
b.sort(reverse=True, key=lambda x: x[1])
j = 0
for i in range(len(b)):
    if j >= n:
        break
    while a[j] < b[i][1] and b[i][0] >= 1:
        a[j] = b[i][1]
        b[i][0] -= 1
        j += 1
        if j >= n:
            break
print(sum(a))
# Judge status: Wrong Answer
import math
a, b, x = map(int, input().split())

A1 = 2*x/(a*b)
num = math.atan(b/A1)
print(math.degrees(num))
# Judge status: Wrong Answer

S = set(input())
T = set(input())

if len(S) == len(T):
    print('Yes')
else:
    print('No')
# Judge status: Accepted
X = input().rstrip()
cnt = 0
res = len(X)
for x in X:
    if x=="S":
        cnt += 1
    else:
        if cnt > 0:
            res -= 2
            cnt -= 1
print(res)
# Judge status: Accepted

N, M = map(int, input().split())
X = list(map(int, input().split()))

X.sort()
diff = sorted(X[i + 1] - X[i] for i in range(M - 1))
print(sum(diff[:max(0, M - N)]))
# Judge status: Wrong Answer
n = int(input())
a = 0
for i in range(n):
  a += i
print(a)
# Judge status: Accepted
n,k=map(int,input().split()) 
s=input() 
print(s[0:k-1]+s[k-1:k].lower()+s[k:])
# Judge status: Accepted
a,b = map(str,input().split())
c = int(a+b)
#print(float(c))
import math
#print(math.sqrt(c))
if c == int(math.sqrt(c))**2:
  print('Yes')
else:
  print('No')
# Judge status: Accepted
n,p = map(int,input().split())
al = list(map(int,input().split()))

for a in al:
    if a % 2 == 1:
        print(2**(n-1))
        exit()

if p == 0:
    print(2**n)
else:
    print(0)
# Judge status: Wrong Answer
n = int(input())
t = [0]
x = [0]
y = [0]
for i in range(n):
  t_, x_, y_ = map(int, input().split())
  t.append(t_)
  x.append(x_)
  y.append(y_)

for j in range(n):
  dt = t[j+1] - t[j]
  dx = x[j+1] - x[j]
  dy = y[j+1] - y[j]
  if dx+dy>dt or dt%2!=(dx+dy)%2:
    print('No')
    exit()
    
print('Yes')
# Judge status: Accepted
n = int(input())
l = list(map(int, input().split()))

mn = min(l)
mx = max(l)

ms = 10**9
ll = [0]*n
for j in range(mn, mx+1):
    for i in range(n):
        ll[i] = (l[i]-j)**2
        
    s = sum(ll)
    ms = min(ms, s)
    
print(ms)
# Judge status: Wrong Answer
N, K = list(map(int, input().split()))
D = list(map(int, input().split()))

for i in range(N, 10**5):
	for c in str(i):
		if c in D:
			break
	else:
		print(i)
		exit()
# Judge status: Accepted
import math
a,b=input().split()
a=int(a)
L=list(b)
if "." in L and L[0]==0:
  c=L[2]+L[3]
  c=int(c)
  print(c*a//100)
elif  "." in L and L[0]!=0:
  c=L[0]+L[2]+L[3]
  c=int(c)
  print(c*a//100)
# Judge status: Accepted
N, A, B, C, D = map(int, input().split())
S = input()

if "##" in S[A - 1: C] or "##" in S[B - 1: D]:
    print("No")
    exit(0)

if C <= D:
    print("Yes")
    exit(0)

ans = False
for i in range(B - 1, D):
    if (S[i - 1] == '.') and (S[i] == '.') and (S[i + 1] == '.'):
        ans = True
        break

if ans:
    print("Yes")
else:
    print("No")
# Judge status: Wrong Answer
import itertools
import math

n = int(input())
towns_li = []
for _ in range(n):
    co = list(map(int, input().split()))
    towns_li.append(co)
di = 0
for i in itertools.permutations(range(n)):
    for j in range(n - 1):
        di += math.sqrt(((towns_li[j][0] - towns_li[j+1][0]) ** 2 + (towns_li[j][1] - towns_li[j+1][1]) ** 2))
print(di / math.factorial(n))
# Judge status: Accepted
N, D = map(int, input().split())

print(-(-N // (2 * D + 1)))
# Judge status: Accepted
A, B, T = map(int, input().split())

r = (T // A) * B
print(r)
# Judge status: Wrong Answer
N=int(input())
a=0
for i in range(1,10**5+1):
  a+=i
  if i>=N:
    print(i)
    exit()
# Judge status: Wrong Answer
N = int(input())
import math
N = math.factorial(N)
print(N)
# Judge status: Wrong Answer
A, B, C, K = map(int, input().split())

la = [A]
lb = [B]
lc = [C]

if A == B == C:
    print("0")

for i in range(K):
    la.append(lb[-1] + lc[-1])
    lb.append(la[-2] + lc[-1])
    lc.append(la[-2] + lb[-2])

if abs(la[-1] - lb[-1]) > 10**18:
    print("Unfair")
else:
    print(la[-1] - lb[-1])
    #print(la, lb, lc)
# Judge status: Accepted
N,K=map(int,input().split())
AB=sorted([list(map(int,input().split()))for i in range(N)])

c=0
for ab in AB:
  c+=ab[1]
  if c>=K:
    exit(print(ab[0]))
# Judge status: Accepted
H, N = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(N)]
dp = [0]
for h in range(H):
    dp.append(min([dp[max(0, h + 1 - A)] + B for A, B in AB]))
print(dp[-1])
# Judge status: Accepted
n,m = map(int, input().split())

if n > (m+n)/3:
    print(m//2)
    exit()
if m > 10000000000:
    print(m//4)
    exit()

while n <= (n+m)/3:
    n += 1
    m -= 2

print(n-1)
# Judge status: Wrong Answer
s = input()

cnt = 0;

for temp in s:
    if temp == "1":
        cnt += 1
    print (cnt)
# Judge status: Accepted
N=int(input())
if N%1000==0:
    print(0)
else:
    print(1000-N%1000)
# Judge status: Accepted
x, y = map(int,input().split())
 
if x%y == 0:
    print(-1)
else:
    print(x)
# Judge status: Wrong Answer
a,b,c = map(int,input().split())
ans = 0

if a * c > b:
    for i in range(c,1,-1):
        if i * a <= b:
            if ans < i: 
                ans = i
    print(ans)
else:
    print(c)
# Judge status: Accepted
n, k = map(int, input().split())
arr = [int(j) for j in input().split()]
if k>= n:
	print(0)
else:
	arr.sort(reverse=True)
	print(sum(arr[k:]))
# Judge status: Wrong Answer
N = int(input())
A = list(map(int, input().split()))

A.sort()
A.reverse()

list = []
ans = 0
list.append(A[0])
for i in range(len(A)):
        ans += list[i]
        list.append(A[i])
        list.append(A[i])

print(ans)
# Judge status: Accepted
A, B, K = map(int, input().split())
num_list = []
for i in range(K):
    num_list.append(A + i)
for i in range(K):
    num_list.append(B - i)
num_list = sorted(set(num_list))

for i in num_list:
    if A <= i <= B:
        print(i)
# Judge status: Accepted
MAX_S = 1_000_000_000
N, K, S = list(map(int, input().split()))
for _ in range(K):
    print(S, '', end='')
if S == MAX_S:
    for _ in range(K, N):
        print(1, '', end='')
else:
    for _ in range(K, N):
        print(MAX_S, '', end='')
print()
# Judge status: Wrong Answer
k,x = map(int,input().split())

lis = [x]

for i in range(1,k):
    lis.append(x-1)
    lis.append(x+1)
new_list = sorted(lis)

print(" ".join(map(str,new_list)))
# Judge status: Accepted
A, B, C, K = [int(x) for x in input().split()]
print(min(K, A) - (min(K - A - B, C) if K - A - B > 0 else 0))
# Judge status: Accepted
import math
a=int(input())
b=math.ceil(a/1.08)
c=math.floor(a/1.08)
if math.floor(b*1.08)==a:
    print(b)
elif math.floor(c*1.08)==a:
    print(c)
else:
    print(":(")
# Judge status: Accepted
def resolve():
	a, b, k = map(int, input().split())
	if (b - a + 1) < k:
		for i in range(a, b+1):
			print(i)
		return
	for i in range(a, min(a+k, b-k+1)):
		print(i)
	for i in range(b-k+1, b+1):
		print(i)
resolve()
# Judge status: Accepted
s = str(input())
a = 0
b = 0
for i in range(len(s)+1):
    if s[i] == "A":
        a = i+1
        break
    else:
        pass
for i in reversed(range(len(s))):
    if s[i] == "Z":
        b = i+1
        break
    else:
        pass
print(b - a + 1)
# Judge status: Accepted
n,m=map(int,input().split())
x=[]
sum=0
for i in range(n):
  s=list(map(int,input().split()))
  s.pop(0)
  x+=s
for j in range(1,m+1):
  if x.count(j)==n:
    sum+=1
print(sum)
# Judge status: Wrong Answer
a, b = map(int, input().split())

if a > 10 or b >10:
  print(-1)
else:
  print(a*b)
# Judge status: Accepted
a1, a2, a3 = map(int,input().split())

if a1+a2+a3 > 21:
    print("bust")
else:
    print("win")
# Judge status: Wrong Answer
s = input()

former = int(s[:2])
later = int(s[2:])

if former==0 or later==0 or (former>31 and later>31):
  print("NA")
elif former<13 and later<13:
  print("AMBIGUOUS")
elif former<13 and later<32:
  print("MMYY")
elif former<32 and later<13:
  print("YYMM")
# Judge status: Accepted
x = int(input())
cnt = 0
total = 0

while x > total:
    cnt += 1
    total = int((1 + cnt) * (cnt/2))
    
print(cnt)
# Judge status: Accepted
N, K = map(int, input().split())
A = [int(i) for i in input().split()]

ans = A
for k in range(K):
    temp = [0 for _ in range(N)]
    for i in range(N):
        a = ans[i]
        temp[max(i-a, 0)] += 1
        if i + a + 1 < N:
            temp[i+a+1] -= 1

    ans[0] = temp[0]
    for j in range(1, N):
        ans[j] = ans[j-1] + temp[j]

    if ans.count(N) == N:
        break

for i in range(N):
    print(ans[i], end=" ")
# Judge status: Accepted
lst=list(str(input()))
a=set()
for i in range(len(lst)):
  a.add(lst[i])
if len(lst)==len(a):
  print("yes")
else:
  print("no")
# Judge status: Wrong Answer
# -*- coding : utf-8 -*-

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

if a+b == c or a+c == b or b+c == a:
  print("YES")
else :
  print("NO")
# Judge status: Accepted
import sys

n, *lst = map(int, sys.stdin.read().split())
alst = [lst[0]]
lst += [lst[-1]]
for i in range(n - 1):
  tmp = min(lst[i], lst[i + 1])
  alst += [tmp]
print(sum(alst))
# Judge status: Accepted
K, N = list(map(int, input().split()))
A = list(map(int, input().split()))
distance = [abs(A[i] - A[i-1]) for i in range(N)]
distance[0] = abs(distance[0]-K)
print(sum(distance) - max(distance))
# Judge status: Wrong Answer
x = list(map(int, input().split()))
x.sort() 
for i in range(len(x)): 
    print(x[i], end = ' ')
# Judge status: Accepted

N, K = map(int, input().split())
S = list(input()+"X")

temp = S[0]
cnt = 1
c_cnt = 1
ans = 0

for i in range(1, N+1):
  if temp == S[i]:
    cnt += 1
  else:
    ans += cnt - 1
    cnt = 1
    c_cnt += 1
    temp = S[i]
  #print(ans, cnt, c_cnt, temp)

#最後の余計な分
c_cnt -= 1

if c_cnt//2 <= K:
  if c_cnt%2 == 0:
    ans += (c_cnt//2) * 2 - 1
  else:
    ans += (c_cnt//2) * 2
else:
  ans += K * 2

print(ans)
# Judge status: Wrong Answer
N, M, K = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
B = [int(_) for _ in input().split()]

v = 0
ans = 0
for i in range(N):
    if v + A[i] <= K:
        v += A[i]
    else:
        mi = i-1
        break
else:
    mi = N-1

for j in range(M):
    while mi > -1 and v + B[j] > K:
        v -= A[mi]
        mi -= 1
    v += B[j]
    if v <= K:
        ans = max(ans, mi+1+ j+1)
        
print(ans)
# Judge status: Accepted
n = int(input())
flag = 0
while n>0:
    if n % 4 == 0:
        flag = 1
        break
    n -= 7
    if n == 0:
        flag=1
        break
print('Yes' if flag == 1 else 'No')
# Judge status: Accepted
from collections import Counter
mod = 998244353
num_nodes = int(input())
d_ls = list(map(int, input().split()))
d_max = max(d_ls)
c = Counter(d_ls)

if c[0] == 1 and d_ls[0] == 0 and c[1] > 0:
    ans = 1
else:
    ans = 0

for i in range(1,d_max):
    ans *= c[i] ** c[i+1]
    ans %= mod
print(ans)
# Judge status: Accepted
H, n = map(int, input().split())
A = []
B = []
for i in range(n):
	a, b = map(int, input().split())
	A.append(a)
	B.append(b)

dp = [0 for i in range(H+1)]

for i in range(1, H+1):
	dp[i] = min(dp[i - A[j]] + B[j]  if A[j] <= i  else  B[j]  for j in range(n))

print(dp[H])
# Judge status: Accepted
import heapq
n = int(input())
robots = []
for _ in range(n):
    robot = tuple(map(int, input().split()))
    heapq.heappush(robots, robot)

robot = heapq.heappop(robots)
max_right = robot[0] + robot[1]
del_count = 0
for i in range(len(robots)):
    robot = heapq.heappop(robots)
    if max_right > robot[0] - robot[1]:
        del_count += 1
        max_right = min(max_right, robot[0] + robot[1])
    else:
        max_right = robot[0] + robot[1]
print(n-del_count)
# Judge status: Accepted
N=int(input())
A=list(map(int,input().split()))
mod=10**9+7

def gcd(a, b):
    if a == 0:
        return b
    else:
        g = gcd(b % a, a)
        return g

lcm=1

for a in A:
    lcm=lcm*a//gcd(a,lcm)

ans=0

for a in A:
    ans+=(lcm*pow(a,mod-2,mod))%mod
    ans%=mod

print(ans)
# Judge status: Wrong Answer
n,a,b=map(int,input().split())
ans=0
if a>b or n==1:
  ans=0
elif a==b:
  ans=1
else:
  ans=(n-2)*(b-a)+1
print(ans)
# Judge status: Wrong Answer
n = int(input())
P = list(map(int,input().split()))
P = [int(i+1==P[i]) for i in range(n)]+[0]
print(P)

ans = 0
ex = 0
for p in P:
  if p and ex:
    ans += 1
    ex = 0
  elif p:
    ex = 1
  elif ex:
    ans += 1
    ex = 0
print(ans)
# Judge status: Wrong Answer
S = input()
for i in range(1, len(S)):
  s = S[:-i]
  l = len(s) // 2
  if s[:l] == s[l:]:
    print(len(s))
# Judge status: Accepted
a,b=input().split()
a=int(a)
b=int(b)
if a<=b:
  print(a)
else:
  print(a-1)
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))

ans = 0
num = 1
for i in range(n):
    if a[i] != num:
        ans += 1
    else:
        num += 1
if num == 1:
    print(-1)
else:
    print(ans)
# Judge status: Accepted
from math import ceil
a, b = map(int, input().split())
print(ceil((b - 1) / (a - 1)))
# Judge status: Accepted
N = int(input())
result = [input() for i in range(N)]
def f(s, result):
    return '%s x %d'%(s, result.count(s))
print(f('AC', result))
print(f('WA', result))
print(f('TLE', result))
print(f('RE', result))
# Judge status: Accepted
N, x = map(int, input().split())
a = list(map(int, input().split()))

result = 0
b = max(a[0] - x, 0)
result += b
a[0] -= b
for i in range(1, N):
    b = max(a[i - 1] + a[i] - x, 0)
    result += b
    a[i] -= b
print(result)
# Judge status: Wrong Answer
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
B.append(0)
B.append(0)

ans = 0
for i in range(N+1):
  if A[i] <= B[i]:
    ans += A[i]
    B[i+1] += B[i]-A[i]
    B[i] -= A[i]
  else:
    ans += B[i]
    B[i] -= B[i]
print(ans)
# Judge status: Wrong Answer
n, m = map(int, input().split())
a = list(map(int, input().split()))

num1 = a[0]
num2 = 0
while num1 % 2 == 0:
    num1 //= 2
    num2 += 1
gc = 2 ** num2

b = []
for i in a:
    if i % gc != 0 or (i // gc) % 2 == 0:
        print(0)
        exit()
    else:
        b.append(i // gc)

from fractions import gcd
lcm = 1
for i in b:
    lcm = (lcm * i) // gcd(lcm, i)

ans = m // lcm
ans = (ans + 1) // 2
print(ans)
# Judge status: Accepted
N = int(input())
A = tuple(map(int, input().split()))

xor = 0
for a in A:
    xor ^= a

for a in A:
    print(xor^a, '',end='')
print()
# Judge status: Wrong Answer
a,b = map(int,input().split())
s = input()
print("Yes" if s[:a].isdigit() and s[a:].isdigit() else "No")
# Judge status: Accepted
from collections import Counter

N = int(input())
S = input()
L = Counter(S)
MOD = 10**9 + 7

ans = 1
for k in L.keys():
    ans *= ((L[k]+1) % MOD)

print((ans-1)%MOD)
# Judge status: Wrong Answer
a, b = map(int, input().split())
if b >= a:
    if (b - a) % (a - 1) == 0:
        print((b - a) // (a - 1) + 1)
    else:
        print((b - a) // (a - 1) + 1 + 1)
else:
    print(1)
# Judge status: Wrong Answer
X = int(input())
money = 100
year = 0
while X > money :
    money = 1.01*money
    year += 1
print(year)
# Judge status: Accepted
import sys
input = sys.stdin.readline

(n, m, x), cost = map(int, input().split()), sys.maxsize
s = [list(map(int, input().split())) for i in range(n)]
for i in range(1, 1 << n):
    k, y = [0 for i in range(m)], 0
    for j in range(n):
        if (i >> j) & 1:
            for ii in range(1, m + 1): k[ii-1] += s[j][ii]
            y += s[j][0]
    if all([k[j] >= x for j in range(m)]): cost = min(cost, y)
print(-1 if cost == sys.maxsize else cost)
# Judge status: Accepted
#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()
    
    k=K%2
    t=(A-B)
    if abs(t)>10**18:print("Unfair");return
    if k%2:t=(-1)*t
    print(t)
    #print(A,B,C)


#%%submit!
resolve()
# Judge status: Accepted
N,M=map(int,input().split())
ab=[]
for i in range(N):
    ab.append(list(map(int,input().split())))
cd=[]
for i in range(M):
    cd.append(list(map(int,input().split())))
def Mandis(x1,x2,y1,y2):
    e=abs(x1-x2)+abs(y1-y2)
    return e
for i in range(N):
    g=0
    for j in range(M-1):
        if Mandis(ab[i][0],cd[j+1][0],ab[i][1],cd[j+1][1])<Mandis(ab[i][0],cd[g][0],ab[i][1],cd[g][1]):
            g=j+1
    print(g+1)
# Judge status: Accepted
A,B=map(int,input().split())
for money in range(1,1001):
    if int(money*0.08)==A and int(money*0.1)==B:
        print(money)
        break
else:
    print(-1)