ZhenlongDai/ACPR huggingface dataset:
Problem: p02580
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):

from collections import defaultdict

H, W, M = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(M)]

ctr_h = defaultdict(list)
ctr_w = defaultdict(list)

for h, w in X:
    ctr_h[h].append((h, w))
    ctr_w[w].append((h, w))

val_h = sorted(ctr_h.items(), key=lambda x: -len(x[1]))
val_w = sorted(ctr_w.items(), key=lambda x: -len(x[1]))

max_h = len(val_h[0][1])
max_w = len(val_w[0][1])

if (len(val_h) > 1 and len(val_h[1][1]) == max_h
        and len(val_w) > 1 and len(val_w[1][1]) == max_w):
    print(max_h + max_w)
else:
    h = val_h[0][0]
    w = val_w[0][0]
    for u, v in X:
        if u == h and v == w:
            print(max_h + max_w - 1)
            break
    else:
        print(max_h + max_w)


Failing test case input:
5 5 10
2 5
4 5
2 3
1 5
2 4
5 4
5 1
5 1
4 5
1 4

Expected output:
7


Actual output:
6


Fixed submission (verdict: Accepted):

import sys
from collections import defaultdict

H, W, M = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(M)]

ctr_h = defaultdict(int)
ctr_w = defaultdict(int)
appeared = set()

for h, w in X:
    ctr_h[h] += 1
    ctr_w[w] += 1
    appeared.add(h * W + w)

val_h = sorted(ctr_h.items(), key=lambda x: -x[1])
val_w = sorted(ctr_w.items(), key=lambda x: -x[1])

max_h = val_h[0][1]
max_w = val_w[0][1]

val_h = [i for i, v in val_h if v == max_h]
val_w = [i for i, v in val_w if v == max_w]

if len(val_h) * len(val_w) > M:
    print(max_h + max_w)
    sys.exit(0)

for h in val_h:
    for w in val_w:
        if h * W + w not in appeared:
            print(max_h + max_w)
            sys.exit(0)
else:
    print(max_h + max_w - 1)
Problem: p02580
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]

def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  H,W,M=LI()
  h=[0]*H
  w=[0]*W
  lh=[]
  lw=[]
  d={}
  for _ in range(M):
    a,b=LI()
    lh.append(a)
    lw.append(b)
    a-=1
    b-=1
    h[a]+=1
    w[b]+=1
    d[(a,b)]=1

  h_koho=[]
  w_koho=[]

  h_max=max(h)
  w_max=max(w)

  for i,x in enumerate(h):
    if x==h_max:
      h_koho.append(x)
  for i,x in enumerate(w):
    if x==w_max:
      w_koho.append(x)

  for x in h_koho:
    for y in w_koho:
      if (x,y) not in d:
        return h_max+w_max

  return h_max+w_max-1


print(main())


Failing test case input:
5 5 10
2 5
4 5
2 1
3 5
2 2
5 4
5 1
5 1
3 5
1 4

Expected output:
7


Actual output:
6


Fixed submission (verdict: Accepted):
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]

def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  H,W,M=LI()
  h=[0]*H
  w=[0]*W
  d={}
  for _ in range(M):
    a,b=LI()
    a-=1
    b-=1
    h[a]+=1
    w[b]+=1
    d[(a,b)]=1

  h_koho=[]
  w_koho=[]

  h_max=max(h)
  w_max=max(w)

  for i,x in enumerate(h):
    if x==h_max:
      h_koho.append(i)
  for i,x in enumerate(w):
    if x==w_max:
      w_koho.append(i)

  for x in h_koho:
    for y in w_koho:
      if (x,y) not in d:
        return h_max+w_max

  return h_max+w_max-1


print(main())
Problem: p02580
Buggy submission (Python (3.8.2), verdict: Wrong Answer):



from math import gcd
from itertools import combinations,permutations,accumulate, product 

from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq














import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7


INF = float('inf')
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
    return int(readline())
H,W,M = readInts()

dic1 = defaultdict(int)
dic2 = defaultdict(int)
s = set()
for i in range(M):
    h,w = map(lambda x:int(x)-1, input().split())
    dic1[h] += 1
    dic2[w] += 1
    s.add((h,w))


ans = 0






for h,w in s:
    ans = max(ans, dic1[h] + dic2[w] - 1)

max1 = max(dic1, key = dic1.get)
max2 = max(dic2, key = dic2.get)
if (max1,max2) in s:
    pass
else:
    ans = max(ans, dic1[max1] + dic2[max2])
print(ans)


Failing test case input:
5 7 10
1 5
4 5
2 2
5 5
1 2
5 4
5 4
5 1
4 3
2 2

Expected output:
7


Actual output:
6


Fixed submission (verdict: Accepted):



from math import gcd
from itertools import combinations,permutations,accumulate, product 

from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq














import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7


INF = float('inf')
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
    return int(readline())
H,W,M = readInts()

dic1 = Counter()
dic2 = Counter()
s = set()
for i in range(M):
    h,w = map(lambda x:int(x)-1, input().split())
    dic1[h] += 1
    dic2[w] += 1
    s.add((h,w))

ans = 0



for h,w in s:
    ans = max(ans, dic1[h] + dic2[w] - 1)

dic1 = dic1.most_common()
dic2 = dic2.most_common()
max1 = dic1[0][1]
max2 = dic2[0][1]

for k1,v1 in dic1:
    if v1 < max1:
        break 
    for k2,v2 in dic2:
        if v2 < max2:
            break 
        if (k1,k2) in s: 
            continue
        
        ans = max(ans, v1 + v2)
        break
print(ans)
Problem: p02580
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
from collections import Counter
from collections import defaultdict

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

H, W, M = li()
PH = []
PW = []

for i in range(M):
    h, w = li()
    PH.append(h)
    PW.append(w)

frequency_h_list = Counter(PH).most_common()
frequency_w_list = Counter(PW).most_common()
most_common_h_cnt = frequency_h_list[0][1]
most_common_w_cnt = frequency_w_list[0][1]

most_common_h_list = []
for x in frequency_h_list:
    if x[1] < most_common_h_cnt:
        break
    most_common_h_list.append(x[0])

most_common_w_list = []
for x in frequency_w_list:
    if x[1] < most_common_w_cnt:
        break
    most_common_w_list.append(x[0])

contain_intersection = {}
for h in most_common_h_list:
    for w in most_common_w_list:
        contain_intersection[h, w] = False

add = 0

for i in range(M):
    h, w = PH[i], PW[i]
    if h not in most_common_h_list and w not in most_common_w_list:
        continue
    if (h, w) not in contain_intersection:
        add = -1
        break
cnt = most_common_h_cnt + most_common_w_cnt + add

print(cnt)

Failing test case input:
5 7 10
1 5
4 5
2 2
5 5
2 2
5 4
5 4
5 1
4 3
2 2

Expected output:
7


Actual output:
6


