Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
x=list(input())
s=0
t=0
ans=0
for i in range(len(x)):
    if x[i]="S":
        s+=1

    else:
        if s==0:
            ans+=1
        else:
            s-=1

print(ans+s)

Fixed submission:
x=list(input())
s=0
t=0
ans=0
for i in range(len(x)):
    if x[i]=="S":
        s+=1

    else:
        if s==0:
            ans+=1
        else:
            s-=1

print(ans+s)

Buggy python submission (verdict: Runtime Error):
x=input()
x=list(x)
s=0
t=0
ans=0
for i in range(len(x)):
    if x[i]="S":
        s+=1

    else:
        if s==0:
            ans+=1
        else:
            s-=1

print(ans+s)

Fixed submission:
x=list(input())
s=0
t=0
ans=0
for i in range(len(x)):
    if x[i]=="S":
        s+=1

    else:
        if s==0:
            ans+=1
        else:
            s-=1

print(ans+s)
Buggy python submission (verdict: Runtime Error):
s=str(input())
n=len(s)-1
#print(s,n)
#print(xy)
bit=[]#1が正直0が嘘
ans=0
def bit_search(bit):
    global ans
    count=[]
    c=0
    if len(bit)==n:#2**n文の組み合わせを調べる加圧10を交互に入れるためのif
        for i in range(n):
            if bit[i]==1:
                count.append(int(s[c:i]))
                c=i
        count.append(int(s[c:n]))
        ans+=sum(count)
    else:
       #再起化することによって最初にbitの配列を作る必要性をなくした
        bit_search(bit+[0])
        bit_search(bit+[1])
bit_search(bit)
print(ans)

Fixed submission:
s=str(input())
n=len(s)-1#間間なので-1
#print(s,n)
#print(xy)
bit=[]#1が＋入れる0がいれない
ans=0
c=0
count=[]
def bit_search(bit):
    #print("DFGHNM")
    count=[]#分けたやつを補完するやつ
    global ans
    c=0
    if len(bit)==n:#2**n文の組み合わせを調べる加圧10を交互に入れるためのif
        for i in range(n):
            if bit[i]==1:
                #print(int(s[c:i+1]))
                count.append(int(s[c:i+1]))
                c=i+1#ここの＋１大事
        #print(int(s[c:n+1]))
        count.append(int(s[c:n+1]))
        ans+=sum(count)
        #print(ans,sum(count),bit,c)
        return 
    else:
       #再起化することによって最初にbitの配列を作る必要性をなくした
        #print(bit)
        bit_search(bit+[0])
        bit_search(bit+[1])

bit_search(bit)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = lambda: sys.stdin.readline().rstrip()
n, k = map(int, input().split())
a = list(map(int, input().split()))

now = 1
for i in range(k):
    now *= a[i]
before = now

for i in range(n - k):
    now *= a[i + k]
    now /= a[i]
    if now > before:
        print('Yes')
    else:
        print('No')
    before = now


Fixed submission:
import sys
input = lambda: sys.stdin.readline().rstrip()
n, k = map(int, input().split())
a = list(map(int, input().split()))

now = 1
# for i in range(k):
#     now *= a[i]
# before = now

for i in range(n - k):
    # now *= a[i + k]
    # now /= a[i]
    if a[i] < a[i + k]:
        print('Yes')
    else:
        print('No')
    # before = now
Buggy python submission (verdict: Runtime Error):
n = int(input())
ans = [0 for _ in range(1001)]
for i in range(1, 40):
    for j in range(1, 40):
        for k in range(1, 40):
            summ = i**2 + j**2 + k**2 + i * j + j * k + k * i
            if summ < 1001:
                ans[summ] += 1

for i in range(1, n):
    print(ans[i])


Fixed submission:
n = int(input())
ans = [0 for _ in range(10001)]
for i in range(1, 100):
    for j in range(1, 100):
        for k in range(1, 100):
            summ = i**2 + j**2 + k**2 + i * j + j * k + k * i
            if summ < 10001:
                ans[summ] += 1

for i in range(1, n + 1):
    print(ans[i])
# print(ans[20])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from itertools import accumulate

input = lambda: sys.stdin.readline().rstrip()
n, m, k = map(int, input().split())

