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

Fixed submission:
a=input()
if a=="SSS":
  print(0)
elif a=="RRR":
  print(3)
elif a=="RRS" or a=="SRR":
  print(2)
else:
  print(1)

Buggy submission (verdict: Runtime Error):
a=input()
if a=="SSS":
  print(0)
elif a="RRR":
  print(3)
elif a="RRS" or a="SRR":
  print(2)
else:
  print(1)

Buggy submission (verdict: Runtime Error):
a=input()
if a==SSS:
  print(0)
elif a=RRR:
  print(3)
elif a=RRS or a=SRR:
  print(2)
else:
  print(1)
Problem p02612 (python)

Fixed submission:
a=int(input())%1000
if a==0:
  print(a)
else:
  print(1000-a)

Buggy submission (verdict: Runtime Error):
a=int(input())%1000
if a=0:
  print(a)
else:
  print(1000-a)
Problem p02640 (python)

Fixed submission:
from fractions import Fraction

a=input()
a=a.split()

X=int(a[0])
Y=int(a[1])

x=Fraction(4*X-Y,2)
y=Fraction(Y-2*X,2)

if x-round(x)==0 and x >= 0:
  if y-round(y)==0 and y >= 0:
    print("Yes")
  else :
    print("No")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
a=34

if a==int
print(6)
Problem p02641 (python)

Fixed submission:
x,n=map(int, input().split())
a=list(map(int, input().split()))

for y in range(x+1):
  for b in[-1,1]:
    c=x+y*b
    if a.count(c)==0:
      print(c)
      exit(0)

Buggy submission (verdict: Runtime Error):
a=input()
a=a.split()
x=int(a[0])
p=input()
p=p.split()

i=0
p_1=p+[]



for y in p_1:
  p_1[i]=abs(int(p_1[i])-x)
  i=i+1

p_1.sort()
if p_1[0]==0:
  del p_1[0]

q=p_1[0]
if str(x-q) in p:
  print(x-q)
else:
  print(x+q)
Problem p02645 (python)

Fixed submission:
S= input()

str = S

print(str[0:3])

Buggy submission (verdict: Runtime Error):
str = S

print(str[0:2])
Problem p02657 (python)

Fixed submission:
a=input()

a=a.split()

A=int(a[0])
B=int(a[1])
C=A*B

print(C)

Buggy submission (verdict: Runtime Error):
s=input()
a=input()
a=a.split()


c=1
for x in a:
  c=c*int(x)
  
if c > 10**18:
  print("-1")
else:  
  print(c)

Buggy submission (verdict: Runtime Error):
a=input()

a=a.split()

x=a[0]
y=a[1]

c=x*y

print(c)
Problem p02658 (python)

Fixed submission:
a=int(input())
A=list(map(int,input().split()))
ans=1
if A.count(0)==0:
    for x in A:
      ans*=x
      if ans>10**18:
        break


    if ans>10**18:
      print(-1)
    else:
      print(ans)
else:
  print(0)

Buggy submission (verdict: Runtime Error):
s=input()
a=input()
a=a.split()


c=1
for x in a:
  c=c*int(x)
  
if c =< 10**18:
  print(c)
else:  
  print("-1")
Problem p02675 (python)

Fixed submission:
a=int(input())

a = a%10

if a== 2 or a==4 or a==5 or a==7 or a==9:
  print("hon")
elif a== 0 or a==1 or a==6 or a==8:
  print("pon")
else :
  print("bon")

Buggy submission (verdict: Runtime Error):
x=input()


x=int(a[0])

if x%10== 2 or 4 or 5 or 7 or 9:
  print("hon")
elif x%10== 0 or 1 or 6 or 8:
  print("pon")
else x%10== 3:
  print("hon")
Problem p02681 (python)

Fixed submission:
x=input()
b=input()

y=b[:-1]

if x==y:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
a=input()
a=a.split()

x=str(a[0])
y=str(a[1])

y=y[:-1]

if x==y:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
a=input()
a=a.split()

x=str(a[0])
y=str(a[1])

y=txt[:-1]

if x=y:
  print("Yes")
else:
  print("No")
Problem p02687 (python)

Fixed submission:
if input()=="ABC":
  print("ARC")
else :
  print("ABC")

Buggy submission (verdict: Runtime Error):
if int(input())==ABC:
  print("ARC")