Fixed submission (verdict: Accepted):
from collections import Counter
from collections import defaultdict

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

H, W, M = li()
PH = []
PW = []
PHF = defaultdict(int)
PWF = defaultdict(int)
PF = defaultdict(int)

for i in range(M):
    h, w = li()
    PH.append(h)
    PW.append(w)
    PHF[h] += 1
    PWF[w] += 1
    PF[h, w] += 1

sorted_PHF = sorted(PHF.items(), key=lambda x: x[1], reverse=True)
sorted_PWF = sorted(PWF.items(), key=lambda x: x[1], reverse=True)
most_common_h_cnt = sorted_PHF[0][1]
most_common_w_cnt = sorted_PWF[0][1]

most_common_h_list = []
for x in sorted_PHF:
    if x[1] < most_common_h_cnt:
        break
    most_common_h_list.append(x[0])

most_common_w_list = []
for x in sorted_PWF:
    if x[1] < most_common_w_cnt:
        break
    most_common_w_list.append(x[0])

add = -1
for h in most_common_h_list:
    for w in most_common_w_list:
        if PF[h, w] == 0:
            add = 0
            break

cnt = most_common_h_cnt + most_common_w_cnt + add

print(cnt)
Problem: p02580
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
from itertools import combinations

H, W, M = map(int, input().split())

bomb_h = [0] * H
bomb_w = [0] * W
grid = [[False] * W for _ in range(H)]
for i in range(M):
    h, w = map(int, input().split())
    bomb_h[h-1] += 1
    bomb_w[w-1] += 1
    grid[h-1][w-1] = True

max_h = max(bomb_h)
max_w = max(bomb_w)

h_indices = []
for i in range(H):
    if bomb_h[i] == max_h:
        h_indices.append(i)

w_indices = []
for i in range(W):
    if bomb_w[i] == max_w:
        w_indices.append(i)

ans = max_w + max_h - 1
for h in h_indices:
    for w in w_indices:
        if not grid[h][w]:
            ans += 1
            break

print(ans)

Failing test case input:
5 5 10
2 5
1 5
2 1
5 1
2 2
5 2
5 1
1 2
3 5
1 4

Expected output:
6


Actual output:
7


Fixed submission (verdict: Accepted):
import sys
input = sys.stdin.buffer.readline

H, W, M = map(int, input().split())

bomb_h = [0] * H
bomb_w = [0] * W
bomb = set()
for i in range(M):
    h, w = map(int, input().split())
    bomb_h[h-1] += 1
    bomb_w[w-1] += 1
    bomb.add((h-1, w-1))

max_h = max(bomb_h)
max_w = max(bomb_w)

h_indices = []
for i in range(H):
    if bomb_h[i] == max_h:
        h_indices.append(i)

w_indices = []
for i in range(W):
    if bomb_w[i] == max_w:
        w_indices.append(i)

ans = max_w + max_h - 1
for h in h_indices:
    for w in w_indices:
        if (h, w) not in bomb:
            ans += 1
            print(ans)
            exit()

if ans == -1:
    ans = 0

print(ans)

Problem: p02580
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import collections

h, w, m = map(int, input().split())
lsh = [0] * h
lsw = [0] * w

bom = []
for _ in range(m):
    m1, m2 = map(int, input().split())
    lsh[m1 - 1] += 1
    lsw[m2 - 1] += 1
    bom.append((m1-1, m2-1))

lshmax = max(lsh)
lswmax = max(lsw)
hin = [i for i in lsh if i == lshmax]
win = [i for i in lsw if i == lswmax]


jd= False

for i in hin:
    for j in win:
        if (i, j) not in bom:
                    jd= True
                    
if jd:
    print(lshmax+lswmax)
else:
    print(lshmax + lswmax -1)

Failing test case input:
5 5 10
2 5
4 5
3 2
5 3
2 2
5 4
5 1
5 1
3 5
1 4

Expected output:
7


Actual output:
6


Fixed submission (verdict: Accepted):
def main():
    h, w, m = map(int, input().split())
    lsh = [0] * h
    lsw = [0] * w

    bom = set()
    for _ in range(m):
        m1, m2 = map(int, input().split())
        lsh[m1 - 1] += 1
        lsw[m2 - 1] += 1
        bom.add((m1-1, m2-1))

    lshmax = max(lsh)
    lswmax = max(lsw)

    hin = [i for i in range(h) if lsh[i] == lshmax]
    win = [i for i in range(w) if lsw[i] == lswmax]

    for i in hin:
        for j in win:
            if (i, j) not in bom:
                print(lshmax + lswmax)
                exit(0)
    else:
        print(lshmax + lswmax -1)


if __name__ == '__main__':
    main()
Problem: p02580
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import sys
HK,WK,M = map(int, input().split())
W = [0] * (WK + 1)
H = [0] * (HK + 1)
HW = {}


for i in range(M):
    h, w = map(int, input().split())

    H[h] += 1
    W[w] += 1

    HW[(h,w)] = 1

answer = 0
HMAX = max(H)
WMAX = max(W)

HEMAX = H.count(HMAX)
WEMAX = W.count(WMAX)
if HEMAX * WEMAX > M:
    print(HMAX + WMAX)
    sys.exit(0)

HMAXES = [i for i, _ in enumerate(H) if _ == HMAX]
WMAXES = [i for i, _ in enumerate(W) if _ == WMAX]


answer = HMAX + WMAX
for h in HMAXES:
    for w in WMAXES:
        if (h,w) in HW:
            print(answer)
            sys.exit(0)
print(answer-1)

Failing test case input:
5 10 10
2 5
4 5
2 3
5 5
2 4
5 4
5 1
1 1
4 5
1 4

Expected output:
6


Actual output:
7


Fixed submission (verdict: Accepted):
import sys
HK,WK,M = map(int, input().split())
W = [0] * (WK + 1)
H = [0] * (HK + 1)
HW = {}


for i in range(M):
    h, w = map(int, input().split())

    H[h] += 1
    W[w] += 1

    HW[(h,w)] = 1

answer = 0
HMAX = max(H)
WMAX = max(W)

HEMAX = H.count(HMAX)
WEMAX = W.count(WMAX)
if HEMAX * WEMAX > M:
    print(HMAX + WMAX)
    sys.exit(0)

HMAXES = [i for i, _ in enumerate(H) if _ == HMAX]
WMAXES = [i for i, _ in enumerate(W) if _ == WMAX]


answer = HMAX + WMAX
for h in HMAXES:
    for w in WMAXES:
        if not (h,w) in HW:
            print(answer)
            sys.exit(0)
print(answer-1)

Problem: p02580
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
H,W,M = map(int,input().split())

h_target = [0]*(H+1)
w_target = [0]*(W+1)
target = []

for _ in range(M):
    h,w = map(int,input().split())
    target.append((h,w))
    h_target[h] += 1
    w_target[w] += 1

max_h_target = max(h_target)
max_w_target = max(w_target)

flag = False 

