Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

def main():
    from itertools import accumulate
    import numpy as np

    n, k = map(int, input().split())
    A = np.array(list(map(int, input().split())))
    A = np.append(A, 0)
    for _ in range(k):
        l = [0] * (n + 1)
        for i, a in enumerate(A[:-1]):
            l[max(0, i - a)] += 1
            l[min(n, i + a + 1)] -= 1
        A = np.array(list(accumulate(l)))
    print(*A[:-1])

if __name__ == "__main__":
    main()

### FIXED CODE ###

import numpy as np
from numba import jit


@jit("i8, i8, i8[:]")
def myfunc(n, k, A):
    for _ in range(k):
        l = np.zeros((n + 1,), dtype=np.int64)
        for i, a in enumerate(A[:-1]):
            l[max(0, i - a)] += 1
            l[min(n, i + a + 1)] -= 1
        A = np.cumsum(l)
        if np.all(A[:-1] == n):
            break
    return A


def main():
    n, k = map(int, input().split())
    A = np.array(list(map(int, input().split())), dtype=np.int64)
    A = np.append(A, 0)
    print(*myfunc(n, k, A)[:-1])


if __name__ == "__main__":
    main()
### BUGGY CODE ###

n = int(input())
l = []
for i in range(n):
    l.append(int(input()))

max_a = max(l)

for j in range(len(l)):
    if max_a == l[j]:
        tmp = l.pop(j)
        print(max(l))
        l.insert(j, tmp)
    else:
        print(max_a)


### FIXED CODE ###

n = int(input())
l = []
for i in range(n):
    l.append(int(input()))

l_b = sorted(l)
max_a = l_b[-1]
max_b = l_b[-2]

for j in range(len(l)):
    if max_a == l[j]:
        print(max_b)
    else:
        print(max_a)
### BUGGY CODE ###

import numpy as np 

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

A = np.array(A,np.int64)##Ai<2^60

ans = 0
mod = int(1e9+7)

for i in range(60+1):
    bottom_bit = (A>>i)&1 ##i回シフトしたときの最下位bit
    ones = sum(bottom_bit[bottom_bit>0])
    ##ans += (N-ones)*ones*(2**i) ##0の個数*1の個数*2^i個
    tmp = ones*(N-ones)
    for j in range(i):
        tmp = (tmp * 2) % mod
    ans += tmp

print(ans%mod)

### FIXED CODE ###

import numpy as np 

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

A = np.array(A,np.int64)##Ai<2^60

ans = 0
mod = int(1e9+7)

for i in range(60+1):
    bottom_bit = (A>>i)&1 ##i回シフトしたときの最下位bit
    ones = np.sum(bottom_bit[bottom_bit>0])
    ##ans += (N-ones)*ones*(2**i) ##0の個数*1の個数*2^i個
    tmp = ones*(N-ones)
    for j in range(i):
        tmp = (tmp * 2) % mod
    ans += tmp

print(ans%mod)
### BUGGY CODE ###

import sys
n=int(input())
As = list(map(int, input().split()))
ans=1
for val in As:
    ans=val*ans

if 10**18<ans:
    print(-1)
else:
    print(ans)

### FIXED CODE ###

import sys
n=int(input())
As = list(map(int, input().split()))
ans=1
for val in As:
    if val==0:
        ans=0
        break
for val in As:
    if ans==0:
        break
    if val==0:
        ans=0
        break
    ans=val*ans
    if 10**18<ans:
        ans=-1
        break

print(ans)
### BUGGY CODE ###

K, S = [int(i) for i in input().split()]


cnt = 0

if S <= K:
    for x in range(S+1):
        for y in range(S+1):
            for z in range(S+1):
                if x + y + z == S:
                    cnt += 1
else :
    for x in range(K+1):
        for y in range(K+1):
            for z in range(K+1):
                if x + y + z == S:
                    cnt += 1

print(cnt)

### FIXED CODE ###

K, S = [int(i) for i in input().split()]


cnt = 0