else :
  print("ABC")
Problem p02817 (python)

Fixed submission:
a,b=map(str,input().split())
print(b+a)

Buggy submission (verdict: Runtime Error):
a=input()
b=input()
print(b+a)
Problem p02609 (python)

Fixed submission:
n = int(input())
x = input()
pop = x.count("1")
lst1 = [1]
for i in range(n-1):
    lst1.append(lst1[-1] * 2 % (pop + 1))
lst1.reverse()
num1 = 0
for i in range(n):
    if x[i] == "1":
        num1 += lst1[i]
        num1 %= (pop + 1)
if pop == 1 or pop == 2:
    lst2 = [0] * n
else:
    lst2 = [1]
    for i in range(n-1):
        lst2.append(lst2[-1] * 2 % (pop - 1))
    lst2.reverse()
    num2 = 0
    for i in range(n):
        if x[i] == "1":
            num2 += lst2[i]
            num2 %= (pop - 1)
x2 = int(x, 2)
for i in range(n):
    if x[i] == "1":
        if pop == 1:
            print(0)
            continue
        elif pop == 2:
            print(1)
            continue
        else:
            num = num2 - lst2[i]
            num %= (pop - 1)
    else:
        num = num1 + lst1[i]
        num %= (pop + 1)
    count = 1
    while num:
        num %= bin(num).count("1")
        count += 1
    print(count)

Buggy submission (verdict: Runtime Error):
n = int(input())
x = input()
pop = x.count("1")
lst1 = [1]
for i in range(n-1):
    lst1.append(lst1[-1] * 2 % (pop + 1))
lst1.reverse()
num1 = 0
for i in range(n):
    if x[i] == "1":
        num1 += lst[i]
        num1 %= (pop + 1)
if pop == 1 or pop == 2:
    lst2 = [0] * n
else:
    lst2 = [1]
    for i in range(n-1):
        lst2.append(lst2[-1] * 2 % (pop - 1))
    lst.reverse()
    num2 = 0
    for i in range(n):
        if x[i] == "1":
            num2 += lst2[i]
            num2 %= (pop - 1)
x2 = int(x, 2)
for i in range(n):
    if x[i] == "1":
        if pop == 1:
            print(0)
            continue
        elif pop == 2:
            print(1)
            continue
        else:
            num = num2 - lst2[i]
            num %= (pop - 1)
    else:
        num = num1 + lst1[i]
        num %= (pop + 1)
    count = 1
    while num:
        num %= bin(num).count("1")
        count += 1
    print(count)
Problem p04001 (python)

Fixed submission:
n = [int(x) for x in input()]
op_cnt = len(n) - 1  
out=0
for i in range(2 ** op_cnt):
    op = ["+"] * op_cnt  
    box=""
    for j in range(op_cnt):
        if ((i >> j) & 1):
            op[op_cnt - 1 - j] = "" 
        box=""  
    for a,b in zip(n,op+[""]):
        box+=(str(a)+b)
    box=box.split('+')
    ou=0
    for k in box:
        out+=int(k)
print(out)

Buggy submission (verdict: Runtime Error):
n = [int(x) for x in input()]
op_cnt = len(n) - 1  
out=0
for i in range(2 ** op_cnt):
    op = ["+"] * op_cnt  
    for j in range(op_cnt):
        if ((i >> j) & 1):
            op[op_cnt - 1 - j] = "" 
        box=""  
    for a,b in zip(n,op+[""]):
        box+=(str(a)+b)
    box=box.split('+')
    ou=0
    for k in box:
        out+=int(k)
print(out)
Problem p02657 (python)

Fixed submission:
A, B = map(int, input().split())
print(A*B)

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

#while True:
N = int(input())
#	if N>=2 and N<=10**5:break

if 2 <= N <= 10**5:
	num = list(map(int, input().split()))
	
#print(num)
ans = reduce(mul,num)
if ans > 10**18:
	print(-1)
else:
	print(ans)
Problem p02641 (python)

Fixed submission:
import sys

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

p.sort()

if x not in p:
    print(x)
    sys.exit()

for i in range(0, 100):
    if (x - i) not in p:
        print(x - i)
        sys.exit()
    if (x + i) not in p:
        print(x + i)
        sys.exit()