for i,j in target:
    if h_target[i] != max_h_target and w_target[j] != max_w_target:
        break
else:
    flag = True

if flag:
    print(max_h_target+max_w_target)
else:
    print(max_h_target+max_w_target-1)

Failing test case input:
5 5 10
2 5
4 5
2 3
5 2
2 2
5 4
5 3
5 1
3 5
1 4

Expected output:
7


Actual output:
6


Fixed submission (verdict: Accepted):
H,W,M = map(int,input().split())

h_target = [0]*(H+1)
w_target = [0]*(W+1)
target = []

for _ in range(M):
    h,w = map(int,input().split())
    target.append((h,w))
    h_target[h] += 1
    w_target[w] += 1

max_h = max(h_target)
max_w = max(w_target)

num_max_h = 0
num_max_w = 0

for i in h_target:
    if i == max_h:
        num_max_h += 1

for i in w_target:
    if i == max_w:
        num_max_w += 1

total = num_max_h*num_max_w
point = 0

for i,j in target:
    if h_target[i] == max_h and w_target[j] == max_w:
        point += 1

if point == total:
    print(max_h+max_w-1)
else:
    print(max_h+max_w)
Problem: p02580
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import sys
import bisect
import itertools
import collections
import fractions
import heapq
import math
from operator import mul
from functools import reduce
from functools import lru_cache


def solve():
    readline = sys.stdin.buffer.readline
    input = readline
    mod = 10 ** 9 + 7
    H, W, M = map(int, input().split())
    Hlist = [0] * H
    Wlist = [0] * W
    hw = []

    for _ in range(M):
        h, w = map(int, input().split())
        Hlist[h-1] += 1
        Wlist[w-1] += 1
        hw.append([h, w])


    hmax = [i for i, x in enumerate(Hlist) if x == max(Hlist)]
    wmax = [i for i, x in enumerate(Wlist) if x == max(Wlist)]
    hmaxset = set(hmax)
    wmaxset = set(wmax)

    flag = False
    for hh in hw:
        h = hh[0] - 1
        w = hh[1] - 1
        if not (h in hmaxset and w in wmaxset):
            flag = True
            break


    if flag:
        print(Hlist[h] + Wlist[w])
    else:
        print(Hlist[h] + Wlist[w] - 1)





if __name__ == '__main__':
    solve()

Failing test case input:
5 5 10
2 5
4 5
3 2
5 3
2 2
5 4
5 1
5 1
3 5
1 4

Expected output:
7


Actual output:
5


Fixed submission (verdict: Accepted):
import sys
import bisect
import itertools
import collections
import fractions
import heapq
import math
from operator import mul
from functools import reduce
from functools import lru_cache


def solve():
    readline = sys.stdin.buffer.readline
    input = readline
    mod = 10 ** 9 + 7
    H, W, M = map(int, input().split())
    Hlist = collections.defaultdict(int)
    Wlist = collections.defaultdict(int)
    hw = []

    for _ in range(M):
        h, w = map(int, input().split())
        Hlist[h-1] += 1
        Wlist[w-1] += 1
        hw.append([h, w])

    
    

    Hlist = sorted(Hlist.items(), key=lambda x: x[1], reverse=True)
    Wlist = sorted(Wlist.items(), key=lambda x: x[1], reverse=True)

    hmaxset = set()
    wmaxset = set()

    maxH = Hlist[0][1]
    for k, v in Hlist:
        if v != maxH:
            break
        else:
            hmaxset.add(k)

    maxW = Wlist[0][1]
    for k, v in Wlist:
        if v != maxW:
            break
        else:
            wmaxset.add(k)


    flag = False
    count = 0
    for hh in hw:
        h = hh[0] - 1
        w = hh[1] - 1
        if h in hmaxset and w in wmaxset:
            count += 1

    lenhmax = len(hmaxset)
    lenwmax = len(wmaxset)

    if count != lenhmax * lenwmax:
        flag = True

    if flag:
        print(maxH + maxW)
    else:
        print(maxH + maxW - 1)





if __name__ == '__main__':
    solve()
Problem: p02580
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
h,w,m=map(int,input().split())
bomb=[list(map(int,input().split())) for _ in range(m)] 
a=[0 for i in range(h+1)] 
b=[0 for _ in range(w+1)] 
for i in range(m):
    a[bomb[i][0]]+=1
    b[bomb[i][1]]+=1
am=max(a) 
bm=max(b) 
hmax=[0]*(h+1) 
wmax=[0]*(w+1) 
for i in range(h+1):
    if am==a[i]:
        hmax[i]+=1
for i in range(w):
    if bm==b[i]:
        wmax[i]+=1
ans=(am+bm) 
k=sum(hmax)*sum(wmax)
if k>m: 
    print(ans)
    exit()
for i in bomb:
    if hmax[i[0]]==1 and wmax[i[1]]==1:
        k-=1
if k==0:
    print(ans-1)
else:
    print(ans)

Failing test case input:
5 5 10
2 5
4 5
2 1
3 5
2 2
5 4
5 2
5 1
3 5
1 4

Expected output:
7


Actual output:
6


Fixed submission (verdict: Accepted):
h,w,m=map(int,input().split())
bomb=[list(map(int,input().split())) for _ in range(m)] 
a=[0 for i in range(h+1)] 
b=[0 for _ in range(w+1)] 
for i in range(m):
    a[bomb[i][0]]+=1
    b[bomb[i][1]]+=1
am=max(a) 
bm=max(b) 
hmax=[0]*(h+1) 
wmax=[0]*(w+1) 
for i in range(h+1):
    if am==a[i]:
        hmax[i]+=1
for i in range(w+1):
    if bm==b[i]:
        wmax[i]+=1
ans=am+bm 
k=sum(hmax)*sum(wmax)
if k>m: 
    print(ans)
    exit()
for i in bomb:
    if hmax[i[0]]==1 and wmax[i[1]]==1:
        k-=1
if k==0:
    print(ans-1)
else:
    print(ans)

Problem: p02580
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):

from collections import defaultdict

H,W,M=map(int,input().split())
AB=[tuple(map(int,input().split()))for i in range(M)]
AB=[(a-1,b-1)for a,b in AB]
st=set(AB)

Wc=defaultdict(lambda :0)
Hc=defaultdict(lambda :0)
for a,b in AB:
    Hc[a]+=1
    Wc[b]+=1

Hm=max(Hc.values())
for i in Hc.keys():
    if Hc[i]==Hm:
        x=i
        break
Wm=max(Wc.values())
for j in Wc.keys():
    if Wc[j]==Wm:
        y=j
        break


ans=Hc[x] + Wc[y] +(-1 if (x,y) in st else 0)
print(ans)


Failing test case input:
5 10 10
2 5
4 5
2 3
5 5
2 4
5 4
5 1
1 1
4 1
1 4

Expected output:
6


Actual output:
5


Fixed submission (verdict: Accepted):

from collections import defaultdict

