Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)
from numba import njit


@njit
def make_my_route(route,A,N):
    pre = 1
    for i in range(N):
        now = A[pre-1]
        route = np.append(route,now)
        temp = np.sum(route == now)
        if temp == 2:
            break
        pre = now
    return route


def main():
    N,K = map(int,input().split())
    A = list(map(int,input().split()))
    A = np.array(A)

    route = np.array([1])

    route = make_my_route(route,A,N)
    now = route[-1]
    start = int(np.where(route == now)[0][0])

    if K < start:
        res = route[K]
    elif start+1 != N:
        K -= start
        loop = route[start:-1]
        # print(loop,K)
        M = len(loop)
        K %= M
        res = loop[K]
    else:
        res = route[K]

    print(res)



main()


Fixed submission:
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)
# from numba import njit


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

    s = []
    ord = [-1] * (N+1)
    v = 1

    while ord[v] == -1:
        ord[v] = len(s)
        s.append(v)
        v = A[v-1]

    c = len(s) - ord[v]
    l = ord[v]

    if K < l:
        res = s[K]
    else:
        K -= l
        K %= c
        res = s[l+K]

    print(res)



main()

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)
from numba import njit


@njit
def make_my_route(route,A,N):
    pre = 1
    for i in range(N):
        now = A[pre-1]
        temp = np.sum(route == now)
        if temp == 1:
            break
        route = np.append(route,now)
        pre = now
    return (route,now)


def main():
    N,K = map(int,input().split())
    A = list(map(int,input().split()))
    A = np.array(A)

    route = np.array([1])

    route,now = make_my_route(route,A,N)
    start = int(np.where(route == now)[0])

    if K < start:
        res = route[K]
    elif start+1 != N:
        K -= start
        loop = route[start:]
        # print(loop,K)
        M = len(loop)
        K %= M
        res = loop[K]
    else:
        res = route[K]

    print(res)



main()


Fixed submission:
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)
# from numba import njit


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

    s = []
    ord = [-1] * (N+1)
    v = 1

    while ord[v] == -1:
        ord[v] = len(s)
        s.append(v)
        v = A[v-1]

    c = len(s) - ord[v]
    l = ord[v]

    if K < l:
        res = s[K]
    else:
        K -= l
        K %= c
        res = s[l+K]

    print(res)



main()
Buggy python submission (verdict: Time Limit Exceeded):
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


def main():
    N,K = map(int,input().split())
    H = list(map(int,input().split()))

    res = 0
    isNotEmpty = True

    for i in range(K):
        if H == []:
            isNotEmpty = False
            break
        temp = max(H)
        H.remove(temp)

    if isNotEmpty:
        res += sum(H)

    print(res)



main()


Fixed submission:
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


def main():
    N,K = map(int,input().split())
    H = list(map(int,input().split()))

    if N <= K:
        print(0)
        sys.exit()
    else:
        H.sort()
        temp = H[:N-K]
        res = sum(temp)

    print(res)



main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

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

mod = 10**9 + 7

res = 0

for i in range(60):
    count = 0
    for j in range(N):
        if ((A[j] >> i) & 1):
            count += 1
    res += (N - count) * count * 2 ** i 
    res %= mod

print(res)


Fixed submission:
import numpy as np
import sys
input = sys.stdin.readline

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

A = np.array(A,np.int64)

mod = 10**9 + 7

res = 0

for i in range(60):
    count = np.count_nonzero(A & 1)
    res += (N - count) * count * 2 ** i
    res %= mod
    A >>= 1

print(res)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

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

INF = 10**9 + 7

res = 0

for i in range(N-1):
    for j in range(i+1,N):
        res += A[i] ^ A[j]
        res %= INF

print(res)

Fixed submission:
import numpy as np
import sys
input = sys.stdin.readline

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

A = np.array(A,np.int64)

mod = 10**9 + 7

res = 0

for i in range(60):
    count = np.count_nonzero(A & 1)
    res += (N - count) * count * 2 ** i
    res %= mod
    A >>= 1

print(res)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

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

INF = 10**9 + 7

res = 0

for i in range(N-1):
    for j in range(i+1,N):
        res += A[i] ^ A[j]
        res %= INF

print(res)


Fixed submission:
import numpy as np
import sys
input = sys.stdin.readline

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

A = np.array(A,np.int64)

mod = 10**9 + 7