Buggy submission (verdict: Runtime Error):
x, n = map(int, input().split())
p = list(map(int,input().split()))

ans1 = int()
ans2 = int()

p.sort()

if x not in p:
    print(x)
    sys.exit()

for i in range(n):
    if x == p[i]:
        for j in range(x + 1, 100):
            if j not in p:
                ans1 = j
                break
        for k in reversed(range(x,)):
            if k not in p:
                ans2 = k
                break

if ans1 - x < x - ans2:
    print(ans1)
else:
    print(ans2)
Problem p02657 (python)

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

print(int(a) * int(b))

Buggy submission (verdict: Runtime Error):
import sys

n= int(input())
a = list(map(int,input().split()))
ans = a[0]
ans_max = 10 ** 18

for i in range(1, n):
    ans *= a[i]
    if ans > ans_max:
        print("-1")
        sys.exit()

print(ans)

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

print(a * b)
Problem p02658 (python)

Fixed submission:
import sys

n= int(input())
a = list(map(int,input().split()))
ans = a[0]
ans_max = 10 ** 18

if 0 in a:
    print(0)
    sys.exit()

for i in range(1, n):
    ans *= a[i]
    if ans > ans_max:
        print("-1")
        sys.exit()

print(ans)

Buggy submission (verdict: Runtime Error):
n= int(input())
a = list(map(int,input().split()))
ans = a[0]
ans_max = 10 ** 18

for i in range(1, n):
    ans *= a[i]
    if ans > ans_max:
        print("-1")
        sys.exit()

print(ans)
Problem p02675 (python)

Fixed submission:
n = int(input())

list = []
list_hon = [2,4,5,7,9]
list_pon = [0,1,6,8]

while n > 0:
    list.append(n % 10)
    n //= 10

if list[0] in list_hon:
    print("hon")
elif list[0] in list_pon:
    print("pon")
else: #(list[0]) == 3
    print("bon")

Buggy submission (verdict: Runtime Error):
import math

a, b, h, m = map(int, input().split())
colon = float()

h_angle = 30 * h
m_angle = 6 * m

angle = abs(h_angle - m_angle)

if angle >= 180:
    angle -= 180


colon = a ** 2 +  b ** 2  - 2 * a * b * (math.cos(math.radians(angle)))

print(math.sqrt(colon))
Problem p02599 (python)

Fixed submission:
n,q = map(int,input().split())
c = tuple(map(int,input().split()))
qs = [[] for _ in range(n)]
for i in range(q):
  l,r = map(int,input().split())
  l -= 1
  r -= 1
  qs[l].append((r,i))

class BIT:
    def __init__(self,n):
        self.num=n
        self.dat=[0]*(self.num+1)
        self.depth=n.bit_length()
    
    def add(self,i,x):
        i+=1
        while i<=self.num:
            self.dat[i]+=x
            i+=i&-i
    
    def sum(self,i):
        i+=1
        s=0
        while i>0:
            s+=self.dat[i]
            i-=i&-i
        return s
    
    def lower_bound(self,x):
        sum_=0
        pos=0
        for i in range(self.depth,-1,-1):
            k=pos+(1<<i)
            if k<=self.num and sum_+self.dat[k]<x:
                sum_+=self.dat[k]
                pos+=1<<i
        return pos, sum_

ps = [-1 for _ in range(n)]
pi = [-1 for _ in range(n+1)]
for i in range(n):
  l = pi[c[i]]
  if l != -1:
    ps[l] = i
  pi[c[i]] = i
    
d = BIT(n)
ans = [0 for _ in range(q)]
for x in range(n-1,-1,-1):
  if ps[x] != -1:
    d.add(ps[x],1)
  for r,i in qs[x]:
    ans[i] = (r-x+1)-d.sum(r)

for i in range(q):
  print(ans[i])

Buggy submission (verdict: Runtime Error):
n,q = map(int,input().split())
c = tuple(map(int,input().split()))
qs = [[] for _ in range(n)]
for i in range(q):
  l,r = map(int,input().split())
  l -= 1
  r -= 1
  qs[l].append((r,i))

