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

S=input()
ans=[0 for i in range(len(S))]

for i in range(len(S)):
  if S[i]=='R':
    counter=0
    while S[i+counter]=='R':
      counter+=1
      
    if counter%2==0:
      ans[i+counter]+=1
    else:
      ans[i+counter-1]+=1
      
  else:
    counter=0
    while S[i-counter]=='L':
      counter+=1
      
    if counter%2==0:
      ans[i-counter]+=1
    else:
      ans[i-counter+1]+=1
      
ans=map(str, ans)
print(' '.join(ans))

### FIXED CODE ###

S=input()
N=len(S)
c=[1]*N
for i in range(N-1):
  if S[i]=='R' and S[i+1]=='R':
    c[i+2]+=c[i]
    c[i]=0
    
for i in range(N-1, 1, -1):
  if S[i]=='L' and S[i-1]=='L':
    c[i-2]+=c[i]
    c[i]=0
    
print(' '.join(map(str, c)))
### BUGGY CODE ###

import re
n=int(input())
s=input()
ans=0
for i in range(1000):
      a='00'+str(i)
      a=a[-3:]
      b=a[0]+r'\d*'+a[1]+r'\d*'+a[2]
      c=re.search(b,s)
      if c!=None:
            ans+=1
print(ans)

### FIXED CODE ###

import re
n=int(input())
s=input()
ans=0
for i in range(1000):
      a='00'+str(i)
      a=a[-3:]
      s0=s
      m=s0.find(a[0])
      if m<0:
            continue
      s0=s0[m+1:]
      m=s0.find(a[1])
      if m<0:
            continue
      s0=s0[m+1:]
      m=s0.find(a[2])
      if m<0:
            continue
      ans+=1
print(ans)
### BUGGY CODE ###

q = int(input())
import math
def is_prime(n):
	if n == 1:
		return False
	
	for k in range(2, int(math.sqrt(n)) + 1):
		if n%k == 0:
			return False
	return True
