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

N, C = list(map(int, input().split()))
tmax = 0
s = [0 for _ in range(N)]
t = [0 for _ in range(N)]
c = [0 for _ in range(N)]
for i in range(N):
    s[i], t[i], c[i] = list(map(int, input().split()))
    if t[i] >= tmax:
        tmax = t[i]

c_timeline = [[0 for _ in range(C)] for _ in range(2*tmax + 1)]
for i in range(N):
    S = s[i]
    T = t[i]
    channel = c[i]-1
    for j in range(2*S-1, 2*T+1):
        c_timeline[j][channel] = 1

rokuga = 0
for timeline in c_timeline:
    time = sum(timeline)
    if rokuga < time:
        rokuga = time

print(rokuga)


### FIXED CODE ###

N, C = list(map(int, input().split()))
tmax = 0
s = [0 for _ in range(N)]
t = [0 for _ in range(N)]
c = [0 for _ in range(N)]
for i in range(N):
    s[i], t[i], c[i] = list(map(int, input().split()))

tmax = max(t)
c_timeline = [[0]*C for _ in range(2 * tmax + 1)]
for i in range(N):
    S = s[i]
    T = t[i]
    channel = c[i] - 1
    for j in range(2 * S - 1, 2 * T + 1):
        c_timeline[j][channel] = 1

rokuga = 0
for timeline in c_timeline:
    time = sum(timeline)
    if rokuga < time:
        rokuga = time

print(rokuga)
### BUGGY CODE ###

import math

N = int(input())
A = []
B = []
for i in range(N):
    in1, in2 = list(map(int,input().split()))
    A.append(in1)
    B.append(in2)
AA = sorted(A)
BB = sorted(B)