a = list(map(int, input().split()))
b = list(map(int, input().split()))
a = [0] + a
b = [0] + b
# 累積和を利用
a_accum = list(accumulate(a))
b_accum = list(accumulate(b))

ans = 0
for i in range(len(a_accum)):
    for j in range(len(b_accum)):
        if (a_accum[i] + b_accum[j] <= k):
            ans = max(ans, i + j)
        else:
            break
print(ans)


Fixed submission:
import sys
from itertools import accumulate
import bisect

input = lambda: sys.stdin.readline().rstrip()
n, m, k = map(int, input().split())

a = list(map(int, input().split()))
b = list(map(int, input().split()))
a = [0] + a
b = [0] + b
# 累積和を利用
a_accum = list(accumulate(a))
b_accum = list(accumulate(b))

# print(a_accum, b_accum)

ans = 0
for i in range(len(a_accum)):
    nokori = k - a_accum[i]
    if nokori < 0:
        break
    # にぶたん
    b_pos = bisect.bisect(b_accum, nokori) - 1
    ans = max(ans, i + b_pos)
    # print(nokori,ans,b_pos)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from itertools import accumulate

input = lambda: sys.stdin.readline().rstrip()
n, m, k = map(int, input().split())

a = list(map(int, input().split()))
b = list(map(int, input().split()))
a = [0] + a
b = [0] + b
# 累積和を利用
a_accum = list(accumulate(a))
b_accum = list(accumulate(b))

ans = 0
for i in range(len(a_accum)):
    for j in range(len(b_accum)):
        if (a_accum[i] + b_accum[j] <= k):
            ans = max(ans, i + j)
print(ans)


Fixed submission:
import sys
from itertools import accumulate
import bisect

input = lambda: sys.stdin.readline().rstrip()
n, m, k = map(int, input().split())

a = list(map(int, input().split()))
b = list(map(int, input().split()))
a = [0] + a
b = [0] + b
# 累積和を利用
a_accum = list(accumulate(a))
b_accum = list(accumulate(b))

# print(a_accum, b_accum)

ans = 0
for i in range(len(a_accum)):
    nokori = k - a_accum[i]
    if nokori < 0:
        break
    # にぶたん
    b_pos = bisect.bisect(b_accum, nokori) - 1
    ans = max(ans, i + b_pos)
    # print(nokori,ans,b_pos)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = lambda: sys.stdin.readline().rstrip()
n = int(input())
a = list(map(int, input().split()))
# a.sort()
check = [True for _ in range(10**6 + 5)]
dic = {}
if len(a) == 1:
    print(1)
    exit()

for i in a:
    if i in dic:
        dic[i] += 1
        continue
    dic[i] = 0
    now = 2 * i
    while (10**6 + 3 > now):
        check[now] = False
        now += i

ans = 0
for i in a:
    if check[i] and dic[i] == 0:
        ans += 1
print(ans)


Fixed submission:
import sys
input = lambda: sys.stdin.readline().rstrip()
n = int(input())
a = list(map(int, input().split()))
# a.sort()
check = [True for _ in range(10**6 + 5)]
dic = {}
if len(a) == 1:
    print(1)
    exit()

for i in a:
    if i in dic:
        dic[i] += 1
        continue
    dic[i] = 0
    now = 2 * i
    while (10**6 + 3 > now):
        check[now] = False
        now += i

ans = 0
for i in a:
    if check[i] and dic[i] == 0:
        ans += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = lambda: sys.stdin.readline().rstrip()
n = int(input())
a = list(map(int, input().split()))
a.sort()
check = [True for _ in range(10**6 + 5)]
dic = {}
if len(a) == 1:
    print(1)
    exit()

for i in a:
    if i in dic:
        dic[i] += 1
        continue
    dic[i] = 0
    now = 2 * i
    while (10**6 + 3 > now):
        check[now] = False
        now += i

ans = 0
for i in a:
    if check[i] and dic[i] == 0:
        ans += 1
print(ans)


Fixed submission:
import sys
input = lambda: sys.stdin.readline().rstrip()
n = int(input())
a = list(map(int, input().split()))
# a.sort()
check = [True for _ in range(10**6 + 5)]
dic = {}
if len(a) == 1:
    print(1)
    exit()

