Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02820 (python)

Fixed submission:
def main():
    N, K = map(int, input().split(" "))
    R, S, P = map(int, input().split(" "))
    strings = input()
    T = []
    for s in strings:
        T.append(s)
    score = {'r': P, 's': R, 'p': S}
    total = 0

    for i in range(K):
        total += score[T[i]]

    for j in range(K, N):
        if T[j] != T[j - K]:
            total += score[T[j]]
        else:
            T[j] = ' '
            continue

    print(total)

   
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    n, k = map(int, input().split())
    r, s, p = map(int, input().split())
    t = list(input())
    score = {"r": p, "s": r, "p": s}
    answer = 0
    for i in range(n):
        if i < k:
            answer += score[t[i]]
            if t[i] == t[i + k]:
                t[i + k] = t[i + k] + "*"
        elif i + k < n:
            if "*" not in t[i]:
                answer += score[t[i][0]]
                if t[i] == t[i + k]:
                    t[i + k] = t[i + k] + "*"
        else:
            if "*" not in t[i]:
                answer += score[t[i][0]]
    print(answer)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    n, k = map(int, input().split())
    r, s, p = map(int, input().split())
    t = list(input())
    score = {"r": p, "s": r, "p": s}
    answer = 0
    for i in range(n):
        if i < k:
            answer += score[t[i]]
            if t[i] == t[i + k]:
                t[i + k] = t[i + k] + "*"
        elif i + k < n:
            if "*" not in t[i]:
                answer += score[t[i]]
                if t[i] == t[i + k]:
                    t[i + k] = t[i + k] + "*"
        else:
            if "*" not in t[i]:
                answer += score[t[i]]
    print(answer)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    n = int(input())
    if n % 2:
        print(0)
    else:
        n //= 2
        i = 5
        answer = 0
        while i <= n:
            answer += n // i
            i *= 5
        print(answer)


if __name__ == '__main__':
    main()
Problem p02935 (python)

Fixed submission:
def main():
    N = int(input())
    v = list(map(int, input().split(" ")))
    while len(v) > 1:
        v.sort(reverse=True)
        a = v[-1]
        b = v[-2]
        v = v[:-2]
        v.append((a + b) / 2)
    print(v[0])


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
from math import floor


def main():
    N = int(input())
    v = list(map(int, input().split(" ")))
    while len(v) > 1:
        v.sort()
        w = []
        if len(v) % 2 == 1:
            w.append(v[-1])
            N -= 1
        for i in range(floor(N / 2)):
            w.append((v[i * 2] + v[i * 2 + 1]) / 2)
        v = w
    print(v[0])


if __name__ == '__main__':
    main()
Problem p02948 (python)

Fixed submission:
from heapq import heappop, heapify, heappush


def main():
    n, m = map(int, input().split())
    work = [[] for _ in range(10 ** 5 + 1)]
    for _ in range(n):
        a, b = map(int, input().split())
        work[a].append(b)
    ans = 0
    q = []
    heapify(q)
    for i in range(1, m + 1):
        for w in work[i]:
            heappush(q, -w)
        if len(q) == 0:
            continue
        ans += heappop(q)
    ans *= -1
    print(ans)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
from heapq import heappop, heapify, heappush


def main():
    n, m = map(int, input().split())
    work = [[] for _ in range(10 ** 4 + 1)]
    for _ in range(n):
        a, b = map(int, input().split())
        work[a].append(b)
    ans = 0
    q = []
    heapify(q)
    for i in range(1, m + 1):
        for w in work[i]:
            heappush(q, -w)
        if len(q) == 0:
            continue
        ans += heappop(q)
    ans *= -1
    print(ans)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
from heapq import heappop, heapify, heappush


def main():
    n, m = map(int, input().split())
    work = [[] for _ in range(10 ** 4 + 1)]
    for _ in range(n):
        a, b = map(int, input().split())
        work[a].append(b)
    ans = 0
    q = []
    heapify(q)
    for i in range(1, m + 1):
        for w in work[i]:
            heappush(q, -w)
        if len(q) == 0:
            continue
        print(q)
        ans += heappop(q)
    ans *= -1
    print(ans)