if N%2==1:
    low = AA[N//2  ]
    high = BB[N//2  ]
    print(high - low +1)

else:
    low = (AA[N//2-1] + AA[N//2]) / 2
    high = (BB[N//2-1] + BB[N//2]) / 2
    #print(low,high)
    count=0
    while True:
        low +=  0.5
        count+=1
        if low==high:
            break
    #low = math.floor(low)
    #high = math.ceil(high)
    print(count+1)

### FIXED CODE ###

import math

N = int(input())
A = []
B = []
for i in range(N):
    in1, in2 = list(map(int,input().split()))
    A.append(in1)
    B.append(in2)
AA = sorted(A)
BB = sorted(B)

if N%2==1:
    low = AA[N//2]
    high = BB[N//2]
    print(high - low +1)

else:
    low = AA[N//2-1] + AA[N//2]
    high = BB[N//2-1] + BB[N//2]
    #print(low,high)
    print(high - low +1)
### BUGGY CODE ###

# -*- coding:utf-8 -*-
import sys

# n??\???????´???°?????°???????????¢??°
def prime(n):
    l = range(0,n+1)
    i,k = 0,2
    result = 1

    if n >= 3:
        prime_nums = [2, 3]
    else:
        prime_nums = []

    while i <= n:
        while l[i] > k:
            result = l[i]%k
            k = k+1
            if result == 0:
                break
            if (l[i]-1 == k) and (result != 0):
                prime_nums.append(l[i])

        i, k = i+1, 2

    #return prime_nums
    return len(prime_nums)

array = []
for i in sys.stdin:
    array.append(int(i))

l = len(array)
for i in array:
    psum = prime(i)
    print(psum)
    

### FIXED CODE ###

from math import sqrt
I_list=[]
prime_list=[]
while True:
    try:
        I_list.append(int(input()))
    except:
        break
I_max=max(I_list)
search_set={x for x in range(2,I_max+1)}
 
 
p=-1
while p<=sqrt(I_max):
    p=min(search_set)
    prime_list.append(p)
    search_set={x for x in search_set if x%p !=0 }
 
search_list=sorted(list(search_set))
prime_list+=search_list
 
#print(prime_list)
 
 
for i in I_list:
    lower_set={j for j in prime_list if j<=i } 
#   print(lower_set)
    print(len(lower_set))
### BUGGY CODE ###

import sys

Num = int(sys.stdin.readline().rstrip())
list_stu_Num = list(sys.stdin.readline().rstrip().split())
list_attend_stu = []
list_stu_Serial_Num = list(range(1, Num + 1))
for i in list_stu_Serial_Num:
    i = str(i)
    l = list_stu_Num.index(i)
    list_attend_stu.append(l)
print(*list(map(lambda x: x + 1, list_attend_stu)))

### FIXED CODE ###

import sys
import numpy as np

Num = int(sys.stdin.readline().rstrip())
list_stu_Num = list(sys.stdin.readline().rstrip().split())
list_stu_Num_int = [int(s) for s in list_stu_Num]
print(*np.argsort(list_stu_Num_int) + 1)
### BUGGY CODE ###

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

#for i in a:
#i=0
b=[0]*n
r=0
#while i<=n:
for i in range(n):
    r=a[i]
    A=a.count(a[i]+1)
    M=a.count(a[i])
    C=a.count(a[i]-1)

    b[i]=A+M+C

print(max(b))


### FIXED CODE ###

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

#for i in a:
#i=0
b=[0]*(10**5+10)
r=0
#while i<=n:
for i in a:
    b[i]+=1
    b[i+1]+=1
    b[i+2]+=1

print(max(b))
### BUGGY CODE ###

n, k = map(int, input().split())
arr = list(map(int, input().split()))
num_arr = [1]*n
length_arr = []
for i in arr:
  length_arr += [i]

for i in range(k):
  max_idx = length_arr.index(max(length_arr))
  tmp = num_arr[max_idx] + 1
  num_arr[max_idx] = tmp
  length_arr[max_idx] = arr[max_idx] // tmp + 1

result_int = max(length_arr) - 0.0001
print(int(result_int//1 + 1))

### FIXED CODE ###

import math
n, k = map(int, input().split())
arr = list(map(int, input().split()))

max_length = max(arr)
low = 1
high = max_length - 1

while low <= high:
  mid = (low + high) //2
  cnt = 0
  for i in range(n):
    cnt += math.ceil(arr[i]/mid) - 1
  if cnt > k:
    low = mid + 1
  else:
    high = mid -1
    max_length = mid

print(max_length)
### BUGGY CODE ###

n,m,d = map(int, input().split())

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

q = int(input())

buf = {}

for j in range(n):
    for k in range(m):
        buf[grid[j][k]] = (j,k)

for _ in range(q):
    l,r = map(int, input().split())
    prev_x= -1
    prev_y = -1
    s = 0

    for j in range(l,r+1,d):
        if j!=l:
            s+= abs(buf[j][0] - buf[j-d][0]) + abs(buf[j][1] - buf[j-d][1])
    print(s)
            
                


### FIXED CODE ###

n,m,d = map(int, input().split())

grid = []

buf = {}

for j in range(n):
    grid.append(list(map(int, input().split())))
    for k in range(len(grid[j])):
        buf[grid[j][k]] = (j,k)
q = int(input())
al = []

cost = [0] * ((n*m)+1)

for i in range(d+1,n*m+1):
    cost[i] = cost[i-d] + abs(buf[i-d][0] - buf[i][0]) + abs(buf[i-d][1] - buf[i][1])

for _ in range(q):
    l,r = map(int, input().split())
    al.append([l,r])
    

for l,r in al:
    print(cost[r]-cost[l])
### BUGGY CODE ###

n = int(input())
x = input()

x_list = list(x)

for i in range(n):
    temp = x_list.copy()
    temp[i] = "1" if temp[i] == "0" else "0"

    ans = 0
    
    while temp.count("1") != 0:
        a = int("".join(temp), 2)

        a = a % temp.count("1")

        temp = list(bin(a)[2:])

        ans += 1

    print(ans)

### FIXED CODE ###

n = int(input())
x = input()

num_of_1 = x.count("1")

first = int(x, 2)

def f(x):
    if x == 0:
        return 0
    return 1 + f(x % bin(x).count('1'))

if num_of_1 == 1:
    for i in range(n):
        if x[i] == '1':
            print(0)
        elif i == n-1:
            print(2)
        else:
            print(1)
    exit()

first_one, first_zero = first % (num_of_1 - 1), first % (num_of_1 + 1)

for i in range(n):
    if x[i] == "0":
        print(1 + f((first_zero + pow(2, n-i-1, num_of_1 + 1)) % (num_of_1 + 1)))
    else:
        print(1 + f((first_one - pow(2, n-i-1, num_of_1 - 1)) % (num_of_1 - 1)))
### BUGGY CODE ###

from operator import mul
from functools import reduce

def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom
K=int(input())
S=input()
N=len(S)
R=10**9+7
A=0
TF=[1]
TS=[1]
for i in range(K+1):
    TF.append(TF[i]*25 %R)
    TS.append(TS[i]*26 %R)
for i in range(K+1): # Sに含まれる文字を加えるときは、必ず後ろであると考え、S[N-1]の(Sの文字を除いた)位置をiとする
    A=(A+TF[i]*TS[K-i]*combinations_count(i+N-1, i)) %R
print(A)

### FIXED CODE ###

K=int(input())
S=input()
N=len(S)
p=10**9+7
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N+K ):
    fact.append((fact[-1] * i) % p) # [-1]は後ろから?
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return (fact[n] * factinv[r] * factinv[n-r]) % p
A=0
TF=[1]
TS=[1]
for i in range(K+1):
    TF.append(TF[i]*25 %p)
    TS.append(TS[i]*26 %p)
for i in range(K+1): # Sに含まれる文字を加えるときは、必ず後ろであると考え、S[N-1]の(Sの文字を除いた)位置をiとする
    A=(A+TF[i]*TS[K-i]*cmb(i+N-1,i,p)) %p
print(A)
### BUGGY CODE ###

#!/usr/bin/python
# -*- coding:utf-8 -*-

n = int(input())
s = input()

m = n
for i in range(0, n):
    left = s[:i].count('W')
    right = s[i:].count('E')
    if left + right < m:
        m = left + right
print(m)

### FIXED CODE ###

#!/usr/bin/python
# -*- coding:utf-8 -*-

n = int(input())
s = input()

right = []
left = []
bufl = 0
bufr = 0
for i in range(n):
    if 'W' == s[i]:
        bufl += 1
    left.append(bufl)
    if 'E' == s[(n-1)-i]:
        bufr += 1
    right.append(bufr)
right.reverse()

m = n
for i in range(n):
    if m > (right[i] + left[i]) - 1:
        m = (right[i] + left[i]) - 1
print(m)
### BUGGY CODE ###

n = int(input())
s = list(input())

for i in reversed(range(len(s)-1)):
    if s[i+1] == s[i]:
        del s[i+1]

print(len(s))


### FIXED CODE ###

n = int(input())
s = list(input())

count = 0
for i in reversed(range(len(s)-1)):
    if s[i+1] == s[i]:
        count += 1

print(len(s)-count)
### BUGGY CODE ###

N,M=map(int,input().split())
A=list((map(int,input().split())))
 
m=[[1,2],[2,5],[3,5],[4,4],[5,5],[6,6],[7,3],[8,7],[9,6]]
B=[]
    
for a in A:
    B.append(m[a-1])

if [5,5] in B:
    if [2,5] in B:
        B.remove([2,5])
    if [3,5] in B:    
        B.remove([3,5])

if [3,5] in B and [2,5] in B:
    B.remove([2,5])

if [7,3] in B:
    if [6,6] in B:
        B.remove([6,6])
    if [9,6] in B:
        B.remove([9,6])
    
if [9,6] in B and [6,6] in B:
    B.remove([6,6])

if [1,2] in B and [7,3] in B:
    if [2,5] in B:
        B.remove([2,5])
    if [3,5] in B:
        B.remove([3,5])
    if [5,5] in B:
        B.remove([5,5])
    if [8,7] in B:
        B.remove([8,7])

if [1,2] in B and ([2,5] in B or [3,5] in B or [5,5] in B) and [8,7] in B:
    B.remove([8,7])
    
if [4,4] in B and [7,3] in B and [8,7] in B:
    B.remove([8,7])
    
if [1,2] in B and [4,4] in B:
    B.remove([4,4])

maxlist=[""]*(N+1)
 
for i in range(N+1):
    if i!=0 and maxlist[i]=="":
        continue
    else:
        for b in B:
            if i+b[1]>N:
                continue
            ans=maxlist[i]+str(b[0])
            _max=maxlist[i+b[1]]
            if len(ans)<len(_max):
                continue
            elif len(ans)>len(_max):
                maxlist[i+b[1]] = ans
            else:
                for j in range(len(ans)):
                    if ans[j]<_max[j]:
                        break
                    if ans[j]>_max[j]:
                        maxlist[i+b[1]] = ans
                        break
 
print(maxlist[N])

### FIXED CODE ###

N,M=map(int,input().split())
A=list((map(int,input().split())))
 
m=[[1,2],[2,5],[3,5],[4,4],[5,5],[6,6],[7,3],[8,7],[9,6]]
B=[]
    
for a in A:
    B.append(m[a-1])

if [5,5] in B:
    if [2,5] in B:
        B.remove([2,5])
    if [3,5] in B:    
        B.remove([3,5])

if [3,5] in B and [2,5] in B:
    B.remove([2,5])

if [7,3] in B:
    if [6,6] in B:
        B.remove([6,6])
    if [9,6] in B:
        B.remove([9,6])
    
if [9,6] in B and [6,6] in B:
    B.remove([6,6])

if [1,2] in B and [7,3] in B:
    if [2,5] in B:
        B.remove([2,5])
    if [3,5] in B:
        B.remove([3,5])
    if [5,5] in B:
        B.remove([5,5])
    if [8,7] in B:
        B.remove([8,7])

if [1,2] in B and ([2,5] in B or [3,5] in B or [5,5] in B) and [8,7] in B:
    B.remove([8,7])
    
if [4,4] in B and [7,3] in B and [8,7] in B:
    B.remove([8,7])
    
if [1,2] in B and [4,4] in B:
    B.remove([4,4])

maxlist=[""]*(N+1)
 
for i in range(N+1):
    if i!=0 and maxlist[i]=="":
        continue
    else:
        for b in B:
            if i+b[1]>N:
                continue
            ans=maxlist[i]+str(b[0])
            _max=maxlist[i+b[1]]
            if len(ans)<len(_max):
                continue
            elif len(ans)>len(_max):
                maxlist[i+b[1]] = ans
            else:
                for j in range(len(ans)):
                    if ans[j]<_max[j]:
                        break
                    if ans[j]>_max[j]:
                        maxlist[i+b[1]] = ans
                        break
 
print(maxlist[N])
### BUGGY CODE ###

N = int(input())
St = input()

#初期化
dp=[[0 for i in range(N+1)] for j in range(N+1)]

#DP:dp[i][j] Sのi文字目以降とj文字目以降の最大マッチング
for i in range(N-1,-1,-1):
  for j in range(N-1, i-1, -1):
    dp[i][j] = max(dp[i][j+1],dp[i+1][j])
    if St[i] == St[j]:
      dp[i][j] = min(max(dp[i][j], dp[i+1][j+1]+1),j-i)
      

print(max(sum(dp, [])))

### FIXED CODE ###

N = int(input())
S = input()
from collections import deque

def is_ok(l):
    hs = set()
    q = deque()
    for i in range(N-l+1):
        h = S[i:i+l]
        if h in hs:
            return True
        q.append(h)
        if len(q) >= l:
            hs.add(q.popleft())
    return False

ok = 0
ng = N//2+1
while ng-ok > 1:
    m = (ng+ok)//2
    if is_ok(m):
        ok = m
    else:
        ng = m
print(ok)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readline
n,m=map(int,input().split())
z=n*(n-1)//2
l=[-1]*n
a=[1]*n
b=[input().split() for _ in range(m)]
c=[0]*m+[z]
def f(x):
  x=int(x)-1
  s=x+0
  while(1):
    t=l[s]
    if t<0:
      l[x]=s
      return s
    s=t
for i in range(m-1,-1,-1):
  x,y=map(f,b[i])
  if x!=y:
    l[x]=y
    z-=a[x]*a[y]
    a[y]+=a[x]
  c[i]=z
for x in c[1:]:
  print(x)

### FIXED CODE ###

import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readline
n,m=map(int,input().split())
z=n*(n-1)//2
l=[-1]*n
a=[1]*n
b=[input().split() for _ in range(m)]
c=[0]*m+[z]
def r(s):
  t=l[s]
  if t<0:
    return s
  else:
    l[s]=r(t)
    return l[s]
def f(s):
  return r(int(s)-1)
for i in range(m-1,-1,-1):
  x,y=map(f,b[i])
  if x!=y:
    l[x]=y
    z-=a[x]*a[y]
    a[y]+=a[x]
  c[i]=z
for x in c[1:]:
  print(x)
### BUGGY CODE ###

if __name__=="__main__":
    N = int(input())
    l = list(map(int,input().split(" ")))
    s = list(set(l))
    dic = {i:0 for i in range(len(s))}
    count = 0
    for i in l:
          dic[s.index(i)] +=1
    for j in range(len(dic)):
        count+= dic[j]-s[j] if s[j]<=dic[j] else dic[j]
    print(count)

### FIXED CODE ###

def main():
    N = int(input())
    l = list(map(int,input().split(" ")))
    dic = {}
    count = 0
    for i in l:
        try:
            dic[i] += 1
        except Exception:
            dic[i] = 1

    for j in dic.items():
        count += j[1] - j[0] if j[1] >= j[0] else j[1]
    print(count)


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

#https://atcoder.jp/contests/abc152/tasks/abc152_c
# -*- coding: utf-8 -*-
N = int(input())
P = input().split()
T = []
L =[0]*(N-1)
L.insert(0,1)
T.insert(0,int(P[0]))
P[0] = int(P[0])
for i in  range(1,len(P)):
  P[i] = int(P[i])
  if min(T)>=P[i]:
    L[i] = 1
    T.append(P[i])
print(L.count(1))

### FIXED CODE ###

#https://atcoder.jp/contests/abc152/tasks/abc152_c
# -*- coding: utf-8 -*-
N = int(input())
P = input().split()
T = []
L =0
T.insert(0,int(P[0]))
P[0] = int(P[0])
for i in  range(1,len(P)):
  P[i] = int(P[i])
  if T[-1]>=P[i]:
    L =+ 1
    if T[-1]>P[i]:
      T.append(P[i])
print(len(T))
### BUGGY CODE ###

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

ans = 0
for i in range(n):
    if i == 0:
        if a[i] == 0:
            f = "+"
            a[i] = 1
        elif a[0] > 0:
            f = "+"
        elif a[0] < 0:
            f = "-"
    else:
        o = sum(a[:i])
        if f == "+":
            if a[i] + o > 0:
                c = -1 - o
                ans += abs(c - a[i])
                a[i] = c
                f = "-"
            else:
                if a[i] + o == 0:
                    a[i] -= 1
                    ans += 1
                f = "-"
        elif f == "-":
            if a[i] + o < 0:
                c = 1 - o
                ans += abs(c - a[i])
                a[i] = c
                f = "+"
            else:
                if a[i] + o == 0:
                    a[i] += 1
                    ans += 1
                f = "+"
#print(a)
print(ans)


### FIXED CODE ###

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

ans = 0
f = 1
num = 0
for i in range(n):
    num += a[i]
    if f:
        if num <= 0:
            ans += 1 - num
            num = 1
        f = 0
    else:
        if num >= 0:
            ans += abs(-1 - num)
            num = -1
        f = 1

ans_2 = 0
f = 1
num = 0
for i in range(n):
    num += a[i]
    if f:
        if num >= 0:
            ans_2 += abs(-1 - num)
            num = -1
        f = 0
    else:
        if num <= 0:
            ans_2 += 1 - num
            num = 1
        f = 1

print(min(ans,ans_2))
### BUGGY CODE ###

n, q = [int(i) for i in input().split()]
string = list(input())

for i in range(q):
    res = 0
    start, end = [int(i) for i in input().split()]
    start -= 1
    temp = string[start:end]
    for j in range(len(temp) - 1):
        if temp[j] == 'A' and temp[j+1] == 'C':
            res += 1
    print(res)

### FIXED CODE ###

N, Q = map(int, input().split())
S = input()
t = [0] * (N + 1)
for i in range(N):
    t[i + 1] = t[i] + (1 if S[i : i + 2] == 'AC' else 0)
for i in range(Q):
    l, r = map(int, input().split())
    print(t[r-1] - t[l-1])
### BUGGY CODE ###

from operator import itemgetter
import sys


class BIT:
    def __init__(self, size: int):
        self.size = size + 1
        self.array = [0] * self.size

    def add(self, i, x):
        while i < self.size:
            self.array[i] += x
            i += i & -i

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.array[i]
            i -= i & -i
        return s


def read():
    return sys.stdin.readline().rstrip()


def add(arr, i, x):
    while i < len(arr):
        arr[i] += x
        i += i & -i


def range_sum(arr, a, b):
    s = 0
    i = b
    while i > 0:
        s += arr[i]
        i -= i & -i
    i = a - 1
    while i > 0:
        s -= arr[i]
        i -= i & -i
    return s


def main():
    n, q = map(int, read().split())
    c = [int(i) for i in read().split()]
    queries = [() for _ in range(q)]
    for i in range(q):
        l, r = map(int, read().split())
        queries[i] = (i, l, r)
    queries.sort(key=itemgetter(2))
    last = [0] * n
    # bit = BIT(n)
    bit = [0] * (n + 1)
    ans = [-1] * q
    cr = 0
    for i, l, r in queries:
        for ri in range(cr, r):
            ci = c[ri] - 1
            if last[ci] > 0:
                # bit.add(last[ci], -1)
                add(bit, last[ci], -1)
            last[ci] = ri + 1
            # bit.add(last[ci], 1)
            add(bit, ri + 1, 1)
            cr = ri + 1
        # ans[i] = bit.sum(r) - bit.sum(l - 1)
        ans[i] = range_sum(bit, l, r)
    print(*ans, sep="\n")


if __name__ == '__main__':
    main()


### FIXED CODE ###

from operator import itemgetter
import sys


class BIT:
    def __init__(self, size: int):
        self.size = size + 1
        self.array = [0] * self.size

    def add(self, i, x):
        if not i > 0:
            return
        while i < self.size:
            self.array[i] += x
            i += i & -i

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.array[i]
            i -= i & -i
        return s


def read():
    return sys.stdin.readline().rstrip()


def main():
    n, q = map(int, read().split())
    c = [int(i) for i in read().split()]
    queries = [() for _ in range(q)]
    for i in range(q):
        l, r = map(int, read().split())
        queries[i] = (i, l, r)
    queries.sort(key=itemgetter(2))
    last = [0] * n
    bit = BIT(n)
    ans = [-1] * q
    cr = 0
    for i, l, r in queries:
        for ri in range(cr, r):
            ci = c[ri] - 1
            bit.add(last[ci], -1)
            last[ci] = ri + 1
            bit.add(last[ci], 1)
            cr = ri
        ans[i] = bit.sum(r) - bit.sum(l - 1)
    print(*ans, sep="\n")


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

S = str(input())
"""
def solution(S):
    a = len(S)
    b = list(0 for j in range(4, a+1)
        for i in range(a-j+1)
            if int(S[i:i+j])%2019==0)
    print(len(b))
solution(S)
"""

def solution(S):
    a = len(S)
    b = list(0 for j in range(4, a+1)
        for i in range(a-j+1)
            if int(S[i:i+j])%3==0 and int(S[i:i+j])%673==0)
    print(len(b))
solution(S)

### FIXED CODE ###

s = input()[::-1] # 入力文字列を逆順でsに格納

counts = [0] * 2019
counts[0] = 1

num, d = 0, 1

for char in s:
    num += int(char) * d
    num %= 2019
    d *= 10
    d%= 2019
    counts[num] += 1

ans = 0
for cnt in counts:
    ans += cnt * (cnt - 1) // 2

print(ans) # 答えの出力
### BUGGY CODE ###

import sys,heapq
input = sys.stdin.readline
 
N,M = list(map(int,input().split()))
A = sorted(list(map(int,input().split())),reverse = 1)
rep = []
for _ in range(M):
    b,c = list(map(int,input().split()))
    tmp = [-c]*b
    rep += tmp
heapq.heapify(rep)
 
for i in range(N):
    A[i] = -1 * heapq.heappushpop(rep,-1*A[i])
print(sum(A))

### FIXED CODE ###

import sys
input = sys.stdin.readline

def sol():
    N,M = list(map(int,input().split()))
    A = list(map(int,input().split()))
    tmp = sorted([list(map(int,input().split())) for _ in range(M)],key = lambda x:-x[1])

    t = []
    for a,b in tmp:
        t+=[b]*a
        
        if len(t) >=N:
            break

    A += t
    A.sort(reverse = 1)
    print(sum(A[:N]))

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

n=int(input())
g={(i,j):[] for i in range(n+1) for j in range(n+1) if i<j}
visit={(i,j):0 for i in range(n+1) for j in range(n+1) if i<j}
d={(i,j):0 for i in range(n+1) for j in range(n+1) if i<j}

inf=10**10

for i in range(1,n+1):
    last=(0,1)
    for j in list(map(int,input().split())):
        current=(min(i,j),max(i,j))
        g[last].append(current)
        last=current

def dfs(u):
    if visit[u]==2:
        return d[u]
    
    ans=0
    visit[u]=1
    for v in g[u]:
        if visit[v]==1:
            print(-1)
            exit(0)
        
        d[u]=max(d[u],1+dfs(v))
    
    visit[u]=2
    return d[u]

print(dfs((0,1)))

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)

n=int(input())
g=[set() for _ in range(n*(n-1)//2+1)]
visit=[0]*(n*(n-1)//2+1)
d=[0]*(n*(n-1)//2+1)

for i in range(1,n+1):
    last=0
    for j in list(map(int,input().split())):
        mi,ma=(min(i-1,j-1),max(i-1,j-1))
        current=ma*(ma-1)//2+mi+1
        g[last].add(current)
        last=current

def dfs(u):
    if visit[u]==2:
        return d[u]
    
    ans=0
    visit[u]=1
    for v in g[u]:
        if visit[v]==1:
            print(-1)
            exit(0)
        
        d[u]=max(d[u],1+dfs(v))
    
    visit[u]=2
    return d[u]

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

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

for i in range(1, N + 1):
    print(A.index(i) + 1, end=' ')


### FIXED CODE ###

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

import numpy as np

A = np.array(A)
print(' '.join([str(i + 1) for i in A.argsort()]))
### BUGGY CODE ###

n=int(input())
sump=1

for i in range(n):
  sump*=i+1
  
print(sump%(10**9+7))

### FIXED CODE ###

n=int(input())
sump=1

for i in range(n):
  sump*=i+1
  sump%=1000000007
  
print(sump)