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

Fixed submission:
import numpy as np
N = int(input())
A = np.array(input().split(), dtype=np.int32)
B = np.array(input().split(), dtype=np.int32)
C = - np.array(input().split(), dtype=np.int32)
 
A.sort()
B.sort()
C.sort()
 
cnt_A = np.searchsorted(A,B,side='left')
cnt_C = np.searchsorted(C,-B,side='left')
 
answer = (cnt_A * cnt_C).sum()
print(answer)

Buggy submission (verdict: Runtime Error):
import numpy as np
N = int(input())
A = np.array(input().split(), dtype=np.int32)
B = np.array(input().split(), dtype=np.int32)
C = - np.array(input().split(), dtype=np.int32)
 
A.sort()
B.sort()
C.sort()
 
cnt_A = np.searchsorted(A,B,side='left')
cnt_C = np.searchsorted(C,-B,side='left')
 
answer = (cnt_A * cnt_C).sum()
print(answer)
Problem p03714 (python)

Fixed submission:
#########################ABC解説実装#########################
import heapq
N=int(input())
A=list(map(int, input().split()))

left, right = A[:N], [-1 * i for i in A[2*N:]]
sum_left, sum_right = sum(left), sum(right)

results = [0] * (N+1)
results[0] = sum_left
results[N] = sum_right

heapq.heapify(left)
heapq.heapify(right)

for i in range(N, 2*N):
    v = A[i]
    p = heapq.heappushpop(left, v)
    sum_left += v - p
    results[i-N+1] += sum_left
    
for i in range(2*N-1, N-1, -1):
    v = -1 * A[i]
    p = heapq.heappushpop(right, v)
    sum_right += v - p
    results[i-N] += sum_right
print(max(results))

Buggy submission (verdict: Runtime Error):
N=int(input())
A=list(map(int, input().split()))
A_rev = [-x for x in A[::-1]] #逆順にして各要素を-1倍する
left, right = A[:N], A_rev[:N]
sum_left_list, sum_right_list = [0]*(N+1), [0]*(N+1)
sum_left, sum_right = sum(left), sum(right)
sum_left_list[0], sum_right_list[0]=sum_left, sum_right

#left: k=N, N+1,..., 2N-1まで動かして大きい方からN個の和を求める
for k in range(N, 2*N):
	val=A[k]
	heapq.heappush(left, val)
	min_val = heapq.heappop(left)
	sum_left += val
	sum_left -= min_val
	sum_left_list[k-N+1] = sum_left

#right: k=N, N+1,..., 2N-1まで動かして大きい方からN個の和を求める
for k in range(N, 2*N):
	val = A_rev[k]
	heapq.heappush(right, val)
	min_val = heapq.heappop(right)
	sum_right += val
	sum_right -= min_val
	sum_right_list[k-N+1] = sum_right
sum_right_list[::-1]

ans=-float("inf")
for i in range(N+1):
	ans=max(ans, sum_left_list[i]+sum_right_list[i])
print(ans)
Problem p03000 (python)

Fixed submission:
N = [int(i) for i in input().split()]
K = [int(i) for i in input().split()]
s = 0
c = 1
for i in K:
    s += i
    if s > N[1]:
        break
    else:
        c += 1
print(c)

Buggy submission (verdict: Runtime Error):
N = [int(i) for i in input().split()]
K = [int(i) for i in input().split()]
s = 0
c = 1
for i in K:
	if (i + s) <= N[1]
  		c += 1
      	s += i + s
	else
    	break
print(c)
Problem p02657 (python)

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

Buggy submission (verdict: Runtime Error):
import numpy as np
from numpy.compat import long

n = int(input())
a = list(map(long ,input().split()))
p = np.prod(a)

if len(str(p))>=19:
    print("-1")
else:
    print(p)

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

n = int(input())
a = list(map(int ,input().split()))
p = np.prod(a)
if len(p)>=19:
    print(-1)
else:
    print(p)
Problem p02675 (python)

Fixed submission:
N = int(input())
a = 0

if N>=100:
    a = N % 100
    if N >= 10:
        a = a % 10