if __name__ == '__main__':
    main()
Problem p03053 (python)

Fixed submission:
from collections import deque
from sys import stdin


def main():
    height, width = map(int, stdin.readline().split())
    q = deque([])
    grid = [stdin.readline() for _ in range(height)]
    distance = [[-1 for _ in range(width)] for _ in range(height)]
    for i in range(height):
        for j in range(width):
            if grid[i][j] == "#":
                q.append((i, j))
                distance[i][j] = 0
    answer = 0
    delta = ((0, 1), (1, 0), (0, -1), (-1, 0))
    while q:
        y, x = q.popleft()
        answer = distance[y][x]
        for dy, dx in delta:
            new_y = y + dy
            new_x = x + dx
            if 0 <= new_y < height and 0 <= new_x < width and distance[new_y][new_x] < 0:
                distance[new_y][new_x] = answer + 1
                q.append((new_y, new_x))
    print(answer)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
from collections import deque
from sys import stdin


def main():
    height, width = map(int, stdin.readline().split())
    q = deque([])
    grid = [stdin.readline() for _ in range(height)]
    distance = [[-1 for _ in range(width)] for _ in range(height)]
    for i in range(height):
        for j in range(width):
            if grid[i][j] == "#":
                q.append((i, j))
                distance[i][j] = 0
    answer = 0
    delta = ((0, 1), (1, 0), (0, -1), (-1, 0))
    while q:
        y, x = q.popleft()
        answer = distance[y][x]
        for dy, dx in delta:
            new_y = y + dy
            new_x = x + dx
            if 0 <= new_y < height and 0 <= new_x < width and grid[new_y][new_x] == ".":
                distance[new_y][new_x] = answer + 1
                grid[new_y][new_x] = "#"
                q.append((new_y, new_x))
    print(answer)


if __name__ == '__main__':
    main()
Problem p03127 (python)

Fixed submission:
# 解説読んでやり方理解した
from fractions import gcd
from functools import reduce


def get_gcd(numbers):
    return reduce(gcd, numbers)


def main():
    N = int(input())
    monsters = list(map(int, input().split(" ")))
    print(get_gcd(monsters))


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
# 解説読んでやり方理解した
from math import gcd
from functools import reduce


def get_gcd(numbers):
    return reduce(gcd, numbers)


def main():
    N = int(input())
    monsters = list(map(int, input().split(" ")))
    print(get_gcd(monsters))


if __name__ == '__main__':
    main()
Problem p03723 (python)

Fixed submission:
def main():
    cookies = list(map(int, input().split()))
    answer = 0
    if cookies[0] == cookies[1] == cookies[2] and cookies[0] % 2 == 0:
        answer = -1
    elif all(cookies[i] % 2 == 0 for i in range(3)):
        half = [0, 0, 0]
        sum_cookies = sum(cookies)
        while all(cookies[i] % 2 == 0 for i in range(3)):
            for i in range(3):
                half[i] = (sum_cookies - cookies[i]) // 2
            cookies[0] = half[1] + half[2]
            cookies[1] = half[0] + half[2]
            cookies[2] = half[1] + half[0]
            answer += 1
    print(answer)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
from functools import reduce
from math import gcd


def main():
    cookies = list(map(int, input().split()))
    answer = -1
    if cookies[0] % 2 or cookies[1] % 2 or cookies[2] % 2:
        answer = 0
    elif len(set(cookies)) > 1:
        answer = reduce(gcd, cookies) - 1
    print(answer)


if __name__ == '__main__':
    main()
Problem p02723 (python)

Fixed submission:
S=str(input())
if S[2]==S[3] and S[4]==S[5]:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
S=input()
if S[2]==S[3] && S[4]==S[5]:
  print('Yes')
else:
  print('No')
Problem p02766 (python)

