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

# -*- coding: utf-8 -*-
#!/usr/bin/env python3

import sys


def main():
    input = sys.stdin.readline
    n, q = [int(i) for i in input().split()]
    s = input().strip()
    qs = [[int(i) for i in input().split()] for _ in range(q)]
    for (l, r) in qs:
        print(s[l - 1 : r].count("AC"))


if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
from itertools import accumulate


def main():
    input = sys.stdin.readline
    n, q = [int(i) for i in input().split()]
    s = input().strip()
    qs = [[int(i) for i in input().split()] for _ in range(q)]
    hoges = [0] + [1 if s[i : i + 2] == "AC" else 0 for i in range(n - 1)]
    hoges = list(accumulate(hoges))
    for (l, r) in qs:
        print(hoges[r - 1] - hoges[l - 1])


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

n=int(input())
a=list(map(int,input().split()))
b=[]
if n%2==0:
    for i in range(n):
        if i%2==0:b.append(a[i])
        if i%2==1:b.insert(0,a[i])
if n%2==1:
    for i in range(n):
        if i%2==1:b.append(a[i])
        if i%2==0:b.insert(0,a[i])


print(*b)

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
if n%2==1:
    print(*(a[::-2]+a[1::2]))
if n%2==0:
    print(*(a[::-2]+a[0::2]))
### BUGGY CODE ###

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

A = list(map(lambda x: x%1000000007,A))

total = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        total += A[i]*A[j] % 1000000007
print(total % 1000000007)


### FIXED CODE ###

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

mod = 10 ** 9 + 7

sum_a=0
for i in A:
    sum_a+=i
    sum_a%=mod

total=0
for i in range(N - 1):
    sum_a -= A[i]
    total+=A[i]*(sum_a)
    total%=mod
print(total)
### BUGGY CODE ###

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

import numpy as np
K = np.array([[0] * N for _ in range(N)])
for i in range(N):
    K[i][i] = 1
    if i != N - 1:
        K[i][i + 1] = 1
    else:
        K[i][0] = 1
        
X = np.linalg.solve(K, A)
X = [str(int(2 * x)) for x in X]
ans = " ".join(X)
print(ans)

### FIXED CODE ###

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

S = sum(A)
A_even_sum = 0
for i in range(1, N - 1, 2):
    A_even_sum += A[i]
X = []
x_1 = (S - 2 * A_even_sum)
X.append(x_1)
for i in range(N - 1):
    x_next = int(2 * A[i] - X[i])
    X.append(x_next)
    X[i] = str(X[i])
X[N - 1] = str(X[N - 1])

ans = " ".join(X)
print(ans)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
cnt = 0

for i in range(n):
    for j in range(n):
        if i == j:
            continue
        if abs((i+1) - (j+1)) == (a[i] + a[j]):
            cnt += 1