for x in range(K+1):
    for y in range(K+1):
        z = S - (x + y) 
        if z >= 0 and z <= K:
            cnt += 1

print(cnt)
### BUGGY CODE ###

N = int(input())
set_list = []
count = 0

for i in range(N):
    S = input()
    if not S in set_list:
        set_list.append(S)
        count += 1

print(count)

### FIXED CODE ###

N = int(input())
set_list = set()

for i in range(N):
    S = input()
    set_list.add(S)

print(len(set_list))
### BUGGY CODE ###

import sys
readline = sys.stdin.readline

N, S = map(int, readline().split())
A = list(int(x) for x in readline().split())
MOD = 998244353

dp = [[0] * (S+1) for _ in range(N+1)]
dp[0][0] = 1

for i in range(N):
    for j in range(S+1):
        # 1,2のケース。jが変わらない遷移が2通りある。
        dp[i+1][j] = (dp[i+1][j] + dp[i][j] * 2) % MOD
        # 3のケース。j+A[i] <= Sならば、j+A[i]に遷移する。
        if j + A[i] <= S:
            dp[i+1][j+A[i]] = (dp[i+1][j+A[i]] + dp[i][j]) % MOD
print(dp[N][S])

### FIXED CODE ###

import sys
readline = sys.stdin.readline

N, S = map(int, readline().split())
A = list(int(x) for x in readline().split())
MOD = 998244353

dp = [[0] * (S+1) for _ in range(N+1)]
dp[0][0] = 1

for i in range(N):
    for j in range(S+1):
        # 1,2のケース。jが変わらない遷移が2通りある。
        dp[i+1][j] = (dp[i+1][j] + dp[i][j] * 2) % MOD
        # 3のケース。j+A[i] <= Sならば、j+A[i]に遷移する。
        if j + A[i] <= S:
            dp[i+1][j+A[i]] = (dp[i+1][j+A[i]] + dp[i][j]) % MOD
print(dp[N][S])
### BUGGY CODE ###

N, W = list(map(int, input().split()))
WE = []
V = []
for i in range(N):
    w, v = list(map(int, input().split()))
    WE.append(w)
    V.append(v)

# DP[i][j]: i以降の品物で重さj以下のときの価値の最大
DP = []
for i in range(N):
    a = [None] * ((10 ** 5)+1)
    DP.append(a)
# DP.append([0] * ((10 ** 5)+1))

# i以降の荷物を使い、重さj以下で価値を最大にする
def search(i, j):
    if i == N:
        return 0

    if DP[i][j] is not None:
        return DP[i][j]

    if j < WE[i]:
        r = search(i+1, j)
        DP[i][j] = r
        return r

    r = max(search(i+1, j), search(i+1, j-WE[i])+V[i])
    DP[i][j] = r
    return r

search(0, W)

# for i in range(N):
#     print(DP[i][:10])

print(DP[0][W])


### FIXED CODE ###

N, W = list(map(int, input().split()))
WE = []
V = []
for i in range(N):
    w, v = list(map(int, input().split()))
    WE.append(w)
    V.append(v)

MAX_W = 10 ** 5

# DP[i][j]: i以降の品物で重さj以下のときの価値の最大
DP = []
for i in range(N):
    a = [None] * (MAX_W + 1)
    DP.append(a)
DP.append([0] * (MAX_W+1))

for i in range(N-1, -1, -1):
    for j in range(MAX_W+1):
        if i == N:  # i番目の品物はない
            DP[i][j] == 0
        elif j < WE[i]:  # この重さの品物は入れないから無視
            DP[i][j] = DP[i+1][j]
        else:
            DP[i][j] = max(DP[i+1][j], DP[i+1][j-WE[i]]+V[i])

# for i in range(N):
#     print(DP[i][:10])
print(DP[0][W])
### BUGGY CODE ###

N, C = map(int, input().split())
program = []
program_list = [0 for _ in range((((10 ** 5) * 2) + 10))]
for _ in range(C + 1):
    program.append(program_list.copy())
sm = program_list.copy()