H,W,M=map(int,input().split())
AB=[tuple(map(int,input().split()))for i in range(M)]
AB=[(a-1,b-1)for a,b in AB]
st=set(AB)

Wc=defaultdict(lambda :0)
Hc=defaultdict(lambda :0)
for a,b in AB:
    Hc[a]+=1
    Wc[b]+=1

Hm=max(Hc.values())
hhh=list(Hc.keys())
www=list(Wc.keys())
for i in hhh:
    if Hc[i]!=Hm:
        Hc.pop(i)
Wm=max(Wc.values())
for j in www:
    if Wc[j]!=Wm:
        Wc.pop(j)

ans=0
count=0
for i in Hc.keys():
    for j in Wc.keys():
        add = -1 if (i,j) in st else 0
        tmp= Hc[i] + Wc[j] + add
        ans=max(ans,tmp)
        if count>300000:
            break
        count+=1

print(ans)
Problem: p02580
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import collections
a = input().split()
M = int(a[2])
hidari = []
migi = []
c = []
 
for i in range(M):
  b = input().split()
  hidari.append(b[0])
  migi.append(b[1])
  c.append(b)
 
countleft = collections.Counter(hidari)
countright = collections.Counter(migi)
leftmax = countleft.most_common()[0][1]
rightmax = countright.most_common()[0][1]
tempmax = int(leftmax + rightmax)
 


leftkeys = (list(countleft.keys())[list(countleft.values()).index(leftmax)])
rightkeys = (list(countright.keys())[list(countright.values()).index(rightmax)])
 
leftkeyN = int(len(leftkeys))
rightkeyN = int(len(rightkeys))
flag = int(0)
cnt = int(0)

for i in range(leftkeyN):
    if flag != 0:
        break
    else:
        for P in range(rightkeyN):
            for T in range(M):
                if c[T] == [leftkeys[i],rightkeys[P]]:
                    cnt = cnt + 1
            if cnt == 0:
                flag = flag + 1
                break
            else:
                cnt = 0
 
if flag == 0:
    print(int(tempmax - 1))
else:
    print(int(tempmax))
    

Failing test case input:
2 3 3
2 2
1 1
2 3

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
import collections
a = input().split()
M = int(a[2])
hidari = []
migi = []
c = []
 
for i in range(M):
  b = input().split()
  hidari.append(b[0])
  migi.append(b[1])
  c.append(b)
  
countleft = collections.Counter(hidari)
countright = collections.Counter(migi)
leftmax = countleft.most_common()[0][1]
rightmax = countright.most_common()[0][1]
tempmax = int(leftmax + rightmax)
 
leftkeys = [k for k, v in countleft.items() if v == leftmax]
rightkeys = [k for k, v in countright.items() if v == rightmax]
 
leftkeyN = int(len(leftkeys))
rightkeyN = int(len(rightkeys))
flag = int(0)
cnt = int(0)



 
for i in range(M):
    goukei = int(countleft.get(c[i][0])) + int(countright.get(c[i][1]))
    if goukei == tempmax:
        cnt += 1
    else:
        pass

if cnt == int(leftkeyN * rightkeyN):
    print(int(tempmax - 1))
else:
    print(int(tempmax))
Problem: p02580
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
from collections import defaultdict
n,m,k=map(int,input().split())
points=set()
row=defaultdict(int)
col=defaultdict(int)
for i in range(k):
    a,b=map(int,input().split())
    points.add((a,b))
    row[a]+=1
    col[b]+=1
m1=max(row.values())
m2=max(col.values())
l1=[]
l2=[]
for i in row:
    if row[i]==m1:
        l1.append(i)
for i in col:
    if col[i]==m2:
        l2.append(i)
ans=m2+m1-1
for i in l1:
    for j in l2:
        if (i,j) not in points:
            print(i,j)
            ans+=1
            print(ans)
            quit()
print(ans)




Failing test case input:
5 5 10
2 2
4 5
2 3
5 5
2 4
1 4
5 1
5 1
3 5
1 1

Expected output:
6


Actual output:
2 5
6


Fixed submission (verdict: Accepted):
from collections import defaultdict
n,m,k=map(int,input().split())
points=set()
row=defaultdict(int)
col=defaultdict(int)
for i in range(k):
    a,b=map(int,input().split())
    points.add((a,b))
    row[a]+=1
    col[b]+=1
m1=max(row.values())
m2=max(col.values())
l1=[]
l2=[]
for i in row:
    if row[i]==m1:
        l1.append(i)
for i in col:
    if col[i]==m2:
        l2.append(i)
ans=m2+m1-1
for i in l1:
    for j in l2:
        if (i,j) not in points:
           
            ans+=1
            print(ans)
            quit()
print(ans)

Problem: p02580
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
h,w,m = map(int,input().split())
b = []
x = [0 for _ in range(w)]
y = [0 for _ in range(h)]
for i in range(m):
  bh,bw = map(int,input().split())
  bh -= 1
  bw -= 1
  b.append((bh,bw))
  x[bw] += 1
  y[bh] += 1


mxx = max(x)
mxy = max(y)

cmxb = 0
for by,bx in b:
  if y[by]+x[bx] == mxx+mxy-1:
    cmxb += 1
cmxx = 0
for xi in x:
  if xi == mxx:
    cmxx += 1
cmxy = 0
for yi in y:
  if yi == mxy:
    cmxy += 1


if cmxb >= cmxx*cmxy:
  print(mxx+mxy-1)
else:
  print(mxx+mxy)

Failing test case input:
5 7 10
1 5
4 5
2 2
5 5
2 2
5 4
5 4
5 1
4 5
2 2

Expected output:
7


Actual output:
8


Fixed submission (verdict: Accepted):
h,w,m = map(int,input().split())
b = []
x = [0 for _ in range(w)]
y = [0 for _ in range(h)]
for i in range(m):
  bh,bw = map(int,input().split())
  bh -= 1
  bw -= 1
  b.append((bh,bw))
  x[bw] += 1
  y[bh] += 1


mxx = max(x)
mxy = max(y)

cmxb = 0
for by,bx in b:
  if y[by]+x[bx] == mxx+mxy:
    cmxb += 1
cmxx = 0
for xi in x:
  if xi == mxx:
    cmxx += 1
cmxy = 0
for yi in y:
  if yi == mxy:
    cmxy += 1


if cmxb == cmxx*cmxy:
  print(mxx+mxy-1)
else:
  print(mxx+mxy)
Problem: p02580
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
H, W, M = map(int, input().split())

H_bom = [0 for i in range(H)]
W_bom = [0 for i in range(W)]
bom_map = [[0 for i in range(W)] for i in range(H)]

for i in range(M):
    M_temp = list(map(int, input().split()))
    H_bom[M_temp[0]-1] += 1
    W_bom[M_temp[1]-1] += 1
    bom_map[M_temp[0]-1][M_temp[1]-1] = 1