Fixed submission:
N,K=map(int, input().split())
ans = 0
while (N > 0):
  N //= K
  ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
N,K=int(input().split())
ans = 0
while (N > 0):
  N //= K
  ans += 1
print(ans)
Problem p02597 (python)

Fixed submission:
n = int(input())
c = input()
l = 0
r = n-1
ans = 0
while l<r:
    while l<n and c[l]=='R':
        l+=1
    while r>=0 and c[r]=='W':
        r-=1
    if l>r:
        break
    ans += 1
    l += 1
    r -= 1
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
c = input()
l = 0
r = n-1
ans = 0
while l<r:
    while l<n and c[l]=='R':
        l+=1
    while l>=0 and c[r]=='W':
        r-=1
    if l>r:
        break
    ans += 1
    l += 1
    r -= 1
print(ans)
Problem p02679 (python)

Fixed submission:
n = int(input())
ab = []
for _ in range(n):
    a, b = map(int, input().split())
    ab.append((a, b))
di = {}
z = 0
def gcd(a, b):
    while b!=0:
        a, b = b, a%b
    return a
for a, b in ab:
    if a*b!=0:
        g = gcd(abs(a), abs(b))
        a, b = a//g, b//g
    if a*b>0:
        ind = (abs(a), abs(b))
    elif a*b<0:
        ind = (abs(b), abs(a))
    else:
        ind = 0
    if ind in di:
        x, y = di[ind]
    else:
        x = y = 0
    if a*b==0:
        if b!=0:
            di[ind] = (x+1, y)
        elif a!=0:
            di[ind] = (x, y+1)
        else:
            z += 1
    else:
        if a*b>0:
            di[ind] = (x+1, y)
        else:
            di[ind] = (x, y+1)
mod = 10**9+7
ans = 1
for i, j in di.values():
    ans *= (pow(2, i, mod)+pow(2, j, mod)-1)
    ans %= mod
print((ans+z-1)%mod)

Buggy submission (verdict: Runtime Error):
n = int(input())
ab = []
for _ in range(n):
    a, b = map(int, input().split())
    ab.append((a, b))
di = {}
def gcd(a, b):
    while b!=0:
        a, b = b, a%b
    return abs(a)
for a, b in ab:
    g = gcd(a, b)
    a, b = a//g, b//g
    if a*b>0:
        ind = (abs(a), abs(b))
    elif a*b<0:
        ind = (abs(b), abs(a))
    else:
        ind = 0
    if ind in di:
        x, y = di[ind]
    else:
        x = y = 0
    if a*b==0:
        if b!=0:
            di[0] = (x+1, y)
        elif a!=0:
            di[0] = (x, y+1)
    else:
        if a*b>0:
            di[ind] = (x+1, y)
        else:
            di[ind] = (x, y+1)
mod = 10**9+7
ans = 1
for i, j in di.values():
    ans *= (pow(2, i, mod)+pow(2, j, mod)-1)
    ans %= mod
print(ans-1)
Problem p02762 (python)

Fixed submission:
n, m, k = map(int, input().split())

friends = [[] for _ in range(n+1)]
blocks = [[] for _ in range(n+1)]

for _ in range(m):
    a, b = map(int, input().split())
    friends[a].append(b)
    friends[b].append(a)

for _ in range(k):
    c, d = map(int, input().split())
    blocks[c].append(d)
    blocks[d].append(c)

groups = [-1]*(n+1)
n_groups = []
g = 0
for i in range(1, n+1):
    if groups[i]>=0:
        continue
    stack = [i]
    cnt = 0
    groups[i] = g
    while len(stack)>0:
        node = stack.pop()
        for c_node in friends[node]:
            if groups[c_node]>=0:
                continue
            stack.append(c_node)
            groups[c_node] = g
            cnt += 1
    n_groups.append(cnt)
    g += 1

ans = []
for i in range(1, n+1):
    tmp = n_groups[groups[i]]
    for j in friends[i]:
        if groups[i] == groups[j]:
            tmp -= 1
    for j in blocks[i]:
        if groups[i] == groups[j]:
            tmp -= 1
    ans.append(tmp)

