ZhenlongDai/ACPR huggingface dataset:
Problem: p02345
Buggy submission (Python3, verdict: Wrong Answer):
import time

N, Q = map(int, input().split())
SegTree = [0 for i in range(4*N)]

def modify(i, left, right, value, pos=-1):
    global SegTree
    if left==right:
        if pos != -1:
            SegTree[i] = value
        else:
            SegTree[i] = 2147483647
        return

    mid = int((left+right)/2)
    if pos==-1 or pos<=mid:
        modify(i*2, left, mid, value, pos)
    if pos==-1 or pos>mid:
        modify(i*2+1, mid+1, right, value, pos)
    
    SegTree[i] = min(SegTree[i*2], SegTree[i*2+1])

def query_min(i, L, R, left, right):
    if right < L or R < left:
        return 2147364748
    if left<=L and R<=right:
        return SegTree[i]
    mid = int((L+R)/2)
    return min(query_min(2*i, L, mid, left, right),
               query_min(2*i+1, mid+1, R, left, right))

modify(i=1, left=0, right=N-1, value=0, pos=-1) 

for querys in range(Q):
    t, a, b = map(int, input().split())
    if t == 0:
        modify(i=1, left=0, right=N-1, pos=a, value=b)
    else:
        print( query_min(i=1, L=0, R=N-1, left=a, right=b) )

Failing test case input:
6 5
0 0 0
0 1 2
1 2 3
1 0 2
1 2 2

Expected output:
2147483647
0
2147483647


Actual output:
2147364748
0
2147364748


Fixed submission (verdict: Accepted):
import time

N, Q = map(int, input().split())
SegTree = [0 for i in range(4*N)]

def modify(i, left, right, value, pos=-1):
    global SegTree
    if left==right:
        if pos != -1:
            SegTree[i] = value
        else:
            SegTree[i] = 2147483647
        return

    mid = int((left+right)/2)
    if pos==-1 or pos<=mid:
        modify(i*2, left, mid, value, pos)
    if pos==-1 or pos>mid:
        modify(i*2+1, mid+1, right, value, pos)
    
    SegTree[i] = min(SegTree[i*2], SegTree[i*2+1])

def query_min(i, L, R, left, right):
    if right < L or R < left:
        return 2147483647
    if left<=L and R<=right:
        return SegTree[i]
    mid = int((L+R)/2)
    return min(query_min(2*i, L, mid, left, right),
               query_min(2*i+1, mid+1, R, left, right))

modify(i=1, left=0, right=N-1, value=0, pos=-1) 

for querys in range(Q):
    t, a, b = map(int, input().split())
    if t == 0:
        modify(i=1, left=0, right=N-1, pos=a, value=b)
    else:
        print( query_min(i=1, L=0, R=N-1, left=a, right=b) )
Problem: p02722
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


N=int(input())
cand=[]

def check(N0,K0):
    if N0%K0==0:
        return check(int(N0/K0),K0)
    elif N0%K0==1:
        return 1
    else:
        return 0

def check0(N0,K0):
    while N0%K0==0:
        N0=int(N0/K0)
    if N0%K0==1:
        return 1
    else:
        return 0


for i in range(2,int((N-1)**0.5)+1):
    if (N-1)%i==0:
        cand.append(i)
        if i!=int((N-1)/i):
            cand.append(int((N-1)/i))
if N>2:
    cand.append(N-1)


for i in range(2,int(N**0.5)+1):
    if N%i==0:
        cand.append(i)
        if i!=int(N/i):
            cand.append(int(N/i))
cand.append(N)

print(cand)
count=0
for i in range(len(cand)):
    if check(N,cand[i]):
        count+=1

print(count)

Failing test case input:
6082577109

Expected output:
12


Actual output:
[2, 3041288554, 4, 1520644277, 113, 53828116, 226, 26914058, 452, 13457029, 6082577108, 3, 2027525703, 7, 868939587, 9, 675841901, 21, 289646529, 63, 96548843, 6082577109]
12


Fixed submission (verdict: Accepted):


N=int(input())
cand=[]

def check(N0,K0):
    if N0%K0==0:
        return check(int(N0/K0),K0)
    elif N0%K0==1:
        return 1
    else:
        return 0

def check0(N0,K0):
    while N0%K0==0:
        N0=int(N0/K0)
    if N0%K0==1:
        return 1
    else:
        return 0


for i in range(2,int((N-1)**0.5)+1):
    if (N-1)%i==0:
        cand.append(i)
        if i!=int((N-1)/i):
            cand.append(int((N-1)/i))
if N>2:
    cand.append(N-1)


for i in range(2,int(N**0.5)+1):
    if N%i==0:
        cand.append(i)
        if i!=int(N/i):
            cand.append(int(N/i))
cand.append(N)


count=0
for i in range(len(cand)):
    if check(N,cand[i]):
        count+=1

print(count)

Problem: p02722
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math


N = int(input())

nn = int(math.sqrt(N))

ans = 0
for x in range(2,nn+1):

    if N % x > 1:
        continue

    if N % x == 1:
        ans += 1
        continue
    
    tmp = N
    while True:
        tmp = tmp / x
        if tmp % x  == 1:
            ans += 1
            break
        elif tmp == x :
            ans += 1
            break
        elif tmp % x >= 1:
            break

print(ans+2)






Failing test case input:
237274827109

Expected output:
24


Actual output:
13


Fixed submission (verdict: Accepted):
import math


N = int(input())

nn = int(math.sqrt(N))


ans = 1
for x in range(2,nn+1):

    if N % x == 1:
        ans += 1
        continue
    
    if N % x > 1:
        continue

    tmp = N
    while tmp > x:
        tmp = tmp / x
        if tmp % x == 1 :
            ans += 1
            break
        elif tmp % x > 1 :
            break
        elif tmp == x:
            ans += 1
            break

x = 1
tmp = N - 1
while tmp / x  > nn:
    if tmp % x == 0:
        ans += 1
    x += 1

print(ans)
Problem: p02722
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def divisor(n):
  list1 = []
  for i in range(1, int(n ** (0.5)) + 1):
    if n % i == 0:
      list1.append(i)
      list1.append(int(n / i))
  list1 = list(set(list1))
  return len(list1) - 1

def function(n):
  ans = 0
  if n >= 2:
    ans += 1
  for i in range(2, int(n ** (0.5)) + 1):
    m = n
    if m % i == 0:
      while m % i == 0:
        m = int(m / i)
      ans += divisor(m)
  ans += divisor(n - 1)
  return ans
n = int(input())
print(function(n))

Failing test case input:
7705668993

Expected output:
64


Actual output:
545