res = 0

for i in range(60):
    count = np.count_nonzero(A & 1)
    res += (N - count) * count * 2 ** i
    res %= mod
    A >>= 1

print(res)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))

INF = 10**9 + 7

res = 0

for i in range(N-1):
    for j in range(i+1,N):
        res += A[i] ^ A[j]
        res %= INF

print(res)


Fixed submission:
import numpy as np
import sys
input = sys.stdin.readline

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

A = np.array(A,np.int64)

mod = 10**9 + 7

res = 0

for i in range(60):
    count = np.count_nonzero(A & 1)
    res += (N - count) * count * 2 ** i
    res %= mod
    A >>= 1

print(res)
Buggy python submission (verdict: Runtime Error):
import numpy as np

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

Asum = sum(A)

Asort = sorted(A)
Fsort = sorted(F,reverse=True)

def test(x):
    res = max(0,Asort-x//Fsort).sum()
    return res <= K

left = -1
right = 10**13

while left+1 < right:
    mid = (left+right)//2
    if test(mid):
        right = mid
    else:
        left = mid

ans = right

print(ans)



Fixed submission:
import numpy as np

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

Asum = sum(A)

Asort = np.array(sorted(A))
Fsort = np.array(sorted(F,reverse=True))

def test(x):
    res = np.maximum(0,Asort-x//Fsort).sum()
    return res <= K

left = -1
right = 10**13

while left+1 < right:
    mid = (left+right)//2
    if test(mid):
        right = mid
    else:
        left = mid

ans = right

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
A = list(map(int,input().split()))
F = list(map(int,input().split()))

Asum = sum(A)

Asort = sorted(A)
Fsort = sorted(F,reverse=True)

def test(x):
    res = 0
    for i in range(N):
        res += max(0,Asort[i]-x//Fsort[i])
    return res <= K

left = -1
right = 10**13

while left+1 < right:
    mid = (left+right)//2
    if test(mid):
        right = mid
    else:
        left = mid

ans = right

print(ans)


Fixed submission:
import numpy as np

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

Asum = sum(A)

Asort = np.array(sorted(A))
Fsort = np.array(sorted(F,reverse=True))

def test(x):
    res = np.maximum(0,Asort-x//Fsort).sum()
    return res <= K

left = -1
right = 10**13

while left+1 < right:
    mid = (left+right)//2
    if test(mid):
        right = mid
    else:
        left = mid

ans = right

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))

P = []

for i in range(N):
    temp = A.index(i+1) + 1
    print(temp,end=' ')
#    temp = str(temp)
#    P.append(temp)


#print(' '.join(P))


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

P = ['']*N

for i in range(N):
    P[A[i]-1] = str(i + 1)


print(' '.join(P))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))

P = []

for i in range(N):
    temp = A.index(i+1) + 1
    temp = str(temp)
    P.append(temp)

print(' '.join(P))


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

P = ['']*N

for i in range(N):
    P[A[i]-1] = str(i + 1)


print(' '.join(P))
Buggy python submission (verdict: Runtime Error):
N,K,Q = map(int,input().split())

if K > Q:
    for i in range(N):
        print('Yes')
        sys.exit()

A = [int(input()) for i in range(Q)]

for i in range(N):
    temp = A.count(i+1)
    if K > Q-temp:
        print('Yes')
    else:
        print('No')


Fixed submission:
N,K,Q = map(int,input().split())

A = []

for i in range(Q):
    A.append(int(input()))

points = [K-Q]*N

for i in range(Q):
    points[A[i]-1] += 1

for i in range(N):
    if points[i] > 0:
        print('Yes')
    else:
        print('No')

Buggy python submission (verdict: Time Limit Exceeded):
N,K,Q = map(int,input().split())

A = [int(input()) for i in range(Q)]

for i in range(N):
    temp = A.count(i+1)
    if K > Q-temp:
        print('Yes')
    else:
        print('No')


Fixed submission:
N,K,Q = map(int,input().split())

A = []

for i in range(Q):
    A.append(int(input()))

points = [K-Q]*N

for i in range(Q):
    points[A[i]-1] += 1

for i in range(N):
    if points[i] > 0:
        print('Yes')
    else:
        print('No')

Buggy python submission (verdict: Time Limit Exceeded):
N,K,Q = map(int,input().split())

A = []

for i in range(Q):
    A.append(int(input()))

