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

Fixed submission:
n=int(input())
a=[0]+[int(x) for x in input().split()]
b=[0]*(n+1)
 
for s in range(n,0,-1):
    i=s
    t=0
    while i<=n:
        t += b[i]
        i += s
    if a[s]!=t%2:
        b[s]=1
print(b.count(1))
for i in range(1,n+1):
    if b[i]==1:
        print(i)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=[0]+[int(x) for x in input().split()]
b=[0]*(n+1)
 
for s in range(n,0,-1):
    i=s
    t=0
    while i<=n:
        t += b[i]
        i += s
    if a[s]!=t%2:
        b[s]=1
print(b.count(1))
for i in range(n+1):
    if b[i+1]==1:
        print(i+1)
Problem p02981 (python)

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

Buggy submission (verdict: Runtime Error):
n,a,b=map(int,input().split()
print(n*min(a,b))

Buggy submission (verdict: Runtime Error):
n,a,b=map(int,input())
print(n*min(a,b))
Problem p02985 (python)

Fixed submission:
def bfs(k):
    p=k
    level={1:1}
    frontier=[1]
    while frontier:
        next=[]
        for u in frontier:
            if u==1:
                l=k-1
            else:
                l=k-2
            i=0
            for v in adj[u]:
                if v not in level:
                    level[v]=1
                    p=(p*(l-i))%(10**9+7)
                    i+=1
                    next.append(v)
        frontier=next
    return p
n,k=map(int,input().split())
adj={}
for i in range(n-1):
    a,b=map(int,input().split())
    if a not in adj:
        adj[a]=[b]
    else:
        adj[a].append(b)
    if b not in adj:
        adj[b]=[a]
    else:
        adj[b].append(a)
if n==1:
  print(k)
else:
  print(bfs(k))

Buggy submission (verdict: Runtime Error):
def bfs(k):
    p=k
    frontier=[1]
    visited={1:1}
    while frontier:
        next=[]
        for u in frontier:
            if u==1:
                l=k-1
            else:
                l=k-2
            i=0
            if u in adj:
            	for v in adj[u]:
                	if v not in visited:
                    	visited[v]=1
                    	p=(p*(l-i))%(10**9+7)
                    	i+=1
                    	next.append(v)
        frontier=next
    return p
  
n,k=map(int,input().split())
adj={}
for w in range(n-1):
    a,b=map(int,input().split())
    if a not in adj:
        adj[a]=[b]
    else:
        adj[a].append(b)
    if b not in adj:
        adj[b]=[a]
    else:
        adj[b].append(a)
print(bfs(k))

Buggy submission (verdict: Runtime Error):
def bfs(k):
    p=k
    frontier=[1]
    visited={1:1}
    while frontier:
        next=[]
        for u in frontier:
            if u==1:
                l=k-1
            else:
                l=k-2
            i=0
            for v in adj[u]:
                if v not in visited:
                    visited[v]=1
                    p=(p*(l-i))%(10**9+7)
                    i+=1
                    next.append(v)
        frontier=next
    return p
  
n,k=map(int,input().split())
adj={}
for w in range(n-1):
    a,b=map(int,input().split())
    if a not in adj:
        adj[a]=[b]
    else:
        adj[a].append(b)
    if b not in adj:
        adj[b]=[a]
    else:
        adj[b].append(a)
print(bfs(k))

Buggy submission (verdict: Runtime Error):
def bfs(k):
    p=k
    level={1:1}
    frontier=[1]
    while frontier:
        next=[]
        for u in frontier:
            if u==1:
                l=k-1
            else:
                l=k-2
            i=0
            for v in adj[u]:
                if v not in level:
                    level[v]=1
                    p=(p*(l-i))%(10**9+7)
                    i+=1
                    next.append(v)
        frontier=next
    return p
n,k=map(int,input().split())
adj={}
for i in range(n-1):
    a,b=map(int,input().split())
    if a not in adj:
        adj[a]=[b]
    else:
        adj[a].append(b)
    if b not in adj:
        adj[b]=[a]
    else:
        adj[b].append(a)
print(bfs(k))
Problem p03043 (python)

Fixed submission:
from math import log
n,k=map(int,input().split())
if n<k:
    p=0
    for i in range(1,n+1):
        po=int(log(k/i,2))
        if i*(2**po)!=k:
            po+=1
        p+=(1/n)*((1/2)**po)
    print(p)
else:
    p=(n-k+1)/n
    for i in range(1,k):
        po=int(log(k/i,2))
        if i*(2**po)!=k:
            po+=1
        p+=(1/n)*((1/2)**po)
    print(p)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
if n<k:
    p=0
    for i in range(1,n+1):
        po=int(log(k/i,2))
        if i*(2**po)!=k:
            po+=1
        p+=(1/n)*((1/2)**po)
    print(p)
else:
    p=(n-k+1)/n
    for i in range(1,k):
        po=int(log(k/i,2))
        if i*(2**po)!=k:
            po+=1
        p+=(1/n)*((1/2)**po)
    print(p)
Problem p03044 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
def dfs(s):
    visited[s]=1
    for v in adj[s]:
        if v not in visited:
            if (s,v) in we:
                y[v]=y[s]+we[(s,v)]
            elif (v,s) in we:
                y[v]=y[s]+we[(v,s)]
            dfs(v)
n=int(input())
adj={}
we={}
visited={}
y=[0]*(n+1)
for q in range(n-1):
    a,b,w=map(int,input().split())
    if a not in adj:
        adj[a]=[b]
    else:
        adj[a].append(b)
    if b not in adj:
        adj[b]=[a]
    else:
        adj[b].append(a)
    we[(a,b)]=w
if n>1:
	dfs(1)
for i in range(1,n+1):
    if y[i]%2==0:
        print(0)
    else:
        print(1)

Buggy submission (verdict: Runtime Error):
def dfs(s):
    visited[s]=1
    for v in adj[s]:
        if v not in visited:
            if (s,v) in we:
                y[v]=y[s]+we[(s,v)]
            elif (v,s) in we:
                y[v]=y[s]+we[(v,s)]
            dfs(v)
n=int(input())
adj={}
we={}
visited={}
y=[0]*(n+1)
for q in range(n-1):
    a,b,w=map(int,input().split())
    if a not in adj:
        adj[a]=[b]
    else:
        adj[a].append(b)
    if b not in adj:
        adj[b]=[a]
    else:
        adj[b].append(a)
    we[(a,b)]=w
if n>1:
	dfs(1)
for i in range(1,n+1):
    if y[i]%2==0:
        print(0)
    else:
        print(1)

Buggy submission (verdict: Runtime Error):
def dfs(s):
    visited[s]=1
    for v in adj[s]:
        if v not in visited:
            if (s,v) in we:
                y[v]=y[s]+we[(s,v)]
            elif (v,s) in we:
                y[v]=y[s]+we[(v,s)]
            dfs(v)
n=int(input())
adj={}
we={}
visited={}
y=[0]*(n+1)
for q in range(n-1):
    a,b,w=map(int,input().split())
    if a not in adj:
        adj[a]=[b]
    else:
        adj[a].append(b)
    if b not in adj:
        adj[b]=[a]
    else:
        adj[b].append(a)
    we[(a,b)]=w
dfs(1)
for i in range(1,n+1):
    if y[1]%2==0:
        print(0)
    else:
        print(1)
Problem p03160 (python)

Fixed submission:
def rec(a):
    dp=[0]*len(a)
    for i in range(len(a)):
        if i==0:
            dp[i]=0
        elif i==1:
            dp[i]=abs(a[i]-a[i-1])
        else:
            dp[i]=min(abs(a[i]-a[i-1])+dp[i-1],abs(a[i]-a[i-2])+dp[i-2])
    return dp[len(a)-1]
n=int(input())
a=[int(i) for i in input().split()]
print(rec(a))

Buggy submission (verdict: Runtime Error):
/* Author - thiolhub */

#include <bits/stdc++.h>

using namespace std;

#define ll              long long int
#define ld              long double
#define db              double
#define pi              3.1415926535897932384626
#define PI              acos(-1.0)
#define endl            "\n"
#define mod             1000000007
#define mk              make_pair
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(t)            ll t; cin>>t; while(t--)
#define sc(a)	        scanf("%lld",&a);
#define pr(a)	        printf("%lld\n",a)
#define f(i,a,n)		for(ll i=a;i<n;i++)
#define m(a)		    memset(a,0,sizeof(a))
#define FastIO          ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)



int main(){ FastIO;

int n,i,j,k;cin>>n;
int a[n]; for(i=0;i<n;i++) cin>>a[i];
int dp[n+1];
for(i=0;i<n;i++) dp[i]=INT_MAX;
dp[0]=0;
for(i=0;i<n-1;i++)
{
	dp[i+1]=min(abs(a[i+1]-a[i])+dp[i],dp[i+1]);
	dp[i+2]=min(abs(a[i+2]-a[i])+dp[i],dp[i+2]);
}
cout<<dp[n-1];

return 0;
}

Buggy submission (verdict: Runtime Error):
inf=10**10
def rec(n):
    if dp[n-1]!=inf:
        return dp[n-1]
    if n==1:
        dp[n-1]=0
        return dp[n-1]
    elif n==2:
        dp[n-1]=abs(a[n-1]-a[n-2])+rec(n-1)
        return dp[n-1]
    else:
        dp[n-1]=min(abs(a[n-1]-a[n-2])+rec(n-1),abs(a[n-1]-a[n-3])+rec(n-2))
        return dp[n-1]
           
n=int(input())
a=[int(i) for i in input().split()]
dp=[inf]*len(a)
print(rec(len(a)))

Buggy submission (verdict: Runtime Error):
from math import inf
def rec(n):
    if dp[n-1]!=inf:
        return dp[n-1]
    if n==1:
        dp[n-1]=0
        return dp[n-1]
    if n<1:
        return inf
    if n==2:
        dp[n-1]=abs(a[n-1]-a[n-2])+rec(n-1)
        return dp[n-1]
    else:
        dp[n-1]=min(abs(a[n-1]-a[n-2])+rec(n-1),abs(a[n-1]-a[n-3])+rec(n-2))
        return dp[n-1]
           
n=int(input())
a=[int(i) for i in input().split()]
dp=[inf]*len(a)
print(rec(len(a)))
Problem p03294 (python)

Fixed submission:
def lcm(a,b):
    return a*b//(gcd(a,b))
def gcd(a,b):
    if b==0:
        return a
    else:
        return gcd(b,a%b)

n=int(input())
a=[int(i) for i in input().split()]
l=1
for i in range(n):
    l=lcm(a[i],l)
s=0
l-=1
for i in range(n):
    s+=l%a[i]
print(s)

Buggy submission (verdict: Runtime Error):
def gcd(a,b):
    if b==0:
        return a
    return gcd(b,a%b)

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

n=int(input())
a=[int(i) for i in input().split()]
l=1
for i in range(n):
    l=lcm(l,a[i])
s=0
l-=1
for i in range(n):
    s+=(l%a[i])
print(int(s))

Buggy submission (verdict: Runtime Error):
n=int(input())
a=[int(i) for i in input().split()]
l=1
for i in range(n):
    l=lcm(a[i],l)
s=0
l-=1
for i in range(n):
    s+=l%a[i]
print(s)
Problem p02789 (python)

Fixed submission:
n, m = list(map(int, input().split()))
print('Yes') if n == m else print('No')

Buggy submission (verdict: Runtime Error):
n, m = list(map(int, input().split()))
print('Yes') if n == M else print('No')
Problem p03125 (python)

Fixed submission:
a, b = [int(x) for x in input().split()]
print([a + b, b - a][int(bool(b % a))])

Buggy submission (verdict: Runtime Error):
a, b = [int(x) for x in input().split()]
print([a + b, b - a][int(b % a)])
Problem p03160 (python)

Fixed submission:
n = int(input())
h = list(map(int, input().split()))
dp = [float('inf')] * n
dp[0] = 0

for i in range(n - 1):
    if i <= n - 3:
        dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]))
        dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]))
    elif i == n - 2:
        dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]))

