Harryxun/stf_run huggingface dataset:
n, k = map(int, input().split())
r, s, p = map(int, input().split())
T=list(input())

commands = [""]*n
ans = 0

for i, t in enumerate(T):
    if t == "p":
        point = s
    elif t == "s":
        point = r
    elif t == "r":
        point = p

    if(i - k) >= 0 and (commands[i-k] == command):
        point = 0

    ans += point
print(ans)


### FIXED CODE ###

n, k = map(int, input().split())
r, s, p = map(int, input().split())
T=list(input())

commands = [""]*n
ans = 0

for i, t in enumerate(T):
    if t == "p":
        command = "s"
        point = s
    elif t == "s":
        command = "r"
        point = r
    elif t == "r":
        command = "p"
        point = p

    if(i - k) >= 0 and (commands[i-k] == command):
        command = ""
        point = 0

    ans += point
    commands[i] = command
print(ans)
import math


def main():
    n = int(input())

    A = [2] * (n + 1)
    
    ans = 1
    for i in range(2, n + 1):
        d = math.isqrt(i)
        A[i] = d + 1
        ans += i * (A[d] + 1)

    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    n = int(input())

    ans = 0
    for i in range(1, n + 1):
        d = n // i
        ans += (i + (i * d)) * d // 2

    print(ans)


if __name__ == '__main__':
    main()
import sys
n=int(input())
h=list(map(int,input().split()))
c=0
t=[]
if n==1:
    print('0')
    sys.exit
for i in range(n-1):
  if h[i]>=h[i+1]:
    c+=1
  else:
    t.append(c)
    c=0
  t.append(c)
print(max(t))


### FIXED CODE ###

n=int(input())
h=list(map(int,input().split()))
c=0
t=0

for i in range(n-1):
  if h[i]>=h[i+1]:
    c+=1
  else:
    t=max(t,c)
    c=0
  t=max(t,c)
print(t)
# -*- coding: utf-8 -*-

import sys
def input(): return sys.stdin.readline().strip()
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, Ma, Mb = map(int, input().split())
l = [[0] * 3 for i in range(N)]
for i in range(N):
    l[i][0], l[i][1], l[i][2] = map(int, input().split())

memo = [[[INF] * 11  for i in range(11)] for i in range(N+1)]
def dfs(cur, a, b, c):
    if memo[cur][a][b] != INF:
        return memo[cur][a][b]
    if cur == N:
        return INF
    mn = INF
    if b != 0 and a / b == Ma / Mb:
        mn = min(c, mn)
    mn = min(dfs(cur+1, a+l[cur][0], b+l[cur][1], c+l[cur][2]), mn)
    mn = min(dfs(cur+1, a, b, c), mn)
    memo[cur][a][b] = mn
    return mn

ans = dfs(0, 0, 0, 0)
if ans == INF:
    print(-1)
else:
    print(ans)


### FIXED CODE ###

# -*- coding: utf-8 -*-

"""
参考：https://img.atcoder.jp/abc054/editorial.pdf
・3次元DP
・送るDP
"""
 
import sys
def input(): return sys.stdin.readline().strip()
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7
 
N, Ma, Mb = map(int, input().split())
l = [[0] * 3 for i in range(N)]
for i in range(N):
    l[i][0], l[i][1], l[i][2] = map(int, input().split())

# 不可能な組み合わせは0とは区別するのでINF初期化
dp = [[[INF] * 401  for i in range(401)] for i in range(N+1)]
dp[0][0][0] = 0
for i in range(N):
    for j in range(401):
        for k in range(401):
            # あり得ない組み合わせの時は送らない
            if dp[i][j][k] == INF: continue
            dp[i+1][j][k] = min(dp[i][j][k], dp[i+1][j][k])
            dp[i+1][j+l[i][0]][k+l[i][1]] = min(dp[i][j][k] + l[i][2], dp[i+1][j+l[i][0]][k+l[i][1]])

ans = INF
for j in range(1, 401):
    for k in range(1, 401):
        # j/k == Ma/Mb だと分母0が心配なので
        if j * Mb == k * Ma:
            ans = min(dp[N][j][k], ans)

if ans == INF:
    print(-1)
