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

n,m=map(int,input().split())
x=list(map(int,input().split()))
x.sort()
if n==1:
    print(max(x)-min(x))
elif m==1 or n>=m:
    print(0)
else:
    x.sort()
    goukei=0
    l=[0]
    for i in range(m-1):
        goukei+=x[i+1]-x[i]
        l.append(x[i+1]-x[i])
    i=0
    for i in range(n-1):
        goukei-=max(l)
        l.remove(max(l))
    print(goukei)

### FIXED CODE ###

n,m=map(int,input().split())
x=list(map(int,input().split()))
x.sort()
if n==1:
    print(max(x)-min(x))
elif m==1 or n>=m:
    print(0)
else:
    x.sort()
    goukei=0
    l=[0]
    for i in range(m-1):
        goukei+=x[i+1]-x[i]
        l.append(x[i+1]-x[i])
    i=0
    l.sort()
    for i in range(n-1):
        goukei-=l[-1-i]
    print(goukei)
### BUGGY CODE ###

def resolve():
    '''
    code here
    '''
    import collections
    H, W, M = [int(item) for item in input().split()]
    targets = [[int(item) -1 for item in input().split()] for _ in range(M)]

    col = [0 for _ in range(H)]
    row = [0 for _ in range(W)]

    grid = [[0 for _ in range(W+1)] for _ in range(H+1)]



    for i,j in targets:
        col[i] += 1
        row[j] += 1
        grid[i][j] = 1

    max_col = max(col)
    max_row = max(row)
    max_col_index = []
    max_row_index = []

    for i in range(H):
        if col[i] == max_col:
            max_col_index.append(i)

    for i in range(W):
        if row[i] == max_row:
            max_row_index.append(i)

    res = 0
    for item in max_col_index:
        for jtem in max_row_index:
            if grid[item][jtem] == 1:
                res = max(res, max_col + max_row -1)
            else:
                res = max(res, max_col + max_row)
    print(res)

if __name__ == "__main__":
    resolve()


### FIXED CODE ###

def resolve():
    '''
    code here
    '''
    H, W, M = [int(item) for item in input().split()]
    targets = [[int(item) -1 for item in input().split()] for _ in range(M)]

    col = [0 for _ in range(H)]
    row = [0 for _ in range(W)]

    bomb_set = set()
    # 配列で要素を作ると要素数が$10^8$超える場合、setで要素の座標を持っておく


    for i,j in targets:
        col[i] += 1
        row[j] += 1
        bomb_set.add((i,j))

    max_col = max(col)
    max_row = max(row)
    max_col_index = []
    max_row_index = []

    for i in range(H):
        if col[i] == max_col:
            max_col_index.append(i)

    for i in range(W):
        if row[i] == max_row:
            max_row_index.append(i)

    res = 0
    for item in max_col_index:
        for jtem in max_row_index:
            if (item,jtem) not in bomb_set:
                res =max_col + max_row
                break
        else:
            res = max(res, max_col + max_row -1 )
    print(res)

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

import numpy as np

n=int(input())
x=np.array([int(item) for item in input().split()])
x_sorted=np.sort(x)