print(*ans)

Buggy submission (verdict: Runtime Error):
n, m, k = map(int, input().split())

friends = [[] for _ in range(n+1)]
blocks = [[] for _ in range(n+1)]

for _ in range(m):
    a, b = map(int, input().split())
    friends[a].append(b)
    friends[b].append(a)

for _ in range(k):
    c, d = map(int, input().split())
    blocks[c].append(d)
    blocks[d].append(c)

groups = []
nseen = {i for i in range(1, n+1)}
while len(nseen)>0:
    stack = [nseen.pop()]
    tmp = set()
    while len(stack)>0:
        node = stack.pop()
        tmp.add(node)
        nseen.remove(node)
        for c_node in friends[node]:
            if c_node not in nseen:
                continue
            stack.append(c_node)
    groups.append(tmp)

for i in range(1, n+1):
    for j in groups:
        if i in j:
            print(len(j - set(friends[i]) - set(blocks[i]))-1, end=' ')
            break
Problem p02763 (python)

Fixed submission:
from bisect import insort_left, bisect_left
n = int(input())
s = list(input())
Q = int(input())
query = [input() for _ in range(Q)]
dic = {chr(i+ord('a')):[] for i in range(26)}
for ind, c in enumerate(s):
    dic[c].append(ind)

for q in query:
    t, a, b = q.split()
    a = int(a)-1
    if t=='1':
        if s[a]==b:
            continue
        ind = bisect_left(dic[s[a]], a)
        dic[s[a]].pop(ind)
        insort_left(dic[b], a)
        s[a] = b
    else:
        b = int(b)-1
        tmp = 0
        for li in dic.values():
            if li and a<=li[-1] and li[bisect_left(li, a)] <= b:
                tmp += 1
        print(tmp)

Buggy submission (verdict: Runtime Error):
from bisect import insort_left
n = int(input())
s = input()
q = int(input())
dic = {}
for ind, c in enumerate(s):
    if c in dic:
        dic[c].append(ind)
    else:
        dic[c] = [ind]

for _ in range(q):
    t, a, b = input().split()
    a = int(a)-1
    if t=='1':
        find_c = False
        for c, li in dic.items():
            if a in li:
                li.remove(a)
            if c==b:
                insort_left(li, a)
                find_c = True
        if not find_c:
            dic[b] = [a]
    else:
        b = int(b)-1
        tmp = 0
        for li in dic.values():
            if li[0]<=b and li[-1]>=a:
                tmp += 1
        print(tmp)
Problem p03045 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
n, m = map(int, input().split())
xy = []
for _ in range(m):
    x, y, _ = map(int, input().split())
    xy.append((x-1, y-1))