else:
    print(ans)
import itertools

def f(a, b, c):
    return a+b > c


input()
l = tuple(map(int, input().split()))

a=0
for t in itertools.combinations(l, 3):
    if f(t):
        a += 1

print(a)


### FIXED CODE ###

import itertools

n, *l = map(int, open(0).read().split())

def f(a,b,c):
    return a+b>c and b+c>a and a+c>b


a=0
for t in itertools.combinations(range(n), 3):
    s=[l[i] for i in t]
    if len(s) != len(set(s)):
        continue
    if f(*s):
        a+=1

print(a)
n = int(input())
a = list(map(int,input().split()))
odd = 0
even4 = 0
for num in a:
  if num%2 == 1:
    odd += 1
  elif num%4 == 0:
    even4 += 1
if odd + even4 == n and even >= odd-1:
  print('Yes')
elif even4 >= odd1:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
odd = 0
even4 = 0
for num in a:
  if num%2 == 1:
    odd += 1
  elif num%4 == 0:
    even4 += 1
if odd + even4 == n and even4 >= odd-1:
  print('Yes')
elif even4 >= odd:
  print('Yes')
else:
  print('No')
S, T = input().split()
A, B = map(int, input().split())
U = input()
if S == U:
    A -= 1
elif T == U:
    B -= 1
print(f"{A} {B}")

### FIXED CODE ###

S, T = input().split()
A, B = map(int, input().split())
U = input()
if S == U:
    A -= 1
elif T == U:
    B -= 1
print("{} {}".format(A, B))
n = int(input())

print("ABC" + n)

### FIXED CODE ###

n = int(input())

print("ABC" + str(n))
N, K = map(int, input().split())
x = list(map(int, input().split()))
dis = []
for i in range(N - K + 1):
    dis.append(abs(x[i] - x[i + K - 1]) + abs(x[i]))
    dis.append(abs(x[i] - x[i + K - 1]) + abs(x[i + k - 1]))
print(min(dis))


### FIXED CODE ###

N, K = map(int, input().split())
x = list(map(int, input().split()))
dis = []
for i in range(N - K + 1):
    dis.append(abs(x[i] - x[i + K - 1]) + abs(x[i]))
    dis.append(abs(x[i] - x[i + K - 1]) + abs(x[i + K - 1]))
print(min(dis))
n, k = map(int, input().split( ))

a = list(map(int, input().split( )))

dp = [0]*(k+1)

for i in range(k+1):
    win = 0
    for j in a:
        if i>=j and dp[i-j] == 0:
            win = 1
            break
    dp[i] = win
#print(*dp)            
if dp[k] == 1:
    print("First")
else:
    print("Second")

### FIXED CODE ###

n, k = map(int, input().split( ))

a = list(map(int, input().split( )))

dp = [0]*(k+1)

for i in range(k+1):
    win = 0
    for j in a:
        if i>=j and dp[i-j] == 0:
            win = 1
            break
    dp[i] = win
#print(*dp)            
if dp[k] == 1:
    print("First")
else:
    print("Second")
# C - Linear Approximation
# https://beta.atcoder.jp/contests/abc102/tasks/arc100_a

# C_Linear_Approximation.py

# 7
# 1 1 1 1 2 3 4
#import sys

N = int(input())
a = list(map(int, input().strip().split(" ")))

for i in range(N):
    a[i] = a[i] - (i+1)

a.sort()
if N % 2 != 0:
    mid = (N-1)/2 +1
else:
    mid = N / 2
b = a[mid]

sadness_left = b * (mid-1) - sum(a[:mid])
sadness = sum(a) - b * N + sadness_left * 2

print(sadness)


### FIXED CODE ###

# C - Linear Approximation
# https://beta.atcoder.jp/contests/abc102/tasks/arc100_a

# C_Linear_Approximation.py

# 7
# 1 1 1 1 2 3 4
#import sys

N = int(input())
a = list(map(int, input().strip().split(" ")))

for i in range(N):
    a[i] = a[i] - (i+1)

a.sort()
if N % 2 != 0:
    mid = (N-1)//2
else:
    mid = N // 2 -1
b = a[mid]