for i in range(n):
  ind=np.ones(n,dtype=bool)
  ind[np.searchsorted(x_sorted,x[i])]=False
  #print(x_sorted[ind])
  print(x_sorted[ind][n//2-1])

### FIXED CODE ###

n = int(input())
x = list(map(int,input().split()))
x_sorted = sorted(x)
pin = x_sorted[n//2]
pre = x_sorted[n//2 - 1]
for i in range(n):
  if x[i] < pin:
    print(pin)
  else:
    print(pre)
### BUGGY CODE ###

n,k = map(int,input().split())
li = list(map(int, input().split()))
max = 0
for i in range(n-k+1):
  tmp = (sum(li[i:i+k])+k)/2
  if tmp > max:
    max = tmp
print(max)

### FIXED CODE ###

N,K=map(int,input().split())
p=list(map(int,input().split()))
ave=[0]*(N-K+1)
tmp=0
for i in range(K):
    tmp+=(p[i]+1)/2
ave[0]=tmp
for i in range(1,N-K+1):
    ave[i]=ave[i-1]-(p[i-1]+1)/2 + (p[i+K-1]+1)/2
print(max(ave))
### BUGGY CODE ###

#154 d
def kitaichi(x):
    return (x+1)/2

n,k=map(int,input().split())
p=list(map(int,input().split()))
ans=0
for i in range(n-k+1):
    s=0
    for j in range(k):
        s+=kitaichi(p[i+j])
    if s>=ans:
        ans=s
print(ans)


### FIXED CODE ###

#abc154 d
n,k=map(int,input().split())
p=list(map(int,input().split()))
wa=[0]*(n+1)

for i in range(n):
    wa[i+1]=p[i]+wa[i]

ans=0
for i in range(n-k+1):
    kitai=k+wa[i+k]-wa[i]
    if kitai>ans:
        ans=kitai
ans/=2
print(ans)
### BUGGY CODE ###

import sys
import collections


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    a = [list(map(int, readline().split())) for _ in range(n)]
    for i in range(n):
        for j in range(n - 1):
            a[i][j] -= 1
    ls = [0] * n
    ql = collections.deque()
    for i in range(n):
        ql.append([0, i])

    for i in range(10 ** 10):
        fq = [True] * n
        while ql:
            d, ps = ql.popleft()
            if d == i:
                if ls[ps] < n - 1 and fq[ps]:
                    fq[ps] = False
                    nw = a[ps][ls[ps]]
                    rw = a[nw][ls[nw]]
                    if ps == rw and fq[nw]:
                        ls[ps] += 1
                        ql.append([d+1, ps])
                        ls[nw] += 1
                        ql.append([d+1, nw])
                        fq[nw] = False
            else:
                ql.appendleft([d, ps])
                break
        if len(ql) == 0 or sum(ls) == n * (n - 1):
            print(i + 1 if sum(ls) == n * (n - 1) else -1)
            exit()


if __name__ == '__main__':
    solve()


### FIXED CODE ###

def slove():
    import sys
    import collections
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = [list(map(int, input().rstrip('\n').split())) for _ in range(n)]
    ad = [0] * n
    dq = collections.deque([[0, i + 1] for i in range(n)])
    for i in range(10 ** 15):
        fd = {}
        while True:
            if len(dq) != 0:
                d, q = dq.popleft()
                q -= 1
                if d <= i:
                    if ad[q] < n - 1:
                        qq = a[q][ad[q]] - 1
                        tq = a[qq][ad[qq]] - 1
                        if q == tq and qq not in fd and tq not in fd:
                            ad[qq] += 1
                            ad[tq] += 1
                            if ad[qq] < n - 1:
                                dq.append([d + 1, qq + 1])
                            if ad[tq] < n - 1:
                                dq.append([d + 1, tq + 1])
                            fd[qq] = 0
                            fd[tq] = 0
                else:
                    dq.append([d, q + 1])
                    break
            else:
                break
        if len(dq) == 0:
            b = True
            for v in ad:
                if v != n - 1:
                    b = False
                    break
            if b:
                print(i + 1)
                exit()
            else:
                print(-1)
                exit()


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

# coding: utf-8

from itertools import product as prod
import sys
input = sys.stdin.readline

mod = int(1e9 + 7)

def f2(K, D):
    l = len(K)
    dp = [[[0] * D for _ in range(2)] for _ in range(l + 1)]
    dp[0][0][0] = 1
    dl = list(range(D)) * (10 // D + 2)
    for i, j, d in prod(range(l), range(2), range(D)):
        maxk = 9 if j else int(K[i])
        dpij = dp[i][j]
        dpi1 = dp[i + 1]
        for k in range(maxk + 1):
            dpi1j = dpi1[j or k < maxk]
            d_ = dl[d + k]
            dpi1j[d_] += dpij[d]
            dpi1j[d_] %= mod
    # K = 0 の場合が含まれるので -1
    return((dp[-1][0][0] + dp[-1][1][0] - 1 + mod) % mod)

K = input().rstrip() # 1 <= K <= 10^10000
D = int(input()) # 1 <= D <= 100
print(f2(K, D))


### FIXED CODE ###

# coding: utf-8

import sys
input = sys.stdin.readline

mod = int(1e9 + 7)

def f(K, D):
    l = len(K)
    dp = [[[0] * D for _ in range(2)] for _ in range(l + 1)]
    dp[0][0][0] = 1
    for i in range(l):
        ki = int(K[i])
        for j in range(2):
            uki = 9 if j else ki
            dpij = dp[i][j]
            for d in range(D):
                for k in range(uki + 1):
                    dpij_ = dp[i + 1][j or k < ki]
                    d_ = (d + k) % D
                    dpij_[d_] += dpij[d]
                    dpij_[d_] %= mod
    # K = 0 の場合が含まれるので -1
    return((dp[-1][0][0] + dp[-1][1][0] - 1 + mod) % mod)

K = input().rstrip() # 1 <= K <= 10^10000
D = int(input()) # 1 <= D <= 100

print(f(K, D))
### BUGGY CODE ###

import sys
from collections import deque


input = sys.stdin.readline

def main():
    N = int(input().rstrip())
    A = list(map(int, input().rstrip().split()))
    M = max(max(A), 1).bit_length()
    B = [0] * M
    p = 10 ** 9 + 7
    ans = 0

    for n in range(N):
        a = deque(bin(A[n])[2:])
        for i in range(len(a)):
            B[i] += int(a.pop())

    for i, b in enumerate(B):
        tmp = b * (N - b) * 2 ** i
        tmp %= p
        ans = ans + tmp
        ans %= p

    print(ans)


if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys
import numpy as np


input = sys.stdin.readline

def main():
    N = int(input().rstrip())
    A = np.array(input().rstrip().split(), dtype=np.int64)
    M = 60
    p = 10 ** 9 + 7
    ans = 0

    for m in range(M):
        B = (A >> m) & 1
        x = np.count_nonzero(B)
        x *= N-x
        
        x *= 2 ** m
        x %= p
        ans += x

    print(ans % p)


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

R, C, K = map(int, input().split())
dp = [[[0]*4 for _ in range(R+1)] for _ in range(C+1)]
val = [[0]*(R+1) for _ in range(C+1)]

for i in range(K):
    r, c, v = map(int, input().split())
    val[c][r] = v

for i in range(1, C+1):
    for j in range(1, R+1):
        dp[i][j][0] = max(max(dp[i][j-1]), dp[i-1][j][0])
        if val[i][j]>0:
            dp[i][j][1] = max(dp[i-1][j][0]+val[i][j], dp[i-1][j][1], max(dp[i][j-1])+val[i][j])
            dp[i][j][2] = max(dp[i-1][j][1]+val[i][j], dp[i-1][j][2])
            dp[i][j][3] = max(dp[i-1][j][2]+val[i][j], dp[i-1][j][3])
        else:
            dp[i][j][1] = dp[i-1][j][1]
            dp[i][j][2] = dp[i-1][j][2]
            dp[i][j][3] = dp[i-1][j][3]           
#print(dp)
print(max(dp[-1][-1]))

### FIXED CODE ###

R, C, K = map(int, input().split())
dp0 = [[0]*(R+1) for _ in range(C+1)]
dp1 = [[0]*(R+1) for _ in range(C+1)]
dp2 = [[0]*(R+1) for _ in range(C+1)]
dp3 = [[0]*(R+1) for _ in range(C+1)]
val = [[0]*(R+1) for _ in range(C+1)]

for i in range(K):
    r, c, v = map(int, input().split())
    val[c][r] = v

for i in range(1, C+1):
    for j in range(1, R+1):
        temp = max(dp0[i][j-1], dp1[i][j-1])
        temp = max(dp2[i][j-1], temp)
        temp = max(dp3[i][j-1], temp)
        dp0[i][j] = max(temp, dp0[i-1][j])
        if val[i][j]>0:
            dp1[i][j] = max(dp0[i-1][j]+val[i][j], dp1[i-1][j],temp+val[i][j])
            dp2[i][j] = max(dp1[i-1][j]+val[i][j], dp2[i-1][j])
            dp3[i][j] = max(dp2[i-1][j]+val[i][j], dp3[i-1][j])
        else:
            dp1[i][j] = dp1[i-1][j]
            dp2[i][j] = dp2[i-1][j]
            dp3[i][j] = dp3[i-1][j]

print(max(dp0[-1][-1], dp1[-1][-1], dp2[-1][-1],dp3[-1][-1]))
### BUGGY CODE ###

K, S = map(int, input().split())

result = 0
for X in range(K+1):
    for Y in range(K+1):
        Z = S-X-Y
        if 0<=Z and Z<=K and S == X+Y+Z:
            result += 1
print(result)



### FIXED CODE ###

K, S = map(int, input().split())

result = 0
for X in range(K+1):
    for Y in range(K+1):
        Z = S-X-Y
        if Z<0:
            continue
        elif K<Z:
            continue
        elif S == X+Y+Z:
            result += 1
print(result)
### BUGGY CODE ###

import math
NUM=10**9+7
n,A,B = map(int,input().split())

s=(2**(n))%NUM
k=math.factorial(n)
a1=math.factorial(A)
a2=math.factorial(n-A)

b1=math.factorial(B)
b2=math.factorial(n-B)

a=a1*a2
b=b1*b2
print(s-1-k//a-k//b)

### FIXED CODE ###

import math

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

 
def comb(n,k,mod):
    """power_funcを用いて(nCk) mod p を求める"""
    if n<0 or k<0 or n<k: return 0
    if n==0 or k==0: return 1
    k=min(n-k,k)
    #分母
    deno=1
    #分子
    mole=1

    for i in range(1,k+1):
        mole=mole*(n-i+1)%mod
        deno=deno*i%mod

    return (mole*pow(deno,mod-2,mod))%mod


def power_func(a,b,p):
    """a^b mod p を求める"""
    if b==0: return 1
    if b%2==0:
        d=power_func(a,b//2,p)
    return d*d %p
    
    if b%2==1:
        return (a*power_func(a,b-1,p ))%p

mod=10**9+7
print((pow(2,n,mod)- 1 - comb(n,a,mod) - comb(n,b,mod))%mod)
#2**n - 1 -nCa -nCb
### BUGGY CODE ###

# -*- coding: utf-8 -*-
"""
Created on Sun Apr 26 20:57:47 2020
"""

import sys
import numpy as np

sys.setrecursionlimit(10 ** 9)
#def input():
#    return sys.stdin.readline()[:-1]
mod = 10**9+7

x = 2019
S = input()
l = len(S)

a, b = [],[0]
for i in range(l):
#    a.append(int(S[:i+1]) % x)
#    if S[i] != '0':
    b.append(int(S[i:]) % x)

ans = 0

xx = np.bincount(b)

def a(n):
    return n*(n+1)//2 

for i in range(len(xx)):
    if xx[i] > 1:
        ans += a(xx[i] - 1)

print(ans)


### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
Created on Sun Apr 26 20:57:47 2020
"""

import sys
#import numpy as np

sys.setrecursionlimit(10 ** 9)
#def input():
#    return sys.stdin.readline()[:-1]
mod = 2019

S = input()
l = len(S)
#S = int(S)

a, b = [],[0]
s = 0
xx = [0 for _ in range(2019)]
xx[0] += 1
for i in range(l):
    s += int(S[-i-1])*pow(10,i,mod)
    s %= mod
#    b.append(s % x)
    xx[s] += 1

ans = 0
#for i in range(len(b)):
#    xx[b[i]] += 1
def a(n):
    return n*(n+1)//2 

for i in range(len(xx)):
    if xx[i] > 1:
        ans += a(xx[i] - 1)

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

n = int(input())
d = input().split()
m = int(input())
t = input().split()

for i in range(m):
    if t[i] in d:
        d.remove(t[i])
    else:
        print('NO')
        exit()

print('YES')

### FIXED CODE ###

n = int(input())
d = input().split()
m = int(input())
t = input().split()

d.sort()
t.sort()
a = 0

for x in t:
    for i in range(a, n):
        if d[i] > x:
            print('NO')
            exit()
        if x == d[i]:
            a = i+1
            break

print('YES')
### BUGGY CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

INF = 10 ** 10

n = int(input())
# 貰うDPだと0へのアクセスが、配るDPだとn+1へのアクセスが必要になる
h = [INF] + list(map(int, input().split())) + [INF]
dp = [INF] + [INF] * n + [INF]
dp[1] = 0

def chmin(dp_table, index, value):
    if dp_table[index] > value:
        dp_table[index] = value

# 貰うDP(dp[i-1], dp[i-2]が計算済み)
#for i in range(2, n+1):
#    chmin(dp, i, dp[i-1] + abs(h[i] - h[i-1]))
#    chmin(dp, i, dp[i-2] + abs(h[i] - h[i-2]))

# 配るDB(dp[i]が計算済み)
#for i in range(1, (n-1)+1):
#    chmin(dp, i+1, dp[i] + abs(h[i] - h[i+1]))
#    chmin(dp, i+2, dp[i] + abs(h[i] - h[i+2]))
#
#print(dp[n])

# 再帰(DFS) (メモ化なし)
def dfs(i):
    if i == 0:
        return INF
    if i == 1:
        return 0

    ans = INF
    prev_cost = dfs(i-1)
    if ans > prev_cost + abs(h[i] - h[i-1]):
        ans = prev_cost + abs(h[i] - h[i-1])
    prev_cost = dfs(i-2)
    if ans > prev_cost + abs(h[i] - h[i-2]):
        ans = prev_cost + abs(h[i] - h[i-2])

    return ans

# 再帰(DFS) (メモ化ありfunctools.lru_cache使用)
import functools
dfs = functools.lru_cache()(dfs)

print(dfs(n))  

### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

INF = 10 ** 10

n = int(input())
h = [0] + list(map(int, input().split()))
dp = [INF] + [INF] * n
dp[1] = 0

def chmin(dp_table, index, value):
    if dp_table[index] > value:
        dp_table[index] = value

for i in range(2, n+1):
    chmin(dp, i, dp[i-1] + abs(h[i] - h[i-1]))
    chmin(dp, i, dp[i-2] + abs(h[i] - h[i-2]))

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

import sys

sys.setrecursionlimit(500005)
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().strip()

n, q = na()
a = na()
lasts = [-1] * (n+1)
rs = []
for i in range(n):
    if lasts[a[i]] != -1:
        rs.append((lasts[a[i]], i))
    lasts[a[i]] = i

rs.sort(key=lambda k: k[0])

qs = []
for i in range(q):
    u = na()
    qs.append((u[0]-1, u[1]-1, i))
qs.sort(key=lambda k: k[0])

def addfenwick(ft, i, v):
    if v == 0 or i < 0: return
    i += 1
    while i < len(ft):
        ft[i] += v
        i += i&-i

def sumfenwick(ft, i):
    s = 0
    i += 1
    while i > 0:
        s += ft[i]
        i -= i&-i
    return s

ft = [0] * (n+10)
anss = [0] * q
p = len(rs)-1
for q in qs[::-1]:
    while p >= 0 and rs[p][0] >= q[0]:
        addfenwick(ft, rs[p][1], 1)
        p -= 1
    anss[q[2]] = q[1]-q[0]+1-sumfenwick(ft, q[1])

for v in anss:
    print(v)


### FIXED CODE ###

import sys
from operator import itemgetter

sys.setrecursionlimit(500005)
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().strip()

n, q = na()
a = na()
lasts = [-1] * (n+1)
rs = []
for i in range(n):
    if lasts[a[i]] != -1:
        rs.append((lasts[a[i]], i))
    lasts[a[i]] = i

rs.sort(key=itemgetter(0))

qs = []
for i in range(q):
    u = na()
    qs.append((u[0]-1, u[1]-1, i))
qs.sort(key=itemgetter(0))

def addfenwick(ft, i, v):
    if v == 0 or i < 0: return
    i += 1
    while i < len(ft):
        ft[i] += v
        i += i&-i

def sumfenwick(ft, i):
    s = 0
    i += 1
    while i > 0:
        s += ft[i]
        i -= i&-i
    return s

ft = [0] * (n+10)
anss = [0] * q
p = len(rs)-1
for q in qs[::-1]:
    while p >= 0 and rs[p][0] >= q[0]:
        addfenwick(ft, rs[p][1], 1)
        p -= 1
    anss[q[2]] = q[1]-q[0]+1-sumfenwick(ft, q[1])

for v in anss:
    print(v)
### BUGGY CODE ###

def main():
    N, M = list(map(int, input().split()))
    A = []
    for i in range(M):
        A.append(int(input()))

    mod = 1000000007

    dp = {i: 0 for i in range(N+1)}
    dp[0] = 1
    for now in range(0, N):
        for next in range(now+1, min(N, now+2)+1):
            if next not in A:
                dp[next] += dp[now]
                #dp[next] %= mod

    print(dp[N] % mod)

if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    N, M = list(map(int, input().split()))
    A = set()
    for i in range(M):
        A.add(int(input()))

    mod = 1000000007

    dp = [0] * (N+1)
    dp[0] = 1
    for now in range(0, N):
        for next in range(now+1, min(N, now+2)+1):
            if next not in A:
                dp[next] += dp[now]
                dp[next] %= mod

    print(dp[N] % mod)

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

s = input()
num = len(s)
ans = 0
for i in range(num-3):
    for j in range(i+4,num+1):
        temp = int(s[i:j])
        if temp % 2019 == 0:
            ans += 1

print(ans)


### FIXED CODE ###

S=input()
N=len(S)
M=2019

remainder=[0]*M
val=0
for i in range(N):
  val=(int(S[N-1-i])*pow(10,i,M)+val)%M
  remainder[val]+=1

ans=remainder[0]
for i in range(2019):
  ans+=remainder[i]*(remainder[i]-1)//2
print(ans)
### BUGGY CODE ###

import sys
input=sys.stdin.readline
#import fractions
#import math
#import collections
#from collections import deque
#from bisect import bisect_left
#N = int(input())
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = list(map(int,input().split()))
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
N,M = map(int,input().split())
A = [int(input()) for _ in range(M)]  
ans = [0] * (N+3)
ans[0] = 1
for i in range(N):
    if i not in A:
        ans[i+1] += ans[i]
        ans[i+1] = ans[i+1] % 1000000007
        ans[i+2] += ans[i]
        ans[i+2] = ans[i+2] % 1000000007
    else:
        ans[i] = 0
print(ans[N])

### FIXED CODE ###

import sys
input=sys.stdin.readline
#import fractions
#import math
#import collections
#from collections import deque
#from bisect import bisect_left
#N = int(input())
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = list(map(int,input().split()))
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
N,M = map(int,input().split())
dicti = {i:True for i in range(N+2)}
for i in range(M):
    a = int(input())
    dicti[a] = False
ans = [0] * (N+3)
ans[0] = 1
for i in range(N):
    if dicti[i]:
        ans[i+1] += ans[i]
        ans[i+1] = ans[i+1] % 1000000007
        ans[i+2] += ans[i]
        ans[i+2] = ans[i+2] % 1000000007
    else:
        ans[i] = 0
print(ans[N])
### BUGGY CODE ###

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

c = 0
for l in range(n):
  for r in range(l, n):
    if sum(a[l:r + 1]) % m == 0:
      c += 1

print(c)

### FIXED CODE ###

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

d = {0: 1}
s = 0
for i in range(N):
  s += A[i]
  m = s % M
  if m in d:
    d[m] += 1
  else:
    d[m] = 1

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

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

n = int(input())

ss = []
for i in range(n):
	ss.append(sorted(str(input())))

c = 0
for i in range(n):
	for l in range(i+1,n):
		if ss[i] == ss[l]:
			c += 1
print(c)


### FIXED CODE ###

n = int(input())

ss = []
for i in range(n):
	ss.append(sorted(str(input())))

sm = sorted(ss)
c = 0
ans = 0
for i in range(n-1):
	if sm[i] == sm[i+1]:
		c += 1
		ans += c
	else:
		c = 0
print(ans)
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
b=[(a[i],i)for i in range(n)]
b.sort(reverse=1)
dp=[(n+1)*[0]for _ in range(n+1)]
for i in range(1,n+1):
  p,j=b[i-1]
  if j<i-1:break
  dp[i][0]+=dp[i-1][0]+p*(j-(i-1))
for i in range(1,n+1):
  p,j=b[i-1]
  if j>(n-i):break
  dp[0][i]+=dp[0][i-1]+p*((n-i)-j)
for i in range(1,n):
  for j in range(1,n):
    if i+j>n:break
    p,k=b[i+j-1]
    if (i-1)<=k:
      dp[i][j]=max(dp[i][j],dp[i-1][j]+p*(k-(i-1)))
    if k<=(n-j):
      dp[i][j]=max(dp[i][j],dp[i][j-1]+p*((n-j)-k))
ans=0
for i in range(n+1):ans=max(ans,dp[i][n-i])
print(ans)

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
b=[(a[i],i)for i in range(n)]
b.sort(reverse=1)
dp=[(n+1)*[0]for _ in range(n+1)]
for i in range(1,n+1):
  p,j=b[i-1]
  if j<i-1:break
  dp[i][0]+=dp[i-1][0]+p*(j-(i-1))
for i in range(1,n+1):
  p,j=b[i-1]
  if j>(n-i):break
  dp[0][i]+=dp[0][i-1]+p*((n-i)-j)
for i in range(1,n):
  for j in range(1,n):
    if i+j>n:break
    p,k=b[i+j-1]
    if (i-1)<=k:
      dp[i][j]=max(dp[i][j],dp[i-1][j]+p*(k-(i-1)))
    if k<=(n-j):
      dp[i][j]=max(dp[i][j],dp[i][j-1]+p*((n-j)-k))
ans=0
for i in range(n+1):ans=max(ans,dp[i][n-i])
print(ans)
### BUGGY CODE ###

a = list(input())
a = a[::-1]
s = [0]

for i in range(len(a)):
    add = s[i] + int(a[i]) * 10**i
    add = add % 2019
    s.append(add)

ans = 0
for i in range(len(s)-3):
    for j in range(i+1,len(s)):
        if s[i] == s[j]:
            ans += 1

print(ans)


### FIXED CODE ###

a = input()[::-1]
add = 0
ans = [1] + [0] * 2018
ans_int = 0
d = 1

for i in range(len(a)):
    add = (add + int(a[i]) * d) % 2019
    d = (10 * d) %2019
    ans[add] += 1

for i in range(len(ans)):
    a =((ans[i] - 1) * ans[i]) /2
    ans_int += a

print(int(ans_int))
### BUGGY CODE ###

n = int(input())
p = list(map(int,input().split()))
count = 1
for i in range(1,p.index(min(p))+1):
    if p[i] == min(p[:i+1]):
        count += 1
print(count)


### FIXED CODE ###

n = int(input())
p = list(map(int,input().split()))
count = 0
t = p[0]
for i in range(n):
    if p[i] <= t:
        count += 1
        t = p[i]
print(count)
### BUGGY CODE ###

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

ans = []
for i in range(n):
    if i % 2 == 0:
        ans.append(a[i])
    else:
        ans.insert(0, a[i])

if n % 2 == 1:
    for i in range(n):
        print(ans[n - 1 - i], end=" ")
else:
    for i in range(n):
        print(ans[i], end=" ")


### FIXED CODE ###

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

if n % 2 == 0:
    for i in reversed(range(n)):
        if i % 2 == 1:
            print(a[i], end=" ")
    for i in range(n):
        if i % 2 == 0:
            print(a[i], end=" ")
else:
    for i in reversed(range(n)):
        if i % 2 == 0:
            print(a[i], end=" ")
    for i in range(n):
        if i % 2 == 1:
            print(a[i], end=" ")