Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

n = int(input())
s = [x for x in [Counter(list(input())) for _ in range(n)]]


alphabet = set('abcdefghijklmnopqrstuvwxyz')
s_list = [int('1' + ''.join([str(s_i[a]) for a in alphabet])) for s_i in s]

count = 0
i = 0

for x in s_list:
  i += 1
  temp = s_list[i:]
  hoge = s[i:]
  for y in temp:
    if y == x:
      count += 1
print(count)

Fixed submission:
def sort_str(s):
  temp = sorted(list(s))
  return ''.join(list(temp))

n = int(input())
s = [input() for _ in range(n)]

s_dict = {}
count = 0

for s_i in s:
  k = sort_str(s_i)
  if k in s_dict:
    count += s_dict[k]
    s_dict[k] += 1
  else:
    s_dict[k] = 1
    
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

n = int(input())
s = [x for x in [Counter(list(input())) for _ in range(n)]]


alphabet = set('abcdefghijklmnopqrstuvwxyz')
s_list = [int(''.join([str(s_i[a]) for a in alphabet])) for s_i in s]

count = 0
i = 0

for x in s_list:
  i += 1
  temp = s_list[i:]
  hoge = s[i:]
  for y in temp:
    if y == x:
      count += 1
print(count)

Fixed submission:
def sort_str(s):
  temp = sorted(list(s))
  return ''.join(list(temp))

n = int(input())
s = [input() for _ in range(n)]

s_dict = {}
count = 0

for s_i in s:
  k = sort_str(s_i)
  if k in s_dict:
    count += s_dict[k]
    s_dict[k] += 1
  else:
    s_dict[k] = 1
    
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

n = int(input())
s = [x for x in [Counter(list(input())) for _ in range(n)]]


alphabet = set('abcdefghijklmnopqrstuvwxyz')
s_list = [''.join([str(s_i[a]) for a in alphabet]) for s_i in s]

count = 0
i = 0

for x in s_list:
  i += 1
  temp = s_list[i:]
  hoge = s[i:]
  for y in temp:
    if y == x:
      count += 1
print(count)

Fixed submission:
def sort_str(s):
  temp = sorted(list(s))
  return ''.join(list(temp))

n = int(input())
s = [input() for _ in range(n)]

s_dict = {}
count = 0

for s_i in s:
  k = sort_str(s_i)
  if k in s_dict:
    count += s_dict[k]
    s_dict[k] += 1
  else:
    s_dict[k] = 1
    
print(count)
Buggy python submission (verdict: Runtime Error):
n = int(input())
p = [int(x) for x in input().split()]

count = 0
index = []

for i in range(n-1):
  if p[i] < p[i+1]:
    pass
  else:
    count += 1
    index.append(i)

if count == 0:
  print('YES')
elif count == 2:
  print('NO')
else:
  p[index[0]], p[index[1] + 1] = p[index[1] + 1], p[index[0]]
  sorted_p = sorted(p)
  if p == sorted_p:
    print('YES')
  else:
    print('NO')

Fixed submission:
n = int(input())
p = [int(x) for x in input().split()]
 
count = 0
index = []
 
for i in range(n-1):
  if p[i] < p[i+1]:
    pass
  else:
    count += 1
    index.append(i)

if count == 0:
  print('YES')
elif count != 2:
  print('NO')
else:
  p[index[0]], p[index[1] + 1] = p[index[1] + 1], p[index[0]]
  sorted_p = sorted(p)
  if p == sorted_p:
    print('YES')
  else:
    print('NO')
Buggy python submission (verdict: Runtime Error):
import sys, re
input = sys.stdin.readline

n = int(input())
a = [int(input()) for x in range(n)]

temp_list = sorted(a)
m = temp_list[n-1]


for x in temp_list[::-1]:
  if x == m:
    continue
  else:
    m_dash = x
    break

for a_i in a:
  if a_i == m:
    print(m_dash)
  else:
    print(m)