print(cnt//2)

### FIXED CODE ###

from collections import Counter
n = int(input())
A = list(map(int, input().split()))
cnt = 0

B = Counter(i + a for i, a in enumerate(A))
C = Counter(j - a for j, a in enumerate(A))
#print(B)
#print(C)
for k, v in B.items():
    cnt += C[k] * v
print(cnt)
### BUGGY CODE ###

n, m = [int(c) for c in input().split()]
As = [int(c) for c in input().split()]
for i in range(m):
    b, c = [int(c) for c in input().split()]
    As += [c] * b
As.sort(reverse=True)
print(sum(As[:n]))

### FIXED CODE ###

n, m = [int(c) for c in input().split()]
A = {}
for a in input().split():
    a = int(a)
    A[a] = A.get(a, 0) + 1
# print(A)

for i in range(m):
    b, c = [int(c) for c in input().split()]
    A[c] = A.get(c, 0) + b
# print(A)

A = sorted([(k, v) for k, v in A.items()], reverse=True)
ans, num = 0, n
for k, v in A:
    # print(k, v, min(num, v))
    ans += k * min(num, v)
    num -= min(num, v)
    if num == 0:
        break
print(ans)
### BUGGY CODE ###

N, K = map(int, input().split())
S = []
for i in range(K):
    L, R = map(int, input().split())
    S += list(range(L, R+1))

dp = [0] * N
dp[0] = 1

#S.sort()

for i in range(1, N):
    for s in S:
        if i - s < 0:continue
        dp[i] += dp[i - s]

print(dp[-1] % 998244353)


### FIXED CODE ###

mod = 998244353
N, K = map(int, input().split())

S = []
for i in range(K):
    L, R = map(int, input().split())
    S.append((L, R))

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

for i in range(2, N+1):
    for s in S:
        l = i - s[1]
        r = i - s[0]
        if r < 1:continue
        l = max(1, l)

        dp[i] += dpsum[r] - dpsum[l-1]
        dp[i] %= mod

    dpsum[i] = (dpsum[i-1] + dp[i]) % mod

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

S = str(input())
Q = int(input())
for i in range(Q):
  q = str(input())
  if int(q[0]) == 1:#Ti = 1
    S = S[::-1]
  else:
    if int(q[2]) == 1:#先頭
      S = q[4] + S
    else:
      S = S + q[4]
      
print(S)

### FIXED CODE ###

S = str(input())
Q = int(input())
st = [0] * Q
n = [0] * Q
p = 0
s_h = 0
for i in range(Q):
  q = str(input())
  if int(q[0]) == 1:#Ti = 1
    s_h += 1
  else:
    if int(q[2]) == 1:#先頭
      st[p] = q[4]
      n[p] = s_h
      p += 1
    else:
      st[p] = q[4]
      n[p] = s_h + 1
      p += 1

odd = ["".join(st[a]) for a in range(Q) if ((n[a] + s_h) % 2 == 1) and (str(st[a]) != "0")]
odd = "".join(odd)
even =  ["".join(st[a]) for a in range(Q) if ((n[a] + s_h) % 2 == 0) and (str(st[a]) != "0")]
even = "".join(even)[::-1]
if s_h % 2 == 1:
  S = S[::-1]

b = [even, S, odd]
#print(S,odd,even)
print("".join(b))
### BUGGY CODE ###

import sys
sys.setrecursionlimit(250010)
N,M=map(int, input().split())
def func(n):
    if n==1:
        return 1
    return n*func(n-1)

if N==M:
    print((func(N)*func(M)*2)%(10**9+7))
elif N==M-1 or M==N-1:
    print((func(N)*func(M))%(10**9+7))
else:
    print(0)


### FIXED CODE ###

N,M=map(int, input().split())
mod=1000000000+7
fact=[1]*100001
for i in range(100000):
    fact[i+1]=fact[i]*(i+1)%mod

if N==M:
    print((fact[N]*fact[M]*2)%mod)
elif abs(N-M)==1:
    print((fact[N]*fact[M])%mod)
else:
    print(0)
### BUGGY CODE ###

n, m = map(int, input().split())
for i in range(m//n, 0, -1):
  if m%i == 0:
    print(i)
    break

### FIXED CODE ###

n, m = map(int, input().split())
for i in range(m//n, 0, -1):
  if m%i == 0:
    print(i)
    break
### BUGGY CODE ###

import numpy as np
from collections import deque

n = int(input())
a = [0] * n
for i in range(n):
    a[i] = int(input())

arr = np.array(a)
jun = np.argsort(arr)
jun = deque(jun)

ans = 0
while jun:
    ans += 1
    i = jun.pop()
    for j in range(i):
        if a[j] != a[i]:
            try:
                jun.remove(j)
            except:
                ValueError

print(ans)

### FIXED CODE ###

# 広義最長部分増加数列の長さを求めるdef
# 配列LIS自体は広義最長部分増加文字列ではない
import bisect
def lis(seq):
    LIS = [seq[0]]
    for i in range(1, len(seq)):
        if seq[i] >= LIS[-1]:
            LIS.append(seq[i])
        else:
            LIS[bisect.bisect_right(LIS, seq[i])] = seq[i]
    return(len(LIS))

n = int(input())
a = [0] * n
for i in range(n):
    a[i] = int(input())

b = a[::-1]
print(lis(b))
### BUGGY CODE ###

from collections import deque

def f1(x,y,xa,ya):
    if reach[xa][ya] == -1 or reach[xa][ya] > reach[x][y]:
         if c[xa][ya] == ".":
            reach[xa][ya] = reach[x][y]
            r.append([xa,ya])
            q.append([xa,ya])

def f2(x,y,xa,ya):
    if 0 <= xa <= h+1 and 0 <= ya <= w+1:
    
        if reach[xa][ya] == -1 or reach[xa][ya] > reach[x][y] + 1:
            if c[xa][ya] == ".":
                reach[xa][ya] = reach[x][y] + 1
                q.append([xa,ya])

h,w = map(int,input().split())
cx, cy = map(int,input().split())
dx, dy = map(int,input().split())

c = [0]*(h+2)
for i in range(1,h+1):
    c[i] = [0] + list(input()) + [0]
c[0]  = [0]*(w+2)
c[-1] = [0]*(w+2)

reach = [[-1 for j in range(w+2)] for i in range(h+2)]
q = deque([])

reach[cx][cy] = 0
q.append([cx,cy])

ans = 0

while q:

    
    
    x,y = q.popleft()
    
    r = deque()
    r.append([x,y])
    while r:
        xx,yy = r.popleft()
        
        f1(xx,yy,xx-1,yy)
        f1(xx,yy,xx+1,yy)
        f1(xx,yy,xx,yy-1)
        f1(xx,yy,xx,yy+1)
    
    for i in range(-2,3):
        for j in range(-2,3):
            f2(x,y,x+i,y+j)


print(reach[dx][dy])


### FIXED CODE ###

from collections import deque
import time


def f1(x,y,xa,ya):
    if reach[xa][ya] == -1 or reach[xa][ya] > reach[x][y]:
         if c[xa][ya] == ".":
            reach[xa][ya] = reach[x][y]
            r.append([xa,ya])
            q.append([xa,ya])

            
            
def f2(x,y,xa,ya):
    if 0 <= xa <= h and 0 <= ya <= w:
    
        if reach[xa][ya] == -1 or reach[xa][ya] > reach[x][y] + 1:
            if c[xa][ya] == ".":
                reach[xa][ya] = reach[x][y] + 1
                q.append([xa,ya])

h,w = map(int,input().split())
cx, cy = map(int,input().split())
dx, dy = map(int,input().split())

t0 = time.time()

c = ["#"]*(h+2)
for i in range(1,h+1):
    c[i] = ["#"] + list(input()) + ["#"]
c[0]  = [0]*(w+2)
c[-1] = [0]*(w+2)

reach = [[-1 for j in range(w+2)] for i in range(h+2)]
q = deque([])

reach[cx][cy] = 0
q.append([cx,cy])

ans = 0

while q:
    
    if time.time() - t0 >= 1.5:
        break
    
    
    x,y = q.popleft()
    
    r = deque()
    r.append([x,y])
    while r:
        xx,yy = r.popleft()
        
        f1(xx,yy,xx-1,yy)
        f1(xx,yy,xx+1,yy)
        f1(xx,yy,xx,yy-1)
        f1(xx,yy,xx,yy+1)
    
    for i in range(-2,3):
        for j in range(-2,3):
            f2(x,y,x+i,y+j)


print(reach[dx][dy])
### BUGGY CODE ###

def bubble_sort(l):
    N = len(l)
    isChange = True
    while isChange:
        isChange = False
        for i in range(N-1):
            if(l[i] > l[i+1]):
                l[i], l[i+1] = l[i+1], l[i]
                isChange = True
    return l

N = int(input())
l = map(int, input().split())
l = list(l)
L = bubble_sort(l)
sum = 0
for k in L:
    sum += k

print("{} {} {}".format(L[0], L[-1], sum))

### FIXED CODE ###

N = input()
l = map(int, input().split())
l = list(l)
print("{} {} {}".format(min(l), max(l), sum(l)))
### BUGGY CODE ###

import sys
input = sys.stdin.readline

H,W,M=map(int,input().split())
B=set([tuple(map(int,input().split())) for i in range(M)])

HH=[0]*(H+1)
WW=[0]*(W+1)

for x,y in B:
    HH[x]+=1
    WW[y]+=1

MAXH=max(HH)
MAXW=max(WW)

ANS=MAXH+MAXW-1

for i in range(1,H+1):
    if HH[i]!=MAXH:
        continue
    for j in range(1,W+1):
        if WW[j]!=MAXW:
            continue

        if (i,j) in B:
            continue
        else:
            print(ANS+1)
            sys.exit()
print(ANS)

        


### FIXED CODE ###

import sys
input = sys.stdin.readline

H,W,M=map(int,input().split())
B=set([tuple(map(int,input().split())) for i in range(M)])

HH=[0]*(H+1)
WW=[0]*(W+1)

for x,y in B:
    HH[x]+=1
    WW[y]+=1

MAXH=max(HH)
MAXW=max(WW)

ANS=MAXH+MAXW-1

HLIST=[]
WLIST=[]
for i in range(1,H+1):
    if HH[i]==MAXH:
        HLIST.append(i)

for j in range(1,W+1):
    if WW[j]==MAXW:
        WLIST.append(j)

for i in HLIST:
    for j in WLIST:
        if (i,j) in B:
            continue
        else:
            print(ANS+1)
            sys.exit()
print(ANS)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**7)

N = int(input())
S = [input() for i in range(N)]

es = [[] for i in range(N)]
for i,row in enumerate(S):
    for j,c in enumerate(row):
        if c=='1':
            es[i].append(j)
            es[j].append(i)

#n個の頂点の色を初期化。0:未着色、1:黒、-1:白
colors = [0 for i in range(N)]

#頂点vをcolor(1 or -1)で塗り、再帰的に矛盾がないか調べる。矛盾があればFalse
def dfs(v,color):
    #今いる点を着色
    colors[v] = color
    #今の頂点から行けるところをチェック
    for to in es[v]:
        #同じ色が隣接してしまったらFalse
        if colors[to] == color:
            return False
        #未着色の頂点があったら反転した色を指定し、再帰的に調べる
        if colors[to] == 0 and not dfs(to, -color):
            return False
    #調べ終わったら矛盾がないのでTrue
    return True

#2部グラフならTrue, そうでなければFalse
def is_bipartite():
    return dfs(0,1) # 頂点0を黒(1)で塗ってDFS開始

if not is_bipartite():
    print(-1)
    exit()

INF = float('inf')
dists = [[1 if c=='1' else INF for c in row] for row in S]
for i in range(N):
    dists[i][i] = 0

for k in range(N):
    for i in range(N):
        for j in range(N):
            dists[i][j] = min(dists[i][j], dists[i][k] + dists[k][j])

print(max(max(row) for row in dists) + 1)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)

N = int(input())
S = [input() for i in range(N)]

es = [[] for i in range(N)]
for i,row in enumerate(S):
    for j,c in enumerate(row):
        if c=='1':
            es[i].append(j)
            es[j].append(i)

#n個の頂点の色を初期化。0:未着色、1:黒、-1:白
colors = [0 for i in range(N)]

#頂点vをcolor(1 or -1)で塗り、再帰的に矛盾がないか調べる。矛盾があればFalse
def dfs(v,color):
    #今いる点を着色
    colors[v] = color
    #今の頂点から行けるところをチェック
    for to in es[v]:
        #同じ色が隣接してしまったらFalse
        if colors[to] == color:
            return False
        #未着色の頂点があったら反転した色を指定し、再帰的に調べる
        if colors[to] == 0 and not dfs(to, -color):
            return False
    #調べ終わったら矛盾がないのでTrue
    return True

#2部グラフならTrue, そうでなければFalse
def is_bipartite():
    return dfs(0,1) # 頂点0を黒(1)で塗ってDFS開始

if not is_bipartite():
    print(-1)
    exit()

INF = float('inf')
dists = [[1 if c=='1' else INF for c in row] for row in S]
for i in range(N):
    dists[i][i] = 0

for k in range(N):
    for i in range(N):
        for j in range(N):
            dists[i][j] = min(dists[i][j], dists[i][k] + dists[k][j])

print(max(max(row) for row in dists) + 1)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**8)
stdin = sys.stdin