elif N >= 10:
    a = N % 10
else:
    a = N

if a == 0:
    print("pon")
elif a == 1:
    print("pon")
elif a == 6:
    print("pon")
elif a == 8:
    print("pon")
elif a == 3:
    print("bon")
else:
    print ("hon")

Buggy submission (verdict: Runtime Error):
K = int(input())
S = input()

if len(S) < K:
    print(S)
else:
    for i in range(K):
        print(S[i],end="")
    print("...")
Problem p02612 (python)

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

Buggy submission (verdict: Runtime Error):
N = 10000 - int(input())
if N % 1000 == 0:
    print(0)
ans = [str(x) for x in list(str(N))]
print(ans[-3]+ans[-2]+ans[-1])

Buggy submission (verdict: Runtime Error):
N = 10000 - int(input())
ans = [str(x) for x in list(str(N))]
print(ans[-3]+ans[-2]+ans[-1])
Problem p04045 (python)

Fixed submission:
numbers = {str(i) for i in range(10)}
N, K = map(int, input().split())
*D, = map(str, input().split())
D = set(D)
available = numbers - D
ans = 0
for i in range(N, 100000):
    nums = set(str(i))
    if nums <= available:
        print(i)
        break

Buggy submission (verdict: Runtime Error):
l = list(range(10))  # LIST10桁の数字を生成
n, k = map(int, input().split())  # n=値段,10000以下 k=嫌いな個数
lis = list(map(int, input().split()))  # 嫌いな数字入力
[l.remove(x) for x in lis]  # 10桁の数字から嫌いな数字を削除
h = n / 10 ** (len(str(n))-1)  # 値段の一番左の数字を取得するための計算
temp = []
for x in l:
    if h < x:
        temp.append(x)
ans = []
ans.append(temp[0])
for x in range(len(str(n))-1):
    ans.append(l[0])
print(int("".join(map(str, ans))))
Problem p02612 (python)

Fixed submission:
N = int(input())
if 0 <= N <= 1000:
  print(1000 - N)
elif 1001 <= N <= 2000:
  print(2000 - N)
elif 2001 <= N <= 3000:
  print(3000 - N)
elif 3001 <= N <= 4000:
  print(4000 - N)
elif 4001 <= N <= 5000:
  print(5000 - N)
elif 5001 <= N <= 6000:
  print(6000 - N)
elif 6001 <=N <= 7000:
  print(7000 - N)
elif 7001 <= N <= 8000:
  print(8000 - N)
elif 8001 <= N <= 9000:
  print(9000 - N)
else:
  print(10000 - N)

Buggy submission (verdict: Runtime Error):
N = int(input())
if 0 <= N <= 1000:
  print(1000 - N)
elif 1001 <= N <= 2000:
  print(2000 - N)
elif 2001 <= N <= 3000:
  print(3000 - N)
elif 3001 <= N <= 4000:
  print(4000 - N)
elif 4001 <= N <= 5000:
  print(5000 - N)
elif 5001 <= N <= 6000:
  print(6000 - N)
elif 6001 <=N <= 7000
  print(7000 - N)
elif 7001 <= N <= 8000:
  print(8000 - N)
elif 8001 <= N <= 9000:
  print(9000 - N)
else:
  print(10000 - N)

Buggy submission (verdict: Runtime Error):
N = int(input())
if N <= 1000:
  print(1000 - N)
elif N <= 2000:
  print(2000 - N)
elif N <= 3000:
  print(3000 - N)
elif N <= 4000:
  print(4000 - N)
elif N <= 5000:
  print(5000 - N)
elif N <= 6000:
  print(6000 - N)
elif N <= 7000
  print(7000 - N)
elif N <= 8000:
  print(8000 - N)
elif N <= 9000:
  print(9000 - N)
else:
  print(10000 - N)
Problem p02621 (python)

Fixed submission:
a = int(input())
n = a + a*a + a*a*a
print(n)

Buggy submission (verdict: Runtime Error):
a = int(input)
n = a + a*a + a*a*a
print(n)
Problem p02639 (python)

Fixed submission:
print(15 - sum(list(map(int , input().split()))))

