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

import bisect
from operator import itemgetter

h,w,n = map(int, input().split())
# 黒マス
black = []

# 周囲に黒マスがあるマス
search = set()

for i in range(n):
    a,b = map(int, input().split())
    a-=1
    b-=1
    black.append([a,b])
    for x in [-1,0,1]:
        for y in [-1,0,1]:
            if 1<=a+y<h-1 and 1<=b+x<w-1:
                search.add((a+y,b+x))  # タプル。set()内にリストは格納できない。

# 二分探索のためソート
black.sort(key=itemgetter(1))
black.sort(key=itemgetter(0))

ans = [0]*10
# 探索すべき全マスに対して、周囲の黒マスの数を数える。
for a,b in search:
    p = 0
    for y in [-1,0,1]:
        for x in [-1,0,1]:
            try:
                if [a+y,b+x]==black[bisect.bisect_left(black,[a+y,b+x])]:
                    p+=1
            except:
                continue
    ans[p]+=1
ans[0]=(h-2)*(w-2)-sum(ans[1:])

for a in ans:
    print(a)

### FIXED CODE ###

h,w,n = map(int, input().split())

# 黒マス black[y座標] = [x1,x2,...]
black = dict()

# 周囲に黒マスがあるマス
search = set()

for i in range(n):
    a,b = map(int, input().split())
    a-=1
    b-=1
    for x in [-1,0,1]:
        for y in [-1,0,1]:
            if 1<=a+y<h-1 and 1<=b+x<w-1:
                search.add((a+y,b+x))  # タプル。set()内にリストは格納できない。
    try:
        black[a][b]=1
    except:
        black[a]=dict()
        black[a][b]=1


ans = [0]*10
# 探索すべき全マスに対して、周囲の黒マスの数を数える。
for a,b in search:
    p = 0
    for y in [-1,0,1]:
        for x in [-1,0,1]:
            try:
                if black[a+y][b+x]==1:
                    p+=1
            except:
                continue
    ans[p]+=1
ans[0]=(h-2)*(w-2)-sum(ans[1:])

for a in ans:
    print(a)
### BUGGY CODE ###

from fractions import gcd


def lcm(a, b):
    return a * b / gcd(a, b)


MOD = 10**9+7
N = int(input())
A = list(map(int, input().split()))

B = sorted(set(A))

l = 1
for b in B:
    if l % b == 0:
        continue
    l = lcm(l, b)

ans = 0
for a in A:
    ans += l // a
    ans %= MOD

print(int(ans))


### FIXED CODE ###

from fractions import gcd

mod = 10 ** 9 + 7

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

lcm = 1
for s in A:
    lcm = s * lcm // gcd(lcm, s)

ans = lcm * sum([pow(s, mod - 2, mod) for s in A]) % mod

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

n = int(input())
sum = 0
for i in range(n):
	sum += i + 1
print(sum - n)

### FIXED CODE ###

