iidai/codenet huggingface dataset:
Language: Python

import sys
sys.setrecursionlimit(100000)


def dfs(i):
    for v, w in V.get(i, []):
        if (w % 2) == 0:
            if color[v] == -1:
                color[v] = color[i]
            elif color[v] == color[i]:
                continue
            elif color[v] != color[i]:
                return False
        else:
            if color[v] == -1:
                color[v] = 0 if color[i] else 1
            elif color[v] == color[i]:
                return False
            elif color[v] != color[i]:
                continue
        dfs(v)
    return True


if __name__ == '__main__':
    n = int(input())
    V = {}
    color = {}
    for i in range(1, n):
        u, v, w = map(int, input().split())
        if not V.get(u, False):
            V[u] = [[v, w]]
        else:
            V[u].append([v, w])

        if not V.get(v, False):
            V[v] = [[u, w]]
        else:
            V[v].append([u, w])

    for i in range(1, n+1):
        color[i] = -1

    while True:
        i = 0
        for j in range(1, n+1):
            if color[j] == -1:
                i = j
                color[i] = 0
                break
        if i == 0:
            for j in range(1, n+1):
                print(color[j])
            break
        else:
            if not dfs(i):
                print('No')
                break


Example test case(s):
input: 3
1 2 2
2 3 1

output: 0
0
1
Language: Python

print(sum(map(lambda x, y: x == y, input(), input())))


Example test case(s):
input: CSS
CSR

output: 2
Language: Python

s = input()
if len(s) < 26:
    for i in range(26):
        c = chr(ord("a")+i)
        if c not in s:
            print(s+c)
            exit()
else:
    for i in reversed(range(1, 26)):
        if s[i-1] < s[i]:
            s1 = s[0:i-1]
            for j in range(26):
                c = chr(ord("a")+j)
                if c > s[i-1] and c not in s1:
                    print(s1+c)
                    exit()
    print(-1)


Example test case(s):
input: atcoder

output: atcoderb
Language: Python

import sys
input = sys.stdin.readline

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

if a >= 13:
    print(b)
elif a >= 6:
    print(int(b/2))
else:
    print(0)


Example test case(s):
input: 30 100

output: 100
Language: Python

N = int(input())
A = []
for _ in range(2):
    s = list(map(int, input().split()))
    A.append(s)


ans = []

count = 0
for i in range(N):
    baselis = A[0]
    groundlis = A[1]
    count = 0
    count = count + sum(baselis[0:i+1]) + sum(groundlis[i:N+1])
    ans.append(count)

print(max(ans))


Example test case(s):
input: 5
3 2 2 4 1
1 2 2 2 1

output: 14
Language: Python

import sys
input = sys.stdin.readline

n = int(input())

ans = 10 ** 18

for i in range(1, int(n ** (1 / 2)) + 2):
    if n % i != 0:
        continue
    j = n // i
    ans = min(ans, i + j - 2)

print(ans)


Example test case(s):
input: 10

output: 5
Language: Python

n, k = map(int, input().split())
print(n+k if k % n == 0 else k-n)


Example test case(s):
input: 4 12

output: 16
Language: Python

import math
N, K = (int(x) for x in input().split())
R = N - K
mod = 10**9 + 7