#判定済み
a = []
#素数
b = []
for i in range(q):
	l, r = map(int, input().split())
	cnt = 0
	for j in range(l, r+1):
		if j%2 == 1:
			if j in a:
				if j in b:
					cnt += 1
				continue
			a.append(j)
			if is_prime(j) and is_prime((j+1)//2):
				b.append(j)
				cnt += 1
	print (cnt)

### FIXED CODE ###

q = int(input())
import math
def is_prime(n):
	if n == 1:
		return False
	
	for k in range(2, int(math.sqrt(n)) + 1):
		if n%k == 0:
			return False
	return True

a = [0 for i in range(10**5+1)]
for i in range(1,10**5+1,2):
	if is_prime(i) and is_prime((i+1)//2):
		a[i] = a[i-1] + 1
		a[i+1] = a[i-1] + 1
	else:
		a[i] = a[i-1]
		a[i+1] = a[i-1]
for i in range(q):
	l, r = map(int, input().split())
	print (a[r]-a[l-1])
### BUGGY CODE ###

def m(n,r):
    d=1
    c=1
    for i in range(r):
        d*=(n-i)
        c*=(i+1)
    return(int(d/c))

n=[int(i) for i in input().split()]
a=sum(n)
if a%3 != 0:print(0)

else:
    b=int(a/3)
    if b==1:
        print(1)
    else:
        c=n[0]-b
        d=n[1]-b
        if c<0 or d<0: print(0)

        else:
            if c==d:
                c=int(b/2)
            d=m(b,min(c,d))
            print(d%(10**9+7))

            

### FIXED CODE ###

def egcd(a, b):
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return (lastx, lasty, a)

# ax ≡ 1 (mod m)

def modinv(a, m):
    (inv, q, gcd_val) = egcd(a, m)
    #print(inv, q, gcd_val)
    return inv % m

def m(n,r):
    d=1
    e=1
    f=1
    for i in range(r):
        d=(n-i)
        e=(i+1)
        d%=(10**9+7)
        f = f*d*modinv(e,(10**9+7))%(10**9+7)
        
    return(f)

n=[int(i) for i in input().split()]
a=sum(n)
if a%3 != 0:print(0)

else:
    b=int(a/3)
    if b==1:
        print(1)
    else:
        c=n[0]-b
        d=n[1]-b
        if c<0 or d<0: print(0)

        else:
            if c==d:
                c=int(b/2)
            d=m(b,min(c,d))
            print(d%(10**9+7))
### BUGGY CODE ###

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

n = int(input())
rev_g = [[] for _ in range(n+1)]
for i in range(n-1):
    a = int(input())
    rev_g[a].append(i+2)

def f(v):
    m = len(rev_g[v])
    if m == 0:
        return 0
    q = []
    for nv in rev_g[v]:
        q.append(f(nv))
    q.sort()
    dp = [0] * (m+1)
    for i in range(m):
        dp[i+1] = max(q[i]+1, dp[i]+1)
    return dp[m]


print(f(1))


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)

n = int(input())
rev_g = [[] for _ in range(n+1)]
for i in range(n-1):
    a = int(input())
    rev_g[a].append(i+2)

def f(v):
    m = len(rev_g[v])
    if m == 0:
        return 0
    q = []
    for nv in rev_g[v]:
        q.append(f(nv))
    q.sort()
    dp = [0] * (m+1)
    for i in range(m):
        dp[i+1] = max(q[i]+1, dp[i]+1)
    return dp[m]


print(f(1))
### BUGGY CODE ###

from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix

def main():

  n,m=map(int,input().split())
  d=[[0 for i in range(n)] for i in range(n)]
  to=[[] for i in range(n)]
  for i in range(m):
    u,v=map(lambda x:int(x)-1,input().split())
    to[u].append(v)
  s,t=map(lambda x:int(x)-1,input().split())

  #print(to)

  # calc d (after 3 times dist)
  for i in range(n):
    first,second,third=[],[],[]
    for j in to[i]:
      first.append(j)
    for j in first:
      for k in to[j]:
        second.append(k)
    for j in second:
      for k in to[j]:
        third.append(k)
        d[i][k]=1

  ans=dijkstra(csr_matrix(d),indices=0).astype(int)
  print(ans[t] if ans[t]>0 else -1)


if __name__=='__main__':
  main()

### FIXED CODE ###

from collections import deque

def main():

  n,m=map(int,input().split())
  INF=10**9
  d=[[INF]*3 for i in range(n)]
  to=[[] for i in range(n)]
  for i in range(m):
    u,v=map(lambda x:int(x)-1,input().split())
    to[u].append(v)
  s,t=map(lambda x:int(x)-1,input().split())

  #print(to)
  # calc d (after 3 times dist)
  d[s][0]=0
  cnt=0
  q=deque([(s,cnt)])
  while q:
    u,c=q.popleft()
    for v in to[u]:
      nc=(c+1)%3
      if d[v][nc]!=INF: continue;
      d[v][nc]=d[u][c]+1
      q.append((v,nc))
      
  #print(d)
  ans=d[t][0]
  print(ans//3 if ans!=INF else -1)

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

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

dp = [0]*N
for i in range(1,N):
    dp[i] = min([dp[i-j]+abs(h[i]-h[i-j]) for j in range(1,min(i,K)+1)])
print(dp[-1])

### FIXED CODE ###

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

dp = [0]*N
for i in range(1,N):
    tmp = 10**10
    for j in range(1,min(i+1,K+1)):
        tmp = min(tmp,dp[i-j]+abs(h[i]-h[i-j]))
    dp[i] = tmp
print(dp[-1])
### BUGGY CODE ###

N=int(input())
A=list(map(int,input().split()))
ans=sum(A)
s=N+1
j=s

if A==sorted(A):
    print(0)
    exit()

for i in range(N//2):
    x=max(A[:s])
    s=A.index(x)
    A[s:j]=[x]*len(A[s:j])
    j=s
    if  A==sorted(A):
        break

print(sum(A)-ans)

### FIXED CODE ###

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

for i in range(1,N):
    if A[i-1] > A[i]:
        A[i]=A[i-1]

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

N, M = map(int, input().split())
A = list(map(int, input().split()))
b = []
for i in range(M):
    b.append(list(map(int, input().split())))
A.sort()
b.sort(key=lambda x: x[1], reverse= True)
for i in range(M):
    for j in range(b[i][0]):
        if A[j] < b[i][1]:
            A[j] = b[i][1]
        else:
            break
    A.sort()
print(sum(A))

### FIXED CODE ###

N, M = map(int, input().split())
A = list(map(int, input().split()))
b = []
for i in range(M):
    b.append(list(map(int, input().split())))
ans = 0
A.sort()
b.sort(key=lambda x: x[1], reverse=True)
j = 0
for i in range(M):
    if j >= N or b[i][1] <= A[j]:
        break
    while j < N and b[i][0] and b[i][1] > A[j]:
        ans += b[i][1]
        b[i][0] -= 1
        j += 1
if j >= N:
    print(ans)
else:
    print(ans + sum(A[j:]))
### BUGGY CODE ###

import bisect

n,m=map(int,input().split())
a = sorted([int(i) for i in input().split()])
ans = 0
while m > 0:
    temp = a[-1]//2
    a = a[:-1]
    index=bisect.bisect_left(a,temp)
    a.insert(index,temp)
    m-=1
print(sum(a))

### FIXED CODE ###

import heapq

n,m=map(int,input().split())
a = sorted([int(i) for i in input().split()])
a = list(map(lambda x: x*(-1), a))
heapq.heapify(a)

while m > 0:
    t = heapq.heappop(a)*(-1)//2
    heapq.heappush(a,-t)
    m-=1
print(-sum(a))
### BUGGY CODE ###

#!/usr/bin/env python3
import sys
from functools import reduce
import fractions

MOD = 1000000007  # type: int

GCD_CACHE = {}


def gcd(x, y):
    if (x, y) in GCD_CACHE:
        return GCD_CACHE[(x, y)]
    d = fractions.gcd(x, y)
    GCD_CACHE[(x, y)] = d
    return d


def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)


def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)


def solve(N: int, A: "List[int]"):
    m = lcm(*A)
    sum = 0
    for a in A:
        sum = (sum + m//a) % MOD
    print(sum)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
from functools import reduce
import fractions

MOD = 1000000007  # type: int

GCD_CACHE = {}


def gcd(x, y):
    if (x, y) in GCD_CACHE:
        return GCD_CACHE[(x, y)]
    d = fractions.gcd(x, y)
    GCD_CACHE[(x, y)] = d
    return d


def lcm_base(x, y):
    return (x * y) // gcd(x, y)


def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)


def solve(N: int, A: "List[int]"):
    m = lcm(*A) % MOD
    sum = 0
    for a in A:
        sum = (sum + m*pow(a, MOD-2, MOD)) % MOD
    print(sum)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)


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