for i in range(N):
    temp = A.count(i+1)
    if K > Q-temp:
        print('Yes')
    else:
        print('No')


Fixed submission:
N,K,Q = map(int,input().split())

A = []

for i in range(Q):
    A.append(int(input()))

points = [K-Q]*N

for i in range(Q):
    points[A[i]-1] += 1

for i in range(N):
    if points[i] > 0:
        print('Yes')
    else:
        print('No')

Buggy python submission (verdict: Time Limit Exceeded):
N,K,Q = map(int,input().split())

A = []

for i in range(Q):
    A.append(int(input()))

res = [K]*N

for i in range(Q):
    res = list(map(lambda x: x-1,res))
    temp = A[i]-1
    res[temp] = res[temp] + 1

for i in range(N):
    if res[i] > 0:
        print('Yes')
    else:
        print('No')


Fixed submission:
N,K,Q = map(int,input().split())

A = []

for i in range(Q):
    A.append(int(input()))

points = [K-Q]*N

for i in range(Q):
    points[A[i]-1] += 1

for i in range(N):
    if points[i] > 0:
        print('Yes')
    else:
        print('No')
Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
A = list(map(int,input().split()))

test = [0]*N

for i in range(M):
    A.sort()
    A[-1] = A[-1] // 2
    if A == test:
        break

total = sum(A)
print(total)


Fixed submission:
N,M = map(int,input().split())
A = list(map(int,input().split()))

test = [0]*N

A = list(map(lambda x: x*(-1) ,A))

import heapq

heapq.heapify(A)

for i in range(M):
    temp = ( heapq.heappop(A) * (-1) ) // 2 * (-1) 
    heapq.heappush(A,temp)
    if A == test:
        break

total = sum(A) * (-1)
print(total)
Buggy python submission (verdict: Runtime Error):
a = list(input())
s1,s2,s3 = a[0],a[1],a[2]

count = 0
for i=range(a):
    count += a[i]

print(count)


Fixed submission:
a = list(input())
s1,s2,s3 = a[0],a[1],a[2]

count = 0
for i in range(len(a)):
    count += int(a[i])

print(count)
Buggy python submission (verdict: Runtime Error):
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


def main():
    S = input().rstrip()

    words = ['dream','dreamer','erase','eraser']

    res = 'YES'

    pre = S
    now = S

    while True:
        for i in range(4):
            word = words[i]
            N = len(word)
            M = len(now)
            if N <= M:
                # l = now[:N]
                r = now[M-N:]
                # if l == word:
                    # now = now[N:]
                if r == word:
                    now = now[:M-N]
            print(now)
        if now == '':
            break
        elif now == pre:
            res = 'NO'
            break
        else:
            pre = now

    print(res)



main()


Fixed submission:
S = input()

words = ['dream','dreamer','erase','eraser']

damm = True

T = ''

while damm:
    damm = False
    for test in words:
        if S.endswith(test+T):
            T = test + T
            damm = True
            break
    if S == T:
        damm = True
        break

if damm:
    print('YES')
else:
    print('NO')
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
# import math
# import collections
import sys
input = sys.stdin.readline

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

ab = []

eff = []

for i in range(N):
    temp = list(map(int,input().split()))
    ab.append(temp)
    for j in range(3):
        for k in range(3):
            if (temp[0]-j >= 1) & (temp[0]-j <= H-2):
                if (temp[1]-k >= 1) & (temp[1]-k <= W-2):
                    eff.append([temp[0]-j,temp[1]-k])

count = [0 for i in range(10)]

while True:
    if eff == []:
        break
    num = eff.count(eff[0])
    count[num] += 1
    eff = [i for i in eff if i != eff[0]]

count[0] = (H-2) * (W-2) - sum(count)

for i in range(10):
    print(count[i])


Fixed submission:
import numpy as np
# import math
import collections
import sys
input = sys.stdin.readline

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

ab = []

eff = collections.defaultdict(int)

for i in range(N):
    temp = list(map(int,input().split()))
    ab.append(temp)
    for j in range(3):
        for k in range(3):
            if (temp[0]-j >= 1) & (temp[0]-j <= H-2):
                if (temp[1]-k >= 1) & (temp[1]-k <= W-2):
                    eff[(temp[0]-j,temp[1]-k)] += 1

count = collections.Counter(eff.values())

