CodeEff/ECCO huggingface dataset:
# Original solution
import re

s = list(re.sub(r'[BC]+', 'B', input().strip().replace('BC', 'D')))
n = len(s)
#print(s)

end = n - 1

count = 0

if n >= 3:
  i = 0
  while i < end:
    if s[i] == 'A' and s[i + 1] == 'D':
      s[i] = 'D'
      s[i + 1] = 'A'
      count = count + 1

      j = i - 1
      while j >= 0 and s[j] == 'A':
        s[j] = 'D'
        s[j + 1] = 'A'
        count = count + 1
        j = j - 1

    i = i + 1

print(count)

# Optimized solution
s = input().strip().replace('BC', 'D')
n = len(s)

count = 0
a_count = 0
for i in range(n):
  if s[i] == 'A':
    a_count += 1
  elif a_count > 0 and s[i] == 'D':
    count += a_count
  else:
    a_count = 0

print(count)
# Original solution
import sys
input=sys.stdin.readline

def main():
    S = input().strip()
    ans = 0
    while 1:
        i = S.find("ABC")
        if i < 0:
            break
        li = 0
        for l in range(i-1,-1,-1):
            if S[l] == "A":
                li += 1
            else:
                break
        ri = 0
        for r in range(i+3,len(S)-1,2):
            if S[r] == "B" and S[r+1] == "C":
                ri += 1
            else:
                break
        x = min(li, ri)
        S = S[:i-x] + "BC"*(x+1) + "A"*(x+1) + S[i+3 + x*2:]
        ans += 1 if x == 0 else (x+1)**2
        
    print(ans)

if __name__ == '__main__':
    main()


# Optimized solution
import sys
input=sys.stdin.readline

def main():
    S = input().strip()
    S = S.replace("BC","D")
    ans = 0
    a = 0
    for c in S:
        if c == "A":
            a += 1
        elif c == "D":
            ans += a
        else:
            a = 0
        
    print(ans)

if __name__ == '__main__':
    main()
# Original solution
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: list(map(int, readline().split()))
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: list(map(int, read().split()))
in_s = lambda: readline().rstrip().decode('utf-8')


def main():

    S = in_s()
    N = len(S)

    def abc_count():

        count = 0
        fa, fb = False, False
        for i in range(N):
            if S[i] == 'A':
                fa = True
            elif fa and S[i] == 'B':
                fb = True
            elif fb and S[i] == 'C':
                count += 1
                fa, fb = False, False
            else:
                fa, fb = False, False

        return count

    ans = 0
    while True:
        t = abc_count()
        if t == 0:
            break
        else:
            ans += t
            S = S.replace('ABC', 'BCA')

    print(ans)


if __name__ == '__main__':
    main()


# Optimized solution
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: list(map(int, readline().split()))
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: list(map(int, read().split()))
in_s = lambda: readline().rstrip().decode('utf-8')


def t(S):

    N = len(S)

    a = [0] * (N + 1)
    d = [0] * (N + 1)
    for i in range(N):
        if S[i] == 'A':
            a[i + 1] = 1
        else:
            d[i + 1] = 1

    for i in range(N):
        a[i + 1] += a[i]
        d[i + 1] += d[i]

    ans = 0
    for i in range(1, N):
        if S[i] == 'D':
            ans += a[i]

    return ans


def main():

    S = in_s()
    S = S.replace('BC', 'D')
    S = S.replace('B', ' ')
    S = S.replace('C', ' ')

    ans = 0
    for ts in S.split():
        ans += t(ts)

    print(ans)


if __name__ == '__main__':
    main()
# Original solution
#!/usr/bin/env python3
import sys


def solve(s: str):
    
    s = s.replace('BC', 'X')

    ans = 0
    while('AX' in s):
        ans += s.count('AX')
        s = s.replace('AX', 'XA', len(s))
        

    print(ans)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  # type: str
    solve(s)

if __name__ == '__main__':
    main()


# Optimized solution
#!/usr/bin/env python3
import sys


def solve(s: str):
    
    s = s.replace('BC', 'X')

    ans = 0
    cur = 0
    for i in range(len(s)):
        if(s[i] == 'A'):
            cur += 1
        elif(s[i] == 'X'):
            ans += cur
        else:
            cur = 0    

    print(ans)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  # type: str
    solve(s)

if __name__ == '__main__':
    main()
# Original solution
from sys import stdin
s = (stdin.readline().rstrip())
ans = 0
while s.count("ABC") != 0:
    ans += s.count("ABC")
    s = s.replace("ABC","BCA")
print(ans)

