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

from collections import deque

def insert(x, dll):
    dll.appendleft(x)

def delete(x, dll):
    try:
        dll.remove(x)
    except ValueError:
        pass

def deleteFirst(dll):
    dll.popleft()

def deleteLast(dll):
    dll.pop()

n = int(input())
command1 = {"insert": insert, "delete": delete}
command2 = {"deleteFirst": deleteFirst, "deleteLast": deleteLast}
dll = deque()
for i in range(n):
    input_line = [str(s) for s in input().split()]
    if(input_line[0] in command1):
        command1[input_line[0]](int(input_line[1]), dll)
    else:
        command2[input_line[0]](dll)
print(*dll)

### FIXED CODE ###

from collections import deque
   
n = int(input())
dll = deque()
   
for i in range(n):
    input_line = input().split()
    if input_line[0] == "insert":
        dll.appendleft(input_line[1])
    elif input_line[0] == "delete":
        try:
            dll.remove(input_line[1])
        except:
            pass
    elif input_line[0] == "deleteFirst":
        dll.popleft()
    else:
        dll.pop()
           
print(*dll)
### BUGGY CODE ###

n,ng = map(int,input().split())
nglist = list(int(input()) for i in range(ng))

MOD   = 10**9+7 
dp    = [0]*(n+1)
dp[0] = 1
 
for i in range(1,n+1):

  if i in nglist:
    dp[i] = 0
    continue

  if i==1:
    dp[1] = dp[0]
    continue
  
  dp[i] = (dp[i-2] + dp[i-1]) % MOD

print(dp[n])

### FIXED CODE ###

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

MOD    = 10**9+7 
nglist = [0]*(n+1)
dp     = [0]*(n+1)
dp[0]  = 1

for i in range(ng):
  x = int(input())
  nglist[x] = 1
 
for i in range(1,n+1):

  if nglist[i]==1:
    dp[i] = 0
    continue

  if i==1:
    dp[1] = dp[0]
    continue
  
  dp[i] = (dp[i-2] + dp[i-1]) % MOD

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

#coding:utf-8
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = False
def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]

    N = II()
    A = LMIIS()
    for i in range(N):
        A[i] = [A[i],i]
    A.sort()

    ans = ''
    for i in range(N):
        ans += str(A[i][1]+1) + ' '
    print(ans.rstrip())
        

if __name__ == '__main__':
    main()

### FIXED CODE ###

#coding:utf-8
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = False
def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]

    N = II()
    A = LMIIS()
    for i in range(N):
        A[i] = [A[i],i]
    A.sort()


    for i in range(N):
        print(A[i][1]+1)

        

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

import math
N,M = map(int,input().split())
for i in range(math.floor(M/N),-1,-1):
    if M%i == 0:
        print(i)
        break

### FIXED CODE ###

N,M = map(int,input().split())
a = []
for i in range(1,int(M**0.5)+1):
    if M%i == 0:
        a.append(i)
        a.append(int(M/i))
a.sort(reverse = True)
for i in a:
    if i <= M/N:
        print(i)
        break
### BUGGY CODE ###

from collections import deque
import copy
H,W = map(int, input().split())
field = [[j == "#" for j in input()] for _ in range(H)]
# dy = [1,-1,0,0]
# dx = [0,0,1,-1]
queue = deque([(i, j) for i in range(H) for j in range(W) if field[i][j]])

count = 0
while True:
    count += 1
    nqueue = deque()
    while queue:
        h,w = queue.popleft()
        if w >0 and not field[h][w-1]:
            field[h][w-1] = True
            nqueue.append([h,w-1])
        if w <W-1 and not field[h][w+1]:
            field[h][w+1] = True
            nqueue.append([h,w+1])
        if h >0 and not field[h-1][w]:
            field[h-1][w] = True
            nqueue.append([h-1,w])
        if h < H-1 and not field[h+1][w]:
            field[h+1][w] = True
            nqueue.append([h+1,w])
        # for i in range(4):
        #     nh = h + dy[i]
        #     nw = w + dx[i]
        #     if (0<=nh<H) and (0<=nw<W):
        #         if field[nh][nw] == False:
        #             field[nh][nw] = True
        #             nqueue.append((nh,nw))
    if nqueue:
        queue = copy.copy(nqueue)
    else:
        break