H_bom_max = max(H_bom)
W_bom_max = max(W_bom)
H_bom_line = []
W_bom_line = []

for i in range(H):
    if H_bom[i] == H_bom_max:
        H_bom_line.append(i)
for i in range(W):
    if W_bom[i] == W_bom_max:
        W_bom_line.append(i)

bom_check_flag = 0

for i in H_bom_line:
    for j in W_bom_line:
        if bom_map[i-1][j-1] == 1:
            print(H_bom_max + W_bom_max)
            bom_check_flag = 1
            break
if bom_check_flag == 0:
    print(H_bom_max + W_bom_max -1)


Failing test case input:
5 5 10
2 5
4 3
2 3
5 5
2 4
5 4
5 1
1 1
4 5
1 4

Expected output:
5


Actual output:
6
6


Fixed submission (verdict: Accepted):
H, W, M = map(int, input().split())

H_bomb = [0 for i in range(H)]
W_bomb = [0 for i in range(W)]
bomb_list = []

for i in range(M):
    M_temp = tuple(map(int, input().split()))
    H_bomb[M_temp[0]-1] += 1
    W_bomb[M_temp[1]-1] += 1
    bomb_list.append(M_temp)


H_bomb_max = max(H_bomb)
W_bomb_max = max(W_bomb)
H_bomb_line = []
W_bomb_line = []

for i in range(H):
    if H_bomb[i] == H_bomb_max:
        H_bomb_line.append(i)
for i in range(W):
    if W_bomb[i] == W_bomb_max:
        W_bomb_line.append(i)

bomb_set = set(bomb_list)
for i in H_bomb_line:
    for j in W_bomb_line:
        if (i+1, j+1) not in bomb_set:
            print(H_bomb_max + W_bomb_max)
            exit()
print(H_bomb_max + W_bomb_max - 1)
Problem: p02580
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
h,w,m = map(int,input().split())
H = [0]*(h+1)
W = [0]*(w+1)
s = set([])
for i in range(m):
    a,b = map(int,input().split())
    s.add((a,b))

    H[a] += 1
    W[b] += 1

x = [0]*(h+1)
y = [0]*(w+1)
    
for i in range(h+1):
    x[i] = [i,H[i]]
for i in range(w+1):
    y[i] = [i,W[i]]

x.sort(key= lambda val : val[1],reverse=True)
y.sort(key= lambda val : val[1],reverse=True)

ma = x[0][1]
mb = y[0][1]
i,j = 0,0
sw = 0
while 1:
    if (x[i][0],y[j][0]) in s:
        pass
    else:
        sw = 1
        break
    if x[i][1] + y[j][1] != ma+mb:
        break
    
    if x[i+1][1] != ma:
        j += 1
        i = 0
    else:
        i += 1
print(ma+mb+sw-1)


Failing test case input:
5 7 10
1 5
4 5
2 2
5 5
2 2
5 4
5 4
5 1
4 5
2 2

Expected output:
7


Actual output:
8


Fixed submission (verdict: Accepted):
import time

t0 = time.time()

h,w,m = map(int,input().split())
H = [0]*(h+1)
W = [0]*(w+1)
s = set([])
for i in range(m):
    a,b = map(int,input().split())
    s.add((a,b))

    H[a] += 1
    W[b] += 1

x = [0]*(h+1)
y = [0]*(w+1)
    
for i in range(h+1):
    x[i] = [i,H[i]]
for i in range(w+1):
    y[i] = [i,W[i]]

x.sort(key= lambda val : val[1],reverse=True)
y.sort(key= lambda val : val[1],reverse=True)

ma = x[0][1]
mb = y[0][1]

i,j = 0,0
sw = 0
while 1:
    if j > w:
        break
    if  x[i][1] == ma:
        if (x[i][0],y[j][0]) in s:
            pass
        else:
            if x[i][1]+y[j][1] == ma+mb:
                sw = 1
                break
        i += 1
    else:
        i = 0
        j += 1
    if time.time() - t0 > 2.5:
        break

    
print(ma+mb+sw-1)

Problem: p02580
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):


h, w, m = map(int, input().split())
hw_array = [list(map(int, input().split())) for _ in range(m)]

h_array = [0]*h
w_array = [0]*w

for hw in hw_array:
    h, w = hw
    h_array[h - 1] += 1
    w_array[w - 1] += 1

h_max = max(h_array)
h_argmax_array = [i for i in h_array if i == h_max]
w_max = max(w_array)
w_argmax_array = [j for j in w_array if j == w_max]

flag = False
for h_argmax in h_argmax_array:
    for w_argmax in w_argmax_array:
        if not [h_argmax + 1, w_argmax + 1] in hw_array:
            flag = True
            break

ans = h_max + w_max
if not flag:
    ans -= 1

print(ans)

Failing test case input:
2 3 3
2 2
1 1
1 2

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):


h, w, m = map(int, input().split())
hw_array = [list(map(int, input().split())) for _ in range(m)]

h_array = [0]*h
w_array = [0]*w

for hw in hw_array:
    h, w = hw
    h_array[h - 1] += 1
    w_array[w - 1] += 1

h_max = max(h_array)
h_argmax_array = [True if i == h_max else False for i in h_array]
w_max = max(w_array)
w_argmax_array = [True if j == w_max else False for j in w_array]

comb = sum(h_argmax_array) * sum(w_argmax_array)
for hw in hw_array:
    h, w = hw
    if h_argmax_array[h - 1] and w_argmax_array[w - 1]:
        comb -= 1
ans = h_max + w_max
if comb == 0:
    ans -= 1

print(ans)
Problem: p02580
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
h,w,m = map(int,input().split())
H = [0]*(h+1)
W = [0]*(w+1)
s = set([])
for i in range(m):
    a,b = map(int,input().split())
    s.add((a,b))

    H[a] += 1
    W[b] += 1

x = [0]*(h+1)
y = [0]*(w+1)
    
for i in range(h+1):
    x[i] = [i,H[i]]
for i in range(w+1):
    y[i] = [i,W[i]]

x.sort(key= lambda val : val[1],reverse=True)
y.sort(key= lambda val : val[1],reverse=True)

ma = x[0][1]
mb = y[0][1]

i,j = 0,0
sw = 0

xx = x.count(ma)
yy = y.count(mb)

for i in range(xx):
    for j in range(yy):
        if (x[i][0],y[j][0]) not in s:
            sw = 1
            break 
print(ma+mb+sw-1)


Failing test case input:
5 5 10
2 2
4 5
2 3
5 5
2 4
1 4
5 1
5 1
3 5
1 4

Expected output:
6


Actual output:
5


Fixed submission (verdict: Accepted):
import time

t0 = time.time()

h,w,m = map(int,input().split())
H = [0]*(h+1)
W = [0]*(w+1)
s = set([])
for i in range(m):
    a,b = map(int,input().split())
    s.add((a,b))

    H[a] += 1
    W[b] += 1

x = [0]*(h+1)
y = [0]*(w+1)
    