def ni(): return int(ns())


def na(): return list(map(int, stdin.readline().split()))


def naa(N): return [na() for _ in range(N)]


def ns(): return stdin.readline().rstrip()  # ignore trailing spaces


class SegmentTreeSET(object):  # 1-indexed [l,r)
    def __init__(self, size):
        self.len = 1 << size.bit_length()
        # print(self.len)
        self.array = [ 0 for _ in range(2 * self.len)]

    def update(self, i, x):  # 0-indexed
        i += self.len
        while i > 0:
            self.array[i] = self.array[i] | x
            i >>= 1
        # print(self.array)

    def get(self, i):  # 0-indexed
        return self.array[i + self.len]

    def get_cnt(self, l, r):  # 0-indexed
        L = l+self.len
        R = r+self.len
        ANS = 0

        while L < R:
            if L & 1:
                ANS = (ANS | self.array[L])
                L += 1

            if R & 1:
                R -= 1
                ANS = (ANS | self.array[R])
            L >>= 1
            R >>= 1

        return bin(ANS).count("1")


N, Q = na()
c_array = na()

tree = SegmentTreeSET(N)
for i, c in enumerate(c_array):
    tree.update(i, 1 << c)

for _ in range(Q):
    l, r = na()
    print(tree.get_cnt(l-1, r))


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**8)
stdin = sys.stdin