n=int(input())
ans=0
a=list(map(int,input().split()))
now=max(a)
matc=list([] for i in range(n+2*now))
for i in range(n):
  matc[now-a[i]].append([i,0])
  matc[now+a[i]].append([i,1])
  now+=1
matc=filter(lambda x: x != [], matc)
#print(matc)
for j in matc: 
  count0=0
  count1=0
  for k in j:
    if k[1]==0:
      count0+=1
    else:
      count1+=1
  ans+=count0*count1
print(ans)
       
       

### FIXED CODE ###

import numpy as np
n=int(input())
ans=0
a=list(map(int,input().split()))
now=max(a)
noww=now
k=n+2*now
matc=[0]*(n+2)
mat2=[0]*(n+2)
for i in range(n):
  neg=i-a[i]
  pos=i+a[i]
  if neg>=0:
    matc[neg]+=1
  if pos<=n:
    mat2[pos]+=1
  now+=1
#print(matc)
for j in range(n+2):
  ans+=matc[j]*mat2[j]
print(ans)
### BUGGY CODE ###

S=input()
ans=""
for i in range(len(S)):
    ans=S[i]+ans
Q=int(input())
tmp=0
for i in range(Q):
    que=input().split()
    if que[0]=='1':
        tmp=1-tmp
    if que[0]=='2':
        if que[1]=='1':
            if tmp==0:
                S=que[2]+S
                ans=ans+que[2]
            else:
                S=S+que[2]
                ans=que[2]+ans
        else:
            if tmp==0:
                S=S+que[2]
                ans=que[2]+ans
            else:
                S=que[2]+S
                ans=ans+que[2]
#print(que)
"""
for i in range(Q):
    if que[i][0]=='1':
        tmp=1-tmp
    if que[i][0]=='2':
        if que[i][1]=='1':
            if tmp==0:
                S=que[i][2]+S
            else:
                S=S+que[i][2]
        else:
            if tmp==0:
                S=S+que[i][2]
            else:
                S=que[i][2]+S
"""
#print(tmp)
if tmp==1:
    print(ans)
    exit()

print(S)

### FIXED CODE ###

from collections import deque
S=deque(input())
ans=""
Q=int(input())
tmp=0
r=[]
l=[]