Buggy submission (verdict: Runtime Error):
x = str(input())
if x[n] == 0:
  print(n)

Buggy submission (verdict: Runtime Error):
x = str(input())
if x[n] ==0:
  print(n)

Buggy submission (verdict: Runtime Error):
x = int(input())
if x[n] ==0:
  print(n)
Problem p02675 (python)

Fixed submission:
mylist1 = [2,4,5,7,9]
mylist2 = [0,1,6,8]
N  = int(input())
X = N % 10
if X in mylist1:
  print('hon')
elif X in mylist2:
  print('pon')
else:
  print('bon')

Buggy submission (verdict: Runtime Error):
mylist1 = [2,4,5,7,9]
mylist2 = [0,1,6,8]
N  = int(input())
X = N % 10
if X in mylsit1:
  print('hon')
elif X in mylist2:
  print('pon')
else:
  print('bon')

Buggy submission (verdict: Runtime Error):
N = int(input())
x = N % 10
if x　in [2,4,5,7,9]:
  print('hon')
elif x in [0,6,1,8]:
  print('pon')
else:
  print('bon')

Buggy submission (verdict: Runtime Error):
N = input()
x = N % 10
if x　in [2,4,5,7,9]:
  print('hon')
elif x in [0,6,1,8]:
  print('pon')
else:
  print('bon')

Buggy submission (verdict: Runtime Error):
N = int(input())
x = N % 10
if x　in [2,4,5,7,9]:
  print('hon')
elif x in [0,6,1,8]:
  print('pon')
else:
  print('bon')
Problem p02684 (python)

Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
c=0
d={}
d[1]=0
dd={}
dd[0]=1
now=1
while True:
    now=a[now-1]
    c+=1
    if now in d:
        break
    d[now]=c
    dd[c]=now
s=d[now]
if k<=s:
    print(dd[k])
    exit()
p=c-s
k-=s
k%=p
k+=s
print(dd[k])

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=list(map(int,input().split()))
c=0
d={}
d[1]=0
dd={}
d[0]=1
now=1
while True:
    now=a[now-1]
    c+=1
    if now in d:
        break
    d[now]=c
    dd[c]=now
s=d[now]
if k<=s:
    print(dd[k])
    exit()
p=c-s
k-=s
k%=p
k+=s
print(dd[k])
Problem p02719 (python)

Fixed submission:
n,k=map(int,input().split())
if k==1:
    print(0)
    exit()
x=n%k
print(min(x,k-x))

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
if k==1:
    print(0)
    exit()

def gcd(x,y):
    if x==y:
        return x
    elif x>y:
        r=-1
        while r!=0:
            r=x%y
            x=y
            y=r
        return x
    else:
        r=-1
        while r!=0:
            r=y%x
            y=x
            x=r
        return y

print(gcd(n,k))
Problem p02850 (python)

Fixed submission:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**9)
n=int(input())
e=[[] for _ in range(n)]
a=[0]*n
b=[0]*n
d={}
def dfs(x,last=-1,ban=-1):
    c=1
    for to in e[x]:
        if to==last:
            continue
        if c==ban:
            c+=1
        d[(x,to)]=c
        dfs(to,x,c)
        c+=1

for i in range(n-1):
    a[i],b[i]=map(int,input().split())
    a[i]-=1
    b[i]-=1
    e[a[i]].append(b[i])
    e[b[i]].append(a[i])

dfs(0)
print(max(d.values()))
for i in range(n-1):
    if (a[i],b[i]) in d:
        print(d[(a[i],b[i])])
    else:
        print(d[(b[i],a[i])])

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
n=int(input())
e=[[] for _ in range(n)]
a=[0]*n
b=[0]*n
d={}
def dfs(x,last=-1,ban=-1):
    c=1
    for to in e[x]:
        if to==last:
            continue
        if c==ban:
            c+=1
        d[(x,to)]=c
        dfs(to,x,c)
        c+=1

for i in range(n-1):
    a[i],b[i]=map(int,input().split())
    a[i]-=1
    b[i]-=1
    e[a[i]].append(b[i])
    e[b[i]].append(a[i])