for i in a:
    if i in dic:
        dic[i] += 1
        continue
    dic[i] = 0
    now = 2 * i
    while (10**6 + 3 > now):
        check[now] = False
        now += i

ans = 0
for i in a:
    if check[i] and dic[i] == 0:
        ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = lambda: sys.stdin.readline().rstrip()

n = int(input())
a = list(map(int, input().split()))
ans = 1
for aa in a:
    ans *= aa

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


Fixed submission:
import sys
input = lambda: sys.stdin.readline().rstrip()

n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 1
for aa in a:
    ans *= aa
    if ans == 0:
        print(0)
        exit()
    elif ans > 10**18:
        print(-1)
        exit()

print(ans)
Buggy python submission (verdict: Runtime Error):
import math


# 素数の判定
def is_prime(n):
    if n == 1:
        return 0

    for k in range(2, int(math.sqrt(n)) + 1):
        chk = False
        while (n % k == 0):
            chk = True
            n /= k
            if k not in check:
                check[k] = 1
            else:
                check[k] += 1
        if chk:
            return n
    if n in check:
        return 0
    else:
        check[n] = 1
        return 1


check = {}
n = int(input())
if n == 1:
    print(0)
else:
    while (1):
        n = is_prime(n)
        if n == 0:
            break
    ans = 0
    for k, v in check.items():
        for i in range(1, 50):
            v -= i
            if v < 0:
                break
            else:
                ans += 1
# print(check)
print(ans)


Fixed submission:
import math


# 素数の判定
def is_prime(n):
    if n == 1:
        return 0

    for k in range(2, int(math.sqrt(n)) + 1):
        chk = False
        while (n % k == 0):
            chk = True
            n /= k
            if k not in check:
                check[k] = 1
            else:
                check[k] += 1
        if chk:
            return n
    if n in check:
        return 0
    else:
        check[n] = 1
        return 1


check = {}
n = int(input())
if n == 1:
    print(0)
else:
    while (1):
        n = is_prime(n)
        if n == 0:
            break
    ans = 0
    for k, v in check.items():
        for i in range(1, 50):
            v -= i
            if v < 0:
                break
            else:
                ans += 1
    # print(check)
    print(ans)
Buggy python submission (verdict: Runtime Error):
x = int(input())
det = 1001001001
for i in range(1000000):
    if abs(i**5 - x) < abs(det):
        det = i**5 - x
        a = i
    else:
        break

if det < 0:
    for i in range(-1, -1000000, -1):
        if i**5 == det:
            b = i
            break
elif det == 0:
    b = 0
else:
    for i in range(1000000):
        if i**5 == det:
            b = i
            break


print(a, b)


Fixed submission:
x = int(input())

for i in range(1000):
    for j in range(1000):
        if i**5 - j**5 == x:
            print(i,j)
            exit()
        elif i**5 - (-j)**5 == x:
            print(i,-j)
            exit()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = lambda: sys.stdin.readline().rstrip()
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(1, n + 1):
    now = a[i - 1]
    for j in range(i + now, n):
        if a[j] + now == (j+1) - i:
            ans += 1

print(ans)


Fixed submission:
import sys
input = lambda: sys.stdin.readline().rstrip()
n = int(input())
a = list(map(int, input().split()))
ans = 0
R = {}
L = {}
for i in range(n):
    r = i + a[i]
    l = max(i - a[i], 0)
    if r in R:
        R[r] += 1
    else:
        R[r] = 1
    if l in L:
        L[l] += 1
    else:
        L[l] = 1

for k, v in R.items():
    if k in L:
        ans += v * L[k]

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
ans = 0
for i in range(len(s)):
    one = s[i]
    for j in range(i + 1, len(s)):
        if s[j] == one:
            continue
        dis1 = j - i
        two = s[j]
        for k in range(j + 1, len(s)):
            if s[k] == one or s[k] == two:
                continue
            else:
                dis2 = k - j
                if dis1 != dis2:
                    ans += 1

print(ans)


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

ans = s.count('R') * s.count('G') * s.count('B')

for i in range(n):
    for j in range(i + 1, n):
        k = 2 * j - i
        # 三個目が範囲内 かつ 三文字違う かつ 距離が同じはダメ
        if k < n and (s[i] != s[j] and s[j] != s[k]
                      and s[i] != s[k]) and j - i == k - j:
            ans -= 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