n = int(input())
print((n * (n+1)) // 2 - n)
### BUGGY CODE ###

n = int(input())
lst = [int(i) for i in input().split()]

count = 0
for i in range(n):
  a = lst[i]
  if n - 1 <= a + i:
    continue
  for j in range(i + a, n):
    b = lst[j]
    if j - i == a + b:
      count += 1
print(count)


### FIXED CODE ###

n = int(input())
lst = [int(i) for i in input().split()]

dic = {}
count = 0
for i in range(n):
  num = lst[i]
  a = i + num
  if a not in dic:
    dic[a] = 1
  else:
    dic[a] += 1
  b = i - num
  if b in dic:
    count += dic[b]
print(count)
### BUGGY CODE ###

n = int(input())
a = [0] * n
b = [0] * n

for i in range(n):
    a[i],b[i] = map(int,input().split(" "))

for i in range(n):
    if max(b) < sum(a):
        print("No")
        break
    a.pop(b.index(max(b)))
    b.pop(b.index(max(b)))
else:
    print("Yes")


### FIXED CODE ###

n = int(input())
a = [[0,0]] * n
time = 0

for i in range(n):
    x,y = map(int,input().split(" "))
    a[i] = [y,x]

a.sort()
for i,j in a:
    time += j
    if i < time:
        print("No")
        break
else:
    print("Yes")
### BUGGY CODE ###

n,m=map(int,input().split())
s=list(map(int,input().split()))
t=list(map(int,input().split()))
a=[1]*(m+1)
for i in range(n):
    b=a[:]
    k=0
    for j in range(m):
        b[j]=(k+b[j])%(10**9+7)
        if s[i]==t[j]:
            k=(k+a[j])%(10**9+7)
    b[-1]=(k+b[-1])%(10**9+7)
    a=b[:]
print(a[-1]%(10**9+7))

### FIXED CODE ###

N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
dp = [1] * (M+1)
dpleft = [0] * (M)
MOD = 10 ** 9 + 7
ndp = [1] * (M+1)
for n in range(N):
    for m in range(M):
        if S[n] == T[m]:
            ndp[m+1] = ndp[m] + dp[m+1]
            dpleft[m] = dp[m+1]
        else:
            ndp[m+1] = ndp[m] + dpleft[m]
    dp = ndp[:]
print(dp[-1] % MOD)
### BUGGY CODE ###

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

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

for i in range(n):
    for j in range(i+1, n):
        if al[i] == al[j]:
            print('NO')
            exit()
print('YES')

### FIXED CODE ###

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

n = int(input())
al = list(map(int, input().split()))
al.sort()

for i in range(n-1):
    if al[i] == al[i+1]:
        print('NO')
        exit()
print('YES')
### BUGGY CODE ###

import sys

n = int(input())
a = []
for i in range(n):
    a.append(list(map(int, input().split())))
day = 0
match = [0 for i in range(n)]
while match != [n - 1 for i in range(n)]:
    add = [False for i in range(n)]
    for i in range(n):
        if match[i] <= n - 2:
            j = a[i][match[i]] - 1
            if a[j][match[j]] - 1 == i:
                add[i] = True
                add[j] = True
    if add != [False for i in range(n)]:
        match = [match[i] + int(add[i]) for i in range(n)]
        day += 1
    else:
        break
else:
    print(day)
    sys.exit()
print(-1)

### FIXED CODE ###

import sys, collections
input = sys.stdin.readline

n = int(input())
a = []
for i in range(n):
    a.append(list(map(int, input().split())))
nums = [0 for i in range(n)]
day = 0
match = 0
flag = True
queue = collections.deque([])
temp = set()
for i in range(1, n + 1):
    i2 = a[i - 1][0]
    if a[i2 - 1][0] == i:
        if i not in temp:
            queue.append([i, i2])
            temp.add(i)
            temp.add(i2)
if not queue:
    flag = False
while queue:
    temp = []
    while queue:
        test = queue.popleft()
        match += 1
        num1, num2 = test[0], test[1]
        nums[num1 - 1] += 1
        nums[num2 - 1] += 1
        temp.append(num1)
        temp.append(num2)
    flag2 = False
    temp2 = set()
    for i in temp:
        if nums[i - 1] <= n - 2:
            new_num = a[i - 1][nums[i - 1]]
            if nums[new_num - 1] <= n - 2 and a[new_num - 1][nums[new_num - 1]] == i:
                if i not in temp2:
                    queue.append([i, new_num])
                    flag2 = True
                    temp2.add(i)
                    temp2.add(new_num)
    if flag2 == False and match < n * (n - 1) // 2:
        flag = False
        break
    day += 1

if flag == True:
    print(day)
else:
    print(-1)
### BUGGY CODE ###

N = int(input())
ans = 0

for i in range(1, N):
    ans += i

print(ans)

### FIXED CODE ###

N = int(input())

ans = (N-1)*N//2 +7
ans -=7

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

n = int(input())

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

import itertools
alsum = list(itertools.accumulate(al))

temp1 = 0
temp2 = 0
for i in range(n):
    if i % 2 ==0:
        if alsum[i] >0:
            pass
        else:
            y = abs(alsum[i])+1
            temp1 += y
            alsum = list(map(lambda x:x +y ,alsum))
    else:
        if alsum[i] <0:
            pass
        else:
            y = alsum[i]+1
            temp1 += y
            alsum = list(map(lambda x:x-y,alsum))
    
import itertools
alsum = list(itertools.accumulate(al))

for j in range(n):
    if j % 2 ==0:
        if alsum[j] <0:
            pass
        else:
            y = abs(alsum[j])+1
            temp2 += y
            alsum = list(map(lambda x:x-y,alsum))
    else:
        if alsum[j] >0:
            pass
        else:
            y = abs(alsum[j])+1
            temp2 += y
            alsum = list(map(lambda x:x+y,alsum))

print(min(temp1,temp2))

### FIXED CODE ###

n = int(input())

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

import itertools
alsum = list(itertools.accumulate(al))

temp1 = 0
temp2 = 0
res = 0
for i in range(n):
    res += al[i]
    if i % 2 ==0:
        if res >0:
            pass
        else:
            y = res*(-1)+1
            temp1 += y
            res =1
    else:
        if res <0:
            pass
        else:
            y = res+1
            temp1 += y
            res = -1
    
res= 0

for j in range(n):
    res += al[j]
    if j % 2 ==0:
        if res <0:
            pass
        else:
            y = res+1
            temp2 += y
            res = -1
    else:
        if res >0:
            pass
        else:
            y = res*(-1)+1
            temp2 += y
            res = 1

print(min(temp1,temp2))
### BUGGY CODE ###

if __name__ == '__main__':
    N = int(input())
    order_list = list(map(int, input().split()))
    present_list = list()

    for i in range(1, (N+1)):
        present_list.append(order_list.index(i) + 1)

    print(' ' .join(map(str, present_list)))

### FIXED CODE ###

if __name__ == '__main__':
    N = int(input())
    order_list = list(map(int, input().split()))
    present_list = list(range(1, N+1))
    temp = zip(order_list, present_list)
    temp = sorted(temp)
    order_list, present_list = zip(*temp)
    print(' '.join(map(str,present_list)))
### BUGGY CODE ###

from collections import deque

mod = 1000000007

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

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

plus_1 = deque()
minus_1 = deque()
plus_2 = deque()
minus_2 = deque()

a.sort()

for i in a:
    if i > 0:
        plus_2.append(i)
    else:
        minus_1.append(i)

a.sort(reverse=True)

for i in a:
    if i > 0:
        plus_1.append(i)
    else:
        minus_2.append(i)

maxa = 1

mini = 1

i = 0

while i < k:
    if len(plus_1) > 1 and len(minus_1) > 1:
        if plus_1[0]*plus_1[1] < minus_1[0]*minus_1[1] and i+2<=k:
            maxa *= minus_1[0]*minus_1[1]
            minus_1.popleft()
            minus_1.popleft()
            i += 2
        else:
            maxa *= plus_1[0]
            plus_1.popleft()
            i += 1
    elif len(plus_1):
        maxa *= plus_1[0]
        plus_1.popleft()
        i += 1
    else:
        maxa *= minus_1[0]
        minus_1.popleft()
        i += 1

i = 0

while i < k:
    if len(plus_2) and len(minus_2):
        if plus_2[0] < abs(minus_2[0]):
            mini *= plus_2[0]
            plus_2.popleft()
        else:
            mini *= minus_2[0]
            minus_2.popleft()
    elif len(plus_2):
        mini *= plus_2[0]
        plus_2.popleft()
    else:
        mini *= minus_2[0]
        minus_2.popleft()
    i += 1

if maxa > 0:
    print(maxa%mod)
else:
    print(mini%mod)

### FIXED CODE ###

MOD = 10 ** 9 + 7
 
N, K = map(int, input().split())
l = list(map(int, input().split()))
pos = []
neg = []
z = 0
 
for v in l:
    if v > 0:
        pos.append(v)
    elif v < 0:
        neg.append(v)
    else:
        z += 1
pos.sort()
neg.sort()
 
if N - z < K:
    print(0)
elif N - z == K:
    if len(neg) % 2 and z:
        print(0)
    else:
        out = 1
        for v in neg + pos:
            out *= v
            out %= 10 ** 9 + 7
        print(out)
elif len(pos) == 0:
    if K % 2:
        if z:
            print(0)
        else:
            neg.reverse()
            out = 1
            for i in range(K):
                out *= neg[i]
                out %= 10 ** 9 + 7
            print(out)
    else:
        out = 1
        for i in range(K):
            out *= neg[i]
            out %= 10 ** 9 + 7
        print(out)
else:
    out = 1
    neg.reverse()
    if K % 2:
        out = pos.pop()
        K -= 1
    while K:
        if len(pos) >= 2:
            nP = pos[-1] * pos[-2]
        else:
            nP = 0
 
        if len(neg) >= 2:
            nN = neg[-1] * neg[-2]
        else:
            nN = 0
 
        if nP > nN:
            pos.pop()
            pos.pop()
            out *= nP
        else:
            neg.pop()
            neg.pop()
            out *= nN
        out %= MOD
        K -= 2
    print(out)
### BUGGY CODE ###

# coding=utf-8
from functools import lru_cache

line = input().split(" ")
h = int(line[0])
w = int(line[1])
d = int(line[2])

table = [0 for _ in range(h*w+1)]
for hi in range(h):
    line = list(map(int, input().split(" ")))

    for wi in range(w):
        table[line[wi]] = (hi+1, wi+1)

@lru_cache()
def calc(l,r):
    ret = 0
    while l!=r:
        c1 = table[l]
        c2 = table[l+d]
        ret += abs(c1[0]-c2[0])+abs(c1[1]-c2[1])
        l += d
    return ret

q = int(input())
for _ in range(q):
    line = input().split(" ")
    l = int(line[0])
    r = int(line[1])
    print(calc(l,r))


### FIXED CODE ###

# coding=utf-8
line = input().split(" ")
h = int(line[0])
w = int(line[1])
d = int(line[2])

table = [0 for _ in range(h*w+1)]
for hi in range(h):
    line = list(map(int, input().split(" ")))

    for wi in range(w):
        table[line[wi]] = (hi+1, wi+1)

def calc(l,r):
    ret = 0
    if l!=r:
        c1 = table[l]
        c2 = table[r]
        ret += abs(c1[0]-c2[0])+abs(c1[1]-c2[1])
    return ret

acc = [0 for _ in range(h*w+1)]
for dd in range(1,d+1):
    s = dd+d
    while s<=h*w:
        acc[s] = calc(s-d,s)+acc[s-d]
        s += d

q = int(input())
for _ in range(q):
    line = input().split(" ")
    l = int(line[0])
    r = int(line[1])

    ret = acc[r] - acc[l]
    print(ret)
### BUGGY CODE ###

buf = input().split()
N = int(buf[0])
M = int(buf[1])
Q = int(buf[2])
import numpy as np
train = np.zeros((N+1, N+1))
for i in range(M):
	buf = input().split()
	L = int(buf[0])
	R = int(buf[1])
	for j in range(L, N+1):
		for k in range(R, N+1):
			train[j][k] += 1
#print(train)
for i in range(Q):
	buf = input().split()
	p = int(buf[0])
	q = int(buf[1])
	r = train[q][q] - train[p-1][q] -train[q][p-1] + train[p-1][p-1]
	print(int(r))

### FIXED CODE ###

import numpy as np
N, M, Q = map(int, input().split())

train = np.zeros((N, N))
for i in range(M):
	L, R = map(int, input().split())
	train[N-L][R-1] += 1
train = np.cumsum(np.cumsum(train, axis=0), axis=1)

for _ in range(Q):
	p, q = map(int, input().split())
	print(int(train[N-p][q-1]))
### BUGGY CODE ###

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

P = 1

for i in range(N):
    P = P * A[i]
 
if P <= 1e18:
    print(P)
else:
    print(-1)

### FIXED CODE ###

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

P = 1
flag = 0

for i in range(N):
    P = P * newA[i]
    if P == 0:
        print(P)
        flag = 1
        break
    elif P > 1e18:
        print(-1)
        flag = 1
        break
        
if flag == 0:
    print(P)
### BUGGY CODE ###

n,m = map(int,input().split())
alis = list(map(int,input().split()))
lis = [list(map(int,input().split())) for x in range(m)]
clis = [[x[1]]*x[0] for x in lis]
clis = [x for y in clis for x in y]
clis.sort(reverse=True)
alis.sort()
ans_lis=[x if x>=y else y for x,y in zip(alis,clis)]
if len(clis) < len(alis):
    ans__ = sum(alis[len(clis):])
    ans_=sum(ans_lis)
    print(ans_+ans__)
else:
    print(sum(ans_lis))


### FIXED CODE ###

n,m = map(int,input().split())
alis = list(map(int,input().split()))
lis = [list(map(int,input().split())) for x in range(m)]
for x in alis:
    lis.append([1,x])
lis.sort(reverse=True,key=lambda x:x[1])
ans = 0
for x in lis:
    (number,point) = x
    if number >= n:
        number = n
        ans += number * point
        #print(n)
        #print(ans,'+=',number,'*',point)
        break
    ans += number * point
    n -= number
    #print(n)
    #print(ans,'+=',number,'*',point)
print(ans)
#print(lis)
### BUGGY CODE ###

from fractions import gcd
def lcm(a, b):
    return a * b // gcd(a, b)

n = int(input())
a = list(map(int,input().split()))
mod = 10 ** 9 + 7

LCM = 1
for i in range(n):
    LCM = lcm(LCM, a[i])

ans = 0
for i in range(n):
    ans = (ans + LCM // a[i]) % mod
print(ans)

### FIXED CODE ###

#E
n=int(input())
a=tuple(map(int,input().split()))
import fractions
lcm=a[0]
b_sum=0
for i in range(1,n):
    lcm=lcm*a[i]//fractions.gcd(lcm,a[i])

num=10**9+7
for i in range(n):
    b_sum+=(lcm//a[i])

print(b_sum%num)
### BUGGY CODE ###

N = int(input())

T = 0
A = 0
for _ in range(N):
  count = 1
  next_T, next_A = [int(i) for i in input().split()]
  if next_T > T and next_A > A:
    T = int(next_T)
    A = int(next_A)
  else: 
    while next_T < T or next_A < A:
      next_T /= count-1 if count > 1 else 1
      next_A /= count-1 if count > 1 else 1
      next_T *= count 
      next_A *= count
      count += 1
    T = int(next_T)
    A = int(next_A)
print(int(sum([T, A])))

### FIXED CODE ###

import math
import sys
from decimal import Decimal


N = int(sys.stdin.readline())
TA = []
for i in range(N):
    TA.append(list(map(int, sys.stdin.readline().split())))

current_T = 1
current_A = 1
for i in range(N):
    count = max(math.ceil(Decimal(current_T)/Decimal(TA[i][0])), math.ceil(Decimal(current_A)/Decimal(TA[i][1])))
    current_T = TA[i][0] * count
    current_A = TA[i][1] * count

print(current_T + current_A)
### BUGGY CODE ###

""" AtCoder """

N, Q = map(int, input().split())
S = input()
lr = [list(map(int, input().split())) for _ in range(Q)]

for i in range(Q):
    print(S[lr[i][0] -1:lr[i][1]].count("AC"))



### FIXED CODE ###

""" AtCoder """

N, Q = map(int, input().split())
S = input()
lr = [list(map(int, input().split())) for _ in range(Q)]

tmp = 0
l = [0]

for i in range(1, N):
    if S[i - 1] + S[i] == "AC":
        tmp += 1
    l.append(tmp)

for i in range(Q):
    print(l[lr[i][1]-1] - l[lr[i][0]-1])
### BUGGY CODE ###

import sys

h, n = list(map(int, input().split()))
INF = 10 ** 18
dp = [INF] * (20201)
dp[0] = 0
for line in sys.stdin:
    a, b = map(int, line.split())
    for i in range(10000):
        if dp[i] == INF:
            continue
        dp[i + a] = min(dp[i + a], dp[i] + b)
print(min(dp[h:]))


### FIXED CODE ###

import sys

h, n = list(map(int, input().split()))
INF = 10 ** 18
dp = [INF] * (20201)
dp[0] = 0
for line in sys.stdin:
    a, b = map(int, line.split())
    for i in range(10000):
        if dp[i] == INF:
            continue
        dp[i + a] = min(dp[i + a], dp[i] + b)
print(min(dp[h:]))
### BUGGY CODE ###

from operator import mul
from functools import reduce
N = int(input())
s =list(map(int, input().split()))
ans = reduce(mul,s)
if ans > 10**18:
	print(-1)
else:
	print(ans)

### FIXED CODE ###

def main():
    n = int(input())
    a = list(map(int,input().split()))
    if 0 in a: 
        print(0)
        return
    ans = 1
    for ai in a:
        ans *= ai
        if ans > 10**18:
            print(-1)
            return
    print(ans)
    
if __name__ =="__main__":
    main()
### BUGGY CODE ###

from decimal import Decimal, getcontext
getcontext().prec = 100000
a, b, c = map(Decimal, input().split())
print("Yes" if a**Decimal(0.5)+b**Decimal(0.5) < c**Decimal(0.5) else "No")


### FIXED CODE ###

from decimal import Decimal, getcontext
getcontext().prec = 1000
a, b, c = map(Decimal, input().split())
print("Yes" if a+b+Decimal(2)*((a*b)**Decimal(0.5)) < c else "No")
### BUGGY CODE ###

import sys
input = sys.stdin.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))

C = []
extend = A.extend
for _ in range(m):
    b, c = map(int, input().split())
    extend([c]*b)

A.sort(reverse=True)
print(sum(A[:n]))

### FIXED CODE ###

import sys

input = sys.stdin.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: -x[1])

