Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
a = list(map(int,input().split()))
ruto = [1]
cnt = 0
saki = a[0]
for i in range(n):
    if cnt != k:
        if saki not in ruto:
            ruto.append(saki)
            cnt += 1
            saki = a[saki-1]
        else:
            where = ruto.index(saki)
            ruto = ruto[where:]
            K = k-where
            ans = K%len(ruto)
            print(ruto[ans])
            break
    else:
        print(ruto[-1])
        break

Fixed submission:
n,k = map(int,input().split())
a = list(map(int,input().split()))
ruto = [1]
kako = [0] * (n+1)
kako[1] = 1
saki = a[0]
flag = 0
for _ in range(k):
    if kako[saki] == 1:
        where = ruto.index(saki)
        ruto = ruto[where:]
        ans = (k-where)%len(ruto)
        print(ruto[ans])
        flag = 1
        break
    else:
        ruto.append(saki)
        kako[saki] = 1
        saki = a[saki-1]
if flag == 0:    
    print(ruto[-1])
Buggy python submission (verdict: Time Limit Exceeded):
n,x,y = map(int,input().split())
ans = {}
for i in range(1,n):
    for j in range(i+1,n+1):
        dist = min(abs(i-j),abs(i-x)+abs(j-y)+1,abs(i-y)+abs(j-x)+1)
        if dist in ans.keys():
            ans[dist] += 1
        else:
            ans[dist] = 1
for k in range(1,n):
    if k in ans.keys():
        print(ans[k])
    else:
        print(0)

Fixed submission:
n,x,y = map(int,input().split())
ans = {}
s = (y-x+1)//2
s = x+s
for i in range(1,n):
    for j in range(i+1,n+1):
        if i <= s:
            dist = min(j-i,abs(i-x)+abs(j-y)+1)
        else:
            dist = j-i
        if dist in ans.keys():
            ans[dist] += 1
        else:
            ans[dist] = 1
for k in range(1,n):
    if k in ans.keys():
        print(ans[k])
    else:
        print(0)

Buggy python submission (verdict: Time Limit Exceeded):
import queue
n,x,y = map(int,input().split())
ans = {}
for i in range(1,n):
    dist = [-1]*n
    q = queue.Queue()
    dist[i-1] = 0
    q.put(i)
    while True:
        if q.empty():
            break
        else:
            a = q.get()
            if a > 1 and dist[a-2] == -1:
                dist[a-2] = dist[a-1]+1
                q.put(a-1)
            if a < n and dist[a] == -1:
                dist[a] = dist[a-1]+1
                q.put(a+1)
            if a == x and dist[y-1] == -1:
                dist[y-1] = dist[a-1]+1
                q.put(y)
            if a == y and dist[x-1] == -1:
                dist[x-1] = dist[a-1]+1
                q.put(x)
    for j in range(i,n):
        s = dist[j]
        if s in ans.keys():
            ans[s] += 1
        else:
            ans[s] = 1
for k in range(1,n):
    if k in ans.keys():
      print(ans[k])
    else:
      print(0)  

Fixed submission:
n,x,y = map(int,input().split())
ans = {}
s = (y-x+1)//2
s = x+s
for i in range(1,n):
    for j in range(i+1,n+1):
        if i <= s:
            dist = min(j-i,abs(i-x)+abs(j-y)+1)
        else:
            dist = j-i
        if dist in ans.keys():
            ans[dist] += 1
        else:
            ans[dist] = 1
