Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
l=list(input())
n=len(l)
p=10**9+7
ans=0
d=0
for i in range(n):
    if l[i]=="1":
        x=n-i-1
        k=x//p
        m=x%p
        K=d//p
        M=d%p
        ans+=(((3**(k+m))%p)*((2**(K+M))%p))%p
        d+=1
    else:
        continue
K=d//p
M=d%p
ans+=2**(K+M)
print(ans%p)



Fixed submission:
l=list(input())
n=len(l)
p=10**9+7
dp1=[0]*n
dp2=[0]*n
dp1[0]=1
dp2[0]=2
for i in range(1,n):
    if l[i]=="1":
        dp1[i]=(3*dp1[i-1]+dp2[i-1])%p
        dp2[i]=(dp2[i-1]*2)%p
    else:
        dp1[i]=(3*dp1[i-1])%p
        dp2[i]=dp2[i-1]
print((dp1[n-1]+dp2[n-1])%p)

Buggy python submission (verdict: Time Limit Exceeded):
l=list(input())
n=len(l)
p=10**9+7
ans=0
d=0
for i in range(n):
    if l[i]=="1":
        x=n-i-1
        k=x//p
        m=x%p
        K=d//p
        M=d%p
        ans+=((3**(k+m))%p)*((2**(K+M))%p)
        d+=1
    else:
        continue
K=d//p
M=d%p
ans+=2**(K+M)
print(ans%p)


Fixed submission:
l=list(input())
n=len(l)
p=10**9+7
dp1=[0]*n
dp2=[0]*n
dp1[0]=1
dp2[0]=2
for i in range(1,n):
    if l[i]=="1":
        dp1[i]=(3*dp1[i-1]+dp2[i-1])%p
        dp2[i]=(dp2[i-1]*2)%p
    else:
        dp1[i]=(3*dp1[i-1])%p
        dp2[i]=dp2[i-1]
print((dp1[n-1]+dp2[n-1])%p)

Buggy python submission (verdict: Time Limit Exceeded):
l=list(input())
n=len(l)
p=10**9+7
ans=0
d=0
for i in range(n):
    if l[i]=="1":
        x=n-i-1
        k=x//p
        m=x%p
        K=d//p
        M=d%p
        ans+=((3**(k+m))%p)*((2**(K+M))%p)
        d+=1
    else:
        continue
ans+=2**d
print(ans%p)



Fixed submission:
l=list(input())
n=len(l)
p=10**9+7
dp1=[0]*n
dp2=[0]*n
dp1[0]=1
dp2[0]=2
for i in range(1,n):
    if l[i]=="1":
        dp1[i]=(3*dp1[i-1]+dp2[i-1])%p
        dp2[i]=(dp2[i-1]*2)%p
    else:
        dp1[i]=(3*dp1[i-1])%p
        dp2[i]=dp2[i-1]
print((dp1[n-1]+dp2[n-1])%p)
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())

import sys
sys.setrecursionlimit(10**9) #再帰の上限をあげる

root=[-1 for i in range(n+1)] #自分が親ならグループの人数のマイナス倍を、そうでないなら（元）親の番号を示す

def r(x):   #親は誰？
    if root[x]<0:
        return x
    else:
        
        return r(root[x])

def unite(x,y):
    x=r(x)
    y=r(y)
    if x==y:
        return
    
    root[x]+=root[y]
    root[y]=x

for i in range(m):
    x,y,z=map(int,input().split())
    unite(x,y)


g=[0]*(n+1)
for i in range(1,n+1):
    g[r(i)]+=1
ans=0
for i in range(n+1):
    if g[i]>0:
        ans+=1
print(ans)



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

import sys
sys.setrecursionlimit(10**9) #再帰の上限をあげる

root=[i for i in range(n+1)] #自分が親なら自身の番号を、そうでないなら（元）親の番号を示す

def r(x):   #親は誰？
    if root[x]==x:
        return x
    else:
        root[x]=r(root[x])
        return root[x]

def unite(x,y):
    x=r(x)
    y=r(y)
    if x==y:
        return
    if x>y:
        x,y=y,x
    root[y]=x

