from bisect import bisect_left

n = int(input())
s = list(map(int, input().split()))

first = max(s)
made = [first]
s.remove(first)
s.append(0)
s.sort()

for _ in range(n):
    made_now = []
    for e in made:
        i = bisect_left(s, e)
        make = s.pop(i - 1)
        if make == 0:
            print("No")
            exit()
        made_now.append(make)

    made += made_now

print("Yes")

from heapq import heappush, heappop
from copy import deepcopy

n = int(input())
s = list(map(int, input().split()))

left = []
for e in s:
    heappush(left, -e)
mx = heappop(left)

made = []
heappush(made, mx)

for _ in range(n):
    made_nxt = deepcopy(made)
    tmp = []

    while made:
        made_val = heappop(made)
        while left and left[0] <= made_val:
            pp = heappop(left)
            tmp.append(pp)

        if not left:
            print("No")
            exit()

        left_val = heappop(left)
        heappush(made_nxt, left_val)

    made = made_nxt

    for e in tmp:
        heappush(left, e)

print("Yes")


from heapq import heappush, heappop
from copy import deepcopy

n = int(input())
s = list(map(int, input().split()))

left = []
for e in s:
    heappush(left, -e)
mx = heappop(left)

made = []
heappush(made, mx)

for _ in range(n):
    made_prev = deepcopy(made)
    tmp = []

    while made_prev:
        made_val = heappop(made_prev)
        while left and left[0] <= made_val:
            pp = heappop(left)
            tmp.append(pp)

        if not left:
            print("No")
            exit()

        left_val = heappop(left)
        heappush(made, left_val)

    for e in tmp:
        heappush(left, e)

print("Yes")

from heapq import heappush, heappop
from copy import deepcopy

def main():
    n = int(input())
    s = list(map(int, input().split()))

    left = []
    for e in s:
        heappush(left, -e)
    mx = heappop(left)

    made = []
    heappush(made, mx)

    for _ in range(n):
        made_prev = deepcopy(made)
        tmp = []

        while made_prev:
            made_val = heappop(made_prev)
            while left and left[0] <= made_val:
                pp = heappop(left)
                tmp.append(pp)

            if not left:
                print("No")
                exit()

            left_val = heappop(left)
            heappush(made, left_val)

        for e in tmp:
            heappush(left, e)

    print("Yes")

if __name__ == "__main__":
    main()


def main(S, T):
    count = 0

    for i in range(len(S)):
        if T[i] == S[i]:
            count += 1

    return count

if __name__ == "__main__":
    S, T = map(str, input().split())
    print(main(S, T))

def main(S, T):
    count = 0

    for i in range(len(S)):
        if T[i] == S[i]:
            count += 1

    return count

if __name__ == "__main__":
    S = input()
    T = input()
    print(main(S, T))

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02921/Python/s746445364.py", line 12, in <module>
    S, T = map(str, input().split())
ValueError: not enough values to unpack (expected 2, got 1)


S = list(input())
T = list(input())

i = 0
ans_cnt = 0

while i < len(S):
    i += 1
    if S[i] == T[i]:
        ans_cnt += 1

print(ans_cnt)

S = list(input())
T = list(input())

i = 0
ans_cnt = 0

while i < len(S):
    if S[i] == T[i]:
        ans_cnt += 1
    i += 1

print(ans_cnt)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02921/Python/s479288383.py", line 9, in <module>
    if S[i] == T[i]:
IndexError: list index out of range


def main(s, t):
    s = list(input())
    t = list(input())
    assert len(s) == len(t)
    res = 0
    for i, ss in enumerate(s):
        if ss == t[i]:
            res += 1
    return res

if __name__ == "__main__":
    main()

def main():
    s = list(input())
    t = list(input())
    assert len(s) == len(t)
    res = 0
    for i, ss in enumerate(s):
        if ss == t[i]:
            res += 1
    print(res)

if __name__ == "__main__":
    main()

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02921/Python/s322260042.py", line 13, in <module>
    main()
TypeError: main() missing 2 required positional arguments: 's' and 't'


s = input().split()
t = input().split()

ans = 0
for i in range(3):
    if s[i] == t[i]:
        ans += 1

print(ans)

s = list(input())
t = list(input())

ans = 0
for i in range(3):
    if s[i] == t[i]:
        ans += 1

print(ans)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02921/Python/s694576581.py", line 6, in <module>
    if s[i] == t[i]:
IndexError: list index out of range


s, t = input()
print(sum(s[i] == t[i] for i in range(3)))

s = input()
t = input()
print(sum(s[i] == t[i] for i in range(3)))

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02921/Python/s393555435.py", line 1, in <module>
    s, t = input()
ValueError: too many values to unpack (expected 2)


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

if B == 1:
    print(0)
else:
    C = A
    cnt = 1
    while C < B:
        C += A - 1
        cnt += 1

print(cnt)


S = input()
List = [input() for i in range(1)]
T = List[0]

Slst = list(S)
Tlst = list(T)
M = 0

for x in range(3):
    if Slst[x] == Tlst[x]:
        M += 1
print(M)

lst = [int(x) for x in input().split()]
A = lst[0]
B = lst[1]

if B >= 2:
    m = 0
    while (A - 1) * m + 1 < B:
        m += 1
    print(m)

if B == 1:
    print(0)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02922/Python/s688512487.py", line 2, in <module>
    List = [input() for i in range(1)]
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02922/Python/s688512487.py", line 2, in <listcomp>
    List = [input() for i in range(1)]
EOFError: EOF when reading a line


A = int(input())
B = int(input())
count = 1

while A < B:
    A += A
    count += 1
    if A > B:
        break

print(count)

A = input().split()
count = 1
a = int(A[0])
b = int(A[1])
c = a

if b == 1:
    print(0)
else:
    while a < b:
        a += c - 1
        count += 1
        if a > b:
            break
    print(count)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02922/Python/s307369986.py", line 1, in <module>
    A = int(input())
ValueError: invalid literal for int() with base 10: '4 10'


def main():
    N = int(input())
    H = [int(x) for x in input().split()]
    ans = []
    count = 0
    if N > 2:
        for i in range(1, N):
            j = i + 1
            if H[-i] <= H[-j]:
                count += 1
            else:
                ans.append(count)
                count = 0
    elif N == 2:
        if H[0] >= H[1]:
            ans.append(1)
    elif N == 1:
        ans.append(1)

    print(max(ans))

if __name__ == "__main__":
    main()

def main():
    N = int(input())
    H = [int(x) for x in input().split()]
    ans = 0
    count = 0

    if N == 2:
        if H[0] >= H[1]:
            ans = 1
    elif N > 2:
        for i in range(1, N):
            j = i + 1
            if H[-i] <= H[-j]:
                count += 1
                if j == N:
                    if ans <= count:
                        ans = count
            else:
                if ans <= count:
                    ans = count
                count = 0
    print(ans)

if __name__ == "__main__":
    main()


#!/usr/bin/env python3
n = int(input())
h = list(map(int, input().split()))
ans = 0
for i in range(n):
    tmp = 0
    for j in range(i, n - 1):
        if h[j] < h[j + 1]:
            tmp = 0
        else:
            tmp += 1
        ans = max(ans, tmp)
print(ans)

#!/usr/bin/env python3
n = int(input())
h = list(map(int, input().split()))
ans = 0
tmp = 0
for i in range(n - 1):
    if h[i] < h[i + 1]:
        tmp = 0
    else:
        tmp += 1
    ans = max(ans, tmp)
print(ans)


def resolve():
    N = int(input())
    H = [int(i) for i in input().split()]
    maxM = 0
    for i in range(N - 1):
        m = 0
        for j in range(i, N - 1):
            if H[j] < H[j + 1]:
                break
            else:
                m += 1
        maxM = max(maxM, m)
    print(maxM)

resolve()

def resolve():
    N = int(input())
    H = [int(i) for i in input().split()]
    maxM = 0
    m = 0
    for i in range(N - 1):
        if H[i] < H[i + 1]:
            m = 0
        else:
            m += 1
            maxM = max(maxM, m)
    print(maxM)

resolve()


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

if N == 1:
    print(0)
else:
    ans = 0
    H1 = H[0]
    H2 = H[1]
    count = 1
    move = 0
    while count != (N):
        count += 1
        if H2 <= H1:
            move += 1
            ans = max(ans, move)
        else:
            move = 0
        if count != N:
            H1 = H2
            H2 = H[count]

print(ans)

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

if N == 1:
    print(0)
else:
    ans = 0
    H1 = H[0]
    H2 = H[1]
    count = 1
    move = 0
    while count != N:
        count += 1
        if H2 <= H1:
            move += 1
            ans = max(ans, move)
        else:
            move = 0
        if count != N:
            H1 = H2
            H2 = H[count]

    print(ans)


n = int(input())
hh = list(map(int, input().split()))

ans = 0
for i in range(n - 1, 0, -1):
    x = 1
    while i + x < n and hh[i + x - 1] >= hh[i + x]:
        x += 1
    ans = max(ans, x - 1)
print(ans)

n = int(input())
h = list(map(int, input().split()))

ans = 0
x = 0
for i in range(1, n):
    if h[i - 1] >= h[i]:
        x += 1
    else:
        x = 0
    ans = max(ans, x)
print(ans)


# coding: utf-8
n = int(input())
lst = list(map(int, input().split()))
cnt = 0
data = []
for i in range(n - 1):
    if lst[i] >= lst[i + 1]:
        cnt += 1
    else:
        data.append(cnt)
        cnt = 0
print(max(cnt))

# coding: utf-8
n = int(input())
lst = list(map(int, input().split()))
cnt = 0
data = []
for i in range(n - 1):
    if lst[i] >= lst[i + 1]:
        cnt += 1
    else:
        data.append(cnt)
        cnt = 0
data.append(cnt)
print(max(data))

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02923/Python/s153309090.py", line 12, in <module>
    print(max(cnt))
TypeError: 'int' object is not iterable


n = input()
h_string = input()
h_list = h_string.split(" ")
for item in h_list:
    item = int(item)

longest = 0
now_value = -1
now_length = 0

for value in h_list:
    if value <= now_value:
        now_length += 1
        now_value = value
        if now_length > longest:
            longest = now_length
    else:
        if now_length > longest:
            longest = now_length
        now_value = value
        now_length = 0

print(longest)

n = input()
h_string = input()
h_list = h_string.split(" ")
for i in range(len(h_list)):
    h_list[i] = int(h_list[i])

longest = 0
now_value = -1
now_length = 0

for value in h_list:
    if value <= now_value:
        now_length += 1
        now_value = value
        if now_length > longest:
            longest = now_length
    else:
        if now_length > longest:
            longest = now_length
        now_value = value
        now_length = 0

print(longest)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02923/Python/s196465841.py", line 14, in <module>
    if value <= now_value:
TypeError: '<=' not supported between instances of 'str' and 'int'


n = int(input())
h = list(map(int, input().split()))

max_step = 0
for i in range(n):
    current_step = 0
    for j in range(i + 1, n):
        if h[j - 1] >= h[j]:
            current_step += 1
            if current_step > max_step:
                max_step = current_step
        else:
            i = j
            break
print(max_step)

n = int(input())
h = list(map(int, input().split()))

max_step = 0
current_step = 0
for i in range(n - 1):
    if h[i] >= h[i + 1]:
        current_step += 1
        if current_step > max_step:
            max_step = current_step
    else:
        current_step = 0
print(max_step)


# -*- coding: utf-8 -*-
# 整数の入力

def main():
    n = int(input())
    h = list(map(int, input().split()))

    result = []
    count = 0
    for i in range(n - 1):
        if h[i] < h[i + 1]:
            result.append(count)
            count = 0
            continue

        count += 1
        if i == n - 2:
            result.append(count)

    print(max(result))

if __name__ == "__main__":
    main()

# -*- coding: utf-8 -*-
# 整数の入力

def main():
    n = int(input())
    h = list(map(int, input().split()))

    if n == 1:
        print(0)
        return

    result = []
    count = 0
    for i in range(n - 1):
        if h[i] < h[i + 1]:
            result.append(count)
            count = 0
            continue

        count += 1
        if i == n - 2:
            result.append(count)

    print(max(result))

if __name__ == "__main__":
    main()


n = int(input())
height = list(map(int, input().split()))
max_count = 0
for i in range(n):
    count = 0
    for j in range(i, n):
        if j == n - 1 or height[j] < height[j + 1]:
            break
        count += 1
    max_count = max(max_count, count)
print(max_count)

n = int(input())
height = list(map(int, input().split()))
max_count = 0
count = 0
for i in range(n - 1):
    if height[i] < height[i + 1]:
        max_count = max(count, max_count)
        count = 0
        continue
    count += 1
max_count = max(count, max_count)
print(max_count)