def fact(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


for i in range(1, K+1):
    if N - K + 1 < i:
        ans = 0
    else:
        ans = fact(R+1, i)*fact(K-1, i-1)
    print(int(ans) % mod)


Example test case(s):
input: 5 3

output: 3
6
1
Language: Python

s = input()
t = input()


def check(a, b):
    s = 0
    for i, j in zip(a, b):
        s += i != j
    return s


ans = 10**6
for i in range(len(s)):
    a = s[i:]
    if len(a) >= len(t):
        ans = min(ans, check(t, a[:len(t)]))
print(ans)


Example test case(s):
input: cabacc
abc

output: 1
Language: Python

N, L = map(int, input().split())
aji = []
for i in range(1, N+1):
    aji.append(L+i-1)
if min(aji) >= 0:
    aji.pop(aji.index(min(aji)))
elif max(aji) <= 0:
    aji.pop(aji.index(max(aji)))
else:
    aji.pop(aji.index(min(aji, key=abs)))
print(sum(aji))


Example test case(s):
input: 5 2

output: 18
Language: Python

x, y, a, b, c = map(int, input().split())
p = sorted([int(i) for i in input().split()], reverse=True)[:x]
q = sorted([int(i) for i in input().split()], reverse=True)[:y]
r = sorted([int(i) for i in input().split()], reverse=True)
pq = sorted(p+q)
for i in range(min(x+y, a+b, c)):
    if pq[i] < r[i]:
        pq[i] = r[i]
print(sum(pq))


Example test case(s):
input: 1 2 2 2 1
2 4
5 1
3

output: 12
Language: Python

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

m1 = int(sum([a[i] * ((-1)**i) for i in range(n)]) / 2)

result = str(m1)

m = [None] * n
m[0] = m1
for i in range(1, n):
    m[i] = a[i-1] - m[i-1]

print(' '.join([str(x*2) for x in m]))


Example test case(s):
input: 3
2 2 4

output: 4 0 4
Language: Python

import sys
N, M = map(int, sys.stdin.readline().split())
A = list(map(int, sys.stdin.readline().split()))
A.sort(reverse=True)
S = sum(A)
for a in A[:M]:
    if a/S - 1/(4*M) < 0:
        print('No')
        break
else:
    print('Yes')


Example test case(s):
input: 4 1
5 4 2 1

output: Yes
Language: Python

a, b = input().split(" ")
a = int(a)
b = int(b)
if a <= b:
    print(a)
else:
    print(a-1)


Example test case(s):
input: 5 5

output: 5
Language: Python

n = int(input())
print(len(set([input() for _ in range(n)])))


Example test case(s):
input: 4
10
8
8
6

output: 3
Language: Python

import heapq
const = 0
left = []
right = []

q = int(input())
cnt = 0
left_sum = 0
right_sum = 0
for _ in range(q):
    t = list(map(int, input().split()))
    if t[0] == 1:

        a, b = t[1:]
        const += b
        if cnt % 2 == 0:
            if not right:
                heapq.heappush(left, -a)
                left_sum += a
                cnt += 1

                continue

            c = heapq.heappop(right)
            right_sum -= c
            if a <= c:
                heapq.heappush(left, -a)
                heapq.heappush(right, c)
                left_sum += a
                right_sum += c
            else:
                heapq.heappush(left, -c)
                heapq.heappush(right, a)
                left_sum += c
                right_sum += a
        else:
            c = heapq.heappop(left)
            left_sum += c
            if a <= -c:
                heapq.heappush(left, -a)
                heapq.heappush(right, -c)
                left_sum += a
                right_sum -= c
            else:
                heapq.heappush(left, c)
                heapq.heappush(right, a)
                left_sum -= c
                right_sum += a
        cnt += 1

    else:
        tmp = -left[0]
        print(tmp, const - left_sum + right_sum + tmp * (cnt % 2))


Example test case(s):
input: 4
1 4 2
2
1 1 -8
2

output: 4 2
1 -3
Language: Python

(a, b, c, k) = list(map(int, input().split()))
if k % 2 == 0:
    print(a-b)
else:
    print(b-a)


Example test case(s):
input: 1 2 3 1

output: 1
Language: Python

from itertools import combinations_with_replacement
import sys


def LI(): return map(int, sys.stdin.readline().rstrip().split())


N, M, Q = LI()

Q_groups = []
for _ in range(Q):
    Q_groups.append([*LI()])

max_score = 0
for p in combinations_with_replacement(range(1, M + 1), r=N):
    temp_score = 0
    for q in Q_groups:
        if p[q[1] - 1] - p[q[0] - 1] == q[2]:
            temp_score += q[3]
    max_score = max(max_score, temp_score)

print(max_score)


Example test case(s):
input: 3 4 3
1 3 3 100
1 2 2 10
2 3 2 10

output: 110
Language: Python

strn = input()
n = int(strn)
shichigolist = ["3", "5", "7"]
shichigo = [[] for _ in range(len(strn))]
for i in range(len(strn)):
    if i == 0:
        for j in shichigolist:
            shichigo[i].append(j)
    else:
        for j in shichigo[i-1]:
            for k in shichigolist:
                shichigo[i].append(j+k)
target = len(strn)-1
for i in range(len(strn)):
    for j in shichigo[i][:]:
        if i == target:
            if int(j) > n:
                shichigo[target].remove(j)
            elif j.count("3") == 0 or j.count("5") == 0 or j.count("7") == 0:
                shichigo[target].remove(j)
        else:
            if j.count("3") == 0 or j.count("5") == 0 or j.count("7") == 0:
                shichigo[i].remove(j)

print(sum([len(shichigo[i]) for i in range(len(strn))]))


Example test case(s):
input: 575

output: 4
Language: Python

a, b, c = map(int, input().split())
print(int((a*b)/2))


Example test case(s):
input: 3 4 5

output: 6
Language: Python

N = int(input())
A = list(map(int, input().split()))
B = [0] * N

for i in range(N - 1, -1, -1):
    tmp_sum = 0
    for j in range((i + 1) * 2 - 1, N, i + 1):
        tmp_sum += B[j]
        tmp_sum %= 2
    B[i] = tmp_sum ^ A[i]

print(sum(B))
print(*[i + 1 for i, b in enumerate(B) if b == 1])


Example test case(s):
input: 3
1 0 0

output: 1
1
Language: Python

S = input()

if S == 'Sunny':
    print('Cloudy')

if S == 'Cloudy':
    print('Rainy')

if S == 'Rainy':
    print('Sunny')


Example test case(s):
input: Sunny

output: Cloudy
Language: Python

s = input()
alphabets = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l",
             "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
for i in range(len(alphabets)):
    if alphabets[i] == s:
        print(alphabets[i+1])


Example test case(s):
input: a

output: b
Language: Python

N = int(input())
cnt = 1
while cnt <= 9:
    if N % cnt == 0 and 1 <= N/cnt <= 9:
        print('Yes')
        break
    else:
        cnt += 1
else:
    print('No')


Example test case(s):
input: 10

output: Yes
Language: Python

import copy


def solve():
    S_d = list(input())
    T = list(input())

    end = len(S_d) - 1
    first = end - len(T) + 1
    while first >= 0:
        t_i = 0
        for s_i in range(first, end+1):
            if T[t_i] != S_d[s_i] and S_d[s_i] != '?':
                break
            t_i += 1
        else:
            break

        first -= 1
        end -= 1

    else:
        print('UNRESTORABLE')
        exit(0)

    ans = copy.deepcopy(S_d)
    t_i = 0
    for i in range(first, end+1):
        ans[i] = T[t_i]
        t_i += 1

    ans = ''.join(ans).replace('?', 'a')
    print(ans)


if __name__ == '__main__':
    solve()


Example test case(s):
input: ?tc????
coder

output: atcoder
Language: Python

X = int(input())
h = X // 500
a = (X % 500) // 5
y = h * 1000 + a * 5
print(y)


Example test case(s):
input: 1024

output: 2020
Language: Python

import math
N, D = map(int, input().split())
mat = []
for d in range(N):
    mat.append([int(x) for x in input().split()])

c = 0
for i in range(len(mat)-1):
    for j in range(i+1, len(mat)):
        dist = math.sqrt(sum([(x-y)**2 for x, y in zip(mat[i], mat[j])]))
        if int(dist) == dist:
            c += 1
print(c)


Example test case(s):
input: 3 2
1 2
5 5
-2 8

output: 1
Language: Python

X, t = map(int, input().split())

if X > t:
    answer = X - t
elif X <= t:
    answer = 0

print(answer)


Example test case(s):
input: 100 17

output: 83
Language: Python

X, A = list(map(int, input().split()))
if X < A:
    print(0)
else:
    print(10)


Example test case(s):
input: 3 5

output: 0
Language: Python

N, K = map(int, input().split())
if N % K == 0:
    print(0)
else:
    print(1)


Example test case(s):
input: 7 3

output: 1
Language: Python

n = int(input())
h = int(n / 3600)
n %= 3600
m = int(n / 60)
n %= 60
s = int(n)
print(str(h) + ":" + str(m) + ":" + str(s))


Example test case(s):
input: 46979

output: 13:2:59
Language: Python

h, w, ka = map(int, input().split())
mat = [list(input()) for i in range(h)]
ans = 0
for i in range(2**(h+w)):
    b = bin(i)[2:].zfill(h+w)
    rs = b[:h]
    cs = b[h:]
    ct = 0
    for l in range(h):
        for k in range(w):
            if mat[l][k] == '#' and rs[l] == '0' and cs[k] == '0':
                ct += 1
    if ct == ka:
        ans += 1
print(ans)


Example test case(s):
input: 2 3 2
..#
###

output: 5
Language: Python

s = input()
q = int(input())
qs = [input().split() for i in range(q)]
n = False
left = right = ""
for operation in qs:
    if operation[0] == '1':
        n = not n
    if operation[0] == '2':
        t, f, c = operation
        f = int(f)
        if n:
            f = 1 if f != 1 else 2
        if f == 1:
            left = c+left
        elif f == 2:
            right += c
s = left+s+right
print(s[::-1] if n else s)


Example test case(s):
input: a
4
2 1 p
1
2 2 c
1

output: cpa
Language: Python

def bubbleSort(cards):
    n = len(cards)
    for i in range(0, n):
        for j in range(n-1, i, -1):
            if int(cards[j][1]) < int(cards[j-1][1]):
                cards[j], cards[j-1] = cards[j-1], cards[j]

    print(" ".join(map(str, cards)))


def selectionSort(cards):
    n = len(cards)
    for i in range(0, n):
        mini = i
        for j in range(i, n):
            if int(cards[j][1]) < int(cards[mini][1]):
                mini = j
        if mini != i:
            cards[i], cards[mini] = cards[mini], cards[i]

    print(" ".join(map(str, cards)))


n = int(input())
cards = input().split(" ")
cards2 = list(cards)
bubbleSort(cards)
print("Stable")
selectionSort(cards2)
if " ".join(map(str, cards2)) == " ".join(map(str, cards)):
    print("Stable")
else:
    print("Not stable")


Example test case(s):
input: 5
H4 C9 S4 D2 C3

output: D2 C3 H4 S4 C9
Stable
D2 C3 S4 H4 C9
Not stable
Language: Python

candy = sorted(map(int, input().split()))
print("Yes" if candy[0]+candy[1] == candy[2] else "No")


Example test case(s):
input: 10 30 20

output: Yes
Language: Python

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


def main():
    A.sort()
    ans = A[-1] - A[0]
    print(ans)


if __name__ == "__main__":
    main()


Example test case(s):
input: 4
1 4 6 3

output: 5
Language: Python

import sys
import math

from collections import defaultdict
from collections import deque


def load(vtype=int):
    return vtype(input().strip())


def load_list(seplator=" ", vtype=int):
    return [vtype(v) for v in input().strip().split(seplator)]


def exit():
    import sys
    sys.exit(0)


def perm_sub(li, used):
    if len(li) == len(used):
        return [deque()]
    k = []
    for i in range(len(li)):
        if i in used:
            continue
        used.add(i)
        sub_list = perm_sub(li, used)
        for sub in sub_list:
            sub.appendleft(li[i])
        k.extend(sub_list)
        used.discard(i)
    return k


def perm_li(li):
    return perm_sub(li, set())


def perm_n(n):
    return perm_sub(list(range(n)), set())


def join_i(li, sep=""):
    return sep.join([str(e) for e in li])


def li2n(li):
    n, base = 0, 1
    for i in range(len(li)-1, -1, -1):
        n += li[i] * base
        base *= 10
    return n


def sli2ili(li):
    return [int(s) for s in li]


def prime_list(n):
    li = [i for i in range(2, n+1)]
    for i in range(len(li)):
        if li[i] >= int(math.sqrt(n)):
            break
        if li[i] == -1:
            continue
        for j in range(i+1, len(li)):
            if li[j] % li[i] == 0:
                li[j] = -1
    return [n for n in li if n != -1]


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


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


def all_subset(li):
    s = []
    n = len(li)
    for bit in range(0, (1 << (n+1))):
        ss = set()
        for i in range(0, n):
            if (bit & (1 << i)):
                ss.add(li[i])
        s.append(ss)
    return s


def factorial(n):
    if n == 1:
        return 1
    return n * factorial(n-1)


def mCn(m, n):
    def factorial_ntimes(m, n):
        r = 1
        while n:
            r *= m
            m -= 1
            n -= 1
        return r
    return int(factorial_ntimes(m, n) / factorial(n))


n = load()
A = load_list()

if n == len(set(A)):
    print('YES')
else:
    print('NO')


Example test case(s):
input: 5
2 6 1 4 5

output: YES
Language: Python

x = input()
if x.islower():
    print("a")
else:
    print("A")


Example test case(s):
input: B

output: A
Language: Python

N = int(input())
A = list(map(int, input().split()))
B = list(A)
count = 1
for i in A:
    B[i-1] = count
    count += 1


print(*B)


Example test case(s):
input: 3
2 3 1

output: 3 1 2
Language: Python

def main():
    q, h, s, d = map(int, input().split())
    n = int(input())
    min_1 = min(q*4, h*2, q*2+h, s)
    min_2 = min(min_1*2, d)

    print((n % 2)*min_1 + (n // 2)*min_2)


if __name__ == '__main__':
    main()


Example test case(s):
input: 20 30 70 90
3

output: 150
Language: Python

n = int(input())
s = input()

r_cnt = s.count('R')
g_cnt = s.count('G')
b_cnt = s.count('B')

ans = r_cnt * g_cnt * b_cnt

for i in range(n):
    for d in range(n):
        j = i + d
        k = j + d
        if k >= n:
            break

        if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:

            ans -= 1
print(ans)


Example test case(s):
input: 4
RRGB

output: 1
Language: Python

h, a = map(int, input().strip().split())

ans = h // a
ama = h % a

if ama != 0:
    ans += 1
print(ans)


Example test case(s):
input: 10 4

output: 3
Language: Python

def atc_079a(input_value: str) -> str:
    n = 3
    for i in range(0, len(input_value) + 1 - n):
        for j in range(1, n):
            if input_value[i] != input_value[i + j]:
                break
            if j == n - 1:
                return "Yes"
    return "No"


input_value = input()
print(atc_079a(input_value))


Example test case(s):
input: 1118

output: Yes
Language: Python

n = int(input())
lst = []
pair = 0
for i in range(n):
    st = ''.join(sorted(list(input())))
    lst.append(st)
lst = sorted(lst)
lst += ['end']
pre = ''
tmp_cnt = 0
cnt = 0
for i in lst:
    if i == pre:
        tmp_cnt += 1
    else:
        cnt += sum([j for j in range(tmp_cnt + 1)])
        tmp_cnt = 0
    pre = i
print(cnt)


Example test case(s):
input: 3
acornistnt
peanutbomb
constraint

output: 1
Language: Python

N = int(input())
A = list(map(int, input().split()))
s = A[0] ^ A[1]
for i in range(2, N):
    s = s ^ A[i]

B = [0]*N
for i in range(N):
    B[i] = s ^ A[i]

L = [str(a) for a in B]
L = " ".join(L)
print(L)


Example test case(s):
input: 4
20 11 9 24

output: 26 5 7 22
Language: Python

print('Christmas'+' Eve'*abs(int(input())-25))


Example test case(s):
input: 25

output: Christmas
Language: Python

N, M = map(int, input().split())
A = map(int, input().split())
A_sum = sum(A)

print(N - A_sum if N - A_sum >= 0 else "-1")


Example test case(s):
input: 41 2
5 6

output: 30
Language: Python

from sys import stdin
def il(func=int): return list(map(func, stdin.readline().rstrip().split()))


ils = lambda n, s="int(input())": [eval(s) for _ in range(n)]


def gcd(a, b):
    if a < b:
        return gcd(b, a)
    if b == 0:
        return a
    return gcd(b, a % b)


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


n, m = il()
s = input()
t = input()
aa = gcd(n, m)
bb = lcm(n, m)
cc = aa // bb
for i in range(aa):
    if s[n//aa*i] != t[m//aa*i]:
        print(-1)
        exit()
print(bb)


Example test case(s):
input: 3 2
acp
ae

output: 6
Language: Python

while True:
    n = int(input())

    if n == 0:
        break

    res = -1111111111
    s = 0
    for i in range(n):
        a = int(input())
        s = max(s + a, a)
        res = max(s, res)

    print(res)


Example test case(s):
input: 7
-5
-1
6
4
9
-6
-7
13
1
2
3
2
-2
-1
1
2
3
2
1
-2
1
3
1000
-200
201
0

output: 19
14
1001
Language: Python

from collections import Counter


def solve():
    N = int(input())
    D = list(map(int, input().split()))

    mod = 998244353

    if D[0] != 0:
        print(0)
        return

    cnt = Counter(D)

    if cnt[0] > 1:
        print(0)
        return

    res = 1

    for i in range(1, max(D)+1):
        if cnt[i-1] == 1:
            continue
        res *= cnt[i-1]**cnt[i] % mod
        res %= mod

    print(res)


solve()


Example test case(s):
input: 4
0 1 1 2

output: 2
Language: Python

from functools import reduce
import math


def lcm(x, y):
    return (x * y) // math.gcd(x, y)


def lcm_list(numbers):
    return reduce(lcm, numbers, 1)


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


A = [a // 2 for a in A]


count_div_2 = None
for a in A:
    cnt = 0
    while a % 2 == 0:
        a //= 2
        cnt += 1

    if count_div_2 is None:
        count_div_2 = cnt

    elif cnt != count_div_2:
        print(0)
        exit()


my_lcm = lcm_list(A)
if my_lcm > M:
    print(0)
    exit()

tmp = M // my_lcm


ans = (tmp + 1) // 2
print(ans)


Example test case(s):
input: 2 50
6 10

output: 2
Language: Python

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

ans = 0
for i in range(N):
    d = min(A[i], B[i])
    ans += d
    A[i] -= d
    B[i] -= d
    d = min(A[i + 1], B[i])
    ans += d
    A[i + 1] -= d
    B[i] -= d

print(ans)


Example test case(s):
input: 2
3 5 2
4 5

output: 9
Language: Python

import numpy as np

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

if n > k:
    tmp = n % k
    if tmp >= k - tmp:
        ans = k - tmp
    else:
        ans = tmp
elif n < k:
    if n >= k - n:
        ans = k - n
    else:
        ans = n
else:
    ans = 0

print(ans)


Example test case(s):
input: 7 4

output: 1
Language: Python

a, b, c = map(int, input().split())
print("Yes" if a + b >= c else "No")


Example test case(s):
input: 50 100 120

output: Yes
Language: Python

import sys
input = sys.stdin.buffer.readline


def main():

    class SegmentTree:

        def __init__(self, size, default):
            self.size = 2**(size-1).bit_length()
            self.default = default
            self.seg = [default]*(2*self.size-1)

        def segfunc(self, x, y):
            return max(x, y)

        def update(self, k, x):
            k += self.size-1
            self.seg[k] = x
            while k:
                k = (k-1)//2
                self.seg[k] = self.segfunc(self.seg[2*k+1], self.seg[2*k+2])

        def query(self, p, q):
            if q <= p:
                return self.default
            p += self.size-1
            q += self.size-2
            ret = self.default
            while q-p > 1:
                if p & 1 == 0:
                    ret = self.segfunc(ret, self.seg[p])
                if q & 1 == 1:
                    ret = self.segfunc(ret, self.seg[q])
                    q -= 1
                p = p//2
                q = (q-1)//2
            ret = self.segfunc(self.segfunc(ret, self.seg[p]), self.seg[q])
            return ret

        def seg_print(self):
            print(self.seg)

    N = int(input())
    a = list(map(int, input().split()))
    ans = [i+1 for i in range(N)]
    left_seg = SegmentTree(N, 0)
    for i, num in enumerate(a):
        ans[num-1] *= i + 1 - left_seg.query(0, num)
        left_seg.update(num-1, i+1)
    right_seg = SegmentTree(N, 0)
    for i, num in enumerate(a[::-1]):
        ans[num-1] *= i + 1 - right_seg.query(0, num)
        right_seg.update(num-1, i+1)

    print(sum(ans))


if __name__ == "__main__":
    main()


Example test case(s):
input: 3
2 1 3

output: 9
Language: Python

N, L = map(int, input().split())
S = [input().rstrip() for _ in range(N)]
print(''.join(sorted(S)))


Example test case(s):
input: 3 3
dxx
axx
cxx

output: axxcxxdxx
Language: Python

S = list(input())

count = 0
record = 0
for i in range(len(S)):
    if S[i] == "A" or S[i] == "C" or S[i] == "G" or S[i] == "T":
        count += 1
    else:
        if count > record:
            record = count
        count = 0
if count > record:
    record = count

print(record)


Example test case(s):
input: ATCODER

output: 3
Language: Python

n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))

ans = 0
for i in T:
    if i == S[-1] or i == S[0]:
        ans += 1
    else:
        left = 0
        right = n-1
        while right-left > 1:
            mid = (left+right)//2
            if S[mid] == i:
                ans += 1
                break
            elif S[mid] < i:
                left = mid
            else:
                right = mid

print(ans)


Example test case(s):
input: 5
1 2 3 4 5
3
3 4 1

output: 3