sadness_left = b * mid - sum(a[:mid])
sadness = sum(a) - b * N + sadness_left * 2

print(sadness)
# -- coding: utf-8 --

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

count = []

for ii in range(1, 101):
    if a % ii == 0 and b % ii == 0:
        count.append(ii)

print(count[-k])


### FIXED CODE ###

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

mon_lim = int(b/a)
if mon_lim < c:
    print(mon_lim)
else:
    print(c)
na,nb,nm =  map(int, (input().split()))

# m 初期化
m = [[0] * 3 for i in range(nm)]
d = [[0] * nb for i in range(na)]
#print(d)

a = list(map(int, input().split()))
b = list(map(int, input().split()))
#  print (a,b)

#  m入力
for k in range(nm):
    i,j,disc = map(int, input().split())
    d[i][j]=disc

best = a[0] + b[0]

for i in range(na):
    for j in range(nb):
        price = a[i] + b[j] - d[i][j]
        if best > price:
            best = price

print(best)


### FIXED CODE ###

s = input()

flag = 0

while flag==0 and len(s)!=0 :
    if s.endswith('hi'):
        s = s[0:len(s)-2]
    else:
        flag = 1
#    print(s)
#    print(len(s))

if flag == 1:
    print('No')
else:
    print('Yes')
N,K = map(int, input().split())
A = list(map(int, input().split()))

move = 1
l = [1]
flag = [False]*(N+1)
flag[1] = True

for i in range(K):
    move = A[move-1]
    if flag[move]:
        ind = l.index(move)
        l = l[ind:]
        break
    flag[move] = True
    l.append(move)

rest = (K-ind) % (len(l))

print(l[rest])


### FIXED CODE ###

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

move = 1
l = [1]
flag = [False]*(N+1)
flag[1] = True

for i in range(K):
    move = A[move-1]
    if flag[move]:
        # ind = l.index(move)
        # l = l[ind:]
        break
    flag[move] = True
    l.append(move)

# print("ind:{}".format(ind))
# print("l:{}".format(l))
ind = l.index(move)
# l = l[ind:]
rest = (K-ind) % (len(l) - ind) + ind

# print(rest)
print(l[rest])
N = int(input())
Alist = sorted(list(map(int, input().split())))
Blist = sorted(list(map(int, input().split())))
Clist = sorted(list(map(int, input().split())))