Fixed submission:
import sys, re
input = sys.stdin.readline

n = int(input())
a = [int(input()) for x in range(n)]

# a をソートして、一番大きい要素を取り出す
temp_list = sorted(a)
m = temp_list[::-1][0]


# 最も大きな数が複数あった場合
if temp_list[::-1][1] == m:
    m_dash = m
else:
    m_dash =temp_list[::-1][1]

for a_i in a:
  if a_i == m:
    print(m_dash)
  else:
    print(m)

Buggy python submission (verdict: Time Limit Exceeded):
import sys, re
input = sys.stdin.readline

n = int(input())
a = [int(input()) for x in range(n)]

# a[0]の場合
temp_list = a[1:]
temp_list.sort()
print(temp_list[-1])

# それ以外の場合
for i in range(1, n):
  temp_list = a[:i] + a[i+1:]
  temp_list.sort()
  print(temp_list[-1])


Fixed submission:
import sys, re
input = sys.stdin.readline

n = int(input())
a = [int(input()) for x in range(n)]

# a をソートして、一番大きい要素を取り出す
temp_list = sorted(a)
m = temp_list[::-1][0]


# 最も大きな数が複数あった場合
if temp_list[::-1][1] == m:
    m_dash = m
else:
    m_dash =temp_list[::-1][1]

for a_i in a:
  if a_i == m:
    print(m_dash)
  else:
    print(m)
Buggy python submission (verdict: Runtime Error):
check = True

if len(set(list(s))) == len(s):
    pass
else:
    for c in list(set(list(s))):
        if list(s).count(c) != 2:
            if check:
                print('No')
                check = False
    if check:
        print('Yes')

Fixed submission:
s = input()

check = True
 
if len(set(list(s))) == len(s):
  print('No')
else:
    for c in list(set(list(s))):
        if list(s).count(c) != 2:
            if check:
                print('No')
                check = False
    if check:
        print('Yes')
Buggy python submission (verdict: Runtime Error):
s = list(input())

t = input()

print(t[int(s[1])-1].lower() + t[int(s[1]):])

Fixed submission:
s = input().split()
t = input()
k = int(s[1]) - 1

print(t[:k] + t[k].lower() + t[k+1:])
Buggy python submission (verdict: Time Limit Exceeded):
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

def search_cd(a):
  common_div = 0
  for a_i in a:
    common_div = gcd(a_i, common_div)
  return common_div

n = int(input())
a = [int(x) for x in input().split()]

m = max([search_cd(a[:i] + a[i+1:]) for i in range(n)])
  
print(m)

Fixed submission:
# b = 0 のとき、aを返す
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
  
n = int(input())
a = [int(x) for x in input().split()]
reversed_a = list(reversed(a))

length = len(a)
left_gcd = [0] * length
right_gcd = [0] * length

for i in range(1, length):
  left_gcd[i] = gcd(a[i-1], left_gcd[i-1])
  right_gcd[i] = gcd(reversed_a[i-1], right_gcd[i-1])
  
right_gcd = right_gcd[::-1]
m = [gcd(r, l) for l, r in zip(left_gcd, right_gcd)]

# print(left_gcd)
# print(right_gcd)
# print(m)

print(max(m))
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()
k = int(input())

x = s[k]
temp_list = []

for c in s:
  if c is not x:
    temp_list.append('*')
  else:
    temp_list.append(c)

print(''.join(temp_list))

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

x = s[k-1]
temp_list = []

for c in s:
  if c is not x:
    temp_list.append('*')
  else:
    temp_list.append(c)

print(''.join(temp_list))
Buggy python submission (verdict: Runtime Error):
from collections import Counter

s = input()
odd = [int(s[i]) for i in range(len(s)) if i % 2]
even = [int(s[i]) for i in range(len(s)) if not i % 2]

odd_c = Counter(odd)
freq_odd = odd_c.most_common()
even_c = Counter(even)
freq_even = even_c.most_common()

if len(odd) == 0 or len(even) == 0:
  count = 0