for i in range(m):
    x,y,z=map(int,input().split())
    unite(x,y)

ans=0
for i in range(1,n+1):
    if root[i]==i:
        ans+=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
v=list(map(int,input().split()))
c=list(map(int,input().split()))
ans=[]
for i in range(2**n):
    x=0
    y=0
    for j in range(n):
        if (i>>j)&1:
            x+=v[j]
            y+=c[j]
    ans.append(x-y)
print(max(ans))


Fixed submission:
n=int(input())
v=list(map(int,input().split()))
c=list(map(int,input().split()))
ans=[]
for i in range(2**n):
    x=0
    y=0
    for j in range(n):
        if (i>>j)&1:
            x+=v[j]
            y+=c[j]
    ans.append(x-y)
print(max(ans))
Buggy python submission (verdict: Runtime Error):
n=int(input())
h=list(map(int,input().split()))
if n==1:
    print(h[0])
elif n==2:
    print(max(h))
else:
    h.append(0)
    h.insert(0,0)
    
    ans=0
    f=[0 for i in range(n+2)]
    
    for i in range(10010):
        a=1
        x=[]
        for j in range(n+2):
            if h[j]<=f[j]:
                x.append(j)
        m=len(x)
        if m==n+2:
            break
        a=m-1
        for j in range(m-1):
            if x[j]+1==x[j+1]:
                a-=1
        ans+=a
        for j in range(n+2):
            f[j]+=1
        
print(ans)
            
            
            
            
        
    
        
        
        
          


Fixed submission:
n=int(input())
h=list(map(int,input().split()))
if n==1:
    print(h[0])
elif n==2:
    print(max(h))
else:
    h.append(0)
    h.insert(0,0)
    
    ans=0
    f=[0 for i in range(n+2)]
    
    for i in range(10010):
        a=1
        x=[]
        for j in range(n+2):
            if h[j]<=f[j]:
                x.append(j)
        m=len(x)
        if m==n+2:
            break
        a=m-1
        for j in range(m-1):
            if x[j]+1==x[j+1]:
                a-=1
        ans+=a
        for j in range(n+2):
            f[j]+=1
        
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
ken=[[] for i in range(n+1)]
inf=[[] for i in range(m)]
def f(x):
    m=0
    while x>0:
        m+=1
        x=x//10
    return m

for i in range(m):
    p,y=map(int,input().split())
    inf[i].append(p)
    inf[i].append(y)
    ken[p].append(y)

for i in range(n):
    ken[i+1]=sorted(ken[i+1])
for i in range(m):
    ans=""
    p=inf[i][0]
    y=inf[i][1]
    for j in range(6-f(p)):
        ans+="0"
    ans=ans+str(p)
    x=ken[p].index(y)+1
    for j in range(6-f(x)):
        ans=ans+"0"
    ans=ans+str(x)
    print(ans)
    
    
    
    



    
        
        
        
          


Fixed submission:
n,m=map(int,input().split())
ken=[1 for i in range(n+1)]
inf=[[] for i in range(m)]
def f(x):
    m=0
    while x>0:
        m+=1
        x=x//10
    return m

for i in range(m):
    p,y=map(int,input().split())
    inf[i].append(i+1)
    inf[i].append(p)
    inf[i].append(y)
inf=sorted(inf, key=lambda x: x[2])

for i in range(m):
    inf[i].append(ken[inf[i][1]])
    ken[inf[i][1]]+=1
inf=sorted(inf)


for i in range(m):
    ans=""
    p=inf[i][1]
    y=inf[i][3]
    for j in range(6-f(p)):
        ans+="0"
    ans=ans+str(p)
    
    for j in range(6-f(y)):
        ans=ans+"0"
    ans=ans+str(y)
    print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
red=[[] for i in range(n)]
blue=[[] for i in range(n)]
for i in range(n):
    a,b=map(int,input().split())
    red[i].append(a)
    red[i].append(b)
for i in range(n):
    a,b=map(int,input().split())
    blue[i].append(a)
    blue[i].append(b)