Fixed submission (verdict: Accepted):
def divisor(n):
  list1 = []
  for i in range(1, int(n ** (0.5)) + 1):
    if n % i == 0:
      list1.append(i)
      list1.append(int(n / i))
  list1 = list(set(list1))
  return len(list1) - 1

def function(n):
  ans = 0
  if n >= 2:
    ans += 1
  for i in range(2, int(n ** (0.5)) + 1):
    m = n
    if m % i == 0:
      while m % i == 0:
        m = int(m / i)
      if m % i == 1:
        ans += 1
  ans += divisor(n - 1)
  return ans
n = int(input())
print(function(n))

Problem: p02722
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math


N = int(input())

nn = int(math.sqrt(N))

ans = 0
for x in range(2,nn+1):

    if N % x > 1:
        continue

    if N % x == 1:
        ans += 1
        continue
    
    tmp = N
    while True:
        tmp = tmp / x
        if tmp % x  == 1:
            ans += 1
            break
        elif tmp == x :
            ans += 1
            break
        elif tmp % x >= 1:
            break

print(ans+3)






Failing test case input:
2777701

Expected output:
72


Actual output:
38


Fixed submission (verdict: Accepted):
import math


N = int(input())

nn = int(math.sqrt(N))


ans = 1
for x in range(2,nn+1):

    if N % x == 1:
        ans += 1
        continue
    
    if N % x > 1:
        continue

    tmp = N
    while tmp > x:
        tmp = tmp / x
        if tmp % x == 1 :
            ans += 1
            break
        elif tmp % x > 1 :
            break
        elif tmp == x:
            ans += 1
            break

x = 1
tmp = N - 1
while tmp / x  > nn:
    if tmp % x == 0:
        ans += 1
    x += 1

print(ans)
Problem: p03297
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from math import floor
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)
T = int(input())
for i in range(T):
    A,B,C,D = map(int,input().split())
    if B > D or B > A:
        print("No")
    else:
        if A%B>C:
            print("No")
        else:
            d = gcd(B,D%B)
            r = A%B
            if r%d == 0:
                if B-d > C:
                    print("No")
                else:
                    print("Yes")
            else:
                if r+floor((B-r)/d) > C:
                    print("No")
                else:
                    print("Yes")


Failing test case input:
14
7 7 5 9
8 7 1 9
11 10 7 12
14 10 1 12
14 14 14 15
14 11 5 11
14 10 12 11
14 10 11 11
0 10 3 10
0 13 9 6
11 18 9 10
16 22 5 10
1000010000100000000 17 5 999999999999999985
1000000000000000000 16 15 2424336645253281229

Expected output:
No
No
No
No
Yes
Yes
Yes
Yes
No
No
No
No
No
Yes


Actual output:
No
No
Yes
No
Yes
Yes
Yes
Yes
No
No
No
No
No
Yes


Fixed submission (verdict: Accepted):
from math import floor
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)
T = int(input())
for i in range(T):
    A,B,C,D = map(int,input().split())
    if B > D or B > A:
        print("No")
    else:
        if A%B>C:
            print("No")
        else:
            d = gcd(B,D%B)
            r = (A%B)%d
            if B - d + r > C:
                print("No")
            else:
                print("Yes")
Problem: p03297
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

T=int(input())
Juice=[None]*T
for i in range(T):
    Juice[i]=list(map(int,input().split()))





def juicecheck(i):
    A=Juice[i][0]
    B=Juice[i][1]
    C=Juice[i][2]
    D=Juice[i][3]

    if A<B:
        print("No")
        return
    elif B>D:
        print("No")
        return
    elif B<C:
        print("Yes")
        return
    else:
        x=A%B
        

        z=gcd(B,D)

        if ((C+1)!=B) and (z==1 or (C+1)%z==B%z==x%z or (C+1)%z<=x%z<B%z or ( (C+1)%z>B%z and ((C+1)%z<=x%z or x%z<B%z))):
            print("No")
            return

        print("Yes")
        return
                
        

for i in range(T):
    juicecheck(i)


Failing test case input:
14
7 7 5 9
8 7 1 9
11 10 7 12
14 10 1 12
14 4 14 11
14 11 5 11
14 18 12 15
0 1 11 11
0 10 3 10
0 8 9 0
11 18 9 10
15 22 5 10
1000010000100000000 17 5 999999999999999985
1000000000000000001 16 15 2424336645253281229

Expected output:
No
No
No
No
Yes
Yes
No
No
No
No
No
No
No
Yes


Actual output:
No
No
Yes
No
Yes
Yes
No
No
No
No
No
No
No
Yes


Fixed submission (verdict: Accepted):
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

T=int(input())
Juice=[None]*T
for i in range(T):
    Juice[i]=list(map(int,input().split()))





def juicecheck(i):
    A=Juice[i][0]
    B=Juice[i][1]
    C=Juice[i][2]
    D=Juice[i][3]

    if A<B:
        print("No")
        return
    elif B>D:
        print("No")
        return
    elif B-1<=C:
        print("Yes")
        return
    else:
        x=A%B
        y=D%B
        

        z=gcd(B,D)

        if z==1 or B-(C+1)>=z or  (C+1)%z<=x%z<=(B-1)%z or ( (C+1)%z>B%z and ((C+1)%z<=x%z or x%z<B%z) ):
            print("No")
            return

        print("Yes")
        return
                
        

for i in range(T):
    juicecheck(i)
Problem: p03297
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
class query:
    def __init__(self, a, b, c, d):
        self.a = a
        self.b = b
        self.c = c
        self.d = d
    def isEternal(self):
        if self.a < self.b:
            return "No"
        if self.a % self.b > self.c:
            return "No"
        if self.d < self.b:
            return "No"
        d = self.b - self.c
        if d <= 0:
            return "Yes"
        if self.b % d == 0 and self.d % d == 0:
            return "Yes"
        if self.a % self.b + self.d == self.a:
            return "Yes"
        return "No"

if __name__ == "__main__":
    t = int(input())
    querys = [query(*[int(s) for s in input().split()]) for _ in range(t)]
    for q in querys:
        print(q.isEternal())


Failing test case input:
14
7 7 5 9
15 7 1 9
14 5 7 14
14 5 1 12
14 8 14 11
14 11 5 11
14 9 12 11
14 10 11 11
0 10 3 11
0 13 9 6
11 4 9 4
16 10 5 10
1100010000100000000 17 5 999999999999999985
1000000000000000000 16 15 2424336645253281229

Expected output:
No
No
Yes
No
Yes
Yes
Yes
Yes
No
No
Yes
No
Yes
Yes


Actual output:
No
No
Yes
No
Yes
Yes
Yes
Yes
No
No
Yes
No
No
Yes