class BIT:
    def __init__(self,n):
        self.num=n
        self.dat=[0]*(self.num+1)
        self.depth=n.bit_length()
    
    def add(self,i,x):
        i+=1
        while i<=self.num:
            self.dat[i]+=x
            i+=i&-i
    
    def sum(self,i):
        i+=1
        s=0
        while i>0:
            s+=self.dat[i]
            i-=i&-i
        return s
    
    def lower_bound(self,x):
        sum_=0
        pos=0
        for i in range(self.depth,-1,-1):
            k=pos+(1<<i)
            if k<=self.num and sum_+self.dat[k]<x:
                sum_+=self.dat[k]
                pos+=1<<i
        return pos, sum_

ps = [-1 for _ in range(n)]
pi = [-1 for _ in range(n)]
for i in range(n):
  l = pi[c[i]]
  if l != -1:
    ps[l] = i
  pi[c[i]] = i
    
d = BIT(n)
ans = [0 for _ in range(q)]
for x in range(n-1,-1,-1):
  if ps[x] != -1:
    d.add(ps[x],1)
  for r,i in qs[x]:
    ans[i] = (r-x+1)-d.sum(r)

for i in range(q):
  print(ans[i])
Problem p02644 (python)

Fixed submission:
h,w,k = map(int,input().split())
x1,y1,x2,y2 = map(int,input().split())
c = []
for i in range(h):
  c.append(list(input()))

q = [(1,x1-1,y1-1)]
c[x1-1][y1-1] = 0
while(q):
  qq = []
  for a,x,y in q:
    for dx,dy in ((0,-1),(0,1),(-1,0),(1,0)):
      for kk in range(1,k+1):
        xx = x+dx*kk
        yy = y+dy*kk
        if not (0 <= xx < h) or not (0 <= yy < w) or c[xx][yy] == '@' or (c[xx][yy] != '.' and c[xx][yy] < a):
          break
        if c[xx][yy] == '.' or (c[xx][yy] != '.' and c[xx][yy] > a):
          c[xx][yy] = a
          qq.append((a+1,xx,yy))
  #print(qq)
  q = qq[:]

print(-1 if c[x2-1][y2-1] == '.' else c[x2-1][y2-1])
#print(c)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 9)
                      
h,w,k = map(int,input().split())
x1,y1,x2,y2 = map(int,input().split())
c = []
for i in range(h):
  c.append(list(input()))

def dfs(x,y,kk,d,a):
  #print(kk,d)
  if c[x][y] == '.':
    c[x][y] = a
  else:
    c[x][y] = min(c[x][y],a)
  for dx,dy in ((-1,0),(1,0),(0,-1),(0,1)):
    if 0 <= x+dx < h and 0 <= y+dy < w and (c[x+dx][y+dy] == '.' or (c[x+dx][y+dy] != '@' and c[x+dx][y+dy] > a)):
      if kk == -1:
        kk = k-1
        a = 1
      elif kk == 0 or d != (dx,dy):
        kk = k
        a += 1
      else:
        kk -= 1
      dfs(x+dx,y+dy,kk,(dx,dy),a)

q = [(0,x1-1,y1-1,-1,())]
while(q):
  qq = []
  for a,x,y,kk,d in q:
    #print(x,y,c[x][y])
    if c[x][y] == '.':
      c[x][y] = a
    else:
      c[x][y] = min(c[x][y],a)
    for dx,dy in ((-1,0),(1,0),(0,-1),(0,1)):
      if 0 <= x+dx < h and 0 <= y+dy < w and (c[x+dx][y+dy] == '.' or (c[x+dx][y+dy] != '@' and c[x+dx][y+dy]>a):
        if kk == -1:
          kk = k-1
          a = 1
        elif kk == 0 or d != (dx,dy):
          kk = k
          a += 1
        else:
          kk -= 1
        qq.append((a,x+dx,y+dy,kk,(dx,dy)))
  q = qq[:]
  q.sort()

print(-1 if c[x2-1][y2-1] == '.' else c[x2-1][y2-1])
print(c)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 9)
                      
h,w,k = map(int,input().split())
x1,y1,x2,y2 = map(int,input().split())
c = []
for i in range(h):
  c.append(list(input()))

