Input:
class Segment_Tree():

    def __init__(self,N,calc,unit,L=[]):

        """calcを演算とするN項のSegment Treeを作成

        N:要素数

        calc:演算(2変数関数,モノイド)

        unit:モノイドcalcの単位元 (xe=ex=xを満たすe)

        """

        self.calc=calc

        self.unit=unit

        N=max(N,len(L))

        d=max(1,(N-1).bit_length())

        k=2**d

        X=[unit]*(k-1)+L+[unit]*(k-len(L))

        self.num=k

        self.depth=d

        for i in range(k-2,-1,-1):

            X[i]=calc(X[2*i+1],X[2*i+2])

        self.data=X

    def index(self,k,index=0):

        return self.data[(self.num-1)+(k-index)]

    def update(self,k,x,index=0):

        """第k要素をxに変え,更新を行う.

        k:数列の要素

        x:更新後の値

        """

        m=(self.num-1)+(k-index)

        self.data[m]=x

        for _ in range(self.depth):

            m=(m-1)//2

            self.data[m]=self.calc(self.data[2*m+1],self.data[2*m+2])

    def sub_array(self,From,To,index=0,left_closed=True,right_closed=True):

        A=From-index+(not left_closed)

        B=To-index-(not right_closed)

        return self.__sub_array_second(A,B+1,0,0,self.num)

    def __sub_array_second(self,a,b,k,l,r):

        if r<=a or b<=l:

            return self.unit

        elif a<=l and r<=b:

            return self.data[k]

        else:

            alpha=self.__sub_array_second(a,b,2*k+1,l,(l+r)//2)

            beta=self.__sub_array_second(a,b,2*k+2,(l+r)//2,r)

            return self.calc(alpha,beta)

    def all_prod(self):

        return self.data[0]

    def max_right(self,l,r,cond,index=0):

        """以下の2つをともに満たすxの1つを返す.\n

        (1) r=l or cond(data[l]*data[l+1]*...*d[r-1]):True

        (2) r=x or cond(data[l]*data[l+1]*...*data[r]):False

        ※fが単調減少の時,cond(data[l]*...*data[r-1])を満たす最大のrとなる.

        cond:関数(引数が同じならば結果も同じ)

        cond(unit):True

        0<=l<=r<=n

        """

        l-=index

        assert 0<=l<=r<=self.num,"添字が範囲外"

        assert cond(self.unit),"単位元が条件を満たさない."

        if l==r:

            return r+index

        l+=(self.num-1)

        sm=self.unit

        calc=self.calc

        while True:

            while l%2:

                l=(l-1)>>1

            if not cond(calc(sm,self.data[l])):

                while l<self.num-1:

                    l=2*l+1

                    if cond(calc(sm,self.data[l])):

                        sm=calc(sm,self.data[l])

                        l+=1

                return min(l-(self.num-1)+index,r)

            sm=calc(sm,self.data[l])

            l+=1

            m=l+1

            if not (m&(-m) !=m):

                break

        return r+index

#================================================

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

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

S=Segment_Tree(N,lambda x,y:max(x,y),-float("inf"),A)

X=[]

for _ in range(Q):

    T,alpha,beta=list(map(int,input().split()))

    if T==1:

        S.update(alpha,beta,1)

    elif T==2:

        X.append(S.sub_array(alpha,beta,1))

    else:

        X.append(S.max_right(alpha,N,lambda x:x<beta,1))

print(("\n".join(map(str,X))))

class Segment_Tree():

    def __init__(self,N,calc,unit,L=[]):

        """calcを演算とするN項のSegment Treeを作成

        N:要素数

        calc:演算(2変数関数,モノイド)

        unit:モノイドcalcの単位元 (xe=ex=xを満たすe)

        """

        self.calc=calc

        self.unit=unit

        N=max(N,len(L))

        d=max(1,(N-1).bit_length())

        k=2**d

        X=[unit]*(k-1)+L+[unit]*(k-len(L))

        self.num=k

        self.depth=d

        for i in range(k-2,-1,-1):

            X[i]=calc(X[2*i+1],X[2*i+2])

        self.data=X

    def index(self,k,index=0):

        return self.data[(self.num-1)+(k-index)]

    def update(self,k,x,index=0):

        """第k要素をxに変え,更新を行う.

        k:数列の要素

        x:更新後の値

        """

        m=(self.num-1)+(k-index)

        self.data[m]=x

        for _ in range(self.depth):

            m=(m-1)//2

            self.data[m]=self.calc(self.data[2*m+1],self.data[2*m+2])

    def sub_array(self,From,To,index=0,left_closed=True,right_closed=True):

        A=From-index+(not left_closed)

        B=To-index-(not right_closed)

        return self.__sub_array_second(A,B+1,0,0,self.num)

    def __sub_array_second(self,a,b,k,l,r):

        if r<=a or b<=l:

            return self.unit

        elif a<=l and r<=b:

            return self.data[k]

        else:

            alpha=self.__sub_array_second(a,b,2*k+1,l,(l+r)//2)

            beta=self.__sub_array_second(a,b,2*k+2,(l+r)//2,r)

            return self.calc(alpha,beta)

    def all_prod(self):

        return self.data[0]

    def max_right(self,l,r,cond,index=0):

        """以下の2つをともに満たすxの1つを返す.\n

        (1) r=l or cond(data[l]*data[l+1]*...*d[r-1]):True

        (2) r=x or cond(data[l]*data[l+1]*...*data[r]):False

        ※fが単調減少の時,cond(data[l]*...*data[r-1])を満たす最大のrとなる.

        cond:関数(引数が同じならば結果も同じ)

        cond(unit):True

        0<=l<=r<=n

        """

        l-=index

        assert 0<=l<=r<=self.num,"添字が範囲外"

        assert cond(self.unit),"単位元が条件を満たさない."

        if l==r:

            return r+index

        l+=(self.num-1)

        sm=self.unit

        calc=self.calc

        while True:

            while l%2:

                l=(l-1)>>1

            if not cond(calc(sm,self.data[l])):

                while l<self.num-1:

                    l=2*l+1

                    if cond(calc(sm,self.data[l])):

                        sm=calc(sm,self.data[l])

                        l+=1

                return min(l-(self.num-1)+index,r)

            sm=calc(sm,self.data[l])

            l+=1

            m=l+1

            if not (m&(-m) !=m):

                break

        return r+index

#================================================

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

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

S=Segment_Tree(N,lambda x,y:max(x,y),-1,A)

X=[]

for _ in range(Q):

    T,alpha,beta=list(map(int,input().split()))

    if T==1:

        S.update(alpha,beta,1)

    elif T==2:

        X.append(S.sub_array(alpha,beta,1))

    else:

        X.append(S.max_right(alpha,N,lambda x:x<beta,1))

print(("\n".join(map(str,X))))

class Segment_Tree:
    def __init__(self, N, calc, unit, L=[]):
        """calcを演算とするN項のSegment Treeを作成
        N:要素数
        calc:演算(2変数関数,モノイド)
        unit:モノイドcalcの単位元 (xe=ex=xを満たすe)
        """
        self.calc = calc
        self.unit = unit
        N = max(N, len(L))
        d = max(1, (N - 1).bit_length())
        k = 2**d
        X = [unit] * (k - 1) + L + [unit] * (k - len(L))
        self.num = k
        self.depth = d
        for i in range(k - 2, -1, -1):
            X[i] = calc(X[2 * i + 1], X[2 * i + 2])
        self.data = X

    def index(self, k, index=0):
        return self.data[(self.num - 1) + (k - index)]

    def update(self, k, x, index=0):
        """第k要素をxに変え,更新を行う.
        k:数列の要素
        x:更新後の値
        """
        m = (self.num - 1) + (k - index)
        self.data[m] = x
        for _ in range(self.depth):
            m = (m - 1) // 2
            self.data[m] = self.calc(self.data[2 * m + 1], self.data[2 * m + 2])

    def sub_array(self, From, To, index=0, left_closed=True, right_closed=True):
        A = From - index + (not left_closed)
        B = To - index - (not right_closed)
        return self.__sub_array_second(A, B + 1, 0, 0, self.num)

    def __sub_array_second(self, a, b, k, l, r):
        if r <= a or b <= l:
            return self.unit
        elif a <= l and r <= b:
            return self.data[k]
        else:
            alpha = self.__sub_array_second(a, b, 2 * k + 1, l, (l + r) // 2)
            beta = self.__sub_array_second(a, b, 2 * k + 2, (l + r) // 2, r)
            return self.calc(alpha, beta)

    def all_prod(self):
        return self.data[0]

    def max_right(self, l, r, cond, index=0):
        """以下の2つをともに満たすxの1つを返す.\n
        (1) r=l or cond(data[l]*data[l+1]*...*d[r-1]):True
        (2) r=x or cond(data[l]*data[l+1]*...*data[r]):False
        ※fが単調減少の時,cond(data[l]*...*data[r-1])を満たす最大のrとなる.
        cond:関数(引数が同じならば結果も同じ)
        cond(unit):True
        0<=l<=r<=n
        """
        l -= index
        assert 0 <= l <= r <= self.num, "添字が範囲外"
        assert cond(self.unit), "単位元が条件を満たさない."
        if l == r:
            return r + index
        l += self.num - 1
        sm = self.unit
        calc = self.calc
        while True:
            while l % 2:
                l = (l - 1) >> 1
            if not cond(calc(sm, self.data[l])):
                while l < self.num - 1:
                    l = 2 * l + 1
                    if cond(calc(sm, self.data[l])):
                        sm = calc(sm, self.data[l])
                        l += 1
                return min(l - (self.num - 1) + index, r)
            sm = calc(sm, self.data[l])
            l += 1
            m = l + 1
            if not (m & (-m) != m):
                break
        return r + index

# ================================================
N, Q = list(map(int, input().split()))
A = list(map(int, input().split()))
S = Segment_Tree(N, lambda x, y: max(x, y), -float("inf"), A)
X = []
for _ in range(Q):
    T, alpha, beta = list(map(int, input().split()))
    if T == 1:
        S.update(alpha, beta, 1)
    elif T == 2:
        X.append(S.sub_array(alpha, beta, 1))
    else:
        X.append(S.max_right(alpha, N, lambda x: x < beta, 1))
print(("\n".join(map(str, X))))

class Segment_Tree:
    def __init__(self, N, calc, unit, L=[]):
        """calcを演算とするN項のSegment Treeを作成
        N:要素数
        calc:演算(2変数関数,モノイド)
        unit:モノイドcalcの単位元 (xe=ex=xを満たすe)
        """
        self.calc = calc
        self.unit = unit
        N = max(N, len(L))
        d = max(1, (N - 1).bit_length())
        k = 2**d
        X = [unit] * (k - 1) + L + [unit] * (k - len(L))
        self.num = k
        self.depth = d
        for i in range(k - 2, -1, -1):
            X[i] = calc(X[2 * i + 1], X[2 * i + 2])
        self.data = X

    def index(self, k, index=0):
        return self.data[(self.num - 1) + (k - index)]

    def update(self, k, x, index=0):
        """第k要素をxに変え,更新を行う.
        k:数列の要素
        x:更新後の値
        """
        m = (self.num - 1) + (k - index)
        self.data[m] = x
        for _ in range(self.depth):
            m = (m - 1) // 2
            self.data[m] = self.calc(self.data[2 * m + 1], self.data[2 * m + 2])

    def sub_array(self, From, To, index=0, left_closed=True, right_closed=True):
        A = From - index + (not left_closed)
        B = To - index - (not right_closed)
        return self.__sub_array_second(A, B + 1, 0, 0, self.num)

    def __sub_array_second(self, a, b, k, l, r):
        if r <= a or b <= l:
            return self.unit
        elif a <= l and r <= b:
            return self.data[k]
        else:
            alpha = self.__sub_array_second(a, b, 2 * k + 1, l, (l + r) // 2)
            beta = self.__sub_array_second(a, b, 2 * k + 2, (l + r) // 2, r)
            return self.calc(alpha, beta)

    def all_prod(self):
        return self.data[0]

    def max_right(self, l, r, cond, index=0):
        """以下の2つをともに満たすxの1つを返す.\n
        (1) r=l or cond(data[l]*data[l+1]*...*d[r-1]):True
        (2) r=x or cond(data[l]*data[l+1]*...*data[r]):False
        ※fが単調減少の時,cond(data[l]*...*data[r-1])を満たす最大のrとなる.
        cond:関数(引数が同じならば結果も同じ)
        cond(unit):True
        0<=l<=r<=n
        """
        l -= index
        assert 0 <= l <= r <= self.num, "添字が範囲外"
        assert cond(self.unit), "単位元が条件を満たさない."
        if l == r:
            return r + index
        l += self.num - 1
        sm = self.unit
        calc = self.calc
        while True:
            while l % 2:
                l = (l - 1) >> 1
            if not cond(calc(sm, self.data[l])):
                while l < self.num - 1:
                    l = 2 * l + 1
                    if cond(calc(sm, self.data[l])):
                        sm = calc(sm, self.data[l])
                        l += 1
                return min(l - (self.num - 1) + index, r)
            sm = calc(sm, self.data[l])
            l += 1
            m = l + 1
            if not (m & (-m) != m):
                break
        return r + index

# ================================================
N, Q = list(map(int, input().split()))
A = list(map(int, input().split()))
S = Segment_Tree(N, lambda x, y: max(x, y), -1, A)
X = []
for _ in range(Q):
    T, alpha, beta = list(map(int, input().split()))
    if T == 1:
        S.update(alpha, beta, 1)
    elif T == 2:
        X.append(S.sub_array(alpha, beta, 1))
    else:
        X.append(S.max_right(alpha, N, lambda x: x < beta, 1))
print(("\n".join(map(str, X))))

-S = Segment_Tree(N, lambda x, y: max(x, y), -float("inf"), A)

+S = Segment_Tree(N, lambda x, y: max(x, y), -1, A)


Input:
def main():

    import collections

    S = eval(input())

    T = eval(input())

    table = collections.defaultdict(set)

    table2 = collections.defaultdict(set)

    a = []

    b = []

    for i, xy in enumerate(zip(S, T)):

        x, y = xy

        if x not in table:

            a.append(i)

        if y not in table2:

            b.append(i)

        table[x].add(i)

        table2[y].add(i)

    flag = True

    if a != b:

        flag = False

    for i in a:

        if flag:

            if table[S[i]] == table2[T[i]]:

                continue

            else:

                flag = False

                break

    if flag:

        print("Yes")

    else:

        print("No")

main()

def main():

    import collections

    S = eval(input())

    T = eval(input())

    N = len(S)

    table = collections.defaultdict(int)

    table2 = collections.defaultdict(int)

    flag = True

    for i in range(N):

        x = S[i]

        y = T[i]

        if x in table:

            if y == T[table[x]]:

                continue

            else:

                flag = False

                break

        else:

            if y in table2:

                flag = False

                break

            table[x] = i

            table2[y] = i

    if flag:

        print("Yes")

    else:

        print("No")

main()

-    table = collections.defaultdict(set)

-    table2 = collections.defaultdict(set)

+    table = collections.defaultdict(int)

+    table2 = collections.defaultdict(int)

-            if table[S[i]] == table2[T[i]]:


Input:
N=int(eval(input()))

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

n=int(eval(input()))

i=0

for m in range(n+1):

	i=i+m

print(i)

N = int(eval(input()))
print((N * (N + 1) // 2))

n = int(eval(input()))
i = 0
for m in range(n + 1):
    i = i + m
print(i)

-N = int(eval(input()))
-print((N * (N + 1) // 2))
+n = int(eval(input()))
+i = 0
+for m in range(n + 1):
+    i = i + m
+print(i)


Input:
from sys import stdin

import sys

A, B, N = [int(x) for x in stdin.readline().rstrip().split()]

# N, M = [int(x) for x in stdin.readline().rstrip().split()]

# U = input().split()

x=min(B-1,N)

ans = int((A*x)/B)-A*int(x/B)

print(ans)

# if N >= B:

from sys import stdin

import sys

A, B, N = [int(x) for x in stdin.readline().rstrip().split()]

# N, M = [int(x) for x in stdin.readline().rstrip().split()]

# U = input().split()

ans = int((A*N)/B)-A*int(N/B)

ans2=0

if B-1<N:

	ans = int((A*(B-1))/B)-A*int((B-1)/B)

else:

  	ans2=0

print(ans)

from sys import stdin
import sys

A, B, N = [int(x) for x in stdin.readline().rstrip().split()]
# N, M = [int(x) for x in stdin.readline().rstrip().split()]
# U = input().split()
x = min(B - 1, N)
ans = int((A * x) / B) - A * int(x / B)
print(ans)
# if N >= B:

from sys import stdin
import sys

A, B, N = [int(x) for x in stdin.readline().rstrip().split()]
# N, M = [int(x) for x in stdin.readline().rstrip().split()]
# U = input().split()
ans = int((A * N) / B) - A * int(N / B)
ans2 = 0
if B - 1 < N:
    ans = int((A * (B - 1)) / B) - A * int((B - 1) / B)
else:
    ans2 = 0
print(ans)

-ans = int((A * x) / B) - A * int(x / B)

+ans = int((A * N) / B) - A * int(N / B)


Input:
S = '>' + eval(input()) + '<='

l = len(S)

A = [0] * (l-2)

zero_posi = []

max_posi = []

for i in range(l-2):

    now = S[i]

    nex = S[i+1]

    if S[i] == '>' and S[i+1] =='<':

        A[i] = 0

        zero_posi.append(i)

while zero_posi:

    start = zero_posi.pop()

    count = 0

    for i in range(start, -1, -1):

        A[i] = max(A[i], count)

        count += 1

        if S[i-1] == '<':

            A[i-1] = max(A[i], count)

            break

    count = 0

    for i in range(start, l-2):

        A[i] = max(A[i], count)

        count += 1

        if S[i + 1] == '>':

            break

ans = sum(A)

print(ans)

S = eval(input())

l = len(S)

A = [0] * (l+1)

count = 0

for i, s in enumerate(S):

    if s == '>':

        count = 0

    else:

        count += 1

        A[i+1] = count

count = 0

for i in range(l-1, -1, -1):

    s = S[i]

    if s == '<':

        count = 0

    else:

        count += 1

        A[i] = max(A[i], count)

print((sum(A)))

S = ">" + eval(input()) + "<="
l = len(S)
A = [0] * (l - 2)
zero_posi = []
max_posi = []
for i in range(l - 2):
    now = S[i]
    nex = S[i + 1]
    if S[i] == ">" and S[i + 1] == "<":
        A[i] = 0
        zero_posi.append(i)
while zero_posi:
    start = zero_posi.pop()
    count = 0
    for i in range(start, -1, -1):
        A[i] = max(A[i], count)
        count += 1
        if S[i - 1] == "<":
            A[i - 1] = max(A[i], count)
            break
    count = 0
    for i in range(start, l - 2):
        A[i] = max(A[i], count)
        count += 1
        if S[i + 1] == ">":
            break
ans = sum(A)
print(ans)

S = eval(input())
l = len(S)
A = [0] * (l + 1)
count = 0
for i, s in enumerate(S):
    if s == ">":
        count = 0
    else:
        count += 1
        A[i + 1] = count
count = 0
for i in range(l - 1, -1, -1):
    s = S[i]
    if s == "<":
        count = 0
    else:
        count += 1
        A[i] = max(A[i], count)
print((sum(A)))

-            A[i - 1] = max(A[i], count)


Input:
#!/usr/bin/env python

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

"""

input:

2 1 1

2

0 1 4 1

3 0 3 3

output:

1.00000000 1.00000000 3.00000000 1.00000000

3.00000000 1.00000000 3.00000000 1.00000000

"""

import sys

import math

class Segment(object):

    __slots__ = ('source', 'target')

    def __init__(self, source, target):

        self.source = complex(source)

        self.target = complex(target)

class Circle(object):

    __slots__ = ('centre', 'radius')

    def __init__(self, x, y, r):

        self.centre = x + y * 1j

        self.radius = r

def dot(a, b):

    return a.real * b.real + a.imag * b.imag

def project(s, p):

    base_vector = s.target - s.source

    prj_ratio = dot(p - s.source, base_vector) / pow(abs(base_vector), 2)

    return s.source + base_vector * prj_ratio

def get_cross_point(c, l):

    prj_vector = project(l, c.centre)

    line_unit_vector = (l.target - l.source) / (abs(l.target - l.source))

    base = math.sqrt(pow(c.radius, 2) - pow(abs(prj_vector - c.centre), 2))

    p1, p2 = prj_vector + line_unit_vector * base, prj_vector - line_unit_vector * base

    if p1.real < p2.real:

        ans = (p1, p2)

    elif p1.real == p2.real:

        if p1.imag < p2.imag:

            ans = (p1, p2)

        else:

            ans = (p2, p1)

    else:

        ans = (p2, p1)

    return ans

def solve(_lines):

    for line in _lines:

        line_axis = tuple(map(int, line))

        p0, p1 = (x + y * 1j for x, y in zip(line_axis[::2], line_axis[1::2]))

        l = Segment(p0, p1)

        cp1, cp2 = get_cross_point(circle, l)

        print(('{0:.8f} {1:.8f} {2:.8f} {3:.8f}'.format(cp1.real, cp1.imag, cp2.real, cp2.imag)))

    return None

if __name__ == '__main__':

    _input = sys.stdin.readlines()

    cx, cy, radius = list(map(int, _input[0].split()))

    q_num = int(_input[1])

    lines = [x.split() for x in _input[2:]]

    circle = Circle(cx, cy, radius)

    solve(lines)

#!/usr/bin/env python

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

"""

input:

2 1 1

2

0 1 4 1

3 0 3 3

output:

1.00000000 1.00000000 3.00000000 1.00000000

3.00000000 1.00000000 3.00000000 1.00000000

"""

import sys

import math

class Segment(object):

    __slots__ = ('source', 'target')

    def __init__(self, source, target):

        self.source = complex(source)

        self.target = complex(target)

class Circle(object):

    __slots__ = ('centre', 'radius')

    def __init__(self, centre, radius):

        self.centre = complex(centre)

        self.radius = float(radius)

def dot(a, b):

    return a.real * b.real + a.imag * b.imag

def project(s, p):

    base_vector = s.target - s.source

    prj_ratio = dot(p - s.source, base_vector) / pow(abs(base_vector), 2)

    return s.source + base_vector * prj_ratio

def get_cross_point(c, l):

    prj_vector = project(l, c.centre)

    line_unit_vector = (l.target - l.source) / (abs(l.target - l.source))

    base = math.sqrt(pow(c.radius, 2) - pow(abs(prj_vector - c.centre), 2))

    p1, p2 = prj_vector + line_unit_vector * base, prj_vector - line_unit_vector * base

    if p1.real < p2.real:

        ans = (p1, p2)

    elif p1.real == p2.real:

        if p1.imag < p2.imag:

            ans = (p1, p2)

        else:

            ans = (p2, p1)

    else:

        ans = (p2, p1)

    return ans

def solve(_lines):

    for line in _lines:

        line_axis = tuple(map(int, line))

        p0, p1 = (x + y * 1j for x, y in zip(line_axis[::2], line_axis[1::2]))

        l = Segment(p0, p1)

        cp1, cp2 = get_cross_point(circle, l)

        print(('{0:.8f} {1:.8f} {2:.8f} {3:.8f}'.format(cp1.real, cp1.imag, cp2.real, cp2.imag)))

    return None

if __name__ == '__main__':

    _input = sys.stdin.readlines()

    cx, cy, r = list(map(int, _input[0].split()))

    q_num = int(_input[1])

    lines = [x.split() for x in _input[2:]]

    circle = Circle(cx + cy * 1j, r)

    solve(lines)

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
2 1 1
2
0 1 4 1
3 0 3 3
output:
1.00000000 1.00000000 3.00000000 1.00000000
3.00000000 1.00000000 3.00000000 1.00000000
"""
import sys
import math

class Segment(object):
    __slots__ = ("source", "target")

    def __init__(self, source, target):
        self.source = complex(source)
        self.target = complex(target)

class Circle(object):
    __slots__ = ("centre", "radius")

    def __init__(self, x, y, r):
        self.centre = x + y * 1j
        self.radius = r

def dot(a, b):
    return a.real * b.real + a.imag * b.imag

def project(s, p):
    base_vector = s.target - s.source
    prj_ratio = dot(p - s.source, base_vector) / pow(abs(base_vector), 2)
    return s.source + base_vector * prj_ratio

def get_cross_point(c, l):
    prj_vector = project(l, c.centre)
    line_unit_vector = (l.target - l.source) / (abs(l.target - l.source))
    base = math.sqrt(pow(c.radius, 2) - pow(abs(prj_vector - c.centre), 2))
    p1, p2 = prj_vector + line_unit_vector * base, prj_vector - line_unit_vector * base
    if p1.real < p2.real:
        ans = (p1, p2)
    elif p1.real == p2.real:
        if p1.imag < p2.imag:
            ans = (p1, p2)
        else:
            ans = (p2, p1)
    else:
        ans = (p2, p1)
    return ans

def solve(_lines):
    for line in _lines:
        line_axis = tuple(map(int, line))
        p0, p1 = (x + y * 1j for x, y in zip(line_axis[::2], line_axis[1::2]))
        l = Segment(p0, p1)
        cp1, cp2 = get_cross_point(circle, l)
        print(
            (
                "{0:.8f} {1:.8f} {2:.8f} {3:.8f}".format(
                    cp1.real, cp1.imag, cp2.real, cp2.imag
                )
            )
        )
    return None

if __name__ == "__main__":
    _input = sys.stdin.readlines()
    cx, cy, radius = list(map(int, _input[0].split()))
    q_num = int(_input[1])
    lines = [x.split() for x in _input[2:]]
    circle = Circle(cx, cy, radius)
    solve(lines)

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
2 1 1
2
0 1 4 1
3 0 3 3
output:
1.00000000 1.00000000 3.00000000 1.00000000
3.00000000 1.00000000 3.00000000 1.00000000
"""
import sys
import math

class Segment(object):
    __slots__ = ("source", "target")

    def __init__(self, source, target):
        self.source = complex(source)
        self.target = complex(target)

class Circle(object):
    __slots__ = ("centre", "radius")

    def __init__(self, centre, radius):
        self.centre = complex(centre)
        self.radius = float(radius)

def dot(a, b):
    return a.real * b.real + a.imag * b.imag

def project(s, p):
    base_vector = s.target - s.source
    prj_ratio = dot(p - s.source, base_vector) / pow(abs(base_vector), 2)
    return s.source + base_vector * prj_ratio

def get_cross_point(c, l):
    prj_vector = project(l, c.centre)
    line_unit_vector = (l.target - l.source) / (abs(l.target - l.source))
    base = math.sqrt(pow(c.radius, 2) - pow(abs(prj_vector - c.centre), 2))
    p1, p2 = prj_vector + line_unit_vector * base, prj_vector - line_unit_vector * base
    if p1.real < p2.real:
        ans = (p1, p2)
    elif p1.real == p2.real:
        if p1.imag < p2.imag:
            ans = (p1, p2)
        else:
            ans = (p2, p1)
    else:
        ans = (p2, p1)
    return ans

def solve(_lines):
    for line in _lines:
        line_axis = tuple(map(int, line))
        p0, p1 = (x + y * 1j for x, y in zip(line_axis[::2], line_axis[1::2]))
        l = Segment(p0, p1)
        cp1, cp2 = get_cross_point(circle, l)
        print(
            (
                "{0:.8f} {1:.8f} {2:.8f} {3:.8f}".format(
                    cp1.real, cp1.imag, cp2.real, cp2.imag
                )
            )
        )
    return None

if __name__ == "__main__":
    _input = sys.stdin.readlines()
    cx, cy, r = list(map(int, _input[0].split()))
    q_num = int(_input[1])
    lines = [x.split() for x in _input[2:]]
    circle = Circle(cx + cy * 1j, r)
    solve(lines)

+    def __init__(self, centre, radius):

-    cx, cy, radius = list(map(int, _input[0].split()))

+    cx, cy, r = list(map(int, _input[0].split()))


Input:
import sys

import numpy as np

from collections import Counter

read = sys.stdin

N, K = list(map(int, read.readline().split()))

k = 2 * K

xyc = np.array(read.read().split(), np.str).reshape(-1, 3)

x = xyc[:, 0].astype(int)

y = xyc[:, 1].astype(int)

c = xyc[:, 2]

x[c == 'B'] -= K

x %= k

y %= k

'''

# grid[[1,1],[2,2]]+=1 としてもgrid[1,2]=1であり重複は考慮されない。

# uniqueを使って(x,y)の重複をカウントする

# return_countはver1.9からだった・・・ ダメじゃん

xy, cnt = np.unique(x + y * 10000, return_counts=True)

x = xy % 10000

y = xy // 10000

'''

xy = Counter(list(zip(x.tolist(), y.tolist())))

cnt = np.array(list(xy.values()), np.int64)

xy = np.array(list(xy.keys()), np.int64)

x = xy[:, 0]

y = xy[:, 1]

grid = np.zeros((3 * K, 3 * K), np.int64)

grid[x, y] += cnt

grid[x + K, y + K] += cnt

grid[x + K, y] -= cnt

grid[x, y + K] -= cnt

np.cumsum(grid, axis=0, out=grid)

np.cumsum(grid, axis=1, out=grid)

p1 = grid[:K, :K] + grid[k:, k:] + grid[K:k, K:k] + grid[k:, :K] + grid[:K, k:]

p2 = grid[K:k, :K] + grid[K:k, k:] + grid[:K, K:k] + grid[k:, K:k]

print((max(p1.max(), p2.max())))

import sys

import numpy as np

from collections import Counter

read = sys.stdin

N, K = list(map(int, read.readline().split()))

k = 2 * K

xyc = np.array(read.read().split(), np.str).reshape(-1, 3)

x = xyc[:, 0].astype(int)

y = xyc[:, 1].astype(int)

c = xyc[:, 2]

x[c == 'B'] -= K

x %= k

y %= k

grid = np.zeros((3 * K, 3 * K), np.int64)

np.add.at(grid, (x, y), 1)

np.add.at(grid, (x + K, y + K), 1)

np.subtract.at(grid, (x + K, y), 1)

np.subtract.at(grid, (x, y + K), 1)

np.cumsum(grid, axis=0, out=grid)

np.cumsum(grid, axis=1, out=grid)

p1 = grid[:K, :K] + grid[k:, k:] + grid[K:k, K:k] + grid[k:, :K] + grid[:K, k:]

p2 = grid[K:k, :K] + grid[K:k, k:] + grid[:K, K:k] + grid[k:, K:k]

print((max(p1.max(), p2.max())))

import sys
import numpy as np
from collections import Counter

read = sys.stdin
N, K = list(map(int, read.readline().split()))
k = 2 * K
xyc = np.array(read.read().split(), np.str).reshape(-1, 3)
x = xyc[:, 0].astype(int)
y = xyc[:, 1].astype(int)
c = xyc[:, 2]
x[c == "B"] -= K
x %= k
y %= k
"""
# grid[[1,1],[2,2]]+=1 としてもgrid[1,2]=1であり重複は考慮されない。
# uniqueを使って(x,y)の重複をカウントする
# return_countはver1.9からだった・・・ ダメじゃん
xy, cnt = np.unique(x + y * 10000, return_counts=True)
x = xy % 10000
y = xy // 10000
"""
xy = Counter(list(zip(x.tolist(), y.tolist())))
cnt = np.array(list(xy.values()), np.int64)
xy = np.array(list(xy.keys()), np.int64)
x = xy[:, 0]
y = xy[:, 1]
grid = np.zeros((3 * K, 3 * K), np.int64)
grid[x, y] += cnt
grid[x + K, y + K] += cnt
grid[x + K, y] -= cnt
grid[x, y + K] -= cnt
np.cumsum(grid, axis=0, out=grid)
np.cumsum(grid, axis=1, out=grid)
p1 = grid[:K, :K] + grid[k:, k:] + grid[K:k, K:k] + grid[k:, :K] + grid[:K, k:]
p2 = grid[K:k, :K] + grid[K:k, k:] + grid[:K, K:k] + grid[k:, K:k]
print((max(p1.max(), p2.max())))

import sys
import numpy as np
from collections import Counter

read = sys.stdin
N, K = list(map(int, read.readline().split()))
k = 2 * K
xyc = np.array(read.read().split(), np.str).reshape(-1, 3)
x = xyc[:, 0].astype(int)
y = xyc[:, 1].astype(int)
c = xyc[:, 2]
x[c == "B"] -= K
x %= k
y %= k
grid = np.zeros((3 * K, 3 * K), np.int64)
np.add.at(grid, (x, y), 1)
np.add.at(grid, (x + K, y + K), 1)
np.subtract.at(grid, (x + K, y), 1)
np.subtract.at(grid, (x, y + K), 1)
np.cumsum(grid, axis=0, out=grid)
np.cumsum(grid, axis=1, out=grid)
p1 = grid[:K, :K] + grid[k:, k:] + grid[K:k, K:k] + grid[k:, :K] + grid[:K, k:]
p2 = grid[K:k, :K] + grid[K:k, k:] + grid[:K, K:k] + grid[k:, K:k]
print((max(p1.max(), p2.max())))

-# grid[[1,1],[2,2]]+=1 としてもgrid[1,2]=1であり重複は考慮されない。

-# uniqueを使って(x,y)の重複をカウントする

-xy, cnt = np.unique(x + y * 10000, return_counts=True)

-xy = Counter(list(zip(x.tolist(), y.tolist())))

-cnt = np.array(list(xy.values()), np.int64)

-xy = np.array(list(xy.keys()), np.int64)


Input:
N, K = list(map(int, input().split()))

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

answer = []

for i in range(N):

  if i + K > N:

    break

  Ys, Yt = X[i], X[i+K-1]

  if Ys > 0:

    answer.append(Yt)

  elif Yt < 0:

    answer.append(-Ys)

  else:

    answer.append(min(Ys*(-2)+Yt, Yt*2-Ys))

print((min(answer)))

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

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

answer = 10 ** 18

for i in range(N - K + 1):

    left, right = i, i + K - 1

    al, ar = abs(X[left]), abs(X[right])

    if X[left] * X[right] >= 0:

        answer = min(answer, max(al, ar))

    else:

        answer = min(answer, al * 2 + ar, al + ar * 2)

print(answer)

N, K = list(map(int, input().split()))
X = list(map(int, input().split()))
answer = []
for i in range(N):
    if i + K > N:
        break
    Ys, Yt = X[i], X[i + K - 1]
    if Ys > 0:
        answer.append(Yt)
    elif Yt < 0:
        answer.append(-Ys)
    else:
        answer.append(min(Ys * (-2) + Yt, Yt * 2 - Ys))
print((min(answer)))

N, K = list(map(int, input().split()))
X = list(map(int, input().split()))
answer = 10**18
for i in range(N - K + 1):
    left, right = i, i + K - 1
    al, ar = abs(X[left]), abs(X[right])
    if X[left] * X[right] >= 0:
        answer = min(answer, max(al, ar))
    else:
        answer = min(answer, al * 2 + ar, al + ar * 2)
print(answer)

+    al, ar = abs(X[left]), abs(X[right])

+        answer = min(answer, max(al, ar))

-        answer.append(min(Ys * (-2) + Yt, Yt * 2 - Ys))

+        answer = min(answer, al * 2 + ar, al + ar * 2)


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

mod = 10**9+7

a = min(a,n-a)

b = min(b,n-b)

m = max(a,b)

X = [0]*(m+1)

Y = [0]*(m+1)

X[0] = 1

X[1] = n

Y[0] = Y[1] = 1

for i in range(2,m+1):

    X[i] = X[i-1]*(n-i+1)%mod

    Y[i] = Y[i-1]*i%mod

ans = (((pow(2,n,mod)-1)%mod-X[a]*pow(Y[a],mod-2,mod)%mod)%mod-X[b]*pow(Y[b],mod-2,mod)%mod)%mod

print(ans)

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

mod = 10**9+7

def combmod(n,k,mod):

    x = y = 1

    for i in range(min(k,n-k)):

        x = x*(n-i)%mod

        y = y*(i+1)%mod

    return x * pow(y, mod-2, mod) % mod

ans = (((pow(2, n, mod) - 1)%mod - combmod(n, a, mod))%mod - combmod(n, b, mod))%mod

print(ans)

n, a, b = list(map(int, input().split()))
mod = 10**9 + 7

def combmod(n, k, mod):
    x = y = 1
    for i in range(min(k, n - k)):
        x = x * (n - i) % mod
        y = y * (i + 1) % mod
    return x * pow(y, mod - 2, mod) % mod

ans = (
    ((pow(2, n, mod) - 1) % mod - combmod(n, a, mod)) % mod - combmod(n, b, mod)
) % mod
print(ans)

+    return x * pow(y, mod - 2, mod) % mod

-    ((pow(2, n, mod) - 1) % mod - X[a] * pow(Y[a], mod - 2, mod) % mod) % mod

-    - X[b] * pow(Y[b], mod - 2, mod) % mod

+    ((pow(2, n, mod) - 1) % mod - combmod(n, a, mod)) % mod - combmod(n, b, mod)


Input:
N, K = list(map(int, input().split()))

num = [0] * K

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

    num[i % K] += 1

res = 0

for a in range(K):

    b = (K - a) % K

    c = (K - a) % K

    if (b + c) % K == 0:

        res += num[a] * num[b] * num[c]

print(res)

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

x = N // K

ans = x ** 3

if K % 2 == 0:

    y = (N + (K // 2)) // K

    ans += y ** 3

print(ans)

N, K = list(map(int, input().split()))
x = N // K
ans = x**3
if K % 2 == 0:
    y = (N + (K // 2)) // K
    ans += y**3
print(ans)

-        res += num[a] * num[b] * num[c]


Input:
A = int(eval(input()))

B = int(eval(input()))

if A > B :

    print('GREATER')

elif A == B:

    print('EQUAL')

else:

    print('LESS')

A = list(eval(input()))

B = list(eval(input()))

if len(A) > len(B):

    print("GREATER")

elif len(B) > len(A):

    print("LESS")

else:

    for i in range(len(A)):

        if int(A[i]) > int(B[i]):

            print("GREATER")

            quit()

        elif int(A[i]) < int(B[i]):

            print("LESS")

            quit()

        else:

            if i  == len(A) - 1 and int(A[i])==int(B[i]):

                print("EQUAL")

A = int(eval(input()))
B = int(eval(input()))
if A > B:
    print("GREATER")
elif A == B:
    print("EQUAL")
else:
    print("LESS")

A = list(eval(input()))
B = list(eval(input()))
if len(A) > len(B):
    print("GREATER")
elif len(B) > len(A):
    print("LESS")
else:
    for i in range(len(A)):
        if int(A[i]) > int(B[i]):
            print("GREATER")
            quit()
        elif int(A[i]) < int(B[i]):
            print("LESS")
            quit()
        else:
            if i == len(A) - 1 and int(A[i]) == int(B[i]):
                print("EQUAL")

+            if i == len(A) - 1 and int(A[i]) == int(B[i]):


Input:
h, w = (int(x) for x in input().split())

ab=[]

ab.append(['#']*(w+2))

for _ in range(h):

    s=eval(input())

    s=list(s)

    s =['#'] + s + ['#']

    ab.append(s)

ab.append(['#']*(w+2))

for i in range(h+2):

    k=ab[i]

    print((''.join(map(str,k))))

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

ans = []

top = ['#']*(W+2)

ans.append(top)

for i in range(H):

    t = list(eval(input()))

    t = ['#'] + t + ['#']

    ans.append(t)

ans.append(top)

for aa in ans:

    print((''.join(map(str,aa))))

h, w = (int(x) for x in input().split())
ab = []
ab.append(["#"] * (w + 2))
for _ in range(h):
    s = eval(input())
    s = list(s)
    s = ["#"] + s + ["#"]
    ab.append(s)
ab.append(["#"] * (w + 2))
for i in range(h + 2):
    k = ab[i]
    print(("".join(map(str, k))))

H, W = list(map(int, input().split()))
ans = []
top = ["#"] * (W + 2)
ans.append(top)
for i in range(H):
    t = list(eval(input()))
    t = ["#"] + t + ["#"]
    ans.append(t)
ans.append(top)
for aa in ans:
    print(("".join(map(str, aa))))

-h, w = (int(x) for x in input().split())


Input:
import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

from copy import deepcopy

from collections import deque

def main():

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

    m = map(int, read().split())

    n = deepcopy(m)

    to = [[] for _ in range(N)]

    for a, b in [(a-1, b-1) for a, b in zip(m, m)][:N-1]:

        to[a].append(b)

        to[b].append(a)

    score = [0 for _ in range(N)]

    for p, x in [(p-1, x) for p, x in zip(n, n)][N-1:]:

        score[p] += x

    dq = deque()

    dq.append(0)

    done = [0 for _ in range(N)]

    done[0] = 1

    while len(dq)>0:

        node = dq.popleft()

        for nx in to[node]:

            if done[nx] == 1:

                continue

            done[nx] = 1

            score[nx] += score[node]

            dq.append(nx)

    for i in score:

        print(i, end=' ')

if __name__ == '__main__':

    main()

import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

from collections import deque

def main():

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

    to = [[] for _ in range(N)]

    for _ in range(N-1):

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

        a -= 1

        b -= 1

        to[a].append(b)

        to[b].append(a)

    score = [0 for  _ in range(N)]

    for _ in range(Q):

        p, x = map(int, readline().split())

        p -= 1

        score[p] += x

    dq = deque()

    dq.append(0)

    done = [0 for _ in range(N)]

    done[0] = 1

    while len(dq)>0:

        v = dq.popleft()

        for nx in to[v]:

            if done[nx]:

                continue

            score[nx] += score[v]

            done[nx] = 1

            dq.append(nx)

    for i in range(N):

        if i==N-1:

            print(score[i])

        else:

            print(score[i], end=' ')

if __name__ == '__main__':

    main()

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from copy import deepcopy
from collections import deque

def main():
    N, Q = map(int, readline().split())
    m = map(int, read().split())
    n = deepcopy(m)
    to = [[] for _ in range(N)]
    for a, b in [(a - 1, b - 1) for a, b in zip(m, m)][: N - 1]:
        to[a].append(b)
        to[b].append(a)
    score = [0 for _ in range(N)]
    for p, x in [(p - 1, x) for p, x in zip(n, n)][N - 1 :]:
        score[p] += x
    dq = deque()
    dq.append(0)
    done = [0 for _ in range(N)]
    done[0] = 1
    while len(dq) > 0:
        node = dq.popleft()
        for nx in to[node]:
            if done[nx] == 1:
                continue
            done[nx] = 1
            score[nx] += score[node]
            dq.append(nx)
    for i in score:
        print(i, end=" ")

if __name__ == "__main__":
    main()

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import deque

def main():
    N, Q = map(int, readline().split())
    to = [[] for _ in range(N)]
    for _ in range(N - 1):
        a, b = map(int, readline().split())
        a -= 1
        b -= 1
        to[a].append(b)
        to[b].append(a)
    score = [0 for _ in range(N)]
    for _ in range(Q):
        p, x = map(int, readline().split())
        p -= 1
        score[p] += x
    dq = deque()
    dq.append(0)
    done = [0 for _ in range(N)]
    done[0] = 1
    while len(dq) > 0:
        v = dq.popleft()
        for nx in to[v]:
            if done[nx]:
                continue
            score[nx] += score[v]
            done[nx] = 1
            dq.append(nx)
    for i in range(N):
        if i == N - 1:
            print(score[i])
        else:
            print(score[i], end=" ")

if __name__ == "__main__":
    main()

-    for a, b in [(a - 1, b - 1) for a, b in zip(m, m)][: N - 1]:

+        a, b = map(int, readline().split())

-    for p, x in [(p - 1, x) for p, x in zip(n, n)][N - 1 :]:

+        p, x = map(int, readline().split())


Input:
n = int(eval(input()))

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

d = {}

for i in a:

  for j in range(i - 1, i + 2): #aの値の両隣まで

    d[j] = d.get(j, 0) + 1#getは第一引数で指定したキーがなかったら第二引数で指定した値を戻す

print((max(d.values())))

N = int(eval(input()))

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

nums = {}

for i in a:

  nums[i] = nums.get(i, 0) + 1

  nums[i+1] = nums.get(i+1, 0) + 1

  nums[i-1] = nums.get(i-1, 0) + 1

ans = 0

for i in list(nums.values()):

  ans = max(ans, i)

print(ans)

n = int(eval(input()))
a = list(map(int, input().split()))
d = {}
for i in a:
    for j in range(i - 1, i + 2):  # aの値の両隣まで
        d[j] = d.get(j, 0) + 1  # getは第一引数で指定したキーがなかったら第二引数で指定した値を戻す
print((max(d.values())))

N = int(eval(input()))
a = list(map(int, input().split()))
nums = {}
for i in a:
    nums[i] = nums.get(i, 0) + 1
    nums[i + 1] = nums.get(i + 1, 0) + 1
    nums[i - 1] = nums.get(i - 1, 0) + 1
ans = 0
for i in list(nums.values()):
    ans = max(ans, i)
print(ans)

-    for j in range(i - 1, i + 2):  # aの値の両隣まで

-        d[j] = d.get(j, 0) + 1  # getは第一引数で指定したキーがなかったら第二引数で指定した値を戻す


Input:
#!/usr/bin/env python

# coding: utf-8

import itertools

def main():

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

    ll = []

    for _ in range(N):

        ll.append(int(eval(input())))

    cand = []

    ids = set(range(N))

    for a in range(1, N-1):

        for b in range(1, N-a):

            for c in range(1, N-a-b+1):

                cand.append((a, b, c))

    best_cost = -1

    for a, b, c in cand:

        la = itertools.combinations(ids, a)

        for a_ in la:

            lb = itertools.combinations(ids-set(a_), b)

            for b_ in lb:

                lc = itertools.combinations(ids-set(a_)-set(b_), c)

                for c_ in lc:

                    cost = (len(a_)-1)*10 + abs(sum(ll[e] for e in a_)-A)

                    cost += (len(b_)-1)*10 + abs(sum(ll[e] for e in b_)-B)

                    cost += (len(c_)-1)*10 + abs(sum(ll[e] for e in c_)-C)

                    if best_cost == -1 or cost < best_cost:

                        best_cost = cost

    print(best_cost)

if __name__ == '__main__':

    main()

#!/usr/bin/env python

# coding: utf-8

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

ll = []

for _ in range(N):

    ll.append(int(eval(input())))

def dfs(n, a, b, c):

    if n == N:

        if a == 0 or b == 0 or c == 0: return float('inf')

        return abs(A-a) + abs(B-b) + abs(C-c)

    ca = dfs(n+1, a+ll[n], b, c)

    if a > 0: ca += 10

    cb = dfs(n+1, a, b+ll[n], c)

    if b > 0: cb += 10

    cc = dfs(n+1, a, b, c+ll[n])

    if c > 0: cc += 10

    cn = dfs(n+1, a, b, c)

    return min(ca, cb, cc, cn)

def main():

    print((dfs(0, 0, 0, 0)))

if __name__ == '__main__':

    main()

#!/usr/bin/env python
# coding: utf-8
import itertools

def main():
    N, A, B, C = list(map(int, input().split()))
    ll = []
    for _ in range(N):
        ll.append(int(eval(input())))
    cand = []
    ids = set(range(N))
    for a in range(1, N - 1):
        for b in range(1, N - a):
            for c in range(1, N - a - b + 1):
                cand.append((a, b, c))
    best_cost = -1
    for a, b, c in cand:
        la = itertools.combinations(ids, a)
        for a_ in la:
            lb = itertools.combinations(ids - set(a_), b)
            for b_ in lb:
                lc = itertools.combinations(ids - set(a_) - set(b_), c)
                for c_ in lc:
                    cost = (len(a_) - 1) * 10 + abs(sum(ll[e] for e in a_) - A)
                    cost += (len(b_) - 1) * 10 + abs(sum(ll[e] for e in b_) - B)
                    cost += (len(c_) - 1) * 10 + abs(sum(ll[e] for e in c_) - C)
                    if best_cost == -1 or cost < best_cost:
                        best_cost = cost
    print(best_cost)

if __name__ == "__main__":
    main()

#!/usr/bin/env python
# coding: utf-8
N, A, B, C = list(map(int, input().split()))
ll = []
for _ in range(N):
    ll.append(int(eval(input())))

def dfs(n, a, b, c):
    if n == N:
        if a == 0 or b == 0 or c == 0:
            return float("inf")
        return abs(A - a) + abs(B - b) + abs(C - c)
    ca = dfs(n + 1, a + ll[n], b, c)
    if a > 0:
        ca += 10
    cb = dfs(n + 1, a, b + ll[n], c)
    if b > 0:
        cb += 10
    cc = dfs(n + 1, a, b, c + ll[n])
    if c > 0:
        cc += 10
    cn = dfs(n + 1, a, b, c)
    return min(ca, cb, cc, cn)

def main():
    print((dfs(0, 0, 0, 0)))

if __name__ == "__main__":
    main()

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

+        return abs(A - a) + abs(B - b) + abs(C - c)

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

-            for c in range(1, N - a - b + 1):

-        la = itertools.combinations(ids, a)

-            lb = itertools.combinations(ids - set(a_), b)

-                lc = itertools.combinations(ids - set(a_) - set(b_), c)

-                    cost = (len(a_) - 1) * 10 + abs(sum(ll[e] for e in a_) - A)

-                    cost += (len(b_) - 1) * 10 + abs(sum(ll[e] for e in b_) - B)

-                    cost += (len(c_) - 1) * 10 + abs(sum(ll[e] for e in c_) - C)

-                    if best_cost == -1 or cost < best_cost:

-                        best_cost = cost


Input:
import sys, re

from collections import deque, defaultdict, Counter

from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd

from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby

from operator import itemgetter, mul

from copy import deepcopy

from string import ascii_lowercase, ascii_uppercase, digits

from bisect import bisect, bisect_left, insort, insort_left

from heapq import heappush, heappop

from functools import reduce, lru_cache

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

def INT(): return int(eval(input()))

def MAP(): return list(map(int, input().split()))

def LIST(): return list(map(int, input().split()))

def TUPLE(): return tuple(map(int, input().split()))

def ZIP(n): return list(zip(*(MAP() for _ in range(n))))

sys.setrecursionlimit(10 ** 9)

INF = float('inf')

mod = 10 ** 9 + 7

#mod = 998244353

from decimal import *

#import numpy as np

#decimal.getcontext().prec = 10

N = INT()

S = eval(input())

former = S[:N]

latter = S[N:][::-1]

dic_f = defaultdict(int)

dic_l = defaultdict(int)

for x in product([0, 1], repeat=N):

	tmp_red = ""

	tmp_blue = ""

	for i in range(N):

		if x[i]:

			tmp_red += former[i]

		else:

			tmp_blue += former[i]

	dic_f["{},{}".format(tmp_red, tmp_blue)] += 1

for x in product([0, 1], repeat=N):

	tmp_red = ""

	tmp_blue = ""

	for i in range(N):

		if x[i]:

			tmp_red += latter[i]

		else:

			tmp_blue += latter[i]

	dic_l["{},{}".format(tmp_red, tmp_blue)] += 1

ans = 0

for key in dic_f:

	ans += dic_f[key] * dic_l[key]

print(ans)

import sys, re

from collections import deque, defaultdict, Counter

from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd

from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby

from operator import itemgetter, mul

from copy import deepcopy

from string import ascii_lowercase, ascii_uppercase, digits

from bisect import bisect, bisect_left, insort, insort_left

from heapq import heappush, heappop

from functools import reduce, lru_cache

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

def INT(): return int(eval(input()))

def MAP(): return list(map(int, input().split()))

def LIST(): return list(map(int, input().split()))

def TUPLE(): return tuple(map(int, input().split()))

def ZIP(n): return list(zip(*(MAP() for _ in range(n))))

sys.setrecursionlimit(10 ** 9)

INF = float('inf')

mod = 10 ** 9 + 7

#mod = 998244353

from decimal import *

#import numpy as np

#decimal.getcontext().prec = 10

def main():

	N = INT()

	S = eval(input())

	former = S[:N]

	latter = S[N:][::-1]

	dic_f = defaultdict(int)

	dic_l = defaultdict(int)

	for x in product([0, 1], repeat=N):

		tmp_red = ""

		tmp_blue = ""

		for i in range(N):

			if x[i]:

				tmp_red += former[i]

			else:

				tmp_blue += former[i]

		dic_f["{},{}".format(tmp_red, tmp_blue)] += 1

	for x in product([0, 1], repeat=N):

		tmp_red = ""

		tmp_blue = ""

		for i in range(N):

			if x[i]:

				tmp_red += latter[i]

			else:

				tmp_blue += latter[i]

		dic_l["{},{}".format(tmp_red, tmp_blue)] += 1

	ans = 0

	for key in dic_f:

		ans += dic_f[key] * dic_l[key]

	print(ans)

if __name__ == '__main__':

	main()

import sys, re
from collections import deque, defaultdict, Counter
from math import (
    ceil,
    sqrt,
    hypot,
    factorial,
    pi,
    sin,
    cos,
    tan,
    asin,
    acos,
    atan,
    radians,
    degrees,
    log2,
    gcd,
)
from itertools import (
    accumulate,
    permutations,
    combinations,
    combinations_with_replacement,
    product,
    groupby,
)
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache

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

def INT():
    return int(eval(input()))

def MAP():
    return list(map(int, input().split()))

def LIST():
    return list(map(int, input().split()))

def TUPLE():
    return tuple(map(int, input().split()))

def ZIP(n):
    return list(zip(*(MAP() for _ in range(n))))

sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
# mod = 998244353
from decimal import *

# import numpy as np
# decimal.getcontext().prec = 10
N = INT()
S = eval(input())
former = S[:N]
latter = S[N:][::-1]
dic_f = defaultdict(int)
dic_l = defaultdict(int)
for x in product([0, 1], repeat=N):
    tmp_red = ""
    tmp_blue = ""
    for i in range(N):
        if x[i]:
            tmp_red += former[i]
        else:
            tmp_blue += former[i]
    dic_f["{},{}".format(tmp_red, tmp_blue)] += 1
for x in product([0, 1], repeat=N):
    tmp_red = ""
    tmp_blue = ""
    for i in range(N):
        if x[i]:
            tmp_red += latter[i]
        else:
            tmp_blue += latter[i]
    dic_l["{},{}".format(tmp_red, tmp_blue)] += 1
ans = 0
for key in dic_f:
    ans += dic_f[key] * dic_l[key]
print(ans)

import sys, re
from collections import deque, defaultdict, Counter
from math import (
    ceil,
    sqrt,
    hypot,
    factorial,
    pi,
    sin,
    cos,
    tan,
    asin,
    acos,
    atan,
    radians,
    degrees,
    log2,
    gcd,
)
from itertools import (
    accumulate,
    permutations,
    combinations,
    combinations_with_replacement,
    product,
    groupby,
)
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache

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

def INT():
    return int(eval(input()))

def MAP():
    return list(map(int, input().split()))

def LIST():
    return list(map(int, input().split()))

def TUPLE():
    return tuple(map(int, input().split()))

def ZIP(n):
    return list(zip(*(MAP() for _ in range(n))))

sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
# mod = 998244353
from decimal import *

# import numpy as np
# decimal.getcontext().prec = 10
def main():
    N = INT()
    S = eval(input())
    former = S[:N]
    latter = S[N:][::-1]
    dic_f = defaultdict(int)
    dic_l = defaultdict(int)
    for x in product([0, 1], repeat=N):
        tmp_red = ""
        tmp_blue = ""
        for i in range(N):
            if x[i]:
                tmp_red += former[i]
            else:
                tmp_blue += former[i]
        dic_f["{},{}".format(tmp_red, tmp_blue)] += 1
    for x in product([0, 1], repeat=N):
        tmp_red = ""
        tmp_blue = ""
        for i in range(N):
            if x[i]:
                tmp_red += latter[i]
            else:
                tmp_blue += latter[i]
        dic_l["{},{}".format(tmp_red, tmp_blue)] += 1
    ans = 0
    for key in dic_f:
        ans += dic_f[key] * dic_l[key]
    print(ans)

if __name__ == "__main__":
    main()

-    dic_f["{},{}".format(tmp_red, tmp_blue)] += 1

-    dic_l["{},{}".format(tmp_red, tmp_blue)] += 1

+    for x in product([0, 1], repeat=N):

+        dic_f["{},{}".format(tmp_red, tmp_blue)] += 1

+    for x in product([0, 1], repeat=N):

+        dic_l["{},{}".format(tmp_red, tmp_blue)] += 1


Input:
#!/usr/bin/env python3

import sys

import math

from bisect import bisect_right as br

from bisect import bisect_left as bl

sys.setrecursionlimit(2147483647)

from heapq import heappush, heappop,heappushpop

from collections import defaultdict

from itertools import accumulate

from collections import Counter

from collections import deque

from operator import itemgetter

from itertools import permutations

mod = 10**9 + 7

inf = float('inf')

def I(): return int(sys.stdin.readline())

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

def main():

  n = I()

  a = [I() for _ in range(n)]

  dp = [inf]*n

  for i in range(n):

    r = br(dp,-a[i])

    dp[r] = -a[i]

  print((n-dp.count(inf)))

  return

if __name__ == '__main__':

  main()

#!/usr/bin/env python3

import sys

import math

from bisect import bisect_right as br

from bisect import bisect_left as bl

sys.setrecursionlimit(2147483647)

from heapq import heappush, heappop,heappushpop

from collections import defaultdict

from itertools import accumulate

from collections import Counter

from collections import deque

from operator import itemgetter

from itertools import permutations

mod = 10**9 + 7

inf = float('inf')

def I(): return int(sys.stdin.readline())

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

n = I()

a = [I() for _ in range(n)]

dp = [10**10]*(n)

for i in range(n):

    r = br(dp, -a[i])

    dp[r] = -a[i]

print((n - dp.count(10**10)))

#!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl

sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop, heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations

mod = 10**9 + 7
inf = float("inf")

def I():
    return int(sys.stdin.readline())

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

def main():
    n = I()
    a = [I() for _ in range(n)]
    dp = [inf] * n
    for i in range(n):
        r = br(dp, -a[i])
        dp[r] = -a[i]
    print((n - dp.count(inf)))
    return

if __name__ == "__main__":
    main()

#!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl

sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop, heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations

mod = 10**9 + 7
inf = float("inf")

def I():
    return int(sys.stdin.readline())

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

n = I()
a = [I() for _ in range(n)]
dp = [10**10] * (n)
for i in range(n):
    r = br(dp, -a[i])
    dp[r] = -a[i]
print((n - dp.count(10**10)))

-def main():
-    n = I()
-    a = [I() for _ in range(n)]
-    dp = [inf] * n
-    for i in range(n):
-        r = br(dp, -a[i])
-        dp[r] = -a[i]
-    print((n - dp.count(inf)))
-    return
-if __name__ == "__main__":
-    main()
+n = I()
+a = [I() for _ in range(n)]
+dp = [10**10] * (n)
+for i in range(n):
+    r = br(dp, -a[i])
+    dp[r] = -a[i]
+print((n - dp.count(10**10)))


Input:
from itertools import product

H, W, K = list(map(int, input().split()))

mod = 10 ** 9 + 7

# dp[i][j]:= 上からi番目, 左からj番目にいる通り数

dp = [[0] * W for i in range(H + 1)]

dp[0][0] = 1

def calc(x):

    if x < 0:

        return 1

    ret = 0

    for p in product(['0', '1'], repeat=x):

        p = ''.join(p)

        if '11' not in p:

            ret += 1

    return ret

for i in range(1, H + 1):

    for j in range(W):

        tmp = 0

        if j > 0:  # 左から

            tmp += dp[i - 1][j - 1] * calc(j - 2) * calc(W - j - 2) % mod

        # 上から

        tmp += dp[i - 1][j] * calc(j - 1) * calc(W - j - 2) % mod

        if j + 1 < W:  # 右から

            tmp += dp[i - 1][j + 1] * calc(j - 1) * calc(W - j - 3) % mod

        dp[i][j] = tmp

print((dp[H][K - 1] % mod))

H, W, K = list(map(int, input().split()))

MOD = 10 ** 9 + 7

def transition(w):

    X = [1, 2, 3, 5, 8, 13, 21, 34]

    if w >= 0:

        return X[w]

    else:

        return 1

# h行w列に到達する方法

dp = [[0] * W for h in range(H + 1)]

dp[0][0] = 1

for h in range(H):

    for w in range(W):

        # 真下へ

        dp[h + 1][w] += dp[h][w] * (transition(w - 1) * transition(W - w - 2))

        dp[h + 1][w] %= MOD

        # 右下へ

        if w + 1 < W:

            dp[h + 1][w + 1] += dp[h][w] * (transition(w - 1) * transition(W - w - 3))

            dp[h + 1][w + 1] %= MOD

        # 左下へ

        if w - 1 >= 0:

            dp[h + 1][w - 1] += dp[h][w] * (transition(w - 2) * transition(W - w - 2))

            dp[h + 1][w - 1] %= MOD

print((dp[H][K - 1]))

from itertools import product

H, W, K = list(map(int, input().split()))
mod = 10**9 + 7
# dp[i][j]:= 上からi番目, 左からj番目にいる通り数
dp = [[0] * W for i in range(H + 1)]
dp[0][0] = 1

def calc(x):
    if x < 0:
        return 1
    ret = 0
    for p in product(["0", "1"], repeat=x):
        p = "".join(p)
        if "11" not in p:
            ret += 1
    return ret

for i in range(1, H + 1):
    for j in range(W):
        tmp = 0
        if j > 0:  # 左から
            tmp += dp[i - 1][j - 1] * calc(j - 2) * calc(W - j - 2) % mod
        # 上から
        tmp += dp[i - 1][j] * calc(j - 1) * calc(W - j - 2) % mod
        if j + 1 < W:  # 右から
            tmp += dp[i - 1][j + 1] * calc(j - 1) * calc(W - j - 3) % mod
        dp[i][j] = tmp
print((dp[H][K - 1] % mod))

H, W, K = list(map(int, input().split()))
MOD = 10**9 + 7

def transition(w):
    X = [1, 2, 3, 5, 8, 13, 21, 34]
    if w >= 0:
        return X[w]
    else:
        return 1

# h行w列に到達する方法
dp = [[0] * W for h in range(H + 1)]
dp[0][0] = 1
for h in range(H):
    for w in range(W):
        # 真下へ
        dp[h + 1][w] += dp[h][w] * (transition(w - 1) * transition(W - w - 2))
        dp[h + 1][w] %= MOD
        # 右下へ
        if w + 1 < W:
            dp[h + 1][w + 1] += dp[h][w] * (transition(w - 1) * transition(W - w - 3))
            dp[h + 1][w + 1] %= MOD
        # 左下へ
        if w - 1 >= 0:
            dp[h + 1][w - 1] += dp[h][w] * (transition(w - 2) * transition(W - w - 2))
            dp[h + 1][w - 1] %= MOD
print((dp[H][K - 1]))

-# dp[i][j]:= 上からi番目, 左からj番目にいる通り数

-    for p in product(["0", "1"], repeat=x):

-        # 上から

-        tmp += dp[i - 1][j] * calc(j - 1) * calc(W - j - 2) % mod

+# h行w列に到達する方法

+        # 真下へ

+        dp[h + 1][w] += dp[h][w] * (transition(w - 1) * transition(W - w - 2))

+        # 右下へ

+            dp[h + 1][w + 1] += dp[h][w] * (transition(w - 1) * transition(W - w - 3))

+        # 左下へ

+            dp[h + 1][w - 1] += dp[h][w] * (transition(w - 2) * transition(W - w - 2))


Input:
from collections import Counter

n = int(eval(input()))

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

if len(set(lst_v)) == 1:

    ans = n // 2

else:

    lst_odd = lst_v[::2]

    lst_even = lst_v[1::2]

    cnt_odd = sorted(list(Counter(lst_odd).items()), key=lambda x: -x[1])

    cnt_even = sorted(list(Counter(lst_even).items()), key=lambda x :-x[1])

    if cnt_odd[0][0] == cnt_even[0][0]:

        rem_number = max(cnt_odd[0][1] + cnt_even[1][1], cnt_odd[1][1] + cnt_even[0][1])

    else:

        rem_number = cnt_odd[0][1] + cnt_even[0][1]

    sum_odd = sum(t[1] for t in cnt_odd)

    sum_even = sum(t[1] for t in cnt_even)

    ans = sum_odd + sum_even - rem_number

print(ans)

from collections import Counter

n = int(eval(input()))

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

if len(set(lst_v)) == 1:

    ans = n // 2

else:

    lst_o = lst_v[::2]

    lst_e = lst_v[1::2]

    cnt_o = sorted(list(Counter(lst_o).items()), key=lambda x: -x[1])

    cnt_e = sorted(list(Counter(lst_e).items()), key=lambda x :-x[1])

    if cnt_o[0][0] == cnt_e[0][0]:

        rem_number = max(cnt_o[0][1] + cnt_e[1][1], cnt_o[1][1] + cnt_e[0][1])

    else:

        rem_number = cnt_o[0][1] + cnt_e[0][1]

    ans = n - rem_number

print(ans)

from collections import Counter

n = int(eval(input()))
lst_v = list(map(int, input().split()))
if len(set(lst_v)) == 1:
    ans = n // 2
else:
    lst_odd = lst_v[::2]
    lst_even = lst_v[1::2]
    cnt_odd = sorted(list(Counter(lst_odd).items()), key=lambda x: -x[1])
    cnt_even = sorted(list(Counter(lst_even).items()), key=lambda x: -x[1])
    if cnt_odd[0][0] == cnt_even[0][0]:
        rem_number = max(cnt_odd[0][1] + cnt_even[1][1], cnt_odd[1][1] + cnt_even[0][1])
    else:
        rem_number = cnt_odd[0][1] + cnt_even[0][1]
    sum_odd = sum(t[1] for t in cnt_odd)
    sum_even = sum(t[1] for t in cnt_even)
    ans = sum_odd + sum_even - rem_number
print(ans)

from collections import Counter

n = int(eval(input()))
lst_v = list(map(int, input().split()))
if len(set(lst_v)) == 1:
    ans = n // 2
else:
    lst_o = lst_v[::2]
    lst_e = lst_v[1::2]
    cnt_o = sorted(list(Counter(lst_o).items()), key=lambda x: -x[1])
    cnt_e = sorted(list(Counter(lst_e).items()), key=lambda x: -x[1])
    if cnt_o[0][0] == cnt_e[0][0]:
        rem_number = max(cnt_o[0][1] + cnt_e[1][1], cnt_o[1][1] + cnt_e[0][1])
    else:
        rem_number = cnt_o[0][1] + cnt_e[0][1]
    ans = n - rem_number
print(ans)

-    cnt_odd = sorted(list(Counter(lst_odd).items()), key=lambda x: -x[1])

-    cnt_even = sorted(list(Counter(lst_even).items()), key=lambda x: -x[1])

-        rem_number = max(cnt_odd[0][1] + cnt_even[1][1], cnt_odd[1][1] + cnt_even[0][1])

+    cnt_o = sorted(list(Counter(lst_o).items()), key=lambda x: -x[1])

+    cnt_e = sorted(list(Counter(lst_e).items()), key=lambda x: -x[1])

-        rem_number = cnt_odd[0][1] + cnt_even[0][1]

-    sum_odd = sum(t[1] for t in cnt_odd)

-    sum_even = sum(t[1] for t in cnt_even)

-    ans = sum_odd + sum_even - rem_number


Input:
from bisect import bisect

n = int(eval(input()))

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

a.sort()

i = bisect(a, (a[-1]+1) // 2)

if a[i] - a[-1] / 2 < a[-1] / 2 - a[i-1]:

    print((a[-1], a[i]))

else:

    print((a[-1], a[i-1]))

n = int(eval(input()))

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

max_a = max(a)

ans = 0

for i in range(n):

    if abs(ans - max_a/2) > abs(a[i] - max_a/2):

        ans = a[i]

print((max_a, ans))

from bisect import bisect

n = int(eval(input()))
a = list(map(int, input().split()))
a.sort()
i = bisect(a, (a[-1] + 1) // 2)
if a[i] - a[-1] / 2 < a[-1] / 2 - a[i - 1]:
    print((a[-1], a[i]))
else:
    print((a[-1], a[i - 1]))

n = int(eval(input()))
a = list(map(int, input().split()))
max_a = max(a)
ans = 0
for i in range(n):
    if abs(ans - max_a / 2) > abs(a[i] - max_a / 2):
        ans = a[i]
print((max_a, ans))

+    if abs(ans - max_a / 2) > abs(a[i] - max_a / 2):


Input:
A, B, C, D = [int(c) for c in eval(input())]

expressions = [

    "{}+{}+{}+{}",

    "{}+{}+{}-{}",

    "{}+{}-{}+{}",

    "{}-{}+{}+{}",

    "{}-{}-{}+{}",

    "{}-{}+{}-{}",

    "{}+{}-{}-{}",

    "{}-{}-{}-{}",

]

for exp in expressions:

    exp = exp.format(A, B, C, D)

    if eval(exp) == 7:

        print((exp + "=7"))

        break

-A, B, C, D = [int(c) for c in eval(input())]

+        print(("{}=7".format(formula)))


Input:
def main():

    N = int(eval(input()))

    A = [int(i) for i in input().split()]

    from collections import Counter

    c = Counter(A)

    ans = 0

    for v in list(c.values()):

        if v > 1:

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

    for k, a in enumerate(A):

        cnt = 0

        add = 0

        if c[a] > 1:

            cnt = c[a]*(c[a]-1)//2

        if c[a] > 2:

            add = (c[a]-1)*(c[a]-2)//2

        print((ans - cnt + add))

if __name__ == '__main__':

    main()

def main():

    N = int(eval(input()))

    A = [int(i) for i in input().split()]

    from collections import Counter

    c = Counter(A)

    ans = 0

    for v in list(c.values()):

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

    for k in range(N):

        v = c[A[k]]

        diff = -v*(v-1)//2 + (v-1)*(v-2)//2

        print((ans + (diff if v != 1 else 0)))

if __name__ == '__main__':

    main()

def main():
    N = int(eval(input()))
    A = [int(i) for i in input().split()]
    from collections import Counter

    c = Counter(A)
    ans = 0
    for v in list(c.values()):
        if v > 1:
            ans += v * (v - 1) // 2
    for k, a in enumerate(A):
        cnt = 0
        add = 0
        if c[a] > 1:
            cnt = c[a] * (c[a] - 1) // 2
        if c[a] > 2:
            add = (c[a] - 1) * (c[a] - 2) // 2
        print((ans - cnt + add))

if __name__ == "__main__":
    main()

def main():
    N = int(eval(input()))
    A = [int(i) for i in input().split()]
    from collections import Counter

    c = Counter(A)
    ans = 0
    for v in list(c.values()):
        ans += v * (v - 1) // 2
    for k in range(N):
        v = c[A[k]]
        diff = -v * (v - 1) // 2 + (v - 1) * (v - 2) // 2
        print((ans + (diff if v != 1 else 0)))

if __name__ == "__main__":
    main()

+        print((ans + (diff if v != 1 else 0)))


Input:
import sys

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

def I(): return int(eval(input()))

n = I()

cnt = [0] * 10001

for x in range(1, 101):

    for y in range(1, 101):

        for z in range(1, 101):

            v = x**2 + y**2 + z**2 + x*y + y*z + z*x

            if v <= n:

                cnt[v] += 1

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

    print((cnt[i]))

import sys

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

def I(): return int(eval(input()))

n = I()

cnt = [0] * 10001

for x in range(1, 101):

    for y in range(1, 101):

        for z in range(1, 101):

            v = x*x + y*y + z*z + x*y + y*z + z*x

            if v <= n:

                cnt[v] += 1

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

    print((cnt[i]))

import sys

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

def I():
    return int(eval(input()))

n = I()
cnt = [0] * 10001
for x in range(1, 101):
    for y in range(1, 101):
        for z in range(1, 101):
            v = x**2 + y**2 + z**2 + x * y + y * z + z * x
            if v <= n:
                cnt[v] += 1
for i in range(1, n + 1):
    print((cnt[i]))

import sys

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

def I():
    return int(eval(input()))

n = I()
cnt = [0] * 10001
for x in range(1, 101):
    for y in range(1, 101):
        for z in range(1, 101):
            v = x * x + y * y + z * z + x * y + y * z + z * x
            if v <= n:
                cnt[v] += 1
for i in range(1, n + 1):
    print((cnt[i]))

+            v = x * x + y * y + z * z + x * y + y * z + z * x


Input:
n = int(eval(input()))

p = 10**9 + 7

def fact(n):

    n_ = 1

    yield n_

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

         n_ = (n_*i) % p

         yield n_

def invfact(n, f, p):

    m = pow(f[n], p-2, p)

    yield m

    for i in range(n, 0, -1):

        m = m * i % p

        yield m

ans = 0

m = n - 1

f = list(fact(m))

rf = list(invfact(m, f, p))

rf.reverse()

perm = 0

for k in range((n+1)//2, n):

    b = m - k

    a = (m - 1) - (2 * b)

    perm_ = f[a+b] * rf[a] %p * f[k] % p

    ans += (perm_ - perm) %p * k % p

    ans %= p

    perm = perm_

print(ans)

n = int(eval(input()))

p = 10**9 + 7

def fact(n):

    n_ = 1

    yield n_

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

         n_ = (n_*i) % p

         yield n_

def invfact(n, f, p):

    m = pow(f[n], p-2, p)

    yield m

    for i in range(n, 0, -1):

        m = m * i % p

        yield m

ans = 0

m = n - 1

f = list(fact(m))

rf = list(invfact(m, f, p))

rf.reverse()

perm = 0

for k in range((n+1)//2, n):

    perm_ = f[k-1] * rf[2*k-n] %p * f[k] % p

    ans += (perm_ - perm) %p * k % p

    ans %= p

    perm = perm_

print(ans)

n = int(eval(input()))
p = 10**9 + 7

def fact(n):
    n_ = 1
    yield n_
    for i in range(1, n + 1):
        n_ = (n_ * i) % p
        yield n_

def invfact(n, f, p):
    m = pow(f[n], p - 2, p)
    yield m
    for i in range(n, 0, -1):
        m = m * i % p
        yield m

ans = 0
m = n - 1
f = list(fact(m))
rf = list(invfact(m, f, p))
rf.reverse()
perm = 0
for k in range((n + 1) // 2, n):
    b = m - k
    a = (m - 1) - (2 * b)
    perm_ = f[a + b] * rf[a] % p * f[k] % p
    ans += (perm_ - perm) % p * k % p
    ans %= p
    perm = perm_
print(ans)

n = int(eval(input()))
p = 10**9 + 7

def fact(n):
    n_ = 1
    yield n_
    for i in range(1, n + 1):
        n_ = (n_ * i) % p
        yield n_

def invfact(n, f, p):
    m = pow(f[n], p - 2, p)
    yield m
    for i in range(n, 0, -1):
        m = m * i % p
        yield m

ans = 0
m = n - 1
f = list(fact(m))
rf = list(invfact(m, f, p))
rf.reverse()
perm = 0
for k in range((n + 1) // 2, n):
    perm_ = f[k - 1] * rf[2 * k - n] % p * f[k] % p
    ans += (perm_ - perm) % p * k % p
    ans %= p
    perm = perm_
print(ans)

-    perm_ = f[a + b] * rf[a] % p * f[k] % p


Input:
#ABC093B

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

ans = []

if abs(A-B) > K:

    for i in range(K):

        ans.append(A+i)

        ans.append(B-i)

    ans = set(ans)

    ans = sorted(ans)

    for j in ans:

         print(j)

else:

    for l in range(abs(A-B)+1):

        print((min(A,B) + l))

#ABC093B

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

ans = []

if B-A + 1 > K*2:

    for i in range(K):

        ans.append(A+i)

        ans.append(B-i)

    ans.sort()

    for j in ans:

         print(j)

else:

    for l in range(B-A+1):

        print((A + l))

# ABC093B
A, B, K = list(map(int, input().split()))
ans = []
if abs(A - B) > K:
    for i in range(K):
        ans.append(A + i)
        ans.append(B - i)
    ans = set(ans)
    ans = sorted(ans)
    for j in ans:
        print(j)
else:
    for l in range(abs(A - B) + 1):
        print((min(A, B) + l))

# ABC093B
A, B, K = list(map(int, input().split()))
ans = []
if B - A + 1 > K * 2:
    for i in range(K):
        ans.append(A + i)
        ans.append(B - i)
    ans.sort()
    for j in ans:
        print(j)
else:
    for l in range(B - A + 1):
        print((A + l))

-if abs(A - B) > K:
+if B - A + 1 > K * 2:
-    ans = set(ans)
-    ans = sorted(ans)
+    ans.sort()
-    for l in range(abs(A - B) + 1):
-        print((min(A, B) + l))
+    for l in range(B - A + 1):
+        print((A + l))


Input:
from collections import deque

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

a = [eval(input()) + '#' for _ in range(h)]

b = ['#' * (w + 1)]

r = 0

for i in range(h):

  for j in range(w):

    if a[i][j] == '.':

      b[:-1] = list(map(list, a))

      b[i][j] = 0

      q = deque([(i, j)])

      while(q):

        i, j = q.popleft()

        r = max(r, b[i][j])

        d = 0

        for i1 in range(i - 1, i + 2):

          for j1 in range(j - d, j + 2, 2):

            if b[i1][j1] == '.':

              b[i1][j1] = b[i][j] + 1

              q.append((i1, j1))

          d ^= 1

print(r)

from collections import deque

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

a = ''.join(eval(input()) + '#' for _ in range(h))

n = len(a)

b = ['#'] * w

r = 0

for i in range(n):

  if a[i] == '.':

    b[:-w] = a

    b[i] = 0

    q = deque([i])

    while(q):

      i = q.popleft()

      r = max(r, b[i])

      for j in (i - 1, i + 1, i - w - 1, i + w + 1):

        if b[j] == '.':

          b[j] = b[i] + 1

          q.append(j)

print(r)

from collections import deque

h, w = list(map(int, input().split()))
a = [eval(input()) + "#" for _ in range(h)]
b = ["#" * (w + 1)]
r = 0
for i in range(h):
    for j in range(w):
        if a[i][j] == ".":
            b[:-1] = list(map(list, a))
            b[i][j] = 0
            q = deque([(i, j)])
            while q:
                i, j = q.popleft()
                r = max(r, b[i][j])
                d = 0
                for i1 in range(i - 1, i + 2):
                    for j1 in range(j - d, j + 2, 2):
                        if b[i1][j1] == ".":
                            b[i1][j1] = b[i][j] + 1
                            q.append((i1, j1))
                    d ^= 1
print(r)

from collections import deque

h, w = list(map(int, input().split()))
a = "".join(eval(input()) + "#" for _ in range(h))
n = len(a)
b = ["#"] * w
r = 0
for i in range(n):
    if a[i] == ".":
        b[:-w] = a
        b[i] = 0
        q = deque([i])
        while q:
            i = q.popleft()
            r = max(r, b[i])
            for j in (i - 1, i + 1, i - w - 1, i + w + 1):
                if b[j] == ".":
                    b[j] = b[i] + 1
                    q.append(j)
print(r)

-a = [eval(input()) + "#" for _ in range(h)]

+a = "".join(eval(input()) + "#" for _ in range(h))

-            b[:-1] = list(map(list, a))

-                for i1 in range(i - 1, i + 2):

-                    for j1 in range(j - d, j + 2, 2):

-                            q.append((i1, j1))


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

"""

Spyderエディタ

これは一時的なスクリプトファイルです。

"""

import math

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

alpha = []

beta = []

for x in range(math.floor(a/0.08), math.floor(a/0.05)):

    if math.floor(x * 0.08) == a:

        alpha.append(x)

for y in range(math.floor(b/0.10), math.floor(b/0.05)):

    if math.floor(y * 0.1) == b:

        beta.append(y)

if min(alpha) in beta:

    print((min(alpha)))

elif min(beta) in alpha:

    print((min(beta)))

else:

    print("-1")

import math

A,B = (int(x) for x in input().split())

A1 = math.ceil(A/0.08)

A2 = math.ceil((A+1)/0.08)

"""if float((A+1)/0.08).is_integer() == True:

    A2 = math.floor((A+1)/0.08)

else:

    A2 = math.floor((A+1)/0.08) + 1

"""

B1 = math.ceil(B/0.1)

B2 = math.ceil((B+1)/0.1)

"""if float((B+1)/0.1).is_integer() == True:

    B2 = math.floor((B+1)/0.1)

else:

    B2 = math.floor((B+1)/0.1) + 1

"""

a = list(range(A1, A2))

b = list(range(B1, B2))

c = set(a) & set(b)

if len(c) == 0:

          print((-1))

else:

          print((min(c)))

# -*- coding: utf-8 -*-
"""
Spyderエディタ
これは一時的なスクリプトファイルです。
"""
import math

a, b = list(map(int, input().split()))
alpha = []
beta = []
for x in range(math.floor(a / 0.08), math.floor(a / 0.05)):
    if math.floor(x * 0.08) == a:
        alpha.append(x)
for y in range(math.floor(b / 0.10), math.floor(b / 0.05)):
    if math.floor(y * 0.1) == b:
        beta.append(y)
if min(alpha) in beta:
    print((min(alpha)))
elif min(beta) in alpha:
    print((min(beta)))
else:
    print("-1")

import math

A, B = (int(x) for x in input().split())
A1 = math.ceil(A / 0.08)
A2 = math.ceil((A + 1) / 0.08)
"""if float((A+1)/0.08).is_integer() == True:
    A2 = math.floor((A+1)/0.08)
else:
    A2 = math.floor((A+1)/0.08) + 1
"""
B1 = math.ceil(B / 0.1)
B2 = math.ceil((B + 1) / 0.1)
"""if float((B+1)/0.1).is_integer() == True:
    B2 = math.floor((B+1)/0.1)
else:
    B2 = math.floor((B+1)/0.1) + 1
"""
a = list(range(A1, A2))
b = list(range(B1, B2))
c = set(a) & set(b)
if len(c) == 0:
    print((-1))
else:
    print((min(c)))

-これは一時的なスクリプトファイルです。

-for x in range(math.floor(a / 0.08), math.floor(a / 0.05)):

-for y in range(math.floor(b / 0.10), math.floor(b / 0.05)):

+A, B = (int(x) for x in input().split())

+"""if float((B+1)/0.1).is_integer() == True:


Input:
N,T = list(map(int,input().split()))

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

cnt = 0

for i in range(1,N):

    emp_time=(t[i]-t[i-1])-T

    if emp_time >= 0:

        cnt += T

    else:

        cnt += t[i]-t[i-1]

print((cnt+T))

# coding: utf-8

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

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

ans = 0

for i in range(n-1):

    if T[i+1] - T[i] >= t:

        ans += t

    else:

        ans += T[i+1] - T[i]

print((ans+t))

N, T = list(map(int, input().split()))
t = list(map(int, input().split()))
cnt = 0
for i in range(1, N):
    emp_time = (t[i] - t[i - 1]) - T
    if emp_time >= 0:
        cnt += T
    else:
        cnt += t[i] - t[i - 1]
print((cnt + T))

# coding: utf-8
n, t = list(map(int, input().split()))
T = list(map(int, input().split()))
ans = 0
for i in range(n - 1):
    if T[i + 1] - T[i] >= t:
        ans += t
    else:
        ans += T[i + 1] - T[i]
print((ans + t))

-N, T = list(map(int, input().split()))
-t = list(map(int, input().split()))
-cnt = 0
-for i in range(1, N):
-    emp_time = (t[i] - t[i - 1]) - T
-    if emp_time >= 0:
-        cnt += T
+# coding: utf-8
+n, t = list(map(int, input().split()))
+T = list(map(int, input().split()))
+ans = 0
+for i in range(n - 1):
+    if T[i + 1] - T[i] >= t:
+        ans += t
-        cnt += t[i] - t[i - 1]
-print((cnt + T))
+        ans += T[i + 1] - T[i]
+print((ans + t))


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

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

cnt = 0

while (H > 0):

    for n in range(N):

        H = H - A[n]

    cnt += 1

if cnt == 1:

    print('Yes')

else:

    print('No')

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

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

for n in range(N):

    H = H - A[n]

if H <= 0:

    print('Yes')

else:

    print('No')

H, N = list(map(int, input().split()))
A = list(map(int, input().split()))
cnt = 0
while H > 0:
    for n in range(N):
        H = H - A[n]
    cnt += 1
if cnt == 1:
    print("Yes")
else:
    print("No")

H, N = list(map(int, input().split()))
A = list(map(int, input().split()))
for n in range(N):
    H = H - A[n]
if H <= 0:
    print("Yes")
else:
    print("No")

-cnt = 0
-while H > 0:
-    for n in range(N):
-        H = H - A[n]
-    cnt += 1
-if cnt == 1:
+for n in range(N):
+    H = H - A[n]
+if H <= 0:


Input:
s = list(eval(input()))

ans = len(s)

for c in s:

    dist = 0

    dists = []

    for d in s:

        if c != d:

            dist += 1

        else:

            dists.append(dist)

            dist = 0

    ans = min(ans, max(dists + [dist]))

print(ans)

s = list(eval(input()))

ans = len(s)

for c in set(s):

    dist = 0

    dists = []

    for d in s:

        if c != d:

            dist += 1

        else:

            dists.append(dist)

            dist = 0

    ans = min(ans, max(dists + [dist]))

print(ans)


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

magic = []

INF = 10**8

dp = [[INF for j in range(h+1)] for i in range(n+1)] #体力がjのモンスターをi番目の魔法までを使って倒せる消費魔力の最小値

for i in range(n):

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

    magic.append([a, b])

for i in range(n):

    for j in range(h):

        if j+1 > magic[i][0]:

            dp[i+1][j+1] = min(dp[i][j+1], dp[i][j+1-magic[i][0]] + magic[i][1], dp[i+1][j+1-magic[i][0]] + magic[i][1])

        else:

            dp[i+1][j+1] = min(dp[i][j+1], magic[i][1])

print((dp[n][h]))

inf = 10**15

mod = 10**9+7

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

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

dp = [[inf for j in range(h+1)] for i in range(n+1)]

for i in range(n):

    dp[i][0] = 0

    a,b = ab[i]

    for j in range(h):

        if j+1-a>=0:

            dp[i+1][j+1] = min(dp[i+1][j+1-a]+b, dp[i][j+1], dp[i][j+1-a]+b)

        else:

            dp[i+1][j+1] = min(dp[i][j+1], b)

print((dp[n][h]))

h, n = list(map(int, input().split()))
magic = []
INF = 10**8
dp = [
    [INF for j in range(h + 1)] for i in range(n + 1)
]  # 体力がjのモンスターをi番目の魔法までを使って倒せる消費魔力の最小値
for i in range(n):
    a, b = list(map(int, input().split()))
    magic.append([a, b])
for i in range(n):
    for j in range(h):
        if j + 1 > magic[i][0]:
            dp[i + 1][j + 1] = min(
                dp[i][j + 1],
                dp[i][j + 1 - magic[i][0]] + magic[i][1],
                dp[i + 1][j + 1 - magic[i][0]] + magic[i][1],
            )
        else:
            dp[i + 1][j + 1] = min(dp[i][j + 1], magic[i][1])
print((dp[n][h]))

inf = 10**15
mod = 10**9 + 7
h, n = list(map(int, input().split()))
ab = [list(map(int, input().split())) for i in range(n)]
dp = [[inf for j in range(h + 1)] for i in range(n + 1)]
for i in range(n):
    dp[i][0] = 0
    a, b = ab[i]
    for j in range(h):
        if j + 1 - a >= 0:
            dp[i + 1][j + 1] = min(
                dp[i + 1][j + 1 - a] + b, dp[i][j + 1], dp[i][j + 1 - a] + b
            )
        else:
            dp[i + 1][j + 1] = min(dp[i][j + 1], b)
print((dp[n][h]))

-    [INF for j in range(h + 1)] for i in range(n + 1)

-]  # 体力がjのモンスターをi番目の魔法までを使って倒せる消費魔力の最小値

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

+dp = [[inf for j in range(h + 1)] for i in range(n + 1)]

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


Input:
def tosec(t):

    return int(t[:2])*60*60 + int(t[3:5])*60 + int(t[6:])

while True:

    n = int(eval(input()))

    if n == 0: break

    time = [0] * (60*60*24 + 1)

    for _ in range(n):

        s, f = input().split()

        time[tosec(s)] += 1

        time[tosec(f)] -= 1

    ans = time[0]

    for i in range(60*60*24):

        time[i+1] += time[i]

        ans = max(ans, time[i+1])

    print(ans)

while True:

    n = eval(input())

    if not n: break

    time = [0]*86400

    for i in range(n):

        s, t = input().split()

        ssec = int(s[0:2])*3600 + int(s[3:5])*60 + int(s[6:8])

        tsec = int(t[0:2])*3600 + int(t[3:5])*60 + int(t[6:8])

        time[ssec] += 1

        time[tsec] -= 1

    ans = time[0]

    for i in range(86400-1):

        time[i+1] += time[i]

        ans = max(ans, time[i+1])

    print(ans)

def tosec(t):
    return int(t[:2]) * 60 * 60 + int(t[3:5]) * 60 + int(t[6:])

while True:
    n = int(eval(input()))
    if n == 0:
        break
    time = [0] * (60 * 60 * 24 + 1)
    for _ in range(n):
        s, f = input().split()
        time[tosec(s)] += 1
        time[tosec(f)] -= 1
    ans = time[0]
    for i in range(60 * 60 * 24):
        time[i + 1] += time[i]
        ans = max(ans, time[i + 1])
    print(ans)

while True:
    n = eval(input())
    if not n:
        break
    time = [0] * 86400
    for i in range(n):
        s, t = input().split()
        ssec = int(s[0:2]) * 3600 + int(s[3:5]) * 60 + int(s[6:8])
        tsec = int(t[0:2]) * 3600 + int(t[3:5]) * 60 + int(t[6:8])
        time[ssec] += 1
        time[tsec] -= 1
    ans = time[0]
    for i in range(86400 - 1):
        time[i + 1] += time[i]
        ans = max(ans, time[i + 1])
    print(ans)


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

edges = []

for i in range(M):

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

    edges.append([a,b,c])

dist = [float('inf')] * (N + 1)

dist[1] = 0

for _ in range(N - 1):

    for a, b, c in edges:

        dist[b] = min(dist[b], dist[a] - c)

ans = dist[N]

for a, b, c in edges:

    dist[b] = min(dist[b], dist[a] - c)

if ans == dist[N]:

    print((-ans))

else:

    print('inf')

def main():

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

    edges = []

    for _ in range(M):

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

        a -= 1

        b -= 1

        edges.append([a,b,c])

    d = [float('inf')] * N

    d[0] = 0

    for i in range(N-1):

        for edge in edges:

            d[edge[1]] = min(d[edge[1]], d[edge[0]] - edge[2])

    ans = d[N-1]

    for edge in edges:

        d[edge[1]] = min(d[edge[1]], d[edge[0]] - edge[2])

    if ans == d[N-1]:

        print((-ans))

    else:

        print('inf')

main()

N, M = list(map(int, input().split()))
edges = []
for i in range(M):
    a, b, c = list(map(int, input().split()))
    edges.append([a, b, c])
dist = [float("inf")] * (N + 1)
dist[1] = 0
for _ in range(N - 1):
    for a, b, c in edges:
        dist[b] = min(dist[b], dist[a] - c)
ans = dist[N]
for a, b, c in edges:
    dist[b] = min(dist[b], dist[a] - c)
if ans == dist[N]:
    print((-ans))
else:
    print("inf")

def main():
    N, M = list(map(int, input().split()))
    edges = []
    for _ in range(M):
        a, b, c = list(map(int, input().split()))
        a -= 1
        b -= 1
        edges.append([a, b, c])
    d = [float("inf")] * N
    d[0] = 0
    for i in range(N - 1):
        for edge in edges:
            d[edge[1]] = min(d[edge[1]], d[edge[0]] - edge[2])
    ans = d[N - 1]
    for edge in edges:
        d[edge[1]] = min(d[edge[1]], d[edge[0]] - edge[2])
    if ans == d[N - 1]:
        print((-ans))
    else:
        print("inf")

main()

-    a, b, c = list(map(int, input().split()))

-        dist[b] = min(dist[b], dist[a] - c)

-    dist[b] = min(dist[b], dist[a] - c)

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

+        a, b, c = list(map(int, input().split()))


Input:
K = int(eval(input()))

a = 7

for n in range(1,1+K):

  if a%K==0:

    print(n)

    exit()

  a = (a*10+7)%K

print((-1))

K = int(eval(input()))

a = 7

for k in range(1,K+1):

  if a%K==0:

    print(k)

    exit()

  a = (10*a+7)%K

print((-1))

K = int(eval(input()))
a = 7
for n in range(1, 1 + K):
    if a % K == 0:
        print(n)
        exit()
    a = (a * 10 + 7) % K
print((-1))

K = int(eval(input()))
a = 7
for k in range(1, K + 1):
    if a % K == 0:
        print(k)
        exit()
    a = (10 * a + 7) % K
print((-1))

-for n in range(1, 1 + K):
+for k in range(1, K + 1):
-        print(n)
+        print(k)
-    a = (a * 10 + 7) % K
+    a = (10 * a + 7) % K


Input:
S=eval(input())

if S=="RRR":

  print((3))

elif "RR" in S:

  print((2))

elif "R" in S:

  print((1))

else:

  print((0))

S=input().split("S")

ans=0

for i in S:

  ans=max(ans,len(i))

print(ans)

#これ思いつく人すごいなぁ

S = eval(input())
if S == "RRR":
    print((3))
elif "RR" in S:
    print((2))
elif "R" in S:
    print((1))
else:
    print((0))

S = input().split("S")
ans = 0
for i in S:
    ans = max(ans, len(i))
print(ans)
# これ思いつく人すごいなぁ

-S = eval(input())
-if S == "RRR":
-    print((3))
-elif "RR" in S:
-    print((2))
-elif "R" in S:
-    print((1))
-else:
-    print((0))
+S = input().split("S")
+ans = 0
+for i in S:
+    ans = max(ans, len(i))
+print(ans)
+# これ思いつく人すごいなぁ


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

#A=[]

Y=[[] for _ in range(N)] #県

for i in range(M):

  p,y=list(map(int, input().split()))

  #A.append((p,y))

  Y[p-1].append([y,i+1])

for i in range(N):

  if Y[i]:

    Y[i].sort(key=lambda x: x[0])

#indexは時間かかる

ans=[]

for i in range(N):

  for j,L in enumerate(Y[i]):

    p,y,n=i+1, L[0],L[1]

    ans.append((n,p,j+1))

ans=sorted(ans)

for n,p,y in ans:

  a=(6-len(str(p)))*"0"+str(p)+(6-len(str(y)))*"0"+str(y)

  print(a)

import bisect

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

P=[[] for _ in range(N)]

L=[]

for i in range(M):

    p,y=list(map(int, input().split()))

    L.append((p,y))

    P[p-1].append(y)

newP=[]

for p in P:

    p=sorted(p)

    newP.append(p)

for i in range(M):

    t=L[i]

    p,y=t

    num=bisect.bisect_right(newP[p-1],y)

    p=str(p).zfill(6)

    num=str(num).zfill(6)

    print((p+num))

N, M = list(map(int, input().split()))
# A=[]
Y = [[] for _ in range(N)]  # 県
for i in range(M):
    p, y = list(map(int, input().split()))
    # A.append((p,y))
    Y[p - 1].append([y, i + 1])
for i in range(N):
    if Y[i]:
        Y[i].sort(key=lambda x: x[0])
# indexは時間かかる
ans = []
for i in range(N):
    for j, L in enumerate(Y[i]):
        p, y, n = i + 1, L[0], L[1]
        ans.append((n, p, j + 1))
ans = sorted(ans)
for n, p, y in ans:
    a = (6 - len(str(p))) * "0" + str(p) + (6 - len(str(y))) * "0" + str(y)
    print(a)

import bisect

N, M = list(map(int, input().split()))
P = [[] for _ in range(N)]
L = []
for i in range(M):
    p, y = list(map(int, input().split()))
    L.append((p, y))
    P[p - 1].append(y)
newP = []
for p in P:
    p = sorted(p)
    newP.append(p)
for i in range(M):
    t = L[i]
    p, y = t
    num = bisect.bisect_right(newP[p - 1], y)
    p = str(p).zfill(6)
    num = str(num).zfill(6)
    print((p + num))

+    num = bisect.bisect_right(newP[p - 1], y)


Input:
s = eval(input())

flag = True

for i in range(1, len(s) + 1):

    if i % 2 == 1:

        if s[i-1] == 'L':

            flag = False

    else:

        if s[i-1] == 'R':

            flag = False

if flag:

    print('Yes')

else:

    print('No')

S=eval(input())

cnt=0

for i in range(len(S)):

    if i%2==0:

        if S[i]=='L':

            cnt+=1

    else:

        if S[i]=='R':

            cnt+=1

if cnt==0:

    print('Yes')

else:

    print('No')

s = eval(input())
flag = True
for i in range(1, len(s) + 1):
    if i % 2 == 1:
        if s[i - 1] == "L":
            flag = False
    else:
        if s[i - 1] == "R":
            flag = False
if flag:
    print("Yes")
else:
    print("No")

S = eval(input())
cnt = 0
for i in range(len(S)):
    if i % 2 == 0:
        if S[i] == "L":
            cnt += 1
    else:
        if S[i] == "R":
            cnt += 1
if cnt == 0:
    print("Yes")
else:
    print("No")

-s = eval(input())
-flag = True
-for i in range(1, len(s) + 1):
-    if i % 2 == 1:
-        if s[i - 1] == "L":
-            flag = False
+S = eval(input())
+cnt = 0
+for i in range(len(S)):
+    if i % 2 == 0:
+        if S[i] == "L":
+            cnt += 1
-        if s[i - 1] == "R":
-            flag = False
-if flag:
+        if S[i] == "R":
+            cnt += 1
+if cnt == 0:


Input:
def main():

  import sys

  input = sys.stdin.buffer.readline

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

  ac,wa,l,k=0,0,[0]*n,[0]*m

  for _ in k:

    p,s=input().split()

    p=int(p)

    if type(l[p-1])==int:

      if s==b'AC':

        ac+=1

        wa+=l[p-1]

        l[p-1]=''

      else:

        l[p-1]+=1

  print((ac,wa))

if __name__ == '__main__':

    main()

def main():

  import sys

  input = sys.stdin.buffer.readline

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

  a,w,l,k=0,0,[0]*n,[0]*m

  for _ in k:

    p,s=input().split()

    p=int(p)-1

    if l[p]>=0:

      if s==b'AC':

        a+=1

        w+=l[p]

        l[p]=-1

      else:

        l[p]+=1

  print((a,w))

if __name__ == '__main__':

    main()

def main():
    import sys

    input = sys.stdin.buffer.readline
    n, m = list(map(int, input().split()))
    ac, wa, l, k = 0, 0, [0] * n, [0] * m
    for _ in k:
        p, s = input().split()
        p = int(p)
        if type(l[p - 1]) == int:
            if s == b"AC":
                ac += 1
                wa += l[p - 1]
                l[p - 1] = ""
            else:
                l[p - 1] += 1
    print((ac, wa))

if __name__ == "__main__":
    main()

def main():
    import sys

    input = sys.stdin.buffer.readline
    n, m = list(map(int, input().split()))
    a, w, l, k = 0, 0, [0] * n, [0] * m
    for _ in k:
        p, s = input().split()
        p = int(p) - 1
        if l[p] >= 0:
            if s == b"AC":
                a += 1
                w += l[p]
                l[p] = -1
            else:
                l[p] += 1
    print((a, w))

if __name__ == "__main__":
    main()


Input:
A = list(map(int, input().split()))

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

max_sum = max([sum(A), sum(B)])

print(max_sum)

A, B = [list(map(int, input().split())) for _ in range(2)]

print((max([sum(A), sum(B)])))

+A, B = [list(map(int, input().split())) for _ in range(2)]


Input:
# ABC79 D - Wall

from scipy.sparse.csgraph import floyd_warshall

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

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

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

C = floyd_warshall(C)

cost = 0

for i in range(H):

    for a in A[i]:

        if a != -1:

            cost += C[a][1]

print((int(cost)))

# ABC79 D - Wall

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

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

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

def f_warshall(C):

  for k in range(10):

    for i in range(10):

      for j in range(10):

        C[i][j] = min(C[i][j], C[i][k] + C[k][j])

f_warshall(C)

cost = 0

for i in range(H):

  for j in range(W):

    if A[i][j] == -1:

      continue

    else:

      cost += C[A[i][j]][1]

print((int(cost)))

-from scipy.sparse.csgraph import floyd_warshall


Input:
import sys

import numpy as np

n = int(eval(input()))

arr = np.array(list(map(int, input().split())))

comp = np.arange(n) + 1

diff = arr - comp

diff.sort()

diff = diff - np.median(diff)

print((int(np.abs(diff).sum())))

import numpy as np

n = int(eval(input()))

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

arr = np.arange(n) + 1

diff = a - arr

diff.sort()

diff = diff - np.median(diff)

print((int(np.abs(diff).sum())))

-arr = np.array(list(map(int, input().split())))

+a = np.array(list(map(int, input().split())))


Input:
n = int(eval(input()))

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

dp = [[0,0,0] for _ in range(n)]

dp[0] = l[0]

for i in range(1, n):

    for j in range(3):

        for k in range(3):

            if j != k:

                dp[i][j] = max(dp[i][j], dp[i-1][k] + l[i][j])

print((max(dp[-1])))

n = int(eval(input()))

abc  = [[], [], []]

abc = [list(map(int, input().split())) for _ in range(n)] # DB取得方法のみ違う, 分かればどっちでもok

#print(abc)

dp = [[0,0,0] for _ in range(n)]

dp[0] = abc[0]

#print(dp)

for i in range(1, n):

    for j in range(3):

        for k in range(3):

            if j != k:

                dp[i][j] = max(dp[i][j], dp[i-1][k] + abc[i][j]) # ここのDB指定方法に影響

print((max(dp[-1])))

n = int(eval(input()))
l = [list(map(int, input().split())) for _ in range(n)]
dp = [[0, 0, 0] for _ in range(n)]
dp[0] = l[0]
for i in range(1, n):
    for j in range(3):
        for k in range(3):
            if j != k:
                dp[i][j] = max(dp[i][j], dp[i - 1][k] + l[i][j])
print((max(dp[-1])))

n = int(eval(input()))
abc = [[], [], []]
abc = [list(map(int, input().split())) for _ in range(n)]  # DB取得方法のみ違う, 分かればどっちでもok
# print(abc)
dp = [[0, 0, 0] for _ in range(n)]
dp[0] = abc[0]
# print(dp)
for i in range(1, n):
    for j in range(3):
        for k in range(3):
            if j != k:
                dp[i][j] = max(dp[i][j], dp[i - 1][k] + abc[i][j])  # ここのDB指定方法に影響
print((max(dp[-1])))

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

+abc = [list(map(int, input().split())) for _ in range(n)]  # DB取得方法のみ違う, 分かればどっちでもok

+                dp[i][j] = max(dp[i][j], dp[i - 1][k] + abc[i][j])  # ここのDB指定方法に影響


Input:
INF = 99999999999

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

c_l = []

a_l = []

for _ in range(n):

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

    c_l.append(a_list[0])

    a_l.append(a_list[1:])

min_c = INF

for i in range(2 ** n):

    bag_c = []

    bag_a = []

    for j in range(n):

        if ((i >> j) & 1):

            bag_c.append(c_l[j])

            bag_a.append(a_l[j])

        l = len(bag_a)

        c_sum = 0

        s_sum = [0]*m

        for ii in range(l):

            c_sum += bag_c[ii]

            for mm in range(m):

                s_sum[mm] += bag_a[ii][mm]

        if min(s_sum) >= x and c_sum < min_c:

            min_c = c_sum

if min_c == INF:

    print((-1))

else:

    print(min_c)

from itertools import product

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

al = []

cl = []

for _ in range(n):

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

    cl.append(row[0])

    al.append(row[1:])

ans = 10**9

bit = 2

ite = list(product(list(range(bit)),repeat=n))

for pattern in ite:

    skills = [0]*m

    cost = 0

    for i, v in enumerate(pattern):

        if v == 1:

            curr_al = al[i]

            cost += cl[i]

            for j, a in enumerate(curr_al):

                skills[j] += a

    if min(skills) >= x:

        ans = min(ans,cost)

if ans == 10**9: ans = -1

print(ans)

INF = 99999999999
n, m, x = list(map(int, input().split()))
c_l = []
a_l = []
for _ in range(n):
    a_list = list(map(int, input().split()))
    c_l.append(a_list[0])
    a_l.append(a_list[1:])
min_c = INF
for i in range(2**n):
    bag_c = []
    bag_a = []
    for j in range(n):
        if (i >> j) & 1:
            bag_c.append(c_l[j])
            bag_a.append(a_l[j])
        l = len(bag_a)
        c_sum = 0
        s_sum = [0] * m
        for ii in range(l):
            c_sum += bag_c[ii]
            for mm in range(m):
                s_sum[mm] += bag_a[ii][mm]
        if min(s_sum) >= x and c_sum < min_c:
            min_c = c_sum
if min_c == INF:
    print((-1))
else:
    print(min_c)

from itertools import product

n, m, x = list(map(int, input().split()))
al = []
cl = []
for _ in range(n):
    row = list(map(int, input().split()))
    cl.append(row[0])
    al.append(row[1:])
ans = 10**9
bit = 2
ite = list(product(list(range(bit)), repeat=n))
for pattern in ite:
    skills = [0] * m
    cost = 0
    for i, v in enumerate(pattern):
        if v == 1:
            curr_al = al[i]
            cost += cl[i]
            for j, a in enumerate(curr_al):
                skills[j] += a
    if min(skills) >= x:
        ans = min(ans, cost)
if ans == 10**9:
    ans = -1
print(ans)

-    a_list = list(map(int, input().split()))

-                s_sum[mm] += bag_a[ii][mm]

-        if min(s_sum) >= x and c_sum < min_c:

+    row = list(map(int, input().split()))

+ite = list(product(list(range(bit)), repeat=n))

+            for j, a in enumerate(curr_al):