dfs(0)
print(max(d.values()))
for i in range(n-1):
    if (a[i],b[i]) in d:
        print(d[(a[i],b[i])])
    else:
        print(d[(b[i],a[i])])
Problem p02936 (python)

Fixed submission:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(1000000)

n,q=map(int,input().split())
g=[[] for _ in range(n+1)]

for _ in range(n-1):
    a,b=map(int,input().split())
    g[a].append(b)
    g[b].append(a)
c=[0]*(n+1)
que=[1]
done=[0]*(n+1)
done[1]=1
for _ in range(q):
    p,x=map(int,input().split())
    c[p]+=x
while que:
    d=que.pop()
    for node in g[d]:
        if not done[node]:
            c[node]+=c[d]
            que.append(node)
            done[node]+=1
print(*c[1:])

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
sys.setrecursionlimit(100000)
n,q=map(int,input().split())
g=[[i] for i in range(n+1)]

for _ in range(n-1):
    a,b=map(int,input().split())
    g[a].append(b)

c=[0]*(n+1)
def dfs(p,x):
    for i in g[p]:
        if r[i]:
            r[i]=0
            c[i]+=x
            dfs(i,x)

for _ in range(q):
    r=[1]*(n+1)
    p,x=map(int,input().split())
    dfs(p,x)


print(*c[1:])
Problem p03006 (python)

Fixed submission:
n=int(input())
xy=[tuple(map(int,input().split())) for _ in range(n)]
pq=[]
for i in range(n):
    for j in range(n):
        if i==j:
            continue
        sx,sy=xy[i]
        gx,gy=xy[j]
        pq.append((gx-sx,gy-sy))


se=set(xy)

ans=n
for p,q in pq:
    now=0
    for x,y in xy:
        if (x+p,y+q) not in se:
            now+=1
    ans=min(ans,now)

print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
da={}
db={}
xy=[]
for _ in range(n):
    xy.append(list(map(int,input().split())))

for i in range(n):
    usedx=[]
    usedy=[]
    x1,y1=xy[i]
    for j in range(n):
        if i==j:
            continue
        x,y=xy[j]

        if x-x1 not in usedx and x-x1!=0:
            if x-x1 not in da:
                da[x-x1]=1
            else:
                da[x-x1]=da[x-x1]+1
            usedx.append(x-x1)

        if y-y1 not in usedy and y-y1!=0:
            if y-y1 not in db:
                db[y-y1]=1
            else:
                db[y-y1]=db[y-y1]+1
            usedy.append(y-y1)
print(n-min(max(da.values()),max(db.values())))
Problem p03043 (python)

Fixed submission:
n,k=map(int,input().split())
cou=0
for i in range(1,min(n+1,k)):
    for j in range(20):
        if i*(2**j)>=k:
            cou+=(1/n)*(1/2)**j
            break
if n>=k:
    cou+=(n+1-k)/n
print(cou)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
ans=0
import math
for i in range(1,n+1):
    x=math.log2(k)-math.log2(i)
    if x<=0:
        ans+=1
        continue
    if x.is_integer():
        ans+=1/(2**x)
    else:
        ans+=1/(2**(int(x)+1))
print(ans/n)
Problem p03061 (python)

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

def gcd(a,b):
    if a == 0:
        return b
    if b == 0:
        return a
    r = 1
    while r > 0:
        r = a % b
        a = b
        b = r
    return a

l=[0]*(n+1)
r=[0]*(n+1)
for i in range(n):
    l[i+1]=gcd(l[i],a[i])
for i in range(n,0,-1):
    r[i-1]=gcd(r[i],a[i-1])

m=[]
for i in range(n):
    m.append(gcd(l[i],r[i+1]))

print(max(m))

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

import fraction
from functools import reduce

def gcd_(*numbers):
    return reduce(fraction.gcd, numbers)

dp=[]
for i in range(n):
    aa=list(a)
    del aa[i]
    dp.append(gcd_(*aa))

print(max(dp))

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

import fraction
from functools import reduce

def gcd(*numbers):
    return reduce(fraction.gcd, numbers)