for i in range(Q):
    que=input().split()
    if que[0]=='1':
        tmp=1-tmp
    if que[0]=='2':
        if que[1]=='1':
            if tmp==0:
                #S=que[2]+S
                #l.append(que[2])
                #ans=ans+que[2]
                S.appendleft(que[2])
            else:
                #S=S+que[2]
                #r.append(que[2])
                #ans=que[2]+ans
                S.append(que[2])
        else:
            if tmp==0:
                #S=S+que[2]
                #r.append(que[2])
                #ans=que[2]+ans
                S.append(que[2])
            else:
                #S=que[2]+S
                #l.append(que[2])
                #ans=ans+que[2]
                S.appendleft(que[2])
#print(que)
"""
for i in range(Q):
    if que[i][0]=='1':
        tmp=1-tmp
    if que[i][0]=='2':
        if que[i][1]=='1':
            if tmp==0:
                S=que[i][2]+S
            else:
                S=S+que[i][2]
        else:
            if tmp==0:
                S=S+que[i][2]
            else:
                S=que[i][2]+S
"""
#print(tmp)
"""
for i in range(len(r)):
    S=S+r[i]
    ans=r[i]+ans
for i in range(len(l)):
    S=l[i]+S
    ans=ans+l[i]
"""
if tmp==1:
    print("".join(reversed(S)))
    exit()

print("".join(S))
### BUGGY CODE ###

import bisect
n = int(input())
m = list(map(int,input().split()))
num=1
for i in range(n):
  if num in m:
    m = m[m.index(num):]
    num+=1
if num == 1:
  print(-1)
else:
  print(n-num+1)

### FIXED CODE ###

n = int(input())
m = list(map(int,input().split()))
num=1
for i in range(n):
  if m[i] == num:
    num+=1
    
if num == 1:
  print(-1)
else:
  print(n-num+1)
### BUGGY CODE ###

import sys
from collections import deque
input = sys.stdin.readline

def main():
    H, W = map(int, input().split())
    board = [input().strip() for i in range(H)]
    min_ = [[int(1e5)] * W for i in range(H)]

    q = deque()
    for y in range(H):
        for x in range(W):
            if board[y][x] == "#":
                q.append((0, x, y))
                min_[y][x] = 0
    
    ans = 0
    while len(q) > 0:
        cost, x, y = q.popleft()
        min_[y][x] = cost
        ans = max(ans, cost)
        for nx, ny in [(x+1, y), (x-1, y), (x, y+1), (x, y-1)]:
            if 0 <= nx and nx < W and 0 <= ny and ny < H:
                if board[ny][nx] == "." and cost + 1 < min_[ny][nx]:
                    q.append((cost+1, nx, ny))
                    min_[ny][nx] = cost+1
    print(ans)

if __name__ == "__main__":
    main()

### FIXED CODE ###

import numpy as np
import sys
input = sys.stdin.readline

def main():
    H, W = map(int, input().split())

    INF = int(1e7)
    a = np.array([list(map(lambda x: 0 if x=="#" else INF, list(input().strip()))) for i in range(H)])

    for i in range(H-1):
        a[i+1] = np.minimum(a[i] + 1, a[i+1])
    for i in range(H-1, 0, -1):
        a[i-1] = np.minimum(a[i] + 1, a[i-1])
    
    for i in range(W-1):
        a[:, i+1] = np.minimum(a[:, i] + 1, a[:, i+1])
    for i in range(W-1, 0, -1):
        a[:, i-1] = np.minimum(a[:, i] + 1, a[:, i-1])

    print(np.max(a))

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

from bisect import bisect_right

n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
bc = [list(map(int, input().split())) for _ in range(m)]
bc.sort(key=lambda x: x[1], reverse=True)

res = 0
for b, c in bc:
    count = bisect_right(a, c, hi=min(b, len(a)))
    res += count * c
    a = a[count:]

print(res + sum(a))


### FIXED CODE ###

from bisect import bisect_right

n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
bc = [list(map(int, input().split())) for _ in range(m)]
bc.sort(key=lambda x: x[1], reverse=True)

res = 0
fin = 0
for b, c in bc:
    count = bisect_right(a, c, lo=fin, hi=min(fin+b, len(a))) - fin
    fin += count
    res += count * c
for i in range(fin, len(a)):
    res += a[i]

print(res)
### BUGGY CODE ###

n=int(input())
l=[0]*10**7
s=int(n**0.65)+1
for x in range(1,s):
    for y in range(1,s-x):
        for z in range(1,s-x-y):
            l[x*x+y*y+z*z+x*y+y*z+z*x-1]+=1
for i in range(n):
    print(l[i])

### FIXED CODE ###