ans = 0
for i in range(len(s)):
    one = s[i]
    for j in range(i + 1, len(s)):
        if s[j] == one:
            continue
        dis1 = j - i
        two = s[j]
        for k in range(j + 1, len(s)):
            if s[k] == one or s[k] == two:
                continue
            else:
                dis2 = k - j
                if dis1 != dis2:
                    ans += 1

print(ans)


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

ans = s.count('R') * s.count('G') * s.count('B')

for i in range(n):
    for j in range(i + 1, n):
        k = 2 * j - i
        # 三個目が範囲内 かつ 三文字違う かつ 距離が同じはダメ
        if k < n and (s[i] != s[j] and s[j] != s[k]
                      and s[i] != s[k]) and j - i == k - j:
            ans -= 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import heapq


def dijkstra_heap(s):
    #始点sから各頂点への最短距離
    d = [float("inf")] * n
    used = [True] * n  #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for e in edge[s]:
        heapq.heappush(edgelist, e)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge[1]]:
            continue
        v = minedge[1]
        d[v] = minedge[0]
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist, [e[0] + d[v], e[1]])
    return d


################################
n, x, y = map(int, input().split())  #n:頂点数
w = n
edge = [[] for i in range(n)]
#edge[i] : iから出る道の[重み,行先]の配列
for i in range(w - 1):
    edge[i + 1].append([1, i])
    edge[i].append([1, i + 1])
edge[x - 1].append([1, y - 1])
edge[y - 1].append([1, x - 1])

dic = {i: 0 for i in range(1, n)}

for i in range(n):
    tmp = dijkstra_heap(i)
    zero = False
    for j in tmp:
        if zero:
            dic[j] += 1
        if j == 0:
            zero = True

for i in range(1, n):
    print(dic[i])


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

dic = {i: 0 for i in range(1, n)}
for i in range(1, n + 1):
    for j in range(i + 1, n + 1):
        dist = min(j - i, abs(i - x) + abs(j - y) + 1)
        dic[dist] += 1


for i in range(1, n):
    print(dic[i])

Buggy python submission (verdict: Time Limit Exceeded):
import heapq


def dijkstra_heap(s):
    #始点sから各頂点への最短距離
    d = [float("inf")] * n
    used = [True] * n  #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for e in edge[s]:
        heapq.heappush(edgelist, e)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge[1]]:
            continue
        v = minedge[1]
        d[v] = minedge[0]
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist, [e[0] + d[v], e[1]])
    return d


################################
n, x, y = map(int, input().split())  #n:頂点数
w = n
edge = [[] for i in range(n)]
#edge[i] : iから出る道の[重み,行先]の配列
for i in range(w - 1):
    edge[i + 1].append([1, i])
    edge[i].append([1, i + 1])
edge[x - 1].append([1, y - 1])
edge[y - 1].append([1, x - 1])

dic = {i: 0 for i in range(1, n)}

# cost = [[float("inf") for i in range(n)] for i in range(n)]
# #cost[u][v] : 辺uvのコスト(存在しないときはinf この場合は10**10)
# for i in range(w - 1):
#     cost[i + 1][i] = 1
#     cost[i][i + 1] = 1
# cost[x - 1][y - 1] = 1
# cost[y - 1][x - 1] = 1

for i in range(n):
    tmp = dijkstra_heap(i)
    zero = False
    for j in tmp:
        if zero:
            dic[j] += 1
        if j == 0:
            zero = True

for i in range(1, n):
    print(dic[i])


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

dic = {i: 0 for i in range(1, n)}
for i in range(1, n + 1):
    for j in range(i + 1, n + 1):
        dist = min(j - i, abs(i - x) + abs(j - y) + 1)
        dic[dist] += 1


for i in range(1, n):
    print(dic[i])