def dfs(x,y,kk,d,a):
  #print(kk,d)
  if c[x][y] == '.':
    c[x][y] = a
  else:
    c[x][y] = min(c[x][y],a)
  for dx,dy in ((-1,0),(1,0),(0,-1),(0,1)):
    if 0 <= x+dx < h and 0 <= y+dy < w and (c[x+dx][y+dy] == '.' or (c[x+dx][y+dy] != '@' and c[x+dx][y+dy] > a)):
      if kk == -1:
        kk = k-1
        a = 1
      elif kk == 0 or d != (dx,dy):
        kk = k
        a += 1
      else:
        kk -= 1
      dfs(x+dx,y+dy,kk,(dx,dy),a)

dfs(x1-1,y1-1,-1,(),0)
print(-1 if c[x2-1][y2-1] == '.' else c[x2-1][y2-1])
#print(c)
Problem p02703 (python)

Fixed submission:
from heapq import heappop, heappush

n,m,s = map(int,input().split())
e = [[] for _ in range(n)]
for i in range(m):
  u,v,a,b = map(int,input().split())
  u -= 1
  v -= 1
  e[u].append((v,a,b))
  e[v].append((u,a,b))
c = []
d = []
for i in range(n):
  x,y = map(int,input().split())
  c.append(x)
  d.append(y)

INF = float('inf')
def dijkstra(s,n,g): # sからの最短距離 頂点数n g[v]=[(u1,w1),(u2,w2)....]:vからuへの有向辺があり、重みw
  que = []
  d = [INF for _ in range(n)]
  d[s] = 0
  heappush(que,(0,s))
  while len(que) > 0:
    p = heappop(que)
    v = p[1]
    if d[v] < p[0]:
      continue
    for u,w in g[v]:
      if d[u] > d[v]+w:
        d[u] = d[v]+w
        heappush(que,(d[u],u))
  return d

def newv(v,s):
  return v*2500+s

s = min(s,2499)
e2 = [[] for _ in range(n*2500)]
for u in range(n):
  for j in range(2500):
    #if j+c[u] < 2500:
    #  e2[newv(u,j)].append((newv(u,j+c[u]),d[u]))
    e2[newv(u,j)].append((newv(u,min(j+c[u],2499)),d[u]))
    for v,a,b in e[u]:
      if j >= a:
        e2[newv(u,j)].append((newv(v,j-a),b))

l = dijkstra(newv(0,s),n*2500,e2)
for i in range(1,n):
  ans = INF
  for j in range(2500):
    ans = min(l[newv(i,j)],ans)
  print(ans)

Buggy submission (verdict: Runtime Error):
def main():
  import sys
  input = sys.stdin.readline
  
  n = int(input())
  s = [[],[]]
  for i in range(2):
    s[i] = tuple(map(int,input().split()))
  u = [[],[]]
  for i in range(2):
    u[i] = tuple(map(int,input().split()))
  
  val = [[0 for _ in range(n)] for _ in range(2)]
  d = [[0 for _ in range(n)] for _ in range(n)]
  ans = [[0 for _ in range(n)] for _ in range(n)]
  
  def flip():
    for i in range(n):
      for j in range(i,n):
        d[i][j],d[j][i] = d[j][i],d[i][j]
    
  def solve():
    for i in range(n):
      for j in range(n):
        d[i][j] = -1
    for k in range(1):
      for i in range(n):
        if s[k][i] != val[k][i]:
          for j in range(n):
            if d[i][j] != -1 and d[i][j] != val[k][i]:
              return False
            d[i][j] = val[k][i]
      flip()
    #print(d)
    for l in range(2):
      for k in range(2):
        for i in range(n):
          if s[k][i] == val[k][i]:
            p = []
            ok = False
            for j in range(n):
              if d[i][j] == val[k][i]:
                ok = True
              if d[i][j] == -1:
                p.append(j)
            if ok:
              continue
            if len(p) == 0:
              return False
            elif len(p) == 1:
              d[i][p[0]] = val[k][i]
        flip()
    #print(d)
    start = 0
    for i in range(n):
      num = start
      flag = False
      for j in range(n):
        if d[i][j] == -1:
          flag = True
          d[i][j] = num
          num ^= 1
      if flag:
        start ^= 1
    return True
  
  for b in range(64):
    for i in range(2):
      for j in range(n):
        val[i][j] = (u[i][j]>>b)&1
    if solve():
      for i in range(n):
        for j in range(n):
          ans[i][j] |= d[i][j]<<b
    else:
      print(-1)
      exit()
  
  for i in range(n):
    print(*ans[i])