red=sorted(red)
blue=sorted(blue)
ans=0
for i in range(n):
    x=blue[i][0]
    y=blue[i][1]
    maxy=-1
    for j in range(n):
        if x>red[j][0] and y>red[j][1]:
            maxy=max(maxy,red[j][1])
    for j in range(n):
        if x>red[j][0] and maxy==red[j][1]:
            ans+=1
            red[j][0]=1000
            break
print(ans)


Fixed submission:
a,b,c=map(int,input().split())
print("Yes" if a+b>=c else "No")
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import permutations as per
s=list(input())
t=list(input())
n=len(t)
s=list(per(s))
t=list(per(t))


x=s[0]
y=t[-1]
l=[]
l.append(x)
l.append(y)
l=sorted(l)

if l.index(x)<l.index(y):
    print("Yes")
else:
    print("No")


Fixed submission:

s=list(input())
t=list(input())
s=sorted(s)
t=sorted(t)
x=s[0]
for i in range(len(s)-1):
    x=x+s[i+1]
y=t[-1]
for i in range(len(t)-1):
    y=y+t[-i-2]




l=[]
l.append(x)
l.append(y)
l=sorted(l)

if l.index(x)<l.index(y):
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import permutations as per
s=list(input())
t=list(input())
n=len(t)
s=list(per(s))
t=list(per(t))

def f(x):
    m=1
    while x>0:
        m*=x
        x=x-1
    return m
x=s[0]
y=t[f(n)-1]
l=s+t
l=sorted(l)
if l.index(x)<l.index(y):
    print("Yes")
else:
    print("No")


Fixed submission:

s=list(input())
t=list(input())
s=sorted(s)
t=sorted(t)
x=s[0]
for i in range(len(s)-1):
    x=x+s[i+1]
y=t[-1]
for i in range(len(t)-1):
    y=y+t[-i-2]




l=[]
l.append(x)
l.append(y)
l=sorted(l)

if l.index(x)<l.index(y):
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
n=int(input())
x=[0]*(10**9+1)
ans=0
for i in range(n):
    a=int(input())
    if x[a]==0:
        x[a]=1
        ans+=1
    else:
        ans-=1
        x[a]=0
print(ans)



Fixed submission:
n=int(input())
a=[]
for i in range(n):
    a.append(int(input()))
a=sorted(a)
ans=0
cnt=1
for i in range(n-1):

    if a[i]==a[i+1]:
        cnt+=1
    else:
        if cnt%2==1:ans+=1
        cnt=1
if cnt%2==1:ans+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline()
from _collections import deque
n,m=map(int,input().split())
edg=[[] for i in range(n+1)]
for i in range(m):
    a,b=map(int,input().split())
    edg[a].append(b)
    edg[b].append(a)
dep=[-1]*(n+1)
dep[1]=0
data=deque([1])
while len(data)>0:
    p=data.popleft()
    for i in edg[p]:
        if dep[i]==-1:
            dep[i]=dep[p]+1
            data.append(i)
print("POSSIBLE" if dep[n]==2 else "IMPOSSIBLE")



Fixed submission:
from _collections import deque
n,m=map(int,input().split())
edg=[[] for i in range(n+1)]
for i in range(m):
    a,b=map(int,input().split())
    edg[a].append(b)
    edg[b].append(a)
dep=[-1]*(n+1)
dep[1]=0
data=deque([1])
while len(data)>0:
    p=data.popleft()
    for i in edg[p]:
        if dep[i]==-1:
            dep[i]=dep[p]+1
            data.append(i)
print("POSSIBLE" if dep[n]==2 else "IMPOSSIBLE")

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
edg=[[0]*(n+1) for i in range(n+1)]
for i in range(m):
    a,b=map(int,input().split())
    edg[a][b]=1
    edg[b][a]=1
f=1
for i in range(2,n+1):
    if edg[i][1]==1 and edg[i][n]==1:
        f=0
print("POSSIBLE" if f==0 else "IMPOSSIBLE")