def binary_search1(num_list, target):
    ans_counter = 0
    if target <= num_list[0]:
        return 0
    
    if num_list[-1] < target:
        return(len(num_list))
    
    for i in range(10000000):

        middle = num_list[len(num_list) // 2]
        left = num_list[:len(num_list) // 2]
        right = num_list[len(num_list) // 2:]

        if target >= left[-1] and right[0] > target:
            ans_counter += len(left)
            return ans_counter

        elif target < left[-1]:
            num_list = left
    
        elif right[0] <= target:
            ans_counter += len(left)
            num_list = right

def binary_search2(num_list, target):
    ans_counter = 0
    if target <= num_list[0]:
        return 0
    
    if num_list[-1] < target:
        return(len(num_list))
    
    for i in range(10000000):

        middle = num_list[len(num_list) // 2]
        left = num_list[:len(num_list) // 2]
        right = num_list[len(num_list) // 2:]

        if target > left[-1] and right[0] >= target:
            ans_counter += len(left)
            return ans_counter

        elif target <= left[-1]:
            num_list = left
    
        elif right[0] < target:
            ans_counter += len(left)
            num_list = right

ans = 0
#for C in Clist:
#    b_point = 0
#    b_point =  binary_search(Blist, C)

#    if b_point >= 0:
#        for B in Blist[:b_point]:
#            a_point =  binary_search(Alist, B)
#            print(B,C,a_point) 
#            ans += (a_point)

for B in Blist:
    a_point = binary_search2(Alist, B)
    c_point = binary_search1(Clist, B)
#    print(B,a_point, c_point, Clist.count(B))

    ans = ans + a_point * (N - c_point)

print(ans)
#for C in Clist:
    




### FIXED CODE ###

import bisect

N = int(input())
Alist = sorted(list(map(int, input().split())))
Blist = sorted(list(map(int, input().split())))
Clist = sorted(list(map(int, input().split())))

ans = 0

for B in Blist:
    Aindex = bisect.bisect_left(Alist, B)
    Cindex = bisect.bisect_right(Clist, B)

#    print(B, Aindex, N-Cindex)
    ans += Aindex * (N - Cindex)

print(ans)
import numpy as np
n, k = map(int, input().split())
a = list(map(int, input().split()))
current = a[:]
for _ in range(k):
    next = [1]*n
    stack = 0
    for j, v in enumerate(current):
        next[j] += stack % 10
        stack //= 10
        if v > 0:
            stack += int('1'*v)
    stack = 0
    for j in range(n-1, -1, -1):
        next[j] += stack % 10
        stack //= 10
        if current[j] > 0:
            stack += int('1' * current[j])
    current = next
print(*current)

### FIXED CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))
current = a[:]
for _ in range(min(42, k)):
    nex = [0]*n
    for i, v in enumerate(current):
        l = max(0, i-v)
        r = min(n-1, i+v)
        nex[l] += 1
        if r+1 < n:
            nex[r+1] -= 1
    for i in range(1, n):
        nex[i] += nex[i-1]
    current = nex

print(*current)
n=int(input())
d={}
for i in range(n):
    s=str(input())
    d.add(s)
print(len(d))

### FIXED CODE ###

n=int(input())
d=set()
for i in range(n):
    s=str(input())
    d.add(s)
print(len(d))
tmp = input().rstrip().split()
N = int(tmp[0])

list = [[] for x in range(100001)]
count = [0]*100000

for  i in range(N):
    work = input().rstrip().split()
    for i in range(int(work[0]),int(work[1])+1):
        if int(work[2]) not in list[i]:
            list[i].append(int(work[2]))
            count[i] += 1
            
print(max(count))


### FIXED CODE ###

N,C = map(int,input().split())
tvs = [list(map(int,input().split())) for _ in range(N)]
chans = [[] for _ in range(C+1)]
tvs.sort(key=lambda x:x[0])
targets = []
times = [0]*(pow(10,5)+2)

for tv in tvs:
  chans[tv[2]].append([tv[0],tv[1]])

for chan in chans:
  tmp = []
  if len(chan) == 1:
    targets.append(chan[0])
    continue
  for x in range(len(chan)):
    if len(tmp) == 0:
      tmp = chan[x]
      continue
    if chan[x][0] <= tmp[1] + 1:
      tmp[1] = chan[x][1]
      if x == len(chan)-1:
        targets.append(tmp)
    else:
      targets.append(tmp)
      tmp = chan[x]

for target in targets:
  times[target[0]] += 1
  times[target[1]+1] += -1

for j in range(1,pow(10,5)+2):
  times[j] += times[j-1]

print(max(times))
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

W = list(map(int,read().rstrip()))

N = len(W)

def Z_Algorithm(S):
    # 共通接頭辞の長さを返す
    N=len(S)
    arr = [0]*N
    arr[0] = N
    i,j = 1,0
    while i<N:
        while i+j<N and S[j]==S[i+j]:
            j += 1
        arr[i]=j
        if not j:
            i += 1
            continue
        k = 1
        while i+k<N and k+arr[k]<j:
            arr[i+k] = arr[k]
            k += 1
        i += k; j -= k
    return arr

def find_good_substr(W):
    Z = Z_Algorithm(W)
    is_good = [True]*N
    for n in range(1,N//2+1):
        # n文字での周期をもってくる
        if not is_good[n]:
            continue
        for i in range(n+n-1,Z[n]+n,n):
            is_good[i] = False
    return is_good

def solve():
    G1 = find_good_substr(W)
    G2 = find_good_substr(W[::-1])
    if G1[-1]:
        # 自分自身がoptimal
        return 1,1

x,y = solve()
print(x)
print(y)



### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

W = list(map(int,read().rstrip()))

N = len(W)

def Z_Algorithm(S):
    # 共通接頭辞の長さを返す
    N=len(S)
    arr = [0]*N
    arr[0] = N
    i,j = 1,0
    while i<N:
        while i+j<N and S[j]==S[i+j]:
            j += 1
        arr[i]=j
        if not j:
            i += 1
            continue
        k = 1
        while i+k<N and k+arr[k]<j:
            arr[i+k] = arr[k]
            k += 1
        i += k; j -= k
    return arr

def find_good_substr(W):
    Z = Z_Algorithm(W)
    is_good = [True]*(N+1) # 長さをインデックス
    for n in range(1,N//2+1):
        # n文字での周期をもってくる
        if not is_good[n]:
            continue
        for i in range(n+n,Z[n]+n+1,n):
            is_good[i] = False
    return is_good

def solve():
    G1 = find_good_substr(W)
    G2 = find_good_substr(W[::-1])[::-1]
    if G1[-1]:
        # 自分自身がoptimal
        return 1,1
    if len(set(W)) == 1:
        return N,1
    # 2個にできるはず
    x = sum(x and y for x,y in zip(G1[1:-1],G2[1:-1]))
    return 2,x

x,y = solve()
print(x)
print(y)
import math
n=int(input())

x,y=0,0
maxs=10**9
start = n%(10**8) if n>maxs else 1

for i in range(start, int(n**0.5)+1,2):
    if n % i == 0:
        if maxs>=i and maxs>=(n//i):
            x=i
            y=n//i
            break
print("0 0 0 "+str(x)+" "+str(y)+" 0")

### FIXED CODE ###

import math
n=int(input())
x1,y1=0,0
x2,y2=10**9,1
y3 = n//x2 +1
if y3>x2:
    y3=x2
x3 = y3*x2 - n


output=[x1,y1,x2,y2,x3,y3]
output=list(map(str,output))
    
print(" ".join(output))
n,m= list(map(int, input().split()))
ans_box=[0]*n
wa=[0]*m
ac=0
wa_cnt=0
for j in range(m):
    k,l=input().split()
    h=int(k)-1
    if ans_box[h]==0:
        if l=="AC":
            ac+=1
            ans_box[h]+=1
            wa_cnt+=wa[h]
        else:
            wa[h]+=1
print(ac,wa_cnt)   

### FIXED CODE ###

n,m= list(map(int, input().split()))
ans_box=[0]*n
wa=[0]*n
ac=0
wa_cnt=0
for j in range(m):
    k,l=input().split()
    h=int(k)-1
    if ans_box[h]==0:
        if l=="AC":
            ac+=1
            ans_box[h]+=1
            wa_cnt+=wa[h]
        else:
            wa[h]+=1
print(ac,wa_cnt)
H,W=map(int, input().split())
field=[[0]*(W+1) for i in range(H+1)]
List=[list(input()) for i in range(H)]

for k in range(1,H):
    for j in range(1,W):
        field[k][j] = List[k-1][j-1]

#print(field)

flag=1

for i in range(1,W):
    for j in range(1,H):
        if field[k][j]=='#' and field[k-1][j]!='#' and field[k+1][j]!='#' and field[k][j-1]!='#' and field[k][j+1]!='#':
            flag=0
            exit()

if flag==1:     
    print('Yes')
else:
    print('No')

### FIXED CODE ###

H,W=map(int,input().split())
S=["."+input()+"." for i in range(H)]
field=["."*(W+2)]+S+["."*(W+2)]

flag=0

for k in range(1,H+1):
    for j in range(1,W+1):
        if field[k][j]=='#' and field[k-1][j]!='#' and field[k+1][j]!='#' and field[k][j-1]!='#' and field[k][j+1]!='#':
            flag=1

if flag==1:
    print('No')
else:     
    print('Yes')
import sys
import numpy as np

I = np.array(sys.stdin.read().split(), dtype=np.int64)
n = I[0]
a = I[1:]

def main():
    i = np.argmax(np.absolute(a))

    if a[i] == 0:
        print(0)
        sys.exit()

    print(n * 2)
    res1 = np.concatenate((np.full(3, i+1)[:, None], np.arange(1, n+1)[:, None]), axis=1)
    if a[i] > 0:
        res2 = np.concatenate((np.arange(1, n)[:, None], np.arange(2, n+1)[:, None]), axis=1)
    else:
        res2 = np.concatenate((np.arange(n, 1)[:, None], np.arange(n-1, 0)[:, None]), axis=1)
    
    return np.concatenate((res1, res2))
    
if __name__ == '__main__':
    ans = main()
    for op in ans:
        print(*op, sep=' ')

### FIXED CODE ###

import sys

n, *a = map(int, sys.stdin.read().split())

def main():
    ma = 0
    idx = 0
    for i in range(n):
        cur = abs(a[i])
        if cur > ma:
            ma = cur
            idx = i

    if a[idx] == 0:
        print(0)
        sys.exit()

    procedures = []
    for i in range(n):
        a[i] += a[idx]
        procedures.append('{0} {1}'.format(idx+1, i+1))

    if a[idx] > 0:
        for i in range(n-1):
            if a[i] > a[i+1]:
                a[i+1] += a[i]
                procedures.append('{0} {1}'.format(i+1, i+2))
    else:
        for i in range(n-1, 0, -1):
            if a[i] < a[i-1]:
                a[i-1] += a[i]
                procedures.append('{0} {1}'.format(i+1, i))

    procedures = [len(procedures)] + procedures
    return procedures
    
if __name__ == '__main__':
    ans = main()
    print(*ans, sep='\n')
n,a,b=map(int(input()));print(min([n*a,b]))

### FIXED CODE ###

n,a,b=map(int,input().split());print(min([n*a,b]))
for i in range(N):
    if flag:
        break
    for j in range(N-i):
        if i*10000 + j*5000 + (N-i-j)*1000 == Y and (N-i-j) >= 0:
            A,B,C = i,j,(N-i-j)
            flag = True
            break
print(A,B,C)

### FIXED CODE ###

N,Y = map(int,input().split())
A,B,C = -1,-1,-1
flag = False
for i in range(N+1):
    if flag:
        break
    for j in range(N+1-i):
        if i*10000 + j*5000 + (N-i-j)*1000 == Y and (N-i-j) >= 0:
            A,B,C = i,j,(N-i-j)
            flag = True
            break
print(A,B,C)
A = input().split()
B = input().split()

Cor = 6-int(A)-int(B)
print(Cor)

### FIXED CODE ###

A = input()
B = input()

Cor = 6-(int(A)+int(B))
print(Cor)
N = int(input())
K = int(input())
print(N-K+1)

### FIXED CODE ###

N,K = map(int, input().split())
print(N-K+1)
a, b, c = map(int, input().split())

a = int(a)
b = int(b)
c = int(c)

x, y, z = sort(a, b, c)

print(x, y, x)



### FIXED CODE ###

a = list(map(int, input().split()))

a.sort()

print(a[0], a[1], a[2])
n = int(input())
s = input()
k = int(input())
c = s[k-1]
i = s.find(c)
s2 = "*"*n
for n in i:
	s2[n] = c
print(s2)


### FIXED CODE ###

n = int(input())
s = input()
k = int(input())
c = s[k-1]
s2 = ""
for m in range(n):
	if s[m] == c:
		s2 += c
	else:
		s2 += '*'
        
print(str(s2))
N=input()
s=[int(input()) for i in range(N)]
print(len(set(s)))

### FIXED CODE ###

N=int(input())
s=[int(input()) for i in range(N)]
print(len(set(s)))
N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))

def kaijou(x):
    result = 1
    for i in range(1, x+1):
        result *= i
    return result

def nokori(X, y):

    X = sorted(X)
    idx = 0
    for i in X:
        if i == y:
            return idx
        idx += 1
a = 1
tmp_P = P.copy()
for idx, i in enumerate(P):
    if idx < len(P):
        a = a + (nokori(tmp_P,i))*kaijou(N-idx-1)
        tmp_P.remove(i)
b = 1
tmp_Q = Q.copy()
for idx, i in enumerate(Q):
    if idx < len(Q):
        b += (nokori(tmp_Q,i))*kaijou(N-idx-1)
        tmp_Q.remove(i)
if a > b:
    print(a-b)
else:
    print(b-a)

### FIXED CODE ###

N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))

def kaijou(x):
    result = 1
    for i in range(1, x+1):
        result *= i
    return result

def nokori(X, y):

    X = sorted(X)
    idx = 0
    for i in X:
        if i == y:
            return idx
        idx += 1
a = 1
tmp_P = P.copy()
for idx, i in enumerate(P):
    if idx < len(P):
        a = a + (nokori(tmp_P,i))*kaijou(N-idx-1)
        tmp_P.remove(i)
b = 1
tmp_Q = Q.copy()
for idx, i in enumerate(Q):
    if idx < len(Q):
        b += (nokori(tmp_Q,i))*kaijou(N-idx-1)
        tmp_Q.remove(i)
if a > b:
    print(a-b)
else:
    print(b-a)
s=input()
S=list(s)
L=len(S)
A=[]
for i in range(L):
    if S[i]=='0' or S[i]=='1':
        A.append(S[i])
    elif S[i]=='B' and len(A)==0:
        A.append('')
    else:
        A.remove(A[-1])
a=''.join(A)
print(a)

### FIXED CODE ###

N=int(input())

print(int((N+1)*N/2))
INF = 1<<31
n = input()
l = [input() for i in xrange(n-1)]
dp = [[INF]*2 for i in xrange(n+1)]
dp[1][0] = 0
for i in xrange(1,n):
    for j in xrange(i+1,0,-1):
        dp[j][1] = min(dp[j][1], dp[j][0]+l[i-1])
        dp[j][0] = min(dp[j-1][0], dp[j-1][1]+l[i-1])
print min(dp[n/2])

### FIXED CODE ###

INF = 1<<31
n = input()
dp = [[[INF]*2 for _ in xrange(n/2+2)] for _ in range(2)]
dp[1][1][0] = dp[1][0][1] = 0
for i in range(2,n+1):
    x = i % 2
    s = input()
    t = min(i,n/2)
    for j in range(1,t+1):
        dp[x][j][0] = min(dp[1-x][j-1][0], dp[1-x][j-1][1] + s)
        dp[x][j][1] = min(dp[1-x][j][0] + s, dp[1-x][j][1])
print min(dp[0][n/2])
n = int(input())
s = input()

if s == "." * n:
    print(0)
else:
    black = s.index("#")
    white = [i for i, x in enumerate(s) if x == "."]
    wb = [i for i, x in enumerate(s[black:]) if x == "."]
    bw = [i for i, x in enumerate(s[:white[-1]]) if x == "#"]
    print(min(len(wb), len(bw)))

### FIXED CODE ###

n = int(input())
s = input()
sr = s[::-1]

ans = s.count(".")
num = ans
for i in range(n):
    if s[i] == ".":
        num -= 1
    else:
        num += 1
    ans = min(num, ans)
print(ans)
S=input()
Q=int(input())

for i in range(Q):
  a=input().split()
  if a[0]=="1":
    S=S[::-1]
  else:
    if a[1]=="1":
      S="".join((a[2],S))
    else:
      S="".join([(S,a[2]))
      
print(S)

### FIXED CODE ###

S=input()
Q=int(input())
import sys
from collections import deque
d=deque()
for _ in S:
  d.append(_)
flag=False

for _ in range(Q):
  s = list(sys.stdin.readline())
  if s[0]=="1":
    if flag:
      flag=False
    else:
      flag=True
  else:
    if s[2]=="1":
      if flag:
        d.append(s[4])
      else:
        d.appendleft(s[4])
    else:
      if flag:
        d.appendleft(s[4])
      else:
        d.append(s[4])
      
if flag:
  d.reverse()
  
print("".join(d))
S = input()
T = input()
count = 0
for i in [:len(S)]:
  if S[i] != T[i]:
    count += 1
print(count)


### FIXED CODE ###

S = input()
T = input()
count = 0
for i in range(len(S)):
  if S[i] != T[i]:
    count += 1
print(count)
wlist = []
for i in range(3) :
    w = input()
    if not w in wlist :
        wlist.append(w)
print(len(wlist))

### FIXED CODE ###

a, b, c = map(int, input().split())
count = 0
if a != b :
    count += 1
if a != c :
    count += 1
if b != c :
    count += 1
if a == b == c :
    count =1
print(count)