main()
Problem p02775 (python)

Fixed submission:
def main():
  N = input()
  N = '0'+N
  dp= [[float('inf') for _ in range(2)] for _ in range(len(N)+1)]
  dp[0][0] = 0
  for i in range(len(N)):
    n = int(N[len(N)-1-i])
    for j in range(2):
      # jが1のときは繰り下がりあり。
      # 引かれる数から1を引く代わりに、引く数xに1を足す。
      x = n+j
      # xが10のとき、必ず繰り下がりが起こる。
      if x < 10:
        dp[i+1][0] = min(dp[i+1][0],dp[i][j]+x)
      # xが0のとき、繰り下がりは起こせない。
      if x > 0:
        dp[i+1][1] = min(dp[i+1][1],dp[i][j]+10-x)
  print(dp[len(N)][0])  
  # print(dp)
  
if __name__ == '__main__':
  main()

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

def main():
  N = input()
  N = '0'+N
  dp= [[float('inf') for _ in range(2)] for _ in range(len(N)+1)]
  dp[0][0] = 0
  for i in range(len(N)):
    n = int(N[len(N)-1-i])
    for j in range(2):
      # jが1のときは繰り下がりあり。
      # 引かれる数から1を引く代わりに、引く数xに1を足す。
      x = n+j
      # xが10のとき、必ず繰り下がりが起こる。
      if x < 10:
        dp[i+1][0] = min(dp[i+1][0],dp[i][j]+x)
      # xが0のとき、繰り下がりは起こせない。
      if x > 0:
        dp[i+1][1] = min(dp[i+1][1],dp[i][j]+10-x)
  print(dp[len(N)][0])  
  # print(dp)
  
if __name__ == '__main__':
  main()

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

def main():
  N = input()
  N = '0'+N
  dp= [[float('inf') for _ in range(2)] for _ in range(len(N)+1)]
  dp[0][0] = 0
  for i in range(len(N)):
    n = int(N[len(N)-1-i])
    for j in range(2):
      # jが1のときは繰り下がりあり。
      # 引かれる数から1を引く代わりに、引く数xに1を足す。
      x = n+j
      # xが10のとき、必ず繰り下がりが起こる。
      if x < 10:
        dp[i+1][0] = min(dp[i+1][0],dp[i][j]+x)
      # xが0のとき、繰り下がりは起こせない。
      if x > 0:
        dp[i+1][1] = min(dp[i+1][1],dp[i][j]+10-x)
  print(dp[len(N)][0])  
  # print(dp)
  
if __name__ == '__main__':
  main()

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

def main():
  N = input()
  N = '0'+N
  dp= [[float('inf') for _ in range(2)] for _ in range(len(N)+1)]
  dp[0][0] = 0
  for i in range(len(N)):
    n = int(N[len(N)-1-i])
    for j in range(2):
      # jが1のときは繰り下がりあり。
      # 引かれる数から1を引く代わりに、引く数xに1を足す。
      x = n+j
      # xが10のとき、必ず繰り下がりが起こる。
      if x < 10:
        dp[i+1][0] = min(dp[i+1][0],dp[i][j]+x)
      # xが0のとき、繰り下がりは起こせない。
      if x > 0:
        dp[i+1][1] = min(dp[i+1][1],dp[i][j]+10-x)
  print(dp[len(N)][0])  
  # print(dp)
  
if __name__ == '__main__':
  main()
Problem p02814 (python)

Fixed submission:
from fractions import gcd

def lcm(a, b):
  return a * b // gcd(a, b)
  
N,M = map(int,input().split())
A = list(map(int,input().split()))

