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

Fixed submission:
N,M=map(int,input().split())
x=[0 for i in range(M)]
y=[0 for i in range(M)]
for i in range(M):
    x[i],y[i]=map(int,input().split())
    x[i]-=1
    y[i]-=1
a=[0 for i in range(N)]
a[0]=1
b=[1 for i in range(N)]
for i in range(M):
    b[x[i]]-=1
    b[y[i]]+=1
    if a[x[i]]==1:
        a[y[i]]=1
    if b[x[i]]==0:
        a[x[i]]=0
print(sum(a))

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
x=[0 for i in range(M)]
y=[0 for i in range(M)]
for i in range(M):
    x[i],y[i]=map(int,input().split())
    x[i]-=1
    y[i]-=1
a=[0 for i in range(N)]
a[0]=N**N
c=[0 for i in range(N)]
c[0]=1
b=[1 for i in range(N)]
for i in range(M):
    b[x[i]]-=1
    b[y[i]]+=1
    t=a[x[i]]
    a[x[i]]-=t/(b[x[i]]+1)
    a[y[i]]+=t/(b[x[i]]+1)
    if b[x[i]]!=0:
        c[x[i]]=1
    else:
        c[x[i]]=0
    if t!=0:
        c[y[i]]=1
print(sum(c))

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
x=[0 for i in range(M)]
y=[0 for i in range(M)]
for i in range(M):
    x[i],y[i]=map(int,input().split())
    x[i]-=1
    y[i]-=1
a=[0 for i in range(N)]
a[0]=N**N
b=[1 for i in range(N)]
for i in range(M):
    b[x[i]]-=1
    b[y[i]]+=1
    t=a[x[i]]
    a[x[i]]-=t/(b[x[i]]+1)
    a[y[i]]+=t/(b[x[i]]+1)
n=0
for i in range(N):
    if a[i]!=0:
        n+=1
print(n)

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
x=[0 for i in range(M)]
y=[0 for i in range(M)]
for i in range(M):
    x[i],y[i]=map(int,input().split())
    x[i]-=1
    y[i]-=1
a=[0 for i in range(N)]
a[0]=N**N
c=[0 for i in range(N)]
c[0]=1
b=[1 for i in range(N)]
for i in range(M):
    b[x[i]]-=1
    b[y[i]]+=1
    t=a[x[i]]
    a[x[i]]-=t/(b[x[i]]+1)
    a[y[i]]+=t/(b[x[i]]+1)
print(sum(c))
Problem p04048 (python)

Fixed submission:
def gcd(a,b):
  if a%b==0:
    return b
  else:
    return gcd(b,a%b)
N,X=map(int,input().split())
print(3*(N-gcd(N,X)))

Buggy submission (verdict: Runtime Error):
def gcd(a,b):
  if a%b==0:
    return b
  else:
    return gcd(b,a%b)