Fixed submission (verdict: Accepted):
def gcd(a, b):
    r = a % b
    while r != 0:
        a, b, r = b, r, b % r
    return b

class query:
    def __init__(self, a, b, c, d):
        self.a = a
        self.b = b
        self.c = c
        self.d = d
    def isEternal(self):
        if self.a < self.b:
            return "No"
        if self.d < self.b:
            return "No"
        if self.b <= self.c:
            return "Yes"
        g = gcd(self.d, self.b)
        if self.b - g + self.a % g > self.c:
            return "No"
        return "Yes"

if __name__ == "__main__":
    t = int(input())
    querys = [query(*[int(s) for s in input().split()]) for _ in range(t)]
    for q in querys:
        print(q.isEternal())
Problem: p03297
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
T=int(input())

Query=[]
for i in range(T):
  Query.append(list(map(int,input().split())))

for i in range(T):
  count=0
  while(True):
    if Query[i][0]%Query[i][1]>Query[i][2]:
      print('No')
      break;
    Query[i][0]=Query[i][0]%Query[i][1] 
    if Query[i][0]<=Query[i][2]: 
      Query[i][0]+=Query[i][3]
    count+=1
    if count==300:
      print('Yes')
      break;

Failing test case input:
14
7 7 5 9
15 7 1 9
14 5 7 12
14 10 1 12
14 14 14 11
14 11 5 11
14 9 12 11
14 10 11 11
0 10 3 11
0 13 9 6
11 18 9 10
16 10 5 10
1000010000100000000 17 5 999999999999999985
1000000000000000000 16 15 2424336645253281229

Expected output:
No
No
Yes
No
No
Yes
Yes
Yes
No
No
No
No
No
Yes


Actual output:
No
No
Yes
No
Yes
Yes
Yes
Yes
No
No
No
No
No
Yes


Fixed submission (verdict: Accepted):
def gcd(a,b):
  while b:
    a,b=b,a%b
  return a
T=int(input())
 
Query=[]
for i in range(T):
  Query.append(list(map(int,input().split())))
 
for i in range(T):
  while(True):
    if Query[i][0]%Query[i][1]>Query[i][2] or Query[i][0]<Query[i][1] or Query[i][1]>Query[i][3]:
      print('No')
      break;
    G=gcd(Query[i][1],Query[i][3]) 
    
    if Query[i][1]-G+Query[i][0]%G>Query[i][2]:
      print('No')
      break;
    else:
      print('Yes')
      break;

Problem: p03297
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from math import floor
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)
T = int(input())
for i in range(T):
    A,B,C,D = map(int,input().split())
    if B > D:
        print("No")
    else:
        if A%B>C:
            print("No")
        else:
            d = gcd(B,D%B)
            r = A%B
            if r%d == 0:
                if B-D > C:
                    print("No")
                else:
                    print("Yes")
            else:
                if r+floor((B-r)/d) > C:
                    print("No")
                else:
                    print("Yes")

Failing test case input:
14
9 7 5 9
9 7 9 9
14 10 7 12
14 10 15 12
14 10 9 12
14 11 7 11
14 10 8 11
14 10 9 11
9 10 3 4
10 11 5 10
11 10 5 7
16 10 5 10
1000000000100000000 17 14 999999999999999985
1000000000010000000 23 15 1358327919252224189

Expected output:
No
Yes
No
Yes
Yes
Yes
No
Yes
No
No
No
No
Yes
No


Actual output:
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
No
No
No
Yes
Yes


Fixed submission (verdict: Accepted):
from math import floor
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)
T = int(input())
for i in range(T):
    A,B,C,D = map(int,input().split())
    if B > D or B > A:
        print("No")
    else:
        if A%B>C:
            print("No")
        else:
            d = gcd(B,D%B)
            r = (A%B)%d
            if B - d + r > C:
                print("No")
            else:
                print("Yes")
Problem: p03297
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
class query:
    def __init__(self, a, b, c, d):
        self.a = a
        self.b = b
        self.c = c
        self.d = d
    def isEternal(self):
        if self.a < self.b:
            return "No"
        ab = self.a % self.b
        if ab > self.c:
            return "No"
        if self.d < self.b:
            return "No"
        d = self.b - self.c
        if d <= 0:
            return "Yes"
        if self.b % d == 0 and self.d % d == 0:
            return "Yes"
        db = self.d % self.b
        if db == 0:
            return "Yes"
        q, r = divmod((self.c - ab), db)
        q += 1 if r != 0 else 0
        if q * db < self.b - ab:
            return "No"
        return "Yes"

if __name__ == "__main__":
    t = int(input())
    querys = [query(*[int(s) for s in input().split()]) for _ in range(t)]
    for q in querys:
        print(q.isEternal())


Failing test case input:
14
9 7 9 9
9 7 6 9
14 10 7 12
14 10 8 12
14 10 9 12
14 10 7 11
14 10 8 11
14 10 9 11
11 19 3 10
10 11 5 10
11 10 5 10
16 10 5 10
1000000000100000000 17 14 999999999999999985
1000000000000000000 27 15 999999999999999985

Expected output:
Yes
Yes
No
Yes
Yes
No
No
Yes
No
No
Yes
No
Yes
No


Actual output:
Yes
Yes
No
Yes
Yes
No
No
Yes
No
No
Yes
No
Yes
Yes


Fixed submission (verdict: Accepted):
def gcd(a, b):
    r = a % b
    while r != 0:
        a, b, r = b, r, b % r
    return b

class query:
    def __init__(self, a, b, c, d):
        self.a = a
        self.b = b
        self.c = c
        self.d = d
    def isEternal(self):
        if self.a < self.b:
            return "No"
        if self.d < self.b:
            return "No"
        if self.b <= self.c:
            return "Yes"
        g = gcd(self.d, self.b)
        if self.b - g + self.a % g > self.c:
            return "No"
        return "Yes"

if __name__ == "__main__":
    t = int(input())
    querys = [query(*[int(s) for s in input().split()]) for _ in range(t)]
    for q in querys:
        print(q.isEternal())
Problem: p03297
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
T = int(input())
a = []
for i in range(T):
    a.append(list(map(int, input().split())))
for r in a:
    s, b, c, d = r[0], r[1], r[2], r[3]
    s_list = []
    while True:
        if (s < b) or (b>d):
            print('No')
            break
        if (c>s):
            print('Yes')
        s = s%b
        s_list.append(s)
        if c < s < b:
            print('No')
            break

        s = s+d
        if s in s_list:
            print('Yes')
            break
        s_list.append(s)


Failing test case input:
14
7 7 5 9
9 7 4 9
14 3 7 12
14 10 15 12
14 10 9 12
3 11 7 9
14 10 8 11
14 10 9 11
10 10 3 10
10 13 6 10
11 10 5 10
16 10 5 10
1000010000100000000 17 5 1378844900267354047
1000000000000000000 16 15 1358327919252224189

