ZhenlongDai/ACPR huggingface dataset:
Problem: p02742
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def resolve():
    h, w = map(int, input().split())
    dy = h 
    if h == 1 or w == 1:
        count = 1
    elif h % 2 == 1:
        count = w * dy + (w-1)
    else:
        count = w * dy

    print(count)

if __name__ == '__main__':
    resolve()


Failing test case input:
-3 -8

Expected output:
12


Actual output:
15


Fixed submission (verdict: Accepted):
def resolve():
    h, w = map(int, input().split())
    dy = h 
    if h == 1 or w == 1:
        count = 1
    elif h % 2 == 1:
        count = w * dy + (w - (w 
    else:
        count = w * dy

    print(count)


if __name__ == '__main__':
    resolve()

Problem: p02742
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
value = input().split()
rows = int(value[0])
colmuns = int(value[1])
OddColNum = colmuns 
EvenColNum = OddColNum
if (colmuns % 2) != 0:
  OddColNum = OddColNum + 1

OddRowCount = rows 
EvenRowCount = rows 
if (OddRowCount % 2) != 0:
  OddRowCount = OddRowCount + 1

counts = OddRowCount * OddColNum + EvenColNum + EvenRowCount
  
print(counts)
    

Failing test case input:
0011101000 0111111001

Expected output:
616721611050500


Actual output:
1233443355414001


Fixed submission (verdict: Accepted):
value = input().split()
rows = int(value[0])
colmuns = int(value[1])


if colmuns == 1:
  rows = 1
elif rows == 1:
  colmuns = 1

OddColNum = colmuns 
EvenColNum = OddColNum
if (colmuns % 2) != 0:
  OddColNum = OddColNum + 1
if (colmuns == 1):
  OddColNum = 1

OddRowCount = 0
EvenRowCount = rows 
if (rows % 2) == 0:
  OddRowCount = rows 
else:
  OddRowCount = (rows 
if (rows == 1):
  OddRowCount = 1

counts = OddRowCount * OddColNum + EvenColNum * EvenRowCount
print(counts)

Problem: p02742
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
h,w=map(int,input().split())
if h == 1 or w == 1:
  print(1)
elif h%2 == 0 or w%2 == 0:
  print(h*w/2)
else:
  print(int(h*w/2)+1)
  


Failing test case input:
1001000111 1000000000

Expected output:
500500055500000000


Actual output:
5.005000555e+17


Fixed submission (verdict: Accepted):
h,w=map(int,input().split())
if h == 1 or w == 1:
  print(1)
elif h%2 == 0 or w%2 == 0:
  print(h*w
else:
  print(h*w

Problem: p02742
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
H,W=map(int,input().split())
if H%2==1 and W%2==1:
    print((H*W+1)/2)
else:
    print(H*W/2)

Failing test case input:
1000000111 1110010000

Expected output:
555005061605555000


Actual output:
5.55005061605555e+17


Fixed submission (verdict: Accepted):
H,W=map(int,input().split())
if H==1 or W==1:
    print(1)
else:
    if H%2==1 and W%2==1:
        print((H*W)
    else:
        print(H*W
Problem: p02742
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
hw = list(map(int, input().split()))

if hw[0] % 2 == 0 and hw[1] % 2 == 0:
    count = hw[0] * hw[1] 
elif hw[0] % 2 != 0 and hw[1] % 2 == 0:
    count = (hw[0] + 1) * hw[1] 
elif hw[0] % 2 == 0 and hw[1] % 2 != 0:
    count = (hw[1] + 1) * hw[0] 
else:
    count = (hw[0] + 1) * (hw[1] + 1) 
print(count)


Failing test case input:
1100110100 0010101111

Expected output:
5556167116160550


Actual output:
11112335332431200


Fixed submission (verdict: Accepted):
hw = list(map(int, input().split()))

if hw[0] == 1 or hw[1] == 1:
    count = 1
elif hw[0] % 2 == 0 and hw[1] % 2 == 0:
    count = (hw[0] * hw[1]) 
elif hw[0] % 2 != 0 and hw[1] % 2 == 0:
    count = ((hw[0] + 1) * hw[1] 
elif hw[0] % 2 == 0 and hw[1] % 2 != 0:
    count = ((hw[1] + 1) * hw[0] 
else:
    count = ((hw[0] + 1) * (hw[1] + 1) 
print(count)

Problem: p02742
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
h,w = (int(i) for i in input().split())

q_h,m_h = divmod(h,2)

if m_h == 0: 	
	print(w * q_h)
else:
	q_w,q_w = divmod(w,2)
	if q_w == 0:
		print(w * q_h + q_w)
	else:
		print(w * q_h + q_w + 1)

Failing test case input:
1000000111 1110000000

Expected output:
555000061605000000


Actual output:
555000061050000000


Fixed submission (verdict: Accepted):
h,w = (int(i) for i in input().split())

q_h,mod_h = divmod(h,2)

if h == 1 or w == 1:
	print(1)
elif mod_h == 0: 	
	print(w * q_h)
else:
	q_w,mod_w = divmod(w,2)
	if mod_w == 0:
		print(w * q_h + q_w)
	else:
		print(w * q_h + q_w + 1)
Problem: p02642
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import math
n=int(input(""))
aa=input("").split(" ")
lista=[]
for i in range(n):
    lista+=[int(aa[i])]
s=0
lista.sort()
listde=set()
for i in range(n-1):
    if(lista[i]==lista[i+1] ):
        listde.add(lista[i])
t=0
for i in range(n):
    t=0
    for k in listde:
        
        if (lista[i]%k==0):
            t=1
            break
    if (t==0):
        s+=1
        if(lista[i]<=math.sqrt(lista[n-1])):
            listde.add(lista[i])
print(s)
    
        


Failing test case input:
10
33 4 45 28 15 19 89 86 2 4

Expected output:
5


Actual output:
6


Fixed submission (verdict: Accepted):
n=int(input(""))
aa=input("").split(" ")
lista=[]
for i in range(n):
    lista+=[int(aa[i])]
lista.sort()
listtf=[]
s=0
for i in range(lista[n-1]):
    listtf+=[True]
for i in range(n):
    
    if(listtf[lista[i]-1]):
        if(i<n-1 and lista[i]==lista[i+1]):
            s-=1
        s+=1
        t=1
        while(t*lista[i]<=lista[n-1]):
            listtf[lista[i]*t-1]=False
            t+=1
print(s)

Problem: p02642
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from collections import deque 
n = int(input())
a = list(map(int, input().split()))
a.sort()
a = deque(a)
y = [min(a)]
t = 0
while a:
    v = a.popleft()
    x = 0
    for j in y:
        if v % j == 0:
            break
        else:
            x += 1
        if v == j:
            t += 1
        if x == len(y):
            y.append(v)
print(len(y) - t)

Failing test case input:
5
42 11 1 1 16

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
from collections import Counter
import bisect
n = int(input()) 
a = list(map(int, input().split())) 
cnt = Counter(a) 
a.sort()
ans = 0
mx = 10 ** 6
p = [0] * (mx + 1)
for i in a:
    if p[i] == 0:
        for j in range(mx + 1):
            x = i * j
            if x > mx:
                break
            p[x] = 1 
        if cnt[i] == 1:
            ans += 1 
print(ans)

Problem: p02642
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
arr = [int(x) for x in input().split()]
d = {}
for x in arr:
  d[x] = d.get(x,0)+1

mxN = 10**6 + 1
rp = [True]*mxN


for i in range(2,len(rp)):
  if i not in d or not rp[i]:continue
  for j in range(i+i,mxN,i):
    if j in d: rp[j] = False





for k,v in d.items():
  if v > 1:rp[k] = False

ans = sum([(1 if rp[x] else 0) for x in arr])
print(ans)





Failing test case input:
5
24 11 8 1 16

Expected output:
1


Actual output:
3


Fixed submission (verdict: Accepted):
n = int(input())
arr = [int(x) for x in input().split()]
d = {}
for x in arr:
  d[x] = d.get(x,0)+1

mxN = 10**6 + 1
rp = [True]*mxN

if 1 in d:
  if d[1] > 1:
    print(0)
    exit()
  else:
    print(1)
    exit()
for i in range(2,len(rp)):
  if i not in d or not rp[i]:continue
  for j in range(i+i,mxN,i):
    if j in d: rp[j] = False





for k,v in d.items():
  if v > 1:rp[k] = False

ans = sum([(1 if rp[x] else 0) for x in arr])
print(ans)
Problem: p02642
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
from collections import defaultdict

N = int(input())
A = list(map(int, input().split()))
A.sort()
dic = defaultdict(int)
for a in A:
    dic[a] += 1
ans = 0
for a in A:
    if dic[a] > 1: continue
    else:
        ans += 1
        idx = 1
        while a*idx <= 10**6:
            dic[a*idx] += 1
            idx += 1
print(ans)


Failing test case input:
10
11 2 41 2 8 25 89 28 2 4

Expected output:
4


Actual output:
5


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

N = int(input())
A = list(map(int, input().split()))
A.sort()
dic = defaultdict(int)
for a in A:
    dic[a] += 1
ctr = defaultdict(int)
ans = 0
for a in A:
    if dic[a] == 1 and ctr[a] == 0:
        ans += 1
    if ctr[a] == 0:
        m = 1
        while a*m <= 10**6:
            ctr[a*m] += 1
            m += 1
print(ans)

Problem: p02642
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict, Counter
import math

rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())
rlf = lambda: map(float, stdin.readline().split())

INF, NINF = float('inf'), float('-inf')

def main():
	n = int(rl())
	A = list(rli())
	Aset = set(A)
	if 1 in Aset:
		print(1)
		return
	Acnt = Counter(A)
	ans = 0
	for i, num in enumerate(A):
		div = 2
		flag = True
		if Acnt[num] > 1:
			continue
		while div*div <= num:
			if num % div == 0:
				other = num
				if div in Aset or other in Aset:
					flag = False
					break
			div += 1
		if flag:
			ans += 1
	print(ans)
	stdout.close()

if __name__ == "__main__":
	main()

Failing test case input:
10
59 18 45 46 8 19 89 86 2 7

Expected output:
6


Actual output:
5


Fixed submission (verdict: Accepted):
from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict, Counter
import math

rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())
rlf = lambda: map(float, stdin.readline().split())

INF, NINF = float('inf'), float('-inf')

def main():
	n = int(rl())
	A = list(rli())
	indices = defaultdict(lambda: [])
	Amax = NINF
	if 1 in indices:
		print(1 if len(indices[1]) == 1 else 0)
		return
	A.sort()	
	for i, num in enumerate(A):
		indices[num].append(i)
		Amax = max(Amax, num)
	set_false = set()
	dp = [1 for _ in range(n)]
	for i, num in enumerate(A):
		if i in set_false: continue
		if len(indices[num]) > 1:
			dp[i] = 0
		curr = num
		while curr <= Amax:
			for j in indices[curr]:
				if i == j: continue
				dp[j] = 0
				set_false.add(j)
			curr += num
	print(sum(dp))
	stdout.close()

if __name__ == "__main__":
	main()
Problem: p02642
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7

INF = 10**18
eps = 10**-7

import itertools

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

A.sort()

from collections import Counter
Ac = Counter(A)
A = []
for k,v in Ac.items():
    if v == 1:
        A.append(k)

check = [[True,False] for i in range(10**6+1)]
ans = 0
for a in A:
    if not check[a][0]:
        continue
    for j in range(2*a,10**6+1,a):
        check[j][0] = False

for a in A:
    if check[a][0]:
        ans += 1
print(ans)



Failing test case input:
5
42 11 1 1 16

Expected output:
0


Actual output:
3


Fixed submission (verdict: Accepted):
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7

INF = 10**18
eps = 10**-7

import itertools

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

A.sort()


check = [[False,False] for i in range(10**6+1)]
ans = 0
for a in A:
    if check[a][1]:
        check[a][0] = True
    if check[a][0]:
        continue
    for j in range(2*a,10**6+1,a):
        check[j][0] = True
    check[a][1] = True
 
for a in A:
    if not check[a][0]:
        ans += 1
print(ans)

Problem: p02642
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import sys











stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

def main():
    n = int(stdin.readline().rstrip())
    
    As = list(map(int, stdin.readline().rstrip().split()))
    
    
    
    
    As.sort(reverse=True)
    l = []
    l.append(As.pop())

    for i in range(1,n):
        t = As.pop()
        
        u = len(l)
        flag = False
        for j in range(u):
            if t%l[j] == 0:
                flag=True
        if flag==False:
            l.append(t)
    print(len(l))






main()


Failing test case input:
10
33 2 26 28 18 35 89 47 2 4

Expected output:
4


Actual output:
5


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










stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

def main():
    N = int(stdin.readline().rstrip())
    
    A = list(map(int, stdin.readline().rstrip().split()))
    A.sort()
    C = Counter(A)
    cannot = set()
    L= max(A)
    ans = 0
    for a in A:
        if a in cannot: continue
        if C[a] == 1:
            ans += 1
        ind = 1
        while a*ind <= L:
            cannot.add(a*ind)
            ind += 1

    print(ans)

main()
Problem: p02642
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))
a.sort()
MAX = int(1e6) + 10
sieve = [0] * int(MAX)
for i in a:
    sieve[i] += 1
ans = 0
for idx, val in enumerate(sieve):
    if val == 0:
        continue
    if val > 1:
        sieve[idx] = 0
        continue
    ans += 1
    for i in range(idx * 2, MAX, idx):
        sieve[i] = 0
print(ans)

Failing test case input:
10
33 2 26 28 8 42 89 86 2 4

Expected output:
2


Actual output:
6


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int, input().split()))
a.sort()
MAX = int(1e6) + 10
sieve = [0] * int(MAX)
for i in a:
    sieve[i] += 1
ans = 0
for idx, val in enumerate(sieve):
    if val == 0:
        continue
    elif val > 1:
        sieve[idx] = 0
    else:
        ans += 1
    for i in range(idx * 2, MAX, idx):
        sieve[i] = 0
print(ans)

Problem: p02642
Buggy submission (Python (3.8.2), verdict: Wrong Answer):

def main():
    import sys
    imput = sys.stdin.readline
    
    
    
    N = int(input())
    A = list(map(int, input().split()))

    
    from collections import Counter
    M = max(A) + 1
    B = [True] * (M)
    A = sorted(A)
    C = Counter(A)

    answer = 0
    for a in A:
        if C[a] > 1:
            continue
        elif B[a]:
            answer += 1
            for j in range(a, M, a):
                B[j] = False

    print(answer)

    
if __name__ == "__main__":
    main()


Failing test case input:
10
33 2 41 28 8 25 38 86 2 8

Expected output:
3


Actual output:
6


Fixed submission (verdict: Accepted):

def main():
    import sys
    imput = sys.stdin.readline
    
    
    
    N = int(input())
    A = list(map(int, input().split()))

    
    from collections import Counter
    M = max(A) + 1
    B = [True] * (M+1)
    A = sorted(A)
    C = Counter(A)

    answer = 0
    for a in A:
        if B[a]:
            for j in range(a, M, a):
                B[j] = False
            if C[a] > 1:
                continue
            else:
                answer += 1

    print(answer)

    
if __name__ == "__main__":
    main()
Problem: p02642
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import math
n=int(input(""))
aa=input("").split(" ")
lista=[]
for i in range(n):
    lista+=[int(aa[i])]
s=0
lista.sort()
cccc=int(lista[n-1]/lista[0])+1
listde=set()
for i in range(n-1):
    if(lista[i]==lista[i+1] ):
        listde.add(lista[i])
t=0
for i in range(n):
    t=0
    for k in listde:
        
        if (lista[i]%k==0):
            t=1
            break
    if (t==0):
        s+=1
        if(lista[i]<=cccc):
            listde.add(lista[i])
print(s)
    
        


Failing test case input:
5
36 11 9 5 17

Expected output:
4


Actual output:
5


Fixed submission (verdict: Accepted):
n=int(input(""))
aa=input("").split(" ")
lista=[]
for i in range(n):
    lista+=[int(aa[i])]
lista.sort()
listtf=[]
s=0
for i in range(lista[n-1]):
    listtf+=[True]
for i in range(n):
    
    if(listtf[lista[i]-1]):
        if(i<n-1 and lista[i]==lista[i+1]):
            s-=1
        s+=1
        t=1
        while(t*lista[i]<=lista[n-1]):
            listtf[lista[i]*t-1]=False
            t+=1
print(s)

Problem: p02642
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from collections import deque

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

A.sort()

ans = 0
max_A = max(A)
ban = [0]*(max_A+1)
again = list()

last = 0
for i in range(N-1):
    if A[i] == A[i+1] and A[i] != last:
        again.append(A[i])
        last = A[i]
if A[N-1] != A[N-2]:
    again.append(A[N-1])

for num in again:
    ban_num = num
    while ban_num <= max_A:
        ban[ban_num] = 1
        ban_num += num
 
for num in A:
    if ban[num] != 1:
        ans += 1
        ban_num = num
        while ban_num <= max_A:
            ban[ban_num] = 1
            ban_num += num

print(ans)

Failing test case input:
4
7 9 5 5

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
from collections import deque

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

A.sort()

ans = 0
max_A = max(A)
ban = [0]*(max_A+1)
again = list()

last = 0
for i in range(N-1):
    if A[i] == A[i+1] and A[i] != last:
        again.append(A[i])
        last = A[i]
if N > 1 and A[N-1] == A[N-2] and A[N-1] != last:
    again.append(A[N-1])

for num in again:
    ban_num = num
    while ban_num <= max_A:
        ban[ban_num] = 1
        ban_num += num
 
for num in A:
    if ban[num] != 1:
        ans += 1
        ban_num = num
        while ban_num <= max_A:
            ban[ban_num] = 1
            ban_num += num

print(ans)
Problem: p02642
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
def main():
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline
    from collections import Counter

    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    counter_A = Counter(A)
    flag = [True] * 1000001

    count = 0
    for i in A:
        if counter_A[i] > 1:
            continue
        if flag[i]:
            count += 1
        multiple = i
        while multiple < 1000001:
            flag[multiple] = False
            multiple += i

    print(count)


main()

Failing test case input:
10
33 2 26 28 8 35 89 86 2 4

Expected output:
3


Actual output:
6


Fixed submission (verdict: Accepted):
def main():
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline
    from collections import Counter

    N = int(input())
    A = list(map(int, input().split()))
    counter_A = Counter(A)
    flag = [True] * 1000001

    count = 0
    for i in sorted(counter_A.keys()):
        if counter_A[i] == 1 and flag[i]:
            count += 1
        multiple = i
        while multiple < 1000001:
            flag[multiple] = False
            multiple += i

    print(count)


main()

Problem: p02642
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
inf =  1000005
def main():
  N =  int(input())
  a = list(map(int, input().split()))
  a.sort()
  detect = [0] *inf
  for i in range(N):
    detect[a[i]] += 1
    if detect[a[i]] >= 2:
      continue
    j = 2
    while (a[i]*j < inf):
      if detect[a[i]*j] >= 2:
        break
      else:
        detect[a[i]*j] += 2
        j+=1
  ans = 0
  for i in range(N):
    if detect[a[i]] == 1:
      ans += 1
  print(ans)
  
if __name__ == "__main__":
  main()

Failing test case input:
10
11 3 41 17 8 52 89 28 3 4

Expected output:
5


Actual output:
7


Fixed submission (verdict: Accepted):
inf =  1100000
def main():
  N =  int(input())
  a = list(map(int, input().split()))
  a.sort()
  detect = [0] *inf
  for x in a:
    if detect[x] != 0:
      detect[x] = 2
      continue
    for i in range(x, inf, x):
      detect[i] += 1
  ans = 0
  for i in range(N):
    if detect[a[i]] == 1:
      ans += 1
  print(ans)
  
if __name__ == "__main__":
  main()

Problem: p02642
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n = int(input())
a = list(map(int,input().split()))

a.sort()
li = [True] * (10**6 + 10)
ans = 0

for i in range(n):
    if not li[a[i]]:
        continue
    li[a[i]] = False
    if i < n-1:
        if a[i+1] == a[i]:
            continue
    ans += 1
    tmp = a[i]
    while tmp < len(li):
        li[tmp] = False
        tmp += a[i]

print(ans)


Failing test case input:
10
33 2 41 28 8 25 38 86 2 4

Expected output:
3


Actual output:
6


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

a.sort()
li = [True] * (10**6 + 10)
ans = 0

for i in range(n):
    if not li[a[i]]:
        continue
    li[a[i]] = False
    tmp = a[i]
    while tmp < len(li):
        li[tmp] = False
        tmp += a[i]
    if i < n-1:
        if a[i+1] == a[i]:
            continue
    ans += 1


print(ans)
Problem: p02642
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
from itertools import islice
def solve(A):
    memo = [0]*(10**6+1)

    for a in A:
        memo[a] += 1
    if memo[1] > 0:
        return 1 if memo[1] == 1 else 0

    res = 0
    for i,v in enumerate(islice(memo,2,None),start=2):
        if v > 0:
            res += v
            j = i
            while j <= 10**6:
                memo[j] = 0
                j += i
    return res

if __name__ == '__main__':
    N = int(input())
    A = list(map(int,input().split()))
    print(solve(A))


Failing test case input:
10
60 2 26 28 8 42 89 86 2 4

Expected output:
1


Actual output:
3


Fixed submission (verdict: Accepted):
from itertools import islice
def solve(A):
    memo = [0]*(10**6+1)

    for a in A:
        memo[a] += 1
    if memo[1] > 0:
        return 1 if memo[1] == 1 else 0

    res = 0
    for i,v in enumerate(islice(memo,2,None),start=2):
        if v > 0:
            res += 1 if v == 1 else 0
            j = i
            while j <= 10**6:
                memo[j] = 0
                j += i
    return res

if __name__ == '__main__':
    N = int(input())
    A = list(map(int,input().split()))
    print(solve(A))

Problem: p02642
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
from collections import Counter as c
n = int(input())
a = list(map(int,input().split()))
a.sort()

count, a_max = 0, a[-1]
li = [-1] * (a_max+1)

for i in a:
  if li[i] == -1:
    count += 1
    li[i] = 0
  li[i] += 1
  j = 2
  while i * j <= a_max:
    li[i*j] = 0
    j += 1

li.sort(reverse=True)
for i in li:
  if i == 1 or i == 0 or i == -1: break
  count -= 1

print(count)

Failing test case input:
10
33 4 45 28 15 19 89 86 2 4

Expected output:
5


Actual output:
4


Fixed submission (verdict: Accepted):
from collections import Counter as c
n = int(input())
a = list(map(int,input().split()))
a.sort()

count, a_max = 0, a[-1]
li = [True] * (a_max+1)

for i in a:
  if li[i] == "x":
    count -= 1
    li[i] = "y"

  if li[i] == True:
    count += 1
    li[i] = "x"

  j = 2
  while i * j <= a_max:
    li[i*j] = False
    j += 1

print(count)

Problem: p02642
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
from collections import Counter
import bisect
N = int(input())
A = list(map(int,input().split()))



cnt = Counter(A)
A.sort()
ans = 0
for i in range(len(A)):
    if cnt[A[i]] > 1:
        continue
    idx = bisect.bisect_right(A, pow(A[i],0.5))
    J = min(idx+1,i)
    
    ok = True
    for j in range(J):
        
        if A[i] % A[j] == 0:
            ok = False
            break
    if ok:
        ans += 1
print (ans)



Failing test case input:
10
11 3 41 17 8 33 89 28 3 4

Expected output:
5


Actual output:
6


Fixed submission (verdict: Accepted):
from collections import Counter
import bisect
N = int(input())
A = list(map(int,input().split()))



cnt = Counter(A)
A.sort()
ans = 0
P = [0] * (10**6+1)

for a in A:
    if P[a]==0:
        for i in range(10**7):
            x = a*i
            if x>10**6:
                break
            P[x] = 1
        if cnt[a]==1:
            ans +=1

print (ans)
Problem: p02642
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
def main():
    import sys
    def input(): return sys.stdin.readline().rstrip()
    n = int(input())
    a = list(map(int, input().split()))
    a = list(set(a))
    a_max = max(a)
    is_divable = [True]*(a_max+1)
    ans = 0
    is_divable[0],is_divable[1] = False,False
    for el in a:
        if is_divable[el]:
            ans +=1
            k = 2
            while k*el <= a_max:
                is_divable[k*el] = False
                k+=1
    print(ans)


if __name__ == '__main__':
    main()


Failing test case input:
4
6 8 2 5

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
def main():
    import sys
    def input(): return sys.stdin.readline().rstrip()
    n = int(input())
    a = list(map(int, input().split()))
    a.sort()
    a_max = a[-1]
    is_divisible = [True]*(a_max+1)
    ans = 0
    is_divisible[0]= False
    el_old = 0
    for el in a:
        if is_divisible[el]:
            if el == el_old:
                ans-=1
                is_divisible[el] = False
                continue
            ans +=1
            k = 2
            while k*el <= a_max:
                is_divisible[k*el] = False
                k+=1
        el_old = el
    print(ans)


if __name__ == '__main__':
    main()

Problem: p02642
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from sys import stdin
data = stdin.readlines()

n = int(data[0].split()[0])
a = [int(s) for s in data[1].split()]
a = sorted(a)

max = a[-1]
print(max)

l = [0]*(max+1)

for i in a:
    l[i] += 1
    if l[i] == 1:
        for j in range(i*2,max+1,i):
            l[j] = 2
print(l.count(1))

Failing test case input:
5
36 11 8 3 17

Expected output:
4


Actual output:
36
4


Fixed submission (verdict: Accepted):
from sys import stdin
data = stdin.readlines()

n = int(data[0].split()[0])
a = [int(s) for s in data[1].split()]
a = sorted(a)

max = a[-1]

l = [0]*(max+1)

for i in a:
    l[i] += 1
    if l[i] == 1:
        for j in range(i*2,max+1,i):
            l[j] = 2
print(l.count(1))

Problem: p02642
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n = int(input())
li = list(map(int,input().split()))
ans = 0

import math
import bisect
import collections
c = collections.Counter(li)
li = list(set(li))

while len(li)>0:
    ba = li.pop(-1)
    if c[ba]>1:
        continue
    
    
    tmp_li = li
    
    for tt in tmp_li:
        if ba%tt == 0:
            break
    else:
        ans += 1
print(ans)

Failing test case input:
10
11 3 41 17 8 33 89 28 3 4

Expected output:
5


Actual output:
6


Fixed submission (verdict: Accepted):
n = int(input())
li = list(map(int,input().split()))
ans = 0
cnt_li = [0]*(10**6+1)

import math
import bisect
import collections
c = collections.Counter(li)
li = list(set(li))
li.sort()

for l in li:
    for x in range(2,10**7):
        if x*l > (10**6):
            break
        else:
            cnt_li[x*l] += 1


while len(li)>0:
    ba = li.pop(-1)
    if c[ba]>1:
        continue
    if cnt_li[ba] == 0:
        ans += 1
print(ans)
Problem: p02919
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N = int(input())
P = list(map(int,input().split()))

b = [0] * (N + 1)
l1 = [max(i-1,-1) for i in range(N)]
r1 = [min(i+1,N) for i in range(N)]
l2 = [max(i-2,-1) for i in range(N)]
r2 = [min(i+2,N) for i in range(N)]

ans = 0
for i in range(N):
    b[P[i]-1] = i 
for i in range(N):
    m = b[i] 
    x1,y1,x2,y2 = l1[m] , r1[m] , l2[m] ,r2[m]
    ans += (i+1) * ((x1-x2) * (y1-m+1) + (y1-y2) * (m-x1))
    
    
    
    if x2 >=0:
        r1[x2] = x1
        r2[x2] = y1
    
    if x1 >= 0:
        r1[x1] = y1 
        r2[x1] = y2
    
    if y1 < N:
        l2[y1] = x2 
        l1[y1] = x1    
    
    if y2 < N:
        l2[y2] = x1
        l1[y2] = y1
print(ans)

Failing test case input:
5
1 3 2 4 5

Expected output:
29


Actual output:
-17


Fixed submission (verdict: Accepted):
N = int(input())
P = [0]+list(map(int,input().split()))+[N+1]
ans = 0
b = [0]*(N+2)
for i in range(N+2):
    b[P[i]] = i
l1 = [max(0,i-1) for i in range(N+2)]
l2 = [max(0,i-2) for i in range(N+2)]
r1 = [min(N+1,i+1) for i in range(N+2)]
r2 = [min(N+1,i+2) for i in range(N+2)]

for i in range(N+1):
    m = b[i]
    x2,x1,y1,y2 = l2[m],l1[m],r1[m],r2[m]
    hoge= i*(abs((m-x1)*(y2-y1)) + abs((y1-m)*(x1-x2)))
    ans += hoge
    
    r1[x1] = y1
    r2[x1] = y2
    
    l1[y1] = x1
    l2[y1] = x2
    
    r1[x2] = x1
    r2[x2] = y1
    
    l1[y2] = y1
    l2[y2] = x1
print(ans)
Problem: p02919
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):





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

In = [0] * (N+1)
for i in range(N):
  In[Pn[i]] = i+1
print(Pn)
print(In)

cnt = 0
l = [0] + [i for i in range(N+1)]
r = [i+1 for i in range((N+1))] + [N+1]

for v in range(1, N+1):
  i = In[v]
  
  l1 = l[i]
  l2 = l[l1]
  r1 = r[i]
  r2 = r[r1]
  cnt += ((l1-l2) * (r1-i) + (i-l1) * (r2-r1)) * v
  
  l[r1] = l1
  r[l1] = r1
    
print(cnt)


Failing test case input:
5
1 3 2 4 5

Expected output:
29


Actual output:
[1, 3, 2, 4, 5]
[0, 1, 3, 2, 4, 5]
29


Fixed submission (verdict: Accepted):





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

In = [0] * (N+1)
for i in range(N):
  In[Pn[i]] = i+1

cnt = 0
l = [0] + [i for i in range(N+1)]
r = [i+1 for i in range((N+1))] + [N+1]

for v in range(1, N+1):
  i = In[v]
  
  l1 = l[i]
  l2 = l[l1]
  r1 = r[i]
  r2 = r[r1]
  cnt += ((l1-l2) * (r1-i) + (i-l1) * (r2-r1)) * v
  
  l[r1] = l1
  r[l1] = r1
    
print(cnt)
Problem: p01359
Buggy submission (Python3, verdict: Wrong Answer):
inputnum,outputnum = (int(n) for n in input().split(' '))
data = {}
while True:
    for i in range(inputnum):
        temp = input().split(' ')
        data[temp[0]] = [int(temp[2]) - int(temp[1]) + 1,int(temp[2])]
    for o in range(outputnum):
        targ = int(input())
        for k,v in data.items():
            if v[0] <= targ  <= v[1]:
                print(k + ' ' + str(targ-v[0] + 1))
                break
        else:
            print("Unknown")
    inputnum,outputnum = (int(n) for n in input().split(' '))
    if inputnum == outputnum == 0:
        break

Failing test case input:
4 3
meiji 15 1877
taisho 4 1917
rhoaw 62 1987
heisei 32 2010
2046
1917
1988
1 1
universalbentury 123 2168
2010
0 0

Expected output:
Unknown
taisho 4
heisei 10
Unknown


Actual output:
Unknown
taisho 4
heisei 10
heisei 32


Fixed submission (verdict: Accepted):
inputnum,outputnum = (int(n) for n in input().split(' '))
while True:
    data = {}
    for i in range(inputnum):
        temp = input().split(' ')
        data[temp[0]] = [int(temp[2]) - int(temp[1]) + 1,int(temp[2])]
    for o in range(outputnum):
        targ = int(input())
        for k,v in data.items():
            if v[0] <= targ  <= v[1]:
                print(k + ' ' + str(targ-v[0] + 1))
                break
        else:
            print("Unknown")
    inputnum,outputnum = (int(n) for n in input().split(' '))
    if inputnum == outputnum == 0:
        break
Problem: p02962
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    MOD = 2**61-1
    SI = lambda : sys.stdin.readline().rstrip()

    s = SI()
    t = SI()
    lens = len(s)
    lent = len(t)

    def cx(x):
        return ord(x) - ord('a') + 1

    hsh = 0
    for x in t:
        hsh = (hsh * 27 + cx(x)) % MOD

    cnt = 0
    f = False
    h = 0
    last_i = 0
    ans = 0
    i = 0
    while True:
        if i >= lent:
            h -= cx(s[(i - lent)%lens]) * pow(27,lent-1,MOD)
        h = (h * 27 + cx(s[i % lens])) % MOD
        if h == hsh:
            cnt += 1
            ans = max(ans,cnt)
            last_i = i
        else:
            if i - last_i >= lent and ans > 0:
                cnt = 0
                f = True
        if i > lens*2 and i > lent:
            break
        i += 1

    if f or ans == 0:
        print(ans)
    else:
        print(-1)

if __name__ == '__main__':
    main()

Failing test case input:
aa`bdca
aa

Expected output:
1

Actual output:
2


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

def main():
    MOD = 2**61-1
    SI = lambda : sys.stdin.readline().rstrip()

    s = SI()
    t = SI()
    lens = len(s)
    lent = len(t)

    def cx(x):
        return ord(x) - ord('a') + 1

    hsh = 0
    for x in t:
        hsh = (hsh * 26 + cx(x)) % MOD

    n = (lens+lent) * 2 + 1
    dp = [0] * n

    h = 0
    ans = 0
    for i in range(n):
        if i >= lent:
            h -= cx(s[(i - lent)%lens]) * pow(26,lent-1,MOD)
        h = (h * 26 + cx(s[i % lens])) % MOD
        if h == hsh:
            if i < lent:
                dp[i] = 1
            else:
                dp[i] = dp[i-lent] + 1
            ans = max(ans,dp[i])

    if n - ans * lent < lent * 2:
        print(-1)
    else:
        print(ans)

if __name__ == '__main__':
    main()
Problem: p02962
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
s = input()
t = input()

def z_algorithm(s):
    a = [0] * len(s)
    i = 1
    j = 0
    a[0] = len(s)
    while i < len(s):
        while i + j < len(s) and s[j] == s[i+j]:
            j += 1
        a[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while i + k < len(s) and k + a[k] < j:
            a[i+k] = a[k]
            k += 1
        i += k
        j -= k
    return a

def solve(i, li):
    ans = 0
    while True:
        if i < 0 or len(li) <= i or visited[i]:
            break
        if li[i] < len(t):
            visited[i] = True
            break
        if li[i] >= len(t):
            visited[i] = True
            ans += 1
            i += len(t)
    return ans


new_s = ""
while True:
    new_s += s
    if len(new_s) > len(t):
        s = new_s
        break
print(1)
exit()

s = s*3
li = z_algorithm(t + s)[len(t):]
visited = [False] * len(li)
ans1 = 0
for i in range(len(li)):
    ans1 = max(ans1, solve(i, li))

s += s
li = z_algorithm(t + s)[len(t):]
visited = [False] * len(li)
ans2 = 0
for i in range(len(li)):
    ans2 = max(ans2, solve(i, li))

if ans1 == ans2:
    print(ans1)
else:
    print(-1)


Failing test case input:
aa`bdcb
^_

Expected output:
0

Actual output:
1


Fixed submission (verdict: Accepted):
s = input()
t = input()

def z_algorithm(s):
    a = [0] * len(s)
    i = 1
    j = 0
    a[0] = len(s)
    while i < len(s):
        while i + j < len(s) and s[j] == s[i+j]:
            j += 1
        a[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while i + k < len(s) and k + a[k] < j:
            a[i+k] = a[k]
            k += 1
        i += k
        j -= k
    return a

def solve(i, li):
    ans = 0
    while True:
        if i < 0 or len(li) <= i or visited[i]:
            break
        if li[i] < len(t):
            visited[i] = True
            break
        if li[i] >= len(t):
            visited[i] = True
            ans += 1
            i += len(t)
    return ans


new_s = s
while True:
    if len(new_s) > len(t):
        s = new_s
        break
    new_s += new_s

s = s*3
li = z_algorithm(t + s)[len(t):]
visited = [False] * len(li)
ans1 = 0
for i in range(len(li)):
    ans1 = max(ans1, solve(i, li))

s += s
li = z_algorithm(t + s)[len(t):]
visited = [False] * len(li)
ans2 = 0
for i in range(len(li)):
    ans2 = max(ans2, solve(i, li))

if ans1 == ans2:
    print(ans1)
else:
    print(-1)
Problem: p02962
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    MOD = 2**61-1
    SI = lambda : sys.stdin.readline().rstrip()

    s = SI()
    t = SI()
    s = s * 2
    lens = len(s)
    lent = len(t)

    def cx(x):
        return ord(x) - ord('a') + 1

    hash = 0
    for x in t:
        hash = (hash * 26 + cx(x)) % MOD

    cnt = 0
    f = False
    h = 0
    last_i = 0
    ans = 0
    for i in range(lens):
        if i >= lent:
            h -= cx(s[i-lent]) * pow(26,lent-1,MOD)
        h = (h * 26 + cx(s[i])) % MOD
        if h == hash:
            cnt += 1
            ans = max(ans,cnt)
            last_i = i
        else:
            if i - last_i >= lent:
                cnt = 0
                f = True
    if f:
        print(ans)
    else:
        print(-1)

if __name__ == '__main__':
    main()

Failing test case input:
b`
baaa`a`

Expected output:
0

Actual output:
-1


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

def main():
    MOD = 2**61-1
    SI = lambda : sys.stdin.readline().rstrip()

    s = SI()
    t = SI()
    lens = len(s)
    lent = len(t)

    def cx(x):
        return ord(x) - ord('a') + 1

    hsh = 0
    for x in t:
        hsh = (hsh * 26 + cx(x)) % MOD

    n = (lens+lent) * 2 + 1
    dp = [0] * n

    h = 0
    ans = 0
    for i in range(n):
        if i >= lent:
            h -= cx(s[(i - lent)%lens]) * pow(26,lent-1,MOD)
        h = (h * 26 + cx(s[i % lens])) % MOD
        if h == hsh:
            if i < lent:
                dp[i] = 1
            else:
                dp[i] = dp[i-lent] + 1
            ans = max(ans,dp[i])

    if n - ans * lent < lent * 2:
        print(-1)
    else:
        print(ans)

if __name__ == '__main__':
    main()
Problem: p02962
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
s = input()
t = input()

def z_algorithm(s):
    a = [0] * len(s)
    i = 1
    j = 0
    a[0] = len(s)
    while i < len(s):
        while i + j < len(s) and s[j] == s[i+j]:
            j += 1
        a[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while i + k < len(s) and k + a[k] < j:
            a[i+k] = a[k]
            k += 1
        i += k
        j -= k
    return a

def solve(i, li):
    ans = 0
    while True:
        if i < 0 or len(li) <= i or visited[i]:
            break
        if li[i] < len(t):
            visited[i] = True
            break
        if li[i] >= len(t):
            visited[i] = True
            ans += 1
            i += len(t)
    return ans


new_s = ""
while True:
    new_s += s
    if len(new_s) > len(t):
        s = new_s
        break

s = s
li = z_algorithm(t + s)[len(t):]
visited = [False] * len(li)
ans1 = 0
for i in range(len(li)):
    ans1 = max(ans1, solve(i, li))

print(ans1)

Failing test case input:
ab`bdca
aa

Expected output:
1

Actual output:
0


Fixed submission (verdict: Accepted):
s = input()
t = input()

def z_algorithm(s):
    a = [0] * len(s)
    i = 1
    j = 0
    a[0] = len(s)
    while i < len(s):
        while i + j < len(s) and s[j] == s[i+j]:
            j += 1
        a[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while i + k < len(s) and k + a[k] < j:
            a[i+k] = a[k]
            k += 1
        i += k
        j -= k
    return a

def solve(i, li):
    ans = 0
    while True:
        if i < 0 or len(li) <= i or visited[i]:
            break
        if li[i] < len(t):
            visited[i] = True
            break
        if li[i] >= len(t):
            visited[i] = True
            ans += 1
            i += len(t)
    return ans


new_s = s
while True:
    if len(new_s) > len(t):
        s = new_s
        break
    new_s += new_s

s = s*3
li = z_algorithm(t + s)[len(t):]
visited = [False] * len(li)
ans1 = 0
for i in range(len(li)):
    ans1 = max(ans1, solve(i, li))

s += s
li = z_algorithm(t + s)[len(t):]
visited = [False] * len(li)
ans2 = 0
for i in range(len(li)):
    ans2 = max(ans2, solve(i, li))

if ans1 == ans2:
    print(ans1)
else:
    print(-1)
Problem: p02962
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def LcpByZ(target):
    len_t = len(target)
    lcp = [-1] * len_t
    top = 1  
    left = 0  
    right = 0  
    lcp[0] = 0
    while top < len_t:
        
        while top + right < len_t and target[right] == target[top + right]:
            right += 1
        
        lcp[top] = right
        left = 1
        
        if right == 0:
            top += 1
            continue
        
        while left + lcp[left] < right and left < right:
            lcp[top + left] = lcp[left]
            left += 1
        
        top += left
        right -= left
        left = 0  
    return lcp

def main():
    tt = t + t
    while len(tt) < len(s): tt += t
    ss = s
    while len(ss) < len(tt) * 2: ss += s
    
    if tt in ss:return -1

    while len(tt) < len(ss): tt += t
    lcp=LcpByZ(tt+"@"+ss)
    
    tn=len(t)
    ans=max(lcp[len(tt):])
    return ans

s=SI()
t=SI()
print(main())



Failing test case input:
^^c
c`_aa

Expected output:
0

Actual output:
1


Fixed submission (verdict: Accepted):
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def LcpByZ(target):
    len_t = len(target)
    lcp = [-1] * len_t
    top = 1  
    left = 0  
    right = 0  
    lcp[0] = 0
    while top < len_t:
        
        while top + right < len_t and target[right] == target[top + right]:
            right += 1
        
        lcp[top] = right
        left = 1
        
        if right == 0:
            top += 1
            continue
        
        while left + lcp[left] < right and left < right:
            lcp[top + left] = lcp[left]
            left += 1
        
        top += left
        right -= left
        left = 0  
    return lcp

def dfs(i,si):
    dp[i]=0
    ni=(i+tn)%sn
    if lcp[tn+1+ni]!=tn:return False
    if ni==si:return True
    if dp[ni]==-1 and dfs(ni,si):return True
    dp[i]=dp[ni]+1

s=SI()
t=SI()
ss = s
while len(ss) < len(s) + len(t): ss += s
lcp = LcpByZ(t + "@" + ss)
sn = len(s)
tn = len(t)
dp=[-1]*sn
for i in range(sn):
    if dp[i]!=-1:continue
    if dfs(i,i):
        print(-1)
        exit()
print(max(dp))
Problem: p02962
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    MOD = 2**61-1
    SI = lambda : sys.stdin.readline().rstrip()

    s = SI()
    t = SI()
    s = s * 3
    lens = len(s)
    lent = len(t)

    def cx(x):
        return ord(x) - ord('a') + 1

    hash = 0
    for x in t:
        hash = (hash * 26 + cx(x)) % MOD

    cnt = 0
    f = False
    h = 0
    last_i = 0
    ans = 0
    for i in range(lens):
        if i >= lent:
            h -= cx(s[i-lent]) * pow(26,lent-1,MOD)
        h = (h * 26 + cx(s[i])) % MOD
        if h == hash:
            cnt += 1
            ans = max(ans,cnt)
            last_i = i
        else:
            if i - last_i >= lent and last_i > 0:
                cnt = 0
                f = True
    if f:
        print(ans)
    else:
        print(-1)

if __name__ == '__main__':
    main()

Failing test case input:
^^b
c`_a`

Expected output:
0

Actual output:
-1


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

def main():
    MOD = 2**61-1
    SI = lambda : sys.stdin.readline().rstrip()

    s = SI()
    t = SI()
    lens = len(s)
    lent = len(t)

    def cx(x):
        return ord(x) - ord('a') + 1

    hsh = 0
    for x in t:
        hsh = (hsh * 26 + cx(x)) % MOD

    n = (lens+lent) * 2 + 1
    dp = [0] * n

    h = 0
    ans = 0
    for i in range(n):
        if i >= lent:
            h -= cx(s[(i - lent)%lens]) * pow(26,lent-1,MOD)
        h = (h * 26 + cx(s[i % lens])) % MOD
        if h == hsh:
            if i < lent:
                dp[i] = 1
            else:
                dp[i] = dp[i-lent] + 1
            ans = max(ans,dp[i])

    if n - ans * lent < lent * 2:
        print(-1)
    else:
        print(ans)

if __name__ == '__main__':
    main()
Problem: p02962
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    MOD = 2**61-1
    SI = lambda : sys.stdin.readline().rstrip()

    u = SI()
    t = SI()
    s = u * 2
    while len(s) < len(t):
        s = s + u
    lens = len(s)
    lent = len(t)

    def cx(x):
        return ord(x) - ord('a') + 1

    hash = 0
    for x in t:
        hash = (hash * 26 + cx(x)) % MOD

    cnt = 0
    f = False
    h = 0
    last_i = 0
    ans = 0
    for i in range(lens):
        if i >= lent:
            h -= cx(s[i-lent]) * pow(26,lent-1,MOD)
        h = (h * 26 + cx(s[i])) % MOD
        if h == hash:
            cnt += 1
            ans = max(ans,cnt)
            last_i = i
        else:
            if i - last_i >= lent and i >= lent:
                cnt = 0
                f = True
    if f or ans == 0:
        print(ans)
    else:
        print(-1)

if __name__ == '__main__':
    main()

Failing test case input:
aa`bdca
aa

Expected output:
1

Actual output:
2


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

def main():
    MOD = 2**61-1
    SI = lambda : sys.stdin.readline().rstrip()

    s = SI()
    t = SI()
    lens = len(s)
    lent = len(t)

    def cx(x):
        return ord(x) - ord('a') + 1

    hsh = 0
    for x in t:
        hsh = (hsh * 26 + cx(x)) % MOD

    n = (lens+lent) * 2 + 1
    dp = [0] * n

    h = 0
    ans = 0
    for i in range(n):
        if i >= lent:
            h -= cx(s[(i - lent)%lens]) * pow(26,lent-1,MOD)
        h = (h * 26 + cx(s[i % lens])) % MOD
        if h == hsh:
            if i < lent:
                dp[i] = 1
            else:
                dp[i] = dp[i-lent] + 1
            ans = max(ans,dp[i])

    if n - ans * lent < lent * 2:
        print(-1)
    else:
        print(ans)

if __name__ == '__main__':
    main()
Problem: p02962
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def rolling_hash(s, w, MOD):
    ret = []
    tmp = 0
    p = pow(26, w, MOD)
    ords = [ord(c) - 97 for c in s]
    for i, o in enumerate(ords):
        tmp = tmp * 26 + o
        if i >= w:
            tmp = (tmp - ords[i - w] * p)
        tmp %= MOD
        ret.append(tmp)
    return ret


def solve(s, t):
    MOD = 10 ** 9 + 7
    ls, lt = len(s), len(t)
    k = (lt - 1) 
    s *= k * 2
    ls *= k
    rs, rt = rolling_hash(s, lt, MOD), rolling_hash(t, lt, MOD)
    rs = rs[ls:]
    ht = rt[-1]

    checked = [-1] * ls

    def series(i, st):
        print(i, st, checked)
        if i == st:
            return float('-inf')
        if checked[i] == -1:
            checked[i] = series((i + lt) % ls, st) + 1 if rs[i] == ht else 0
        return checked[i]

    for i, hs in enumerate(rs):
        if hs != ht:
            continue
        ret = series((i + lt) % ls, i)
        if ret == float('-inf'):
            return -1
        checked[i] = ret + 1

    return max(0, max(checked))


s = input()
t = input()
print(solve(s, t))


Failing test case input:
bb`adca
`a

Expected output:
1

Actual output:
5 3 [-1, -1, -1, -1, -1, -1, -1]
1


Fixed submission (verdict: Accepted):
import sys

sys.setrecursionlimit(10 ** 6)


def rolling_hash(s, w, MOD):
    ret = []
    tmp = 0
    p = pow(26, w, MOD)
    ords = [ord(c) - 97 for c in s]
    for i, o in enumerate(ords):
        tmp = tmp * 26 + o
        if i >= w:
            tmp = (tmp - ords[i - w] * p)
        tmp %= MOD
        ret.append(tmp)
    return ret


def solve(s, t):
    MOD = 10 ** 9 + 7
    ls, lt = len(s), len(t)
    k = (lt - 1) 
    s *= k * 2
    ls *= k
    rs, rt = rolling_hash(s, lt, MOD), rolling_hash(t, lt, MOD)
    rs = rs[ls:]
    ht = rt[-1]

    checked = [-1] * ls

    def series(i, st):
        if st <= i < st + lt:
            return float('-inf')
        if checked[i] == -1:
            checked[i] = series((i + lt) % ls, st) + 1 if rs[i] == ht else 0
        return checked[i]

    for i, hs in enumerate(rs):
        if hs != ht:
            continue
        ret = series((i + lt) % ls, i)
        if ret == float('-inf'):
            return -1
        checked[i] = ret + 1

    return max(0, max(checked))


s = input()
t = input()
print(solve(s, t))