s_list = []
t_list = []
c_list = []
for _ in range(N):
    s, t, c = map(int, input().split())
    s_list.append(s)
    t_list.append(t)
    c_list.append(c)

for i in range(1, C + 1):
    for j in range(len(s_list)):
        if i == c_list[j]:
            program[i][(s_list[j] * 2) - 1] += 1
            program[i][(t_list[j] * 2)] -= 1
    for j in range(1, len(program_list)):
        program[i][j] += program[i][j - 1]
    for j in range(0, len(program_list)):
        if program[i][j] > 0:
            sm[j] += 1
print(max(sm))


### FIXED CODE ###

N, C = map(int, input().split())
program = []
program_list = [False for _ in range((((10 ** 5) * 2) + 10))]
for _ in range(C + 1):
    program.append(program_list.copy())

for _ in range(N):
    s, t, c = map(int, input().split())
    s2 = (t * 2) - ((s * 2) - 1)
    program[c][(s * 2) - 1:t * 2] = [True] * s2

max_c = 0
for i in range(len(program_list)):
    c = 0
    for j in range(1, C + 1):
        if program[j][i]:
            c += 1
        if c > max_c:
            max_c = c
print(max_c)
### BUGGY CODE ###

import collections
import math

# 組み合わせ算出
def combinations_count(n, r):
    if n == 1:
        return 0
    if n == 0:
        return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

if __name__ == '__main__':
    N= int(input())
    a = list(map(int, input().split()))
    c = collections.Counter(a)
    results = {}
    for i in set(a):
        total = 0
        for j in c:
            if i == j:
                total = total + combinations_count(c[j]-1, 2)
            else:
                total += combinations_count(c[j], 2)
        results[i] = total

    for i in a:
        print(results[i])

### FIXED CODE ###

import collections
import math


if __name__ == '__main__':
    N= int(input())
    a = list(map(int, input().split()))
    c = collections.Counter(a)
    result = 0
    for i in set(a):
        # c[i]の中から2個選ぶ
        result += (c[i]*(c[i]-1))/2

    for i in a:
        d = c[i]
        print(int(result - (d*(d-1))/2 + ((d-1)*(d-2))/2))
### BUGGY CODE ###

import re
s=input()
c=0
while "ABC" in s:
    t=re.subn("ABC","BCA",s)
    s=t[0]
    c+=t[1]
print(c)


### FIXED CODE ###

s=input()
i=1
new=[s[0]]
while i<len(s):
    if s[i]=="C" and s[i-1] == "B":
        new.pop()
        new.append("K")
    else:
        new.append(s[i])
    i+=1

cnt=0
ans=0
for i in range(len(new)-1,-1,-1):
    if new[i]=="A" and cnt > 0:
        ans+=cnt
    elif new[i]=="K":
        cnt+=1
    else:
        cnt=0
    
print(ans)
### BUGGY CODE ###

S = list(map(int, list(input())))
before = len(S)

if 0 not in S:
    print(0)
elif 1 not in S:
    print(0)

else:
    while True:
        if 0 not in S:
            after = len(S)
            break
        elif 1 not in S:
            after = len(S)
            break
        
        for i in range(before - 2):
            if S[i] == 1 and S[i + 1] == 0:
                S.pop(i)
                S.pop(i)
                break
            elif S[i] == 0 and S[i + 1] == 1:
                S.pop(i)
                S.pop(i)
                break
    print(before - after)

### FIXED CODE ###

S = list(map(int, list(input())))

if 0 not in S:
    print(0)

elif 1 not in S:
    print(0)

else:
    zeros = S.count(0)
    ones = S.count(1)
    if zeros > ones:
        print(ones * 2)
    else:
        print(zeros * 2)
### BUGGY CODE ###

n = int(input())
dic = {}
for i in input().split():
    if i not in dic:
        dic[i] = 0
    dic[i] += 1