for k in range(1,n):
    if k in ans.keys():
        print(ans[k])
    else:
        print(0)
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
p = list(map(int,input().split()))
p_2 = []
for i in range(n):
    if p[i]%2 == 0:
        p_2.append(p[i]//2+0.5)
    else:
        p_2.append(p[i]//2 + 1)
maxer = 0
for i in range(n-k+1):
    cnt = sum(p_2[i:i+k])
    if cnt >= maxer:
        maxer = cnt
print(maxer)

Fixed submission:
n,k = map(int,input().split())
p = list(map(int,input().split()))
maxer = sum(p[:k])
cnt = maxer
st = 0
for i in range(n-k):
    cnt = cnt - p[i] + p[i+k]
    if cnt >= maxer:
        maxer = cnt
        st = i+1
ans = 0
for i in range(st,st+k):
    if p[i]%2 == 0:
        ans += (p[i]//2+0.5)
    else:
        ans += (p[i]//2 + 1)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
p = list(map(int,input().split()))
p_2 = []
for i in range(n):
    if p[i]%2 == 0:
        p_2.append(p[i]//2+0.5)
    else:
        p_2.append(p[i]//2 + 1)
maxer = 0
for i in range(n-k+1):
    cnt = sum(p_2[i:i+k])
    if cnt >= maxer:
        maxer = cnt
print(maxer)

Fixed submission:
n,k = map(int,input().split())
p = list(map(int,input().split()))
maxer = sum(p[:k])
cnt = maxer
st = 0
for i in range(n-k):
    cnt = cnt - p[i] + p[i+k]
    if cnt >= maxer:
        maxer = cnt
        st = i+1
ans = 0
for i in range(st,st+k):
    if p[i]%2 == 0:
        ans += (p[i]//2+0.5)
    else:
        ans += (p[i]//2 + 1)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, k, q = map(int, input().split())
a = [int(input()) for i in range(q)]
for s in range(1, n+1):
	b = a.count(s)
	if b > q-k:
		print("Yes")
	else:
		print("No")

Fixed submission:
n, k, q = map(int, input().split())
a = [k-q] * n
for s in range(q):
	t = int(input())
	a[t-1] += 1
for u in range(n):
	if a[u] > 0:
		print("Yes")
	else:
		print("No")
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = [int(i) for i in input().split()]
a.sort(reverse=True)
if n == 1:
	print(a[0]//(2**m))
else:
	for s in range(m):
		maxnum = 0
		flag = 0
		for t in range(s):
			if maxnum <= a[t]:
				maxnum = a[t]
				flag = t
		a[flag] = a[flag]//2
	print(sum(a))

Fixed submission:
import bisect
n,m = map(int,input().split())
a = list(map(int,input().split()))
while m != 0:
    a.sort()
    where = bisect.bisect_left(a,a[-1]//2)
    where = abs(where-(n+1))
    for i in range(1,min(where,m+1)):
        a[-i] = a[-i]//2
        m = m-1
print(sum(a))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a = [int(i) for i in input().split()]
a.sort(reverse=True)
for t in range(m):
	b = a[0]//2
	del a[0]
	if len(a) == 0:
		a.append(b)
	elif b <= a[-1]:
		a.append(b)
	else:
		for s in range(n-1):
			if b >= a[s]:
				a.insert(s, b)
				break
print(sum(a))

Fixed submission:
import bisect
n,m = map(int,input().split())
a = list(map(int,input().split()))
while m != 0:
    a.sort()
    where = bisect.bisect_left(a,a[-1]//2)
    where = abs(where-(n+1))
    for i in range(1,min(where,m+1)):
        a[-i] = a[-i]//2
        m = m-1
print(sum(a))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a = [int(i) for i in input().split()]
a.sort(reverse=True)
for i in range(m):
	a[0] = a[0]//2
	a.sort(reverse=True)
print(sum(a))

Fixed submission:
import bisect
n,m = map(int,input().split())
a = list(map(int,input().split()))
while m != 0:
    a.sort()
    where = bisect.bisect_left(a,a[-1]//2)
    where = abs(where-(n+1))
    for i in range(1,min(where,m+1)):
        a[-i] = a[-i]//2
        m = m-1
print(sum(a))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ans = 0
for i in range(n):
  ans += i
print(ans)

Fixed submission:
n = int(input())
print((n-1)*n//2)
Buggy python submission (verdict: Time Limit Exceeded):
import queue
n,Q = map(int,input().split())
ki = [[] for i in range(n)]
for _ in range(n-1):
    a,b = map(int,input().split())
    ki[a-1].append(b-1)
    ki[b-1].append(a-1)
q = queue.Queue()
cnt = [0] * n
for _ in range(Q):
    p,x = map(int,input().split())
    cnt[p-1] += x
vis = [-1] * n
q.put(0)
vis[0] = 1
while True:
    if q.empty():
        break
    a = q.get()
    a_ = ki[a]
    for i in a_:
        if vis[i] == -1:
            q.put(i)
            vis[i] = 1
            cnt[i] += cnt[a]
print(*cnt)

Fixed submission:
from collections import deque
n,Q = map(int,input().split())
ki = [[] for i in range(n)]
for _ in range(n-1):
    a,b = map(int,input().split())
    ki[a-1].append(b-1)
    ki[b-1].append(a-1)
q = deque()
cnt = [0] * n
for _ in range(Q):
    p,x = map(int,input().split())
    cnt[p-1] += x
vis = [-1] * n
q.append(0)
vis[0] = 1
while q:
    a = q.popleft()
    a_ = ki[a]
    for i in a_:
        if vis[i] == -1:
            q.append(i)
            vis[i] = 1
            cnt[i] += cnt[a]
print(*cnt)

Buggy python submission (verdict: Time Limit Exceeded):
import queue
n,Q = map(int,input().split())
ki = [[] for i in range(n)]
for _ in range(n-1):
    a,b = map(int,input().split())
    ki[a-1].append(b-1)
    ki[b-1].append(a-1)
q = queue.Queue()
cnt = [0] * n
for _ in range(Q):
    p,x = map(int,input().split())
    cnt[p-1] += x
vis = [-1] * n
q.put(0)
vis[0] = 1
while True:
    if q.empty():
        break
    a = q.get()
    a_ = ki[a]
    for i in a_:
        if vis[i] == -1:
            q.put(i)
            vis[i] = 1
            cnt[i] += cnt[a]
print(*cnt)

Fixed submission:
from collections import deque
n,Q = map(int,input().split())
ki = [[] for i in range(n)]
for _ in range(n-1):
    a,b = map(int,input().split())
    ki[a-1].append(b-1)
    ki[b-1].append(a-1)
q = deque()
cnt = [0] * n
for _ in range(Q):
    p,x = map(int,input().split())
    cnt[p-1] += x
vis = [-1] * n
q.append(0)
vis[0] = 1
while q:
    a = q.popleft()
    a_ = ki[a]
    for i in a_:
        if vis[i] == -1:
            q.append(i)
            vis[i] = 1
            cnt[i] += cnt[a]
print(*cnt)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
S = {}
cnt = 0
for _ in range(n):
    s = input()
    s = sorted(s)
    u = "".join(s)
    if u in S.keys():
        S[u] += 1
    else:
        S[u] = 1
for x in S.values():
    x = x-1
    cnt += x*(x+1)//2
print(cnt)

Fixed submission:
n = int(input())
S = {}
cnt = 0
for _ in range(n):
    s = input()
    s = sorted(s)
    u = ""
    for i in range(len(s)):
      u += s[i]
    if u in S.keys():
        S[u] += 1
    else:
        S[u] = 1
for x in S.values():
    x = x-1
    cnt += x*(x+1)//2
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
S = {}
cnt = 0
for _ in range(n):
    s = input()
    s = sorted(s)
    u = ""
    for i in range(len(s)):
      u += s[i]
    if u in S.keys():
        S[u] += 1
    else:
        S[u] = 1
for x in S.values():
    x = x-1
    cnt += x*(x+1)//2
print(cnt)

Fixed submission:
n = int(input())
S = {}
cnt = 0
for _ in range(n):
    s = input()
    s = sorted(s)
    u = ""
    for i in range(len(s)):
      u += s[i]
    if u in S.keys():
        S[u] += 1
    else:
        S[u] = 1
for x in S.values():
    x = x-1
    cnt += x*(x+1)//2
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
A = list()
for i in range(m):
    a = int(input())
    A.append(a)
dp = [0]*(n+1)
dp[0] = 1
if 1 not in A:
    dp[1] = 1
for i in range(2,n+1):
    if i not in A:
        dp[i] = dp[i-2] + dp[i-1]
        dp[i] = dp[i]%1000000007
print(dp[-1]%1000000007)

Fixed submission:
n,m = map(int,input().split())
A = list()
for i in range(m):
    a = int(input())
    A.append(a)
dp = [0]*(n+1)
dp[0] = 1
if 1 in A:
  del A[0]
else:
  dp[1] = 1
for i in range(2,n+1):
    if len(A) != 0:        
        if i != A[0]:
            dp[i] = dp[i-2] + dp[i-1]
            dp[i] = dp[i]%1000000007
        else:
          del A[0]
    else:
        dp[i] = dp[i-2] + dp[i-1]
        dp[i] = dp[i]%1000000007
print(dp[-1]%1000000007)

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
A = list()
for i in range(m):
    a = int(input())
    A.append(a)
dp = [0]*(n+1)
dp[0] = 1
if 1 not in A:
    dp[1] = 1
for i in range(2,n+1):
    if i not in A:
        dp[i] = dp[i-2] + dp[i-1]
print(dp[-1]%1000000007)

Fixed submission:
n,m = map(int,input().split())
A = list()
for i in range(m):
    a = int(input())
    A.append(a)
dp = [0]*(n+1)
dp[0] = 1
if 1 in A:
  del A[0]
else:
  dp[1] = 1
for i in range(2,n+1):
    if len(A) != 0:        
        if i != A[0]:
            dp[i] = dp[i-2] + dp[i-1]
            dp[i] = dp[i]%1000000007
        else:
          del A[0]
    else:
        dp[i] = dp[i-2] + dp[i-1]
        dp[i] = dp[i]%1000000007
print(dp[-1]%1000000007)
Buggy python submission (verdict: Runtime Error):
r, g, b, n = map(int, input().split())
counter = 0
for s in range(n+1):
    for t in range(n-i+1):
        u = n - r*s - g*t
        if u >= 0 and u % b == 0:
            counter += 1
print(counter)

Fixed submission:
n,k = map(int,input().split())
print(n-k+1)
Buggy python submission (verdict: Time Limit Exceeded):
R, G, B, N = map(int, input().split())
counter = 0
r = N // R + 1
g = N // G + 1
for s in range(r):
  for t in range(g):
    u = N - R*s - G*t
    if u >= 0 and u % B == 0:
      counter += 1
print(counter)

Fixed submission:
r, g, b, n = map(int, input().split())
counter = 0
for s in range(n+1):
  for t in range(n-s+1):
    u = n - r*s - g*t
    if u >= 0 and u % b == 0:
      counter += 1
print(counter)

Buggy python submission (verdict: Runtime Error):
r, g, b, n = map(int, input().split())
counter = 0
for s in range(n+1):
    for t in range(n-i+1):
        u = n - r*s - g*t
        if u >= 0 and u % b == 0:
            counter += 1
print(counter)

Fixed submission:
r, g, b, n = map(int, input().split())
counter = 0
for s in range(n+1):
  for t in range(n-s+1):
    u = n - r*s - g*t
    if u >= 0 and u % b == 0:
      counter += 1
print(counter)

Buggy python submission (verdict: Time Limit Exceeded):
R, G, B, N = map(int, input().split())
counter = 0
r = N // R + 1
for s in range(r):
	g = (N - s*R) // G + 1
	for t in range(g):
		if s*R + t*G <= N and (N - (s*R + t*G)) % B == 0:
			counter += 1
print(counter)


Fixed submission:
r, g, b, n = map(int, input().split())
counter = 0
for s in range(n+1):
  for t in range(n-s+1):
    u = n - r*s - g*t
    if u >= 0 and u % b == 0:
      counter += 1
print(counter)

Buggy python submission (verdict: Time Limit Exceeded):
R, G, B, N = map(int, input().split())
counter = 0
r = N // R + 1
g = N // G + 1
for s in range(r):
	for t in range(g):
		if s*R + t*G <= N and (N - (s*R + t*G)) % B == 0:
			counter += 1
print(counter)


Fixed submission:
r, g, b, n = map(int, input().split())
counter = 0
for s in range(n+1):
  for t in range(n-s+1):
    u = n - r*s - g*t
    if u >= 0 and u % b == 0:
      counter += 1
print(counter)

Buggy python submission (verdict: Time Limit Exceeded):
A = [int(i) for i in input().split()]
n = A.pop(3)
num1 = A[0]
num2 = A[1]
num3 = A[2]
cnt = 0
for s in range(n // num3 + 1):
	total = 0
	for t in range(n // num2 + 1):
		k = (n-(s*num3+t*num2))//num1
		if k >= 0:
			total = s*num3+t*num2+k*num1
			if total == n:
				cnt += 1
print(cnt)

Fixed submission:
r, g, b, n = map(int, input().split())
counter = 0
for s in range(n+1):
  for t in range(n-s+1):
    u = n - r*s - g*t
    if u >= 0 and u % b == 0:
      counter += 1
print(counter)
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()
count1 = 0
count2 = 0
m = -1
t = n
for x in range(n):
	if s[x] == "#":
		m = x
		break
if m != -1:
	for u in range(m,n):
	    if s[u] == ".":
		    count1 += 1
		else:
			count2 += 1
	while s[t] == "#":
		count2 -= 1
		t = t-1
print(min(count1,count2))

Fixed submission:
n = int(input())
s = input()
counter = s.count(".")
ans = counter
for i in range(n):
	if s[i] == ".":
		counter -= 1
	else:
		counter += 1
	ans = min(ans, counter)
print(ans)
Buggy python submission (verdict: Runtime Error):
a = [int(input()) for i in range(5)]
b = []
for i in range(5):
	x = a[i]%10
	if x != 0:
	    b.append(10 - x)
ans = 0
for u in a:
    ans += u // 10 * 10
ans += len(b) * 10
ans -= max(b)
print(ans) 

Fixed submission:
a = [int(input()) for i in range(5)]
b = []
for i in range(5):
	x = a[i]%10
	if x != 0:
	    b.append(10 - x)
ans = 0
for u in a:
    ans += u // 10 * 10
ans += len(b) * 10
if len(b) != 0:
	ans -= max(b)
print(ans)

Buggy python submission (verdict: Runtime Error):
a = [int(input()) for i in range(5)]
b = []
for i in range(5):
	x = a[i]%10
	if x != 0:
	    b.append(10 - x)
ans = 0
for u in a:
    ans += u // 10 * 10
ans += len(b) * 10
ans -= max(b)
print(ans) 

Fixed submission:
a = [int(input()) for i in range(5)]
b = []
for i in range(5):
	x = a[i]%10
	if x != 0:
	    b.append(10 - x)
ans = 0
for u in a:
    ans += u // 10 * 10
ans += len(b) * 10
if len(b) != 0:
	ans -= max(b)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
s = input()
for t in range(q):
	l, r = map(int, input().split())
	u = s[l-1:r]
	counter = 0
	for i in range(len(u)-1):
		if u[i] == "A" and u[i+1] == "C":
			counter += 1
	print(counter)

Fixed submission:
n, q = map(int, input().split())
s = input()
b = [0]
for t in range(1, n):
	if s[t-1] == "A" and s[t] == "C":
		b.append(b[t-1] + 1)
	else:
		b.append(b[t-1])
for u in range(q):
	l, r = map(int, input().split())
	print(b[r-1] - b[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int,input().split())
s = input()
b = []
for t in range(n-1):
	if s[t] == "A" and s[t+1] == "C":
		b.append(t+1)
for u in range(q):
	l, r = map(int, input().split())
	C = []
	if l != r:
		C = [i for i in range(l, r)]
		D = set(b) & set(C)
		print(len(D))

Fixed submission:
n, q = map(int, input().split())
s = input()
b = [0]
for t in range(1, n):
	if s[t-1] == "A" and s[t] == "C":
		b.append(b[t-1] + 1)
	else:
		b.append(b[t-1])
for u in range(q):
	l, r = map(int, input().split())
	print(b[r-1] - b[l-1])
Buggy python submission (verdict: Runtime Error):
n = int(input())
h = list(map(int,input().split())
dp = [0]*n
dp[1] = abs(h[0]-h[1])
for i in range(2,n):
    dp[i] = min(dp[i-2]+abs(h[i-2]-h[i]), dp[i-1]+abs(h[i-1]-h[i]))
print(dp[-1])

Fixed submission:
n = int(input())
h = list(map(int, input().split()))
DP = [0] * n
DP[0] = 0
DP[1] = abs(h[0]-h[1])
for i in range(2,n):
    DP[i] = min(DP[i-2]+abs(h[i-2]-h[i]),DP[i-1]+abs(h[i-1]-h[i]))
print(DP[-1])
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int, input().split())
h = list(map(int, input().split()))
dp = [0] * n
dp[0] = 0
dp[1] = abs(h[0]-h[1])

for i in range(2,n):
    best_jump = 10**10
    
    for j in range(1, k+1):
        if i-j < 0:
            break
        else:
            jump = dp[i-j] + abs(h[i]-h[i-j])      
            if jump < best_jump:
                best_jump = jump            
    dp[i] = best_jump
    
print(dp[-1])

Fixed submission:
n,k = map(int, input().split())
h = list(map(int, input().split()))
dp = [0] * n
dp[0] = 0
dp[1] = abs(h[0]-h[1])

for i in range(2,n):
    best_jump = 10**10
    
    for j in range(1, k+1):
        if i-j < 0:
            break
        else:
            jump = dp[i-j] + abs(h[i]-h[i-j])      
            if jump < best_jump:
                best_jump = jump            
    dp[i] = best_jump
    
print(dp[-1])
Buggy python submission (verdict: Runtime Error):
n = int(input())
for _ in range(n):
    a,b,c = map(int,input().split())
    A.append(a)
    B.append(b)
    C.append(c)
dp = [[0]*3 for i in range(n)]
dp[0][0] = A[0]
dp[0][1] = B[0]
dp[0][2] = C[0]
for i in range(1,n):
    dp[i][0] = max(dp[i-1][1]+A[i],dp[i-1][2]+A[i])
    dp[i][1] = max(dp[i-1][0]+B[i],dp[i-1][2]+B[i])
    dp[i][2] = max(dp[i-1][0]+C[i],dp[i-1][1]+C[i])
print(max(dp[-1]))

Fixed submission:
n = int(input())
A = []
B = []
C = []
for i in range(n):
    a,b,c = map(int,input().split())
    A.append(a)
    B.append(b)
    C.append(c)
    
dp = [[0 for i in range(3)] for j in range(n)]

dp[0][0] = A[0]
dp[0][1] = B[0]
dp[0][2] = C[0]

for i in range(1,n):
    dp[i][0] = max(dp[i-1][1],dp[i-1][2])+A[i]
    dp[i][1] = max(dp[i-1][0],dp[i-1][2])+B[i]
    dp[i][2] = max(dp[i-1][0],dp[i-1][1])+C[i]

print(max(dp[n-1][0],dp[n-1][1],dp[n-1][2]))
Buggy python submission (verdict: Runtime Error):
N,W = map(int,input().split())
w_list = []
v_list = []
for _ in range(N):
    w,v = map(int,input().split())
    w_list.append(w)
    v_list.append(v)
dp = [[0]*(W+1) for i in range(N+1)]
for i in range(1,N+1):
    w = w_list[i-1]
    v = v_list[i-1]
    for j in range(1,W+1):
        if j-w >= 0:
            dp[i][j] = max(dp[i-1][j],dp[i-1][j-w]+v)
        else:
            dp[i][j] = dp[i-1][j]
print(dp[N][W])

Fixed submission:
N,W = map(int,input().split())
w_list = []
v_list = []
for _ in range(N):
    w,v = map(int,input().split())
    w_list.append(w)
    v_list.append(v)
dp = [[10**12]*(10**5+1) for i in range(N+1)]
dp[0][0] = 0
for i in range(1,N+1):
    w = w_list[i-1]
    v = v_list[i-1]
    for j in range(10**5+1):
        if j-v >= 0:
            dp[i][j] = min(dp[i-1][j], dp[i-1][j-v]+w)
        else:
            dp[i][j] = dp[i-1][j]
maxer = 0
for j in range(10**5+1):
    if dp[i][j] <= W:
        maxer = j
print(maxer)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int,input().split())
a = []
for i in range(m):
    x,y=[int(i) for i in input().split()]
    a.append([x,y])
for s in range(m):
	counter = 1
	for t in range(m):
		if a[s][0] == a[t][0] and a[s][1] > a[t][1]:
			counter += 1
	print(str("{0:06d}".format(a[s][0])) + str("{0:06d}".format(counter)))

Fixed submission:
n,m = map(int,input().split())
si = []
for i in range(m):
    p,y = map(int,input().split())
    si.append([i,p,y])
si.sort(key=lambda x:x[2])
ans = []
all = [0]*n
for i in range(m):
    now = si[i]
    all[now[1]-1] += 1
    x = all[now[1]-1]
    ans.append([now[0],now[1],x])
ans.sort(key=lambda x:x[0])
for i in range(m):
    now = ans[i]
    str_1 = str(now[1])
    str_1 = str_1.zfill(6)
    str_2 = str(now[2])
    str_2 = str_2.zfill(6)
    print(str_1+str_2)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
v = [int(i) for i in input().split()]
if len(set(v)) == 1:
    print(int(n / 2))
else:
    v1 = v[0::2]
    v2 = v[1::2]
    v1b = set(v1)
    stop1 = len(v1b)
    A1 = []
    for i in v1b:
        num = v1.count(i)
        A1.append(num)
    A1.sort()
    ans1 = sum(A1[:stop1-1])
    v2b = set(v2)
    stop2 = len(v2b)
    A2 = []
    for t in v2b:
        num = v2.count(t)
        A2.append(num)
    A2.sort()
    ans2 = sum(A2[:stop2-1])
    print(ans1 + ans2)

Fixed submission:
import collections
n = int(input())
v_ = list(map(int,input().split()))
setv = set(v_)
if len(setv) == 1:
    print(n//2)
else: 
    v1 = v_[::2]
    v2 = v_[1::2]
    v1com = collections.Counter(v1)
    v2com = collections.Counter(v2)
    v1com = v1com.most_common()
    v2com = v2com.most_common()
    if v1com[0][0] != v2com[0][0]:
        print(n-v1com[0][1]-v2com[0][1])
    else:
        print(n-v1com[0][1]-max(v1com[1][1],v2com[1][1]))
Buggy python submission (verdict: Runtime Error):
import math
n = int(input())
print(2 * n // math.gcd(2 , n))

Fixed submission:
n = int(input())
if n % 2 == 0:
	print(n)
else:
	print(2 * n)
Buggy python submission (verdict: Runtime Error):
a = list(map(int,input().split()))
wa = 0
for i in range(n):
	a[i] = a[i] - (i + 1)
	wa += a[i]
b = round(wa/n)
ans = 0
for i in range(n):
	ans += abs(a[i] - b)
print(ans)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
a2 = [a[x] - (x + 1) for x in range(n)]
a2.sort()
c = n // 2
b = a2[c]
ans = 0
for i in range(n):
	ans += abs(a2[i] - b)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = list(input())
ans = 10**7
for i in range(n):
	count = 0
	a = s[:i]
	b = s[i:]
	ac = a.count("W")
	bc = b.count("E")
	count = ac + bc
	if count <= ans:
		ans = count
print(ans)

Fixed submission:
n = int(input())
s = list(input())
counter = s.count("E")
ans = counter
for i in range(1,n+1):
	if s[i-1] == "W":
		counter += 1
	elif s[i-1] == "E":
		counter -= 1
	if ans >= counter:
		ans = counter
print(ans)
Buggy python submission (verdict: Runtime Error):
H,W = map(int,input().split())
s = [list(input()) for i in range(H)]
for i in range(H):
	for j in range(W):
		if s[i][j] == "#":
			if s[i-1][j] == "." and s[i+1][j] == "." and s[i][j-1] == "." and s[i][j+1] == ".":
			    print("No")
			    exit()
print("Yes") 

Fixed submission:
H,W = map(int,input().split())
s = [list(input()) for i in range(H)]
for i in range(H):
	for j in range(W):
		if s[i][j] == "#":
			if s[max(0,i-1)][j] == "." and s[min(H-1,i+1)][j] == "." and s[i][max(0,j-1)] == "." and s[i][min(W-1,j+1)] == ".":
			    print("No")
			    exit()
print("Yes")
Buggy python submission (verdict: Runtime Error):
n = int(input())
x = list(map(int,input().split()))
w = sorted(x)
l = int(n/2)
a = w[l - 1]
b = w[l]
for i in range(n):
	if x[i] <= a:
		print(b)
	else:
		print(a)


Fixed submission:
A,B,X = map(int,input().split())
if 0 <= X - A <= B:
	print('YES')
else:
	print('NO')