dp=[]
for i in range(n):
    aa=list(a)
    del aa[i]
    dp.append(gcd(*aa))

print(max(dp))

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

import fraction
from functools import reduce

def gcd(*numbers):
    return reduce(fraction.gcd, numbers)

dp=[]
for i in range(n):
    aa=list(a)
    del aa[i]
    dp.append(gcd(*aa))

print(max(dp))

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

import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

dp=[]
for i in range(n):
    aa=list(a)
    del aa[i]
    dp.append(gcd(*aa))

print(max(dp))

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

import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

dp=[]
for i in range(n):
    aa=list(a)
    del aa[i]
    dp.append(gcd(*aa))

print(max(dp))
Problem p03062 (python)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
c=0
for i in range(n):
    if a[i]<0:
        c+=1
        a[i]=-1*a[i]
aa=list(map(abs,a))
if c%2==0:
    print(sum(aa))
else:
    print(sum(aa)-2*min(aa))

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
c=0
for i in range(a):
    if a[i]<0:
        c+=1
        a[i]=-1*a[i]
aa=list(map(abs,a))
if c%2==0:
    print(sum(aa))
else:
    print(sum(aa)-2*min(aa))

Buggy submission (verdict: Runtime Error):
n=int(input())
aa=(map(int,input().split()))
aa.append(0)
aaa=tuple(a)
a=list(aaa)
for i in range(n-1):
    if a[i]<0:
        a[i]=-1*a[i]
        a[i+1]=-1*a[i+1]
b=list(aaa)
for i in range(n,0,-1):
    if b[i]<0:
        b[i]=-1*b[i]
        b[i-1]=-1*b[i-1]