B = set()
l = 1
for i in range(len(A)):
  c = 0
  a = A[i]
  while(a%2 == 0):
    a //= 2
    c += 1
  if i == 0:
    c0 = c
  else:
    if c0 != c:
      print(0)
      exit()
  l = lcm(l,A[i]//2)

print((M+l)//(2*l))

Buggy submission (verdict: Runtime Error):
from fractions import gcd
import sys
sys.setrecursionlimit(10 ** 9)

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

def llcm(a):
  if len(a) == 1:
    return a
  elif len(a) == 2:
    return lcm(a[0],a[1])
  else:
    return lcm(a[0],llcm(a[1:]))
  
N,M = map(int,input().split())
A = list(map(int,input().split()))

B = set()
flag = False
for a in A:
  if (a//2)%2 == 1 and (a//2) >=3:
    flag = True
  B.add(a//2)

l = llcm(list(B))
#print(l)
if l > M:
  ans = 0
else:
  ans = 1+(M-l)//(2*l)
if not flag:
  ans = max(ans-1,0)
print(ans)

Buggy submission (verdict: Runtime Error):
from fractions import gcd
import sys
sys.setrecursionlimit(10 ** 9)

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

def llcm(a):
  if len(a) == 1:
    return a
  elif len(a) == 2:
    return lcm(a[0],a[1])
  else:
    return lcm(a[0],llcm(a[1:]))
  
N,M = map(int,input().split())
A = list(map(int,input().split()))

B = set()
flag = False
for a in A:
  if (a//2)%2 == 1 and (a//2) >=3:
    flag = True
  B.add(a//2)

l = llcm(list(B))
#print(l)
if l > M:
  ans = 0
else:
  ans = 1+(M-l)//(2*l)
if not flag:
  ans = max(ans-1,0)
print(ans)

Buggy submission (verdict: Runtime Error):
from fractions import gcd
import sys
sys.setrecursionlimit(10 ** 9)

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

def llcm(a):
  if len(a) == 1:
    return a
  elif len(a) == 2:
    return lcm(a[0],a[1])
  else:
    return llcm(a[0],a[1:])
  
N,M = map(int,input().split())
A = list(map(int,input().split()))

B = set()
for a in A:
  if (a//2)%2 == 0:
    print(0)
    exit()
  else:
    B.add(a//2)

l = llcm(list(B))
#print(l)
if l > M:
  ans = 0
else:
  ans = 1+(M-l)//(2*l)
print(ans)
Problem p02824 (python)

Fixed submission:
N,M,V,P = map(int,input().split())
A = sorted(list(map(int,input().split())),reverse= True)

def check(i):
  if i <= P-1:
    return True
  vote = (V-1)*M
  vote -= (N-1-i)*M
  vote -= (P-1)*M
  if vote <= 0:
    return A[i]+M >= A[P-1]
  else:
    for j in range(i-1,P-1,-1):
      if A[j] > A[i]+M:
        return False
      v = min(A[i]+M-A[j],M,vote)
      vote -= v
      if vote <= 0:
        break
    if vote <= 0:
      return A[i]+M >= A[P-1]
    else:
      return A[i]+M >= A[P-1]+vote

ok = -1
ng = N
while(ok+1 < ng):
  md = (ok+ng)//2
  if check(md):
    ok = md
  else:
    ng = md
print(ok+1)

Buggy submission (verdict: Runtime Error):
N,M,V,P = map(int,input().split())
A = sorted(list(map(int,input().split())),reverse= True)
#print(A)

ans = set()
i = 0
while(A[i] >= A[P-1]):
  ans.add(i)
  i += 1
#print(ans)

csum = [0 for _ in range(N)]
csum[P-1] = A[P-1]
for i in range(P,N):
  csum[i] = csum[i-1]+A[i]

for i in range(P,N):
  if A[i]+M >= (csum[i-1]+((V-P)*M-(N-1-i)*M)+1)//(i-(P-1)):
    ans.add(i)
#print(ans)

print(len(ans)-1)

Buggy submission (verdict: Runtime Error):
N,M,V,P = map(int,input().split())
A = sorted(list(map(int,input().split())),reverse= True)
#print(A)

ans = set()
i = 0
while(A[i] >= A[P-1]):
  ans.add(i)
  i += 1
#print(ans)

for i in range(P,N):
  if A[i]+M >= A[P-1]+((V-P+1)*M-(N-1-i)*M)//(i-(P-1)):
    ans.add(i)
#print(ans)

print(len(ans))
Problem p02845 (python)

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

C = [3] + [0 for i in range(N)]

ans = 1
for a in A:
  ans *= C[a]
  ans %= MOD
  C[a] -= 1
  C[a+1] += 1
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
MOD = 1000000007

C = [3] + [0 for i in range(N)]

ans = 1
for a in A:
  ans *= C[a]
  ans %= MOD
  C[a] -= 1
  C[a+1] += 1
print(ans)