def ni(): return int(ns())


def na(): return list(map(int, stdin.readline().split()))


def naa(N): return [na() for _ in range(N)]


def ns(): return stdin.readline().rstrip()  # ignore trailing spaces


class SegmentTreeSUM(object):  # 1-indexed [l,r)
    def __init__(self, size):
        self.len = 1 << (size-1).bit_length()
        # print(self.len)
        self.array = [0 for _ in range(2 * self.len)]

    def update(self, i, x):  # 0-indexed
        i += self.len
        while i > 0:
            self.array[i] = self.array[i] + x
            i >>= 1
        # print(self.array)

    def get(self, i):  # 0-indexed
        return self.array[i + self.len]

    def get_sum(self, l, r):  # 0-indexed
        L = l+self.len
        R = r+self.len
        ANS = 0

        while L < R:
            if L & 1:
                ANS = ANS + self.array[L]
                L += 1

            if R & 1:
                R -= 1
                ANS = ANS + self.array[R]
            L >>= 1
            R >>= 1

        return ANS


N, Q = na()
c_array = na()

tree = SegmentTreeSUM(N)


q_array = []
for i in range(Q):
    l, r = na()
    q_array.append([i, l-1, r])

q_array = sorted(q_array, key=lambda x: x[2])
ans = [0] * Q
last_idx = [-1] * (N+1)
q_idx = 0
for i, c in enumerate(c_array):
    tree.update(i, 1)
    if last_idx[c] != -1:
        tree.update(last_idx[c], -1)
    last_idx[c] = i
    while(q_idx < Q and q_array[q_idx][2] == (i+1)):
        idx, l, r = q_array[q_idx]
        ans[idx] = tree.get_sum(l, r)
        q_idx += 1