print(dp[-1])

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

dp = [0, abs(h[1]-[0])]

for i in range(2,n):
    dp.append(min(dp[i-1] + abs(h[i]-h[i+1]), dp[i] + abs(h[i]-h[i+2])))
    
print(dp[-1])
Problem p03323 (python)

Fixed submission:
a, b = map(int, input().split())
print([':(', 'Yay!'][int((a <= 8) & (b <= 8))])

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())
print([':(', 'Yay!'][int((a <= 16) & (b <= 8)])
Problem p02882 (python)

Fixed submission:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from math import degrees, atan

a, b, x = li()
c = x / (a*a)

if x == a*a*b:
    print(0)
elif a * c > (a * b) / 2:
    print(90 - degrees(atan((a / (2*(b-c))))))
else:
    print(90 - degrees(atan(2*a*c / (b**2))))

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

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from math import degrees, atan

a, b, x = li()
c = x / (a*a)

if a * c > (a * b) / 2:
    print(90 - degrees(atan((a / (2*(b-c))))))
else:
    print(90 - degrees(atan(2*a*c / (b**2))))
Problem p02941 (python)

Fixed submission:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


from heapq import heappush, heappop

n = ni()
a = list(li())
b = list(li())

# n = 10**5
# a = [1]*(10**5)
# b = [5] + [1]*(10**5-2) + [7]

que = []

for i, bi in enumerate(b):
    heappush(que, (-bi, i))

ans = 0
while que:

    cur, position = heappop(que)
    cur = -cur

    if cur - b[(position-1)%n] - b[(position+1)%n] < a[position]:
        continue

    ope = (cur - a[position]) // (b[(position-1)%n] + b[(position+1)%n])

    ans += ope
    b[position] -= ope * (b[(position-1)%n] + b[(position+1)%n])
    heappush(que, (-b[position], position))

ok = True
for ai, bi in zip(a, b):
    if ai != bi:
        ok = False

if ok:
    print(ans)
else:
    print(-1)

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

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


from heapq import heappush, heappop

n = ni()
a = list(li())
b = list(li())

que = []

for i, bi in enumerate(b):
    heappush(que, (-bi, i))

ans = 0
while que:
    cur, position = heappop(que)
    cur = -cur

    if cur - b[(position-1)%n] - b[(position+1)%n] < a[position]:
        continue

    ope = cur // (b[(position-1)%n] + b[(position+1)%n])
    ans += ope
    b[position] -= ope * (b[(position-1)%n] + b[(position+1)%n])
    heappush(que, (-b[position], position))

ok = True
for ai, bi in zip(a, b):
    if ai != bi:
        ok = False

if ok:
    print(ans)
else:
    print(-1)
Problem p02957 (python)

Fixed submission:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

a, b = li()

print((a+b) // 2 if (a+b) % 2 == 0 else "IMPOSSIBLE")

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

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

a, b = li()

print((a+b) // 2 if (a+b) % 2 == 0 else "IMPOSSIBLE"
Problem p02997 (python)

Fixed submission:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n, k = li()

if k > (n-1) * (n-2) // 2:
    print(-1)

else:
    edges = []
    for i in range(1,n):
        edges.append((1, i+1))

    surp = (n-1)*(n-2) // 2 - k
    for frm in range(1, n):
        for to in range(frm+1, n):
            if surp == 0:
                break

            edges.append((frm+1, to+1))
            surp -= 1


    print(len(edges))
    for ei, ej in edges:
        print(ei, ej)

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

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n, k = li()

if k > (n-1) * (n-2):
    print(-1)

else:
    edges = []
    for i in range(1,n):
        edges.append((1, i+1))

    surp = (n-1)*(n-2) // 2 - k
    for frm in range(1, n):
        for to in range(frm+1, n):
            if surp == 0:
                break

            edges.append((frm+1, to+1))
            surp -= 1


print(len(edges))
for ei, ej in edges:
    print(ei, ej)
Problem p03014 (python)

Fixed submission:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


h, w = li()
grid = [lc() for _ in range(h)]


lr = [[0]*w for _ in range(h)]
tb = [[0]*w for _ in range(h)]

for row in range(h):
    for col in range(w):
        if col == 0:
            lr[row][col] = 1 if grid[row][col] == "." else 0

        else:
            if grid[row][col] == "#":
                continue

            else:
                lr[row][col] = lr[row][col-1] + 1

for row in range(h):
    for col in range(w-2, -1, -1):
        if lr[row][col] == 0:
            continue
        else:
            lr[row][col] = max(lr[row][col+1], lr[row][col])

for col in range(w):
    for row in range(h):
        if row == 0:
            tb[row][col] = 1 if grid[row][col] == "." else 0

        else:
            if grid[row][col] == "#":
                continue
            else:
                tb[row][col] = tb[row-1][col] + 1

for col in range(w):
    for row in range(h-2, -1, -1):
        if tb[row][col] == 0:
            continue
        else:
            tb[row][col] = max(tb[row+1][col], tb[row][col])

ans = 0
for row in range(h):
    for col in range(w):
        ans = max(ans, lr[row][col] + tb[row][col])

print(max(0, ans-1))

Buggy submission (verdict: Runtime Error):
h, w = li()
grid = [lc() for _ in range(h)]

def left_right(grid, row, col, cnt, w):
    if col == w:
        return cnt

    elif grid[row][col] == "#":
        return cnt

    else:
        cnt = left_right(grid, row, col+1, cnt+1, w)

    lr[row][col] = cnt
    return cnt


def top_bottom(grid, row, col, cnt, h):
    if row == h:
        return cnt

    elif grid[row][col] == "#":
        return cnt

    else:
        cnt = top_bottom(grid, row+1, col, cnt+1, h)

    tb[row][col] = cnt
    return cnt

lr = [[0]*w for _ in range(h)]
tb = [[0]*w for _ in range(h)]

for row in range(h):
    for col in range(w):
        if grid[row][col] == "." and lr[row][col] == 0:
            left_right(grid, row, col, 0, w)

for col in range(w):
    for row in range(h):
        if grid[row][col] == "." and tb[row][col] == 0:
            top_bottom(grid, row, col, 0, h)

ans = 0
for row in range(h):
    for col in range(w):
        ans = max(ans, lr[row][col] + tb[row][col])

print(ans-1)
Problem p03081 (python)

Fixed submission:
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

# シミュレーション関数
def to_end(num, board, query, goal):
    for (qs, qd) in query:
        if qs == board[num]:
            if qd == 'L':
                num -= 1
            elif qd == 'R':
                num += 1
                
            if num == goal:
                return True
            
    return False


# 左へ二分探索
def find_rightest_left(board, query):
    left = 0
    right = len(board)-1
    
    while right-left > 1:
        mid = (left+right) // 2
        if to_end(mid, board, query, 0):
            left = mid
        else:
            right = mid
            
    return left
            
# 右へ二分探索
def find_leftest_right(board, query):
    R = len(board)-1
    left = 0
    right = R
    
    while right-left > 1:
        mid = (left+right) // 2
        if to_end(mid, board, query, R):
            right = mid
        else:
            left = mid
            
    return R - right
    
n,q = li()
board = "0" + ns() + "0"
query = [tuple(ls()) for _ in range(q)]

rightest_left = find_rightest_left(board, query)
leftest_right = find_leftest_right(board, query)

print(max(n - rightest_left - leftest_right, 0))

Buggy submission (verdict: Runtime Error):
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

idx = {chr(i): [] for i in range(65, 92)}

n,q = li()
s = ns()


from_left = [(si, 'L') for si in s]
from_right = [(si, 'R') for si in s[::-1]]

query = [tuple(ls()) for _ in range(q)]

left_cur = 0
right_cur = 0

for qi in query[::-1]:
    if qi == from_left[left_cur]:
        left_cur += 1
        
    if qi == from_right[right_cur]:
        right_cur += 1
        
print(max(n - (left_cur + right_cur), 0))
Problem p03086 (python)

Fixed submission:
s = input()
atcg = set(["A", "T", "C", "G"])

ans = 0
tmp = 0
for si in s:
  if si in atcg:
    tmp += 1
  else:
    ans = max(ans, tmp)
    tmp = 0
    
ans = max(ans, tmp)
print(ans)

Buggy submission (verdict: Runtime Error):
s = ns()
atcg = set(["A", "T", "C", "G"])

ans = 0
tmp = 0
for si in s:
  if si in atcg:
    tmp += 1
  else:
    ans = max(ans, tmp)
    tmp = 0
    
ans = max(ans, tmp)
print(ans)

Buggy submission (verdict: Runtime Error):
s = ns()
atcg = "ATCG"

ans = 0
tmp = 0
for si in s:
  if si in atcg:
    tmp += 1
  else:
    ans = max(ans, tmp)
    tmp = 0
    
ans = max(ans, tmp)
print(ans)