for i in range(h+1):
    x[i] = [i,H[i]]
for i in range(w+1):
    y[i] = [i,W[i]]

x.sort(key= lambda val : val[1],reverse=True)
y.sort(key= lambda val : val[1],reverse=True)

ma = x[0][1]
mb = y[0][1]

i,j = 0,0
sw = 0
while 1:
    if j > w:
        break
    if  x[i][1] == ma:
        if (x[i][0],y[j][0]) in s:
            pass
        else:
            if x[i][1]+y[j][1] == ma+mb:
                sw = 1
                break
        i += 1
    else:
        i = 0
        j += 1
    if time.time() - t0 > 2.5:
        break

    
print(ma+mb+sw-1)
Problem: p02580
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from collections import defaultdict
row=defaultdict(int)
col=defaultdict(int)
H,W,M=map(int,input().split())

matrix=defaultdict(bool)
for i in range(M):
    h,w=map(int,input().split())
    row[h-1]+=1
    col[w-1]+=1
    matrix[(h-1,w-1)]=True




temp=list(row.items())
temp.sort(key=lambda x:x[1])
a,b=temp[-1][0],temp[-1][1]
cnt=0
for i in range(W):
    temp=0
    if matrix[(a,i)]:
        temp=(b+col[i]-1)
    else:
        temp=(b+col[i])
    cnt=max(cnt,temp)

temp=list(col.items())
temp.sort(key=lambda x:x[1])
a,b=temp[-1][0],temp[-1][1]
cnt2=0
for i in range(H):
    temp=0
    if matrix[(a,i)]:
        temp=(b+row[i]-1)
    else:
        temp=(b+row[i])
    cnt2=max(cnt2,temp)
print(max(cnt,cnt2))

Failing test case input:
5 10 10
2 5
4 5
2 3
5 5
2 4
5 4
5 1
1 1
4 5
1 4

Expected output:
6


Actual output:
7


Fixed submission (verdict: Accepted):
from collections import defaultdict
row=defaultdict(int)
col=defaultdict(int)
H,W,M=map(int,input().split())

matrix=defaultdict(bool)
for i in range(M):
    h,w=map(int,input().split())
    row[h-1]+=1
    col[w-1]+=1
    matrix[(h-1,w-1)]=True




temp=list(row.items())
temp.sort(key=lambda x:x[1])
a,b=temp[-1][0],temp[-1][1]
cnt=0
for i in range(W):
    temp=0
    if matrix[(a,i)]:
        temp=(b+col[i]-1)
    else:
        temp=(b+col[i])
    cnt=max(cnt,temp)

temp=list(col.items())
temp.sort(key=lambda x:x[1])
a,b=temp[-1][0],temp[-1][1]
cnt2=0
for i in range(H):
    temp=0
    if matrix[(i,a)]:
        temp=(b+row[i]-1)
    else:
        temp=(b+row[i])
    cnt2=max(cnt2,temp)
print(max(cnt,cnt2))
Problem: p02922
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


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


A, B = map(int, input().split())

if A == B:
    print(1)
    exit()

count = 1
B -= A
while True:
    count += 1
    if A > B:
        print(count)
        exit()

    B -= A

Failing test case input:
2 50

Expected output:
49


Actual output:
26


Fixed submission (verdict: Accepted):


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


A, B = map(int, input().split())

if B == 1:
    print(0)
    exit()

if A >= B:
    print(1)
    exit()

count = 2
B -= (A-1)
while True:
    if A >= B:
        print(count)
        exit()

    count += 1
    B -= (A-1)

Problem: p02922
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
A = list(map(int,input().split(" ")))
B = math.ceil(A[1] / A[0])
print(B)

Failing test case input:
2 27

Expected output:
26


Actual output:
14


Fixed submission (verdict: Accepted):
import math
A,B = list(map(int,input().split(" ")))
print(math.ceil((B-1) / (A-1)))

Problem: p02922
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
A, B = map(int, input().split())
sum = 0
i = 1
if B != 1:
    sum = A
    while sum < B:
        sum += (A-1)*i
        i += 1
    print(i)
else:
    print(0)

Failing test case input:
2 50

Expected output:
49


Actual output:
11


Fixed submission (verdict: Accepted):
A, B = map(int, input().split())
sum = 0
i = 1
if B != 1:
    while sum < B:
        sum = A + (A-1)*(i-1)
        i += 1
    print(i-1)
else:
    print(0)

Problem: p02922
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
A, B = map(int, input().split())
a, c = 0, 1
while c < B:
  c += A
  a += 1
print(a)

Failing test case input:
4 16

Expected output:
5


Actual output:
4


Fixed submission (verdict: Accepted):
A, B = map(int, input().split())
a, c = 0, 1
while c < B:
  c += A - 1
  a += 1
print(a)

Problem: p02922
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
A,B=map(int,input().split())
count = 0
total = 0
if B==1:
  print(0)
else:
  while True:
    total += A
    count += 1
    if total>=B:
      break
      total -= 1
  print(count)

Failing test case input:
3 34

Expected output:
17


Actual output:
12


Fixed submission (verdict: Accepted):
A,B=map(int,input().split())
count = 0
total = 0
if B==1:
  print(0)
else:
  while True:
    total += A
    count += 1
    if total>=B:
      break
    total -= 1
  print(count)

Problem: p02922
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a,b = map(int,input().split(" "))
k = 1
while (a * k + 1) < b:
    k +=1
print(k)

Failing test case input:
2 50

Expected output:
49


Actual output:
25


Fixed submission (verdict: Accepted):
a,b = map(int,input().split(" "))
k = 0
while ((a-1) * k + 1) < b:
    k +=1
print(k)

Problem: p02922
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from math import ceil
A, B = map(int, input().split())
print(ceil(B/A))

Failing test case input:
3 59

Expected output:
29


Actual output:
20


Fixed submission (verdict: Accepted):
from math import ceil
A, B = map(int, input().split())
print(ceil((B - 1)/(A - 1)))
Problem: p02922
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
a, b = map(int, input().split())
num = a
for i in range(50):
    if num > b:
        break
    else:
        num -= 1
        num += a
print(i+1)

Failing test case input:
3 31

Expected output:
15


Actual output:
16


Fixed submission (verdict: Accepted):
a, b = map(int, input().split())
if b == 1:
    print(0)
    exit(0)
num = a
c = 1
while True:
    if num >= b:
        break
    else:
        num += a-1
        c += 1
print(c)

Problem: p02922
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
a, b = (int(i) for i in input().split())
count = 0
while True:
    b -= a
    count += 1
    if b <= 0: break
    b -= 1
print(count)

Failing test case input:
3 79

Expected output:
39


Actual output:
20


Fixed submission (verdict: Accepted):
a, b = (int(i) for i in input().split())
count = 0
if b == 1:
    print("0")
    exit()
while True:
    b -= a
    count += 1
    if b <= 0: break
    b += 1
print(count)