print(count-1)

### FIXED CODE ###

from collections import deque
import copy

def main():
    h, w = map(int, input().split())
    a = [[j == "#" for j in input()] for _ in range(h)]


    # スタート地点をqueueに追加
    que = deque([(i, j) for i in range(h) for j in range(w) if a[i][j]])

    count = 0
    while True:
        count += 1
        nque = deque()
        while que:
            y, x = que.popleft()
            if x > 0 and not a[y][x-1]:
                a[y][x-1] = True
                nque.append((y,x-1))
            if x < w-1 and not a[y][x+1]:
                a[y][x+1] = True
                nque.append((y,x+1))
            if y > 0 and not a[y-1][x]:
                a[y-1][x] = True
                nque.append((y-1,x))
            if y < h-1 and not a[y+1][x]:
                a[y+1][x] = True
                nque.append((y+1,x))

        if nque:
            que = copy.copy(nque)
        else:
            break

    print(count - 1)

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

n,m = map(int,input().split())
price = []
honsu = []
for i in range(n):
  a,b = map(int,input().split())
  price.append(a)
  honsu.append(b)
for j in range(n):
  k = j + 1
  while(k<n):
    if price[j] > price[k]:
      temp1 = price[j]
      temp2 = honsu[j]
      price[j] = price[k]
      honsu[j] = honsu[k]
      price[k] = temp1
      honsu[k] = temp2
    k+=1
money = 0
for l in range(n):
  if(m-honsu[l]>0):
    m -= honsu[l]
    money += honsu[l] * price[l]
  else:
    c = abs(m-honsu[l])
    m -= honsu[l]-c
    money += (honsu[l]-c) * price[l]
  if(m == 0):
    break;
print(money)

### FIXED CODE ###

n,m = map(int,input().split())
price = []
honsu = []
c = []
for i in range(n):
  a,b = map(int,input().split())
  c.append([a,b])
c = sorted(c)
price,honsu=zip(*c)
money = 0
l = 0
while m > 0:
  if(m-honsu[l]>0):
    m -= honsu[l]
    money += honsu[l] * price[l]
  else:
    c = abs(m-honsu[l])
    m -= honsu[l]-c
    money += (honsu[l]-c) * price[l]
  l += 1
print(money)
### BUGGY CODE ###

#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

def gcd(n,m):
    if m == 0:
        return n
    else:
        return gcd(m,n%m)

def lcm(n,m):
    return n*m // gcd(n,m)