class UnionFind():
    def __init__(self, n):
        self.li = list(range(n))
    def root(self, x):
        if self.li[x]==x:
            return x
        self.li[x] = self.root(self.li[x])
        return self.li[x]
    def unite(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        if rx==ry:
            return
        self.li[ry] = rx
    def same(self, x, y):
        return self.root(x)==self.root(y)

uf = UnionFind(n)
for x, y in xy:
    uf.unite(x, y)
for i in range(n):
    uf.root(i)
print(len(set(uf.li)))

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
xy = []
for _ in range(m):
    x, y, _ = map(int, input().split())
    xy.append((x-1, y-1))

class UnionFind():
    def __init__(self, n):
        self.li = list(range(n))
    def root(self, x):
        if self.li[x]==x:
            return x
        self.li[x] = self.root(self.li[x])
        return self.li[x]
    def unite(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        if rx==ry:
            return
        self.li[ry] = rx
    def same(self, x, y):
        return self.root(x)==self.root(y)

uf = UnionFind(n)
for x, y in xy:
    uf.unite(x, y)
for i in range(n):
    uf.root(i)
print(len(set(uf.li)))
Problem p03108 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
n, m = map(int, input().split())
ab = []
for _ in range(m):
    a, b = map(int, input().split())
    ab.append((a-1, b-1))

class UnionFind():
    def __init__(self, li):
        self.li = li
        self.cnt = [1]*len(li)
        self.ans = 0
    def root(self, x):
        if self.li[x]==x:
            return x
        self.li[x] = self.root(self.li[x])
        return self.li[x]
    def unite(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        if rx==ry:
            return self.ans
        self.li[ry] = rx
        self.ans -= self.cnt[rx]*(self.cnt[rx]-1)//2
        self.ans -= self.cnt[ry]*(self.cnt[ry]-1)//2
        self.cnt[rx] += self.cnt[ry]
        self.ans += self.cnt[rx]*(self.cnt[rx]-1)//2
        return self.ans
uf = UnionFind(list(range(n)))
ans = [n*(n-1)//2]
for a, b in ab[::-1][:-1]:
    ans.append(n*(n-1)//2-uf.unite(a, b))
for i in reversed(ans):
    print(i)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
ab = []
for _ in range(m):
    a, b = map(int, input().split())
    ab.append((a-1, b-1))

class UnionFind():
    def __init__(self, li):
        self.li = li
        self.cnt = [1]*len(li)
        self.ans = 0
    def root(self, x):
        if self.li[x]==x:
            return x
        self.li[x] = self.root(self.li[x])
        return self.li[x]
    def unite(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        if rx==ry:
            return self.ans
        self.li[ry] = rx
        self.ans -= self.cnt[rx]*(self.cnt[rx]-1)//2
        self.ans -= self.cnt[ry]*(self.cnt[ry]-1)//2
        self.cnt[rx] += self.cnt[ry]
        self.ans += self.cnt[rx]*(self.cnt[rx]-1)//2
        return self.ans
uf = UnionFind(list(range(n)))
ans = [n*(n-1)//2]
for a, b in ab[::-1][:-1]:
    ans.append(n*(n-1)//2-uf.unite(a, b))
for i in reversed(ans):
    print(i)
Problem p03329 (python)

Fixed submission:
import sys
n = int(input())
INF = 10*n
dp = [INF]*(n+1)
dp[0] = 0
for i in range(1, n+1):
    tmp = dp[i-1] + 1
    for j in range(10):
        if i-6**j<0:
            break
        tmp = min(tmp, dp[i-6**j] + 1)
    for j in range(10):
        if i-9**j<0:
            break
        tmp = min(tmp, dp[i-9**j] + 1)
    dp[i] = tmp
print(dp[n])

Buggy submission (verdict: Runtime Error):
import sys
n = int(input())
mem = [None]*(n+1)
def DFS(k, d):
    if k<0 or d>2000:
        return 10**9
    if k==0:
        return 0
    if k<6:
        return k
    if mem[k] is not None:
        return mem[k]
    tmp = 10**5
    for i in range(1, 7):
        tmp = min(tmp, DFS(k-6**i, d+1)+1)
    for i in range(1, 6):
        tmp = min(tmp, DFS(k-9**i, d+1)+1)
    mem[k] = tmp
    return tmp
if n<6:
    print(n)
else:
    print(DFS(n, 0))

Buggy submission (verdict: Runtime Error):
import sys
n = int(input())
mem = [None]*(n+1)
def DFS(k, d):
    if k<0 or d>5000:
        return 10**9
    if k==0:
        return 0
    if k<6:
        return k
    if mem[k] is not None:
        return mem[k]
    tmp = 10**5
    for i in range(1, 7):
        tmp = min(tmp, DFS(k-6**i, d+1)+1)
    for i in range(1, 6):
        tmp = min(tmp, DFS(k-9**i, d+1)+1)
    mem[k] = tmp
    return tmp
if n<6:
    print(n)
else:
    print(DFS(n, 0))
Problem p03724 (python)

Fixed submission:
n, m = map(int, input().split())
nnode = [0]*n
for _ in range(m):
    a, b = map(int, input().split())
    nnode[a-1] += 1
    nnode[b-1] += 1
for i in nnode:
    if i%2==1:
        print('NO')
        break
else:
    print('YES')

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
nnode = [0]*n
for _ in range(n):
    a, b = map(int, input().split())
    nnode[a-1] += 1
    nnode[b-1] += 1
for i in nnode:
    if i%2==1:
        print('NO')
        break
else:
    print('YES')
Problem p02777 (python)

Fixed submission:
S, T = input().split()
A, B = map(int, input().split())
print(A-1, B) if input()==S else print(A, B-1)

Buggy submission (verdict: Runtime Error):
S, T = input().split
A, B = map(int, input().split)
U = input()

print(A-1, B if S ==U else A, B-1)
Problem p02790 (python)

Fixed submission:
a,b = input().split()
num_a = int(a)
num_b = int(b)

if num_a < num_b:
  print(a*num_b)
else:
  print(b*num_a)

Buggy submission (verdict: Runtime Error):
a, b = input().split()
print(min(a*b, b*a))

Buggy submission (verdict: Runtime Error):
a,b = map(input().split())
num_a = int(a)
num_b = int(b)

if num_a < num_b:
  print(a*num_b)
else:
  print(b*num_a)
Problem p02881 (python)

Fixed submission:
N = int(input())
m = 100000000000000
for i in range(1, int(N**0.5)+1):
  if N%i == 0:
    m = min(m, i+N//i)
print(m-2)

Buggy submission (verdict: Runtime Error):
N = int(input())
t = N+1
for n in reversed(range(0, int(N**0.5))):
  if N%n==0:
    t = n+N//n
    break
print(t-2)

Buggy submission (verdict: Runtime Error):
N = int(input())
for n in reversed(range(1, int(N**0.5))):
  if N%n==0:
    t = n+N//n
    break
print(t-2)
Problem p02987 (python)

Fixed submission:
from collections import Counter
s = Counter(input()).values()
print("Yes" if min(s)==max(s) and len(s)==2 else "No")

Buggy submission (verdict: Runtime Error):
s = sorted(input())
print("Yes" if s[0]==s[1] and S[1]!=S[2] and s[2]==s[3] else "No")
Problem p02596 (python)

Fixed submission:
k = int(input())
ans = 0
now = 7
while True:
    ans += 1
    now %= k
    if now == 0:
        print(ans)
        exit()
    now = now * 10 + 7
    if ans == 1000000:
        print(-1)
        exit()

Buggy submission (verdict: Runtime Error):
k = int(input())
ans = 0
now = 7
while True:
    ans += 1
    now %= k
    if now == 0:
        print(ans)
        exit(-1)
    now = now * 10 + 7
    if ans == 1000000:
        print(-1)
        exit(-1)
Problem p02580 (python)

Fixed submission:
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

h, w, m = LI()
bomb = defaultdict(lambda : 0)
cnt_h = [0] * h
cnt_w = [0] * w
for _ in range(m):
    H, W = LI()
    bomb[(H-1, W-1)] = 1
    cnt_h[H-1] += 1
    cnt_w[W-1] += 1

m_h = max(cnt_h)
m_w = max(cnt_w)
H_l = defaultdict(int)
W_l = defaultdict(int)
for i in range(h):
    if cnt_h[i] == m_h:
        H_l[i] = 1

for i in range(w):
    if cnt_w[i] == m_w:
        W_l[i] = 1

ans = m_h + m_w

for i in H_l.keys():
    for j in W_l.keys():
        if bomb[(i, j)] == 0:
            print(ans)
            quit()

print(ans-1)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

h, w, m = LI()
cnt = [[0] * w for _ in range(h)]
cnt_h = [0] * h
cnt_w = [0] * w
for _ in range(m):
    H, W = LI()
    cnt[H-1][W-1] += 1
    cnt_h[H-1] += 1
    cnt_w[W-1] += 1

ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans, cnt_h[i] + cnt_w[j] - cnt[i][j])
print(ans)