Fixed submission:
from _collections import deque
n,m=map(int,input().split())
edg=[[] for i in range(n+1)]
for i in range(m):
    a,b=map(int,input().split())
    edg[a].append(b)
    edg[b].append(a)
dep=[-1]*(n+1)
dep[1]=0
data=deque([1])
while len(data)>0:
    p=data.popleft()
    for i in edg[p]:
        if dep[i]==-1:
            dep[i]=dep[p]+1
            data.append(i)
print("POSSIBLE" if dep[n]==2 else "IMPOSSIBLE")
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
b=[a[0]]
for i in range(1,n):
    b.append(b[-1]+a[i])
s=sum(a)
ans=10**20
for i in range(n-1):
    ans=min(ans,abs(sum(a)-2*b[i]))
print(ans)


Fixed submission:
n=int(input())
a=list(map(int,input().split()))
b=[a[0]]
for i in range(1,n):
    b.append(b[-1]+a[i])
s=sum(a)
ans=10**20
for i in range(n-1):
    ans=min(ans,abs(s-2*b[i]))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def factorial(n):
    f=1
    for i in range(1,n+1):
        f*=i%(10**9+7)
    return f
n,m=map(int,input().split())
N=factorial(n)
if abs(n-m)>1:
    print(0)
elif abs(n-m)==0:
    print(2*N*N%(10**9+7))