q = int(input())
for j in range(q):
    b,c = (str(x) for x in input().split())
    if b not in dic:
        pass
    else:
        if c not in dic:
            dic[c] = dic[b]
            dic[b] = 0
        else:
            dic[c] += dic[b]
            dic[b] = 0
    ans = 0
    for k in dic:
        ans += int(k)*dic[k]
    print(ans)


### FIXED CODE ###

n = int(input())
dic = {}
list = [int(i) for i in input().split()]
for i in list:
    if i not in dic:
        dic[i] = 0
    dic[i] += 1
q = int(input())
ans = sum(list)
for j in range(q):
    b,c = (int(x) for x in input().split())
    if b not in dic:
        print(ans)
        continue
    else:
        if c not in dic:
            dic[c] = dic[b]
        else:
            dic[c] += dic[b]
    ans = ans + (c-b)*dic[b]
    dic[b] = 0
    print(ans)
### BUGGY CODE ###

k = int(input())
x = 7%k
l = []
i = 1
while(True):
    if x in l:
        print('-1')
        break
    if x==0:
        print(i)
        break    
        
    l.append(x)
    x = (x*10+7)%k
    i += 1

### FIXED CODE ###

k = int(input())
x = 7%k
i = 1
for i in range(1,k+1):
    if x==0:
        break    
    x = (x*10+7)%k
    i += 1
    
if x == 0:
    print(i)
else:
    print('-1')
### BUGGY CODE ###

from collections import defaultdict
S = int(input())

d = defaultdict(int)

for i in range(len(str(S))+1):
    t = S % (10**i)
    d[t % 2019] += 1

ans = 0
for v in d.values():
    ans += v*(v-1)//2
print(ans)


### FIXED CODE ###

import collections
S = input()[::-1]

d = 1
M = []
for s in S:
    M.append(int(s)*d % 2019)
    d *= 10
    d %= 2019

S = [0]
for m in M:
    S.append((S[-1]+m) % 2019)

C = collections.Counter(S)

ans = 0
for v in C.values():
    ans += v*(v-1)//2
print(ans)
### BUGGY CODE ###

N, Q = map(int, input().split())
S = input()
lr_list = [list(map(int, input().split())) for q in range(Q)]
 
# 1文字目から n 文字目までの AC の数 = 1文字目から n - 1 文字目までの、Cを右に持つ A の数
 
where_ac = [0] * N
 
for i in range(N-1):
	#    print(i)
    if S[i] == 'A' and S[i+1] == 'C':
        where_ac[i+1] += 1
 
count = [sum(where_ac[0:i+1]) for i in range(N)]
 
for lr in lr_list:
    print(count[lr[1]-1] - count[lr[0]-1])

### FIXED CODE ###

N, Q = map(int, input().split())
S = input()

where_ac = [0] * N

for i in range(N-1):    
  if S[i] == 'A' and S[i+1] == 'C':
    where_ac[i+1] = where_ac[i] + 1
  else:
    where_ac[i+1] = where_ac[i]
        
for q in range(Q):
  l, r = map(int, input().split())
  print(where_ac[r-1] - where_ac[l-1])
### BUGGY CODE ###

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

ans = set(range(1,N+1))
for _ in range(M):
    a,b = map(int,input().split())
    filset = set(range(a,b+1))
    
    ans = ans & filset

print(len(ans))

### FIXED CODE ###

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

L = 0
R = N+1
for _ in range(M):
    l,r = map(int,input().split())
    
    L = max(l,L)
    R = min(r,R)

print(len(range(L,R+1)))
### BUGGY CODE ###

K = int(input())
S = input()
X = len(S)
mod = 10**9+7

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 2*10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