Expected output:
No
No
Yes
Yes
Yes
No
No
Yes
Yes
No
Yes
No
No
Yes


Actual output:
No
No
Yes
Yes
Yes
Yes
Yes
Yes
No
No
Yes
Yes
No
Yes
No
No
Yes


Fixed submission (verdict: Accepted):
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a


T = int(input())
a = []
for i in range(T):
    a.append(list(map(int, input().split())))
for r in a:
    s, b, c, d = r[0], r[1], r[2], r[3]
    mod_list = []
    if (s < b) or (b>d):
        print('No')
        continue
    if (c>b):
        print('Yes')
        continue

    g = gcd(b,d)

    if b- g + s%g > c:
        print('No')
    else:
        print('Yes')
Problem: p03297
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

T=int(input())
Juice=[None]*T
for i in range(T):
    Juice[i]=list(map(int,input().split()))





def juicecheck(i):
    A=Juice[i][0]
    B=Juice[i][1]
    C=Juice[i][2]
    D=Juice[i][3]

    if A<B:
        print("No")
        return
    elif B>D:
        print("No")
        return
    elif B-1<=C:
        print("Yes")
        return
    else:
        x=A%B
        y=D%B
        

        z=gcd(B,D)

        if z==1 or  (C+1)%z<=x%z<B%z or ( (C+1)%z>B%z and ((C+1)%z<=x%z or x%z<B%z) ):
            print("No")
            return

        print("Yes")
        return
                
        

for i in range(T):
    juicecheck(i)


Failing test case input:
14
9 7 5 11
12 7 12 9
14 10 7 12
14 10 8 12
2 10 3 12
26 10 2 11
14 10 8 11
14 10 9 11
6 10 3 10
10 10 5 10
11 10 5 1
16 10 5 10
1000000000100000000 17 14 999999999999999985
1000000000000000000 17 15 999999999999999985

Expected output:
No
Yes
No
Yes
No
No
No
Yes
No
Yes
No
No
Yes
Yes


Actual output:
No
Yes
Yes
Yes
No
No
No
Yes
No
Yes
No
No
Yes
Yes


Fixed submission (verdict: Accepted):
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

T=int(input())
Juice=[None]*T
for i in range(T):
    Juice[i]=list(map(int,input().split()))





def juicecheck(i):
    A=Juice[i][0]
    B=Juice[i][1]
    C=Juice[i][2]
    D=Juice[i][3]

    if A<B:
        print("No")
        return
    elif B>D:
        print("No")
        return
    elif B-1<=C:
        print("Yes")
        return
    else:
        x=A%B
        y=D%B
        

        z=gcd(B,D)

        if z==1 or B-(C+1)>=z or  (C+1)%z<=x%z<=(B-1)%z or ( (C+1)%z>B%z and ((C+1)%z<=x%z or x%z<B%z) ):
            print("No")
            return

        print("Yes")
        return
                
        

for i in range(T):
    juicecheck(i)

Problem: p03297
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
T = int(input())

def gcd (a: int,b: int) -> int:
    if a < b: a,b = b,a
    return a if b == 0 else gcd(b,a%b)
def lcm (a: int,b: int) -> int:
    return a 


for i in range(T):
    A,B,C,D = map(int,input().split(" "))
    g = gcd(B,D)
    if C >= ((B - g) + (A % g)):
        print("Yes")
    else:
        print("No")




Failing test case input:
14
9 7 5 9
9 7 6 9
14 10 7 12
14 10 15 3
14 10 9 12
22 10 7 11
14 10 8 11
14 10 9 11
9 17 3 10
10 11 5 10
11 10 5 10
16 10 5 10
1000000000100000000 17 14 999999999999999985
1000001000000000000 16 15 999999999999999985

Expected output:
No
Yes
No
No
Yes
No
No
Yes
No
No
Yes
No
Yes
Yes


Actual output:
No
Yes
No
Yes
Yes
No
No
Yes
No
No
Yes
No
Yes
Yes


Fixed submission (verdict: Accepted):
T = int(input())

def gcd (a: int,b: int) -> int:
    if a < b: a,b = b,a
    return a if b == 0 else gcd(b,a%b)
def lcm (a: int,b: int) -> int:
    return a 


for i in range(T):
    A,B,C,D = map(int,input().split(" "))
    g = gcd(B,D)
    if A < B or D < B:
        print("No")
        continue
    if C >= ((B - g) + (A % g)):
        print("Yes")
    else:
        print("No")
Problem: p03297
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
n=int(input())
for _ in range(n):
    a,b,c,d=map(int,input().split())
    if d<b:
        print("No")
        continue
    elif a<b:
        print("No")
        continue
    g=1
    h=1
    if 1+h>c:
        print("No")
        continue
    print("Yes")


Failing test case input:
14
9 7 5 9
9 7 2 9
1 10 7 12
14 10 5 12
12 10 9 12
11 11 7 11
14 10 8 11
14 10 9 11
9 10 3 10
10 11 5 10
11 10 9 10
16 7 5 10
1000000000100000000 17 14 999999999999999985
0000000000000000000 16 15 959335908062480470

Expected output:
No
No
No
No
Yes
Yes
No
Yes
No
No
Yes
No
Yes
No


Actual output:
Yes
Yes
No
Yes
Yes
Yes
Yes
Yes
No
No
Yes
Yes
Yes
No