print("\n".join(map(str, ans)))
### BUGGY CODE ###

import sys
input=sys.stdin.readline

n = int(input())
l = list(map(int, input().split()))
L = list(set(l))
count = 0
for x in L:
  if l.count(x) == x:
    continue
  elif l.count(x) > x:
    count += l.count(x) - x
  else:
    count += l.count(x)
print(count)

### FIXED CODE ###

n = int(input())
l = list(map(int, input().split()))
dic = {}
count = 0

for i in range(n):
  dic.setdefault(l[i],0)
  dic[l[i]] += 1

for x,y in dic.items():
  if x <= y:
    count += y - x
  else:
    count += y
print(count)
### BUGGY CODE ###

def bubble_sort_cnt(a):
    cnt = 0
    for i in range(len(a) - 1):
        for j in range(i + 1, len(a)):
            if a[i] > a[j]:
                cnt += 1
    return cnt

n = int(input())
a = list(map(int, input().split()))
print(bubble_sort_cnt(a))

### FIXED CODE ###

SENTINEL = 10 ** 9 +1
cnt = 0
def merge(A, left, mid, right):
    global cnt

    L = A[left:mid] + [SENTINEL]
    R = A[mid:right] + [SENTINEL]
    
    i = j = 0
    for k in range(left, right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
            cnt += mid - left - i  # ☆

def merge_sort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(A, left, mid)
        merge_sort(A, mid, right)
        merge(A, left, mid, right)

n = input()
A = list(map(int, input().split()))
merge_sort(A,0,len(A))
print(cnt)
### BUGGY CODE ###

n = int(input())
s_li = []
for i in range(n):
    s = input()
    s_i = {}
    for j in range(10):
        s_i[s[j]] = 0
    for j in range(10):
        s_i[s[j]] += 1
    buf = ""
    for k, v in sorted(s_i.items()):
        buf += str(k) + str(v)
    s_li.append(buf)

ans = 0

for i in range(n):
    for j in reversed(range(n)):
        if i >= j :
            break
        if s_li[i] == s_li[j]:
            ans += 1
print(ans)


### FIXED CODE ###

n = int(input())
s_li = [input() for i in range(n)]

ans = 0
s_dict = {}
for i in s_li :
    s_i = [ch for ch in i]
    s_i.sort()
    s_i = "".join(s_i)
    if s_i in s_dict :
        ans += s_dict[s_i]
        s_dict[s_i] += 1
    else :
        s_dict[s_i] = 1
print(ans)
### BUGGY CODE ###

n,m = map(int,input().split())
g = [[] for i in range(n)]
for i in range(m):
  x,y = map(int,input().split())
  x-=1;y-=1
  g[x].append(y)
dp = [0] * n
while True:
  flag = 1
  for i in range(n):
    for j in g[i]:
      if dp[j] < dp[i]+1:
        dp[j] = dp[i]+1
        flag = 0
  if flag:
    break
print(max(dp))

### FIXED CODE ###

from collections import deque
n,m = map(int,input().split())
g = [[] for i in range(n)]
h = [[] for i in range(n)]
for i in range(m):
  x,y = map(int,input().split())
  x-=1;y-=1
  g[x].append(y)
  h[y].append(x)
topo = []
hukasa = [0] * n
hairu = [0]*n
que = deque([])
for i in range(n):
  hairu[i] = len(h[i])
  if hairu[i] == 0:
    topo.append(i)
    que.append(i)
def dfs(x):
  for i in g[x]:
    hairu[i]-=1
    if hairu[i] == 0:
      topo.append(i)
      que.append(i)
while que:
  x = que.popleft()
  dfs(x)
def dfs2(x):
  for i in g[x]:
    hukasa[i] = max(hukasa[i],hukasa[x]+1)
for i in topo:
  dfs2(i)
print(max(hukasa))
### BUGGY CODE ###

from itertools import accumulate
n,m = [int(a) for a in input().strip().split(' ')]
As = [0] + list(accumulate([int(a)%m for a in input().strip().split(' ')]))

def isok(i,j):
    di = As[j] - As[i-1]
    if di % m == 0:
        return True
    else:
        return False


counter = 0
for i in range(n):
    for j in range(i, n):
        if isok(i+1, j+1):
            counter += 1
print(counter)


### FIXED CODE ###

from itertools import accumulate
n,m = [int(a) for a in input().strip().split(' ')]
As = accumulate([int(a)%m for a in input().strip().split(' ')])
As = [0] + [i%m for i in As]
As = sorted(As)
count = 0
ba = None
Bs = []
for a in As:
    if a == ba:
        count += 1
    elif ba != None:
        Bs.append(count*(count+1))
        count = 0
    ba = a
if count != 0:
    Bs.append(count*(count+1))
print(int(sum(Bs)/2))
### BUGGY CODE ###


from itertools import accumulate
def resolve():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    for _ in range(K):
        imos_table = [0] * (N + 1)
        for i, a in enumerate(A):
            # 配列の個数を超えないように注意
            imos_table[max(i - a, 0)] += 1
            imos_table[min(i + a+1, N)] -= 1
        A = list(accumulate(imos_table))[:-1]

        if all([True if a == N else False for a in A]):
            print(*A)
            return
    else:
        print(*A)

if __name__ == "__main__":
    resolve()


### FIXED CODE ###


from itertools import accumulate
def resolve():

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

    for _ in range(K):
        imos_table = [0]*(N+1)
        for i, a in enumerate(A):
            # 配列の個数を超えないように注意
            imos_table[max(i - a, 0)] += 1
            imos_table[min(i + a + 1, N)] -= 1
        A = list(accumulate(imos_table))[:-1]
        if all([True if a == N else False for a in A]):
            print(*A)
            return
    else:
        print(*A)

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

import copy
def search_ans(fee,box,not_open_luxuary,feebox):
  for k,i in enumerate(box):
    if list(set(i[1]) & set(not_open_luxuary))!=[]:
      a=copy.deepcopy(not_open_luxuary)
      t=copy.deepcopy(box)
      fee1=fee
      for j in list(set(i[1]) & set(a)):
        a.remove(j)
      fee1+=i[0]
      if a==[]:
        feebox.append(fee1)
      else:
        t.pop(k)
        search_ans(fee1,t,a,feebox)
	
def main():
  n,m=map(int,input().split())
  index_box=list(range(n+1))
  index_box.pop(0)
  box=[]
  N=[0]*13
  N[0]=10**4
  feebox=[]
  M=[]
  for i in range(m):
  	a1,b1=map(int,input().split())
  	c1=list(map(int,input().split()))
  	box.append([a1,c1])
  search_ans(0,box,index_box,feebox)
  if feebox==[]:
    print(-1)
  else:
    print(min(feebox))

main()

### FIXED CODE ###

def main():
  N,M=map(int,input().split())
  Inf=10**8
  dp=[Inf]*(2**N)
  dp[0]=0
  for i in range(M):
    a,b=map(int,input().split())
    tmp=list(map(int,input().split()))
    open_tresure=list(1<<j-1 for j in tmp)
   # print(open_tresure)
    op_tr=sum(open_tresure)
    for j in range(2**N):
      key=op_tr | j
      dp[key]=min(dp[key],dp[j]+a)
  if dp[-1]==Inf:
    print(-1)
  else:
    print(dp[-1])

main()
### BUGGY CODE ###

L,R = list(map(int,input().split()))

minimum = 2020

for i in range(L,R):
    for j in range(i+1,R+1):
        mod = (i*j)%2019
        if minimum > mod:
            minimum = mod
print(minimum)

### FIXED CODE ###

L,R=map(int,input().split())
if (R-L)>=673:
  print(0)
else:
  ans=2019
  for i in range(L,R):
    for j in range(i+1,R+1):
      ans=min(ans,(i*j)%2019)
  print(ans)
### BUGGY CODE ###

n,k=map(int,input().split())
a=list(map(int,input().split()))
d={}
for i in a:
    d[i]=d.get(i,0)+1
c=0
while len(d)>k:
    x=min(d, key=d.get)
    c+=d[x]
    del d[x]
print(c)


### FIXED CODE ###

n,k=map(int,input().split())
a=list(map(int,input().split()))
s=set(a)
l=[0]*(n+1)
for i in range(n):
    l[a[i]]+=1
l=[i for i in l if i>0]
l.sort()
le=len(s)
c=0
for i in range(len(l)):
    if le<=k:
        break
    else:
        c+=l[i]
        le-=1
print(c)