def power(n, r, mod):
    if r == 0: return 1
    if r%2 == 0:
        return power(n*n % mod, r//2, mod) % mod
    if r%2 == 1:
        return n * power(n, r-1, mod) % mod


A = 0
B = K
temp = cmb(A+X-1,X-1,mod)*power(25,A,mod)
temp %= mod
temp *= power(26,B,mod)
temp %= mod

ans = temp

for i in range(X+1,K+X+1):

    temp *= 25
    temp %= mod
    
    temp *= pow(26, mod-2, mod)
    temp %= mod
    
    temp *= i-1
    temp %= mod
    
    temp *= pow(i-X, mod-2, mod)
    temp %= mod    

    ans += temp
    ans %= mod

print(ans)

### FIXED CODE ###

K = int(input())
S = input()
X = len(S)
mod = 10**9+7

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 2*10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

def power(n, r, mod):
    if r == 0: return 1
    if r%2 == 0:
        return power(n*n % mod, r//2, mod) % mod
    if r%2 == 1:
        return n * power(n, r-1, mod) % mod


A = 0
B = K
temp = cmb(A+X-1,X-1,mod)*power(25,A,mod)
temp %= mod
temp *= power(26,B,mod)
temp %= mod

ans = temp

for i in range(X+1,K+X+1):

    temp *= 25
    temp %= mod
    
    temp *= pow(26, mod-2, mod)
    temp %= mod
    
    temp *= i-1
    temp %= mod
    
    temp *= pow(i-X, mod-2, mod)
    temp %= mod    

    ans += temp
    ans %= mod

print(ans)
### BUGGY CODE ###

N = int(input())
S = list(input() for _ in range(N))
D = list(set(S))
D.sort()
n = 0
for d in D:
  if n < S.count(d):
    n = S.count(d)
    li = []
    li.append(d)
  elif n == S.count(d):
    li.append(d)
for l in li:
  print(l)

### FIXED CODE ###

from collections import Counter as c
N = int(input())
S = list(input() for _ in range(N))
S.sort()
C, i = c(S).most_common(), 0
l, n = len(C), C[0][1]
while i < l:
  if n == C[i][1]: print(C[i][0])
  else: break
  i += 1
### BUGGY CODE ###

n = int(input())
h = list(map(int, input().split()))
c = 0
for i in range(n-1):
    if c >= n - i:
        break
    tmp = 0
    for j in range(i, n-1):
        if h[j] >= h[j+1]:
            tmp += 1
        else:
            break
    c = max(tmp, c)
print(c)


### FIXED CODE ###

n = int(input())
h = list(map(int, input().split()))
dp = [0] * n
for i in range(1, n):
    if h[i-1] >= h[i]:
        dp[i] = dp[i-1] + 1
print(max(dp))
### BUGGY CODE ###

N,W = map(int,input().split())
weight = [0]
value = [0]
for i in range(N):
    w,v = map(int,input().split())
    weight.append(w)
    value.append(v)
maxValue = N*1000
dp = [[float("inf") for i in range(maxValue+1)] for j in range(N+1)]
for i in range(N+1):
    dp[i][0] = 0

for i in range(1,N+1):
    for v in range(1,maxValue+1):
        dp[i][v] = dp[i-1][v]
        if value[i] > v: continue;
        dp[i][v] = min(dp[i][v],weight[i] + dp[i-1][v-value[i]])
ans = 0
for x in range(maxValue+1):
    if dp[N][x] <= W:
        ans = x
print(ans)

### FIXED CODE ###

N,W = map(int,input().split())
weight = [0]
value = [0]
for i in range(N):
    w,v = map(int,input().split())
    weight.append(w)
    value.append(v)
    
maxValue = sum(value)
INF = 10**10
dp = [[INF for i in range(maxValue+1)] for j in range(N+1)]
for i in range(N+1):
    dp[i][0] = 0
for i in range(1,N+1):
    for v in range(1,maxValue+1):
        if value[i] <= v:
            dp[i][v] = min(dp[i-1][v],weight[i] + dp[i-1][v-value[i]])
        else:
            dp[i][v] = dp[i-1][v]
ans = 0
for x in range(maxValue+1):
    if dp[N][x] <= W:
        ans = x
print(ans)
### BUGGY CODE ###

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

INF = float('inf')
dp = [INF] * n
dp[0] = 0
# dp[i] = (足場iにたどり着いた時点でのコストの最小値)

for i in range(n):
    for j in range(i + 1, min(i + k + 1, n)):
        if dp[j] > dp[i] + abs(h[j] - h[i]):
            dp[j] = dp[i] + abs(h[j] - h[i])

print(dp[n - 1])


### FIXED CODE ###

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

INF = float('inf')
dp = [INF] * n
dp[0] = 0
# dp[i] = (足場iにたどり着いた時点でのコストの最小値)

for i in range(n):
    for j in range(i + 1, min(i + k + 1, n)):
        dp[j] = min(dp[j], dp[i] + abs(h[j] - h[i]))

print(dp[n - 1])
### BUGGY CODE ###

n = int(input())
s = [input() for _ in range(n)]
count = 0
s_new = []
for word in s:
  word_new = sorted(word)
  count += s_new.count(word_new)
  s_new.append(word_new)
print(count)

### FIXED CODE ###

from collections import Counter
n = int(input())
s = [input() for _ in range(n)]
c = Counter()
count = 0
for word in s:
  a = ''.join(sorted(word))
  count += c[a]
  c[a] += 1
print(count)
### BUGGY CODE ###

N= int(input())
p=1
for i in range(N):
  p *= (i+1)
print(p%(10**9+7))

### FIXED CODE ###

import math
n = int(input())
print(math.factorial(n)%(10**9+7))
### BUGGY CODE ###

h, w, d = map(int, input().split())
num_dict = {}
for i in range(h):
    num_list = [int(i) for i in input().split()]
    for j, num in enumerate(num_list):
        num_dict[num] = (i + 1, j + 1)
q = int(input())
for _ in range(q):
    ans = 0
    l, r = map(int, input().split())
    for i in range(l, r + d, d):
        n_x, n_y = num_dict[i]
        if i > l:
            ans += abs(temp_x - n_x) + abs(temp_y - n_y)
        temp_x = n_x
        temp_y = n_y
    print(ans)

### FIXED CODE ###

h, w, d = map(int, input().split())
num_dict = [[] for _ in range(h * w)]
for i in range(h):
    num_list = [int(i) for i in input().split()]
    for j, num in enumerate(num_list):
        num_dict[num - 1] = (i + 1, j + 1)
accum_list = [0 for _ in range(h * w)]
for i in range((h * w) - d - 1, -1, -1):
    accum_list[i] += (abs(num_dict[i + d][0] - num_dict[i][0]) +
                      abs(num_dict[i + d][1] - num_dict[i][1]) + accum_list[i + d])
q = int(input())
for _ in range(q):
    l, r = map(int, input().split())
    print(accum_list[l - 1] - accum_list[r - 1])
### BUGGY CODE ###

n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]

ab.sort()

dp = [0]*(m+1)
for i in range(1, m+1):
  bmax = 0
  bidx = -1
  for idx, [a, b] in enumerate(ab):
    if a > i:
      break
    if b > bmax:
      bmax = b
      bidx = idx
  dp[i] = dp[i-1] + bmax
  if bidx != -1:
    ab.pop(bidx)
print(dp[-1])

### FIXED CODE ###

import heapq

dic = {}
n, m = map(int, input().split())
for _ in range(n):
  a, b = map(int, input().split())
  if dic.get(a) is not None:
    dic[a].append(-b)
  else:
    dic[a] = [-b,]

ans = 0
bite = []
for i in range(1, m+1):
  if dic.get(i) is not None:
    #bite = bite + dic[i]
    for val in dic[i]:
      heapq.heappush(bite, val)
  if len(bite) > 0:
    #heapq.heapify(bite)
    ans += heapq.heappop(bite)
print(ans*-1)
### BUGGY CODE ###

X, Y, A, B, C=map(int, input().split())
p=list(map(int, input().split()))
p.sort()
q=list(map(int, input().split()))
q.sort()
r=list(map(int, input().split()))
r.sort(reverse=True)

i=-X
j=-Y
k=0

while k<C and (r[k]>p[i] or r[k]>q[j]):
  if p[i]>q[j] and j<0:
    j+=1
    k+=1
  elif p[i]>q[j] and j>=0 and i<0:
    i+=1
    k+=1
  elif p[i]<q[j] and i<0:
    i+=1
    k+=1
  elif p[i]<q[j] and i>=0 and j<0:
    j+=1
    k+=1
    
if i==0:
  a=0
else:
  a=sum(p[i:])
  
if j==0:
  b=0
else:
  b=sum(q[j:])
  
if k==0:
  c=0
else:
  c=sum(r[:k])
  
print(a+b+c)

### FIXED CODE ###

X, Y, A, B, C=map(int, input().split())
p=list(map(int, input().split()))
p.sort()
q=list(map(int, input().split()))
q.sort()
r=list(map(int, input().split()))
r.sort(reverse=True)

i=-X
j=-Y
k=0
deru=0
while deru==0 and k<C and (r[k]>p[i] or r[k]>q[j]):
  if p[i]>q[j] and j<0:
    j+=1
    k+=1
  elif p[i]>q[j] and j>=0 and i<0 and p[i]<r[k]:
    i+=1
    k+=1
  elif p[i]<=q[j] and i<0:
    i+=1
    k+=1
  elif p[i]<=q[j] and i>=0 and j<0 and q[j]<r[k]:
    j+=1
    k+=1
  else:
    deru=1
    
if i==0:
  a=0
else:
  a=sum(p[i:])
  
if j==0:
  b=0
else:
  b=sum(q[j:])
  
if k==0:
  c=0
else:
  c=sum(r[:k])
  
print(a+b+c)
### BUGGY CODE ###

N = int(input())
A=list(map(int,input().split()))
#print(A)
B={}
for i in A:
    #print(i)
    if i in B:
        B[i]=B[i]+1
        #print(B)
    else:
        B[i]=1
        #print(B)

for i in A:
    tmp=0
    for k,v in B.items():
        if i==k:
            tmp+=int(0.5*(v-1)*(v-2))
            
        else:
            tmp+=int(0.5*(v)*(v-1))

    print(tmp)


### FIXED CODE ###

from collections import Counter
N = int(input())
A=list(map(int,input().split()))
B=Counter(A)
tmp=0
for i in B.values():
    tmp+=int(0.5*(i)*(i-1))
    #print(tmp)
for i in A:            
    print(tmp-B[i]+1)
### BUGGY CODE ###

import itertools
 
S = list(map(int, input().strip().split()))
N = S[0]
K = S[1]
p = list(map(int, input().strip().split()))
lists = [1000000000000]
for l in list(itertools.combinations(p, K)):
  sums = sum(list(l))
  if sums <= min(lists):
    lists.append(sums)

print(min(lists))


### FIXED CODE ###

S = list(map(int, input().strip().split()))
N = S[0]
K = S[1]
p = list(map(int, input().strip().split()))
lists = []
for l in range(K):
  lists.append(min(p))
  p.remove(min(p))
  
print(sum(lists))
### BUGGY CODE ###

N, K = map(int, input().split())
LR = set()
MOD = 998244353

for i in range(K):
    l, r = map(int, input().split())
    for j in range(l, r + 1):
        LR.add(j)
#print(list(LR))

# LR = [list(map(int,input().split())) for i in range(N)]
dp = [0] * (N + 1)
dp[0] = 1
for i in range(1, N):
    for d in LR:
        if i - d < 0: break
        dp[i] += (dp[i - d]) % MOD
print(dp[N-1] % MOD)


### FIXED CODE ###

N, K = map(int, input().split())
LR = [list(map(int, input().split())) for i in range(K)]
MOD = 998244353

dp = [0] * (N + 1)
dp[1] = 1
dp_sum = [0] * (N + 1)
dp_sum[1] = 1


def get(l, r, i):
    return dp_sum[max((i - l), 0)] - dp_sum[max((i - r-1), 0)]


for i in range(1, N+1):
    for l, r in LR:
        dp[i] += get(l, r, i) % MOD
    dp_sum[i] = (dp_sum[i - 1] + dp[i])%MOD
print(dp[N] % MOD)