count0 = (H-2) * (W-2) - sum(count.values())

print(count0)
for i in range(1,10):
    if i in count:
        print(count[i])
    else:
        print(0)
Buggy python submission (verdict: Time Limit Exceeded):
N,A = map(int,input().split())
x = list(map(int,input().split()))

temp = x + [A]

X = max(temp)

m = N * X

dp = [[[0]*(m+1) for k in range(N+1)] for j in range(N+1)]

dp[0][0][0] = 1

res = 0

for j in range(N+1):
    for k in range(N+1):
        for s in range(m+1):
            if (j >= 1) & (s < x[j-1]):
                dp[j][k][s] = dp[j-1][k][s]
            elif (j >= 1) & (k >= 1) & (s >= x[j-1]):
                dp[j][k][s] = dp[j-1][k][s] + dp[j-1][k-1][s-x[j-1]]

        if (k >= 1) & (j == N):
            res += dp[N][k][k*A]

print(res)


Fixed submission:
N,A = map(int,input().split())
x = list(map(int,input().split()))

temp = x + [A]

X = max(temp)

m = N * X

dp = [[[0 for s in range(m+1)] for k in range(N+1)] for j in range(N+1)]

dp[0][0][0] = 1

res = 0

for j in range(N):
    for k in range(N):
        for s in range(m):
            if dp[j][k][s]:
                dp[j+1][k][s] += dp[j][k][s]
                dp[j+1][k+1][s+x[j]] += dp[j][k][s]

for k in range(1,N+1):
    res += dp[N][k][k*A]

print(res)

Buggy python submission (verdict: Time Limit Exceeded):
N,A = map(int,input().split())
x = list(map(int,input().split()))

temp = x + [A]

X = max(temp)

m = N * X

dp = [[[0]*(m+1) for k in range(N+1)] for j in range(N+1)]

for j in range(N+1):
    for k in range(N+1):
        for s in range(m+1):
            if (j == 0) & (k == 0) & (s == 0):
                dp[j][k][s] = 1
            elif (j >= 1) & (s < x[j-1]):
                dp[j][k][s] = dp[j-1][k][s]
            elif (j >= 1) & (k >= 1) & (s >= x[j-1]):
                dp[j][k][s] = dp[j-1][k][s] + dp[j-1][k-1][s-x[j-1]]

res = 0

for i in range(N):
    res += dp[N][i+1][(i+1)*A]

print(res)


Fixed submission:
N,A = map(int,input().split())
x = list(map(int,input().split()))

temp = x + [A]

X = max(temp)

m = N * X

dp = [[[0 for s in range(m+1)] for k in range(N+1)] for j in range(N+1)]

dp[0][0][0] = 1

res = 0

for j in range(N):
    for k in range(N):
        for s in range(m):
            if dp[j][k][s]:
                dp[j+1][k][s] += dp[j][k][s]
                dp[j+1][k+1][s+x[j]] += dp[j][k][s]

for k in range(1,N+1):
    res += dp[N][k][k*A]

print(res)
Buggy python submission (verdict: Runtime Error):
s = str(input())

flag = True

res = -1

for i in range(len(s)-2):
    if s[i] == s[i+1]:
        print(i+1,i+3)
        flag = False
        break
    elif s[i] == s[i+2]:
        print(i+1,i+3)
        flag = False
        break

if flag:
    if s[-2] == s[-1]:
        print(len(s)-2,len(s))
    elif s[-3] == s[-1]:
        print(len(s)-2,len(s))
    else:
        print(res,res)


Fixed submission:
s = str(input())

flag = True

res = -1

import sys

if len(s) == 2:
    if s[0] == s[1]:
        print(1,2)
    else:
        print(-1,-1)
    sys.exit()

for i in range(len(s)-2):
    if s[i] == s[i+1]:
        print(i+1,i+3)
        flag = False
        break
    elif s[i] == s[i+2]:
        print(i+1,i+3)
        flag = False
        break

if flag:
    if s[-2] == s[-1]:
        print(len(s)-2,len(s))
    elif s[-3] == s[-1]:
        print(len(s)-2,len(s))
    else:
        print(res,res)

Buggy python submission (verdict: Time Limit Exceeded):
s = str(input())

partlen = 3

flag = True

res = -1