elif len(freq_odd) == 1 or len(freq_even) == 1:
  if len(freq_odd) > len(freq_even):
    if freq_even[0][0] ==  0:
      count = freq_odd[1][1]
    else:
      count = freq_odd[0][1]
  else:
    if freq_odd[0][0] ==  0:
      count = freq_even[1][1]
    else:
      count = freq_even[0][1]
else:
  if freq_odd[0][1] >= freq_even[0][1]:
    count = freq_even[0][1] + freq_odd[1][1]
  else:
    count = freq_odd[0][1] + freq_even[1][1]

print(count)

Fixed submission:
s = input()

if len(s) % 2:
  white_black = '10' * (len(s) // 2) + '1'
  black_white = '01' * (len(s) // 2) + '0'
else:
  white_black = '10' * (len(s) // 2)
  black_white = '01' * (len(s) // 2)

if s == white_black or s == black_white:
  count = 0
else:
  diff_wb = sum([len(x) for x, y in zip(s, white_black) if x != y])
  diff_bw = sum([len(x) for x, y in zip(s, black_white) if x != y])
  count = min(diff_wb, diff_bw)

print(count)
Buggy python submission (verdict: Runtime Error):
s = input()
acgt = {'A', 'C', 'G', 'T'}
count = 0
temp_list= []

for c in s:
  if c in acgt:
    count += 1
  else:
    temp_list.append(count)
    count = 0

print(max(temp_list))

Fixed submission:
s = input()
acgt = {'A', 'C', 'G', 'T'}
count = 0
temp_list= []

for c in s:
  if c in acgt:
    count += 1
  else:
    count = 0
  
  temp_list.append(count)
  
print(max(temp_list))
Buggy python submission (verdict: Time Limit Exceeded):
import re
pattern = re.compile('01|10')

def remove(tower, count):
  m = pattern.split(tower)
  operation = len(m) - 1
  print(count * 2) if operation == 0 else remove(''.join(m), count + operation)  

count = 0
remove(input(), count)


Fixed submission:
s = input()
zero = len([x for x in s if x == "0"])
one = len(s) - zero

print(min(zero, one) * 2)

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

pattern = re.compile(r'01|10')

def remove(tower, count):
  target = len(pattern.findall(tower))
  if target:
    remove(pattern.sub('', tower), count + target)
  else:
    print(count * 2)

count = 0
remove(input(), count)

Fixed submission:
s = input()
zero = len([x for x in s if x == "0"])
one = len(s) - zero

print(min(zero, one) * 2)

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

pattern = re.compile(r'01|10')

def remove(tower, count):
  target = len(pattern.findall(tower))
  if target:
    tower = pattern.sub('', tower)
    remove(tower, count + target)
  else:
    print(count * 2)

count = 0
remove(input(), count)

Fixed submission:
s = input()
zero = len([x for x in s if x == "0"])
one = len(s) - zero

print(min(zero, one) * 2)
Buggy python submission (verdict: Runtime Error):
import re, sys
input = sys.stdin.readline

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

h, w = map(int, input().split())

for i in range(h):
  col = my_index(input().split(), 'snuke')
  if col == False:
    row = i + 1
    break

alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
print(alphabet[col] + str(row))

Fixed submission:
import sys
input = sys.stdin.readline
alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ans = 'snake'
h, w = map(int, input().split())

for i in range(h):
  i += 1
  s = [x for x in input().split()]
  if 'snuke' in s:
    ans = alphabet[s.index('snuke')] + str(i)
    break

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

n,m = map(int, input().split())
h_a = list(map(int, input().split()))

m_l = [[0,0]]*m
for i in range(m):
  m_l[i] = list(map(int, input().split()))

cnt = 0
for ni in range(n):
  t = h_a[ni]
  for r in m_l:
    com = -1;
    if r[0] - 1 == ni:
      com = h_a[r[1] - 1]
    elif r[1] - 1 == ni:
      com = h_a[r[0] - 1]
    if com >= t:
      t = float('inf')
      break

  if t==h_a[ni]:
    cnt += 1

print(cnt)

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

m_l = [[0,0]]*m
r_l = [{}]*n
for i in range(m):
  r = list(map(int, input().split()))
  a = r[0] - 1
  b = r[1] - 1

  ral = set([]) if len(r_l[a]) == 0 else r_l[a]
  rbl = set([]) if len(r_l[b]) == 0 else r_l[b]

  ral.add(b)
  rbl.add(a)

  r_l[a] = ral
  r_l[b] = rbl

cnt = 0
for ni in range(n):
  for r in r_l[ni]:
    if h_a[r] >= h_a[ni]:
      break
  else:
    cnt+=1

print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
x = int(input())

x_r = x**(1/5).real
for a in range(round(x_r), 10**9):
  f_a = a**5
  r_b = (x-f_a)**(1/5).real
  b = round(r_b.real)
  if f_a - b**5 == x:
    print(a, b)
    break
  b *= -1
  if f_a - b**5 == x:
    print(a, b)
    break

Fixed submission:
x = int(input())

for a in range(-120, 120):
  f_a = a**5
  r_b = (x-f_a)**(1/5).real
  b = round(r_b.real)
  if f_a - b**5 == x:
    print(a, b)
    break
  b *= -1
  if f_a - b**5 == x:
    print(a, b)
    break

Buggy python submission (verdict: Time Limit Exceeded):
x = int(input())

for a in range(1, 10**9):
  f_a = a**5
  r_b = (x-f_a)**(1/5).real
  b = round(r_b.real)
  if f_a - b**5 == x:
    print(a, b)
    break
  b *= -1
  if f_a - b**5 == x:
    print(a, b)
    break

Fixed submission:
x = int(input())

for a in range(-120, 120):
  f_a = a**5
  r_b = (x-f_a)**(1/5).real
  b = round(r_b.real)
  if f_a - b**5 == x:
    print(a, b)
    break
  b *= -1
  if f_a - b**5 == x:
    print(a, b)
    break
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int, input().split()))

m = 0
t = 0

for i in range(1, n):
    count = A.count(i)
    print(count)
    m += count
    t = i
    if m == n - 1:
        break
for _ in range(t, n):
    print(0)


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

# m = 0
# t = 0

# for i in range(1, n):
#     count = A.count(i)
#     print(count)
#     m += count
#     t = i
#     if m == n - 1:
#         break
# for _ in range(t, n):
#     print(0)

B = [0] * n
for i in A:
    B[i-1] += 1
for i in B:
    print(i)

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

m = 0
t = 0

for i in range(1, n):
    count = A.count(i)
    print(count)
    m += count
    t = i
    if m == n - 1:
        break
for _ in range(t, n):
    print(0)


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

# m = 0
# t = 0

# for i in range(1, n):
#     count = A.count(i)
#     print(count)
#     m += count
#     t = i
#     if m == n - 1:
#         break
# for _ in range(t, n):
#     print(0)

B = [0] * n
for i in A:
    B[i-1] += 1
for i in B:
    print(i)

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

m = 0
t = 0

for i in range(1, n):
    count = A.count(i)
    print(count)
    m += count
    t = i
    if m == n - 1:
        break
for _ in range(t, n):
    print(0)


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

# m = 0
# t = 0

# for i in range(1, n):
#     count = A.count(i)
#     print(count)
#     m += count
#     t = i
#     if m == n - 1:
#         break
# for _ in range(t, n):
#     print(0)

B = [0] * n
for i in A:
    B[i-1] += 1
for i in B:
    print(i)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int, input().split()))