Fixed submission (verdict: Accepted):
import fractions 
n=int(input())
for _ in range(n):
    a,b,c,d=map(int,input().split())
    if d<b:
        print("No")
        continue
    elif a<b:
        print("No")
        continue
    elif c>=b:
        print("Yes")
        continue
    g=fractions.gcd(b,d)
    h=((b-1-a%b)
    if a%b+h>c:
        print("No")
        continue
    print("Yes")
Problem: p02458
Buggy submission (Python3, verdict: Wrong Answer):



from bisect import bisect_left, bisect_right, insort_left
dict = {}
keytbl = []
cnt = 0
q = int(input())
for i in range(q):
	a = list(input().split())
	ki = int(a[1])
	if a[0] == '0':
		if ki not in dict:
			dict[ki] = 1
			insort_left(keytbl, ki)
		else: dict[ki] += 1
		cnt += 1
		print(cnt)
	elif a[0] == '1': print(dict[ki] if ki in dict else 0)
	elif a[0] == '2':
		if ki in dict:
			cnt -= dict[ki]
			dict[ki] = 0
	else:
		L = bisect_left (keytbl, int(a[1]))
		R = bisect_right(keytbl, int(a[2]), L)
		for j in range(L, R):
			if dict[keytbl[j]] > 0: print(keytbl[j])


Failing test case input:
10
1 1
0 1
0 2
1 3
2 2
1 1
0 1
1 6
1 4
3 1 4

Expected output:
0
1
2
0
1
2
0
0
1
1


Actual output:
0
1
2
0
1
2
0
0
1


Fixed submission (verdict: Accepted):



from bisect import bisect_left, bisect_right, insort_left
dict = {}
keytbl = []
cnt = 0
q = int(input())
for i in range(q):
	a = list(input().split())
	ki = int(a[1])
	if a[0] == '0':
		if ki not in dict:
			dict[ki] = 1
			insort_left(keytbl, ki)
		else: dict[ki] += 1
		cnt += 1
		print(cnt)
	elif a[0] == '1': print(dict[ki] if ki in dict else 0)
	elif a[0] == '2':
		if ki in dict:
			cnt -= dict[ki]
			dict[ki] = 0
	else:
		L = bisect_left (keytbl, int(a[1]))
		R = bisect_right(keytbl, int(a[2]), L)
		for j in range(L, R):
			for k in range(dict[keytbl[j]]): print(keytbl[j])
Problem: p03183
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n = int(input())
wsv = [list(map(int,input().split())) for i in range(n)]
wsv.sort(key = lambda x:x[0]+x[1],reverse=True)
smx = max(list(zip(*wsv))[1])
dp = [[0 for i in range(smx+1)] for j in range(n+1)]
for i in range(1,n+1):
  dp[i] = dp[i-1][:]
  w,s,v = wsv[i-1]
  dp[i][s] = max(dp[i-1][s],v)
  for ss in range(smx+1)[::-1]:
    sn = min(ss-w,s)
    if sn >= 0:
      dp[i][sn] = max(dp[i-1][sn],dp[i-1][ss]+v)
print(max(dp[-1]))

Failing test case input:
3
3 5 20
1 1 7
3 1 40

Expected output:
67


Actual output:
47


Fixed submission (verdict: Accepted):
n = int(input())
wsv = [list(map(int,input().split())) for i in range(n)]
wsv.sort(key = lambda x:x[0]+x[1],reverse=True)
smx = max(list(zip(*wsv))[1])
dp = [[0 for i in range(smx+1)] for j in range(n+1)]
for i in range(1,n+1):
  dp[i] = dp[i-1][:]
  w,s,v = wsv[i-1]
  dp[i][s] = max(dp[i-1][s],v)
  for ss in range(smx+1)[::-1]:
    sn = min(ss-w,s)
    if sn >= 0 and dp[i-1][ss]:
      dp[i][sn] = max(dp[i][sn],dp[i-1][sn],dp[i-1][ss]+v)
print(max(dp[-1]))

Problem: p03183
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):



def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    
    
    N=I()
    wsv=[]
    for i in range(N):
        w,s,v=MI()
        wsv.append([w,s,v])
        
    wsv.sort(key=lambda x:(x[0]+x[1]))
    
    N2=2*(10**4) +1
    dp=[[-1]*N2 for _ in range(N+1)]
    
    for i in range(N):
        w,s,v=wsv[i]
        for j in range(N2):
            dp[i+1][j]=max(dp[i][j],dp[i+1][j])
            if s>=j and j+w<=(N2-1):
                dp[i+1][j+w]=max(dp[i+1][j+w],dp[i][j]+v)
                
    print(max(dp[-1]))
            
        

main()


Failing test case input:
5
1 10001 1000000001
1 10101 1000001000
1 10000 1000000000
2 11001 1000001000
1 00010 1000010010

Expected output:
5000012011


Actual output:
5000012010


Fixed submission (verdict: Accepted):

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    
    
    N=I()
    wsv=[]
    for i in range(N):
        w,s,v=MI()
        wsv.append([w,s,v])
        
    wsv.sort(key=lambda x:(x[0]+x[1]))
    
    N2=2*(10**4) +1
    dp=[[0]*N2 for _ in range(N+1)]
    
    for i in range(N):
        w,s,v=wsv[i]
        for j in range(N2):
            dp[i+1][j]=max(dp[i][j],dp[i+1][j])
            if s>=j and j+w<=(N2-1):
                dp[i+1][j+w]=max(dp[i+1][j+w],dp[i][j]+v)
                
    print(max(dp[-1]))
            
        

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

def solve():
    N = int(input())
    items = [tuple(map(int, input().split())) for _ in range(N)]

    capW = max([w+s for w, s, v in items])
    items.sort(key=lambda x: x[0]+x[1])

    def knapsack01(items, capW):
        dp = [0] * (capW+1)
        for wi, si, vi in items:
            for w in reversed(range(wi, si+wi+1)):
                v0 = dp[w-wi] + vi
                if v0 > dp[w]:
                    dp[w] = v0
        return dp[-1]

    ans = knapsack01(items, capW)
    print(ans)


solve()


Failing test case input:
3
3 5 20
1 1 7
3 1 40

Expected output:
67


Actual output:
20


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

def solve():
    N = int(input())
    items = [tuple(map(int, input().split())) for _ in range(N)]

    capW = max([w+s for w, s, v in items])
    items.sort(key=lambda x: x[0]+x[1])

    def knapsack01(items, capW):
        dp = [0] * (capW+1)
        for wi, si, vi in items:
            for w in reversed(range(wi, si+wi+1)):
                v0 = dp[w-wi] + vi
                if v0 > dp[w]:
                    dp[w] = v0
        return max(dp)

    ans = knapsack01(items, capW)
    print(ans)


solve()

Problem: p03183
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    
    
    N=I()
    wsv=[]
    for i in range(N):
        w,s,v=MI()
        wsv.append([w,s,v])
        
    wsv.sort(key=lambda x:(x[0]+x[1]))
    
    N2=2*(10**4) +1
    dp=[[-1]*N2 for _ in range(N+1)]
    
    for i in range(N):
        w,s,v=wsv[i]
        for j in range(N2):
            dp[i+1][j]=max(dp[i][j],dp[i+1][j])
            if s>=j and j+w<=(10**4):
                dp[i+1][j+w]=max(dp[i+1][j+w],dp[i][j]+v)
                
    print(max(dp[-1]))
            
        

main()


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

Expected output:
17


Actual output:
16


Fixed submission (verdict: Accepted):

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    
    
    N=I()
    wsv=[]
    for i in range(N):
        w,s,v=MI()
        wsv.append([w,s,v])
        
    wsv.sort(key=lambda x:(x[0]+x[1]))
    
    N2=2*(10**4) +1
    dp=[[0]*N2 for _ in range(N+1)]
    
    for i in range(N):
        w,s,v=wsv[i]
        for j in range(N2):
            dp[i+1][j]=max(dp[i][j],dp[i+1][j])
            if s>=j and j+w<=(N2-1):
                dp[i+1][j+w]=max(dp[i+1][j+w],dp[i][j]+v)
                
    print(max(dp[-1]))
            
        