# Optimized solution
from sys import stdin
s = (stdin.readline().rstrip())
s = s.replace("BC","D")
ans = 0
acc = 0

for i in s:
    if i == "B" or i == "C":
        acc = 0
        continue
        
    if i == "A":
        acc += 1
    
    if i == "D":
        ans += acc

print(ans)
# Original solution
def main():
    s = input().replace('BC', 'X')
    count = 0
    N = len(s)
    for i in range(N - 1):
        if s[i] == 'A':
            n = 1
            while i + n < N:
                if s[i + n] == 'A':
                    n += 1
                    continue
                elif s[i + n] == 'X':
                    n += 1
                    count += 1
                else:
                    break
    print(count)

if __name__ == '__main__':
    main()


# Optimized solution
def main():
    s = input().replace('BC', 'X')[::-1]
    N = len(s)
    count = 0
    tmp = 0
    for i in range(N):
        if s[i] == 'X':
            tmp += 1
        elif s[i] == 'A':
            count += tmp
        else:
            tmp = 0
    print(count)

if __name__ == '__main__':
    main()
# Original solution
#!/usr/bin/env python3
import sys

def conv2num(c):
    if c == "A":
        return 1
    elif c == "D":
        return 2
    elif c == "B":
        return 3
    else:
        return 4

def solve(s: str):

    res = 0

    s = s.replace("BC","D")
    s = [ conv2num(c) for c in s ]
    i = 0
    endi = len(s) - 1
    while i < endi:
        if s[i] == 1 and s[i+1] == 2:
            ai = i
            for j in range(i-1,-1,-1):
                if s[j] == 1 and j >=0 :
                    ai = j 
                else:
                    break
            s[ai]   = 2
            s[ai+1] = 1
            res += 1

            st = ai+2
            ed = i +2
            if st != ed:
                for k in range(st,ed):
                    s[k] = 1
                    res += 1
        i += 1

    print(res)

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  # type: str
    solve(s)

if __name__ == '__main__':
    main()


# Optimized solution
#!/usr/bin/env python3
import sys

def conv2num(c):
    if c == "A":
        return 1
    elif c == "D":
        return 2
    elif c == "B":
        return 3
    else:
        return 4

def solve(s: str):

    res = 0
    s = s.replace("BC","D")
    s = [ conv2num(c) for c in s ]

    acnt = 0
    for i,c in enumerate(s):
        if c == 1:
            acnt += 1
        elif c == 2:
            res += acnt
        else:
            acnt = 0


    print(res)

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  # type: str
    solve(s)

if __name__ == '__main__':
    main()
# Original solution
import sys
stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

S = list(rs())
cur = 'D'
answer = 0
A_cnt = 0
for s in S:
    if cur == 'A':
        if s == 'A':
            A_cnt += 1
        elif s == 'B':
            cur = s
        else:
            cur = 'D'
            A_cnt = 0
    elif cur == 'B':
        if s == 'A':
            A_cnt = 1
            cur = s
        elif s == 'B':
            A_cnt = 0
            cur = 'D'
        elif s == 'C':
            answer += A_cnt
            cur = s
        else:
            cur = 'D'
            A_cnt = 0
    elif cur == 'C':
        if s == 'A':
            A_cnt += 1
            cur = s
        elif s == 'B':
            cur = s
        else:
            cur = 'D'
            A_cnt = 0
    else:
        if s == 'A':
            A_cnt += 1
            cur = s
        else:
            A_cnt = 0
            cur = 'D'

print(answer)


# Optimized solution
import sys
stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

S = rs()
S = S.replace('BC', 'D')
cnt_A = 0
answer = 0
for s in S:
    if s == 'A':
        cnt_A += 1
    elif s == 'D':
        answer += cnt_A
    else:
        cnt_A = 0
print(answer)
# Original solution
S = input().replace("BC", "D")

ans = a = 0
for s in S:
    if s == "A":
        a += 1
    elif s == "D":
        ans += a
    else:
        a = 0

print(ans)

# Optimized solution
def main():
    S = input().replace("BC", "D")

    ans = a = 0
    for s in S:
        if s == "A":
            a += 1
        elif s == "D":
            ans += a
        else:
            a = 0

    print(ans)

main()
# Original solution
import sys