n,m = LI()
a = LI()
b = [i//2 for i in a]

if n == 1:
    lb = b[0]
else:
    lb = lcm(b[0],b[1])

for i in b[2:]:
    lb = lcm(lb,i)

for i in b:
    if lb//i % 2 == 0:
        ans = 0
        break
else:
    if lb > m:
        ans = 0
    else:
        ans = (m//lb + 1)//2
print(ans)


### FIXED CODE ###

#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

def gcd(n,m):
    if m == 0:
        return n
    else:
        return gcd(m,n%m)

def lcm(n,m):
    return n*m // gcd(n,m)


n,m = LI()
a = LI()
b = [i//2 for i in a]

lb = 1
for i in b:
    lb = lcm(lb,i)
    if lb > m:
        print(0)
        quit()

for i in b:
    if lb//i % 2 == 0:
        ans = 0
        break
else:
    if lb > m:
        ans = 0
    else:
        ans = (m//lb + 1)//2
print(ans)
### BUGGY CODE ###

import collections
q=collections.deque()
h,w=map(int,input().split())
arr=[[] for _ in range(h+2)]
for i in range(w+2):
  arr[0].append('#')
for i in range(h):
  arr[i+1].append('#')
  for j in input():
    arr[i+1].append(j)
  arr[i+1].append('#')
for i in range(w+2):
  arr[h+1].append('#')
dx=[-1,0,1,0]
dy=[0,-1,0,1]
for i in range(1,h+1):
  for j in range(1,w+1):
    if arr[i][j]=='#':
      q.append((i,j,0))
while 1:
  y,x,cnt=q.popleft()
  for i in range(4):
    if arr[y+dy[i]][x+dx[i]]=='.':
      q.append((y+dy[i],x+dx[i],cnt+1))
      arr[y+dy[i]][x+dx[i]]='#'
  if len(q)==0:
    print(cnt)
    break

### FIXED CODE ###

import collections
q=collections.deque()
h,w=map(int,input().split())
arr=[[] for _ in range(h+2)]
for i in range(w+2):
  arr[0].append('#')
for i in range(h):
  arr[i+1].append('#')
  for j in input():
    arr[i+1].append(j)
  arr[i+1].append('#')
for i in range(w+2):
  arr[h+1].append('#')
dx=[-1,0,1,0]
dy=[0,-1,0,1]
for i in range(1,h+1):
  for j in range(1,w+1):
    if arr[i][j]=='#':
      q.append([i,j,0])
while 1:
  y,x,cnt=q.popleft()
  for i in range(4):
    if arr[y+dy[i]][x+dx[i]]=='.':
      q.append([y+dy[i],x+dx[i],cnt+1])
      arr[y+dy[i]][x+dx[i]]='#'
  if len(q)==0:
    print(cnt)
    break
### BUGGY CODE ###

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

ans = 0
for i in range(1<<q):
  score = 0
  A = [0]*(n+1)
  for j in range(q):
    if (i>>j)&1 == 1:
      A[abcd[j][1]] = A[abcd[j][0]] + abcd[j][2]
      if A[abcd[j][1]] > m:
        break
  for j in range(q):
    if A[abcd[j][1]] - A[abcd[j][0]] == abcd[j][2]:
      score += abcd[j][3]
  if score > ans:
    ans = score
print(ans)

### FIXED CODE ###

n, m, q = map(int, input().split())
abcd = [list(map(int, input().split())) for _ in range(q)]
a,b,c,d = [],[],[],[]
for i in range(q):
  a.append(abcd[i][0])
  b.append(abcd[i][1])
  c.append(abcd[i][2])
  d.append(abcd[i][3])

def score(A):
  tmp = 0
  for ai, bi, ci, di in zip(a, b, c, d):
      if A[bi] - A[ai] == ci:
          tmp += di
  return tmp

def dfs(A):
  if len(A)==n+1:
    return score(A)
  ans = 0
  for i in range(A[-1],m):
    A.append(i)
    ans = max(ans,dfs(A))
    A.pop()
  return ans

print(dfs([0]))
### BUGGY CODE ###

import sys
from collections import OrderedDict

sys.setrecursionlimit(10 ** 6)  # 再帰関数の再帰の深さを設定
to_index = lambda x: int(x) - 1  # 入力した数字に1を引いたものを返す
print_list_in_2D = lambda x: print(*x, sep="\n")  # リストの要素を改行を挟んで表示する関数


# 入力を整数に変換して受け取る
def input_int():
    return int(input())


def map_int_input():
    return map(int, input())


MII = map_int_input


def MII_split():
    return map(int, input().split())


def MII_to_index():
    return map(to_index, input())


def MII_split_to_index():
    return map(to_index, input().split())


# 入力全てを整数に変換したものの配列を受け取る
def list_int_inputs():
    return list(map(int, input()))


LII = list_int_inputs


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


# 2次元リスト化
def LII_2D(rows_number):
    return [LII() for _ in range(rows_number)]


def LII_split_2D(rows_number):
    return [LII_split() for _ in range(rows_number)]


N, X, Y = MII_split()

dists = []
for start_node in range(N - 1):

    dists_from_start = OrderedDict()

    for i in range(start_node, N):
        dists_from_start[i] = i - start_node
    # if X - 1 >= start_node:
    #     dists_from_start[Y - 1] = dists_from_start[X - 1] + 1
    #     for i in range(start_node, N):
    #         dists_from_start[i] = dists_from_start[Y - 1] + abs(i - (Y - 1))
    # else:
    back_s = abs(start_node - (X - 1))
    for i in range(start_node, N):
        dist_t = back_s + 1 + abs(Y - 1 - i)
        dists_from_start[i] = min(dist_t, dists_from_start[i])

    dists += dists_from_start.values()

for k in range(1, N):
    print(dists.count(k))


### FIXED CODE ###

import sys

sys.setrecursionlimit(10 ** 6)  # 再帰関数の再帰の深さを設定
to_index = lambda x: int(x) - 1  # 入力した数字に1を引いたものを返す
print_list_in_2D = lambda x: print(*x, sep="\n")  # リストの要素を改行を挟んで表示する関数

# 入力を整数に変換して受け取る
def input_int():
    return int(input())

def map_int_input():
    return map(int, input())

MII = map_int_input

def MII_split():
    return map(int, input().split())

def MII_to_index():
    return map(to_index, input())

def MII_split_to_index():
    return map(to_index, input().split())

# 入力全てを整数に変換したものの配列を受け取る
def list_int_inputs():
    return list(map(int, input()))

LII = list_int_inputs

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

# 2次元リスト化
def LII_2D(rows_number):
    return [LII() for _ in range(rows_number)]

def LII_split_2D(rows_number):
    return [LII_split() for _ in range(rows_number)]

N, X, Y = MII_split()

dist_counts = {}
for start_node in range(N - 1):
    back_s = abs(start_node - (X - 1))
    for i in range(start_node, N):
        dist_t = back_s + 1 + abs(Y - 1 - i)
        dist = min(dist_t, i - start_node)
        if dist in dist_counts:
            dist_counts[dist] += 1
        else:
            dist_counts[dist] = 1

for k in range(1, N):
    print(dist_counts[k] if k in dist_counts else 0)
### BUGGY CODE ###

import numpy as np 
N = int(input())
A = list(map(int, input().split()))
A =np.array(A,dtype=int)
id =np.arange(1,N+1)

count =0
for i in range(1,N+1):
    x2_big = id[i+1:] -A[i+1:] #各人のidと身長の差
    x1 = i +A[i-1] #iの身長とidの和
    count += np.count_nonzero(x1 ==x2_big)     
    
    """x2_small = id[:i] +A[:i] #各人のidと身長の差
    x1 = i -A[i-1] #iの身長とidの和
    count += np.count_nonzero(x1 ==x2_small)     
    """
print(count)

### FIXED CODE ###

from collections import Counter
N = int(input())
A = list(map(int, input().split()))
l =[]
r =[]
for id,h in enumerate(A,start=1):
    r.append(id -h)
    l.append(id +h)

r_cou =Counter(r)
l_cou =Counter(l)
ans =[]
for i in l_cou.keys():
    ans.append(l_cou[i] *r_cou.get(i,0))

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

N = int(input())
S = input()
cnt = 0
for i in range(len(S)):
    for j in range(i+1,len(S)):
        for k in range(j+1,len(S)):
            if S[i] != S[j] and S[i] != S[k] and S[j] != S[k] and (j-i) != (k-j):
                cnt += 1
print(cnt)

### FIXED CODE ###

N = int(input())
S = input()
SL = list(S)
cnt = 0
nr = SL.count('R')
ng = SL.count('G')
nb = SL.count('B')
ans = nr * ng * nb
cnt = 0
for i in range(len(S)):
    for d in range(N):
        j = i + d
        k = j + d
        if k >= N:
            break
        if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
            ans -= 1
print(ans)
### BUGGY CODE ###

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

# 入力を整数に変換して受け取る
def input_int():
    return int(input())


# マイナス1した値を返却
def int1(x):
    return int(x) - 1


# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
    return map(int, input().split())


# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
    return tuple(map(int, input().split()))


# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))


def main():
    n, k = input_to_int_map()
    a = {i + 1: int(val) for i, val in enumerate(input().split())}

    place = 1
    place_goneds = [place]
    i = 0
    loop_start_index = 0
    while i < n:
        place = a[place]
        goned = False
        for j, place_goned in enumerate(place_goneds):
            if place_goned == place:
                loop_start_index = j
                goned = True
                break

        if goned:
            break

        place_goneds.append(place)
        i += 1

    if k < len(place_goneds):
        return place_goneds[k]

    move_cnt = k - loop_start_index
    loop_list = place_goneds[loop_start_index:]
    return loop_list[move_cnt % len(loop_list)]


if __name__ == "__main__":
    print(main())


### FIXED CODE ###

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

# 入力を整数に変換して受け取る
def input_int():
    return int(input())


# マイナス1した値を返却
def int1(x):
    return int(x) - 1


# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
    return map(int, input().split())


# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
    return tuple(map(int, input().split()))


# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))


def main():
    n, k = input_to_int_map()
    a = {i + 1: int(val) for i, val in enumerate(input().split())}

    place = 1
    visit = {place}
    place_visits = [place]
    for i in range(k):
        place = a[place]
        if place in visit:
            left = place_visits.index(place)
            return place_visits[left + (k - left) % (i + 1 - left)]
        else:
            visit.add(place)
            place_visits.append(place)

    return place


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

import sys

input=sys.stdin.readline

N=int(input())
node=[]
for i in range(0,N-1):
    for j in range(i+1,N):
        node.append((i,j))

_to={key:set([]) for key in node}
_from={key:set([]) for key in node}

for i in range(0,N):
    A=list(map(int,input().split()))
    for j in range(0,N-2):
        if A[j]-1>i:
            if A[j+1]-1>i:
                _to[(i,A[j]-1)].add((i,A[j+1]-1))
                _from[(i,A[j+1]-1)].add((i,A[j]-1))
            else:
                _to[(i,A[j]-1)].add((A[j+1]-1,i))
                _from[(A[j+1]-1,i)].add((i,A[j]-1))
        else:
            if A[j+1]-1>i:
                _to[(A[j]-1,i)].add((i,A[j+1]-1))
                _from[(i,A[j+1]-1)].add((A[j]-1,i))
            else:
                _to[(A[j]-1,i)].add((A[j+1]-1,i))
                _from[(A[j+1]-1,i)].add((A[j]-1,i))

day=0
q=set([])
flag={n:0 for n in node}
for key in node:
    if not _from[key]:
        q.add(key)
sub=set([])
while q:
    while q:
        x=q.pop()
        for n in _to[x]:
            flag[n]+=1
            if flag[n]==len(_from[n]):
                sub.add(n)
        if not q:
            q=sub
            sub=set([])
            day+=1
            break
able=True
for n in node:
    if flag[n]!=len(_from[n]):
        able=False
if able:
    print(day)
else:
    print(-1)

### FIXED CODE ###

N=int(input())
A=[[] for i in range(0,N)]
nodes=[]
for i in range(0,N-1):
    for j in range(i+1,N):
        nodes.append((i,j))

order={i:[0 for j in range(0,N)] for i in range(0,N)}
for i in range(0,N):
    A[i]=list(map(int,input().split()))
    for j in range(0,N-1):
        order[i][A[i][j]-1]=j
        #i番目の人がj番目の人と戦うのが何番目か


q=set([])
for battle in nodes:
    i,j=battle
    if order[i][j]==0 and order[j][i]==0:
        q.add(battle)

flag=[0 for i in range(0,N)]

day=0
sub=set([])
while q:
    while q:
        i,j=q.pop()
        flag[i]+=1
        flag[j]+=1
        if flag[i]!=N-1:
            s=A[i][order[i][j]+1]-1
            if flag[s]>=order[s][i]:
                sub.add((i,s))
        if flag[j]!=N-1:
            t=A[j][order[j][i]+1]-1
            if flag[t]>=order[t][j]:
                sub.add((j,t))

        if not q:
            day+=1
            q=sub
            sub=set([])
            break

able=True
for i in range(0,N):
    if flag[i]!=N-1:
        able=False

if able:
    print(day)
else:
    print(-1)
### BUGGY CODE ###

import numpy as np

N, K = map(int, input().split())
p = np.array(list(map(int, input().split())))

p_0 = np.hstack((p, np.array([0] * (K-1))))

ps = p_0
for i in range(1,K):
    ps = ps + np.roll(p_0,i)

max = np.max(ps)

print((max + K) / 2)

### FIXED CODE ###

import numpy as np

N, K = map(int, input().split())
p = np.array(list(map(int, input().split())))

begin = 0
till = K

max = np.sum(p[0:K])
partial = max
for i in range(N-K):
    partial = partial - p[begin] + p[till]
    if(max < partial):
        max = partial

    begin += 1
    till += 1

print((max + K) / 2)
### BUGGY CODE ###

import math, collections
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n = int(input())
a = list(map(int, input().split()))
al = collections.Counter(a)
res = [0]*(n+1)
dp = [0]*(n+1)
for i in al:
    if al[i]==1: 
        continue
    if dp[al[i]] == 0:
        res[i] += combinations_count(al[i], 2)
        dp[al[i]] += res[i]
    else: res[i] = dp[al[i]]
sum_ = sum(res)
for i in a:
    if al[i]==1:
        print(sum_)
        continue
    if al[i]==2:
        print(sum_-res[i])
        continue
    if dp[al[i]-1] == 0:
        dp[al[i]-1] = combinations_count(al[i]-1, 2)
        print(sum_-res[i]+ dp[al[i]-1])
    else: print(sum_-res[i]+ dp[al[i]-1])

### FIXED CODE ###

import math, collections
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n = int(input())
a = list(map(int, input().split()))
al = collections.Counter(a)
res = [0]*(n+1)
dp = [0]*(n+1)
for i in al:
    if al[i]==1: 
        continue
    if dp[al[i]] == 0:
        res[i] += combinations_count(al[i], 2)
        dp[al[i]] += res[i]
    else: res[i] = dp[al[i]]
sum_ = sum(res)
for i in a:
    if al[i]==1:
        print(sum_)
        continue
    if al[i]==2:
        print(sum_-res[i])
        continue
    if dp[al[i]-1] == 0:
        dp[al[i]-1] = combinations_count(al[i]-1, 2)
        print(sum_-res[i]+ dp[al[i]-1])
    else: print(sum_-res[i]+ dp[al[i]-1])
### BUGGY CODE ###

k,n=map(int,input().split())
x=list(map(int,input().split()))
xx=[]
for i in x:
    xx.append(i)
    xx.append(i-k)
y=sorted(xx)
z=[]
for i in range(n+1):
    z.append(max(y[i:i+n])-min(y[i:i+n]))
print(min(z))

### FIXED CODE ###

k,n=map(int,input().split())
x=list(map(int,input().split()))
xx=[]
for i in x:
    xx.append(i)
    xx.append(i-k)
y=sorted(xx)
z=[]
for i in range(n+1):
    z.append(y[i+n-1]-y[i])
print(min(z))
### BUGGY CODE ###

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

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

dp = [[0] * 2 for i in range(n)]

ans = l[:]

if k > 10**2:
    k = 100
    
for i in range(k):
    for j in range(n):
        dp[j][0] = (j+1 - ans[j] - 0.5)
        dp[j][1] = (j+1 + ans[j] + 0.5)

    ans = [0] * n

    for x in range(n):
        for y in range(n):
            if dp[y][0] <= x+1 <= dp[y][1]:
                ans[x] += 1

else:
    print(*ans)


### FIXED CODE ###

import numpy as np
from numba import njit

@njit #処理の並列化

def imos(n, a):
    
    l=np.zeros((n+1), dtype = np.int64)

    for i in range(n):
        ai = a[i] # 光の強さ_これにより照らせる範囲が決まる
        start = max(0, i - ai) #StartIndex_照らせる範囲
        end = min(n, i + ai + 1) #EndIndex + 1_照らせる範囲
        l[start] += 1 # 各々を'+1'と'-1'で表し...
        l[end] -= 1
    return np.cumsum(l)[:n] # 累積和をとる_cumulative sum

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

for _ in range(k):
    a = imos(n, a)
    if a.min() == n: # すべての要素が最大値'n'になるとbreak
        break

print(*a)
### BUGGY CODE ###

N,M = map(int,input().split())
A=[int(x) for x in input().split()]
count=0
for i in range(N):
  for j in range(i,N):
    if sum(A[i:j+1])%M==0:
      count +=1
print(count)

### FIXED CODE ###

import collections
import numpy as np

N,M = map(int,input().split())
A=np.array([0]+[int(x) for x in input().split()])
B=np.mod(A.cumsum(),M)
answer=0
C = collections.Counter(B)

for x in C.values():
  answer += x*(x-1)//2
print(answer)