Problem: p02922
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def solve():
    N, M = map(int, input().split())

    c = 0
    if M == 1:
        return c

    c += 1
    if N >= M:
        return c
    
    M -= N
    for i in range(2, 100):
        if M - N <= 0:
            return i
        M -= (N-1)

print(solve())

Failing test case input:
2 46

Expected output:
45


Actual output:
44


Fixed submission (verdict: Accepted):
def solve():
    N, M = map(int, input().split())

    if M == 1:
        return 0
    
    
    diff = N-1
    sum = N
    c = 1
    while sum < M:
        sum += diff
        c += 1
    return c

print(solve())

Problem: p02922
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a,b = map(int,input().split())
c = 1 + (a-1)
ans = 0
if c <= b:
  ans += 1
  c += (a-1)
print(ans)
  

Failing test case input:
3 41

Expected output:
20


Actual output:
1


Fixed submission (verdict: Accepted):
a,b = map(int,input().split())
c = 1 
ans = 0
while c < b:
  c += a-1
  ans += 1
print(ans)

Problem: p02922
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a, b = map(int, input().split())

if b - a == 1:
  print(2)
else:
  print(round((b-1)/(a-1)))

Failing test case input:
4 8

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
a, b = map(int, input().split())

if (b - a) % (a - 1) == 0:
  print(round((b - a) / (a - 1) + 1))