def main():
    input = sys.stdin.readline
    S = list(input().strip())
    n = len(S)

    ans = 0
    cnt = 0
    for i in range(n):
        if S[i:i+3] == ['A', 'B', 'C']:
            cnt += 1
            S[i] = 'B'
            S[i+1] = 'C'
            S[i+2] = 'A'

    S = S[::-1]
    for i in range(n):
        if S[i:i+3] == ['C', 'B', 'A']:
            cnt += 1
            S[i] = 'A'
            S[i+1] = 'C'
            S[i+2] = 'B'

    ans += cnt
    while cnt > 0:
        cnt = 0
        S = S[::-1]
        for i in range(n):
            if S[i:i+3] == ['A', 'B', 'C']:
                cnt += 1
                S[i] = 'B'
                S[i+1] = 'C'
                S[i+2] = 'A'

        S = S[::-1]
        for i in range(n):
            if S[i:i+3] == ['C', 'B', 'A']:
                cnt += 1
                S[i] = 'A'
                S[i+1] = 'C'
                S[i+2] = 'B'

        ans += cnt


    return ans


if __name__ == '__main__':
    print((main()))


# Optimized solution
import sys

def main():
    input = sys.stdin.readline
    S = input().strip()
    n = len(S)

    T = ''
    i = 0
    while i < n:
        if S[i] == 'A':
            T += 'A'
            i += 1
        elif S[i:i+2] == 'BC':
            T += 'D'
            i += 2
        else:
            T += S[i]
            i += 1

    ans = 0
    cnt = 0
    for c in T:
        if c == 'A':
            cnt += 1
        elif c == 'D':
            ans += cnt
        else:
            cnt = 0

    return ans


if __name__ == '__main__':
    print((main()))