main()
Problem: p04008
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys
input = sys.stdin.readline


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

ans = 0
graph = [[] for _ in range(N)]
Par = [-1]*N
for i, a in enumerate(A):
    if i == 0:
        if a != 1:
            ans += 1
        continue
    Par[i] = a-1
    graph[a-1].append(i)

qs = []

stack = [0]
Depth = [-1]*N
Depth[0] = 0
while stack:
    p = stack.pop()
    for np in graph[p]:
        Depth[np] = Depth[p] + 1
        stack.append(np)
    qs.append((Depth[p], p))

qs.sort(reverse=True)
checked = [False]*N

for d, s in qs:
    if d <= K: break
    if checked[s]: continue

    for _ in range(K-1):
        s = Par[s]
    
    que = [s]
    while que:
        qq = []
        for p in que:
            for np in graph[p]:
                if not checked[np]:
                    checked[np] = True
                    qq.append(np)
        que = qq
    
    ans += 1

print(ans)

Failing test case input:
8 2
4 1 2 3 1 2 4 7

Expected output:
3


Actual output:
4


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


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

ans = 0
graph = [[] for _ in range(N)]
Par = [-1]*N
for i, a in enumerate(A):
    if i == 0:
        if a != 1:
            ans += 1
        continue
    Par[i] = a-1
    graph[a-1].append(i)

qs = []

stack = [0]
Depth = [-1]*N
Depth[0] = 0
while stack:
    p = stack.pop()
    for np in graph[p]:
        Depth[np] = Depth[p] + 1
        stack.append(np)
    qs.append((Depth[p], p))

qs.sort(reverse=True)
checked = [False]*N

for d, s in qs:
    if d <= K: break
    if checked[s]: continue

    for _ in range(K-1):
        s = Par[s]
    
    que = [s]
    checked[s] = True
    while que:
        qq = []
        for p in que:
            for np in graph[p]:
                if not checked[np]:
                    checked[np] = True
                    qq.append(np)
        que = qq
    
    ans += 1

print(ans)

Problem: p04008
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

import sys
sys.setrecursionlimit(2 * 10 ** 5 + 10)

n,k =  [int(i) for i in input().split()]
a   =  [int(i)-1 for i in input().split()]


def dfs(u, d):
    change = 0
    if d>k:
        d = 0
        change += 1
    for v in edges[u]:
        change += dfs(v, d+1)
    return change


cnt = 0
if a[0]!=0:
    cnt += 1

edges = [[] for _ in range(n)]
for i in range(1,n):
    pa = a[i]
    edges[a[i]].append(i)   

cnt += dfs(0,0)    
print(cnt)

Failing test case input:
8 2
-1 1 4 5 1 1 5 4

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):




import sys
sys.setrecursionlimit(2 * 10 ** 5 + 10)

n,k =  [int(i) for i in input().split()]
a   =  [int(i)-1 for i in input().split()]



def dfs(u):
    global cnt
    depth = 0 
    
    for v in edges[u]:
        depth = max(depth, (dfs(v)+1)%k) 
        
    
    if depth==k-1 and u!=0 and a[u] != 0:
        cnt += 1
        
    return depth


cnt = 0
if a[0]!=0:
    cnt += 1

edges = [[] for _ in range(n)]
for i in range(1,n):
    pa = a[i]
    edges[a[i]].append(i)   

dfs(0)    
print(cnt)
Problem: p04008
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys
sys.setrecursionlimit(10**6)
n,k = map(int,input().split())
a = [int(i)-1 for i in input().split()]
edg = [[] for i in range(n)]
for i in range(1,n):
  edg[a[i]].append(i)
ans = [0] * n
ans[0] = a[0] != 0
def dfs(now):
  res = 0
  for e in edg[now]:
    res = max(res, dfs(e)+1)
  if res == k - 1 and a[now] != 0:
    ans[now] = 1
    res = 0
  return res
      
dfs(0)
print(sum(ans))


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

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
import sys
sys.setrecursionlimit(10**6)
n,k = map(int,input().split())
a = [int(i)-1 for i in input().split()]
edg = [[] for i in range(n)]
for i in range(1,n):
  edg[a[i]].append(i)
ans = [0] * n
ans[0] = a[0] != 0
def dfs(now):
  res = 0
  for e in edg[now]:
    res = max(res, dfs(e)+1)
  if res == k - 1 and a[now] != 0:
    ans[now] = 1
    res = -1
  return res
      
dfs(0)
print(sum(ans))

Problem: p04008
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

import sys
sys.setrecursionlimit(2 * 10 ** 5 + 10)

n,k =  [int(i) for i in input().split()]
a   =  [int(i)-1 for i in input().split()]


def dfs(u, d):
    change = 0
    if d>k:
        d = 1
        change += 1
    for v in edges[u]:
        change += dfs(v, d+1)
    return change


cnt = 0
if a[0]!=0:
    cnt += 1

edges = [[] for _ in range(n)]
for i in range(1,n):
    pa = a[i]
    edges[a[i]].append(i)   

cnt += dfs(0,0)    
print(cnt)

Failing test case input:
8 2
-1 1 4 5 1 4 5 4

Expected output:
2


Actual output:
4


Fixed submission (verdict: Accepted):




import sys
sys.setrecursionlimit(2 * 10 ** 5 + 10)

n,k =  [int(i) for i in input().split()]
a   =  [int(i)-1 for i in input().split()]



def dfs(u):
    global cnt
    depth = 0 
    
    for v in edges[u]:
        depth = max(depth, (dfs(v)+1)%k) 
        
    
    if depth==k-1 and u!=0 and a[u] != 0:
        cnt += 1
        
    return depth


cnt = 0
if a[0]!=0:
    cnt += 1

edges = [[] for _ in range(n)]
for i in range(1,n):
    pa = a[i]
    edges[a[i]].append(i)   

dfs(0)    
print(cnt)
Problem: p04008
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n, k = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
if A[0] != 1:
  ans += 1
C = [[] for _ in range(n+1)]
P = [-1 for _ in range(n+1)]
for i, a in enumerate(A[1:], 2):
  C[a].append(i)
  P[i] = a
def dfs(v):
  global ans
  temp = 0
  for nv in C[v]:
    temp = max(temp, dfs(nv)+1)
  if v == 1:
    return
  if P[v] != 1 and temp == k-1:
    temp = 0
    ans += 1
  return temp
dfs(1)
print(ans)

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

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)

n, k = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
if A[0] != 1:
  ans += 1