elif n>m:
    print((N*N//n)%(10**9+7))
else:
    print(N*N*m%(10**9+7))


Fixed submission:
n,m=map(int,input().split())
p=10**9+7
if abs(n-m)>=2:
    print(0)
elif n==m:
    ans=1
    for i in range(1,n+1):
        ans=(ans*i)%p
    print((2*ans*ans)%p)
else:
    ans=1
    for i in range(1,n+1):
        ans=(ans*i)%p
    for i in range(1,m+1):
        ans=(ans*i)%p
    print(ans%p)
Buggy python submission (verdict: Runtime Error):
n=int(input())
x=[[0 for i in range(26)] for j in range(n)]
for i in range(n):
    s=input()
    for j in range(len(s)):
        x[i][ord(s[j])-97]+=1
ans=[0]*26
for i in range(n):
    ans[i]=min(x[j][i] for j in range(n))
a=[]
for i in range(26):
    for j in range(ans[i]):
        a.append(chr(97+i))
print("".join(a))



Fixed submission:
n=int(input())
x=[[0 for i in range(26)] for j in range(n)]
for i in range(n):
    s=input()
    for j in range(len(s)):
        x[i][ord(s[j])-97]+=1
ans=[0]*26
for i in range(26):
    ans[i]=min(x[j][i] for j in range(n))
a=[]
for i in range(26):
    for j in range(ans[i]):
        a.append(chr(97+i))
print("".join(a))
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
road=[[] for _ in range(n+1)]
for i in range(m):
    a,b=map(int,input().split())
    road[a].append(b)
    road[b].append(a)
dp=[[0]*(n+1) for _ in range(2**n)]
dp[1][1]=1
for i in range(1,2**n):
    for j in range(1,n+1):
        for k in road[j]:
            
                dp[i+2**(k-1)][k]+=dp[i][j]
print(sum(dp[2**n-1]))



Fixed submission:
n,m=map(int,input().split())
root=[[] for _ in range(n+1)]
for i in range(m):
    a,b=map(int,input().split())
    root[a].append(b)
    root[b].append(a)
s=[0]*(n+1)
s[0]=1
s[1]=1
ans=0
def f(a,x):
    global ans
    for i in root[a]:
        if x[i]==0:
            z=[x[j] for j in range(n+1)]
            z[i]=1
            f(i,z)
    if x.count(1)==n+1:
        ans+=1
f(1,s)
print(ans)
Buggy python submission (verdict: Runtime Error):
n,a=map(int,input().split())

x=list(map(int,input().split()))
A=max(x)
x.insert(0,-1)
dp=[[[0]*(n+1) for _ in range(n*A+1)] for i in range(n+1)]
dp[1][x[1]][1]=1
dp[1][0][0]=1
for i in range(1,n):
    q=x[i+1]
    for s in range(n*A+1):
        for k in range(i+1):
            if s+q<=n*A:
                dp[i+1][s+q][k+1]+=dp[i][s][k]
            dp[i+1][s][k]+=dp[i][s][k]

ans=0
i=1

while i<=n:
    ans+=dp[n][a*(i)][i]
    i+=1
print(ans)




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

x=list(map(int,input().split()))
A=max(x)
x.insert(0,-1)
dp=[[[0]*(n+1) for _ in range(n*A+1)] for i in range(n+1)]
dp[1][x[1]][1]=1
dp[1][0][0]=1
for i in range(1,n):
    q=x[i+1]
    for s in range(n*A+1):
        for k in range(i+1):
            if s+q<=n*A:
                dp[i+1][s+q][k+1]+=dp[i][s][k]
            dp[i+1][s][k]+=dp[i][s][k]

ans=0
i=1

while i<=n and a*i<=n*A:
    ans+=dp[n][a*(i)][i]
    i+=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,X,M=map(int,input().split())
A=[X]
A1=X
ans=0
for i in range(1,N):
    if 2*A1>M:
        A2=((M-A1)**2)%M
    else:
        A2=(A1**2)%M
    if A2 in A:
        num=A.index(A2)
        loop=i-num
        loop_A=A[num::]
        loop_val=sum(loop_A)
        rest=N-i
        x=rest%loop
        for _ in range(x):
            ans+=A[num]
            num+=1
        ans=ans+(rest//loop)*loop_val
        break
    else:
       A1=A2 
       A.append(A2)

print(sum(A)+ans)

Fixed submission:
N,X,M=map(int,input().split())
A=[X]
A1=X
ans=0
for i in range(1,N):
    if 2*A1>M:
        A2=((M-A1)**2)%M
    else:
        A2=(A1**2)%M
    if A2 in A:
        num=A.index(A2)
        loop=i-num
        loop_A=A[num::]
        loop_val=sum(loop_A)
        rest=N-i
        x=rest%loop
        for _ in range(x):
            ans+=A[num]
            num+=1
        ans=ans+(rest//loop)*loop_val
        break
    else:
       A1=A2 
       A.append(A2)

print(sum(A)+ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,X,M=map(int,input().split())
A=[X]
A1=X
ans=0
for i in range(1,N):
    if 2*A1>M:
        A2=((M-A1)**2)%M
    else:
        A2=(A1**2)%M
    if A2 in A:
        num=A.index(A2)
        loop=i-num
        loop_A=A[num::]
        loop_val=sum(loop_A)
        rest=N-i
        x=rest%loop
        for _ in range(x):
            ans+=A[num]
            num+=1
        ans=ans+(rest//loop)*loop_val
        break
    else:
       A1=A2 
       A.append(A2)

print(sum(A)+ans)

Fixed submission:
N,X,M=map(int,input().split())
A=[X]
A1=X
ans=0
for i in range(1,N):
    if 2*A1>M:
        A2=((M-A1)**2)%M
    else:
        A2=(A1**2)%M
    if A2 in A:
        num=A.index(A2)
        loop=i-num
        loop_A=A[num::]
        loop_val=sum(loop_A)
        rest=N-i
        x=rest%loop
        for _ in range(x):
            ans+=A[num]
            num+=1
        ans=ans+(rest//loop)*loop_val
        break
    else:
       A1=A2 
       A.append(A2)

print(sum(A)+ans)
Buggy python submission (verdict: Time Limit Exceeded):
K=int(input())

j=0
ans=0
a=0
while True:
    a=a*10+7
    ans+=1
    if a%K==0:
        break
    
    if ans>K:
        ans=-1
        break

print(ans)

Fixed submission:
K=int(input())
 
j=0
ans=0
a=0
while True:
    a=a*10+7
    a=a%K
    ans+=1
    
    if a==0:
        break
    
    if ans>K:
        ans=-1
        break
 
print(ans)
Buggy python submission (verdict: Runtime Error):
N=int(input())
c=list(input())
c1=c[::-1]
ans=0

w_index=[i for i, x in enumerate(c) if x=="W"]
r_index=[i for i, x in enumerate(c1) if x=="R"]

for i in range(len(r_index)):
    r_index[i]=N-1-r_index[i]


if "R" in c and "W" in c:
    while True:
        w=int(w_index[ans])
        r=int(r_index[ans])
        if w-r==1:
             break
        ans+=1

print(ans)

Fixed submission:
N=int(input())
c=list(input())
c1=c[::-1]
ans=0

w_index=[i for i, x in enumerate(c) if x=="W"]
r_index=[i for i, x in enumerate(c1) if x=="R"]

for i in range(len(r_index)):
    r_index[i]=N-1-r_index[i]


if "R" in c and "W" in c:
    for i in range(min(len(r_index),len(w_index))):
        w=w_index[ans]
        r=r_index[ans]
        if w-r>0:
             break
        ans+=1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
c=list(input())
ans=0

if "R" in c and "W" in c:
    while True:
        c1=c[::-1]
        w_index=int(c.index("W"))
        r_index=int(N-1-c1.index("R"))
        if w_index-r_index==1:
             break
        ans+=1
        c[w_index]="R"
        c[r_index]="W"

print(ans)

Fixed submission:
N=int(input())
c=list(input())
c1=c[::-1]
ans=0

w_index=[i for i, x in enumerate(c) if x=="W"]
r_index=[i for i, x in enumerate(c1) if x=="R"]

for i in range(len(r_index)):
    r_index[i]=N-1-r_index[i]


if "R" in c and "W" in c:
    for i in range(min(len(r_index),len(w_index))):
        w=w_index[ans]
        r=r_index[ans]
        if w-r>0:
             break
        ans+=1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
c=list(input())
ans=0

if "R" in c and "W" in c:
    while True:
        c1=c[::-1]
        w_index=int(c.index("W"))
        r_index=int(N-1-c1.index("R"))
        if w_index-r_index==1:
             break
        ans+=1
        c[w_index]="R"
        c[r_index]="W"

print(ans)

Fixed submission:
N=int(input())
c=list(input())
c1=c[::-1]
ans=0

w_index=[i for i, x in enumerate(c) if x=="W"]
r_index=[i for i, x in enumerate(c1) if x=="R"]

for i in range(len(r_index)):
    r_index[i]=N-1-r_index[i]


if "R" in c and "W" in c:
    for i in range(min(len(r_index),len(w_index))):
        w=w_index[ans]
        r=r_index[ans]
        if w-r>0:
             break
        ans+=1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S=list(input())

i=0
N1=N #配列長さ
while i<=N1-2:
    if S[i]==S[i+1]:
        for k in range(i+2,N):
            S[k-1]=S[k]
        N1=N1-1
    else:
        i=i+1
print(N1)

Fixed submission:
N=int(input())
S=list(input())

a=0#色変化
for i in range(N-1):
    if not S[i]==S[i+1]:
        a=a+1
print(a+1)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S=list(input())

i=0
N1=N #配列長さ
while i<=N1-2:
    if S[i]==S[i+1]:
        for k in range(i+2,N):
            S[k-1]=S[k]
        N1=N1-1
    else:
        i=i+1
print(N1)

Fixed submission:
N=int(input())
S=list(input())

a=0#色変化
for i in range(N-1):
    if not S[i]==S[i+1]:
        a=a+1
print(a+1)
Buggy python submission (verdict: Runtime Error):
import bisect

N=int(input())
L=list(map(int,input().split()))

L=sorted(L)

ans=0
for i in range(N-1):
    for k in range(i+1,N-1):
        a=L[i]+L[k]
        b=bisect.bisect_left(L,a)
        ans=ans+(b-k-1)

print(ans)

Fixed submission:
import bisect

N=int(input())
L=list(map(int,input().split()))

L=sorted(L)

ans=0
for i in range(N-1):
    for k in range(i+1,N-1):
        a=L[i]+L[k]
        b=bisect.bisect_left(L,a)
        ans=ans+(b-k-1)

print(ans)

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

a=0
for i in range(N-1):
    for k in range(1,N-i-1):
        a=a+sum(x<L[i]+L[i+k] for x in L[i+k+1:N])

print(a)

Fixed submission:
import bisect

N=int(input())
L=list(map(int,input().split()))

L=sorted(L)

ans=0
for i in range(N-1):
    for k in range(i+1,N-1):
        a=L[i]+L[k]
        b=bisect.bisect_left(L,a)
        ans=ans+(b-k-1)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
L=list(map(int,input().split()))
L=sorted(L)

a=0
for i in range(N-1):
    for k in range(1,N-i-1):
        a=a+sum(x<L[i]+L[i+k] for x in L[i+k+1:N])

print(a)

Fixed submission:
import bisect

N=int(input())
L=list(map(int,input().split()))

L=sorted(L)

ans=0
for i in range(N-1):
    for k in range(i+1,N-1):
        a=L[i]+L[k]
        b=bisect.bisect_left(L,a)
        ans=ans+(b-k-1)

print(ans)
Buggy python submission (verdict: Runtime Error):
def count(x,y):
    return abs((x-y)/2)

N,A,B=map(int,input().split())


if (A-B)%2==0:
    ans=count(A,B)

else:
    
    if (A-1)<(N-B):
        ans=A
        A=1
        B=B-ans
    else:
        ans=N-B+1
        A=A+ans
        B=N
    
    ans+=count(A,B)

print(int(ans))

Fixed submission:
s=input()
k=int(input())

ans=1
for i in range(min(len(s),k)):
    if int(s[i])!=1:
        ans=s[i]
        break

print(ans)

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

s0=int(s[0])
if s0==1:
    print(s[1])
else:
    print(s0)

Fixed submission:
s=input()
k=int(input())

ans=1
for i in range(min(len(s),k)):
    if int(s[i])!=1:
        ans=s[i]
        break

print(ans)
Buggy python submission (verdict: Runtime Error):
H,W=map(int,input().split())

xy=((-1,0),(-1,0),(1,0),(0,1))
S=[]
S.append("."*(W+2))
for i in range(H):
    S.append("."+input()+".")

S.append("."*(W+2))

for i in range(1,H+1):
    for j in range(1,W+1):
        if S[i][j]==".":
            continue
        ans=False
        for x,y in xy:
            if S[i+x][j+y]=="#":
                ans=True
                break

if ans==True:
    print("Yes")
else:
    print("No")

Fixed submission:
import numpy as np

H,W=map(int,input().split())

s=np.zeros((H+2,W+2),dtype=int)

for i in range(H):
    s0=input()
    for j in range(W):
        if s0[j]==".":
            num=0
        elif s0[j]=="#":
            num=1
        
        s[i+1][j+1]=num
        

ans_s=s[1:H+1,1:W+1]

ans=0
for k in range(1,H+1):
    for l in range(1,W+1):
        if s[k][l]==1:
            if s[k-1][l]==0 and s[k+1][l]==0 and s[k][l-1]==0 and s[k][l+1]==0:
                ans=1
                break

if ans==1:
    print("No")
else:
    print("Yes")
Buggy python submission (verdict: Time Limit Exceeded):
import sys

N=int(input())
a=list(map(int,input().split()))

max_a=max(a)
min_a=min(a)
a0=a.count(min_a)
a1=a.count(min_a+1)
ans=1
for i in range(min_a+1,max_a):
    a2=a.count(i+1)
    ans=max(ans,(a0+a1+a2))
    a0=a1
    a1=a2
    if i ==max_a-1:
        print(ans)
        sys.exit()

print(N)

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

nums=[0]*(10**5+1)
for i in a:
    nums[i]+=1

ans0=nums[0]+nums[1]+nums[2]
ans=ans0
for i in range(2,10**5-1):
    ans1=ans0-nums[i-2]+nums[i+1]
    ans=max(ans,ans1)
    ans0=ans1

print(ans)