# Original solution
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return list(map(int, stdin.readline().split()))
def li_(): return [int(x) - 1 for x in stdin.readline().split()]
def lf(): return list(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 choose_abc_range(s):
    ranges = []
    cur = 0
    while cur < len(s):
        if s[cur:cur+3] == "ABC":
            st = cur
            j = cur

            while s[j:j+3] == "ABC":
                j += 3

            ed = j

            ranges.append([st, ed])
            cur = j

        else:
            cur += 1

    return ranges

def get_a(sa):
    a = 0
    for sai in sa:
        if sai == "A":
            a += 1
        else:
            break

    return a

def get_bc(sb):
    b = 0
    for sbi in sb[::2]:
        if sbi == "bc":
            b += 1
        else:
            break

    return b

s = ns()
ans = 0
while "ABC" in s:

    ranges = choose_abc_range(s)
    for l, r in ranges:
        k = (r-l+1)//3
        a = get_a(s[l-1::-1])
        b = get_bc(s[r:])

        ans += k*(k+1)//2 + max(a*k + b*(k+a), b*k, a*(k+b))

        s = s[:l-a] + "BC"*(k+b) + "A"*(k+a) + s[r+2*b:]

print(ans)

# Optimized solution
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return list(map(int, stdin.readline().split()))
def li_(): return [int(x) - 1 for x in stdin.readline().split()]
def lf(): return list(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())


s = ns()

cur = 0
anum = 0
bcnum = 0
ans = 0

while cur < len(s):
    if s[cur:cur+1] == "A":
        anum += 1
        cur += 1

    elif s[cur:cur+2] == "BC":
        bcnum += 1
        ans += anum
        cur += 2

    else:
        anum = 0
        bcnum = 0
        cur += 1

print(ans)
# Original solution
s = input().strip()
x = s[0]
for i in range(1,len(s)):
    if s[i]=="C" and s[i-1]=="B":
        x = x[:-1]+"T"
    else:
        x += s[i]
cnt = 0
ca = 0
for i in range(len(x)):
    if x[i]=="A":
        ca += 1
    elif x[i]=="T":
        cnt += ca
    elif x[i]=="B" or x[i]=="C":
        ca = 0
print(cnt) 

# Optimized solution
s = input().strip()
x = [s[0]]
for i in range(1,len(s)):
    if s[i]=="C" and s[i-1]=="B":
        x.pop()
        x.append("T")
    else:
        x.append(s[i])
cnt = 0
ca = 0
for i in range(len(x)):
    if x[i]=="A":
        ca += 1
    elif x[i]=="T":
        cnt += ca
    elif x[i]=="B" or x[i]=="C":
        ca = 0
print(cnt)
# Original solution
import  re
s = input().replace("BC", "X")
cnt = 0
while "AX" in s:
  if "AXAX" in s:
    tmp = re.subn("AXAX", "XXAA", s)
    s = tmp[0]
    cnt += tmp[1] * 3

  tmp = re.subn("AX", "XA", s)
  s = tmp[0]
  cnt += tmp[1]
print(cnt)

# Optimized solution
cnt, tmp = 0, 0
for c in input().replace("BC", "X"):
  if c == "A":
    tmp += 1
  elif c == "X":
    cnt += tmp
  else:
    tmp = 0
print(cnt)
# Original solution
# coding: utf-8
# Your code here!
s=list(input().replace("BC","Z"))
ans=0

def seisan(list):
    count=0
    N=len(list)-1
    for index,content in enumerate(list):
        if content=="A":
            count+=(N-index)
            N-=1
    return count

temp=[]
while s:
    this=s.pop(0)
    if this=="B" or this=="C":
        ans+=seisan(temp)
        temp.clear()
    else:
        temp.append(this)

print((ans+seisan(temp)))


# Optimized solution
# coding: utf-8
# Your code here!
s=list(input().replace("BC","Z"))[::-1]
ans=0

def seisan(list):
    count=0
    N=len(list)-1
    for index,content in enumerate(list):
        if content=="A":
            count+=(N-index)
            N-=1
    return count

temp=[]
while s:
    this=s.pop(-1)
    if this=="B" or this=="C":
        ans+=seisan(temp)
        temp.clear()
    else:
        temp.append(this)

print((ans+seisan(temp)))
#ちょくだいさん連投ゆるして
# Original solution
s = input().replace("BC", "D")

ans = 0
cnt = 0
for i in s[::-1]:
    if i == "D":
        cnt += 1
    elif i == "A":
        ans += cnt
    else:
        cnt = 0



print(ans)

# Optimized solution
s = input().replace("BC", "D")
a = 0
c = 0
for i in s[::-1]:
    if i == "D":
        c += 1
    elif i == "A":
        a += c
    else:
        c = 0
print(a)
# Original solution
S = list(input().replace("BC", "D"))
l = []
ans = 0
for i in range(len(S)-1):
    if(S[i] == "A" and S[i+1] == "D"):
        l.append(i+1)
        l.append(i-1)
        S[i] = "D"
        S[i+1] = "A"
        ans += 1

while(len(l)):
    target = l[0]
    if(target < len(S) - 1 and target >= 0):
        if(S[target] == "A" and S[target+1] == "D"):
            ans += 1
            S[target+1] = "A"
            S[target] = "D"
            l.append(target+1)
            l.append(target-1)
    l.pop(0)

print(ans)


# Optimized solution
S = list(input().replace("BC", "D"))
l = []
ans = 0
a_cnt = 1
d_cnt = 1
for i in range(len(S)-1):
    if (S[i] == "A" and S[i + 1] == "D"):
        ans += a_cnt
        S[i] = "D"
        S[i + 1] = "A"
    else:
        if(S[i] == "A" and S[i+1] == "A"):
            a_cnt += 1
        else:
            a_cnt = 1

print(ans)
# Original solution
ans=0
for x in input().replace('BC','y').replace('A','x').replace('B',' ').replace('C',' ').split():
    c=0
    for t in x:
        if t=='y':
            ans+=c
        else:c+=1
print(ans)

# Optimized solution
def f():
    ans,c=0,0
    for t in input().replace('BC','y').replace('A','x'):
        if t=='y':ans+=c
        elif t=='x':c+=1
        else:c=0
    print(ans)
if __name__ == "__main__":
    f()
# Original solution
import sys
readline = sys.stdin.readline

S = readline().rstrip()
S = S.replace("BC","X")
S = S.replace("B",".").replace("C",".")
arr = S.split(".")
ans = 0
for a in arr:
  cnt = 0
  for i in range(len(a)):
    if a[i] == "X":
      ans += (i - cnt)
      cnt += 1
  
print(ans)

# Optimized solution
import sys
readline = sys.stdin.readline

S = readline().rstrip().replace("BC","X")

# AAXXX のようにAとXだけで構成されている部分は、
# Xを全て左に移動する
# BとCが残っている部分で切れる

parts = S.replace("B",",").replace("C",",").split(",")

ans = 0
for part in parts:
  # Xを探し、Xにあったら、そのときのインデックス - それまでにXを見つけた数する
  cnt = 0
  for i in range(len(part)):
    if part[i] == "X":
      ans += (i - cnt)
      cnt += 1

print(ans)
# Original solution
# coding:utf-8

import math

def main():
    s = list(input())
    s.reverse()
    cnt = 0
    total = 0
    while True:
        chk = False
        for i in s:
            if i == 'C' and cnt < len(s) - 2:
                if s[cnt+1] == 'B' and s[cnt+2] == 'A':
                    s[cnt] = 'A'
                    s[cnt+1] = 'C'
                    s[cnt+2] = 'B'
                    total += 1
                    chk = True
                    break
            cnt += 1
        if chk == True:
            cnt = 0
            continue
        else:
            break
    print(total)


if __name__ == "__main__":
    main()



# Optimized solution
# coding:utf-8

import math

def main():
    s = list(input())
    substr = ''
    total = []
    cnt = 0
    m = False
    for i in s:
        if i == 'A' and m == False:
            cnt += 1
        elif i == 'A':
            cnt = 1
            m = False
        elif i == 'B' and m == False:
            m = True
        elif i == 'C' and m == True:
            total.append(cnt)
            m = False
        else:
            m = False
            cnt = 0
    result = 0
    for i in total:
        result += i
    print(result)

if __name__ == "__main__":
    main()
# Original solution
from copy import deepcopy

def solve():
    s = [_ for _ in input()]
    ans = 0
    chlist = []
    for i in range(len(s) - 2):
        if s[i] == 'A':
            chlist.append(i)
    found = True
    while found:
        found = False
        tmp_cl = deepcopy(chlist)
        for it in range(len(tmp_cl)):
            i = chlist[it]
            if s[i:(i+3)] == ['A', 'B', 'C']:
                s[i], s[i+1], s[i+2] = 'B', 'C', 'A'
                chlist[it] = i + 2
                ans += 1
                found = True
    print(ans)

if __name__ == '__main__':
    solve()


# Optimized solution
def solve2():
    s = input()
    s = s.replace('BC', 'X')
    ans = 0
    acc_A = 0
    for ele in s:
        if ele == 'A':
            acc_A += 1
        elif ele == 'X':
            ans += acc_A
        else:
            acc_A = 0
    print(ans)

if __name__ == '__main__':
    solve2()
# Original solution
from sys import stdin
s = stdin.readline().rstrip()
point = 0
while True:
    if "ABC" not in s:
        break
    else:
        point += s.count("ABC")
        s = s.replace("ABC","BCA")
print(point)

# Optimized solution
from sys import stdin
s = stdin.readline().rstrip()
s = s.replace("BC","D")
point = 0
count = 0
for i in s:
    if i == "A":
        count += 1
    elif i == "D":
        point += count
    else:
        count = 0
print(point)
# Original solution
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(2147483647)
input=lambda:sys.stdin.readline().rstrip()

def solve():
    n = int(eval(input()))
    edge = [[] for _ in range(n)]
    for v in range(1,n):
        u = int(eval(input()))-1
        edge[u].append(v)

    dp = [None]*n
    def dfs(s):
        if dp[s] != None:
            return dp[s]
        if edge[s] == []:
            dp[s] = 0
            return 0
        tmp = []
        for v in edge[s]:
            tmp.append(dfs(v))
        dp[s] = max(1+i+x for i,x in enumerate(sorted(tmp,reverse=1)))
        return dp[s]
    print((dfs(0)))
    
if __name__=='__main__':
    solve()



# Optimized solution
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n=int(eval(input()))
    E=[[] for _ in range(n)]
    for v in range(1,n):
        u=int(eval(input()))-1
        E[u].append(v)
        E[v].append(u)

    dp=[None]*n
    def dfs(v,p=-1)->int:
        if(dp[v] is not None): return dp[v]
        if(E[v]==[p]):
            dp[v]=0
            return 0
        res=[]
        for nv in E[v]:
            if(nv==p): continue
            res.append(dfs(nv,v))
        dp[v]=max(1+i+x for i,x in enumerate(sorted(res,reverse=1)))
        return dp[v]

    print((dfs(0)))
resolve()
# Original solution
import sys
from heapq import heapify,heappush,heappop
sys.setrecursionlimit(10**7)
N=int(eval(input()))
List=[[] for i in range(N)]
for i in range(1,N):
  a=int(eval(input()))
  List[a-1].append(i)

def f(x):
  if len(List[x])==0:
    return 0
  L=[]
  heapify(L)
  for a in List[x]:
    heappush(L,f(a))
  n=len(L)
  res=0
  for i in range(n):
    b=heappop(L)
    res=max(res,b+n-i)
  return res
print((f(0)))
  

# Optimized solution
import sys
from heapq import heapify,heappush,heappop
sys.setrecursionlimit(10**7)
input=sys.stdin.readline
N=int(eval(input()))
List=[[] for i in range(N)]
for i in range(1,N):
  a=int(eval(input()))
  List[a-1].append(i)

def f(x):
  if len(List[x])==0:
    return 0
  L=[]
  heapify(L)
  for a in List[x]:
    heappush(L,f(a))
  n=len(L)
  res=0
  for i in range(n):
    b=heappop(L)
    res=max(res,b+n-i)
  return res
print((f(0)))