C = [[] for _ in range(n+1)]
P = [-1]*(n+1)
for i, a in enumerate(A[1:], 2):
  C[a].append(i)
  P[i] = a
def dfs(v):
  global ans
  temp = 0
  for nv in C[v]:
    temp = max(temp, dfs(nv)+1)
  if v == 1:
    return
  if P[v] != 1 and temp == k-1:
    temp = -1
    ans += 1
  return temp
dfs(1)
print(ans)

Problem: p04008
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys
sys.setrecursionlimit(10**6)
n,k = map(int,input().split())
a = [int(i)-1 for i in input().split()]
edg = [[] for i in range(n)]
for i in range(1,n):
  edg[a[i]].append(i)
ans = [0] * n
ans[0] = a[0] != 0
def dfs(now):
  res = 0
  for e in edg[now]:
    res = max(res, dfs(e))
  if res == k - 1 and a[now] != 0:
    ans[now] = 1
    res = 0
  return res + 1
      
dfs(0)
print(sum(ans))


Failing test case input:
8 2
4 1 2 3 1 2 4 6

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):
import sys
sys.setrecursionlimit(10**6)
n,k = map(int,input().split())
a = [int(i)-1 for i in input().split()]
edg = [[] for i in range(n)]
for i in range(1,n):
  edg[a[i]].append(i)
ans = [0] * n
ans[0] = a[0] != 0
def dfs(now):
  res = 0
  for e in edg[now]:
    res = max(res, dfs(e)+1)
  if res == k - 1 and a[now] != 0:
    ans[now] = 1
    res = -1
  return res
      
dfs(0)
print(sum(ans))
Problem: p04008
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys
input = sys.stdin.readline
import heapq as hp

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

ans = 0
graph = [[] for _ in range(N)]
for i, a in enumerate(A):
    if i == 0:
        if a != 1:
            ans += 1
        continue
    graph[a-1].append(i)

stack = [0]
children = [1]*N
while stack:
    p = stack.pop()
    if p >= 0:
        stack.append(~p)
        for np in graph[p]:
            stack.append(np)
    else:
        p = ~p
        for ch in graph[p]:
            children[p] += children[ch]

q = [(-children[0], 0)]
Depth = [-1]*N
while q:
    _, s = hp.heappop(q)
    if s != 0: ans += 1
    Depth[s] = 0
    que = [s]
    for _ in range(K):
        qq = []
        for p in que:
            for np in graph[p]:
                if Depth[np] == -1:
                    Depth[np] = Depth[p] + 1
                    qq.append(np)
        if not qq:
            break
        que = qq
    if que:
        for p in que:
            for np in graph[p]:
                hp.heappush(q, (-children[np], np))

print(ans)

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

Expected output:
6


Actual output:
5


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


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

ans = 0
graph = [[] for _ in range(N)]
Par = [-1]*N
for i, a in enumerate(A):
    if i == 0:
        if a != 1:
            ans += 1
        continue
    Par[i] = a-1
    graph[a-1].append(i)

qs = []

stack = [0]
Depth = [-1]*N
Depth[0] = 0
while stack:
    p = stack.pop()
    for np in graph[p]:
        Depth[np] = Depth[p] + 1
        stack.append(np)
    qs.append((Depth[p], p))

qs.sort(reverse=True)
checked = [False]*N

for d, s in qs:
    if d <= K: break
    if checked[s]: continue

    for _ in range(K-1):
        s = Par[s]
    
    que = [s]
    checked[s] = True
    while que:
        qq = []
        for p in que:
            for np in graph[p]:
                if not checked[np]:
                    checked[np] = True
                    qq.append(np)
        que = qq
    
    ans += 1

print(ans)
Problem: p04008
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys
input = sys.stdin.readline
import heapq as hp

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

ans = 0
graph = [[] for _ in range(N)]
Par = [-1]*N
for i, a in enumerate(A):
    if i == 0:
        if a != 1:
            ans += 1
        continue
    Par[i] = a-1
    graph[a-1].append(i)

q = []

stack = [0]
Depth = [-1]*N
Depth[0] = 0
while stack:
    p = stack.pop()
    for np in graph[p]:
        Depth[np] = Depth[p] + 1
        stack.append(np)
    if len(graph[p]) == 0:
        hp.heappush(q, (-Depth[p], p))

checked = [False]*N

while q:
    d, s = hp.heappop(q)
    d = -d
    if d <= K: break
    if checked[s]: continue
    
    
    for _ in range(K-1):
        s = Par[s]
    
    que = [s]
    while que:
        qq = []
        for p in que:
            for np in graph[p]:
                if not checked[np]:
                    checked[np] = True
                    qq.append(np)
        que = qq
    
    hp.heappush(q, (-Depth[Par[s]], Par[s]))
    ans += 1

print(ans)

Failing test case input:
8 1
-1 1 4 5 1 1 5 4

Expected output:
5


Actual output:
6


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


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

ans = 0
graph = [[] for _ in range(N)]
Par = [-1]*N
for i, a in enumerate(A):
    if i == 0:
        if a != 1:
            ans += 1
        continue
    Par[i] = a-1
    graph[a-1].append(i)

qs = []

stack = [0]
Depth = [-1]*N
Depth[0] = 0
while stack:
    p = stack.pop()
    for np in graph[p]:
        Depth[np] = Depth[p] + 1
        stack.append(np)
    qs.append((Depth[p], p))

qs.sort(reverse=True)
checked = [False]*N

for d, s in qs:
    if d <= K: break
    if checked[s]: continue

    for _ in range(K-1):
        s = Par[s]
    
    que = [s]
    checked[s] = True
    while que:
        qq = []
        for p in que:
            for np in graph[p]:
                if not checked[np]:
                    checked[np] = True
                    qq.append(np)
        que = qq
    
    ans += 1

print(ans)
Problem: p04008
Buggy submission (Python (3.4.3), verdict: Wrong Answer):




import sys
sys.setrecursionlimit(2 * 10 ** 5 + 10)

n,k =  [int(i) for i in input().split()]
a   =  [int(i)-1 for i in input().split()]



def dfs(u):
    global cnt
    depth = 0 
    
    for v in edges[u]:
        depth = max(depth, dfs(v)+1) 
    
    if depth>=k and u!=0:
        cnt += 1
        depth = 0
    
    return depth


cnt = 0
if a[0]!=0:
    cnt += 1

edges = [[] for _ in range(n)]
for i in range(1,n):
    pa = a[i]
    edges[a[i]].append(i)   

dfs(0)    
print(cnt)

Failing test case input:
8 2
4 1 4 5 2 2 5 4

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):




import sys
sys.setrecursionlimit(2 * 10 ** 5 + 10)