for i in range(1, n+1):
    count = A.count(i)
    print(count)


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

# m = 0
# t = 0

# for i in range(1, n):
#     count = A.count(i)
#     print(count)
#     m += count
#     t = i
#     if m == n - 1:
#         break
# for _ in range(t, n):
#     print(0)

B = [0] * n
for i in A:
    B[i-1] += 1
for i in B:
    print(i)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())

for i in range(2**n):
    # if k ** (i - 1) - 1 < n <= k ** i - 1:
    if n <= k ** i - 1:
        print(i)
        exit()


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

for i in range(2**31):
    if n <= k ** i - 1:
        print(i)
        exit()

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())

for i in range(2**n):
    if k ** (i - 1) - 1 < n <= k ** i - 1:
        print(i)
        exit()


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

for i in range(2**31):
    if n <= k ** i - 1:
        print(i)
        exit()
Buggy python submission (verdict: Time Limit Exceeded):
n, k, q = map(int, input().split())
A = [int(input()) for _ in range(q)]
# print(A)
for i in range(1, n + 1):
    if k - q + (A.count(i)) > 0:
        print('Yes')
    else:
        print('No')


Fixed submission:
n, k, q = map(int, input().split())
Point = [k - q] * n
for _ in range(q):
    Point[int(input()) - 1] += 1