maxi = n*2
extend = A.extend
[extend([ls[1]] * ls[0]) for ls in BC if len(A) <= maxi]
A.sort(reverse=True)

print(sum(A[:n]))
### BUGGY CODE ###

from fractions import gcd
n, m = map(int, input().split())
s = input()
t = input()
lcm_nm = int(n * m / gcd(n, m))
for i in range(lcm_nm):
  if(not(i % (lcm_nm/n) == 0 and i % (lcm_nm/m) == 0)):
    continue
  if(s[int(i / (lcm_nm/n))] != t[int(i / (lcm_nm/m))]):
    ans = -1
    break
else:
  ans = lcm_nm
print(ans)

### FIXED CODE ###

from fractions import gcd
n, m = map(int, input().split())
s = input()
t = input()
g = gcd(n, m)
for i in range(g):
    if s[n // g * i] != t[m // g * i]:
        print(-1)
        break
else:
    print(n * m // g)
### BUGGY CODE ###

S=input()
MOD=10**9+7
dp=[0]*13
dp[0]=1
for i in range(len(S)):
    new_dp=[0]*13
    s=S[-1-i]
    if s=="?":
        for j in range(10):
            for k in range(13):
                new_dp[(k+j*10**i)%13]+=dp[k]
    else:
        for k in range(13):
            new_dp[(k+int(s)*10**i)%13]+=dp[k]
    dp=new_dp
print(dp[5]%MOD)

### FIXED CODE ###

S=input()
MOD=10**9+7
dp=[0]*13
dp[0]=1
r=1
for i in range(len(S)):
    new_dp=[0]*13
    s=S[-1-i]
    if s=="?":
        for j in range(10):
            rem=(j*r)%13
            for k in range(13):
                new_dp[(k+rem)%13]+=dp[k]
    else:
        rem=(int(s)*r)%13
        for k in range(13):
            new_dp[(k+rem)%13]+=dp[k]
    for l in range(13):
        new_dp[l]%=MOD
    dp=new_dp
    r=(r*10)%13
print(dp[5])
### BUGGY CODE ###

import collections
def main():

    H, W, N = map(int, input().split())
    checked = collections.defaultdict(set)
    black = collections.defaultdict(set)
    refs = []
    for _ in range(N):
        a, b = map(int, input().split())
        black[a].add(b)
        refs.append([a, b])

    ans = [0 for _ in range(10)]
    for a, b in refs:
        for da in [-1, 0, 1]:
            for db in [-1, 0, 1]:
                c, d = a+da, b+db
                if d not in checked[c]:
                    checked[c].add(d)
                    if all(1<=c+dc<=H and 1<=d+dd<=W for dc in [-1,0,1] for dd in[-1, 0, 1]):
                        count = 0
                        for dc in [-1, 0, 1]:
                            for dd in [-1, 0, 1]:
                                if d+dd in black[c+dc]:
                                    count += 1
                        ans[count] += 1
    ans[0] = (H-2)*(W-2) - sum(ans[1:]) 
    for i in range(10):
        print(ans[i])

if __name__ == '__main__':
    main()

### FIXED CODE ###

import collections
def main():

    H, W, N = map(int, input().split())
    checked = collections.defaultdict(set)
    black = collections.defaultdict(set)
    refs = []
    for _ in range(N):
        a, b = map(int, input().split())
        black[a].add(b)
        refs.append([a, b])

    ans = [0 for _ in range(10)]
    for a, b in refs:
        for da in [-1, 0, 1]:
            for db in [-1, 0, 1]:
                c, d = a+da, b+db
                if d not in checked[c]:
                    checked[c].add(d)
                    if all(1<=c+dc<=H and 1<=d+dd<=W for dc in [-1,0,1] for dd in[-1, 0, 1]):
                        count = 0
                        for dc in [-1, 0, 1]:
                            for dd in [-1, 0, 1]:
                                if d+dd in black[c+dc]:
                                    count += 1
                        ans[count] += 1
    ans[0] = (H-2)*(W-2) - sum(ans[1:]) 
    for i in range(10):
        print(ans[i])

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

#input
N, P = map(int, input().split())
S = list(map(int, list(input())))

# process
ans = 0
for i in range(N-1):
    mod = S[i]%P
    if mod == 0:
        ans += 1
    pmod = mod

    for j in range(i+1, N):
        mod = (S[j]+pmod*10)%P
        if mod == 0:
            ans += 1
        pmod = mod

if S[-1]%P == 0:
    ans += 1

# output
print(ans)

### FIXED CODE ###

#input
N, P = map(int, input().split())
S = input()

# process
ans = 0
if P == 2 or P == 5:
    # 1桁目がPで割り切れる数をカウント
    for i in range(N):
        if int(S[i]) % P == 0:
            ans += i+1

else:
    cnt = [0]*P # S[i:N]%Pの結果をカウント
    num = 0
    tenPow = 1
    for i in reversed(range(N)):
        num = (num + int(S[i])*tenPow)%P
        tenPow = tenPow*10%P
        cnt[num] += 1

    ans += cnt[0]
    for c in cnt:
        ans += c*(c-1)//2 # c=0,1のときは0加算

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

n, m = map(int,input().split())
 
l = [""] * m
ans2 = [1,n]

for i in range(m):
    s,t = map(int,input().split())
    try:
        ans2 = [j for j in range(min(ans2),max(ans2)+1) if s <= j <= t]
    except:
        break


print(len(ans2))


### FIXED CODE ###

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

left_max = -1
right_min = n+1

for i in range(m):
    s,t = map(int,input().split())
    left_max = max(left_max,s)
    right_min = min(right_min, t)
    
print(max(0, right_min - left_max +1))