n,k =  [int(i) for i in input().split()]
a   =  [int(i)-1 for i in input().split()]



def dfs(u):
    global cnt
    depth = 0 
    
    for v in edges[u]:
        depth = max(depth, (dfs(v)+1)%k) 
        
    
    if depth==k-1 and u!=0 and a[u] != 0:
        cnt += 1
        
    return depth


cnt = 0
if a[0]!=0:
    cnt += 1

edges = [[] for _ in range(n)]
for i in range(1,n):
    pa = a[i]
    edges[a[i]].append(i)   

dfs(0)    
print(cnt)

Problem: p04008
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys
sys.setrecursionlimit(10**6)
n,k = map(int,input().split())
a = [int(i)-1 for i in input().split()]
edg = [[] for i in range(n)]
for i in range(1,n):
  edg[a[i]].append(i)
ans = [0] * n
ans[0] = a[0] != 0
def dfs(now):
  res = 0
  for e in edg[now]:
    res = max(res, dfs(e))
  if res == k - 1 and a[now] != 0 and now != 0:
    ans[now] = 1
    res = 0
  return res + 1
      
dfs(0)
print(sum(ans))


Failing test case input:
8 1
-1 1 4 5 1 1 5 4

Expected output:
5


Actual output:
4


Fixed submission (verdict: Accepted):
import sys
sys.setrecursionlimit(10**6)
n,k = map(int,input().split())
a = [int(i)-1 for i in input().split()]
edg = [[] for i in range(n)]
for i in range(1,n):
  edg[a[i]].append(i)
ans = [0] * n
ans[0] = a[0] != 0
def dfs(now):
  res = 0
  for e in edg[now]:
    res = max(res, dfs(e)+1)
  if res == k - 1 and a[now] != 0:
    ans[now] = 1
    res = -1
  return res
      
dfs(0)
print(sum(ans))
Problem: p01968
Buggy submission (Python3, verdict: Wrong Answer):

from collections import Counter
def inpl(): return tuple(map(int, input().split()))

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

C = Counter(A)
if C[-2] % 2 == 0:
    ans = [i+1 for i, a in enumerate(A) if abs(a) == 2]
    print(len(ans))
    if len(ans):
        print(*ans, sep="\n")
elif C[-1] > 0:
    ans = [i+1 for i, a in enumerate(A) if abs(a) == 2] + [A.index(-1) + 1]
    print(len(ans))
    if len(ans):
        print(*sorted(ans), sep="\n")
else:
    del A[-A[::-1].index(-2) - 1]
    ans = [i+1 for i, a in enumerate(A) if abs(a) == 2]
    print(len(ans))
    if len(ans):
        print(*ans, sep="\n")


Failing test case input:
4
0 -2 0 2

Expected output:
1
4


Actual output:
1
3


Fixed submission (verdict: Accepted):

from collections import Counter
def inpl(): return tuple(map(int, input().split()))

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

C = Counter(A)
if C[-2] % 2 == 0:
    ans = [i+1 for i, a in enumerate(A) if abs(a) == 2]
    print(len(ans))
    if len(ans):
        print(*ans, sep="\n")
elif C[-1] > 0:
    ans = [i+1 for i, a in enumerate(A) if abs(a) == 2] + [A.index(-1) + 1]
    print(len(ans))
    if len(ans):
        print(*sorted(ans), sep="\n")
else:
    d = N -A[::-1].index(-2)
    ans = [i+1 for i, a in enumerate(A) if abs(a) == 2]
    del ans[ans.index(d)]
    print(len(ans))
    if len(ans):
        print(*ans, sep="\n")
Problem: p03769
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

n = int(input())
x = []
y = []
k = 1
for c in bin(n)[2 :][1 :]:
    x += [ k ]
    y += [ k ]
    k += 1
    if int(c):
        x = [ k ] + x
        y += [ k ]
        k += 1
if not (x + y):
    x = [ 100 ]
print(len(x + y))
print(*(x + y))


Failing test case input:
462

Expected output:
28
14 12 10 8 4 2 1 3 5 6 7 9 11 13 1 2 3 4 5 6 7 8 9 10 11 12 13 14


Actual output:
26
12 10 8 4 2 1 3 5 6 7 9 11 13 1 2 3 4 5 6 7 8 9 10 11 12 13


Fixed submission (verdict: Accepted):

n = int(input())
x = []
y = []
k = 1
for c in bin(n + 1)[2 :][1 :]:
    x += [ k ]
    y += [ k ]
    k += 1
    if int(c):
        x = [ k ] + x
        y += [ k ]
        k += 1
print(len(x + y))
print(*(x + y))
Problem: p01102
Buggy submission (Python3, verdict: Wrong Answer):
s=[]

while 1:
    l1=input()
    if l1==".":
        break
    l2=input()

    sp1=l1.split('"')
    sp2=l2.split('"')
    
    t=0
    if len(sp1)==len(sp2):
        for i in range(len(sp1)):
            if i%2==1 and sp1[i]!=sp2[i]:
                t+=1
            elif i%2!=1 and sp1[i]!=sp2[i]:
                t+=2


    if sp1==sp2:
        s+=["INDENTCAL"]
    elif t==1:
        s+=["CLODSE"]
    else:
        s+=["DIFFERENT"]

for x in s:
    print(x)



Failing test case input:
print"hello";print123
print"hello";print123
read"B1input";solve;output;
read"B2";stlve;ovtpuo;
read"C1";solve;output"C1ans";
read"C2";solve;output"C2ans";
""""""""
"""42"""""
slwo"program"
fast"code"
"super"fast"program"
"super"faster"program"
""X
X
I"S""CREAM"
I"CE""CREAM"
11"22"11
1"33"111
.

Expected output:
IDENTICAL
DIFFERENT
DIFFERENT
CLOSE
DIFFERENT
DIFFERENT
DIFFERENT
CLOSE
DIFFERENT


Actual output:
INDENTCAL
DIFFERENT
DIFFERENT
CLODSE
DIFFERENT
DIFFERENT
DIFFERENT
CLODSE
DIFFERENT


Fixed submission (verdict: Accepted):
s=[]

while 1:
    l1=input()
    if l1==".":
        break
    l2=input()

    sp1=l1.split('"')
    sp2=l2.split('"')
    
    t=0
    if len(sp1)==len(sp2):
        for i in range(len(sp1)):
            if i%2==1 and sp1[i]!=sp2[i]:
                t+=1
            elif i%2!=1 and sp1[i]!=sp2[i]:
                t+=2


    if sp1==sp2:
        s+=["IDENTICAL"]
    elif t==1:
        s+=["CLOSE"]
    else:
        s+=["DIFFERENT"]

for x in s:
    print(x)