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

import itertools


def main():
    N = int(input())
    S = input()

    ans = 0
    for ix_i, i in enumerate(S):
        for j in range(ix_i+1, N):
            if i == S[j]:
                continue
            for k in range(j+1, N):
                if (S[j] == S[k]) or (i == S[k]):
                    continue
                if (j-ix_i) == (k-j):
                    continue

                ans += 1

    print(ans)
    return 0

if __name__ == '__main__':
    main()

### FIXED CODE ###

import math
import collections

def main():
    N = int(input())
    S = input()

    c = collections.Counter(S)
    c = c['R'] * c['G'] * c['B']

    count = 0
    for i in range(N):
        for j in range(i+1, N):
            k = 2*j-i
            if k < N:
                if (S[i] != S[j]) and (S[j] != S[k]) and (S[i] != S[k]):
                    count += 1

    print(c - count)

    return 0

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

N = int(input())

divs = []
for i in range(1,N):
  if N % i == 0:
    if i < N//i -1:
      divs.append(N//i-1)
    else:
      break
print(sum(divs))


### FIXED CODE ###

N = int(input())

divs = []
for i in range(1,int(N**0.5)+2):
  if N % i == 0:
    if i < N//i -1:
      divs.append(N//i-1)
    else:
      break
print(sum(divs))
### BUGGY CODE ###

a, b = map(int, input().split())
for i in range(max(a, b), a*b+1):
  if not i % a and not i % b:
    print(i)
    quit()

### FIXED CODE ###

from fractions import gcd
a, b = map(int, input().split())
print(a*b // gcd(a, b))
### BUGGY CODE ###


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


ans = 1

for i in range(2,int(p**(1./n))+1):
	if(p < i**n):break
	while(p%(i**n)==0):
		ans*=i
		p//=i**n
print(ans)



### FIXED CODE ###

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


ans = 1
if(n==1):print(p)
else:

	for i in range(2,int(p**(1./n))+1):
		while(p%(i**n)==0):
			ans*=i
			p//=i**n
	print(ans)
### BUGGY CODE ###

#substring列挙したらTLE(部分点)
s = input()
k = int(input())
s_set_sort = sorted(set(s))

li = []
count = 0
while count < k:
    s_head = s_set_sort.pop(0)
    for i in range(len(s)):
        if s[i] == s_head:
            count2 = 0
            for j in range(len(s)-i):
                if s[i:i+j+1] not in li:
                    count += 1
                    count2 += 1
                    li.append(s[i:i+j+1])
                    if count2 >= k:
                        break
li.sort()
print(li[k-1])

### FIXED CODE ###

#substring列挙したらTLE(部分点)
s = input()
k = int(input())
s_set_sort = sorted(set(s))

li = []
count = 0
while count < k:
    s_head = s_set_sort.pop(0)
    for i in range(len(s)):
        if s[i] == s_head:
            for j in range(k):
                if s[i:i+j+1] not in li:
                    count += 1
                    li.append(s[i:i+j+1])
li.sort()
print(li[k-1])
### BUGGY CODE ###

from operator import itemgetter
import numpy as np

N, T = [int(i) for i in input().split()]

data = []
for i in range(N):
    data.append([int(i) for i in input().split()])

data.sort(key=itemgetter(0))

#dp = [[0] * (T+1) for i in range(N)]
dp = np.zeros((N, T+1), int)

dp[0][T] = data[0][1]
for i in range(1, N):
    time = data[i-1][0]
    value = data[i-1][1]
    add_value = data[i][1]
    for j in range(T):
        if j >= time:
            dp[i][j] = max(dp[i-1][j], dp[i-1][j-time] + value)
        else:
            dp[i][j] = dp[i-1][j]
    dp[i][T] = dp[i][T-1] + add_value

ans = np.max(np.array([row[-1] for row in dp[:]]))
print(ans)


### FIXED CODE ###

from operator import itemgetter
N, T = [int(i) for i in input().split()]

data = []
for i in range(N):
    data.append([int(i) for i in input().split()])

data.sort(key=itemgetter(0))

dp = [[0]*(T) for i in range(N)]
ans = data[0][1]
for i in range(1, N):
    for j in range(T):
        if j >= data[i-1][0]:
            value1 = dp[i-1][j]
            value2 = dp[i-1][j-data[i-1][0]] + data[i-1][1]
            dp[i][j] = max(value1, value2)
        else:
            dp[i][j] = dp[i-1][j]
    value3 = dp[i][T-1] + data[i][1]
    ans = max(value3, ans)
print(ans)
### BUGGY CODE ###

n, k = map(int, input().split())
mod = 998244353
lr = []
s = set()
for i in range(k):
  l,r = map(int, input().split())
  for j in range(l,r+1):
    s.add(j)

dp = [0 for i in range(n+1)]
dp[1] = 1
for i in range(1,n+1):
  for j in s:
    if i-j < 1:
      continue
    dp[i] += dp[i-j]
    dp[i] %= mod
# print (dp)
print (dp[n])

### FIXED CODE ###

n, k = map(int, input().split())
mod = 998244353
lr = []
s = set()
for i in range(k):
  l,r = map(int, input().split())
  for j in range(l,r+1):
    s.add(j)
  lr.append([l,r])

dp = [0 for i in range(n+1)]
dp[1] = 1
tot = [0 for i in range(k)]

for i in range(1,n+1):
  for j in range(k):
    l,r = lr[j][0],lr[j][1]
    if i-l < 1:
      continue
    tot[j] += dp[i-l]
    if i-r > 1:
      tot[j] -= dp[i-r-1]
    dp[i] += tot[j]
    dp[i] %= mod
print (dp[n])
### BUGGY CODE ###

n = int(input())
ans = 10**12
def factorization(n): #素因数分解
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

q = factorization(n)
ans_list = []
for i in range(len(q)):#分解してリストに一つずつ格納
    for j in range(q[i][1]):
        ans_list.append(q[i][0])

if len(ans_list) == 1:
    print(ans_list[0]-1)
    exit()
        
ans_list = sorted(ans_list,reverse = True)#最小となるようにソートして掛けていく
p = 1
for i in ans_list:
    p *= i
s = len(ans_list)
for i in range(2 ** s):
    bag = []
    for j in range(s):  # このループが一番のポイント
        if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
            bag.append(ans_list[j]) 
    a = 1
    for t in bag:
        a *= t
    b = p/a
    
    ans = min(ans,a+b-2)
    
print(int(ans))




### FIXED CODE ###

N=int(input())
a=1
for i in range(1,int(N**(1/2))+2):
    if N%i==0:
        a=max(a,i)
print(a+N//a-2)
### BUGGY CODE ###

n = int(input())
l = []
for i in range(n):
    a = int(input())
    if a not in l:
        l.append(a)
    else:
        l.remove(a)
print(len(l))

### FIXED CODE ###

n = int(input())
a1 = [int(input()) for i in range(n)]
from collections import Counter
a = Counter(a1).most_common()
num = 0
for i in range(len(a)):
    if a[i][1]%2 == 1:
        num += 1
print(num)
### BUGGY CODE ###

import collections
N = int(input())
S = [input() for n in range(N)]

cnt = collections.Counter(S)
ans = sorted([k for k, v in cnt.items() if v == cnt.most_common()[0][1]])

for a in ans:
    print(a)

### FIXED CODE ###

import collections
N = int(input())
S = [input() for n in range(N)]

cnt = collections.Counter(S)
m = max(cnt.values())

ans = []
for k, v in cnt.items():
    if v == m:
        ans.append(k)
        
ans.sort()
for a in ans:
    print(a)
### BUGGY CODE ###

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

c=1
path=[]
while len(path)<=k:
    if c in path:
        p=path.index(c)
        pattern_l = len(path)-p
        k-=((k-p)//pattern_l)*pattern_l
    path.append(c)
    c=A[c-1]
print(path[k])


### FIXED CODE ###

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

c=1
path=[]
d={}
l=0
while l<=k:
    if c in d:
        p=d[c]
        #print(p, path)
        pattern_l = l-p
        k-=((k-p)//pattern_l)*pattern_l
    path.append(c)
    l+=1
    d[c]=l-1
    c=A[c-1]
print(path[k])
### BUGGY CODE ###

n=int(input())
p=list( int(s[2:]) for s in input().split() )
z=0
res=[100-p[0], p[0]]+[0]*(n//2 - 1)
for i in range(1,n):
    z=z+1
    for j in range(len(res)-1, 0, -1):
        res[j]=(res[j]*(100-p[i]) + (res[j-1]*p[i]) )
    res[0]=res[0]*(100-p[i])
    if z==10:
        for x in res: x=x//100**5
        z=5
print( 1-(sum(res[:1+n//2])/(100**(z+1)) ) )

### FIXED CODE ###

n=int(input())
p=list( float(s) for s in input().split() )
 
res=[1-p[0], p[0]]+[0]*(n//2 - 1)
for i in range(1,n):
    for j in range(len(res)-1, 0, -1):
        res[j]=(res[j]*(1-p[i]) + (res[j-1]*p[i]) )
    res[0]=res[0]*(1-p[i])
print( (1-sum(res[:1+n//2])) )
### BUGGY CODE ###

n,k=map(int,input().split())
P=list(map(int,input().split()))
K=[]

DP=[float("inf")]*1001
for i in P:
    if DP[i]==float("inf"):
        DP[i]=(i*(i+1)//2)/i
    K.append(DP[i])

ans=0
for i in range(n-k+1):
    ans=max(ans,sum(K[i:i+k]))
print(ans)

### FIXED CODE ###

n,k=map(int,input().split())
P=list(map(int,input().split()))
K=[]

DP=[0]*1001
for i in P:
    if DP[i]==0:
        DP[i]=(i*(i+1)//2)/i
    K.append(DP[i])

K.append(0)
ans=sum(K[:k])
score=sum(K[:k])
for i in range(n-k+1):
    score -=K[i]
    score +=K[i+k]
    ans=max(ans,score)
print(ans)
### BUGGY CODE ###

#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n,m,que=MI()
lis=[[0]*n for i in range(n)]
for i in range(m):
    l,r=MI()
    lis[l-1][r-1]+=1
for i in range(n):
    lis[i]=list(accumulate(lis[i]))
#print(lis)
for i in range(que):
    p,q=MI()
    ans=0
    for i in range(p,q+1):
        if i==1:
            ans+=lis[i-1][q-1]
        else:
            ans+=lis[i-1][q-1]-lis[i-1][i-2]
    print(ans)

### FIXED CODE ###

#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n,m,que=MI()
lis=[[0]*n for i in range(n)]
for i in range(m):
    l,r=MI()
    lis[l-1][r-1]+=1
for i in range(n):
    lis[i]=list(accumulate(lis[i]))
#print(lis)
for i in range(que):
    p,q=MI()
    ans=0
    for i in range(p,q+1):
        if i==1:
            ans+=lis[i-1][q-1]
        else:
            ans+=lis[i-1][q-1]-lis[i-1][i-2]
    print(ans)
### BUGGY CODE ###

k = int(input())
runrun_counter = 0
no_runrun = False
ans = 0
for i in range(1,10**8):
    if i < 10:
        ans = i
        runrun_counter += 1
    else:
        num = [int(s) for s in list(str(i))]
        for n in range(len(num)-1):
            if abs(num[n]-num[n+1]) > 1:
                no_runrun = True
                break
        if not no_runrun:
            runrun_counter += 1
            ans = int(''.join(map(str, num)))
        no_runrun = False
    if runrun_counter == k:
        print(ans)
        exit()

### FIXED CODE ###

import queue

k = int(input())
q = queue.Queue()
x = -1
for i in range(1,10):
    q.put(i)
for i in range(1,k+1):
    x = q.get()
    if x % 10 != 0:
        q.put(10 * x + (x % 10) - 1)
    q.put(10 * x + (x % 10))
    if x % 10 != 9:
        q.put(10 * x + (x % 10) + 1)
print(x)
### BUGGY CODE ###

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

a = []
for i in range(L,R + 1):
  for j in range(i + 1,R + 1):
    a.append(i * j % 2019)

print(min(a))

### FIXED CODE ###

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

a = 100000000000
for i in range(L,R + 1):
  if a == 0:
    break
  for j in range(i + 1,R + 1):
    if a >= i * j % 2019:
      a = i * j % 2019
      if a == 0:
        break
  

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

N = int(input())
ans = 0
for i in range(1, N + 1):
    n = N // i  # 項数n
    cnt = (n * (2 * i + (n - 1) * i)) // 2  # 初項i, 項数n の等差数列の和の公式
    ans += cnt
print(ans)

### FIXED CODE ###

N = int(input())
ans = 0
for i in range(1, N + 1):
    n = N // i  # 項数n
    cnt = (n * (2 * i + (n - 1) * i)) // 2  # 初項i, 項数n の等差数列の和の公式
    ans += cnt
print(ans)
### BUGGY CODE ###

n=int(input())
s=[]
t=[]
for i in range(n):
    a,b=map(int,input().split())
    s.append([a,b,i])
    t.append([b,a,i])
s.sort()
t.sort()
r=0
q=0
p=[]
for i in range(n):
    if i%2!=1:
        while s[-1][2] in p:
            s.pop(-1)
        else:
            r+=s[-1][0]
            p.append(s[-1][2])
    else:
        while t[-1][2] in p:
            t.pop(-1)
        else:
            q+=t[-1][0]
            p.append(t[-1][2])
print(r-q)

### FIXED CODE ###

n=int(input())
s=[list(map(int,input().split()))for i in range(n)]
print(sum(sorted([x[1]+x[0] for x in s])[::-2])-sum([x[1]for x in s]))
### BUGGY CODE ###

# E - Crested Ibis vs Monster
from collections import defaultdict


def main():
    H, N, *AB = map(int, open(0).read().split())
    dp = defaultdict(lambda: 1 << 30)  # dp[i] := min magic points to decrease monster's health by i
    dp[0] = 0
    for a, b in zip(*[iter(AB)] * 2):
        for i in range(H):
            if i not in dp:
                continue
            if i + a < H:
                dp[i + a] = min(dp[i + a], dp[i] + b)
            else:
                dp[H] = min(dp[H], dp[i] + b)
    print(dp[H])


if __name__ == "__main__":
    main()


### FIXED CODE ###

# E - Crested Ibis vs Monster
from collections import defaultdict


def main():
    H, N, *AB = map(int, open(0).read().split())
    dp = defaultdict(lambda: 1 << 30)  # dp[i] := min magic points to decrease monster's health by i
    dp[0] = 0
    for a, b in zip(*[iter(AB)] * 2):
        for i in range(H):
            if i not in dp:
                continue
            dp[i + a] = min(dp[i + a], dp[i] + b)
    ans = min(magic for health, magic in dp.items() if health >= H)
    print(ans)


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

#####

import numpy as np
from numpy import newaxis, float32, float64, int32, int64, int16, int8, uint8, uint32, complex64, complex128

#####

def getIntList(inp):
	return [int(_) for _ in inp]


from sys import stdin
import sys

def getInputs():
	inputs=[]
	for line in stdin:
		line=line.split()
		inputs.append(line)
	return inputs


def main(inputs):
	n,p=getIntList(inputs[0])
	s=inputs[1][0]
	
	ans=0
	if p%2==0 or p%5==0:
		for i0 in range(len(s)-1,-1,-1):
			sub=int(s[i0:i0+1])
			if sub%p==0:
				ans+=i0+1
	else:
		numP0=np.zeros(p, int32)
		numP0[0]=1
		for i0 in range(len(s)-1,-1,-1):
			sub=s[i0:]
			sub=int(sub)
			sub%=p
			ans+=numP0[sub]
			numP0[sub]+=1
# 			print(s[i0:], sub, numP0, ans)
	print(ans)
		

if __name__=="__main__":
	inputs=getInputs()
# 	inputs=simInputs()
	main(inputs)

### FIXED CODE ###


#####

import numpy as np
from numpy import newaxis, float32, float64, int32, int64, int16, int8, uint8, uint32, complex64, complex128

#####

def getIntList(inp):
	return [int(_) for _ in inp]


from sys import stdin
import sys

def getInputs():
	inputs=[]
	for line in stdin:
		line=line.split()
		inputs.append(line)
	return inputs



def main(inputs):
	n,p=getIntList(inputs[0])
	s=inputs[1][0]
	
	ans=0
	if p%2==0 or p%5==0:
		for i0 in range(len(s)-1,-1,-1):
			sub=int(s[i0:i0+1])
			if sub%p==0:
				ans+=i0+1
	else:
		numP0=np.zeros(p, int32)
		numP0[0]=1
		r=0
		modD=int(1%p)
		for i0 in range(len(s)-1,-1,-1):
			
			sub=s[i0:i0+1]
			sub=int(sub)
			sub=r+sub*modD
			r=sub%p
			ans+=numP0[r]
			numP0[r]+=1
			modD=int((modD*10)%p)
	print(ans)
		
	

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

import heapq

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

from operator import mul
from functools import reduce

def cmb(n, r):
    r = min(n - r, r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under

heapq.heapify(A)

cmb_list = {}
cmb_list[(K - 1, K - 1)] = cmb(K - 1, K - 1)
for i in range(K, N):
    cmb_list[(i, K-1)] = cmb_list[(i-1, K-1)] * i // (i - (K - 1))
# print(cmb_list)

# print(A)

max_f = 0
min_f = 0


for idx in range(N):
    a = heapq.heappop(A)
    if idx >= K-1:
        max_f += cmb_list[(idx, K-1)]*a
        # print("max", cmb(idx, K-1), idx, K-1, a)

    if N-(idx+1) >= K - 1:
        min_f += cmb_list[(N-(idx+1), K-1)]*a
        # print("min", cmb(N-(idx+1), K-1), N-(idx+1), K-1, a)

print((max_f - min_f) % (10**9+7))

### FIXED CODE ###

import heapq

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

from operator import mul
from functools import reduce

MOD = 10 ** 9 + 7

def mpow(a, n):
    if n == 0: return 1
    if n == 1: return a % MOD
    if n % 2 == 1: return (a % MOD * mpow(a, n - 1) % MOD) % MOD
    t = mpow(a, n // 2)
    return (t * t) % MOD

fac = [1] * (n + 1)
inv_fac = [1] * (n + 1)
for i in range(n):
    fac[i + 1] = (fac[i] * (i + 1)) % MOD
inv_fac[n] = mpow(fac[n], MOD - 2)
for i in range(n, 0, -1):
    inv_fac[i - 1] = (inv_fac[i] * i) % MOD

def cmb(n, r):
    if n == 0 and r == 0: return 1
    if n < r or n < 0: return 0
    return (fac[n] * (inv_fac[r] * inv_fac[n - r]) % MOD) % MOD

A.sort()

# cmb_list = {}
# cmb_list[(K - 1, K - 1)] = cmb(K - 1, K - 1)
# for i in range(K, n):
#     cmb_list[(i, K-1)] = cmb_list[(i-1, K-1)] * i // (i - (K - 1))

max_f = 0
min_f = 0

for idx in range(n):
    a = heapq.heappop(A)
    if idx >= K - 1:
        max_f += cmb(idx, K - 1) * a
        # print("max", cmb(idx, K-1), idx, K-1, a)

    if n - (idx + 1) >= K - 1:
        min_f += cmb(n - (idx + 1), K - 1) * a
        # print("min", cmb(N-(idx+1), K-1), N-(idx+1), K-1, a)

print((max_f - min_f) % (10**9+7))
### BUGGY CODE ###

n, p = map(int, input().split())
s = input()
ans = 0
x0 = [0]*p
y = [0]*(10*p)
for i in range(10*p):
  y[i] = i%p
for t in s:
  x1 = [0]*p
  z = int(t)
  x1[z%p] = 1
  for j in range(p):
    x1[y[10*j+z]] += x0[j]
  x0 = x1
  ans += x0[0]
print(ans)

### FIXED CODE ###

n, p = map(int, input().split())
s = input()
x = [1] + [0]*(p-1)
ans = 0
u = 0
if p in [2,5]:
  for i in range(n):
    if int(s[i])%p==0:
      ans += i+1
else:
  for i in range(n-1,-1,-1):
    u = (int(s[i])*pow(10,n-1-i,p)+u)%p
    ans += x[u]
    x[u] += 1
print(ans)
### BUGGY CODE ###

A,B,N=list(map(int,input().split()))
list_ans=[]
minimum=min(N-20,0)
for i in range(minimum,N+1):
  list_ans.append(int(A*i/B)-A*int(i/B))
print(int(max(list_ans)))

### FIXED CODE ###

A,B,N=list(map(int,input().split()))
list_ans=[]
minimum=min(B-1,N)
print(int(A*minimum/B)-A*int(minimum/B))
### BUGGY CODE ###

cnt = 0
R, G, B, N = map(int, input().split())

for r in range((N//R)+2):
    for g in range(min((N//G)+2, (N-r*R)//G+1)):
        m = N - r*R - g*G
        if m == 0 or (m % B == 0 and m >= B):
            cnt += 1

print(cnt)

### FIXED CODE ###

cnt = 0
R, G, B, N = map(int, input().split())
comb = []
tmp = []
rgb = [R, G, B]

for r in range((N//R)+2):
    for g in range((N//G)+2):
        m = N - r*R - g*G
        if m == 0 or (m % B == 0 and m >= B):
            cnt += 1

print(cnt)
### BUGGY CODE ###

n,k = list(map(int,input().split()))
h = list(map(int,input().split()))
dp=[0]+[float("inf") for i in range(n+k)]
for i in range(n-1):
    for j in range(k):
        if j+i+1>n-1:break
        dp[j+i+1]=min(dp[j+i+1],dp[i]+abs(h[j+i+1]-h[i]))
print(dp[n-1])

### FIXED CODE ###

n,k = list(map(int,input().split()))
h = list(map(int,input().split()))
dp=[0]+[float("inf") for i in range(n+k)]
for i in range(n-1):
    for j in range(k):
        if j+i+1>n-1:break
        dp[j+i+1]=min(dp[j+i+1],dp[i]+abs(h[j+i+1]-h[i]))
print(dp[n-1])
### BUGGY CODE ###

H,W,M = map(int,input().split())
lsx = [0] + [0]*H
lsy = [0] + [0]*W
lsxy = []
for i in range(M):
    x,y = map(int,input().split())
    lsx[x] += 1
    lsy[y] += 1
    lsxy.append([x,y])
maxx = max(lsx)
maxy = max(lsy)
lsmaxx = [i for i, x in enumerate(lsx) if x == maxx]
lsmaxy = [i for i, x in enumerate(lsy) if x == maxy]
lenlen = len(lsmaxx)*len(lsmaxy)
factor = 1
for i in lsmaxx:
    for j in lsmaxy:
        if not [i,j] in lsxy:
            factor = 0
            break
    if factor == 0:
        break
print(maxx+maxy-factor)


### FIXED CODE ###

H,W,M = map(int,input().split())
lsx = [0] + [0]*H
lsy = [0] + [0]*W
lsxy = []
for i in range(M):
    x,y = map(int,input().split())
    lsx[x] += 1
    lsy[y] += 1
    lsxy.append([x,y])
maxx = max(lsx)
maxy = max(lsy)
cx = lsx.count(maxx)
cy = lsy.count(maxy)
al = cx*cy
for i in range(M):
    if lsx[lsxy[i][0]] == maxx and lsy[lsxy[i][1]] == maxy:
        al -= 1
if al == 0:
    factor = 1
else:
    factor = 0        
print(maxx+maxy-factor)
### BUGGY CODE ###

def main():
    S = input()
    l = []
    l2 = []
    mod = (10 ** 9) + 7
    for i in range(6):
        d = {j:0 for j in range(13)}
        d2 = {j:0 for j in range(10)}
        for j in range(0, 10):
            t = (j *(10 ** i)) % 13
            d[t] += 1
            d2[j] = t
        l.append(d)
        l2.append(d2)
    r = 0
    c = {j:0 for j in range(13)}
    c[0] = 1
    n = {j:0 for j in range(13)}
    for i, v in enumerate(reversed(S)):
        if v == '?':
            for j in range(13):
                for k in range(13):
                    n[(j + k) % 13] += c[k] * l[i % 6][j]
            c = n
            n = {j:0 for j in range(13)}
        else:
            r += (l2[i % 6][int(v)]) % 13
    r = (5 - r) % 13
    print(c[r] % mod)
main()



### FIXED CODE ###

def main():
    S = input()
    l = []
    l2 = []
    mod = (10 ** 9) + 7
    for i in range(6):
        d = [0] * 13
        d2 = [0] * 10
        for j in range(0, 10):
            t = (j *(10 ** i)) % 13
            d[t] += 1
            d2[j] = t
        l.append(d)
        l2.append(d2)
    r = 0
    c = [0] * 13
    c[0] = 1
    n = [0] * 13
    i = 0
    for v in reversed(S):
        if v == '?':
            k = 0
            for j in range(13):
                for k in range(13):
                    if l[i][j]:
                        kk = (j+k) % 13
                        n[kk] += c[k]
                        n[kk] %= mod
            c = n
            n = [0] * 13
        else:
            r += (l2[i][int(v)])
            r %= 13
        i += 1
        i %= 6
    r = (5 - r) % 13
    print(c[r] % mod)
main()