n=int(input())
l=[0]*10**7
s=int(n**0.7)+10
for x in range(1,s):
    for y in range(1,s-x):
        for z in range(1,s-x-y):
            l[x*x+y*y+z*z+x*y+y*z+z*x-1]+=1
for i in range(n):
    print(l[i])
### BUGGY CODE ###



def li():
    return [int(x) for x in input().split()]

N, K = li()
P = [0] + li()
C = [0] + li()
max_scores = [-10**12] * (N+10)
for init_i in range(1, N+1):
    i = init_i
    scores = [0]
    for l in range(1, K+1):
        i = P[i]
        score = scores[l-1] + C[i]
        scores.append(score)
    scores[0] = -10**9
    max_scores[i] = max(scores)
print(max(max_scores))

### FIXED CODE ###

def li():
    return [int(x) for x in input().split()]

N, K = li()
P = [0] + li()
C = [0] + li()

def get_cycle(start_i):
    cycle = []
    i = start_i
    while True:
        i = P[i]
        if i == start_i:
            break
        cycle.append(i)
    cycle.append(start_i)
    return cycle

def get_cycle_scores(cycle):
    score = 0
    scores = [score]
    for i in cycle:
        score += C[i]
        scores.append(score)
    return scores

max_scores = []
for start_i in range(1,N+1):
    cycle = get_cycle(start_i)
    scores = get_cycle_scores(cycle)
    cycle_len = len(cycle)
    score_per_cycle = scores[cycle_len]
    # 1cycle以下の場合は全て調べればよし
    if K <= len(cycle):
        max_score = max(scores[move] for move in range(1, K+1))
        max_scores.append(max_score)
        continue
    # 1サイクルごとのスコアがマイナスならサイクルを回らないのがハイスコア
    if score_per_cycle <= 0:
        max_score = max(scores[move] for move in range(1, cycle_len+1))
        max_scores.append(max_score)
        continue
    # 1サイクルごとのスコアがプラスなら限界までサイクルを回るのがハイスコア
    # ラスト1cycleのスコアを調べる
    scores_last_cycle = []
    for move in range(K-cycle_len+1, K+1):
        # 何周したか
        loop_cnt = move // cycle_len
        # あまり
        rest_move = move % cycle_len
        # スコア = 1周ごとのスコア * 何周したか + あまり
        score = loop_cnt * score_per_cycle + scores[rest_move]
        scores_last_cycle.append(score)

    max_scores.append(max(scores_last_cycle))

print(max(max_scores))
### BUGGY CODE ###

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()
alis = li()
import numpy as np
alis = np.array(alis,dtype=np.int64)
b = [0] * 61
count = 0
while True:
    if np.all(alis== 0):
        break
    c = (alis % 2 == 0)
    b[count] = sum(c)
    count += 1
    alis //= 2
mod = 10 ** 9 + 7
ans = 0
for i in range(61):
    tmp = (1<<i) % mod
    k = (b[i] * (n-b[i]))  % mod
    k = k*tmp % mod
    ans += k
    ans %= mod
print(ans)



### FIXED CODE ###

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()
alis = li()
import numpy as np
A = np.array(alis,dtype=np.int64)
b = [0] * 61
count = 0
ans = 0
MOD = 10**9 + 7
while A.any():
    one = np.count_nonzero(A & 1)
    k = (1<<count) % MOD
    #ans += (one * (n - one) * pow(2, count, MOD)) % MOD
    ans += (one * (n - one)) * k % MOD
    ans %= MOD
    A >>= 1
    count += 1
 
print(ans)
### BUGGY CODE ###

s = input()
K = int(input())

ss = sorted(list(set(s)))

def f(s, c):
    indexes = []
    # r = []
    st = set()
    for i, si in enumerate(s):
        if si == c:
            indexes.append(i)
    for i in indexes:
        for j in range(i, len(s)):
            x = s[i:j+1]
            # r.append(x)
            st.add(x)
    # return r
    return sorted(list(st))

# st = set()
r = []
for ssi in ss:
    x =  f(s, ssi)
    r += x
    if len(r) > 5:
        break


ans = r[K-1]
print(ans)

### FIXED CODE ###

s = input()
K = int(input())

ss = sorted(list(set(s)))

def f(s, c):
    indexes = []
    st = set()
    for i, si in enumerate(s):
        if si == c:
            indexes.append(i)
    for i in indexes:
        cnt = 0
        for j in range(i, len(s)):
            x = s[i:j+1]
            st.add(x)
            cnt += 1
            # print('cnt', cnt)
            if cnt > 5:
                break
    return sorted(list(st))