else:
  print(round((b - a)

Problem: p02922
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
a,b = map(int,input().split())
sum = a
count = 1
while sum < b :
  sum += a
  count += 1
print (count)

Failing test case input:
2 13

Expected output:
12


Actual output:
7


Fixed submission (verdict: Accepted):
a,b = map(int,input().split())
sum = 1
count = 0
while sum < b :
  sum += a - 1
  count += 1
print (count)

Problem: p02922
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import math

a, b = map(int, input().split(' '))

print(math.ceil(b / a))


Failing test case input:
2 45

Expected output:
44


Actual output:
23


Fixed submission (verdict: Accepted):
import math

a, b = map(int, input().split(' '))

print(math.ceil((b - 1) / (a - 1)))
Problem: p02922
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
def resolve():
    a, b = map(int, input().split())
    ret = 0
    if b > 1:
        n, m = divmod(b, a)
        ret = n + (1 if m > 0 else 0)
    print(ret)


if __name__ == '__main__':
    resolve()

Failing test case input:
3 41

Expected output:
20


Actual output:
14


Fixed submission (verdict: Accepted):
def resolve():
    a, b = map(int, input().split())
    ret = 0
    if b > 1:
        from math import ceil
        ret = ceil((b - 1) / (a - 1))
    print(ret)


if __name__ == '__main__':
    resolve()

Problem: p02922
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a, b = map(int, input().split())

if a >= b:
    print(1)
    exit()
    
x = 2 * a - 1

for i in range(2, a + 1):
    if x >= b:
        print(i)
        exit()
    x = x + a - 1


Failing test case input:
2 36

Expected output:
35


Actual output:
no output


Fixed submission (verdict: Accepted):
a, b = map(int, input().split())

if b <= 1:
    print(0)
    exit()

x = a

for i in range(1, 100000):
    if x >= b:
        print(i)
        exit()
    x = x + a - 1

Problem: p02922
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
(A, B), = [list(map(int, s.split())) for s in open(0)]
if A >= B:
    print(1)
else:
    if (B - A)%(A - 1) == 0:
        print(int((B - A)/(A - 1) + 1))
    else:
        t = (B - A)
        while A + (A - 1)*(t - 1) < B:
            t += 1
        print(int(t))

Failing test case input:
5 20

Expected output:
5


Actual output:
15


Fixed submission (verdict: Accepted):
(A, B), = [list(map(int, s.split())) for s in open(0)]

if B == 1:
    print(0)
elif A >= B:
    print(1)
else:
    cnt = 1
    while True:
        if B <= A + (A - 1)*(cnt - 1):
            break
        cnt += 1
    print(cnt)

Problem: p02922
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
a,b = map(int,input().split())
print(math.ceil(a/b))

Failing test case input:
4 16

Expected output:
5


Actual output:
1


Fixed submission (verdict: Accepted):
import math
a,b = map(int,input().split())
print(math.ceil((b-a)/(a-1))+1)

Problem: p02922
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
A,B = map(int,input().split())
print(math.ceil(B/A))

Failing test case input:
2 29

Expected output:
28


Actual output:
15


Fixed submission (verdict: Accepted):
import math
A,B = map(int,input().split())
print(1+math.ceil((B-A)/(A-1)))

Problem: p02922
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a,b = map(int,input().split())
c = b 
if ((b > 1) and (b < a)) or (a==b):
    print(1)
elif b == 1:
    print(0)
else:
    print(c + 1)

Failing test case input:
2 36

Expected output:
35


Actual output:
37


Fixed submission (verdict: Accepted):
a,b = map(int,input().split())
sum = 1
if ((b > 1) and (b < a)):
    print(1)
elif b == 1:
    print(0)
else:
    b = b - a
    while 0 < b:
        b = b - (a-1)
        sum=sum+1
    print(sum)
Problem: p00006
Buggy submission (Python3, verdict: Wrong Answer):
txt = input("")
for i in range(0,len(txt)):
 print(txt[(len(txt)-i-1)],end="")
 print()


Failing test case input:
o5yf`o3m

Expected output:
m3o`fy5o


Actual output:
m
3
o
`
f
y
5
o


Fixed submission (verdict: Accepted):
txt = input("")
for i in range(0,len(txt)):
 print(txt[(len(txt)-i-1)],end="")
print()

Problem: p00006
Buggy submission (Python3, verdict: Wrong Answer):
print(input()[::-3])

Failing test case input:
rf5xno3a

Expected output:
a3onx5fr


Actual output:
anf


Fixed submission (verdict: Accepted):
print(input()[::-1])

Problem: p00006
Buggy submission (Python3, verdict: Wrong Answer):
import math
import sys

lines = input()
print(lines[0:len(lines)-1:-1])

Failing test case input:
o3o5mzfa

Expected output:
afzm5o3o


Actual output:
no output


Fixed submission (verdict: Accepted):
import math
import sys

lines = input()
print(lines[::-1])

Problem: p00006
Buggy submission (Python3, verdict: Wrong Answer):
print(input()[-1])


Failing test case input:
nx44alcl

Expected output:
lcla44xn


Actual output:
l


Fixed submission (verdict: Accepted):
print(input()[::-1])

Problem: p00006
Buggy submission (Python3, verdict: Wrong Answer):
import sys
print(sys.stdin.readline()[:-1:-1])

Failing test case input:
m5ny`fn4

Expected output:
4nf`yn5m


Actual output:
no output


Fixed submission (verdict: Accepted):
import sys
str = sys.stdin.readline()[:-1]
print(str[::-1])
Problem: p03326
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N, M = map(int, input().split())
cake = [list(map(int, input().split())) for _ in range(N)]

INF = 10 ** 18
dp = [[[-INF] * 8 for _ in range(M + 1)] for _ in range(N + 1)]
for i in range(8):
    dp[0][0][i] = 0

for i in range(1, N + 1):
    x, y, z = cake[i - 1]
    for j in range(M, 0, -1):
        for msk in range(8):
            mx = x * (1 - 2 * (msk >> 2 & 1))
            my = y * (1 - 2 * (msk >> 1 & 1))
            mz = z * (1 - 2 * (msk >> 0 & 1))
            dp[i][j][msk] = max(dp[i - 1][j][msk],
                                dp[i - 1][j - 1][msk] + mx + my + mz)

print(max(dp[N][M][i] for i in range(8)))

Failing test case input:
10 0
-1 -252 15
33 11 1
-94 45 1
0 -1 8
-123 60 656
-17 -195 -24
-26 0 4
42 24 -34
26 -17 5
-6 18 82

Expected output:
0


Actual output:
-1000000000000000000


Fixed submission (verdict: Accepted):
N, M = map(int, input().split())
cake = [list(map(int, input().split())) for _ in range(N)]

INF = 10 ** 18
dp = [[[-INF] * 8 for _ in range(M + 1)] for _ in range(N + 1)]
for i in range(N + 1):
    for msk in range(8):
        dp[i][0][msk] = 0

for i in range(1, N + 1):
    x, y, z = cake[i - 1]
    for j in range(1, M + 1):
        for msk in range(8):
            mx = x * (1 - 2 * (msk >> 2 & 1))
            my = y * (1 - 2 * (msk >> 1 & 1))
            mz = z * (1 - 2 * (msk >> 0 & 1))
            dp[i][j][msk] = max(dp[i - 1][j][msk],
                                dp[i - 1][j - 1][msk] + mx + my + mz)

print(max(dp[N][M][i] for i in range(8)))

Problem: p03326
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
xyz = [None] * N
for i in range(N):
    _x, _y, _z = map(int, input().split())
    xyz[i] = [_x, _y, _z]
ans = 0
for i in range(2):
    for j in range(2):
        for k in range(2):
            sx, sy, sz = (-1)**i, (-1)**j, (-1)**k
            xyz.sort(key = lambda v : -(sx * v[0] + sy * v[1] + sz * v[2]))
            X, Y, Z = 0, 0, 0
            for i in range(M):
                X += xyz[i][0]
                Y += xyz[i][1]
                Z += xyz[i][2]
            ans = max(ans, abs(X) + abs(Y) + abs(Z))
print(ans)

Failing test case input:
10 5
10 -80 21
23 16 3
-94 0 1
-26 -2 18
-69 72 79
-26 -86 -54
-87 -8 48
21 65 -25
25 -140 87
-62 18 82

Expected output:
657


Actual output:
646


Fixed submission (verdict: Accepted):
from itertools import product
import sys
def input():
    return sys.stdin.readline()[:-1]
N, M = map(int, input().split())
xyz = [None] * N
for i in range(N):
    _x, _y, _z = map(int, input().split())
    xyz[i] = [_x, _y, _z]
ans = 0
for i, j, k in product([0, 1], repeat=3):
    sx, sy, sz = (-1)**i, (-1)**j, (-1)**k
    xyz.sort(key = lambda v : -(sx * v[0] + sy * v[1] + sz * v[2]))
    X, Y, Z = 0, 0, 0
    for i in range(M):
        X += xyz[i][0]
        Y += xyz[i][1]
        Z += xyz[i][2]
    ans = max(ans, abs(X) + abs(Y) + abs(Z))
print(ans)
Problem: p03326
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
[N, M] = map(int, input().split())
a = [list(map(int, input().split())) for i in range(N)]
def value(xyz, sign):
	return sum([xyz[i]*(1 - 2*((sign & (1 << i)) >> i)) for i in range(3)])
print(max([sum([value(a[i], sign) for i in sorted([i for i in range(N)], key = lambda index : value(a[index], sign))[-M:]]) for sign in range(8)]))


Failing test case input:
10 0
-1 -252 15
33 11 1
-94 45 1
0 -1 8
-123 60 656
-17 -195 -24
-26 0 4
42 24 -34
26 -17 5
-6 18 82

Expected output:
0


Actual output:
1187


Fixed submission (verdict: Accepted):
[N, M] = map(int, input().split())
a = [list(map(int, input().split())) for i in range(N)]
def value(xyz, sign):
	return sum([xyz[i]*(1 - 2*((sign & (1 << i)) >> i)) for i in range(3)])
print(0 if M == 0 else max([sum([value(a[j], sign) for j in sorted([i for i in range(N)], key = lambda index : value(a[index], sign))[-M:]]) for sign in range(8)]))

Problem: p03326
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,m = map(int, input().split())
x = [tuple(map(int, input().split())) for _ in range(n)]
from itertools import *
res = 0
for a in product([-1, 1], [-1, 1], [-1, 1]):
  res = max(res, sum(sorted((max(0, sum(i*j for i,j in zip(a,t))) for t in x),reverse=True)[:m]))
print(res)

Failing test case input:
10 8
1 -80 11
10 12 6
-3 45 2
-1 -1 7
-57 118 159
-12 -79 -54
-26 2 6
21 65 -25
26 -140 99
-66 18 82

Expected output:
591


Actual output:
618


Fixed submission (verdict: Accepted):
n,m = map(int, input().split())
x = [tuple(map(int, input().split())) for _ in range(n)]
from itertools import *
res = 0
for a in product([-1, 1], [-1, 1], [-1, 1]):
  res = max(res, sum(sorted((sum(i*j for i,j in zip(a,t)) for t in x),reverse=True)[:m]))
print(res)

Problem: p03326
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys
input = sys.stdin.readline
from itertools import product
n, m = map(int, input().split())
xyz = [list(map(int, input().split())) for _ in range(n)]

ans = 0
for p in product([1, -1], repeat=3):
    dp = [0] * (m+1)
    for i in range(n):
        x, y, z = [s*t for s,t in zip(p, xyz[i])]
        for j in list(range(m))[::-1]:
            dp[j+1] = max(dp[j+1], dp[j]+x+y+z)
    ans = max(ans, dp[m])
print(ans)

Failing test case input:
5 5
1 -2 4
-4 5 -9
7 -8 -16
-10 7 -12
13 -3 15

Expected output:
26


Actual output:
48


Fixed submission (verdict: Accepted):
import sys
input = sys.stdin.readline
from itertools import product
n, m = map(int, input().split())
xyz = [list(map(int, input().split())) for _ in range(n)]

ans = 0
for p in product([1, -1], repeat=3):
    temp = []
    for x, y, z in xyz:
        x*=p[0];y*=p[1];z*=p[2]
        temp.append(x+y+z)
    temp.sort(reverse=True)
    ans = max(ans, sum(temp[:m]))
print(ans)