for e in Point:
    if e > 0:
        print('Yes')
    else:
        print('No')
Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
aa = 10 * ((a + 9) // 10)
bb = 10 * ((b + 9) // 10)
cc = 10 * ((c + 9) // 10)
dd = 10 * ((d + 9) // 10)
ee = 10 * ((e + 9) // 10)
x = min(set([a%10,b%10,c%10,d%10,e%10]) - {0})
# print(x)
print(aa+bb+cc+dd+ee-(10-x))


Fixed submission:
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
aa = 10 * ((a + 9) // 10)
bb = 10 * ((b + 9) // 10)
cc = 10 * ((c + 9) // 10)
dd = 10 * ((d + 9) // 10)
ee = 10 * ((e + 9) // 10)
if len(set([a%10,b%10,c%10,d%10,e%10]) - {0}) > 0:
    x = min(set([a%10,b%10,c%10,d%10,e%10]) - {0})
else:
    x = 10
# print(x)
print(aa+bb+cc+dd+ee-(10-x))

Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
aa = 10 * ((a + 9) // 10)
bb = 10 * ((b + 9) // 10)
cc = 10 * ((c + 9) // 10)
dd = 10 * ((d + 9) // 10)
ee = 10 * ((e + 9) // 10)
x = min(set([a%10,b%10,c%10,d%10,e%10]) - {0})
print(x)
print(aa+bb+cc+dd+ee-(10-x))


Fixed submission:
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
aa = 10 * ((a + 9) // 10)
bb = 10 * ((b + 9) // 10)
cc = 10 * ((c + 9) // 10)
dd = 10 * ((d + 9) // 10)
ee = 10 * ((e + 9) // 10)
if len(set([a%10,b%10,c%10,d%10,e%10]) - {0}) > 0:
    x = min(set([a%10,b%10,c%10,d%10,e%10]) - {0})
else:
    x = 10
# print(x)
print(aa+bb+cc+dd+ee-(10-x))
Buggy python submission (verdict: Runtime Error):
S = list(input())
A = ['A', 'C', 'G', 'T']
T = []
ans = 0
for e in S:
	if e in A:
		ans += 1
	else:
		T.append(ans)
		ans = 0
print(max(T))

Fixed submission:
S = list(input())
A = ['A', 'C', 'G', 'T']
T = []
ans = 0
for e in S:
	if e in A:
		ans += 1
	else:
		T.append(ans)
		ans = 0
T.append(ans)
print(max(T))
Buggy python submission (verdict: Runtime Error):
k = int(input())
print(k//2 ** 2) if k % 2 == 0 else pritn(k//2 * (k//2 + 1))

Fixed submission:
k = int(input())
print((k//2) ** 2) if k % 2 == 0 else print(k//2 * (k//2 + 1))
Buggy python submission (verdict: Runtime Error):
#n:shinamono no kazu
#m:waribiki maisuu
import heapq

n,m=map(int,input().split())

a=heaqp.heapify(list(map(lambda x : int(x)*(-1),input().split())))

for _ in range(m):
  minA=heapq.heappop(a)
  heapq.heappush(a,minA/2.0)
#print(a)
result=0
for item in a:
  result+=item*(-1)//1
  
print(int(result))


Fixed submission:
#n:shinamono no kazu
#m:waribiki maisuu
import heapq

n,m=map(int,input().split())
a=list(map(lambda x:int(x)*(-1),input().split()))
#print(temp)
heapq.heapify(a)
for _ in range(m):
  minA=heapq.heappop(a)
  #print(minA)
  heapq.heappush(a,minA/2.0)
  #print(a)
#print(a)
result=0
for item in a:
  result+=item*(-1)//1
  
print(int(result))

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect

#n:shinamono no kazu
#m:waribiki maisuu

n,m=map(int,input().split())

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

indexMax=len(a)-1

for _ in range(m):
  maxA=a[indexMax]
  a.pop(indexMax)
  a.insert(bisect(a, maxA/2.0), maxA/2.0)

#print(a)
result=0
for item in a:
  result+=item//1
  
print(int(result))

Fixed submission:
#n:shinamono no kazu
#m:waribiki maisuu
import heapq

n,m=map(int,input().split())
a=list(map(lambda x:int(x)*(-1),input().split()))
#print(temp)
heapq.heapify(a)
for _ in range(m):
  minA=heapq.heappop(a)
  #print(minA)
  heapq.heappush(a,minA/2.0)
  #print(a)
#print(a)
result=0
for item in a:
  result+=item*(-1)//1
  
print(int(result))

Buggy python submission (verdict: Time Limit Exceeded):
#n:shinamono no kazu
#m:waribiki maisuu

n,m=map(int,input().split())

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

for _ in range(m):
  maxA=max(a)
  a.remove(maxA)
  a.append(maxA/2)
#print(a)
result=0
for item in a:
  result+=item//1
  
print(int(result))

Fixed submission:
#n:shinamono no kazu
#m:waribiki maisuu
import heapq

n,m=map(int,input().split())
a=list(map(lambda x:int(x)*(-1),input().split()))
#print(temp)
heapq.heapify(a)
for _ in range(m):
  minA=heapq.heappop(a)
  #print(minA)
  heapq.heappush(a,minA/2.0)
  #print(a)
#print(a)
result=0
for item in a:
  result+=item*(-1)//1
  
print(int(result))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
r=[[0]*(n+1) for _ in range(n+1)]

#print(r)

maxV=0
for i in range(n):
  for j in  range(n):
    ii=n-1-i
    jj=n-1-j
    if s[ii]==s[jj]:
      r[ii][jj]=min(r[ii+1][jj+1]+1,abs(ii-jj))
      maxV=max(maxV,r[ii][jj])

print(maxV)

Fixed submission:
n=int(input())
s=input()
r=[[0]*(n+1) for _ in range(n+1)]

#print(r)

maxV=0
for i in range(n):
  for j in  range(n):
    ii=n-1-i
    jj=n-1-j
    if s[ii]==s[jj]:
      r[ii][jj]=min(r[ii+1][jj+1]+1,abs(ii-jj))
      maxV=max(maxV,r[ii][jj])

print(maxV)
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))[::-1]


i=0
result=0

while i<n-1:
  maxV=max(a[i],a[i+1])
  temp=min(a[i],a[i+1])
  result+=temp
  j=i+2
  while j<n:
    if temp>a[j]:
      result+=temp
      #print(i,j)
    else:
      if a[j]>maxV:
        temp=maxV
        result+=temp
        maxV=a[j]
      else:
        temp=a[j]
        result+=temp
    #print(i,j,temp)
        
    j+=1
  
  i+=1
  
print(result)
  


Fixed submission:
n=int(input())
print(n**3)
Buggy python submission (verdict: Runtime Error):
#b is limit
a,b=map(int,input().split())
r=input()

if len(r)==1:
  print(0)
  exit()
  
i=1  
count=0
while i<len(r):
  if r[i-1:i+1]=="RL":
    count+=1
  i+=1
result=(a-1)-2*max(0,count-b)

if r[0]!=r[-1]:
  count-b<=0:
    result-=1

  
print(result)
  



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

c=0
for i in range(1,n):
  if r[i-1]==r[i]:
    c+=1
  
print(min(n-1,c+2*k))
Buggy python submission (verdict: Runtime Error):
n=int(input())
r=list(range(1,n+1))

#print(r)
print(sum(r)-(n))

Fixed submission:
n=int(input())
sumNum=n*(n-1)//2

#print(r)
print(sumNum)
Buggy python submission (verdict: Runtime Error):
#N is numbers of BAITO, M is limit of days
N,M=map(int,input().split())

i=0
inp ={}
while i<N:
  readTime,inCome=map(int,input().split())
  if readTime in inp:
    inp[readTime].append(inCome)
  else:
    inp[readTime]=[inCome]
  
  i=i+1

#print(inp)  

result=0
pool=[]
i=1
while i<=M:
  if i in inp:
	  pool=pool+inp[i]
  #print(i,pool)
  
  if len(pool)>0:
    result=result+max(pool)
    pool.remove(max(pool))
    #print(pool)
  
  i=i+1
 
print(result)

Fixed submission:
A,B =map(int,input().split())
print(max([A+B,A-B,A*B]))
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())

i=0
sortedSet=[]
result=0
while i<N:
  temp=''.join(sorted(input()))
  sortedSet.append(temp)
  j=0
  while j<i:
    if sortedSet[j]==temp:
      result=result+1
    j=j+1
  i=i+1

print(result)

Fixed submission:
N=int(input())
 
i=0
sortedSet={}
while i<N:
  temp=''.join(sorted(input()))
  
  if temp in sortedSet:
    sortedSet[temp]=sortedSet[temp]+1
  else:
    sortedSet[temp]=1
  i=i+1

  
result=0
for v in sortedSet.values():
  result=int(result+v*(v-1)/2)
 
print(result)

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

i=0
sortedSet=[]

while i<N:
  temp=input()
  tempSet={}
  j=0
  while j<len(temp):
    if temp[j] in tempSet:
      tempSet[temp[j]]=tempSet[temp[j]]+1
    else:
      tempSet[temp[j]]=1
    j=j+1
  #print(tempSet)
  sortedSet.append(tempSet)
  i=i+1

result=0
i=0
while i<N:
  j=i+1
  while j<N:
    if sortedSet[i]==sortedSet[j]:
      result=result+1
      #print(i,j)
    j=j+1
  i=i+1

print(result)

Fixed submission:
N=int(input())
 
i=0
sortedSet={}
while i<N:
  temp=''.join(sorted(input()))
  
  if temp in sortedSet:
    sortedSet[temp]=sortedSet[temp]+1
  else:
    sortedSet[temp]=1
  i=i+1

  
result=0
for v in sortedSet.values():
  result=int(result+v*(v-1)/2)
 
print(result)

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

i=0
sortedSet=[]

while i<N:
  temp=input()
  tempSet=[]
  j=0
  while j<len(temp):
    tempSet.append(temp[j])
    j=j+1
  tempSet.sort()
  #print(tempSet)
  sortedSet.append(tempSet)
  i=i+1

result=0
i=0
while i<N:
  j=i+1
  while j<N:
    if sortedSet[i]==sortedSet[j]:
      result=result+1
      #print(i,j)
    j=j+1
  i=i+1

print(result)

Fixed submission:
N=int(input())
 
i=0
sortedSet={}
while i<N:
  temp=''.join(sorted(input()))
  
  if temp in sortedSet:
    sortedSet[temp]=sortedSet[temp]+1
  else:
    sortedSet[temp]=1
  i=i+1

  
result=0
for v in sortedSet.values():
  result=int(result+v*(v-1)/2)
 
print(result)