Buggy python submission (verdict: Time Limit Exceeded):
# flip = True:その場が黒
def dfs(flip, nowx, nowy, step):
    if nowx == gx and nowy == gy:
        if field[nowy][nowx] == '#':
            step += 1
        elif field[nowy][nowx] == '.' and flip:
            step += 1
        return step
    else:
        if field[nowy][nowx] == '.':
            if flip:
                step += 1
                flip = False
        elif field[nowy][nowx] == '#':
            if flip == False:
                flip = True
        if nowx + 1 == w:
            return dfs(flip, nowx, nowy + 1, step)
        if nowy + 1 == h:
            return dfs(flip, nowx + 1, nowy, step)
        return min(dfs(flip, nowx + 1, nowy, step),
                   dfs(flip, nowx, nowy + 1, step))


h, w = map(int, input().split())
field = [[c for c in input().strip()] for _ in range(h)]
sx, sy = 0, 0
gx, gy = w - 1, h - 1
dirx = [1, 0]
diry = [0, 1]

print(dfs(False, sx, sy, 0))


Fixed submission:
h, w = map(int, input().split())
field = [[c for c in input().strip()] for _ in range(h)]
sx, sy = 0, 0
gx, gy = w - 1, h - 1
dirx = [1, 0]
diry = [0, 1]
inf = 1001001001
dp = [[(inf, False) for _ in range(w)] for _ in range(h)]
flip = False
step = 0
for i in range(w):
    if field[0][i] == '.':
        if flip:
            step += 1
            flip = False
    elif field[0][i] == '#':
        if flip == False:
            flip = True
    dp[0][i] = (step, flip)

flip = False
step = 0
for i in range(h):
    if field[i][0] == '.':
        if flip:
            step += 1
            flip = False
    elif field[i][0] == '#':
        if flip == False:
            flip = True
    dp[i][0] = (step, flip)

for i in range(1, h):
    for j in range(1, w):
        tmp1, f1 = dp[i - 1][j]
        tmp2, f2 = dp[i][j - 1]
        if field[i][j] == '.':
            if f1:
                tmp1 += 1
                #f1 = False
            if f2:
                tmp2 += 1
                #f2 = False
            dp[i][j] = (min(tmp1, tmp2), False)
        else:
            if i == gy and j == gx:
                dp[i][j] = (min(tmp1 + 1, tmp2 + 1), True)
            else:
                dp[i][j] = (min(tmp1, tmp2), True)

print(dp[h - 1][w - 1][0])
Buggy python submission (verdict: Time Limit Exceeded):
def cmb(n, k, mod):
    numerator = 1
    for i in range(k):
        numerator = (numerator * (n-i)) % mod

    denominator = 1
    for i in range(1, k+1):
        denominator = (denominator * i) % mod

    return (numerator * pow(denominator, mod-2, mod)) % mod


def pow_k(x, n):
    """
    O(log n)
    """
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2

    return K * x


n, a, b = map(int, input().split())
mod = 10**9 + 7
print((pow_k(2, n) % mod - cmb(n, a, mod) - cmb(n, b, mod) - 1) % mod)


Fixed submission:
def cmb(n, k, mod):
    numerator = 1
    for i in range(k):
        numerator = (numerator * (n-i)) % mod

    denominator = 1
    for i in range(1, k+1):
        denominator = (denominator * i) % mod

    return (numerator * pow(denominator, mod-2, mod)) % mod


def pow_k(x, n):
    """
    O(log n)
    """
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2

    return K * x


def myPow(x, n, m):
    if(n == 0):
        return 1
    if(n % 2 == 0):
        return myPow(x * x % m, n / 2, m)
    else:
        return x * myPow(x, n - 1, m) % m


n, a, b = map(int, input().split())
mod = 10**9 + 7
print((myPow(2, n, mod) - cmb(n, a, mod) - cmb(n, b, mod) - 1) % mod)
Buggy python submission (verdict: Time Limit Exceeded):
# Python3ではTLE
# PyPyなら回る
h, n = map(int, input().split())
inf = 1001001001
dp = [[inf for _ in range(h+1)] for _ in range(n+1)]
dp[0][0] = 0
for i in range(n):
    a, b = map(int, input().split())
    for j in range(h + 1):
        # 外側参照しないように
        nj = max(0, j-a)
        dp[i+1][j] = min(dp[i][j], dp[i+1][nj]+b)

print(dp[n][h])