n = int(input())
hlist = list(map(int, input().split()))
delta = [hlist[i + 1] - hlist[i] for i in range(len(hlist) - 1)]

counter = 0
for i in range(len(delta)):
    if delta[i] <= 0:
        counter += 1
    else:
        ans = counter
        counter = 0
ans = max(ans, counter)
print(ans)

n = int(input())
h = list(map(int, input().split()))

counter, ans = 0, 0
for i in range(len(h) - 1):
    if h[i] >= h[i + 1]:
        counter += 1
    else:
        if ans <= counter:
            ans = counter
        counter = 0
ans = max(ans, counter)

print(ans)


n = int(input())
h = list(map(int, input().split()))

ans = 0
for left in range(n - 1):
    right = left + 1
    length = 0
    while right < n and h[right - 1] >= h[right]:
        length += 1
        right += 1
    ans = max(ans, length)
print(ans)

n = int(input())
h = list(map(int, input().split()))

dp = [0] * n
dp[0] = 0
ans = 0
for i in range(1, n):
    if h[i - 1] >= h[i]:
        if dp[i - 1] == 0:
            dp[i] = 1
        else:
            dp[i] = dp[i - 1] + 1
        ans = max(dp[i], ans)
print(ans)


from sys import stdin

n = int(stdin.readline().rstrip())
h = [int(x) for x in stdin.readline().rstrip().split()]

m = 0
count = 0
for i in range(n):
    if (i == n - 1) and (m < count):
        m = count
    else:
        if h[i] >= h[i + 1]:
            count += 1
        else:
            if m < count:
                m = count
            count = 0

print(m)

from sys import stdin

n = int(stdin.readline().rstrip())
h = [int(x) for x in stdin.readline().rstrip().split()]

m = 0
count = 0
for i in range(n):
    if i == n - 1:
        if m < count:
            m = count
    else:
        if h[i] >= h[i + 1]:
            count += 1
        else:
            if m < count:
                m = count
            count = 0

print(m)


N = int(input())
print(sum(list(range(N))))


N = int(input())

c = 0
for i in range(1, N):
    c += i

print(c)

