Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03672 (python)

Fixed submission:
s=list(str(input())
        )
for i in range(1,len(s)//2):
    s=s[:-2]
    if s[:len(s)//2]==s[len(s)//2:]:
        break
print(len(s))

Buggy submission (verdict: Runtime Error):
s=int(input())

for n in range(1,len(s)-1):
    s=s[:-2]
    if s[:len(s)//2]==s[len(s)//2:]:
        break
print(len(s))

Buggy submission (verdict: Runtime Error):
s=list(input())
x=len(s)

for i range(1,x//2):
    s=s[:-2]
    if s[:len(s)//2==s[len(s)//2:]:
            break
print(len(s))

Buggy submission (verdict: Runtime Error):
s=list(input())
x=len(s)

for i i range(1,x//2):
    s=s[:-2]
    if s[:len(s)//2==s[len(s)//2:]:
            break
print(len(s))
Problem p03720 (python)

Fixed submission:
n,m=map(int,input().split())
x=[]

for i in range(m):
    a,b=map(int,input().split())
    x.append(a)
    x.append(b)


for j in range(1,n+1):
    print(x.count(j))

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
l=[]
for i in range(m):
    a,b=map(int,input().split())
    l.append(a)
    l.append(b)

z=list(set(l))
for i in range(1,n+1):
    print(l.count(z[i]))
Problem p03721 (python)

Fixed submission:
n,k = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
a.sort()
now = 0
for i in a:
  now += i[1]
  if now >= k:
    print(i[0])
    break

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=[list(map(int,input().split()) for _ in range(n)]
a.sort

new=0

for i in a:
    now+=i[1]
    if now>=k:
        print(i[0])
        break
Problem p03759 (python)

Fixed submission:
#coding utf-8 -*-

lis=list(map(int,input().split()))
lis_1=sorted(lis)

if lis_1[2] - lis_1[1] == lis_1[1] - lis_1[0]:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
# -*- coding utf-8 -*-
o=list(str(input()))
e=list(str(input()))
ans=[]

for i in range(len(o)):
    ans+=o[i:i+1]
    ans+=e[i:i+1]

print(''.join(ans))
Problem p03836 (python)

Fixed submission:
sx,sy,tx,ty=map(int,input().split())
x=tx-sx
y=ty-sy
ans=""

ans="U"*y + "R"*x
ans+="D"*y + "L"*x

ans+="L"+"U"*(y+1)+"R"*(x+1)+"D"
ans+="R"+"D"*(y+1)+"L"*(x+1)+"U"
print(ans)

Buggy submission (verdict: Runtime Error):
sx,sy,tx,ty=map(int,input().split())
a=tx-sx
b=ty-sy
ans=""

ans="U"*b+"R"*a
ans+="D"*b+"L"*a

ans+="D"+"R"(a+1)+"U"*(b+1)+"L"
ans+="U"+"L"(a+1)+"D"(b+1)+"R"

print(ans)
Problem p03860 (python)

Fixed submission:
# -*- coding utf-8 -*-

x,y,z =list(map(str,input().split()))

print(x[0].upper() + y[0].upper() + z[0].upper())

Buggy submission (verdict: Runtime Error):
a,b,x=map(int,input().split())
ans=0
for i in range(a,b+1):
    if i%x == 0:
        ans+=1
    else:
        ans=ans
print(ans)

Buggy submission (verdict: Runtime Error):
# -*- coding utf-8 -*-

a,b,x=map(int,input().split())
ans=0

for i in range(a,b+1):
    if i%x==0:
        ans+=1
    else:
        ans=ans
print(ans)

Buggy submission (verdict: Runtime Error):
# -*- coding utf-8 -*-

a,b,x=map(int,input().split())
ans=0

for i in range(a,b+1):
    if i%x==0:
        ans+=1
    else:
        ans+=0
print(ans)

Buggy submission (verdict: Runtime Error):
# -*- coding utf-8 -*-

a,b,x=map(int,input().split())
ans=0

for i in range(a,b+1):
    if i%x==0:
        ans+=1
    else:
        pass
print(ans)

Buggy submission (verdict: Runtime Error):
# -*- coding utf-8 -*-

a,b,x=map(int,input().split())
ans=0

for i in range(a,b+1):
    if i%x==0:
        ans+=1
    else:
        pass
print(ans)
Problem p03997 (python)

Fixed submission:
# -*- coding utf-8 -*-

a = int(input())
b = int(input())
h = int(input())

x = (a+b)*h/2

print(round(x))

Buggy submission (verdict: Runtime Error):
# -*- coding utf-8 -*-

n = int(input())
k = int(input())
x = int(input())
y = int(input())

if n <= k :
    print(n*x)
elif k < n :
    ans = (k*x) + (y*(n-k))
    print(ans)
Problem p04043 (python)

Fixed submission:
# -*- coding utf-8 -*-

x = list(map(int,input().split()))

x.sort() 
if x == [5,5,7]:
    print ("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
# -*- coding utf-8 -*-

n,l=map(int,input().split())

s =[str(input()) for i in range(n)]

s.sort()

print(*s,sep="")
Problem p02947 (python)

Fixed submission:
import math
import sys
import itertools
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

"""
# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]

# 標準入力取得
## 文字列
    = sys.stdin.readline().rstrip()
    = list(sys.stdin.readline().rstrip())

## 数値
    = int(sys.stdin.readline())
    = map(int, sys.stdin.readline().split())
    = list(map(int, sys.stdin.readline().split()))
    = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき
"""

if __name__ == "__main__":
    n = int(sys.stdin.readline())
    s = list(sys.stdin.readlines())
    new_s=sorted(s)
    char_list=[]
    dic ={}
    for i in s:
        i = i.replace('\n','')
        new_s=sorted(i)
        new_s = ''.join(new_s)
        char_list.append(new_s)
        if new_s not in dic:
            dic[new_s] = 1
        else:
            dic[new_s] += 1
    # c = 0
    # for j in range(n):
    #     if char_list[j] in char_list[j+1:]:
    #         c+=char_list[j+1:].count(char_list[j])
    # print(c)

    def combinations_count(n, r):
        if n - r < 0:
            return 0
        else:
            return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

    # print(char_list)
    # print(dic)
    c=0
    # print(dic.values())
    for i in dic.values():
        c+=combinations_count(i, 2)
    print(c)

Buggy submission (verdict: Runtime Error):
import math
import sys
import itertools
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

"""
# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]

# 標準入力取得
## 文字列
    = sys.stdin.readline().rstrip()
    = list(sys.stdin.readline().rstrip())

## 数値
    = int(sys.stdin.readline())
    = map(int, sys.stdin.readline().split())
    = list(map(int, sys.stdin.readline().split()))
    = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき
"""

if __name__ == "__main__":
    n = int(sys.stdin.readline())
    s = list(sys.stdin.readlines())
    new_s=sorted(s)
    char_list=[]
    dic ={}
    for i in s:
        i = i.replace('\n','')
        new_s=sorted(i)
        new_s = ''.join(new_s)
        char_list.append(new_s)
        if new_s not in dic:
            dic[new_s] = 1
        else:
            dic[new_s] += 1
    # c = 0
    # for j in range(n):
    #     if char_list[j] in char_list[j+1:]:
    #         c+=char_list[j+1:].count(char_list[j])
    # print(c)

    def combinations_count(n, r):
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

    # print(char_list)
    # print(dic)
    c=0
    # print(dic.values())
    for i in dic.values():
        c+=combinations_count(i, 2)
    print(c)
Problem p03000 (python)

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

D=0
i=0
c=0
while D <= X:
    try:
        c+=1
        # if i>len(l):
        #     break
        D+=l[i]
        i+=1
    except IndexError:
        break

print(c)

Buggy submission (verdict: Runtime Error):
N, X = list(map(int, input().split()))
l = list(map(int, input().split()))

D=0
i=0
c=0
while D <= X:
    c+=1
    D+=l[i]
    i+=1
    if i>len(l):
        break

print(c)

Buggy submission (verdict: Runtime Error):
N, X = list(map(int, input().split()))
l = list(map(int, input().split()))

D=0
i=0
c=0
while D <= X:
    c+=1
    D+=l[i]
    i+=1


print(c)

Buggy submission (verdict: Runtime Error):
N, X = list(map(int, input().split()))
l = list(map(int, input().split()))

D=0
i=0
c=0
while D <= X:
    D+=l[i]
    i+=1
    c+=1

print(c)
Problem p03086 (python)

Fixed submission:
"""
# 標準入力取得
## 文字列
 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())

## 数値
 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

if __name__ == "__main__":
    S= list(sys.stdin.readline().rstrip())
    N = len(S)

    ans=0
    for i in range(N):
        for j in range(i,N):
            if all("ACGT".count(c) == 1 for c in S[i:j+1]): #all()は中身がすべてTrueならTrueを返す。S部分文字列から１個ずつ取り出して"ACGT".count(c) == 1で判定
                ans = max(ans, j-i+1)
            # print(all("ACGT".count(c) == 1 for c in S[i:j+1]))

    print(ans)

Buggy submission (verdict: Runtime Error):
"""
# 標準入力取得
## 文字列
 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())

## 数値
 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

if __name__ == "__main__":
    S= list(sys.stdin.readline().rstrip())
    l = ["A","C","G","T"]

    c=0
    c_l=[]
    for e in S:
        if e in l:
            c+=1
        else:
            c_l.append(c)
            c=0

    print(max(c_l))
Problem p03262 (python)

Fixed submission:
from functools import reduce
from fractions import gcd
N,X=map(int,input().split())
x=[abs(X-int(i)) for i in input().split()]
print(reduce(gcd,x))

Buggy submission (verdict: Runtime Error):
"""
# 標準入力取得
## 文字列
 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())

## 数値
 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd

import functools
from functools import reduce


def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

if __name__ == "__main__":
    N,X = map(int, sys.stdin.readline().split())
    x = list(map(int, sys.stdin.readline().split()))
    l=[]
    for i in range(N):
        l.append(abs(X-x[i]))
    ans = functools.reduce(math.gcd,l)
    print(ans)

Buggy submission (verdict: Runtime Error):
"""
# 標準入力取得
## 文字列
 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())

## 数値
 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd

import functools

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

if __name__ == "__main__":
    N,X = map(int, sys.stdin.readline().split())
    x = list(map(int, sys.stdin.readline().split()))
    l=[]
    for i in range(N):
        l.append(abs(X-x[i]))
    ans = functools.reduce(math.gcd,l)
    print(ans)
Problem p02991 (python)

Fixed submission:
from heapq import *
f_inf = float('inf')

def dijkstra(start,node,edge):
    #始点sから各頂点への最短距離
    #node:頂点数
    #d:各頂点へのコスト(存在しないときはinf)
    #q:キュー(スタートからのコスト,頂点)
    d = [[f_inf, f_inf, f_inf] for _ in [0]*node]
    d[start][0] = 0
    #スタートをキューに入れる
    q = [(0,start)]

    while(len(q) != 0):
    #キューの先頭を取得
      ci,i = heappop(q)
    #キューの先頭から繋がっている頂点を探索
      for j in edge[i]:
        nc = ci + 1
        if (d[j][nc%3] > nc):
          d[j][nc%3] = nc
          heappush(q,(nc, j))
    return d
#入力
N,M = (int(x) for x in input().split())
#エッジ
E = [[] for _ in [0]*N]

for i in range(M):
  a,b = (int(x) for x in input().split())
  E[a-1].append(b-1)

S,T = (int(x)-1 for x in input().split())
d = dijkstra(S, N, E)
ans = d[T][0]

if ans == f_inf:
  print(-1)
else:
  print(ans//3)

Buggy submission (verdict: Runtime Error):
from heapq import *
f_inf = float('inf')

def dijkstra(start,node,edge):
    #始点sから各頂点への最短距離
    #node:頂点数
    #d:各頂点へのコスト(存在しないときはinf)
    #q:キュー(スタートからのコスト,頂点)
    d = [[f_inf, f_inf, f_inf] for _ in [0]*node]
    d[start][0] = 0
    #スタートをキューに入れる
    q = [(0,start)]

    while(len(q) != 0):
    #キューの先頭を取得
      ci,i = heappop(q)
    #キューの先頭から繋がっている頂点を探索
      for j in edge[i]:
        nc = ci + 1
        if (d[j][nc%3] > nc):
          d[j][nc%3] = nc
          heappush(q,(nc, j))
    return d
#入力
N,M = (int(x) for x in input().split())
#二種類のエッジ
E = [[] for _ in [0]*N]

for i in range(M):
  a,b = (int(x) for x in input().split())
  E[a-1].append(b-1)

S,T = (int(x) for x in input().split())
d = dijkstra(S, N, E)
ans = d[T][0]

if ans == f_inf:
  print(-1)
else:
  print(ans//3)
Problem p02993 (python)

Fixed submission:
S = int(input())
lst = []
while S > 0:
    lst.append(S%10)
    S //= 10 # 必須
while(len(lst) <= 4):
  lst.append(0)
  
if lst[0] == lst[1] or lst[1] == lst[2] or lst[2] == lst[3]:
  print("Bad")
else:
  print("Good")

Buggy submission (verdict: Runtime Error):
S = int(input())
lst = []
while S > 0:
    lst.append(S%10)
    S //= 10 # 必須
if lst[0] == lst[1] or lst[1] == lst[2] or lst[2] == lst[3]:
  print("Bad")
else:
  print("Good")
Problem p02999 (python)

Fixed submission:
X,A = (int(x) for x in input().split())
 
if X < A:
  print(0)
else:
  print(10)

Buggy submission (verdict: Runtime Error):
X,A = (int(x) for x in input().split())

if x < A:
  print(0)
else:
  print(10)
Problem p03000 (python)

Fixed submission:
X,A = (int(x) for x in input().split())
L = list(map(int,input().split()))
cnt = 0
ans = 0
for i in range(X):
    ans += L[cnt]
    if(ans <= A):
        cnt += 1

print(cnt + 1)

Buggy submission (verdict: Runtime Error):
X,A = (int(x) for x in input().split())
if X == 1:
  L = int(input())
  if L <= A:
    print(2)
  
else:
  L = list(map(int,input().split()))
  cnt = 0
  idx = 0
  ans = 0

  while(ans <= A):
    ans += L[idx]
    idx += 1
    cnt += 1

  print(cnt)

Buggy submission (verdict: Runtime Error):
X,A = (int(x) for x in input().split())
L = list(map(int,input().split()))
cnt = 0
idx = 0
ans = 0
while(ans <= A):
  ans += L[idx]
  idx += 1
  cnt += 1
  
print(cnt)
Problem p03006 (python)

Fixed submission:
import collections
N = int(input())
if N == 1:
  print(1)
elif N == 2:
  print(1)
else:
  ball = [tuple(map(int, input().split())) for _ in range(N)]
  ball.sort(key=lambda x:(x[0], x[1]))
  diff = [tuple((ball[i][0] - ball[j][0], ball[i][1] - ball[j][1])) for i in range(N) for j in range(i + 1, N)]
  c = collections.Counter(diff)
  ans = c.most_common()[0][1]
  print(N - ans)

Buggy submission (verdict: Runtime Error):
import collections
N = int(input())
if N == 1:
  print(1)
elif N == 2:
  print(1)
else:
  ball = [tuple(map(int, input().split())) for _ in range(N)]
  ball = ball.sorted()
  diff = [tuple((ball[i][0] - ball[j][0], ball[i][1] - ball[j][1])) for i in range(N) for j in range(i + 1, N)]
  c = collections.Counter(diff)
  ans = c.most_common()[0][1]
  print(N - ans)

Buggy submission (verdict: Runtime Error):
import collections
N = int(input())
if N == 1:
  print(1)
else if  N == 2:
  print(1)
else:
  ball = [tuple(map(int, input().split())) for _ in range(N)]
  ball.sort(key=lambda x:(x[0], x[1]))
  diff = [tuple((ball[i][0] - ball[i-1][0], ball[i][1] - ball[i-1][1])) for i in range(1,N)]
  c = collections.Counter(diff)
  ans = c.most_common()[0][1]
  print(N - ans)

Buggy submission (verdict: Runtime Error):
import collections
N = int(input())
ball = [tuple(map(int, input().split())) for _ in range(N)]
ball.sort(key=lambda x:(x[0], x[1]))
diff = [tuple((ball[i][0] - ball[i-1][0], ball[i][1] - ball[i-1][1])) for i in range(1,N)]
c = collections.Counter(diff)
ans = c.most_common()[0][1]
print(N - ans)
Problem p03044 (python)

Fixed submission:
import numpy as np
import sys
INF = float('inf')
sys.setrecursionlimit(10**5)
max = 10**5+5

def dk(start,node,edge):
  ans = [INF] * node
  ans[0] = 0
  q = [start]
  
  while(len(q) != 0):
    i = q.pop()
    for j, cost in edge[i]:
      if(ans[j] != INF):
        continue
      ans[j] = (ans[i] + cost)%2
      q.append(j)
  return ans

#入力
N = int(input())
#エッジ
E = [[] for _ in [0]*(max)]

for i in range(N-1):
  a,b,w = (int(x) for x in input().split())
  E[a-1].append((b-1, w))
  E[b-1].append((a-1, w))


ans = dk(0, N, E)

#出力
print(*ans, sep = "\n")

Buggy submission (verdict: Runtime Error):
from heapq import *
import numpy as np

def dk(start,node,edge):
  d = [0] * node
  d[start] = 0
  q = [(0, start)]
  
  while(len(q) != 0):
    ci, i = heappop(q)
    for j in edge[i]:
      nc = ci + cost[i][j]
      d[j] = int(nc%2)
      heappush(q,(nc, j))
  return d

#入力
N = int(input())
#エッジ
E = [[] for _ in [0]*(N)]
cost = np.zeros((N, N))

for i in range(N-1):
  a,b,w = (int(x) for x in input().split())
  E[a-1].append(b-1)
  cost[a-1][b-1] = w
  cost[b-1][a-1] = w


d = dk(0, N, E)

#出力
print(*d, sep = "\n")

Buggy submission (verdict: Runtime Error):
from heapq import *
import numpy as np
import sys
sys.setrecursionlimit(200000)

def dk(start,node,edge):
  d = [0]*node
  d[start] = 0
  q = [(0, start)]
  
  while(len(q) != 0):
    ci, i = heappop(q)
    for j in edge[i]:
      nc = ci + cost[i][j]
      if nc%2 == 1:
        d[j] = 1
      heappush(q,(nc, j))
  return d

#入力
N = int(input())
#エッジ
E = [[] for _ in [0]*(N+1000)]
cost = np.zeros((N+1000, N+1000))

for i in range(N-1):
  a,b,w = (int(x) for x in input().split())
  E[a-1].append(b-1)
  cost[a-1][b-1] = w
  cost[b-1][a-1] = w


d = dk(0, N, E)

#出力
print(*d, sep = "\n")

Buggy submission (verdict: Runtime Error):
from heapq import *
import numpy as np

def dk(start,node,edge):
  d = [0]*node
  d[start] = 0
  q = [(0, start)]
  
  while(len(q) != 0):
    ci, i = heappop(q)
    for j in edge[i]:
      nc = ci + cost[i][j]
      if nc%2 == 1:
        d[j] = 1
      heappush(q,(nc, j))
  return d

#入力
N = int(input())
#エッジ
E = [[] for _ in [0]*N]
cost = np.zeros((N, N))

for i in range(N-1):
  a,b,w = (int(x) for x in input().split())
  E[a-1].append(b-1)
  cost[a-1][b-1] = w
  cost[b-1][a-1] = w


d = dk(0, N, E)

#出力
print(*d, sep = "\n")
Problem p03062 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
Amin = 10**9
ans = 0
counter = 0
for i in range(N):
  if(A[i] < 0):
    counter = counter + 1
  a = abs(A[i])
  ans += a
  Amin = min(a, Amin)
    
if(counter%2 == 1):
    ans -= 2*Amin
  
print(ans)

Buggy submission (verdict: Runtime Error):
import fractions
N = int(input())
A = list(map(int, input().split()))
A.sort()

ans = 0
counter = 0
for i in range(N):
  ans += abs(A[i])
  if(A[i] < 0):
    counter = counter + 1
    
if(counter%2 == 1):
  if(abs(A[counter - 1]) >= A[counter]):
    ans -= A[counter]*2
  else:
    ans -= A[counter-1]*2
  
print(ans)
Problem p03074 (python)

Fixed submission:
n, k = map(int, input().split())
s = input()
arr = []

if(s[0] == '0'):
  arr.append(0)
for i in range(n-1):
  if(s[i] != s[i+1]):
    arr.append(i+1)
arr.append(n)
if(s[-1] == '0'):
  arr.append(n)
    
width = 2*k + 1
len_arr = len(arr)

if(2*k >= len_arr):
  ans = arr[-1]
else:
  ans = arr[2*k]
  left = 2
  while True:
    if(left + width > len_arr):
      break
    tmp = arr[left + width - 1] - arr[left - 1]
    ans = max(ans, tmp)
    left += 2
print(ans)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
s = input()
arr = []

if(s[0] == '0'):
  arr.append(0)
for i in range(n-1):
  if(s[i] != s[i+1]):
    arr.append(i+1)
arr.append(n)
if(s[-1] == '0'):
  arr.append(n)
    
width = 2*k + 1
len_arr = len(arr)

ans = arr[2*k]
left = 2
while True:
  if(left + width > len_arr):
    break
  tmp = arr[left + width - 1] - arr[left - 1]
  ans = max(ans, tmp)
  left += 2

print(ans)
Problem p03160 (python)

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

def solve():
  dp = [0]*N
  dp[1] = abs(A[1] - A[0])
  for i in range(2,N):
    dp[i] = min((dp[i-1] + abs(A[i] - A[i-1])), (dp[i-2] + abs(A[i] - A[i-2])))
  return dp

dp = solve()
print(dp[N-1])

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
dp = [-1]*(N+100010)
dp[0] = 0
dp[1] = abs(A[1] - A[0])


def rec(i):
  if dp[i] != -1:
    return dp[i]
  dp[i] = min(rec(i-1) + abs(A[i-1] - A[i]), rec(i-2) + abs(A[i-2] - A[i]))
  return dp[i]

print(rec(N-1))

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
dp = [-1]*(N+2)
dp[0] = 0
dp[1] = abs(A[1] - A[0])


def rec(i):
  if dp[i] != -1:
    return dp[i]
  dp[i] = min(rec(i-1) + abs(A[i-1] - A[i]), rec(i-2) + abs(A[i-2] - A[i]))
  return dp[i]

print(rec(N-1))

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
dp = [-1]*N
dp[0] = 0
dp[1] = abs(A[1] - A[0])


def rec(i):
  if dp[i] != -1:
    return dp[i]
  dp[i] = min(rec(i-1) + abs(A[i-1] - A[i]), rec(i-2) + abs(A[i-2] - A[i]))
  return dp[i]

print(rec(N-1))
Problem p03354 (python)

Fixed submission:
n, m = map(int, input().split())
p = list(map(int, input().split()))
xy = [list(map(int, input().split())) for _ in range(m)]

class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]

    def root(self, i):
        if(self.par[i] == i):
          return i
        else:
          self.par[i] = self.root(self.par[i])
          return self.par[i]

    def union(self, x, y):
        x = self.root(x)
        y = self.root(y)
        self.par[x] = y

    def same(self, x, y):
        return self.root(x) == self.root(y)

uf = UnionFind(n)
for x, y in xy:
    uf.union(x-1, y-1)
ans = 0
for i in range(n):
    if uf.same(i, p[i]-1):
        ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
p = list(map(int, input().split()))
xy = [list(map(int, input().split())) for _ in range(m)]

class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]

    def root(self, i):
        if(self.par[i] == i):
          return i
        else:
          self.par[x] = self.find(self.par[x])
          return self.par[i]

    def union(self, x, y):
        x = self.root(x)
        y = self.root(y)
        self.par[x] = y

    def same(self, x, y):
        return self.root(x) == self.root(y)

uf = UnionFind(n)
for x, y in xy:
    uf.union(x-1, y-1)
ans = 0
for i in range(n):
    if uf.same(i, p[i]-1):
        ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
p = list(map(int, input().split()))
xy = [list(map(int, input().split())) for _ in range(m)]

class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]

    def root(self, i):
        if(self.par[i] == i):
          return i
        else:
          return self.root(self.par[i])

    def union(self, x, y):
        x = self.root(x)
        y = self.root(y)
        self.par[x] = y

    def same(self, x, y):
        return self.root(x) == self.root(y)

uf = UnionFind(n)
for x, y in xy:
    uf.union(x-1, y-1)
ans = 0
for i in range(n):
    if uf.same(i, p[i]-1):
        ans += 1

print(ans)