while flag:
    for i in range(len(s)-partlen+1):
        BoderNum = partlen // 2 +1
        temp = s[i:i+partlen]
        for j in range(partlen):
            TestNum = temp.count(temp[j])
            if TestNum >= BoderNum:
                print(i+1,i+partlen)
                flag = False
                break
        if flag == False:
            break
    if partlen == len(s):
        print(res,res)
        break
    partlen += 1


Fixed submission:
s = str(input())

flag = True

res = -1

import sys

if len(s) == 2:
    if s[0] == s[1]:
        print(1,2)
    else:
        print(-1,-1)
    sys.exit()

for i in range(len(s)-2):
    if s[i] == s[i+1]:
        print(i+1,i+3)
        flag = False
        break
    elif s[i] == s[i+2]:
        print(i+1,i+3)
        flag = False
        break

if flag:
    if s[-2] == s[-1]:
        print(len(s)-2,len(s))
    elif s[-3] == s[-1]:
        print(len(s)-2,len(s))
    else:
        print(res,res)
Buggy python submission (verdict: Runtime Error):
H,W,A,B = map(int,input().split())

mod = 10**9 + 7

f = [1]
for i in range(H+W):
    f.append(f[i]*(i+1)%mod)

def comb(A,B,mod):
    return f[A] * pow(f[B],mod-2,mod) * pow(f[a-b],mod-2,mod) % mod

res = 0

for i in range(B,W):
    res += comb(H-A+i-1,i,mod) * comb(A+W-i-2,A-1,mod) % mod

print(res%mod)

Fixed submission:
H,W,A,B = map(int,input().split())

mod = 10**9 + 7

f = [1]
for i in range(H+W):
    f.append(f[i]*(i+1)%mod)

def comb(A,B,mod):
    return f[A] * pow(f[B],mod-2,mod) * pow(f[A-B],mod-2,mod) % mod

res = 0

for i in range(B,W):
    res += comb(H-A+i-1,i,mod) * comb(A+W-i-2,A-1,mod) % mod

print(res%mod)

Buggy python submission (verdict: Time Limit Exceeded):
import math

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

res1 = math.factorial(H+W-2)//(math.factorial(H-1)*math.factorial(W-1))
res1 = res1 % (10**9 + 7)

res2 = 0

for i in range(B):
    temp1 = math.factorial(H-A-1+i)//(math.factorial(H-A-1)*math.factorial(i))
    temp1 = temp1 % (10**9 + 7)
    if A == 1:
        temp2 = 1
    else:
        temp2 = math.factorial(W+A-i-2)//(math.factorial(A-1)*math.factorial(W-i-1))
        temp2 = temp2 % (10**9 + 7)
    res2 += temp1 * temp2
    res2 = res2 % (10**9 + 7)

res = res1 - res2
res = res % (10**9 + 7)

print(res)


Fixed submission:
H,W,A,B = map(int,input().split())

mod = 10**9 + 7

f = [1]
for i in range(H+W):
    f.append(f[i]*(i+1)%mod)

def comb(A,B,mod):
    return f[A] * pow(f[B],mod-2,mod) * pow(f[A-B],mod-2,mod) % mod

res = 0

for i in range(B,W):
    res += comb(H-A+i-1,i,mod) * comb(A+W-i-2,A-1,mod) % mod

print(res%mod)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input().split()
w_index = []
r_index = []
length_ = len(S[0])

for i in range(len(S[0])):
    s = S[0][i]
    if s =='W':
        w_index.append(i)
    else:
        r_index.append(i)
        
if len(w_index) == 0 or len(r_index) == 0:
    print(0)

else:
    
    ng_num = 0
    for r_i in range(len(r_index)):

        if r_i not in r_index:
            ng_num += 1
        
    print(ng_num)

Fixed submission:
N = int(input())
S = input().split()[0]

length = len(S)

W_count = S.count('W')
R_count = S.count('R')

c = 0
if R_count < W_count:
    
    for i in range(R_count):
        s = S[i]
        if s !='R':
            c+=1
        
            
else:
    for i in range(W_count):
        s = S[-1-i]
        if s != 'W':
            c+=1
print(c)
Buggy python submission (verdict: Runtime Error):
result = 0
for n in range (L, R + 1):
    if n % D == 0:
        result += 1
print(result)

Fixed submission:
L, R, D = map(int, input().split())
result = 0
for n in range (L, R + 1):
    if n % D == 0:
        result += 1
print(result)