print(max(sum(a),sum(b))
Problem p03067 (python)

Fixed submission:
a,b,c=map(int,input().split())
if (c>a and c<b) or (c<a and c>b):
    print("Yes")
else:
    print("No")

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

b2=0
h2=0
for i in range(len(s)-1,-1,-1):
    if s[i]=="#" and h2!=0:
        b2+=1
    if s[i]==".":
        h2+=1
print(b2)
Problem p03071 (python)

Fixed submission:
a,b=map(int,input().split())
m=0
if a>b:
    m+=a
    a=a-1
else:
    m+=b
    b=b-1
m+=max(a,b)
print(m)

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
if a>b:
    m+=a
    a=a-1
m+=max(a,b)
print(m)
Problem p03074 (python)

Fixed submission:
n,k=map(int,input().split())
s=input()
wa=[]
now=1
cnt=0
for i in range(n):
    if s[i]==str(0+now):
        cnt+=1
    else:
        wa.append(cnt)
        now=1-now
        cnt=1
if cnt!=0:
    wa.append(cnt)

if len(wa)%2==0:
    wa.append(0)

add=2*k+1
ans=0

left=0
right=0
tmp=0
for i in range(0,len(wa),2):
    nextleft=i
    nextright=min(i+add, len(wa))

    while nextleft > left:
        tmp-=wa[left]
        left+=1
    while nextright > right:
        tmp+=wa[right]
        right+=1

    ans=max(tmp,ans)
print(ans)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
s=input()
from collections import deque
l=deque()
c=1
for i in range(1,n):
    if s[i]!=s[i-1]:
        l.append([s[i-1],c])
        c=1
    else:
        c+=1
l.append([s[-1],c])
if l[0][0]=="1":
    a,c=l.popleft()
    l[0][1]+=c
if l[-1][0]=="1":
    a,c=l.pop()
    l[-1][1]+=c

ll=[]
for i in range(len(l)):
    ll.append(l[i][1])

ans=0
for i in range(len(ll)-2*k+1):
    ans=max(ans,sum(ll[i:i+2*k]))
print(ans)
Problem p03078 (python)

Fixed submission:
x,y,z,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=sorted(list(map(int,input().split())),reverse=True)
ab=[]
for i in a:
    for j in b:
        ab.append(i+j)
ab.sort(reverse=True)
ans=[]
for i in range(min(k,len(ab))):
    for j in range(min(k,len(c))):
        ans.append(ab[i]+c[j])
ans.sort(reverse=True)
for i in range(k):
    print(ans[i])

Buggy submission (verdict: Runtime Error):
x,y,z,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
aa=sorted(a,reverse=True)
bb=sorted(b,reverse=True)
cc=sorted(c,reverse=True)
n=0
l=[]
while n<=k:
    for i in range(15):
        for j in range(15):
            for x in range(15):
                ll=l.append(aa[i]+bb[j]+cc[x])
ll.sort(reverse=True)
for i in range(k):
    print(ll[i])

Buggy submission (verdict: Runtime Error):
x,y,z,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
aa=sorted(a,reverse=True)
bb=sorted(b,reverse=True)
cc=sorted(c,reverse=True)
n=0
l=[]
while n<=k:
    for i in range(100):
        for j in range(100):
            for x in range(100):
                ll=l.append(aa[i]+bb[j]+cc[x])
ll.sort(reverse=True)
for i in range(k):
    print(ll[i])

Buggy submission (verdict: Runtime Error):
x,y,z,k=map(int,input().split())
a=list(map(int,input().split())).sort(reverse=True)
b=list(map(int,input().split())).sort(reverse=True)
c=list(map(int,input().split())).sort(reverse=True)
n=0
l=[]
while n=<k:
    for i in range(k//3):
        for j in range(k//3):
            for x in range(k//3):
                l.append(a[i]+b[j]+c[x])
l.sort(reverse=True)
for i in range(k):
    print(l[i])
Problem p03085 (python)

Fixed submission:
b=input()
if b=="A":
    print("T")
elif b=="T":
    print("A")
elif b=="C":
    print("G")
else:
    print("C")

Buggy submission (verdict: Runtime Error):
b=input()
if b="A":
    print("T")
elif b="T":
    print("T")
elif b="C":
    print("G")
else:
    print("C")
Problem p03088 (python)

Fixed submission:
n=int(input())
mod=10**9+7
memo=[{} for _ in range(n+1)]
def ok(last4):
    for i in range(4):
        t=list(last4)
        if i>=1:
            t[i-1],t[i]=t[i],t[i-1]
        if "".join(t).count("AGC")>=1:
            return False
    return True

def dfs(cur,last3):
    if last3 in memo[cur]:
        return memo[cur][last3]
    if cur==n:
        return 1
    ret=0
    for c in "ACGT":
        if ok(last3+c):
            ret=(ret+dfs(cur+1,last3[1:]+c))%mod
    memo[cur][last3]=ret
    return ret
dfs(0,"TTT")
print(memo[0]["TTT"])

Buggy submission (verdict: Runtime Error):
n=int(input())
mod=10**9+7
memo=[[] for _ in range(n+1)]
def ok(last4):
    for i in range(4):
        t=list(last4)
        if i>=1:
            t[i-1],t[i]=t[i],t[i-1]
        if "".join(t).count("AGC")>=1:
            return False
    return True

def dfs(cur,last3):
    if last3 in memo[cur]:
        return memo[cur][last3]
    if cur==n:
        return 1
    ret=0
    for c in "ACGT":
        ret=(ret+dfs(cur+1,last3[1:]+c))%mod
    memo[cur][last3]=ret
    return ret
print(dfs(0,"TTT"))
Problem p03096 (python)

Fixed submission:
nn=int(input())
import sys
input=sys.stdin.readline
cc=[int(input()) for _ in range(nn)]
c=[cc[0]]
for i in range(1,nn):
    if cc[i]!=c[-1]:
        c.append(cc[i])
n=len(c)
mod=10**9+7
dp=[0]*(n+1)
sm=[0]*(max(c)+1)
dp[0]=1
for i in range(n):
    x=c[i]
    dp[i+1]+=sm[x]+dp[i]
    sm[x]+=dp[i]
    dp[i]%=mod
    dp[i+1]%=mod
print(dp[n])

Buggy submission (verdict: Runtime Error):
nn=int(input())
import sys
input=sys.stdin.readline
cc=[int(input()) for _ in range(n)]
c=[cc[0]]
for i in range(1,nn):
    if cc[i]!=c[-1]:
        c.append(cc[i])
n=len(c)
mod=10**9+7
dp=[0]*(n+1)
sm=[0]*(max(c)+1)
dp[0]=1
for i in range(n):
    x=c[i]
    dp[i+1]+=sm[x]+dp[i]
    sm[x]+=dp[i]
    dp[i]%=mod
    dp[i+1]%=mod
print(dp[n])

Buggy submission (verdict: Runtime Error):
n=int(input())
c=[int(input()) for _ in range(n)]
c.insert(0,0)
mod=10**9+7
dp=[0]*(n+1)
dp[0]=1
place=[[] for _ in range(n+1)]

for i in range(n+1):
    place[c[i]].append(i)

import bisect
for i in range(1,n+1):
    dp[i]+=dp[i-1]
    col=c[i-1]
    it=bisect.bisect_left(place[col],i-1)
    if it>0:
        j=place[col][it-1]
        if i-1-j>1:
            dp[i]+=dp[j+1]
print(dp[n])

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
n=int(input())
c=[int(input()) for _ in range(n)]
#g=[[]for _ in range(2*(10**5)+1)]
g=[[] for _ in range(10)]


for i in range(n):
    g[c[i]].append(i)

ans=1
for i in range(len(g)):
    if not g[i]:
        continue
    new=[]
    now=g[i][0]
    cnt=1
    m=1
    for j in range(1,len(g[i])):
        m+=1
        if now+1==g[i][j]:
            cnt+=1
            now+=1
        else:
            now=g[i][j]
            new.append(cnt)
            cnt=1
    new.append(cnt)
    ans2=m*(m-1)//2
    for k in new:
        ans2-=k*(k-1)//2
    ans+=ans2

print(ans)
Problem p03101 (python)

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

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

Buggy submission (verdict: Runtime Error):
s=(H-h)*(W-w)
print(s)

Buggy submission (verdict: Runtime Error):
int(input(H W h w))

s=(H-h)*(W-w)
print(s)

Buggy submission (verdict: Runtime Error):
int(input(H,W,h,w))

s=(H-h)*(W-w)
print(s)
Problem p03111 (python)

Fixed submission:
N,A,B,C=map(int,input().split())
l=[int(input()) for i in range(N)]
inf=10**9

def dfs(cur,a,b,c):
    if cur==N:
        return abs(a-A)+abs(b-B)+abs(c-C)-30 if min(a,b,c)>0 else inf
    ret0=dfs(cur+1,a,b,c)
    ret1=dfs(cur+1,a+l[cur],b,c)+10
    ret2=dfs(cur+1,a,b+l[cur],c)+10
    ret3=dfs(cur+1,a,b,c+l[cur])+10
    return min(ret0,ret1,ret2,ret3)

print(dfs(0,0,0,0))

Buggy submission (verdict: Runtime Error):
N,A,B,C=map(int,input().split())
l=[int(input()) for i in range(n)]
inf=10**9

def dfs(cur,a,b,c):
    if cur==N:
        return abs(a-A)+abs(b-B)+abs(c-C)-30 if min(a,b,c)>0 else inf
    ret0=dfs(cur+1,a,b,c)
    ret1=dfs(cur+1,a+l[cur],b,c)+10
    ret2=dfs(cur+1,a,b+l[cur],c)+10
    ret3=dfs(cur+1,a,b,c+l[cur])+10
    return min(ret0,ret1,ret2,ret3)

print(dfs(0,0,0,0))
Problem p03130 (python)

Fixed submission:
g=[0]*5
for _ in range(3):
    a,b=map(int,input().split())
    g[a]+=1
    g[b]+=1
if g.count(1)==2:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
h,w=map(int,input().split())
l=[]
n=0
m=0
cou=0
for i in range(h):
    x=input()
    if x==("."*w):
        cou+=1
        continue
    l.append(list(x))
for i in range(w):
    k=0
    for j in range(h-cou-1):
        if l[j][i]=="#":
            break
        else:
            k+=1
    if k==h-cou:
        for d in range(h-cou):
            del l[d][i]
for i in range(h-cou):
    l[i]="".join(l[i])
    print(l[i])