N = int(input())
print(N * (N - 1) // 2)


n = int(input())

sum = 0
for i in range(n):
    sum += i

print(sum)


# -*- coding: utf-8 -*-
# 整数の入力

def main():
    n = int(input())
    ans = 0
    for i in range(1, n + 1):
        ans += i - 1
    print(ans)

if __name__ == "__main__":
    main()

# -*- coding: utf-8 -*-
# 整数の入力
from decimal import Decimal

def main():
    n = int(input())

    if n == 1:
        print(0)
        return

    # print(int(n ** 2 - n))
    # print((n ** 2 - n) / 2)
    # print(n * (n - 1))
    # print(n * (n - 1) / 2)
    ans = int(Decimal(n * (n - 1)) / 2)
    print(ans)
    # print(ans * 2)

if __name__ == "__main__":
    main()


n = int(input())
sum = 0
for i in range(n):
    sum += i

print(sum)

n = int(input())
if n % 2 == 0:
    sum = int(n / 2)
    sum = sum * (n - 1)

else:
    sum = int((n - 1) / 2)
    sum = sum * n

print(int(sum))


N = int(input())

result = 0
for i in range(N):
    result += i

print(result)

N = int(input())

n = N - 1
result = 0

if n != 0:
    result = n * (n + 1) // 2

print(result)


N = int(input())
max = 0

for i in range(N):
    max += i

print(max)

N = int(input())
max = 0

print((N - 1) * N // 2)


n = int(input())
ans = 0
for i in range(1, n):
    ans += i
print(ans)

n = int(input())
print(n * (n - 1) // 2)


N = int(input())
print((N - 1) * N // 2)


n = int(input())
ans = 0

for i in range(1, n):
    ans += i

print(ans)


n = int(input())
a = list(range(1, n))
print(sum(a))

n = int(input())
ans = (n - 1) * (1 + n - 1) // 2
print(ans)


n = int(input())

a = list(range(1, n))

print(sum(a))


n = int(input())

ans = 0
for i in range(n):
    ans += i

print(ans)

n = int(input())

ans = n * (n - 1) // 2

print(ans)


N = int(input())
print(sum(range(1, N)))


N = int(input())
ans = 0

for i in range(1, N):
    ans += i

print(ans)


N = int(input())
print(sum(list(range(N))[1:]))


n = int(input())
print(sum(x for x in range(n)))


N = int(input())
res = 0
for i in range(N):
    res += i
print(res)

N = int(input())
res = int(N * (N - 1) // 2)
print(res)


# from math import factorial,sqrt
# from itertools import permutations as permus
# from fractions import gcd
# from collections import deque,Counter
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import scipy as scp

# 入力の受け取り
n = int(input())

ans = sum(range(n))

print(ans)
# print("{:.10f}".format(ans))

# from math import factorial,sqrt
# from itertools import permutations as permus
# from fractions import gcd
# from collections import deque,Counter
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import scipy as scp

# 入力の受け取り
n = int(input())

n = n - 1

ans = (1 + n) * n // 2

print(ans)
# print("{:.10f}".format(ans))


N = int(input())

x = [i + 1 for i in range(N)]

print(sum(x) - N)

N = int(input())

print(N * (N + 1) // 2 - N)


N = int(input())
ans = 0

for i in range(N):
    ans += i

print(ans)


# -*- coding: utf-8 -*-
n = int(input())

tmp = [i for i in range(1, n + 1)]
print(sum(tmp) - n)

# -*- coding: utf-8 -*-
n = int(input())

su = n * (n + 1) // 2
print(su - n)


a = int(input())
sum = 0
for i in range(a):
    sum += i
print(sum)

a = int(input())
sum = 0
sum = (a - 1) * a // 2
print(sum)


N = int(input())

list = list(range(N))

print(sum(list))

N = int(input())

print(N * (N - 1) // 2)


N = int(input())

ans = 0
for n in range(1, N):
    ans += n
print(ans)


N = int(input())

print(sum(i % (i + 1) for i in range(1, N)))

N = int(input())

print(int(N * (N - 1) // 2))


N = int(input())
print(sum(v for v in range(N)))


N = int(input())

if N == 1:
    print(0)
else:
    print(sum([i for i in range(1, N)]))


n = int(input())

print(n * (n - 1) // 2)


n = int(input())

ans = 0
for i in range(1, n):
    ans += i

print(ans)


def main():
    n = int(input())
    print(sum(range(n)))

main()

def main():
    n = int(input())
    print((n - 1) * n // 2)

main()


N = int(input())
print(sum([i for i in range(N)]))

N = int(input())
print(N * (N - 1) // 2)


n = int(input())
m = 0

for i in range(n):
    t = i + 1
    if t == n:
        m += 0
    else:
        m += t % (t + 1)

print(m)

n = int(input())

m = n * (n - 1) // 2

print(m)


n = int(input())
r = 0
for i in range(n):
    r += i
print(r)


n = int(input())
ans = 0

for i in range(n):
    ans += i
print(ans)

n = int(input())
ans = 0

print((n * (n - 1)) // 2)


n = int(input())
ans = 0
for i in range(n):
    ans += i
print(ans)


n = int(input())
print((n - 1) * n // 2)


N = int(input())
# print(sum([i for i in range(N)]))
print(N * (0 + N - 1) // 2)


N = int(input())

ans = 0
for i in range(N):
    ans += i
print(ans)

N = int(input())

ans = N * (N - 1) // 2

print(ans)


n = int(input())
print(n * (n - 1) // 2)


N = int(input())
score = 0

for i in range(1, N):
    score += i

print(score)


n = int(input())

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

n = int(input())

ans = n * (n // 2)
if (n - 1) % 2 == 0:
    print(ans)
else:
    print(ans - int(n / 2))


N = int(input())
print(sum(i for i in range(N)))

N = int(input())
print((N - 1) * N // 2)


n = int(input())
print(sum(range(1, n)))

n = int(input())
ans = n * (n - 1) // 2
print(ans)


n = int(input())
print(sum(i for i in range(1, n)))


n = int(input())

n_list = [i for i in range(1, n)]
ans = sum(n_list)
print(ans)

from decimal import Decimal

n = int(input())

ans = Decimal((n - 1) * n) / 2
print(ans)


# -*- coding: utf-8 -*-

N = int(input())

ans = 0
for y in range(1, N):
    ans += y

print(ans)

# -*- coding: utf-8 -*-

N = int(input())

ans = ((N + 1) * N) // 2
ans -= N

print(ans)


N = int(input())

sum = 0
for i in range(N):
    sum += i

print(sum)


# しらんけど
n = int(input())
print(sum(range(n)))

# しらんけど
# ふつうにこれやったらTLEなったのでアレする
# n = int(input())
# print(sum(range(n)))

n = int(input())
if n % 2 == 0:
    a = (1 + n) * (n // 2)
    print(a - n)
else:
    a = (1 + n) * ((n - 1) // 2) + (n // 2 + 1)
    print(a - n)


N = int(input())

res = 0
for i in range(N):
    res += i

print(res)

N = int(input())

res = (N - 1) * N // 2

print(res)


n = int(input())

ans = n * (n - 1) // 2
print(ans)


n = int(input())

ans = 0

for i in range(1, n):
    ans += i

print(ans)


n = int(input())
num = 0

for i in range(n):
    num = num + i

print(num)

n = int(input())

num = 0

num = n * (n - 1) // 2

print(num)


import sys

N = int(sys.stdin.readline())
print(sum(n + 1 for n in range(N - 1)))

import sys

N = int(sys.stdin.readline())
print(int((N - 1) * N // 2))


N = int(input())

result = 0
for i in range(N):
    result += i
print(result)

N = int(input())

print(N * (N - 1) // 2)


N = int(input())
n = 0
for m in range(N - 1, 0, -1):
    n = n + m
print(n)


n = int(input().strip())
ans = 0
for i in range(n):
    ans = ans + i
print(ans)

import math

n = int(input().strip())
ans = (n * (n - 1)) // 2

print(ans)


# -*- coding: utf-8 -*-
N = int(input())
sum = 0
for i in range(N):
    sum += i
print(sum)

# -*- coding: utf-8 -*-
import math

N = int(input()) - 1
M = 0
x = int(math.ceil((N) / 2))
if N % 2 == 0:
    M = x * (N + 1)
else:
    M = (x - 1) * (N + 1) + x
print(M)


N = int(input())

sum = 0
for i in range(N):
    sum += i
print(sum)


N = int(input())
print(sum([i for i in range(1, N)]))

N = int(input())
print(N * (N - 1) // 2)


n = int(input())

sum = 0
for i in range(1, n):
    sum += i

print(sum)

n = int(input())
print(sum(range(1, n)))


import sys

sys.setrecursionlimit(4100000)

def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins

def solve(inputs):
    [N] = string_to_int(inputs[0])
    count = 0
    for x in range(1, N):
        count += x
    return count

def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))

if __name__ == "__main__":
    ret = solve(inputs(1))
    print(ret)

import sys
import math

sys.setrecursionlimit(4100000)

def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins

def solve(inputs):
    [N] = string_to_int(inputs[0])
    num = N - 1
    if num == 0:
        return 0
    if num == 1:
        return 1
    if num % 2 == 0:
        # half_l = math.floor(num / 2)
        # half = (half_l + half_l + 1) / 2
        half = num // 2
        append = num // 2
    else:
        half = (num + 1) // 2
        append = 0
        # half = math.floor(num / 2)
    return half * num + append

def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))

if __name__ == "__main__":
    ret = solve(inputs(1))
    print(ret)


n = int(input())
ans = 0
for i in range(1, n):
    ans += i
print(ans)


N = int(input())
ans = 0
for i in range(N):
    ans += i

print(ans)


n = int(input())
m = [i for i in range(n)]
print(sum(m))


N = int(input())

lis = [i for i in range(1, N)]

print(sum(lis))

N = int(input())

ans = N * (N - 1) // 2

print(ans)


# 2020/08/16
# AtCoder Beginner Contest 139 - D

# Input
n = int(input())

# Calc
asum = 0
# for i in range(1, n+1):
#     asum = asum + (n + 1 - i) % i
for i in range(1, n):
    asum = asum + i

# Output
print(asum)

# 2020/08/16
# AtCoder Beginner Contest 139 - D

# Input
n = int(input())

# Calc
ans = n * (n - 1) // 2

# Output
print(ans)


import sys

input = sys.stdin.readline

n = int(input())

e = [[] for _ in range(n)]
for i in range(n):
    a = map(int, input().split())
    for aa in a:
        aa -= 1
        e[i].append(aa)
# print(e)

inds = [0] * n
cur = [e[i][0] for i in range(n)]
# print(cur)
cnt = 0
while sum(cur) != -n:
    flg = False
    bls = [False] * n
    for ind, target in enumerate(cur):
        if bls[ind] or bls[target]:
            continue
        if cur[target] == ind:
            flg = True
            inds[ind] += 1
            inds[target] += 1
            bls[ind] = True
            bls[target] = True
            cur[ind] = e[ind][inds[ind]] if inds[ind] < n - 1 else -1
            cur[target] = e[target][inds[target]] if inds[target] < n - 1 else -1
    if not flg:
        print(-1)
        exit()
    cnt += 1
    # print(cur, cnt)

print(cnt)

def check(player):
    if not a[player]:
        return
    opponent = a[player][-1]
    if not a[opponent]:
        return
    if a[opponent][-1] == player:
        tpl = (player, opponent)
        q.add((min(tpl), max(tpl)))

n = int(input())

a = []
for _ in range(n):
    t = list(map(lambda x: int(x) - 1, input().split()))
    t.reverse()
    a.append(t)

q = set()
for i in range(n):
    check(i)

day = 0
while q:
    day += 1
    prev_q = set()
    q, prev_q = prev_q, q
    for player, opponent in prev_q:
        a[player].pop()
        a[opponent].pop()
    for player, opponent in prev_q:
        check(player)
        check(opponent)

if any(a[player] for player in range(n)):
    print(-1)
    exit()

print(day)


from collections import defaultdict

n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]

adj = defaultdict(list)
in_deg = defaultdict(int)
for u, row in enumerate(a, 1):
    for v1, v2 in zip(row, row[1:]):
        uu1, vv1 = min(u, v1), max(u, v1)
        uu2, vv2 = min(u, v2), max(u, v2)
        adj[(uu1, vv1)].append((uu2, vv2))
        in_deg[(uu1, vv1)]
        in_deg[(uu2, vv2)] += 1

now = [tpl for tpl, val in in_deg.items() if val == 0]
day = 0
while now:
    day += 1
    nxt = []
    for u in now:
        for v in adj[u]:
            in_deg[v] -= 1
            if in_deg[v] == 0:
                nxt.append(v)

    now = nxt

if max(in_deg.values()) > 0:
    day = -1

print(day)

from collections import defaultdict

n = int(input())
a = [tuple(map(int, input().split())) for _ in range(n)]

adj = defaultdict(list)
in_deg = defaultdict(int)
for u, row in enumerate(a, 1):
    for v1, v2 in zip(row, row[1:]):
        uu1, vv1 = min(u, v1), max(u, v1)
        uu2, vv2 = min(u, v2), max(u, v2)
        match1 = uu1 + vv1 * 1000
        match2 = uu2 + vv2 * 1000
        adj[match1].append(match2)
        in_deg[match1]
        in_deg[match2] += 1

now = [key for key, val in in_deg.items() if val == 0]
day = 0
while now:
    day += 1
    nxt = []
    for u in now:
        for v in adj[u]:
            in_deg[v] -= 1
            if in_deg[v] == 0:
                nxt.append(v)

    now = nxt

if max(in_deg.values()) > 0:
    day = -1

print(day)


def solve():
    rem = N * (N - 1) // 2
    for day in range(N * (N - 1) // 2):
        did_play = [0] * N
        for i in range(N):
            if did_play[i] or A[i] == []:
                continue
            opponent = A[i][-1]
            if A[opponent][-1] == i and not did_play[opponent]:
                A[i].pop()
                A[opponent].pop()
                rem -= 1
                did_play[i] = 1
                did_play[opponent] = 1
        if sum(did_play) == 0:
            break
        if rem == 0:
            return day + 1
    return -1

N = int(input())
A = [list(map(lambda x: int(x) - 1, input().split()))[::-1] for _ in range(N)]
print(solve())

from sys import setrecursionlimit

def encode(i, j):
    if i < j:
        i, j = j, i
    return i * (i - 1) // 2 + j + 1

def dfs(v):
    if visited[v] == 2:
        return dp[v]
    visited[v] = 1
    for nv in g[v]:
        if visited[nv] == 1:
            print(-1)
            exit()
        dp[v] = max(dp[v], dfs(nv) + 1)
    visited[v] = 2
    return dp[v]

setrecursionlimit(10**6)
N = int(input())
GAMES_CNT = N * (N - 1) // 2
g = [[] for _ in range(GAMES_CNT + 1)]
for i in range(N):
    orig = 0
    for j in map(lambda x: int(x) - 1, input().split()):
        dest = encode(i, j)
        g[orig].append(dest)
        orig = dest
dp = [0] * (GAMES_CNT + 1)
visited = [0] * (GAMES_CNT + 1)
print(dfs(0))


import sys

N = int(input())
A = [list(map(lambda x: int(x) - 1, input().split(" "))) for i in range(N)]

canUse = set(range(N))

ans = 0
while any([len(i) > 0 for i in A]):
    # print("\\nDay", ans)
    ans += 1
    canUseNew = set()
    for n in canUse:
        if not A[n]:
            continue

        first = A[n][-1]
        if first in canUseNew or n in canUseNew:
            continue

        if A[first][-1] == n:
            # print("Do", n + 1, first + 1)
            A[n].pop()
            A[first].pop()
            canUseNew.add(n)
            canUseNew.add(first)

    if len(canUseNew) == 0:
        print(-1)
        sys.exit(0)
    canUse = canUseNew

print(ans)

import sys

N = int(input())
A = [list(map(lambda x: int(x) - 1, input().split(" "))) for i in range(N)]

canUse = set(range(N))

ans = 0
done = 0
while done < N:
    ans += 1
    canUseNew = set()
    # print("LC", len(canUse))
    for n in canUse:
        if not A[n]:
            continue

        first = A[n][-1]
        if first in canUseNew or n in canUseNew:
            continue

        if A[first][-1] == n:
            # print("Do", n + 1, first + 1)
            A[n].pop()
            if len(A[n]) == 0:
                done += 1
            A[first].pop()
            if len(A[first]) == 0:
                done += 1
            canUseNew.add(n)
            canUseNew.add(first)

    if len(canUseNew) == 0:
        print(-1)
        sys.exit(0)
    canUse = canUseNew

print(ans)


N = int(input())

G = [list(map(lambda x: int(x) - 1, input().split())) for _ in range(N)]
cur = [0] * N
edge = [0] * N
for i in range(N):
    edge[i] = G[i][cur[i]]

day = 0
player = set(range(N))
while len(player) > 0:
    day += 1
    game = []
    for i in player:
        if i == edge[edge[i]]:
            game.append(i)
    if len(game) == 0:
        print(-1)
        exit()
    else:
        for j in game:
            cur[j] += 1
            c = cur[j]
            if c >= N - 1:
                player.remove(j)
            else:
                edge[j] = G[j][c]

print(day)

N = int(input())

G = [list(map(int, input().split())) for _ in range(N)]
cur = [0] * N
edge = [0] * N
for i in range(N):
    edge[i] = G[i][0] - 1

day = 0
player = set(range(N))
cnt = 0
while len(player) > 0:
    day += 1
    game = set()
    for i in player:
        e = edge[i]
        if i == edge[e] and i != e:
            game.add(i)
            game.add(e)
    player = set()
    for j in game:
        cur[j] += 1
        c = cur[j]
        if c >= N - 1:
            edge[j] = j
        else:
            edge[j] = G[j][c] - 1
            player.add(j)

if min(cur) != N - 1:
    ans = -1
else:
    ans = day
print(ans)


import sys

n = int(input())
a = []
for _ in range(n):
    a.append(list(map(int, input().split())))
ans = 0
pos = [0] * n

while any([(n - 1) - x for x in pos]):
    pos_check = [False] * n
    checker = True
    for i in range(n):
        for j in range(i + 1, n):
            if pos[i] == n - 1 or pos[j] == n - 1:
                continue
            if a[i][pos[i]] == j + 1 and a[j][pos[j]] == i + 1:
                pos_check[i] = True
                pos_check[j] = True
    for i in range(n):
        if pos_check[i]:
            pos[i] += 1
            checker = False
    if checker:
        print(-1)
        sys.exit()
    ans += 1
print(ans)

n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]

l = [i for i in range(n)]
pos = [0] * n
res = 0
cnt = 0
while True:
    res += 1
    flag = True
    tmp = l.copy()
    l = []
    used = [False] * n
    for v in tmp:
        if used[v] or pos[v] == n - 1:
            continue

        opp = a[v][pos[v]] - 1

        if used[opp] or pos[opp] == n - 1:
            continue

        if a[opp][pos[opp]] - 1 == v:
            pos[v] += 1
            pos[opp] += 1
            l.append(v)
            l.append(opp)
            used[v] = True
            used[opp] = True
            flag = False
            if pos[v] == n - 1:
                cnt += 1
            if pos[opp] == n - 1:
                cnt += 1

    if flag:
        print(-1)
        break

    if cnt == n:
        print(res)
        break


from collections import deque, defaultdict
from time import time

N = int(input())
A = [deque(map(lambda a: int(a) - 1, input().split())) for _ in range(N)]
S = time()

canBattle = defaultdict(lambda: False)
D = [0] * N

while True:
    isChanged = False
    for i, a in enumerate(A):
        if not a:
            continue
        j = a[0]
        canBattle[(i, j)] = True

        if canBattle[(j, i)]:
            isChanged = True
            A[i].popleft()
            A[j].popleft()
            d = max(D[i], D[j])
            D[i], D[j] = d + 1, d + 1
    if all(len(a) == 0 for a in A):
        print(max(D))
        exit()
    if time() - S >= 1.800:
        print(N * (N - 1) // 2)
        exit()
    if not isChanged:
        break

print(-1)

from collections import deque, defaultdict
from time import time

S = time()

N = int(input())
A = [deque(map(lambda a: int(a) - 1, input().split())) for _ in range(N)]

canBattle = defaultdict(lambda: False)
D = [0] * N

while True:
    isChanged = False
    for i, a in enumerate(A):
        if not a:
            continue
        j = a[0]
        canBattle[(i, j)] = True

        if canBattle[(j, i)]:
            isChanged = True
            A[i].popleft()
            A[j].popleft()
            d = max(D[i], D[j])
            D[i], D[j] = d + 1, d + 1
    if all(len(a) == 0 for a in A):
        print(max(D))
        exit()
    if time() - S >= 1.700:
        print(N * (N - 1) // 2)
        exit()
    if not isChanged:
        break

print(-1)


from sys import exit, setrecursionlimit

def get_node_id(i, j, node_id_db):
    if i < j:
        return node_id_db[i][j]
    else:
        return node_id_db[j][i]

def dfs(node_id, edges, dp):
    t = dp[node_id]
    if t >= 0:
        return t
    dp[node_id] = 0
    result = 0
    for n in edges[node_id]:
        t = dfs(n, edges, dp)
        if t == 0:  # looped
            print(-1)
            exit()
        if t > result:
            result = t
    result += 1
    dp[node_id] = result
    return result

setrecursionlimit(1000000)

N = int(input())
A = [[int(e) - 1 for e in input().split()] for _ in range(N)]

node_id_db = [[0] * N for _ in range(N)]
v = 0
for i in range(N):
    for j in range(i + 1, N):
        node_id_db[i][j] = v
        v += 1

start_nodes = []
edges = [[] for _ in range(N * (N - 1) // 2)]
for i in range(N):
    Ai = A[i]
    from_id = get_node_id(i, Ai[0], node_id_db)
    if i < Ai[0]:
        start_nodes.append(from_id)
    for j in range(1, N - 1):
        to_id = get_node_id(i, Ai[j], node_id_db)
        edges[from_id].append(to_id)
        from_id = to_id

dp = [-1] * (N * (N - 1) // 2)
print(max(dfs(n, edges, dp) for n in start_nodes))

from sys import setrecursionlimit

def get_node_id(i, j, node_id_db):
    if i < j:
        return node_id_db[i][j]
    else:
        return node_id_db[j][i]

def dfs(node_id, edges, dp):
    t = dp[node_id]
    if t >= 0:
        return t
    dp[node_id] = 0
    result = 0
    for n in edges[node_id]:
        t = dfs(n, edges, dp)
        if t == 0:  # looped
            print(-1)
            exit()
        if t > result:
            result = t
    result += 1
    dp[node_id] = result
    return result

def main():
    N = int(input())
    A = [[int(e) - 1 for e in input().split()] for _ in range(N)]

    node_id_db = [[0] * N for _ in range(N)]
    v = 0
    for i in range(N):
        for j in range(i + 1, N):
            node_id_db[i][j] = v
            v += 1

    start_nodes = []
    edges = [[] for _ in range(N * (N - 1) // 2)]
    for i in range(N):
        Ai = A[i]
        from_id = get_node_id(i, Ai[0], node_id_db)
        if i < Ai[0]:
            start_nodes.append(from_id)
        for j in range(1, N - 1):
            to_id = get_node_id(i, Ai[j], node_id_db)
            edges[from_id].append(to_id)
            from_id = to_id

    dp = [-1] * (N * (N - 1) // 2)
    print(max(dfs(n, edges, dp) for n in start_nodes))

setrecursionlimit(10**6)
main()


import sys

def topological_sort(root, links, in_count):
    topological = []
    q = root
    while q:
        v = q.pop()
        topological.append(v)
        for u in links[v]:
            in_count[u] -= 1
            if in_count[u] == 0:
                q.add(u)
    return topological

n = int(input())
match_count = n * (n - 1) // 2

offsets = [0]
tmp = -2
for i in range(1, n + 1):
    offsets.append(tmp)
    tmp += n - i - 1

roots = set()
in_links = [set() for _ in range(match_count)]
out_links = [set() for _ in range(match_count)]

for i, line in enumerate(sys.stdin, start=1):
    aaa = list(map(int, line.split()))
    j = aaa[0]
    prev = offsets[i] + j if i < j else offsets[j] + i
    roots.add(prev)

    for j in aaa[1:]:
        key = offsets[i] + j if i < j else offsets[j] + i
        out_links[prev].add(key)
        in_links[key].add(prev)
        prev = key

in_count = list(map(len, in_links))
roots = {r for r in roots if in_count[r] == 0}

if not roots:
    print(-1)
    exit()

topological = topological_sort(roots, out_links, in_count)
if len(topological) != match_count:
    print(-1)
    exit()

depth = [0] * match_count
for v in topological:
    depth[v] = max(map(depth.__getitem__, in_links[v]), default=0) + 1

print(max(depth))

import sys
from collections import deque

def topological_check(roots, out_links, in_count):
    depth = [0] * match_count
    for r in roots:
        depth[r] = 1
    q = deque(roots)
    while q:
        v = q.popleft()
        d = depth[v] + 1
        for u in out_links[v]:
            in_count[u] -= 1
            if in_count[u] == 0:
                depth[u] = d
                q.append(u)
    if any(in_count):
        return -1
    return max(depth)

n = int(input())
match_count = n * (n - 1) // 2

offsets = [0]
tmp = -2
for i in range(1, n + 1):
    offsets.append(tmp)
    tmp += n - i - 1

roots = set()
in_links = [set() for _ in range(match_count)]
out_links = [set() for _ in range(match_count)]

for i, line in enumerate(sys.stdin, start=1):
    aaa = list(map(int, line.split()))
    j = aaa[0]
    prev = offsets[i] + j if i < j else offsets[j] + i
    roots.add(prev)

    for j in aaa[1:]:
        key = offsets[i] + j if i < j else offsets[j] + i
        out_links[prev].add(key)
        in_links[key].add(prev)
        prev = key

in_count = list(map(len, in_links))
roots = {r for r in roots if in_count[r] == 0}

if not roots:
    print(-1)
    exit()

print(topological_check(roots, out_links, in_count))


n = int(input())
A = [list(int(x) - 1 for x in input().split()) for _ in range(n)]
B = [0] * n

ans = 1
while True:
    day_set = set()
    for i in range(n):
        if i in day_set or B[i] >= n - 1:
            continue
        j = A[i][B[i]]
        if j in day_set or B[j] >= n - 1:
            continue
        if A[j][B[j]] == i:
            B[i] += 1
            B[j] += 1
            day_set.add(i)
            day_set.add(j)
            if all(b >= n - 1 for b in B):
                print(ans)
                exit()
    if not day_set:
        print(-1)
        exit()
    else:
        ans += 1

n = int(input())
A = [list(int(x) - 1 for x in input().split()) for _ in range(n)]
B = [0] * n

ans = 1
stack = [i for i in range(n)]
while True:
    day_set = set()
    next_stack = []
    while stack:
        i = stack.pop()
        if i in day_set or B[i] >= n - 1:
            continue
        j = A[i][B[i]]
        if j in day_set or B[j] >= n - 1:
            continue
        if A[j][B[j]] == i:
            B[i] += 1
            B[j] += 1
            day_set.add(i)
            day_set.add(j)
            next_stack += [i, j]
            if all(b >= n - 1 for b in B):
                print(ans)
                exit()

    if not day_set:
        print(-1)
        exit()
    ans += 1
    stack = next_stack


from collections import deque
from typing import List, Optional, Tuple

def cycle_detectable_topological_sort(
    graph: List[List[int]], in_degrees: List[int], first_index: int = 0
) -> Tuple[Optional[List[int]], Optional[List[int]]]:
    """Topological sort that uses Kahn's algorithm and detects a loop (DAG or not).
    Returns:
        if the given graph is DAG, a list of sorted vertices and a list of depths of
        each vertex is returned.
        Otherwise, (None, None) is returned.
    """
    V = len(graph) + first_index
    order = []
    depths = [-1] * V  # depths[i] := the length of the longest path to V_i
    for i in range(first_index, V):
        if not in_degrees[i]:
            order.append(i)
            depths[i] = 0

    queue = deque(order)
    while queue:
        u = queue.popleft()
        cur_depth = depths[u]
        for v in graph[u]:
            in_degrees[v] -= 1
            if not in_degrees[v]:
                depths[v] = max(depths[v], cur_depth + 1)
                queue.append(v), order.append(v)
    return (order, depths) if len(order) + first_index == V else (None, None)

def abc139_e():
    N, *A = map(int, open(0).read().split())

    ids = [[-1] * (N + 1) for _ in range(N + 1)]
    cur_id = 0
    for i in range(1, N + 1):
        for j in range(i + 1, N + 1):
            ids[i][j] = ids[j][i] = cur_id
            cur_id += 1

    graph = [[] for _ in range(N * (N - 1) // 2)]
    in_degrees = [0] * (N * (N - 1) // 2)
    for i, a in enumerate(zip(*[iter(A)] * (N - 1)), 1):
        prev_id = -1
        for j in a:
            cur_id = ids[i][j]
            if prev_id != -1:
                graph[prev_id].append(cur_id)
                in_degrees[cur_id] += 1
            prev_id = cur_id

    _, depths = cycle_detectable_topological_sort(graph, in_degrees, 1)
    print(max(depths) + 1 if depths is not None else -1)

if __name__ == "__main__":
    abc139_e()

from collections import deque
from typing import List, Optional, Tuple

def cycle_detectable_topological_sort(
    graph: List[List[int]], in_degrees: List[int], first_index: int = 0
) -> Tuple[Optional[List[int]], Optional[List[int]]]:
    """Topological sort that uses Kahn's algorithm and detects a loop (DAG or not).
    Returns:
        if the given graph is DAG, a list of sorted vertices and a list of depths of
        each vertex is returned.
        Otherwise, (None, None) is returned.
    """
    V = len(graph) + first_index
    order = []
    depths = [-1] * V  # depths[i] := the length of the longest path to V_i
    for i in range(first_index, V):
        if not in_degrees[i]:
            order.append(i)
            depths[i] = 0

    queue = deque(order)
    while queue:
        u = queue.popleft()
        cur_depth = depths[u]
        for v in graph[u]:
            in_degrees[v] -= 1
            if not in_degrees[v]:
                depths[v] = cur_depth + 1
                queue.append(v), order.append(v)
    return (order, depths) if len(order) + first_index == V else (None, None)

def abc139_e():
    # https://atcoder.jp/contests/abc139/tasks/abc139_e
    N, *A = map(int, open(0).read().split())

    ids = [[-1] * (N + 1) for _ in range(N + 1)]
    cur_id = 0
    for i in range(1, N + 1):
        for j in range(i + 1, N + 1):
            ids[i][j] = ids[j][i] = cur_id
            cur_id += 1

    graph = [[] for _ in range(N * (N - 1) // 2)]
    in_degrees = [0] * (N * (N - 1) // 2)
    for i, a in enumerate(zip(*[iter(A)] * (N - 1)), 1):
        source = -1
        for j in a:
            target = ids[i][j]
            if source != -1:
                graph[source].append(target)
                in_degrees[target] += 1
            source = target

    _, depths = cycle_detectable_topological_sort(graph, in_degrees)
    print(max(depths) + 1 if depths else -1)

def grl_4_a():
    # https://onlinejudge.u-aizu.ac.jp/courses/library/5/GRL/4/GRL_4_A
    V, _, *ST = map(int, open(0).read().split())
    graph = [[] for _ in range(V)]
    in_degrees = [0] * V
    for s, t in zip(*[iter(ST)] * 2):
        graph[s].append(t)
        in_degrees[t] += 1

    res, _ = cycle_detectable_topological_sort(graph, in_degrees)
    print(1 if res is None else 0)

if __name__ == "__main__":
    abc139_e()
    # grl_4_a()

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02925/Python/s199555877.py", line 60, in <module>
    abc139_e()
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02925/Python/s199555877.py", line 55, in abc139_e
    _, depths = cycle_detectable_topological_sort(graph, in_degrees, 1)
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02925/Python/s199555877.py", line 18, in cycle_detectable_topological_sort
    if not in_degrees[i]:
IndexError: list index out of range


# E - League
import sys
from collections import deque
from typing import Deque, List

readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readline

def main():
    N = int(readline())
    A: List[Deque[int]] = [deque()] + list(
        deque(map(int, line.split())) for line in readlines()
    )
    matched_games_cnt = 0
    next_games_opponent, last_games_day = [0] * (N + 1), [0] * (N + 1)
    queue = deque(list(range(1, N + 1)))
    while queue:
        player = queue.popleft()
        if not A[player]:  # The player has finished all games.
            continue
        opponent = A[player].popleft()

        # The opponent will have another game before playing against x.
        if next_games_opponent[opponent] != player:
            next_games_opponent[player] = opponent
            continue

        # The opponent's next game is against the player and vice versa.
        matched_games_cnt += 1
        last_games_day[player] = last_games_day[opponent] = (
            max(last_games_day[player], last_games_day[opponent]) + 1
        )
        # No next game is currently planned.
        next_games_opponent[player] = next_games_opponent[opponent] = 0
        queue.append(player), queue.append(opponent)

    print(max(last_games_day) if matched_games_cnt == N * (N - 1) // 2 else -1)

if __name__ == "__main__":
    main()

# E - League
import sys
from collections import deque
from typing import Deque, List

readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def main():
    N = int(readline())
    A: List[Deque[int]] = [deque()] + [
        deque(map(int, line.split())) for line in readlines()
    ]
    matched_games_cnt = 0
    next_games_opponent, last_games_day = [0] * (N + 1), [0] * (N + 1)
    queue = deque(list(range(1, N + 1)))
    while queue:
        player = queue.popleft()
        if not A[player]:  # The player has finished all games.
            continue
        opponent = A[player].popleft()

        # The opponent will have another game before playing against x.
        if next_games_opponent[opponent] != player:
            next_games_opponent[player] = opponent
            continue

        # The opponent's next game is against the player and vice versa.
        matched_games_cnt += 1
        last_games_day[player] = last_games_day[opponent] = (
            max(last_games_day[player], last_games_day[opponent]) + 1
        )
        # No next game is currently planned.
        next_games_opponent[player] = next_games_opponent[opponent] = 0
        queue.append(player), queue.append(opponent)

    print(max(last_games_day) if matched_games_cnt == N * (N - 1) // 2 else -1)

if __name__ == "__main__":
    main()

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02925/Python/s342375203.py", line 42, in <module>
    main()
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02925/Python/s342375203.py", line 12, in main
    A: List[Deque[int]] = [deque()] + list(
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02925/Python/s342375203.py", line 13, in <genexpr>
    deque(map(int, line.split())) for line in readlines()
AttributeError: 'int' object has no attribute 'split'


n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
cnt = 0
cnt2 = 0
for i, ai in enumerate(a):
    for j in range(i, n):
        if ai > a[j]:
            cnt += 1
    if i > 0:
        for j in range(i):
            if ai > a[j]:
                cnt2 += 1

if k % 2 == 0:
    mul = (1 + k) * (k // 2)
else:
    mul = (1 + k) * (k // 2) + (k // 2 + 1)
if k > 1:
    k -= 1
    if k % 2 == 0:
        mul2 = (1 + k) * (k // 2)
    else:
        mul2 = (1 + k) * (k // 2) + (k // 2 + 1)
print(((cnt * mul) + (cnt2 * mul2)) % 1000000007)

n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
cnt = 0
cnt2 = 0
for i, ai in enumerate(a):
    for j in range(i, n):
        if ai > a[j]:
            cnt += 1
    if i > 0:
        for j in range(i):
            if ai > a[j]:
                cnt2 += 1

if k % 2 == 0:
    mul = (1 + k) * (k // 2)
else:
    mul = (1 + k) * (k // 2) + (k // 2 + 1)
mul2 = 0
if k > 1:
    k -= 1
    if k % 2 == 0:
        mul2 = (1 + k) * (k // 2)
    else:
        mul2 = (1 + k) * (k // 2) + (k // 2 + 1)
print(((cnt * mul) + (cnt2 * mul2)) % 1000000007)


a = int(input())
s = int(input())
print(s if a < 3200 else "red")

a = int(input())
s = input()
print(s if a >= 3200 else "red")

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02933/Python/s382036046.py", line 2, in <module>
    s = int(input())
ValueError: invalid literal for int() with base 10: 'pink'


n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in n:
    ans += 1 / i
print(1 / ans)

n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in a:
    ans += 1 / i
print(1 / ans)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02934/Python/s273231160.py", line 4, in <module>
    for i in n:
TypeError: 'int' object is not iterable


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

div = 0
for i in range(n):
    div += a / a[i]
print(1 / div)

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

div = 0
for i in range(n):
    div += 1 / a[i]
print(1 / div)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02934/Python/s178492873.py", line 6, in <module>
    div += a / a[i]
TypeError: unsupported operand type(s) for /: 'list' and 'int'


def gcd(a, b):
    mi = min(a, b)
    ma = max(a, b)
    r = ma % mi
    if r == 0:
        return mi
    gcd(mi, r)

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

Sum = sum(A)
s = []
multi = 1.0
for t in A:
    multi = int((multi * t) / gcd(int(multi), int(t)))

for a in A:
    s.append(int(multi / a))

print(multi / sum(s))

N = input()
A = list(map(float, input().split()))

print(1 / sum(1 / x for x in A))


import numpy as np

n = int(input())

a = list(map(int, input().split()))
p = np.prod(a)

top = p
under = 0

for aa in a:
    under += p / aa

print(top / under)

import numpy as np

n = int(input())

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

ue = 1

for aa in a:
    ue *= aa

shita = 0

for aa in a:
    shita += ue / aa

print(ue / shita)


import numpy as np

N = int(input())
A = [float(input()) for _ in range(N)]

nA = np.array(A)
print(np.reciprocal(np.sum(np.reciprocal(nA))))

import numpy as np

N = int(input())
A = [float(x) for x in input().split()]

nA = np.array(A)
print(np.reciprocal(np.sum(np.reciprocal(nA))))


import math

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

a = A[0]

for i in range(1, N):
    a = (a * A[i]) // math.gcd(a, A[i])

b = 0

for i in range(N):
    b += a // A[i]

print(a / b)

import math

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

# num is numerator
# den is denominator
num, den = A[0], 0

for i in A:
    num = (num * i) // math.gcd(num, i)

for i in A:
    den += num // i

ans = num / den
print(ans)


from sys import stdin, setrecursionlimit
import numpy as np

def main():
    input = stdin.buffer.readline
    n = int(input())
    a = list(map(int, input().split()))

    num = np.prod(a)

    den = sum([num // a[i] for i in range(n)])

    print(num / den)

if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

from sys import stdin, setrecursionlimit

def main():
    input = stdin.buffer.readline
    n = int(input())
    a = list(map(int, input().split()))

    num = 1
    for ai in a:
        num *= ai

    den = sum([num // a[i] for i in range(n)])

    print(num / den)

if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


import heapq
import math

def solve(n, v):
    heapq.heapify(v)
    nn = math.ceil(n / 2)

    while len(nn) != 1:
        x = heapq.heappop(v)
        y = heapq.heappop(v)
        z = (x + y) / 2
        heapq.heappush(v, z)

    return v[0]

n = int(input())
v = list(map(int, input().split()))

print(solve(n, v))

import heapq
import math

def solve(n, v):
    heapq.heapify(v)

    while len(v) != 1:
        x = heapq.heappop(v)
        y = heapq.heappop(v)
        z = (x + y) / 2
        heapq.heappush(v, z)

    return v[0]

n = int(input())
v = list(map(int, input().split()))

print(solve(n, v))

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02935/Python/s983148308.py", line 21, in <module>
    print(solve(n, v))
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02935/Python/s983148308.py", line 9, in solve
    while len(nn) != 1:
TypeError: object of type 'int' has no len()


import numpy as np

def get_answer(n, a):
    n = int(n)
    a = [int(v) for v in a.split(" ")]
    indexes_all = create_index(n)
    v_max = -1
    for indexes in indexes_all:
        v = a[indexes[0]]
        for i in range(1, len(indexes)):
            v = (v + a[indexes[i]]) / 2
        if v > v_max:
            v_max = v
    return v_max

def create_index(n):
    ret_all = []
    index_queue = np.arange(0, n)
    ret = []
    search_index(index_queue, ret_all, ret, n)
    return ret_all

def search_index(index_q, ret_all, ret, n):
    if n <= 0:
        ret_all.append(list(ret))
        return
    for i in range(n):
        index = index_q[i]
        index_q = np.delete(index_q, i)
        ret.append(index)
        search_index(index_q, ret_all, ret, n - 1)
        index_q = np.insert(index_q, i, index)
        ret.pop()

if __name__ == "__main__":
    input1 = input()
    input2 = input()
    print(get_answer(input1, input2))

def sort_index(a):
    for i in range(len(a)):
        for j in range(i + 1, len(a)):
            if a[i] > a[j]:
                a[i], a[j] = a[j], a[i]
    return a

def get_answer(n, a):
    n = int(n)
    a = [int(v) for v in a.split(" ")]
    a = sort_index(a)
    v_max = 0
    v = a[0]
    for i in range(1, len(a)):
        v = (v + a[i]) / 2
    if v > v_max:
        v_max = v
    return v_max

if __name__ == "__main__":
    input1 = input()
    input2 = input()
    print(get_answer(input1, input2))


from itertools import combinations

n = int(input())
values = list(map(int, input().split()))

ans = 0

def dfs(v):
    if len(v) == 2:
        global ans
        ans = max((v[0] + v[1]) / 2, ans)
        return

    for vv in combinations(v, 2):
        v_alche = v[:]
        v_alche.remove(vv[0])
        v_alche.remove(vv[1])
        v_alche.append((vv[0] + vv[1]) / 2)
        dfs(v_alche)

dfs(values)
print(ans)

n = int(input())
v = list(map(int, input().split()))

v.sort(reverse=True)

while len(v) > 1:
    v = v[:-2] + [(v[-1] + v[-2]) / 2]

print(v[0])


# -*- coding: utf-8 -*-
from decimal import Decimal
from itertools import permutations

# 整数の入力
N = int(input())

# スペース区切りの整数の入力
V = list(map(Decimal, input().split()))

result = 0

for values in permutations(V, N):
    new_result = values[0]

    for value in values[1:]:
        new_result = (new_result + value) / 2

    if result < new_result:
        result = new_result

# 出力
print(result)

# -*- coding: utf-8 -*-
from decimal import Decimal
from itertools import permutations

# 整数の入力
N = int(input())

# スペース区切りの整数の入力
V = list(map(Decimal, input().split()))

result = 0

V = sorted(V)
result = V[0]

for value in V[1:]:
    result = (result + value) / 2

# 出力
print(result)


import sys

input = sys.stdin.readline  # NOQA
sys.setrecursionlimit(10**7)  # NOQA

def dfs(G, v, p, counter, x):
    """G: graph, v: vertex, p: parent"""
    counter[v] += x
    # Loop for each child
    for c in G[v]:
        if c == p:
            continue  # Avoid multiple access to parent
        dfs(G, c, v, counter, x)

def calc_parent(G, v, p, parent):
    parent[v] = p
    for c in G[v]:
        if c == p:
            continue
        calc_parent(G, c, v, parent)

def main():
    N, Q = map(int, input().split())
    G = [[] for _ in range(N)]
    for _ in range(N - 1):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        G[a].append(b)
        G[b].append(a)

    parent = [-1] * N
    calc_parent(G, 0, -1, parent)
    counter = [0] * N
    for _ in range(Q):
        p, x = map(int, input().split())
        p -= 1
        dfs(G, p, parent[p], counter, x)

    print(*counter)

if __name__ == "__main__":
    main()

import sys

input = sys.stdin.readline  # NOQA
sys.setrecursionlimit(10**7)  # NOQA

def dfs(G, v, p, counter):
    """G: graph, v: vertex, p: parent"""
    # Loop for each child
    counter_v = counter[v]
    for c in G[v]:
        if c == p:
            continue  # Avoid multiple access to parent
        counter[c] += counter_v
        dfs(G, c, v, counter)

def main():
    N, Q = map(int, input().split())
    G = [[] for _ in range(N)]
    for _ in range(N - 1):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        G[a].append(b)
        G[b].append(a)

    counter = [0] * N
    for _ in range(Q):
        p, x = map(int, input().split())
        p -= 1
        counter[p] += x

    dfs(G, 0, -1, counter)
    print(*counter)

if __name__ == "__main__":
    main()


N, Q = map(int, input().split())

values = [0] * N
links = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    links[a - 1].append(b - 1)
    links[b - 1].append(a - 1)
for _ in range(Q):
    p, x = map(int, input().split())
    values[p - 1] += x

s = [(0, -1)]
while s:
    i, p = s.pop(0)
    for j in links[i]:
        if j == p:
            continue
        values[j] += values[i]
        s.append((j, i))
print(*values)

def main():
    N, Q = map(int, input().split())

    values = [0] * N
    links = [[] for _ in range(N)]
    for _ in range(N - 1):
        a, b = map(int, input().split())
        links[a - 1].append(b - 1)
        links[b - 1].append(a - 1)
    for _ in range(Q):
        p, x = map(int, input().split())
        values[p - 1] += x

    s = [(0, -1)]
    while s:
        i, p = s.pop()
        for j in links[i]:
            if j == p:
                continue
            values[j] += values[i]
            s.append((j, i))
    print(*values)

main()


from collections import deque

N, Q = map(int, input().split())

G = dict()
for i in range(1, N + 1):
    G[i] = dict()

for _ in range(N - 1):
    a, b = map(int, input().split())
    G[a][b] = 1
    G[b][a] = 1

parents = [0] * (N + 1)
values = [0] * (N + 1)
values_sum = [-1] * (N + 1)

for _ in range(Q):
    p, x = map(int, input().split())
    values[p] += x

# solve
values_sum[1] = values[1]

queue = deque([1])
while len(queue) > 0:
    p = queue.popleft()
    for q in G[p].keys():
        if G[p][q] == 1:
            if values_sum[q] == -1:
                values_sum[q] = values_sum[p] + values[q]
                G[q][p] = 0
                queue.append(q)

print(*values_sum[1:])

from collections import defaultdict

N, Q = map(int, input().split())

G = defaultdict(list)

for _ in range(N - 1):
    a, b = map(int, input().split())
    G[a].append(b)
    G[b].append(a)

parents = [0] * (N + 1)
values = [0] * (N + 1)
values_sum = [-1] * (N + 1)

for _ in range(Q):
    p, x = map(int, input().split())
    values[p] += x

# solve
values_sum[1] = values[1]

queue = [1]
while len(queue) > 0:
    p = queue.pop()
    for q in G[p]:
        if values_sum[q] == -1:
            values_sum[q] = values_sum[p] + values[q]
            queue.append(q)

print(*values_sum[1:])


# -*- coding: utf-8 -*-

import sys

def main():
    n, q = [int(x) for x in sys.stdin.readline().rstrip().split(" ")]

    tree = {}
    data = [0 for x in range(n)]

    for _ in range(n - 1):
        a, b = [int(x) for x in sys.stdin.readline().rstrip().split(" ")]
        if a not in tree:
            tree[a] = []
        tree[a].append(b)

    for _ in range(q):
        p, x = [int(x) for x in sys.stdin.readline().rstrip().split(" ")]
        data[p - 1] += x

    def add(p, x):
        data[p - 1] += x
        if p not in tree:
            return
        for p2 in tree[p]:
            add(p2, data[p - 1])

    add(1, 0)

    print(" ".join([str(x) for x in data]))

if __name__ == "__main__":
    main()

# -*- coding: utf-8 -*-

import sys

sys.setrecursionlimit(10**6)

def main():
    n, q = map(int, sys.stdin.readline().split())

    tree = [[] for x in range(n + 1)]
    data = [0 for x in range(n + 1)]

    for _ in range(n - 1):
        a, b = map(int, sys.stdin.readline().split())
        tree[a].append(b)
        tree[b].append(a)

    for _ in range(q):
        p, x = map(int, sys.stdin.readline().split())
        data[p] += x

    def dfs(p, p2, x):
        data[p] += x
        for p3 in tree[p]:
            if p3 == p2:
                continue
            dfs(p3, p, data[p])

    dfs(1, 0, 0)

    print(" ".join([str(x) for x in data[1:]]))

if __name__ == "__main__":
    main()


import sys

sys.setrecursionlimit(1000000)
N, Q = map(int, input().split())
A, B = [], []

edges = [[] for _ in range(N + 1)]
nums = [0 for _ in range(N + 1)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    edges[a].append(b)
    edges[b].append(a)

for _ in range(Q):
    p, x = map(int, input().split())
    nums[p] += x

def dfs(now, parent):
    for i in edges[now]:
        if i != parent:
            nums[i] += nums[now]
            dfs(i, now)

dfs(1, 0)
for n in nums[1:]:
    print(n)

import sys

sys.setrecursionlimit(10**6)
INF = float("inf")
MOD = 10**9 + 7

def input():
    return sys.stdin.readline().strip()

def main():
    N, Q = map(int, input().split())

    edges = [[] for _ in range(N + 1)]
    nums = [0 for _ in range(N + 1)]
    for _ in range(N - 1):
        a, b = map(int, input().split())
        edges[a].append(b)
        edges[b].append(a)

    for _ in range(Q):
        p, x = map(int, input().split())
        nums[p] += x

    def dfs(now, parent):
        for i in edges[now]:
            if i != parent:
                nums[i] += nums[now]
                dfs(i, now)

    dfs(1, 0)
    for n in nums[1:]:
        print(n)

if __name__ == "__main__":
    main()


def main():
    s = input()
    t = input()
    sletters = set()
    for i in s:
        sletters.add(i)

    for i in t:
        if i not in sletters:
            print(-1)
            return

    i = 0
    j = 0
    ans = 0
    while i < len(s) and j < len(t):
        if s[i] == t[j]:
            j += 1
        i += 1
        ans += 1
        if i == len(s):
            i = 0

    print(ans)

main()

import bisect

def main():
    s = input()
    t = input()
    sletters = [0] * 26
    for i in range(len(s)):
        x = ord(s[i]) - ord("a")
        if sletters[x] == 0:
            sletters[x] = [i]
        else:
            sletters[x].append(i)

    ans = 0
    curr_index = -1
    for i in t:
        x = ord(i) - ord("a")
        if sletters[x] == 0:
            print(-1)
            return
        index = bisect.bisect(sletters[x], curr_index)
        # print(sletters[x],i,curr_index,index)
        if index == len(sletters[x]):
            ans += len(s) - curr_index
            curr_index = sletters[x][0]
            ans += curr_index
        else:
            ans += sletters[x][index] - curr_index
            curr_index = sletters[x][index]

    print(ans)

main()


# -*- coding: utf-8 -*-

s = input()
t = input()

if not set(t) <= set(s):
    print(-1)
    exit()

repeat = 0
s_idx = 0
for c in t:
    idx = s[s_idx:].find(c)
    if idx == -1:
        idx = s.find(c)
        repeat += 1
    else:
        idx = idx + s_idx
    s_idx = idx + 1
else:
    ans = repeat * len(s) + s_idx

print(ans)

# -*- coding: utf-8 -*-

from bisect import bisect_left

s = input()
t = input()

if not set(t) <= set(s):
    print(-1)
    exit()

s_dict = {}
for i in range(len(s)):
    c = s[i]
    if c not in s_dict.keys():
        s_dict[c] = [i]
    else:
        s_dict[c].append(i)

repeat = 0
s_idx = 0
for c in t:
    idx = bisect_left(s_dict[c], s_idx)
    if idx == len(s_dict[c]):
        s_idx = s_dict[c][0] + 1
        repeat += 1
    else:
        s_idx = s_dict[c][idx] + 1
else:
    ans = repeat * len(s) + s_idx

print(ans)


def main():
    s = input()
    t = input()

    if not set(t) <= set(s):
        print(-1)
        return

    s_indexes = {c: [] for c in "abcdefghijklmnopqrstuvwxyz"}
    for i, s_c in enumerate(s):
        s_indexes[s_c].append(i)
    s_pointer = {c: 0 for c in "abcdefghijklmnopqrstuvwxyz"}
    s_length = {c: len(s_indexes[c]) for c in "abcdefghijklmnopqrstuvwxyz"}

    power = 0
    last_index = -1
    for i, t_c in enumerate(t):
        if s_length[t_c] <= s_pointer[t_c]:
            # reset
            s_pointer = {c: 0 for c in "abcdefghijklmnopqrstuvwxyz"}
            power += 1
        elif s_indexes[t_c][s_pointer[t_c]] <= last_index:
            for i, index in enumerate(s_indexes[t_c]):
                if last_index < index:
                    s_pointer[t_c] = i
                    break
            else:
                # reset
                s_pointer = {c: 0 for c in "abcdefghijklmnopqrstuvwxyz"}
                power += 1

        last_index = s_indexes[t_c][s_pointer[t_c]]
        s_pointer[t_c] += 1

    print(len(s) * power + last_index + 1)

main()

def main():
    s = input()
    t = input()

    if not set(t) <= set(s):
        print(-1)
        return

    s_indexes = {c: [] for c in "abcdefghijklmnopqrstuvwxyz"}
    for i, s_c in enumerate(s):
        s_indexes[s_c].append(i)
    s_pointer = {c: 0 for c in "abcdefghijklmnopqrstuvwxyz"}
    s_length = {c: len(s_indexes[c]) for c in "abcdefghijklmnopqrstuvwxyz"}

    power = 0
    last_index = -1
    for i, t_c in enumerate(t):
        if s_length[t_c] <= s_pointer[t_c]:
            # reset
            s_pointer = {c: 0 for c in "abcdefghijklmnopqrstuvwxyz"}
            power += 1
        elif s_indexes[t_c][s_pointer[t_c]] <= last_index:
            for j in range(s_pointer[t_c], s_length[t_c]):
                if last_index < s_indexes[t_c][j]:
                    s_pointer[t_c] = j
                    break
            else:
                # reset
                s_pointer = {c: 0 for c in "abcdefghijklmnopqrstuvwxyz"}
                power += 1

        last_index = s_indexes[t_c][s_pointer[t_c]]
        s_pointer[t_c] += 1

    print(len(s) * power + last_index + 1)

main()


from collections import defaultdict
import bisect

S = input()
T = input()

d = defaultdict(list)
for i, s in enumerate(S, start=1):
    d[s].append(i)

ans = 0
i = 0

for t in T:
    if not d[t]:
        print(-1)
        exit()

    if i > d[t][-1]:
        ans += len(S)
        i = 0
    pos = bisect.bisect_right(d[t], i)
    i = d[t][pos]

ans += i
print(ans)

from collections import defaultdict
import bisect

S = input()
T = input()

d = defaultdict(list)
for i, s in enumerate(S, start=1):
    d[s].append(i)

ans = 0
i = 0

for t in T:
    if not d[t]:
        print(-1)
        exit()

    if i >= d[t][-1]:
        ans += len(S)
        i = d[t][0]
        continue

    pos = bisect.bisect_right(d[t], i)
    i = d[t][pos]

ans += i
print(ans)


N, *A = map(int, open(0).read().split())

A = [0] + A
B = [0] * (N + 1)
sum_B = 0
for i in range(N, 0, -1):
    if sum(B[j] for j in range(i, N + 1, i)) % 2 != A[i]:
        B[i] = 1
        sum_B += 1
print(sum_B)
print(*[i for i, b in enumerate(B) if b])

from bisect import bisect_left

def solve():
    S = input()
    T = input()
    if not set(T) <= set(S):
        return -1

    pos = {c: [] for c in "abcdefghijklmnopqrstuvwxyz"}
    for i, c in enumerate(S):
        pos[c].append(i)
    ans = 0
    cur_pos = 0
    for t in T:
        nxt_idx = bisect_left(pos[t], cur_pos)
        if nxt_idx == len(pos[t]):
            ans += len(S)
            cur_pos = 0
            nxt_idx = bisect_left(pos[t], cur_pos)
            cur_pos = pos[t][nxt_idx] + 1
        else:
            cur_pos = pos[t][nxt_idx] + 1

    return ans + cur_pos

print(solve())

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02937/Python/s027416660.py", line 1, in <module>
    N, *A = map(int, open(0).read().split())
ValueError: invalid literal for int() with base 10: 'contest'


# https://atcoder.jp/contests/agc037/tasks/agc037_a

s = input()

ans = 0
pre = s[0]
i = 0
while i < len(s):
    cur = s[i]
    if pre == cur:
        pre = s[i] + s[i + 1]
        i += 2
    else:
        pre = cur
        i += 1
    ans += 1
print(ans)

# https://atcoder.jp/contests/agc037/tasks/agc037_a

s = input()

ans = 0
pre = ""
cur = ""
for i in range(len(s)):
    pre += s[i]
    if pre != cur:
        ans += 1
        cur = pre
        pre = ""
print(ans)


from itertools import combinations

s = input()
n = len(s)
ap = list(range(1, n))

set_s = set()

def check(k):
    if k == 1:
        return True

    rtn = False
    for v in combinations(ap, k - 1):
        can = True
        x_past = 0
        w_past = ""

        for x in v:
            w = s[x_past:x]
            if w == w_past:
                can = False
                break
            x_past = x
            w_past = w
        w_last = s[v[-1] :]
        if w == w_last:
            can = False

        if can is True:
            rtn = True
            break

    return rtn

low = 1
high = n
while low <= high:
    mid = (low + high) // 2
    if check(mid):
        low = mid + 1
    else:
        high = mid - 1

print(min(high, low))

s = input()

count = 0
j = 0
past_str = ""

for i in range(len(s)):
    now_str = s[j : i + 1]
    if now_str != past_str:
        count += 1
        j = i + 1
        past_str = now_str

print(count)


from sys import stdin

def main():

    S = stdin.readline().rstrip()
    S_len = len(S)

    sum = 0
    s = S[0]
    x = 1

    while True:
        if len(s) == 1:
            if s == S[x]:
                s = s + S[x]
            else:
                sum += 1
                s = S[x]
        else:
            sum += 2
            x += 1
            s = S[x]
        x += 1

        if x >= S_len:
            sum += 1
            break

    print(sum)

if __name__ == "__main__":
    main()

from sys import stdin

def main():

    S = stdin.readline().rstrip()
    S_len = len(S)

    sum = 0
    s = S[0]
    x = 1

    while True:
        if len(s) == 1:
            if s == S[x]:
                s = s + S[x]
            else:
                sum += 1
                s = S[x]
        else:
            sum += 2
            x += 1

            if x >= S_len:
                break
            s = S[x]
        x += 1

        if x >= S_len:
            sum += 1
            break

    print(sum)

if __name__ == "__main__":
    main()


from heapq import heapify, heappop, heappush

def solve(n, aaa, bbb):
    q = [(-b, i) for i, b in enumerate(bbb) if b != aaa[i]]
    heapify(q)
    ans = 0
    while q:
        b, i = heappop(q)
        b = -b
        b -= bbb[(i - 1) % n] + bbb[(i + 1) % n]
        if b <= 0:
            return -1
        bbb[i] = b
        ans += 1
        if b != aaa[i]:
            heappush(q, (-b, i))
    return ans

n = int(input())
aaa = list(map(int, input().split()))
bbb = list(map(int, input().split()))
print(solve(n, aaa, bbb))

from heapq import heapify, heappop, heappush

def solve(n, aaa, bbb):
    q = [(-b, i) for i, b in enumerate(bbb) if b != aaa[i]]
    heapify(q)
    ans = 0
    while q:
        b, i = heappop(q)
        b = -b - aaa[i]
        d, b = divmod(b, bbb[(i - 1) % n] + bbb[(i + 1) % n])
        if d == 0:
            return -1
        b += aaa[i]
        bbb[i] = b
        ans += d
        if b != aaa[i]:
            heappush(q, (-b, i))
    return ans

n = int(input())
aaa = list(map(int, input().split()))
bbb = list(map(int, input().split()))
print(solve(n, aaa, bbb))


A = int(input())
B = int(input())
c = A + B
d = A - B
e = A * B
f = [c, d, e]
maxvalue = c
for i in range(len(f)):
    if f[i] > maxvalue:
        maxvalue = f[i]
print(maxvalue)

A, B = map(int, input().split())
c = A + B
d = A - B
e = A * B
f = [c, d, e]
maxvalue = c
for i in range(len(f)):
    if f[i] > maxvalue:
        maxvalue = f[i]
print(maxvalue)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02945/Python/s027556545.py", line 1, in <module>
    A = int(input())
ValueError: invalid literal for int() with base 10: '-13 3'


N = int(input())
s = [list(input()) for _ in range(N)]
S = []
for i in range(N):
    S.append("".join(sorted(s[i])))
print(S)

cnt = 0
for i in range(N):
    cnt += S.count(S[i]) - 1
print(int(cnt / 2))

A, B = map(int, input().split())
print(max(A + B, A - B, A * B))

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02945/Python/s567458637.py", line 1, in <module>
    N = int(input())
ValueError: invalid literal for int() with base 10: '-13 3'


A, B = int(input().split())
list = []
list.append(A + B)
list.append(A - B)
list.append(A * B)
print(max(list))

A, B = map(int, input().split())
list = []
list.append(A + B)
list.append(A - B)
list.append(A * B)
print(max(list))

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02945/Python/s147643407.py", line 1, in <module>
    A, B = int(input().split())
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'list'


A = int(input())
B = input()

answer = max(
    A + B,
    A - B,
    A * B,
)

print(answer)

data = input()
data = data.split(" ")

A = int(data[0])
B = int(data[1])

answer = max(
    A + B,
    A - B,
    A * B,
)

print(answer)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02945/Python/s283924824.py", line 1, in <module>
    A = int(input())
ValueError: invalid literal for int() with base 10: '-13 3'


# じゃあ全部保存していってやるよ
n = int(input())
d = {}
arr = []
for _ in range(n):
    x = list(sorted(input()))
    arr.append(x)
    if x not in d:
        d[x] = 1
    else:
        d[x] += 1

c = 0
for a in arr[:0:-1]:
    if d[a] > 0:
        c += d[a] - 1
        d[a] -= 1

print(c)

# じゃあ全部保存していってやるよ
# atcoderのpython3のバージョンが古すぎて(3.4.3)TypeError: unhashable type: 'list'なるのでため息つきながら直した

n = int(input())
d = {}
arr = []
for _ in range(n):
    x = "".join(list(map(str, list(sorted(input())))))
    arr.append(x)
    if x not in d:
        d[x] = 1
    else:
        d[x] += 1

c = 0
for a in arr[:0:-1]:
    if d[a] > 0:
        c += d[a] - 1
        d[a] -= 1

print(c)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02947/Python/s642649306.py", line 8, in <module>
    if x not in d:
TypeError: unhashable type: 'list'


from collections import Counter
from itertools import combinations

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

cnt = 0
for t, u in combinations(s, 2):
    if Counter(t) == Counter(u):
        cnt += 1

print(cnt)

from collections import Counter
from math import factorial

def count_combinations(n, r):
    return factorial(n) // (factorial(r) * factorial(n - r))

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

t = ["".join(sorted(str)) for str in s]
c = Counter(t)
ll = [i for _, i in c.items() if i > 1]
cnt = 0
for i in ll:
    cnt += count_combinations(i, 2)

print(cnt)


def to_dict(text):
    d = {}
    for c in text:
        d[c] = d.get(c, 0) + 1
    return d

n = int(input())
combination_count = 0
s = []
for _ in range(n):
    si = to_dict(input())
    combination_count += sum(1 for old_si in s if old_si == si)
    s.append(si)

print(combination_count)

import collections

n = int(input())
counter = collections.Counter(str(sorted(input())) for _ in range(n))
combination_count = sum((v - 1) * v // 2 for v in counter.values())

print(combination_count)


N = int(input())
s = []
for _ in range(N):
    si = sorted(input())
    s.append(si)
ans = 0
for i in range(0, N - 1):
    for j in range(i + 1, N):
        if s[i] == s[j]:
            ans += 1
print(ans)

from collections import Counter

N = int(input())
c = Counter()
for _ in range(N):
    si = "".join(sorted(input()))
    c[si] += 1

ans = sum([n * (n - 1) // 2 for n in c.values()])
print(ans)


from collections import Counter

def main():
    N = int(input())
    s = [Counter(input()) for _ in range(N)]
    ans = 0
    for i in range(N):
        for j in range(i + 1, N):
            if s[i] == s[j]:
                ans += 1
    print(ans)

if __name__ == "__main__":
    main()

from collections import Counter

def main():
    N = int(input())
    s = ["".join(sorted(input())) for _ in range(N)]
    S = Counter(s)
    ans = 0
    for a in S.values():
        ans += sigma(a)
    print(ans)

def sigma(x):
    sum = 0
    for i in range(1, x):
        sum += i
    return sum

if __name__ == "__main__":
    main()


from collections import defaultdict

n = int(input())
d = []
count = 0
t = [0] * n
for _ in range(n):
    s = input()
    dic = defaultdict(int)
    for c in s:
        dic[c] += 1
    for i in range(len(d)):
        if all(dic[key] == d[i][key] for key in dic):
            if t[i] != 0:
                count += t[i] + 1
                t[i] += 1
                break
            else:
                count += 1
                t[i] += 1
    d.append(dic)

print(count)

import collections

n = int(input())
S = []
count = 0
for _ in range(n):
    S.append("".join(sorted(list(input()))))

for i, v in collections.Counter(S).items():
    for i in range(1, v):
        count += i

print(count)


def main():
    N = int(input())
    S = [sorted(input()) for i in range(N)]
    ans = 0
    for i in range(N):
        for j in range(i + 1, N):
            if S[i] == S[j]:
                ans += 1

    print(ans)

if __name__ == "__main__":
    main()

#!/usr/bin/env python3
import collections
import math

def main():
    N = int(input())
    S = ["".join(sorted(input())) for i in range(N)]
    cnt = collections.Counter(S)
    ans = 0
    for v in cnt.values():
        if v != 1:
            ans += math.factorial(v) // (math.factorial(v - 2) * 2)

    print(ans)

if __name__ == "__main__":
    main()


n = int(input())
cnt = 0
sListSum = 0
sList = [None] * n

for i in range(n):
    s = sorted(input())
    sListSum += sList.count(s)
    sList[i] = s

print(sListSum)

import sys
import collections
import bisect

def main():
    n = int(input())
    s = ["".join(sorted(list(input()))) for _ in range(n)]
    c = collections.Counter(s)
    cVals = c.values()
    cSum = 0
    for cVal in cVals:
        cSum += cVal * (cVal - 1) // 2
    print(cSum)

if __name__ == "__main__":
    main()


import math

N = int(input())
S_lists = [input() for i in range(N)]

S_dict = {}

for S in S_lists:
    S_list = list(S)
    S_list.sort()

    S_str = "".join(S_list)
    if S_str in S_dict.keys():
        S_dict[S_str] = S_dict[S_str] + 1
    else:
        S_dict[S_str] = 1

answer = 0
for v in S_dict.values():
    if v > 1:
        answer += int(math.factorial(v) / 2)

print(answer)

N = int(input())
S_lists = [input() for i in range(N)]

S_dict = {}

for S in S_lists:
    S_list = list(S)
    S_list.sort()

    S_str = "".join(S_list)
    if S_str in S_dict.keys():
        S_dict[S_str] = S_dict[S_str] + 1
    else:
        S_dict[S_str] = 1

answer = 0
for v in S_dict.values():
    if v > 1:
        answer += int(v * (v - 1) / 2)

print(answer)


# coding: utf-8
n = int(input())
lst = [input() for i in range(n)]
cnt = 0
for j in range(n - 1):
    for k in range(j + 1, n):
        if sorted(list(lst[j])) == sorted(list(lst[k])):
            cnt += 1

print(cnt)

# coding: utf-8
from collections import Counter

n = int(input())
lst = [input() for i in range(n)]
cnt = Counter()
ans = 0
for i in lst:
    a = "".join(sorted(list(i)))
    if a in cnt:
        ans += cnt[a]
    cnt[a] += 1

print(ans)


# -*- coding: utf-8 -*-
# 整数の入力

def main():
    # a, b
    n = int(input())
    s = []
    for _ in range(n):
        s.append(sorted(input()))
    print(process(n, s))

def process(n, s):
    count = 0
    for i in range(0, n):
        for k in range(i, n):
            if i == k:
                continue
            if s[i] == s[k]:
                count += 1
    return count

if __name__ == "__main__":
    main()

# -*- coding: utf-8 -*-
# 整数の入力

def main():
    # a, b
    n = int(input())
    s = []
    for _ in range(n):
        s.append(input())
    print(process(n, s))

def process(n, s):
    s = list(map(lambda s: "".join(sorted(s)), s))
    hash = {}

    count = 0
    for i in range(0, n):
        if s[i] in hash:
            hash[s[i]] += 1
        else:
            hash[s[i]] = 1
        count += hash[s[i]] - 1
    return count

if __name__ == "__main__":
    main()


# #!/usr/bin/env python3
# # -*- coding: utf-8 -*-
from itertools import combinations

def main():
    N = int(input())
    S = [sorted(input()) for _ in range(N)]
    ptn = list(combinations(S, 2))
    result = 0

    for p in ptn:
        result += all([p[0] == p[1]])
    print(result)

if __name__ == "__main__":
    main()

# #!/usr/bin/env python3
# # -*- coding: utf-8 -*-
from collections import defaultdict

def main():
    N = int(input())
    dct = defaultdict(int)

    for i in range(N):
        s = input()
        sorted_s = "".join(sorted(s))
        dct[sorted_s] += 1

    ans = 0
    for k, v in dct.items():
        ans += v * (v - 1) // 2
    print(ans)

if __name__ == "__main__":
    main()


import collections
import itertools

N = int(input())
moji = [input() for _ in range(N)]

check = [[0] * N for _ in range(N)]

cnt = 0
for i in range(N):
    c = []
    x = collections.Counter(moji[i])

    c.append(i)

    for j in range(i + 1, N):
        if check[i][j] == 1:
            continue

        y = collections.Counter(moji[j])

        if x == y:
            c.append(j)

    if len(c) > 1:
        for u, v in itertools.combinations(c, 2):
            check[u][v] = 1
            cnt += 1

print(cnt)

N = int(input())
moji_lst = [input() for _ in range(N)]

dic = {}
cnt = 0

for moji in moji_lst:
    x = "".join(sorted(moji))

    if x in dic:
        dic[x] += 1
        cnt += dic[x]
    else:
        dic[x] = 0

print(cnt)


import itertools

def main():
    n = int(input())
    s = [sorted(input()) for _ in range(n)]
    seq = list(itertools.combinations(s, 2))
    ans = 0
    for i in seq:
        if i[0] == i[1]:
            ans += 1

    print(ans)

if __name__ == "__main__":
    main()

def main():
    n = int(input())
    s = ["".join(sorted(input())) for _ in range(n)]
    ans = 0
    dic = {}
    for i in s:
        if i not in dic:
            dic[i] = 0
        else:
            dic[i] += 1
            ans += dic[i]
        # print(ans)
    print(ans)

if __name__ == "__main__":
    main()


n = int(input())

S = []
for _ in range(n):
    s = list(input())
    s.sort()
    S.append("".join(s))
S.sort()

C = []
i = 0
while i < n:
    c = S.count(S[i])
    if c > 1:
        C.append(c)
    i += c

ans = 0
for c in C:
    ans += c * (c - 1) // 2

print(ans)

n = int(input())

S = []
for _ in range(n):
    s = list(input())
    s.sort()
    S.append("".join(s))
S.sort()

C = []
c = 1
for i in range(n - 1):
    if S[i] == S[i + 1]:
        c += 1
    else:
        C.append(c)
        c = 1
C.append(c)

ans = 0
for c in C:
    ans += c * (c - 1) // 2

print(ans)


n = int(input())
strs = list()
for _ in range(n):
    strs.append(sorted(list(input())))

total = 0
for i in range(n):
    for j in range(i + 1, n):
        if strs[i] == strs[j]:
            total += 1
print(total)

n = int(input())
d = {}

for _ in range(n):
    s = "".join(sorted(input()))
    if s in d:
        d[s] += 1
    else:
        d[s] = 1

ans = 0
for k, v in d.items():
    ans += (v * (v - 1)) / 2

print(int(ans))


N = int(input())

L = [list(input()) for _ in range(N)]

dic = []
flag = {}
res = 0
for i in range(N):
    L[i].sort()

    if L[i] in dic:
        flag[str(L[i])] += 1
        res += flag[str(L[i])]
    else:
        dic.append(L[i])
        flag[str(L[i])] = 0

print(res)

N = int(input())

L = [list(input()) for _ in range(N)]

dic = []
flag = {}
res = 0
for i in range(N):
    L[i].sort()

    if str(L[i]) in flag:
        flag[str(L[i])] += 1
        res += flag[str(L[i])]
    else:
        dic.append(L[i])
        flag[str(L[i])] = 0

print(res)


from math import factorial

N = int(input())
d = {}
for _ in range(N):
    s = input()
    s_sorted = "".join(sorted(s))
    if not d.get(s_sorted):
        d[s_sorted] = 1
    else:
        d[s_sorted] += 1

ans = 0
for _, v in d.items():
    if v == 1:
        continue
    x = factorial(v) / factorial(2) / factorial(v - 2)
    ans += x

print(round(ans))

from math import factorial

N = int(input())
d = {}
for _ in range(N):
    s = input()
    s_sorted = "".join(sorted(s))
    if not d.get(s_sorted):
        d[s_sorted] = 1
    else:
        d[s_sorted] += 1

ans = 0
for _, v in d.items():
    if v == 1:
        continue
    ans += v * (v - 1) // 2

print(round(ans))


from itertools import combinations

N = int(input())
S = [sorted(input()) for _ in range(N)]

print(sum(1 if s1 == s2 else 0 for s1, s2 in combinations(S, 2)))

from collections import Counter

N = int(input())
S = ["".join(sorted(list(input()))) for _ in range(N)]

cnt = Counter(S)
print(sum(v * (v - 1) // 2 for v in cnt.values()))


x = []
cnt = 0
for _ in range(int(input())):
    a = sorted(input())
    cnt += x.count(a)
    x.append(a)
print(cnt)

import collections

n = int(input())
x = ["".join(sorted(input())) for _ in range(n)]
a = collections.Counter(x)
print(sum(i * ~-i // 2 for i in a.values()))


import sys

n = int(input())
alphabet = [chr(ord("a") + i) for i in range(26)]
count = [[0] * 26 for _ in range(n)]
for i in range(n):
    for s in sys.stdin.readline().strip():
        count[i][alphabet.index(s)] += 1

uniq = set(list(map(tuple, count)))
ans = 0
for u in uniq:
    n = count.count(list(u))
    ans += n * (n - 1) // 2
print(ans)

import sys
import collections

n = int(input())
lst = [None] * n
for i in range(n):
    lst[i] = "".join(sorted(list(sys.stdin.readline().strip())))

ans = 0
for v in collections.Counter(lst).values():
    ans += v * (v - 1) // 2
print(ans)


from collections import defaultdict

N = int(input())

result = 0
store = []
for _ in range(N):
    d = defaultdict(int)
    s = input()
    for c in set(s):
        d[c] += s.count(c)
    result += store.count(d)
    store.append(d)
print(result)

from collections import defaultdict
import sys

readline = sys.stdin.readline

N = int(input())

result = 0
d = defaultdict(int)
for _ in range(N):
    s = input()
    s = "".join(sorted(s))
    if s in d:
        d[s] += 1
    else:
        d[s] = 1
print(sum([int((v) * (v - 1) / 2) for k, v in d.items()]))


N = int(input())
s = []
ans = 0
for _ in range(N):
    si = input()
    sortedSi = "".join(sorted(list(si)))
    ans += s.count(sortedSi)
    s.append(sortedSi)

print(ans)

N = int(input())
dic = {}
ans = 0
for _ in range(N):
    si = input()
    sortedSi = "".join(sorted(si))
    if sortedSi in dic:
        dic[sortedSi] += 1
    else:
        dic[sortedSi] = 1

for val in dic.values():
    ans += val * (val - 1) // 2

print(ans)


from collections import Counter

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

ans = 0
for i in range(n):
    for j in range(i + 1, n):
        if s[i] == s[j]:
            ans += 1

print(ans)

from collections import Counter

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

for i in range(n):
    s[i].sort()
    s[i] = "".join(s[i])

c = Counter(s)

ans = 0

for v in c.values():
    ans += v * (v - 1) // 2
print(ans)


import itertools
import collections

def resolve():
    N = int(input())
    s = [input() for _ in range(N)]
    ans = 0
    for tmp in itertools.combinations(s, 2):
        d1 = collections.defaultdict(int)
        d2 = collections.defaultdict(int)
        for ch in tmp[0]:
            d1[ch] += 1
        for ch in tmp[1]:
            d2[ch] += 1
        if d1 == d2:
            ans += 1
    print(ans)

resolve()

def resolve():
    N = int(input())
    s = [input() for _ in range(N)]
    ans = 0
    chk = {}
    for tmp in s:
        d1 = "".join(sorted(list(tmp)))
        if d1 in chk.keys():
            ans += chk[d1]
            chk[d1] += 1
        else:
            chk[d1] = 1
    print(ans)

resolve()


# https://atcoder.jp/contests/abc137/tasks/abc137_c
# C - Green Bin
import collections
import itertools

n = int(input().split()[0])
s_list = []
c_list = []

for _ in range(n):
    s = input().split()[0]
    s_list.append(s)
    c_list.append(collections.Counter(s))

p = itertools.combinations(c_list, 2)
ans = sum([1 if a == b else 0 for a, b in list(p)])
print(ans)

# https://atcoder.jp/contests/abc137/tasks/abc137_c
# C - Green Bin
import collections
import itertools
import math

n = int(input().split()[0])
s_list = []
c_list = []

for _ in range(n):
    s = input().split()[0]
    s_list.append("".join(sorted(s)))

counter = collections.Counter(s_list)

def C(n, k):
    return math.factorial(n) / (math.factorial(k) * math.factorial(n - k))

p_list = [C(value, 2) for key, value in counter.items() if value > 1]
ans = int(sum(p_list))

print(ans)


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

def is_anagram(s_i, s_j):
    for k in range(10):
        if s_i[k] != s_j[k]:
            return False
    return True

num = 0
for i in range(n):
    for j in range(i + 1, n):
        if is_anagram(s[i], s[j]):
            num += 1
print(num)

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

num = 0
num_same = 1
prev = sorted_s[0]
for i in range(1, len(sorted_s)):
    if prev != sorted_s[i]:
        num += int(num_same * (num_same - 1) / 2)
        num_same = 1
        prev = sorted_s[i]
    else:
        num_same += 1
num += int(num_same * (num_same - 1) / 2)
print(num)


n = int(input())

s = [""] * n
t = [""] * n

cnt = 0

for i in range(n):
    s[i] = input()
    t[i] = sorted(s[i])

t = sorted(t)

for i in range(n - 1):
    for j in range(i + 1, n):
        if t[i] == t[j]:
            cnt += 1

print(cnt)

n = int(input())

s = [""] * n
t = [""] * n

cnt = 0
flg = 0

for i in range(n):
    s[i] = input()
    t[i] = sorted(s[i])

t = sorted(t)

for i in range(n - 1):
    if t[i] == t[i + 1]:
        flg += 1
        cnt += flg
    else:
        flg = 0

print(cnt)


from collections import Counter

anagrams = []
for _ in range(int(input())):
    count = Counter(input())
    found = False
    for v in anagrams:
        if v["count"] == count:
            found = True
            v["total"] += 1
            break
    if not found:
        anagrams.append({"count": count, "total": 1})

total = 0
for v in anagrams:
    n = v["total"]
    total += n * (n - 1) / 2

print(int(total))

from collections import defaultdict

anagrams = defaultdict(int)
for _ in range(int(input())):
    anagrams[str(sorted(input()))] += 1

total = 0
for k, v in anagrams.items():
    total += v * (v - 1) / 2

print(int(total))


qt = int(input())
sl = [input() for i in range(qt)]
ls = []
count = 0

for s in sl:
    s = "".join(sorted(s))
    ls.append(s)

i = 0
j = 0
key = ""

while len(ls) > i:
    while len(ls) > (j + 1):
        j += 1
        if ls[i] == ls[j]:
            count += 1
    i += 1
    j = i

print(count)

import math as m

qt = int(input())
sl = [input() for i in range(qt)]
d = {}
count = 0

for s in sl:
    s = "".join(sorted(s))
    if s in d:
        d[s] += 1
    else:
        d[s] = 1

for e in d.values():
    if e > 1:
        count += m.factorial(e) // (m.factorial(e - 2) * 2)

print(count)


import sys
from functools import reduce
from operator import mul

input = sys.stdin.readline

# def c(num):
#     return reduce(mul, range(1, num + 1))
def cmb(n, r):
    r = min(n - r, r)
    if r <= 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under

def main():
    n = int(input())
    lines = ["".join(sorted(input().strip())) for _ in range(n)]
    count = 0
    for text in set(lines):
        txt_cnt = lines.count(text)
        if txt_cnt == 1:
            continue
        count += cmb(txt_cnt, 2)
    print(count)

if __name__ == "__main__":
    main()

import sys
from functools import reduce
from operator import mul
from collections import Counter

input = sys.stdin.readline

def cmb(n, r):
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under

def main():
    n = int(input())
    lines = ["".join(sorted(input().strip())) for _ in range(n)]
    count = 0
    for _, v in Counter(lines).most_common():
        if v == 1:
            break
        count += cmb(v, 2)
    print(count)

if __name__ == "__main__":
    main()


import collections
import math

n = int(input())
sl = collections.Counter([str(sorted(input())) for _ in range(n)])

ret = 0
for _, v in sl.most_common():
    if 2 <= v:
        ret += int(math.factorial(v) / math.factorial(2) / math.factorial(v - 2))

print(ret)

import collections

n = int(input())
sl = collections.Counter([str(sorted(input())) for _ in range(n)])

ret = 0
for _, v in sl.most_common():
    if 2 <= v:
        ret += v * (v - 1) // 2

print(ret)


a = int(input())
b = [sorted(list(input())) for _ in range(a)]
b.sort()
cnt = 0
for i in range(a):
    for j in range(i + 1, a):
        if b[i][0] == b[j][0]:
            if "".join(b[i]) == "".join(b[j]):
                cnt += 1
        else:
            break
print(cnt)

import collections

a = int(input())
b = ["".join(sorted(list(input()))) for _ in range(a)]
b = collections.Counter(b)
total = 0
for i in b.values():
    for j in range(1, i):
        total += j
print(total)


import sys
import heapq

N, M = list(map(int, input().split()))
possiblyValidJobs = {}
for line in sys.stdin:
    A, B = map(int, line.split())
    if A > M:
        continue

    if A in possiblyValidJobs:
        possiblyValidJobs[A] += 1
    else:
        possiblyValidJobs[A] = 1

validJobsOnThisDay = []
ans = 0
for daysBeforeDeadline in range(1, M + 1):
    if daysBeforeDeadline in possiblyValidJobs:
        for wage in possiblyValidJobs[daysBeforeDeadline]:
            heapq.heappush(validJobsOnThisDay, -wage)
    if validJobsOnThisDay:
        ans += -heapq.heappop(validJobsOnThisDay)
print(ans)

import sys
import heapq

N, M = list(map(int, input().split()))
possiblyValidJobs = {}
for line in sys.stdin:
    A, B = map(int, line.split())
    if A > M:
        continue

    if A in possiblyValidJobs:
        possiblyValidJobs[A].append(B)
    else:
        possiblyValidJobs[A] = [B]

validJobsOnThisDay = []
ans = 0
for daysBeforeDeadline in range(1, M + 1):
    if daysBeforeDeadline in possiblyValidJobs:
        for wage in possiblyValidJobs[daysBeforeDeadline]:
            heapq.heappush(validJobsOnThisDay, -wage)
    if validJobsOnThisDay:
        ans += -heapq.heappop(validJobsOnThisDay)
print(ans)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02948/Python/s294834943.py", line 20, in <module>
    for wage in possiblyValidJobs[daysBeforeDeadline]:
TypeError: 'int' object is not iterable


n, m = map(int, input().split())
ab = [(map(int, input().split())) for _ in range(n)]

jobs = [(a, -b) for a, b in ab]
jobs.sort()

ans = 0
job_index = 0
for i in range(m):
    while job_index < len(jobs):
        if jobs[job_index] + i < m:
            ans -= jobs[job_index][1]
        else:
            job_index += 1
print(ans)

from heapq import heappush, heappop

n, m = map(int, input().split())
ab = [tuple(map(int, input().split())) for _ in range(n)]

jobs = [[] for _ in range(m)]
for a, b in ab:
    if a <= m:
        jobs[a - 1].append(-b)

ans = 0
available = []
for job in jobs:
    for jo in job:
        heappush(available, jo)

    if available:
        ans -= heappop(available)

print(ans)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02948/Python/s258753664.py", line 11, in <module>
    if jobs[job_index] + i < m:
TypeError: can only concatenate tuple (not "int") to tuple


# -*- coding: utf-8 -*-

n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]

ab.sort(reverse=True)
ab.sort(key=lambda x: x[1], reverse=True)

days_left = [1] * (m + 2)
ans = 0
for a, b in ab:
    i = a
    while days_left[i] == 0:
        i += 1
    if i == m + 1:
        continue
    days_left[i] = 0
    ans += b

print(ans)

# -*- coding: utf-8 -*-

import heapq

class MaxHeap:
    def __init__(self, li):
        self.heap = [-e for e in li]
        heapq.heapify(self.heap)

    def push(self, val):
        heapq.heappush(self.heap, -val)

    def pop(self):
        return -heapq.heappop(self.heap)

    def __len__(self):
        return len(self.heap)

n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]

ab.sort()

h = MaxHeap([])

i = 0
ans = 0
for day in range(1, m + 1):
    while i < n and ab[i][0] <= day:
        h.push(ab[i][1])
        i += 1
    if len(h) == 0:
        continue
    ans += h.pop()

print(ans)