r = []
for ssi in ss:
    x =  f(s, ssi)
    r += x
    if len(r) > 5:
        break


ans = r[K-1]
# print(r)
print(ans)
### BUGGY CODE ###

from collections import defaultdict
import sys
sys.setrecursionlimit(10**8)

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

'''
A
1 ~ N -> mod0
N+1 ~ 2N -> mod1

B
1 ~ N -> mod2
N+1 ~ 2N -> mod3
'''

lines = defaultdict(set)
for _ in range(M):
    a,b = map(int, input().split())
    a-=1
    b-=1
    sa, sb = s[a], s[b]
    if sa == sb:
        lines[a].add(b+N)
        lines[b].add(a+N)
    else:
        lines[a+N].add(b)
        lines[b+N].add(a)

ed = [0]*(2*N)

def dfs(s):
    global ed
    ed[s] = 1
    for t in lines[s]:
        if ed[t] == 1: #今訪れている
            print('Yes')
            sys.exit()
        elif ed[t] == 0:
            dfs(t)
    ed[s] = 2

for s in range(N):
    if ed[s] == 0:
        dfs(s)

print('No')


### FIXED CODE ###

from collections import defaultdict
import sys
sys.setrecursionlimit(10**8)

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

'''
A
1 ~ N -> mod0
N+1 ~ 2N -> mod1

B
1 ~ N -> mod2
N+1 ~ 2N -> mod3
'''

lines = [[] for i in range(2*N)]
for _ in range(M):
    a,b = map(int, input().split())
    a-=1
    b-=1
    sa, sb = s[a], s[b]
    if sa == sb:
        lines[a].append(b+N)
        lines[b].append(a+N)
    else:
        lines[a+N].append(b)
        lines[b+N].append(a)

ed = [0]*(2*N)

def dfs(s):
    global ed
    ed[s] = 1
    for t in lines[s]:
        if ed[t] == 1: #今訪れている
            print('Yes')
            sys.exit()
        elif ed[t] == 0:
            dfs(t)
    ed[s] = 2

for s in range(N):
    if ed[s] == 0:
        dfs(s)

print('No')
### BUGGY CODE ###

import sys
input = sys.stdin.readline
import heapq
from collections import Counter

H,W,M = map(int, input().split())
BH = [[0,i] for i in range(H)]
BW = [[0,i] for i in range(W)]
Bomb = []
for _ in range(M):
  h,w = map(int, input().split())
  h,w = h-1,w-1
  BH[h][0] += 1
  BW[w][0] += 1
  Bomb.append((h,w))
  
BH.sort(reverse=True)
BW.sort(reverse=True)
  
BombC = Counter(Bomb)
"""
print(BombC)
print(BH)
print(BW)
"""

h = []
ans = 0
nowh, noww = 0,0
i,j = 0,0
heapq.heappush(h, (-BH[i][0] - BW[j][0], BH[i][1], BW[j][1], i,j))
while h:
  cost, nowh, noww,i,j = heapq.heappop(h)
  cost = -cost
  #print(cost,nowh,noww)
  if (nowh,noww) not in BombC:
    ans = max(ans,cost)
    break
  else:
    ans = max(ans, cost-BombC[(nowh,noww)])
    if i+1 < H:
      heapq.heappush(h, (-BH[i+1][0] - BW[j][0], BH[i+1][1], BW[j][1],i+1, j))
    if j+1 < W:
      heapq.heappush(h, (-BH[i][0] - BW[j+1][0], BH[i][1], BW[j+1][1],i, j+1))
      
print(ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline

H,W,M = map(int, input().split())
BH = [0 for i in range(H)]
BW = [0 for i in range(W)]
Bomb = set()
for _ in range(M):
  h,w = map(int, input().split())
  h,w = h-1,w-1
  BH[h] += 1
  BW[w] += 1
  Bomb.add((h,w))
  
BHMAX = max(BH)
BWMAX = max(BW)
HS = set()
WS = set()
for i in range(H):
  if BH[i] == BHMAX:
    HS.add(i)
for i in range(W):
  if BW[i] == BWMAX:
    WS.add(i)
    
ans = 0
cnt = 0
for h,w in Bomb:
  if h in HS and w in WS:
    ans = max(ans, BHMAX + BWMAX - 1)
    cnt += 1

if cnt < len(HS) * len(WS):
  ans = BHMAX + BWMAX
print(ans)