Fixed submission:
h, n = map(int, input().split())
inf = 1001001001
dp = [inf for _ in range(h+1)]
dp[0] = 0
ans = inf
for i in range(n):
    a, b = map(int, input().split())
    for j in range(h + 1):
        # 外側参照しないように
        nj = min(j+a, h)
        dp[nj] = min(dp[nj], dp[j]+b)

print(dp[h])

Buggy python submission (verdict: Time Limit Exceeded):
h, n = map(int, input().split())
inf = 1001001001
dp = [inf for _ in range(h+1)]
dp[0] = 0
ans = inf
for i in range(n):
    a, b = map(int, input().split())
    for j in range(h + 1):
        # 外側参照しないように
        nj = min(j+a, h)
        dp[nj] = min(dp[nj], dp[j]+b)

print(dp[h])


Fixed submission:
h, n = map(int, input().split())
inf = 1001001001
dp = [inf for _ in range(h+1)]
dp[0] = 0
ans = inf
for i in range(n):
    a, b = map(int, input().split())
    for j in range(h + 1):
        # 外側参照しないように
        nj = min(j+a, h)
        dp[nj] = min(dp[nj], dp[j]+b)

print(dp[h])
Buggy python submission (verdict: Time Limit Exceeded):
import sys

sys.setrecursionlimit(2000)


def dfs(now):
    if now == x:
        print(1)
        exit()
    elif now > x:
        return False
    for i in range(6):
        if (dfs(now + 100 + i)):
            pass


x = int(input())
if x >= 2100:
    print(1)
else:
    dfs(0)
    print(0)


Fixed submission:
x = int(input())
if x >= 2100:
    print(1)
else:
    for i in range(1, 21):
        x -= 100
        if x < 0:
            break
        if x in range(0, i * 5 + 1):
            print(1)
            exit()
    print(0)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()

# now = 0
# left = 0
# right = 0
ans = []
for i in range(len(s) + 1):

    left = 0
    right = 0
    # 左側
    for j in range(i, 0, -1):
        if s[j - 1] != '<':
            break
        else:
            left += 1
    # 右側
    for j in range(i, len(s)):
        if s[j] != '>':
            break
        else:
            right += 1
    ans.append(max(left, right))
# print(ans)
print(sum(ans))


Fixed submission:
s = input()

# now = 0
left = 0
right = 0
ans = []
for i in range(len(s) + 1):
    if left == 0:
        # 左側
        for j in range(i - 1, -1, -1):
            if s[j] != '<':
                break
            else:
                left += 1
    else:
        if s[i - 1] == '<':
            left += 1
        else:
            left = 0
    # 右側
    if right == 0:
        for j in range(i, len(s)):
            if s[j] != '>':
                break
            else:
                right += 1
    else:
        if i == len(s):
            right = 0
        elif s[i] == '>':
            right -= 1
        else:
            right = 0
    ans.append(max(left, right))
# print(ans)
print(sum(ans))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = [int(i) for i in input().split()]
l = sorted(l, reverse=True)

ans = 0
for i in range(len(l)-2):
    for j in range(i + 1, len(l) - 1):
        for k in range(j + 1, len(l)):
            if l[i] < l[j] + l[k]:
                ans += 1
            else:
                break

print(ans)


Fixed submission:
import bisect
import sys
input = lambda: sys.stdin.readline().rstrip()
n = int(input())
l = list(map(int, input().split()))
l = sorted(l)
ans = 0
for b in range(n):
    for a in range(b):
        tmp = l[a] + l[b]
        r = bisect.bisect_left(l, tmp)
        ll = b + 1
        ans += max(0, r - ll)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = [int(i) for i in input().split()]

#l = list(set(l))
ans = 0
for i in range(len(l)-2):
    for j in range(i + 1, len(l) - 1):
        for k in range(j + 1, len(l)):
            if l[i] < l[j] + l[k] and l[j] < l[i] + l[k] and l[k] < l[i] + l[j]:
                ans += 1

print(ans)


Fixed submission:
import bisect
import sys
input = lambda: sys.stdin.readline().rstrip()
n = int(input())
l = list(map(int, input().split()))
l = sorted(l)
ans = 0
for b in range(n):
    for a in range(b):
        tmp = l[a] + l[b]
        r = bisect.bisect_left(l, tmp)
        ll = b + 1
        ans += max(0, r - ll)
print(ans)