N,X=map(int,input().split())
print(3*(N-gcd(N,X))

Buggy submission (verdict: Runtime Error):
def gcd(a,b):
  if a%b==0:
    return b
  else:
    return gcd(b,a%b):
N,X=map(int,input().split())
print(3*(N-gcd(N,X))
Problem p02700 (python)

Fixed submission:
a,b,c,d = map(int,input().split())

takahashi = c//b
if c%b!=0:
    takahashi += 1
    
aoki = a//d
if a%d!=0:
    aoki += 1

if takahashi <= aoki:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
a,b,c,d = map(int,input().split())
if c%b =< a%d:
    print("Yes")
else:
    print("No")
Problem p02983 (python)

Fixed submission:
l,r=map(int,input().split())

if r-l>=2019:
    print(0)
else:
    i_l=[]
    for i in range(l,r):
        for j in range(i+1,r+1):
            i_l.append((i%2019*j%2019)%2019)
    print(min(i_l))

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

if r-l>=2019:
    print(0)
else:
    i_l=[]
    for i in range(l,r):
        for j in (i+1,r+1):
        i_l.append((i%2019*j%2019)%2019)
    print(min(i_l))
Problem p02995 (python)

Fixed submission:
import fractions
a,b,c,d=map(int,input().split())

#b以下の自然数で、cでもdでも割り切れないものの個数から
#a-1以下の自然数で、cでもdでも割り切れないものの個数を引けばOK

#cとdの最小公倍数を求める
def lcm(x,y):
    return (x*y)//fractions.gcd(x,y)

#b以下の自然数で、cでもdでも割り切れないものの個数を求める
b_ika=b-(b//c+b//d-b//lcm(c,d))
a_mimann=a-1-((a-1)//c+(a-1)//d-(a-1)//lcm(c,d))

ans=b_ika-a_mimann

print(ans)

Buggy submission (verdict: Runtime Error):
import math

A, B, C, D = map(int, input().split())

def lcm(x, y):
    return (x * y) // math.gcd(x, y)


p = B-(int(B/C) + int(B/D) - int(B/lcm(C,D)))

q = A-1-(int((A-1)/C) + int((A-1)/D) - int((A-1)/lcm(C,D)))

print(p-q)

Buggy submission (verdict: Runtime Error):
import math

A, B, C, D = map(int, input().split())

def lcm(x, y):
    return (x * y) // math.gcd(x, y)


p = B-(int(B/C) + int(B/D) - int(B/lcm(C,D)))

q = A-1-(int((A-1)/C) + int((A-1)/D) - int((A-1)/lcm(C,D)))

print(p-q)
Problem p02999 (python)

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

Buggy submission (verdict: Runtime Error):
X, A = map(int, input().split())
if X < A:
    print(0)
else:
    print(10)

Buggy submission (verdict: Runtime Error):
X, A = map(int, input().split())
if X < A:
    print("0")
else:
    print("10")

Buggy submission (verdict: Runtime Error):
X, A = map(int, input().split())
if X < A:
    print("0")
else:
    print("1")
Problem p03000 (python)

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

lenL = 0

for i in range(len(L)):
    lenL += L[i]
    i += 1

if lenL <= X:
    print(N+1)
else:
    j = 1
    sumL = L[0]

    while sumL <= X:
        sumL += L[j]
        j += 1
    print(j)

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

j = 1
sumL = L[0]

while sumL <= X:
    sumL += L[j]
    j += 1

print(j)
Problem p03101 (python)

Fixed submission:
H, W = map(int, input().split())
h, w = map(int, input().split())

print(H*W-(h*W+H*w-h*w))

Buggy submission (verdict: Runtime Error):
n,m,c=map(int, input().split())
b=list(map(int, input().split()))
tmp=0
cnt=0
a_i=[]
for _ in range(n):
    a=list(map(int, input().split()))
    for i in range(m):
        tmp=0
        tmp+=int(a[i])*int(b[i])
    if tmp+c>0:
        cnt+=1
        
print(cnt)
Problem p03106 (python)

Fixed submission:
a,b,k=map(int, input().split())
l=[]
for i in range(1,101):
    if a%i==0 and b%i==0:
        l.append(i)
if k==len(l):
    print(l[0])
else:
    print(l[-k])

Buggy submission (verdict: Runtime Error):
a,b,k=map(int, input().split())
l=[]
for i in range(1,100):
    if a%i==0 and b%i==0:
        l.append(i)
if k==len(k):
    print(l[0])
else:
    print(l[-k])
Problem p03238 (python)

Fixed submission:
N = int(input())
if N == 1:
    print("Hello World")
else:
    A = int(input())
    B = int(input())
    print(A+B)

Buggy submission (verdict: Runtime Error):
N = int(input())
if N == 1:
    print("Hello World")
else:
    A,B = map(int, input().split())
    print(A+B)
Problem p03251 (python)

Fixed submission:
n,m,X,Y=map(int, input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
x.append(X)
y.append(Y)
if max(x)<min(y):
    print("No War")
else:
    print("War")

Buggy submission (verdict: Runtime Error):
n,m,X,Y=map(int, input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))

if max(x,X)<min(y,Y):
    print("No war")
else:
    print("War")
Problem p03289 (python)

Fixed submission:
import sys
s=input()
l=[]
for i in range(2,len(s)-1):
    l.append(s[i])
if l.count("C")!=1:
    print("WA")
    sys.exit()
else:
    k=s[1:s.index("C")]+s[s.index("C")+1:]

if s[0]=="A" and l.count("C")==1 and k==k.lower():
    print("AC")
else:
    print("WA")

Buggy submission (verdict: Runtime Error):
s=input()
l=[]
for i in range(2,len(s)-1):
    l.append(s[i])

k=s[1:s.index("C")]+s[s.index("C")+1:]

if s[0]=="A" and l.count("C")==1 and k==k.lower():
    print("AC")
else:
    print("WA")
Problem p03293 (python)

Fixed submission:
import sys
s = input()
t = input()
for i in range(len(t)):
    l = t[i:]+t[:i]
    if s==l:
        print("Yes")
        sys.exit()
print("No")

Buggy submission (verdict: Runtime Error):
s = input()
t = input()
k = t.index(s[0])
t = t[k:]+t[:k]
if s==t:
    print("Yes")
else:
    print("No")
Problem p03386 (python)

Fixed submission:
a,b,k=map(int,input().split())

ans=list(range(a,min(a+k,b)))+list(range(max(a,b-k+1),b+1))
ans=set(ans)
ans=list(ans)
ans.sort()
for i in range(len(ans)):
    print(ans[i])

Buggy submission (verdict: Runtime Error):
a,b,k=map(int,input().split())

s=set()
l=[]

for i in range(a,b+1):
    l.append(i)

for i in range(k):
    s.add(l[i])
    s.add(l[-i-1])
    
s_l=list(s)
s_l.sort()
for i in range(len(s_l)):
    print(s_l[i])

Buggy submission (verdict: Runtime Error):
a,b,k=map(int, input().split())

if k>=b:
    for i in range(a, b+1):
        print(i)

else:
    
    l1=[i for i in range(a,b+1)] 
    l2=[]
    for i in range(k):
        l2.append(l1[i])
    for i in range(b-a-k+1,b-a+1):
        l2.append(l1[i])

    l_set = list(set(l2))
    l_set.sort()
    for i in range(len(l_set)):
        print(l_set[i])

Buggy submission (verdict: Runtime Error):
a,b,k=map(int, input().split())

if k>b:
    for i in range(a, b+1):
        print(i)

else:
    l1=[i for i in range(a,b+1)] 
    l2=[]
    for i in range(k):
        l2.append(l1[i])
    for i in range(b-a-k+1,b-a+1):
        l2.append(l1[i])

    l_set = list(set(l2))
    l_set.sort()
    for i in range(len(l_set)):
        print(l_set[i])

Buggy submission (verdict: Runtime Error):
a,b,k=map(int, input().split())
if k>b:
    k=b-1

l1=[i for i in range(a,b+1)] 
l2=[]
for i in range(k):
    l2.append(l1[i])
for i in range(b-a-k+1,b-a+1):
    l2.append(l2[i])

l_set = list(set(l2))
l_set.sort()
for i in range(len(l_set)):
    print(l_set[i])

Buggy submission (verdict: Runtime Error):
a,b,k=map(int, input().split())
if k>b:
    k=b-1

l=[i for i in range(a,b+1)] 
set_l=set()
for i in range(k):
    set_l.add(l[i])
for i in range(b-a-k+1,b-a+1):
    set_l.add(l[i])

l_set = list(set_l)
l_set.sort()
for i in range(len(l_set)):
    print(l_set[i])
Problem p03423 (python)

Fixed submission:
N = int(input())
print(int(N/3))

Buggy submission (verdict: Runtime Error):
s = [input() for i in range(3)]
print(s[0][0], s[1][1], s[2][2], sep="")
Problem p03544 (python)

Fixed submission:
n=int(input())
a,b,c=2,1,3
if n==0:
    print(2)
elif n==1:
    print(1)
elif n==2:
    print(3)
else:
    for i in range(n-2):
        a,b,c=b,c,b+c
    print(c)

Buggy submission (verdict: Runtime Error):
def lucas(n):
    if n==0:
        return 2
    elif n==1:
        return 1
    else:
        return lucas(n-1)+lucas(n-2)
n= int(input())

l=((1+math.sqrt(5))/2)**n+((1-math.sqrt(5))/2)**n
print(int(l))
Problem p03574 (python)

Fixed submission:
h,w=map(int,input().split())
s=[input() for _ in range(h)]
 
for i in range(h):
    ans=""
    for j in range(w):
        if(s[i][j]=="#"):
            ans+="#"
        else:
            tmp=0
            for k in s[max(0, i-1):min(h, i+2)]:
                tmp+=k[max(0, j-1):min(w, j+2)].count("#")
                
            ans+=str(tmp)
    print(ans)

Buggy submission (verdict: Runtime Error):
h,w=map(int,input().split())
s=[input() for i in range(h)]

for i in range(h):
    for j in range(w):
        c=0
        for a in range(i-1,i+2):
            for b in range(j-1,j+2):
                c+=all((min(a,b)>=0,a<h,b<w))and s[a][b]=='#'
        if s[i][j]=='.':s[i][j]=c

for a in s:
    print(*a,sep='')
Problem p03680 (python)

Fixed submission:
import sys
n=int(input())
a=[int(input()) for _ in range(n)]
       
cnt=0
tmp=1

for i in range(n):
    cnt+=1
    tmp=a[tmp-1]
    if tmp==2:
        print(cnt)
        sys.exit()
print(-1)

Buggy submission (verdict: Runtime Error):
import sys
n=int(input())
a=[int(input()) for _ in range(n)]
       
cnt=0
tmp=1

for i in range(n):
    cnt+=1
    already.append(tmp)
    tmp=a[tmp-1]
    if tmp==2:
        print(cnt)
        sys.exit()
print(-1)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=[int(input()) for _ in range(n)]

for i in range(a):
    if a[i]==i+1:
        print(-1)
        
cnt=0
tmp=1
already=[]
while True:
    cnt+=1
    already.append(tmp)
    tmp=a[tmp-1]
    if tmp==2:
        print(cnt)
        break
    elif tmp in already:
        print(-1)
        break
Problem p03719 (python)

Fixed submission:
a, b, c  = map(int, input().split())

if a<=c and c<=b:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
a, b, c  = map(int, input().split())

if A<=c and c<=b:
    print("Yes")
else:
    print("No")
Problem p03844 (python)

Fixed submission:
a,op,b=input().split()
if op=="+":
    print(int(a)+int(b))
else:
    print(int(a)-int(b))

Buggy submission (verdict: Runtime Error):
a,b=map(str, input().split())
if a==b:
    print("H")
else:
    print("D")
Problem p03998 (python)

Fixed submission:
import sys
sa=list(str(input()))
sb=list(str(input()))
sc=list(str(input()))

tmp="a"

while True:
    if tmp=="a":
        if len(sa)==0:
            print("A")
            sys.exit()
        else:
            tmp=sa[0]
            sa.pop(0)
    elif tmp=="b":
        if len(sb)==0:
            print("B")
            sys.exit()
        else:
            tmp=sb[0]
            sb.pop(0)
    elif tmp=="c":      
        if len(sc)==0:
            print("C")
            sys.exit()
        else:
            tmp=sc[0]
            sc.pop(0)

Buggy submission (verdict: Runtime Error):
import sys
sa=list(str(input()))
sb=list(str(input()))
sc=list(str(input()))

tmp="a"

while True:
    if tmp=="a":
        if len(sa)==0:
            print("A")
            sys.exit()
        else:
            tmp=sa[0]
            sa=sa.lstrip(sa[0])
    elif tmp=="b":
        if len(sb)==0:
            print("B")
            sys.exit()
        else:
            tmp=sb[0]
            sb=sb.lstrip(sb[0])
    elif tmp=="c":      
        if len(sc)==0:
            print("C")
            sys.exit()
        else:
            tmp=sc[0]
            sc=sc.lstrip(sc[0])
Problem p02586 (python)

Fixed submission:
import sys
input = sys.stdin.readline

R,C,K = map(int,input().split())

dp = [[0]*4 for i in range(C+1)]
prev = [0]*(C+1)
tb = [[0]*(C+1) for i in range(R+1)]

for i in range(K):
    r,c,v = map(int,input().split())
    tb[r][c] = v

for i in range(1,R+1):
    for j in range(1,C+1):
        pmx = 0
        for k in range(4):
            mx = dp[j-1][k]
            if k > 0:
                mx = max(mx,dp[j-1][k-1]+tb[i][j])
            if k == 0:
                mx = max(mx,prev[j])
            elif k == 1:
                mx = max(mx,prev[j]+tb[i][j])
            dp[j][k] = mx
            pmx = max(pmx,mx)
        prev[j] = pmx

print(prev[C])

Buggy submission (verdict: Runtime Error):
import numpy as np
import sys
input = sys.stdin.readline

R,C,K = map(int,input().split())

tb = np.zeros((R+1,C+1),dtype=np.int32)
dp = np.zeros((C+1,4),dtype=np.int64)
prev = np.zeros(C+1,dtype=np.int64)

for i in range(K):
    r,c,v = map(int,input().split())
    tb[r][c] = v

for i in range(1,R+1):
    for j in range(1,C+1):
        for k in range(4):
            dp[j][k] = dp[j-1][k]
            if k > 0:
                dp[j][k] = max(dp[j][k],dp[j-1][k-1]+tb[i][j])
            if k == 0:
                dp[j][k] = max(dp[j][k],prev[j])
            elif k == 1:
                dp[j][k] = max(dp[j][k],prev[j]+tb[i][j])
    prev = np.max(dp,axis=1)

print(prev[C])
Problem p02536 (python)

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

class DisjointSetUnion():
    def __init__(self, n):
        self.n = n
        self.par_size = [-1] * n

    def merge(self, a, b):
        #assert 0 <= a < self.n
        #assert 0 <= b < self.n
        x = self.leader(a)
        y = self.leader(b)
        if x == y: return x
        if -self.par_size[x] < -self.par_size[y]: x, y = y, x
        self.par_size[x] += self.par_size[y]
        self.par_size[y] = x
        return x

    def same(self, a, b):
        #assert 0 <= a < self.n
        #assert 0 <= b < self.n
        return self.leader(a) == self.leader(b)

    def leader(self, a):
        #assert 0 <= a < self.n
        x = a
        while self.par_size[x] >= 0:
            x = self.par_size[x]
        while self.par_size[a] >= 0:
            self.par_size[a] = x
            a = self.par_size[a]
        return x

    def size(self, a):
        #assert 0 <= a < self.n
        return -self.par_size[self.leader(a)]

    def groups(self):
        leader_buf = [0] * self.n
        group_size = [0] * self.n
        res = [[] for _ in range(self.n)]
        for i in range(self.n):
            leader_buf[i] = self.leader(i)
            group_size[leader_buf[i]] += 1
        for i in range(self.n):
            res[leader_buf[i]].append(i)
        res = [res[i] for i in range(self.n) if res[i]]
        return res

uf = DisjointSetUnion(N)

for _ in range(M):
    a, b = map(int, input().split())
    uf.merge(a - 1, b - 1)

l = len(uf.groups())
print(l - 1)

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

class DisjointSetUnion():
    def __init__(self, n):
        self.n = n
        self.par_size = [-1] * n

    def merge(self, a, b):
        #assert 0 <= a < self.n
        #assert 0 <= b < self.n
        x = self.leader(a)
        y = self.leader(b)
        if x == y: return x
        if -self.par_size[x] < -self.par_size[y]: x, y = y, x
        self.par_size[x] += self.par_size[y]
        self.par_size[y] = x
        return x

    def same(self, a, b):
        #assert 0 <= a < self.n
        #assert 0 <= b < self.n
        return self.leader(a) == self.leader(b)

    def leader(self, a):
        #assert 0 <= a < self.n
        x = a
        while self.par_size[x] >= 0:
            x = self.par_size[x]
        while self.par_size[a] >= 0:
            self.par_size[a] = x
            a = self.par_size[a]
        return x

    def size(self, a):
        #assert 0 <= a < self.n
        return -self.par_size[self.leader(a)]

    def groups(self):
        leader_buf = [0] * self.n
        group_size = [0] * self.n
        res = [[] for _ in range(self.n)]
        for i in range(self.n):
            leader_buf[i] = self.leader(i)
            group_size[leader_buf[i]] += 1
        for i in range(self.n):
            res[leader_buf[i]].append(i)
        res = [res[i] for i in range(self.n) if res[i]]
        return res

uf = DisjointSetUnion(N)

for _ in range(M):
    a, b = map(int, input().split())
    uf.merge(a, b)

l = len(uf.groups())
print(l - 1)
Problem p02599 (python)

Fixed submission:
import sys
input = sys.stdin.buffer.readline

N, Q = map(int, input().split())
C = list(map(lambda x: int(x) - 1, input().split()))

query = []

for i in range(Q):
    l, r, = map(int, input().split())
    query.append((l - 1, r, i))

query.sort(key = lambda x: x[1])

rt = 0
L = [None for _ in range(N)]
res = [0 for _ in range(Q)]
bit = [0 for _ in range(N + 1)]

for l, r, id in query:
    while rt < r:
        if L[C[rt]] is not None:
            idx = L[C[rt]] + 1
            while idx <= N:
                bit[idx] -= 1
                idx += idx & -idx
        L[C[rt]] = rt
        idx = rt + 1
        while idx <= N:
            bit[idx] += 1
            idx += idx & -idx
        rt += 1
    sr = 0
    sl = 0
    idx = r
    while idx:
        sr += bit[idx]
        idx -= idx & -idx
    idx = l
    while idx:
        sl += bit[idx]
        idx -= idx & -idx
    res[id] = sr - sl

print('\n'.join(map(str, res)))

Buggy submission (verdict: Runtime Error):
class BinaryIndexedTree():  #1-indexed
    def __init__(self, n):
        self.n = n
        self.tree = [0 for _ in range(n + 1)]

    def sum(self, idx):
        res = 0
        while idx:
            res += self.tree[idx]
            idx -= idx & -idx
        return res

    def add(self, idx, x):
        while idx <= self.n:
            self.tree[idx] += x
            idx += idx & -idx

    def bisect_left(self, x):
        if x <= 0: return 0
        res, tmp = 0, 2**((self.n).bit_length() - 1)
        while tmp:
            if res + tmp <= self.n and self.tree[res + tmp] < x:
                x -= self.tree[res + tmp]
                res += tmp
            tmp >>= 1
        return res + 1

import sys
input = sys.stdin.buffer.readline

N, Q = map(int, input().split())
C = list(map(int, input().split()))

query = []

for i in range(Q):
    l, r, = map(int, input().split())
    query.append((l - 1, r, i))

query.sort(key = lambda x: x[1])

lt, rt = 0, 0
L = [None for _ in range(N)]
res = [0 for _ in range(Q)]
bit = BinaryIndexedTree(N)

for l, r, idx in query:
    while rt < r:
        if L[C[rt]] is not None:
            bit.add(L[C[rt]] + 1, -1)
        L[C[rt]] = rt
        bit.add(rt + 1, 1)
        rt += 1
    res[idx] = bit.sum(r) - bit.sum(l)

print('\n'.join(map(str, res)))
Problem p02618 (python)

Fixed submission:
D = int(input())
C = list(map(int, input().split()))
S = [list(map(int, input().split())) for _ in range(D)]

res = 0
last = [0 for _ in range(26)]

for d in range(D):
    maxtmp = -10**18
    contest = None
    for i in range(26):
        tmp = res
        lasttmp = last[:]
        tmp += S[d][i]
        lasttmp[i] = d + 1
        for j in range(26):
            tmp -= C[j] * ((d + 1) - lasttmp[j])
        if maxtmp <= tmp:
            maxtmp = tmp
            contest = i
    res += S[d][contest]
    last[contest] = d + 1
    for j in range(26):
        res -= C[j] * ((d + 1) - last[j])
    print(contest + 1)

Buggy submission (verdict: Runtime Error):
D = int(input())
C = list(map(int, input().split()))
S = [list(map(int, input().split())) for _ in range(D)]

res = 0
last = [0 for _ in range(26)]

for d in range(D):
    maxtmp = 0
    contest = None
    for i in range(26):
        tmp = res
        lasttmp = last[:]
        tmp += S[d][i]
        lasttmp[i] = d + 1
        for j in range(26):
            tmp -= C[j] * ((d + 1) - lasttmp[j])
        if maxtmp <= tmp:
            maxtmp = tmp
            contest = i
    res += S[d][contest]
    last[contest] = d + 1
    for j in range(26):
        res -= C[j] * ((d + 1) - last[j])
    print(contest + 1)
Problem p02814 (python)

Fixed submission:
from functools import reduce

def gcd(x,y):
    while y: x,y = y,x%y
    return x

def lcm(x,y):
    return x//gcd(x,y)*y

def ex_euclid(x,y):
    c0,c1 = x,y
    a0,a1 = 1,0
    b0,b1 = 0,1
    while c1:
        a0,a1 = a1,a0-c0//c1*a1
        b0,b1 = b1,b0-c0//c1*b1
        c0,c1 = c1,c0%c1
    return c0,a0,b0

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

if N == 1:
    a = A[0]
    print((M-a//2%a)//a+1)

else:
    LCM = reduce(lcm,A)

    SCMs = []
    flag = True

    for i in range(N-1):
        c,a,b = ex_euclid(A[i],-A[i+1])
        if (A[i+1]-A[i])//2%c == 0:
            SCMs.append(A[i]*((A[i+1]-A[i])//2//c)*a+A[i]//2)
        else:
            flag = False
            break

    print((M-reduce(lcm,SCMs)%LCM)//LCM+1 if flag else 0)

Buggy submission (verdict: Runtime Error):
from functools import reduce

def gcd(x,y):
    while y: x,y = y,x%y
    return x

def lcm(x,y):
    return x//gcd(x,y)*y

def ex_euclid(x,y):
    c0,c1 = x,y
    a0,a1 = 1,0
    b0,b1 = 0,1
    while c1:
        a0,a1 = a1,a0-c0//c1*a1
        b0,b1 = b1,b0-c0//c1*b1
        c0,c1 = c1,c0%c1
    return c0,a0,b0

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

LCM = reduce(lcm,A)

SCMs = []
flag = True

for i in range(N-1):
    c,a,b = ex_euclid(A[i],-A[i+1])
    if (A[i+1]-A[i])//2%c == 0:
        SCMs.append(A[i]*((A[i+1]-A[i])//2//c)*a+A[i]//2)
    else:
        flag = False
        break
        
print((M-reduce(lcm,SCMs)%LCM)//LCM+1 if flag else 0)