Input:
INFTY = 100000000000000000000000000

n = int(input())

graph = {}

for i in range(n):

    entry = list(map(int, input().split(' ')))

    u = entry[0]

    k = entry[1]

    graph[u] = {}

    for j in range(k):

        v = entry[2+j*2]

        c = entry[2+j*2+1]

        graph[u][v] = c

d = {}

visited = {}

for i in range(n):

    d[i] = INFTY

    visited[i] = False

s = 0

d[s] = 0

visited[s] = True

while True:

    for i in range(n):

        if not visited[i] and i in graph[s] and d[i] > d[s] + graph[s][i]:

            d[i] = d[s] + graph[s][i]

    mincost = INFTY

    minnode = -1

    for i in range(n):

        if not visited[i] and d[i] < mincost:

            mincost = d[i]

            minnode = i

    if mincost == INFTY: break

    visited[minnode] = True

    s = minnode

for i in range(n):

    print(i,d[i])

from collections import defaultdict

def dijkstra(G, s):

  heap = Heap()

  heap.push((s, 0))

  fixed = set()

  d = defaultdict(lambda: 999999999999999999999)

  d[s] = 0

  while len(heap.data) > 0:

    v = heap.pop()

    if v in fixed:

      continue

    for u in G[v]:

      if u in fixed:

        continue

      c = G[v][u]

      if d[v] + c < d[u]:

        d[u] = d[v] + c

        heap.push((u, d[u]))

    fixed.add(v)

  return d

class Heap:

  def __init__(self):

    self.data = []

  def push(self,x):

    self.data.append(x)

    i = len(self.data)-1

    while self._p(i) >= 0:

      if self.data[i][1] < self.data[self._p(i)][1]:

        tmp = self.data[i]

        self.data[i] = self.data[self._p(i)]

        self.data[self._p(i)] = tmp

        i = self._p(i)

      else:

        break

  def pop(self):

    ret = self.top()

    n = self.data.pop()

    if len(self.data) > 0:

      self.data[0] = n

      i = 0

      while True:

        if self._l(i) < len(self.data):

          l = self.data[self._l(i)]

        else:

          l = (-1, 999999999999999999999)

        if self._r(i) < len(self.data):

          r = self.data[self._r(i)]

        else:

          r = (-1, 999999999999999999999)

        if l[1] > r[1]:

          if r[1] < self.data[i][1]:

            tmp = self.data[i]

            self.data[i] = self.data[self._r(i)]

            self.data[self._r(i)] = tmp

            i = self._r(i)

          else:

            break

        else:

          if l[1] < self.data[i][1]:

            tmp = self.data[i]

            self.data[i] = self.data[self._l(i)]

            self.data[self._l(i)] = tmp

            i = self._l(i)

          else:

            break

    return ret[0]

  def top(self):

    return self.data[0]

  def _p(self, i):

    i = i+1

    return i//2-1

  def _l(self, i):

    i = i+1

    return i*2-1

  def _r(self, i):

    i = i+1

    return i*2

G = {}

n = int(eval(input()))

for _ in range(n):

  entry = [int(v) for v in input().strip().split(' ')]

  u = entry[0]

  k = entry[1]

  G[u] = {}

  for i in range(k):

    v = entry[2+i*2]

    c = entry[3+i*2]

    G[u][v] = c

d = dijkstra(G, 0)

for i in range(n):

  print((i, d[i]))

INFTY = 100000000000000000000000000
n = int(input())
graph = {}
for i in range(n):
    entry = list(map(int, input().split(" ")))
    u = entry[0]
    k = entry[1]
    graph[u] = {}
    for j in range(k):
        v = entry[2 + j * 2]
        c = entry[2 + j * 2 + 1]
        graph[u][v] = c
d = {}
visited = {}
for i in range(n):
    d[i] = INFTY
    visited[i] = False
s = 0
d[s] = 0
visited[s] = True
while True:
    for i in range(n):
        if not visited[i] and i in graph[s] and d[i] > d[s] + graph[s][i]:
            d[i] = d[s] + graph[s][i]
    mincost = INFTY
    minnode = -1
    for i in range(n):
        if not visited[i] and d[i] < mincost:
            mincost = d[i]
            minnode = i
    if mincost == INFTY:
        break
    visited[minnode] = True
    s = minnode
for i in range(n):
    print(i, d[i])

from collections import defaultdict

def dijkstra(G, s):
    heap = Heap()
    heap.push((s, 0))
    fixed = set()
    d = defaultdict(lambda: 999999999999999999999)
    d[s] = 0
    while len(heap.data) > 0:
        v = heap.pop()
        if v in fixed:
            continue
        for u in G[v]:
            if u in fixed:
                continue
            c = G[v][u]
            if d[v] + c < d[u]:
                d[u] = d[v] + c
                heap.push((u, d[u]))
        fixed.add(v)
    return d

class Heap:
    def __init__(self):
        self.data = []

    def push(self, x):
        self.data.append(x)
        i = len(self.data) - 1
        while self._p(i) >= 0:
            if self.data[i][1] < self.data[self._p(i)][1]:
                tmp = self.data[i]
                self.data[i] = self.data[self._p(i)]
                self.data[self._p(i)] = tmp
                i = self._p(i)
            else:
                break

    def pop(self):
        ret = self.top()
        n = self.data.pop()
        if len(self.data) > 0:
            self.data[0] = n
            i = 0
            while True:
                if self._l(i) < len(self.data):
                    l = self.data[self._l(i)]
                else:
                    l = (-1, 999999999999999999999)
                if self._r(i) < len(self.data):
                    r = self.data[self._r(i)]
                else:
                    r = (-1, 999999999999999999999)
                if l[1] > r[1]:
                    if r[1] < self.data[i][1]:
                        tmp = self.data[i]
                        self.data[i] = self.data[self._r(i)]
                        self.data[self._r(i)] = tmp
                        i = self._r(i)
                    else:
                        break
                else:
                    if l[1] < self.data[i][1]:
                        tmp = self.data[i]
                        self.data[i] = self.data[self._l(i)]
                        self.data[self._l(i)] = tmp
                        i = self._l(i)
                    else:
                        break
        return ret[0]

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

    def _p(self, i):
        i = i + 1
        return i // 2 - 1

    def _l(self, i):
        i = i + 1
        return i * 2 - 1

    def _r(self, i):
        i = i + 1
        return i * 2

G = {}
n = int(eval(input()))
for _ in range(n):
    entry = [int(v) for v in input().strip().split(" ")]
    u = entry[0]
    k = entry[1]
    G[u] = {}
    for i in range(k):
        v = entry[2 + i * 2]
        c = entry[3 + i * 2]
        G[u][v] = c
d = dijkstra(G, 0)
for i in range(n):
    print((i, d[i]))

-    entry = list(map(int, input().split(" ")))

+            if self.data[i][1] < self.data[self._p(i)][1]:

+                self.data[i] = self.data[self._p(i)]

+                self.data[self._p(i)] = tmp

+                if self._l(i) < len(self.data):

+                    l = self.data[self._l(i)]

+                if self._r(i) < len(self.data):

+                    r = self.data[self._r(i)]

+                    if r[1] < self.data[i][1]:

+                        tmp = self.data[i]

+                        self.data[i] = self.data[self._r(i)]

+                        self.data[self._r(i)] = tmp

+                    if l[1] < self.data[i][1]:

+                        tmp = self.data[i]

+                        self.data[i] = self.data[self._l(i)]

+                        self.data[self._l(i)] = tmp

+    entry = [int(v) for v in input().strip().split(" ")]

-        if not visited[i] and i in graph[s] and d[i] > d[s] + graph[s][i]:

-        if not visited[i] and d[i] < mincost:


Input:
import itertools

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

comb = [] #0:使用しない,1:竹Aの材料,2:竹Bの材料,3:竹Cの材料

L = []

for i in range(N):

  l = int(eval(input()))

  L.append(l)

  comb.append([0,1,2,3])

All_comb =  list(itertools.product(*comb))

min_MP = float('inf')

for i in range(len(All_comb)):

  tmp = All_comb[i]

  Non_material = []

  A_material = []

  B_material = []

  C_material = []

  for j in range(len(tmp)):

    if(tmp[j] == 0): Non_material.append(L[j])

    elif(tmp[j] == 1): A_material.append(L[j])

    elif(tmp[j] == 2): B_material.append(L[j])

    elif(tmp[j] == 3): C_material.append(L[j])

    a,b,c = len(A_material),len(B_material),len(C_material)

    if((a>=1)and(b>=1)and(c>=1)):

     sum_A,sum_B,sum_C = sum(A_material),sum(B_material),sum(C_material)

     MP = abs(A-sum_A)+abs(B-sum_B)+abs(C-sum_C) +10*(a+b+c-3)

     min_MP = min(MP,min_MP)

print(min_MP)

import itertools

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

Comb = itertools.product([0,1,2,3],repeat=N)

L = []

for i in range(N):

  l = int(eval(input()))

  L.append(l)

# 各竹について

# 0 : 使用しない

# 1 : 竹Aの材料にする

# 2 : 竹Bの材料にする

# 3 : 竹Cの材料にする

# 竹A,B,Cの作成法 :

# とりあえず全部合成 → 目的の長さに合わせる

ans = float('inf')

for X in Comb:

  tmp = 0

  m_A,m_B,m_C = [],[],[]

  for i in range(N):

    if(X[i] == 1): m_A.append(L[i])

    elif(X[i] == 2): m_B.append(L[i])

    elif(X[i] == 3): m_C.append(L[i])

  # 空の竹リストがないなら

  if(len(m_A)*len(m_B)*len(m_C) != 0):

    for take_list,take_len in zip([m_A,m_B,m_C],[A,B,C]):

      tmp += (len(take_list)-1)*10 # 合成

      tmp += (abs(take_len-sum(take_list)))*1 # 延長or短縮

    ans = min(ans,tmp)

print(ans)

import itertools

N, A, B, C = list(map(int, input().split()))
comb = []  # 0:使用しない,1:竹Aの材料,2:竹Bの材料,3:竹Cの材料
L = []
for i in range(N):
    l = int(eval(input()))
    L.append(l)
    comb.append([0, 1, 2, 3])
All_comb = list(itertools.product(*comb))
min_MP = float("inf")
for i in range(len(All_comb)):
    tmp = All_comb[i]
    Non_material = []
    A_material = []
    B_material = []
    C_material = []
    for j in range(len(tmp)):
        if tmp[j] == 0:
            Non_material.append(L[j])
        elif tmp[j] == 1:
            A_material.append(L[j])
        elif tmp[j] == 2:
            B_material.append(L[j])
        elif tmp[j] == 3:
            C_material.append(L[j])
        a, b, c = len(A_material), len(B_material), len(C_material)
        if (a >= 1) and (b >= 1) and (c >= 1):
            sum_A, sum_B, sum_C = sum(A_material), sum(B_material), sum(C_material)
            MP = abs(A - sum_A) + abs(B - sum_B) + abs(C - sum_C) + 10 * (a + b + c - 3)
            min_MP = min(MP, min_MP)
print(min_MP)

import itertools

N, A, B, C = list(map(int, input().split()))
Comb = itertools.product([0, 1, 2, 3], repeat=N)
L = []
for i in range(N):
    l = int(eval(input()))
    L.append(l)
# 各竹について
# 0 : 使用しない
# 1 : 竹Aの材料にする
# 2 : 竹Bの材料にする
# 3 : 竹Cの材料にする
# 竹A,B,Cの作成法 :
# とりあえず全部合成 → 目的の長さに合わせる
ans = float("inf")
for X in Comb:
    tmp = 0
    m_A, m_B, m_C = [], [], []
    for i in range(N):
        if X[i] == 1:
            m_A.append(L[i])
        elif X[i] == 2:
            m_B.append(L[i])
        elif X[i] == 3:
            m_C.append(L[i])
    # 空の竹リストがないなら
    if len(m_A) * len(m_B) * len(m_C) != 0:
        for take_list, take_len in zip([m_A, m_B, m_C], [A, B, C]):
            tmp += (len(take_list) - 1) * 10  # 合成
            tmp += (abs(take_len - sum(take_list))) * 1  # 延長or短縮
        ans = min(ans, tmp)
print(ans)

-comb = []  # 0:使用しない,1:竹Aの材料,2:竹Bの材料,3:竹Cの材料

+Comb = itertools.product([0, 1, 2, 3], repeat=N)

-        a, b, c = len(A_material), len(B_material), len(C_material)

-            sum_A, sum_B, sum_C = sum(A_material), sum(B_material), sum(C_material)

-            MP = abs(A - sum_A) + abs(B - sum_B) + abs(C - sum_C) + 10 * (a + b + c - 3)

+# 0 : 使用しない

+# 1 : 竹Aの材料にする

+# 2 : 竹Bの材料にする

+# 3 : 竹Cの材料にする

+# とりあえず全部合成 → 目的の長さに合わせる

+    # 空の竹リストがないなら

+    if len(m_A) * len(m_B) * len(m_C) != 0:

+        for take_list, take_len in zip([m_A, m_B, m_C], [A, B, C]):

+            tmp += (len(take_list) - 1) * 10  # 合成

+            tmp += (abs(take_len - sum(take_list))) * 1  # 延長or短縮


Input:
from collections import defaultdict

N = int(eval(input()))

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

D = defaultdict(int)

for i in range(N):

    D[A[i]] += 1

delete = 0

for d in D:

    if d < D[d]:

        delete += D[d] - d

    elif d > D[d]:

        delete += D[d]

print(delete)

import sys

def solve():

    input = sys.stdin.readline

    N = int(eval(input()))

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

    AD = dict()

    for a in A:

        if a in AD: AD[a] += 1

        else: AD[a] = 1

    count = 0

    for key in AD:

        if AD[key] == key: continue

        elif AD[key] > key: count += AD[key] - key

        else: count += AD[key]

    print(count)

    return 0

if __name__ == "__main__":

    solve()

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


Input:
import sys

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

if M==0:

  print((0))

  sys.exit(0)

xyzlist=[]

for i in range(N):

  x,y,z=list(map(int,input().split()))

  xyzlist.append((x,y,z))

#print(xyzlist)

selected_list1=[False]*N

pt_list=[0,0,0]

for _ in range(M):

  max_ind=-1

  max_point=-10**20

  for i in range(N):

    if selected_list1[i]:

      continue

    x,y,z=xyzlist[i]

    point=abs(pt_list[0]+x)-abs(pt_list[0])+abs(pt_list[1]+y)-abs(pt_list[1])+abs(pt_list[2]+z)-abs(pt_list[2])

    if max_point<point:

      max_ind=i

      max_point=point

  #print(max_ind+1,xyzlist[max_ind])

  selected_list1[max_ind]=True

  mx,my,mz=xyzlist[max_ind]

  pt_list=[pt_list[0]+mx,pt_list[1]+my,pt_list[2]+mz]

  #print(pt_list)

#print(selected_list1)

#print(pt_list)

answer1=0

for i in range(3):

  answer1+=abs(pt_list[i])

#print(answer1)

maxabs_ind=[-1,-1,-1]

maxabs=[-1,-1,-1]

for i in range(N):

  x,y,z=xyzlist[i]

  if abs(x)>maxabs[0]:

    maxabs_ind[0]=i

    maxabs[0]=abs(x)

  if abs(y)>maxabs[1]:

    maxabs_ind[1]=i

    maxabs[1]=abs(y)

  if abs(z)>maxabs[2]:

    maxabs_ind[2]=i

    maxabs[2]=abs(z)

#print(maxabs_ind)

selected_list2=[False]*N

selected_list2[maxabs_ind[0]]=True

pt_list=list(xyzlist[maxabs_ind[0]])

#print(pt_list)

for _ in range(M-1):

  max_ind=-1

  max_point=-10**20

  for i in range(N):

    if selected_list2[i]:

      continue

    x,y,z=xyzlist[i]

    point=abs(pt_list[0]+x)-abs(pt_list[0])+abs(pt_list[1]+y)-abs(pt_list[1])+abs(pt_list[2]+z)-abs(pt_list[2])

    if max_point<point:

      max_ind=i

      max_point=point

  #print(max_ind+1,xyzlist[max_ind])

  selected_list2[max_ind]=True

  mx,my,mz=xyzlist[max_ind]

  pt_list=[pt_list[0]+mx,pt_list[1]+my,pt_list[2]+mz]

  #print(pt_list)

#print(selected_list2)

#print(pt_list)

answer2=0

for i in range(3):

  answer2+=abs(pt_list[i])

#print(answer2)

selected_list3=[False]*N

selected_list3[maxabs_ind[1]]=True

pt_list=list(xyzlist[maxabs_ind[1]])

#print(pt_list)

for _ in range(M-1):

  max_ind=-1

  max_point=-10**20

  for i in range(N):

    if selected_list3[i]:

      continue

    x,y,z=xyzlist[i]

    point=abs(pt_list[0]+x)-abs(pt_list[0])+abs(pt_list[1]+y)-abs(pt_list[1])+abs(pt_list[2]+z)-abs(pt_list[2])

    if max_point<point:

      max_ind=i

      max_point=point

  #print(max_ind+1,xyzlist[max_ind])

  selected_list3[max_ind]=True

  mx,my,mz=xyzlist[max_ind]

  pt_list=[pt_list[0]+mx,pt_list[1]+my,pt_list[2]+mz]

  #print(pt_list)

#print(selected_list3)

#print(pt_list)

answer3=0

for i in range(3):

  answer3+=abs(pt_list[i])

#print(answer3)

selected_list4=[False]*N

selected_list4[maxabs_ind[2]]=True

pt_list=list(xyzlist[maxabs_ind[2]])

#print(pt_list)

for _ in range(M-1):

  max_ind=-1

  max_point=-10**20

  for i in range(N):

    if selected_list4[i]:

      continue

    x,y,z=xyzlist[i]

    point=abs(pt_list[0]+x)-abs(pt_list[0])+abs(pt_list[1]+y)-abs(pt_list[1])+abs(pt_list[2]+z)-abs(pt_list[2])

    if max_point<point:

      max_ind=i

      max_point=point

  #print(max_ind+1,xyzlist[max_ind])

  selected_list4[max_ind]=True

  mx,my,mz=xyzlist[max_ind]

  pt_list=[pt_list[0]+mx,pt_list[1]+my,pt_list[2]+mz]

  #print(pt_list)

#print(selected_list3)

#print(pt_list)

answer4=0

for i in range(3):

  answer4+=abs(pt_list[i])

#print(answer4)

#print(answer1,answer2,answer3,answer4)

print((max(answer1,answer2,answer3,answer4)))

import sys

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

xyzlist=[]

for i in range(N):

  x,y,z=list(map(int,input().split()))

  xyzlist.append((x,y,z))

#print(xyzlist)

answer=0

for b in range(2**3):

  bit=[0]*3

  for i in range(3):

    bit[i]=b%2

    b//=2

  #print(bit)

  slist=[]

  for x,y,z in xyzlist:

    if bit[0]==1:

      x=-x

    if bit[1]==1:

      y=-y

    if bit[2]==1:

      z=-z

    slist.append(x+y+z)

  slist.sort(reverse=True)

  answer=max(answer,sum(slist[:M]))

print(answer)

import sys

N, M = list(map(int, input().split()))
if M == 0:
    print((0))
    sys.exit(0)
xyzlist = []
for i in range(N):
    x, y, z = list(map(int, input().split()))
    xyzlist.append((x, y, z))
# print(xyzlist)
selected_list1 = [False] * N
pt_list = [0, 0, 0]
for _ in range(M):
    max_ind = -1
    max_point = -(10**20)
    for i in range(N):
        if selected_list1[i]:
            continue
        x, y, z = xyzlist[i]
        point = (
            abs(pt_list[0] + x)
            - abs(pt_list[0])
            + abs(pt_list[1] + y)
            - abs(pt_list[1])
            + abs(pt_list[2] + z)
            - abs(pt_list[2])
        )
        if max_point < point:
            max_ind = i
            max_point = point
    # print(max_ind+1,xyzlist[max_ind])
    selected_list1[max_ind] = True
    mx, my, mz = xyzlist[max_ind]
    pt_list = [pt_list[0] + mx, pt_list[1] + my, pt_list[2] + mz]
    # print(pt_list)
# print(selected_list1)
# print(pt_list)
answer1 = 0
for i in range(3):
    answer1 += abs(pt_list[i])
# print(answer1)
maxabs_ind = [-1, -1, -1]
maxabs = [-1, -1, -1]
for i in range(N):
    x, y, z = xyzlist[i]
    if abs(x) > maxabs[0]:
        maxabs_ind[0] = i
        maxabs[0] = abs(x)
    if abs(y) > maxabs[1]:
        maxabs_ind[1] = i
        maxabs[1] = abs(y)
    if abs(z) > maxabs[2]:
        maxabs_ind[2] = i
        maxabs[2] = abs(z)
# print(maxabs_ind)
selected_list2 = [False] * N
selected_list2[maxabs_ind[0]] = True
pt_list = list(xyzlist[maxabs_ind[0]])
# print(pt_list)
for _ in range(M - 1):
    max_ind = -1
    max_point = -(10**20)
    for i in range(N):
        if selected_list2[i]:
            continue
        x, y, z = xyzlist[i]
        point = (
            abs(pt_list[0] + x)
            - abs(pt_list[0])
            + abs(pt_list[1] + y)
            - abs(pt_list[1])
            + abs(pt_list[2] + z)
            - abs(pt_list[2])
        )
        if max_point < point:
            max_ind = i
            max_point = point
    # print(max_ind+1,xyzlist[max_ind])
    selected_list2[max_ind] = True
    mx, my, mz = xyzlist[max_ind]
    pt_list = [pt_list[0] + mx, pt_list[1] + my, pt_list[2] + mz]
    # print(pt_list)
# print(selected_list2)
# print(pt_list)
answer2 = 0
for i in range(3):
    answer2 += abs(pt_list[i])
# print(answer2)
selected_list3 = [False] * N
selected_list3[maxabs_ind[1]] = True
pt_list = list(xyzlist[maxabs_ind[1]])
# print(pt_list)
for _ in range(M - 1):
    max_ind = -1
    max_point = -(10**20)
    for i in range(N):
        if selected_list3[i]:
            continue
        x, y, z = xyzlist[i]
        point = (
            abs(pt_list[0] + x)
            - abs(pt_list[0])
            + abs(pt_list[1] + y)
            - abs(pt_list[1])
            + abs(pt_list[2] + z)
            - abs(pt_list[2])
        )
        if max_point < point:
            max_ind = i
            max_point = point
    # print(max_ind+1,xyzlist[max_ind])
    selected_list3[max_ind] = True
    mx, my, mz = xyzlist[max_ind]
    pt_list = [pt_list[0] + mx, pt_list[1] + my, pt_list[2] + mz]
    # print(pt_list)
# print(selected_list3)
# print(pt_list)
answer3 = 0
for i in range(3):
    answer3 += abs(pt_list[i])
# print(answer3)
selected_list4 = [False] * N
selected_list4[maxabs_ind[2]] = True
pt_list = list(xyzlist[maxabs_ind[2]])
# print(pt_list)
for _ in range(M - 1):
    max_ind = -1
    max_point = -(10**20)
    for i in range(N):
        if selected_list4[i]:
            continue
        x, y, z = xyzlist[i]
        point = (
            abs(pt_list[0] + x)
            - abs(pt_list[0])
            + abs(pt_list[1] + y)
            - abs(pt_list[1])
            + abs(pt_list[2] + z)
            - abs(pt_list[2])
        )
        if max_point < point:
            max_ind = i
            max_point = point
    # print(max_ind+1,xyzlist[max_ind])
    selected_list4[max_ind] = True
    mx, my, mz = xyzlist[max_ind]
    pt_list = [pt_list[0] + mx, pt_list[1] + my, pt_list[2] + mz]
    # print(pt_list)
# print(selected_list3)
# print(pt_list)
answer4 = 0
for i in range(3):
    answer4 += abs(pt_list[i])
# print(answer4)
# print(answer1,answer2,answer3,answer4)
print((max(answer1, answer2, answer3, answer4)))

import sys

N, M = list(map(int, input().split()))
xyzlist = []
for i in range(N):
    x, y, z = list(map(int, input().split()))
    xyzlist.append((x, y, z))
# print(xyzlist)
answer = 0
for b in range(2**3):
    bit = [0] * 3
    for i in range(3):
        bit[i] = b % 2
        b //= 2
    # print(bit)
    slist = []
    for x, y, z in xyzlist:
        if bit[0] == 1:
            x = -x
        if bit[1] == 1:
            y = -y
        if bit[2] == 1:
            z = -z
        slist.append(x + y + z)
    slist.sort(reverse=True)
    answer = max(answer, sum(slist[:M]))
print(answer)

-    # print(max_ind+1,xyzlist[max_ind])

-    pt_list = [pt_list[0] + mx, pt_list[1] + my, pt_list[2] + mz]

-    # print(max_ind+1,xyzlist[max_ind])

-    # print(max_ind+1,xyzlist[max_ind])

-    # print(max_ind+1,xyzlist[max_ind])

-print((max(answer1, answer2, answer3, answer4)))

+    answer = max(answer, sum(slist[:M]))


Input:
import sys

input = sys.stdin.readline

n = int(eval(input()))

s = str(eval(input()))

A = list(s)

A = A[0:n]

A = [{ord(c)-ord('a')} for c in A]

#print(A)

def segfunc(x, y):

    return x | y

def init(init_val):

    # set_val

    for i in range(n):

        seg[i+num-1] = init_val[i]

    # built

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

        seg[i] = segfunc(seg[2*i+1], seg[2*i+2])

def update(k, x):

    k += num - 1

    seg[k] = x

    while k:

        k = (k-1)//2

        seg[k] = segfunc(seg[2*k+1], seg[2*k+2])

def query(p, q):

    if q <= p:

        return ide_ele

    p += num - 1

    q += num - 2

    res = ide_ele

    while q-p>1:

        if p%2 == 0:

            res = segfunc(res, seg[p])

        if q%2 == 1:

            res = segfunc(res, seg[q])

            q -= 1

        p = p//2

        q = (q-1)//2

    if p == q:

        res = segfunc(res, seg[p])

    else:

        res = segfunc(segfunc(res, seg[p]), seg[q])

    return res

# identity element

ide_ele = set()

# num: n以上の最小の2のべき乗

num = 2**(n-1).bit_length()

seg = [ide_ele]*2*num

init(A)

q = int(eval(input()))

for _ in range(q):

    c, x, y = list(map(str, input().split()))

    if c == '1':

        x = int(x)-1

        y = {ord(y)-ord('a')}

        update(x, y)

    else:

        l = int(x)-1

        r = int(y)-1

        print((len(query(l, r+1))))

n = int(eval(input()))

S = list(str(eval(input())))

S = [{ord(c)-ord('a')} for c in S]

def segfunc(x, y):

    return x | y

def init(init_val):

    # set_val

    for i in range(n):

        seg[i+num-1] = init_val[i]

    # built

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

        seg[i] = segfunc(seg[2*i+1], seg[2*i+2])

def update(k, x):

    k += num - 1

    seg[k] = x

    while k:

        k = (k-1)//2

        seg[k] = segfunc(seg[2*k+1], seg[2*k+2])

def query(p, q):

    if q <= p:

        return ide_ele

    p += num - 1

    q += num - 2

    res = ide_ele

    while q-p>1:

        if p&1 == 0:

            res = segfunc(res, seg[p])

        if q&1 == 1:

            res = segfunc(res, seg[q])

            q -= 1

        p = p//2

        q = (q-1)//2

    if p == q:

        res = segfunc(res, seg[p])

    else:

        res = segfunc(segfunc(res, seg[p]), seg[q])

    return res

# identity element

ide_ele = set()

# num: n以上の最小の2のべき乗

num = 2**(n-1).bit_length()

seg = [ide_ele]*2*num

init(S)

import sys

input = sys.stdin.readline

q = int(eval(input()))

for i in range(q):

    t, x, y = list(map(str, input().split()))

    if t == '1':

        x = int(x)

        y = ord(y)-ord('a')

        update(x-1, {y})

    else:

        x = int(x)

        y = int(y)

        print((len(query(x-1, y))))

import sys

input = sys.stdin.readline
n = int(eval(input()))
s = str(eval(input()))
A = list(s)
A = A[0:n]
A = [{ord(c) - ord("a")} for c in A]
# print(A)
def segfunc(x, y):
    return x | y

def init(init_val):
    # set_val
    for i in range(n):
        seg[i + num - 1] = init_val[i]
    # built
    for i in range(num - 2, -1, -1):
        seg[i] = segfunc(seg[2 * i + 1], seg[2 * i + 2])

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

def query(p, q):
    if q <= p:
        return ide_ele
    p += num - 1
    q += num - 2
    res = ide_ele
    while q - p > 1:
        if p % 2 == 0:
            res = segfunc(res, seg[p])
        if q % 2 == 1:
            res = segfunc(res, seg[q])
            q -= 1
        p = p // 2
        q = (q - 1) // 2
    if p == q:
        res = segfunc(res, seg[p])
    else:
        res = segfunc(segfunc(res, seg[p]), seg[q])
    return res

# identity element
ide_ele = set()
# num: n以上の最小の2のべき乗
num = 2 ** (n - 1).bit_length()
seg = [ide_ele] * 2 * num
init(A)
q = int(eval(input()))
for _ in range(q):
    c, x, y = list(map(str, input().split()))
    if c == "1":
        x = int(x) - 1
        y = {ord(y) - ord("a")}
        update(x, y)
    else:
        l = int(x) - 1
        r = int(y) - 1
        print((len(query(l, r + 1))))

n = int(eval(input()))
S = list(str(eval(input())))
S = [{ord(c) - ord("a")} for c in S]

def segfunc(x, y):
    return x | y

def init(init_val):
    # set_val
    for i in range(n):
        seg[i + num - 1] = init_val[i]
    # built
    for i in range(num - 2, -1, -1):
        seg[i] = segfunc(seg[2 * i + 1], seg[2 * i + 2])

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

def query(p, q):
    if q <= p:
        return ide_ele
    p += num - 1
    q += num - 2
    res = ide_ele
    while q - p > 1:
        if p & 1 == 0:
            res = segfunc(res, seg[p])
        if q & 1 == 1:
            res = segfunc(res, seg[q])
            q -= 1
        p = p // 2
        q = (q - 1) // 2
    if p == q:
        res = segfunc(res, seg[p])
    else:
        res = segfunc(segfunc(res, seg[p]), seg[q])
    return res

# identity element
ide_ele = set()
# num: n以上の最小の2のべき乗
num = 2 ** (n - 1).bit_length()
seg = [ide_ele] * 2 * num
init(S)
import sys

input = sys.stdin.readline
q = int(eval(input()))
for i in range(q):
    t, x, y = list(map(str, input().split()))
    if t == "1":
        x = int(x)
        y = ord(y) - ord("a")
        update(x - 1, {y})
    else:
        x = int(x)
        y = int(y)
        print((len(query(x - 1, y))))

-    c, x, y = list(map(str, input().split()))

+    t, x, y = list(map(str, input().split()))


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

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

for i in range(N):

    Ai = int(eval(input()))

    for _ in range(Ai):

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

        A[i].append((x - 1, y))

def countBit(x):

    if x == 0:

        return 0

    else:

        return countBit(x >> 1) + (x & 1)

res = 0

for bits in range(2 ** N):

    bits_ = bin(bits)

    consistency = True

    for i, testimony in enumerate(A):

        if not ((bits >> i) & 1):

            continue

        for t in testimony:

            if ((bits >> t[0]) & 1) ^ t[1]:

                consistency = False

    if consistency:

        res = max(res, countBit(bits))

print(res)

N = int(eval(input()))

A = [[set() for _ in range(2)] for _ in range(N)]

for i in range(N):

    Ai = int(eval(input()))

    for _ in range(Ai):

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

        A[i][y].add(x - 1)

ans = 0

for bit in range(1 << N):

    truth = set()

    false = set()

    ppl_truth = set()

    ppl_false = set()

    for i in range(N):

        if (bit >> i) & 1:

            ppl_truth.add(i)

            truth |= A[i][1]

            false |= A[i][0]

        else:

            ppl_false.add(i)

    if ppl_truth >= truth and ppl_false >= false:

        ans = max(ans, len(ppl_truth))

print(ans)

N = int(eval(input()))
A = [[] for _ in range(N)]
for i in range(N):
    Ai = int(eval(input()))
    for _ in range(Ai):
        x, y = list(map(int, input().split()))
        A[i].append((x - 1, y))

def countBit(x):
    if x == 0:
        return 0
    else:
        return countBit(x >> 1) + (x & 1)

res = 0
for bits in range(2**N):
    bits_ = bin(bits)
    consistency = True
    for i, testimony in enumerate(A):
        if not ((bits >> i) & 1):
            continue
        for t in testimony:
            if ((bits >> t[0]) & 1) ^ t[1]:
                consistency = False
    if consistency:
        res = max(res, countBit(bits))
print(res)

+A = [[set() for _ in range(2)] for _ in range(N)]

-        return countBit(x >> 1) + (x & 1)

+    if ppl_truth >= truth and ppl_false >= false:


Input:
from sys import stdin

input = stdin.readline

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

ac = [False] * N

wa = [0] * N

wa_cnt = 0

for i in range(M):

  p, s = input().split()

  p = int(p) - 1

  if ac[p] is False and s == "AC":

    wa_cnt += wa[p]

    ac[p] = True

  elif s == "WA":

    wa[p] += 1

print((ac.count(True), wa_cnt))

import sys

N, M, *PS = sys.stdin.read().strip().split()

N = int(N)

ac = [0] * N

wa = [0] * N

for p, s in zip(*[iter(PS)] * 2):

  p = int(p) - 1

  if s == "AC":

    ac[p] = 1

  elif ac[p] == 0:

    wa[p] += 1

penalties = sum([w * a for a, w in zip(ac, wa)])

print(("{} {}".format(sum(ac), penalties)))

+N, M, *PS = sys.stdin.read().strip().split()

+penalties = sum([w * a for a, w in zip(ac, wa)])


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

if 0<a:

    ans = 'Positive'

elif b<0:

    ans = 'Positive' if (b-a)%2==1 else 'Negative'

else:

    ans = 'Zero'

print(ans)

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

if a>0:

    print('Positive')

elif b<0:

    if (a-b+1)%2==0:

        print('Positive')

    else:

        print('Negative')

else:

    print('Zero')

a, b = list(map(int, input().split()))
if 0 < a:
    ans = "Positive"
elif b < 0:
    ans = "Positive" if (b - a) % 2 == 1 else "Negative"
else:
    ans = "Zero"
print(ans)

a, b = list(map(int, input().split()))
if a > 0:
    print("Positive")
elif b < 0:
    if (a - b + 1) % 2 == 0:
        print("Positive")
    else:
        print("Negative")
else:
    print("Zero")

-    ans = "Positive" if (b - a) % 2 == 1 else "Negative"


Input:
def main():

    X, Y = (int(i) for i in input().split())

    fac = [0] * max(X, Y)

    finv = [0] * max(X, Y)

    inv = [0] * max(X, Y)

    MOD = (10**9) + 7

    def COMinit(m):

        fac[0] = 1

        finv[0] = 1

        if m > 1:

            fac[1] = 1

            finv[1] = 1

            inv[1] = 1

            for i in range(2, m):

                fac[i] = fac[i-1] * i % MOD

                inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD

                finv[i] = finv[i - 1] * inv[i] % MOD

    def COM(n, k):

        if n < k:

            return 0

        if n < 0 or k < 0:

            return 0

        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD

    COMinit(max(X, Y))

    if (X+Y) % 3 != 0:

        return print(0)

    n = (2*Y - X) // 3

    m = (2*X - Y) // 3

    print(COM(n+m, m))

if __name__ == '__main__':

    main()

def main():

    X, Y = (int(i) for i in input().split())

    if (X+Y) % 3 != 0:

        return print(0)

    m = (X + Y)//3 + 3

    fac = [0] * m

    finv = [0] * m

    inv = [0] * m

    MOD = 10**9 + 7

    def COMBinitialize(m):

        fac[0] = 1

        finv[0] = 1

        if m > 1:

            fac[1] = 1

            finv[1] = 1

            inv[1] = 1

            for i in range(2, m):

                fac[i] = fac[i-1] * i % MOD

                inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD

                finv[i] = finv[i - 1] * inv[i] % MOD

    def COMB(n, k):

        if n < k:

            return 0

        if n < 0 or k < 0:

            return 0

        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD

    COMBinitialize(m)

    n = (X+Y)//3

    k = X - n

    print(COMB(n, k))

if __name__ == '__main__':

    main()

def main():
    X, Y = (int(i) for i in input().split())
    fac = [0] * max(X, Y)
    finv = [0] * max(X, Y)
    inv = [0] * max(X, Y)
    MOD = (10**9) + 7

    def COMinit(m):
        fac[0] = 1
        finv[0] = 1
        if m > 1:
            fac[1] = 1
            finv[1] = 1
            inv[1] = 1
            for i in range(2, m):
                fac[i] = fac[i - 1] * i % MOD
                inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
                finv[i] = finv[i - 1] * inv[i] % MOD

    def COM(n, k):
        if n < k:
            return 0
        if n < 0 or k < 0:
            return 0
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD

    COMinit(max(X, Y))
    if (X + Y) % 3 != 0:
        return print(0)
    n = (2 * Y - X) // 3
    m = (2 * X - Y) // 3
    print(COM(n + m, m))

if __name__ == "__main__":
    main()

def main():
    X, Y = (int(i) for i in input().split())
    if (X + Y) % 3 != 0:
        return print(0)
    m = (X + Y) // 3 + 3
    fac = [0] * m
    finv = [0] * m
    inv = [0] * m
    MOD = 10**9 + 7

    def COMBinitialize(m):
        fac[0] = 1
        finv[0] = 1
        if m > 1:
            fac[1] = 1
            finv[1] = 1
            inv[1] = 1
            for i in range(2, m):
                fac[i] = fac[i - 1] * i % MOD
                inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
                finv[i] = finv[i - 1] * inv[i] % MOD

    def COMB(n, k):
        if n < k:
            return 0
        if n < 0 or k < 0:
            return 0
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD

    COMBinitialize(m)
    n = (X + Y) // 3
    k = X - n
    print(COMB(n, k))

if __name__ == "__main__":
    main()

-    fac = [0] * max(X, Y)
-    finv = [0] * max(X, Y)
-    inv = [0] * max(X, Y)
-    MOD = (10**9) + 7
+    if (X + Y) % 3 != 0:
+        return print(0)
+    m = (X + Y) // 3 + 3
+    fac = [0] * m
+    finv = [0] * m
+    inv = [0] * m
+    MOD = 10**9 + 7
-    def COMinit(m):
+    def COMBinitialize(m):
-    def COM(n, k):
+    def COMB(n, k):
-    COMinit(max(X, Y))
-    if (X + Y) % 3 != 0:
-        return print(0)
-    n = (2 * Y - X) // 3
-    m = (2 * X - Y) // 3
-    print(COM(n + m, m))
+    COMBinitialize(m)
+    n = (X + Y) // 3
+    k = X - n
+    print(COMB(n, k))


Input:
import heapq

def dijkstra(s):

    inf=float("inf")

    color=["white" for _ in range(n)]

    D=[inf for _ in range(n)]

    M=[[] for _ in range(n)]

    for a,b,c in ABC:

        M[a-1].append([b-1,c])

        M[b-1].append([a-1,c])

    D[s]=0

    H=[(0,s)]

    heapq.heapify(H)

    while len(H)>=1:

        u=heapq.heappop(H)[1]

        if color[u]=="black":continue

        color[u]="black"

        V=[(i,j) for i,j in M[u] if color[i]!="black"]

        while len(V)!=0:

            for i,j in V:

                if D[u]+j<D[i]:

                    D[i]=D[u]+j

                    color[i]="gray"

                    heapq.heappush(H,(D[i],i))

            break

    return D

n=int(eval(input()))

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

q,k=list(map(int,input().split()))

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

D=dijkstra(k-1)

for x,y in XY:

    print((D[x-1]+D[y-1]))

import heapq

import sys

input=sys.stdin.readline

def dijkstra(s):

    inf=float("inf")

    color=["white" for _ in range(n)]

    D=[inf for _ in range(n)]

    M=[[] for _ in range(n)]

    for a,b,c in ABC:

        M[a-1].append([b-1,c])

        M[b-1].append([a-1,c])

    D[s]=0

    H=[(0,s)]

    heapq.heapify(H)

    while len(H)>=1:

        u=heapq.heappop(H)[1]

        if color[u]=="black":continue

        color[u]="black"

        V=[(i,j) for i,j in M[u] if color[i]!="black"]

        while len(V)!=0:

            for i,j in V:

                if D[u]+j<D[i]:

                    D[i]=D[u]+j

                    color[i]="gray"

                    heapq.heappush(H,(D[i],i))

            break

    return D

n=int(eval(input()))

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

q,k=list(map(int,input().split()))

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

D=dijkstra(k-1)

for x,y in XY:

    print((D[x-1]+D[y-1]))

import heapq

def dijkstra(s):
    inf = float("inf")
    color = ["white" for _ in range(n)]
    D = [inf for _ in range(n)]
    M = [[] for _ in range(n)]
    for a, b, c in ABC:
        M[a - 1].append([b - 1, c])
        M[b - 1].append([a - 1, c])
    D[s] = 0
    H = [(0, s)]
    heapq.heapify(H)
    while len(H) >= 1:
        u = heapq.heappop(H)[1]
        if color[u] == "black":
            continue
        color[u] = "black"
        V = [(i, j) for i, j in M[u] if color[i] != "black"]
        while len(V) != 0:
            for i, j in V:
                if D[u] + j < D[i]:
                    D[i] = D[u] + j
                    color[i] = "gray"
                    heapq.heappush(H, (D[i], i))
            break
    return D

n = int(eval(input()))
ABC = [list(map(int, input().split())) for _ in range(n - 1)]
q, k = list(map(int, input().split()))
XY = [list(map(int, input().split())) for _ in range(q)]
D = dijkstra(k - 1)
for x, y in XY:
    print((D[x - 1] + D[y - 1]))

import heapq
import sys

input = sys.stdin.readline

def dijkstra(s):
    inf = float("inf")
    color = ["white" for _ in range(n)]
    D = [inf for _ in range(n)]
    M = [[] for _ in range(n)]
    for a, b, c in ABC:
        M[a - 1].append([b - 1, c])
        M[b - 1].append([a - 1, c])
    D[s] = 0
    H = [(0, s)]
    heapq.heapify(H)
    while len(H) >= 1:
        u = heapq.heappop(H)[1]
        if color[u] == "black":
            continue
        color[u] = "black"
        V = [(i, j) for i, j in M[u] if color[i] != "black"]
        while len(V) != 0:
            for i, j in V:
                if D[u] + j < D[i]:
                    D[i] = D[u] + j
                    color[i] = "gray"
                    heapq.heappush(H, (D[i], i))
            break
    return D

n = int(eval(input()))
ABC = [list(map(int, input().split())) for _ in range(n - 1)]
q, k = list(map(int, input().split()))
XY = [list(map(int, input().split())) for _ in range(q)]
D = dijkstra(k - 1)
for x, y in XY:
    print((D[x - 1] + D[y - 1]))

+import sys
+
+input = sys.stdin.readline


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

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 fractions import gcd

from heapq import heappush, heappop

from functools import reduce

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 ZIP(n): return list(zip(*(MAP() for _ in range(n))))

sys.setrecursionlimit(10 ** 9)

INF = float('inf')

mod = 10**9 + 7

#from decimal import *

S = eval(input())

N = len(S)

dp = [[0, 0] for _ in range(N+1)]

dp[1][0] = 1

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

	if S[i-1] != S[i-2]:

		dp[i][0] = dp[i-1][0] + 1

	dp[i][0] = max(dp[i][0], dp[i-1][1] + 1)

	dp[i][1] = dp[i-2][0] + 1

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

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

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 fractions import gcd

from heapq import heappush, heappop

from functools import reduce

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 ZIP(n): return list(zip(*(MAP() for _ in range(n))))

sys.setrecursionlimit(10 ** 9)

INF = float('inf')

mod = 10**9 + 7

#from decimal import *

S = eval(input())

N = len(S)

dp = [[0, 0] for _ in range(N+1)]

dp[1][0] = 1

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

	if S[i-1] != S[i-2]:

		dp[i][0] = dp[i-1][0] + 1

	else:

		dp[i][0] = dp[i-1][1] + 1

	dp[i][1] = dp[i-2][0] + 1

	#print(dp)

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

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
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 fractions import gcd
from heapq import heappush, heappop
from functools import reduce

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 ZIP(n):
    return list(zip(*(MAP() for _ in range(n))))

sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
# from decimal import *
S = eval(input())
N = len(S)
dp = [[0, 0] for _ in range(N + 1)]
dp[1][0] = 1
for i in range(2, N + 1):
    if S[i - 1] != S[i - 2]:
        dp[i][0] = dp[i - 1][0] + 1
    dp[i][0] = max(dp[i][0], dp[i - 1][1] + 1)
    dp[i][1] = dp[i - 2][0] + 1
print((dp[-1][0]))

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
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 fractions import gcd
from heapq import heappush, heappop
from functools import reduce

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 ZIP(n):
    return list(zip(*(MAP() for _ in range(n))))

sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
# from decimal import *
S = eval(input())
N = len(S)
dp = [[0, 0] for _ in range(N + 1)]
dp[1][0] = 1
for i in range(2, N + 1):
    if S[i - 1] != S[i - 2]:
        dp[i][0] = dp[i - 1][0] + 1
    else:
        dp[i][0] = dp[i - 1][1] + 1
    dp[i][1] = dp[i - 2][0] + 1
    # print(dp)
print((dp[-1][0]))


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

ans = 0

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

    tmp = n//i

    ans += (tmp*(tmp+1)//2)*i

print(ans)

import numba

@numba.njit

def main(n):

    ans = 0

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

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

            ans += k*f

    return ans

n = int(eval(input()))

print((main(n)))

n = int(eval(input()))
ans = 0
for i in range(1, n + 1):
    tmp = n // i
    ans += (tmp * (tmp + 1) // 2) * i
print(ans)

import numba

@numba.njit
def main(n):
    ans = 0
    for k in range(1, n + 1):
        for f in range(1, n // k + 1):
            ans += k * f
    return ans

n = int(eval(input()))
print((main(n)))

+import numba
+
+
+@numba.njit
+def main(n):
+    ans = 0
+    for k in range(1, n + 1):
+        for f in range(1, n // k + 1):
+            ans += k * f
+    return ans
+
+
-ans = 0
-for i in range(1, n + 1):
-    tmp = n // i
-    ans += (tmp * (tmp + 1) // 2) * i
-print(ans)
+print((main(n)))


Input:
from collections import Counter, defaultdict, deque

class UnionFind(object):

    """Union find tree."""

    def __init__(self, nodes):

        self.par = list(range(nodes + 1))

        self.sizes = [1] * (nodes + 1)

    def root(self, key):

        if key != self.par[key]:

            k0 = key

            while k0 != self.par[k0]:

                k0 = self.par[k0]

            self.par[key] = k0

        return self.par[key]

    def merge(self, a, b):

        ra = self.root(a)

        rb = self.root(b)

        if ra != rb:

            sa = self.sizes[ra]

            sb = self.sizes[rb]

            self.par[ra] = rb

            self.sizes[rb] += sa

            return sa * sb

        return 0

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

AB = []

for _ in range(M):

    AB.append(list(map(int, input().split())))

uni = UnionFind(N)

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

anses = [comb]

for a, b in AB[-1:0:-1]:

    red = uni.merge(a, b)

    comb -= red

    anses.append(comb)

for ans in reversed(anses):

    print(ans)

from collections import Counter, defaultdict, deque

class UnionFind(object):

    """Union find tree."""

    def __init__(self, nodes):

        self.par = [-1] * nodes

    def root(self, key):

        if self.par[key] < 0:

            return key

        self.par[key] = self.root(self.par[key])

        return self.par[key]

    def size(self, key):

        return -self.par[self.root(key)]

    def merge(self, a, b):

        a = self.root(a)

        b = self.root(b)

        if a == b:

            return

        if self.size(a) < self.size(b):

            a, b = b, a

        self.par[a] += self.par[b]

        self.par[b] = a

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

AB = []

for _ in range(M):

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

    a -= 1

    b -= 1

    AB.append([a, b])

uni = UnionFind(N)

ans = [0] * M

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

for i, (a, b) in enumerate(AB[-1:0:-1], 1):

    ans[-i - 1] = ans[-i]

    if uni.root(a) != uni.root(b):

        ans[-i - 1] -= uni.size(a) * uni.size(b)

        uni.merge(a, b)

print(*ans, sep='\n')

from collections import Counter, defaultdict, deque

class UnionFind(object):
    """Union find tree."""

    def __init__(self, nodes):
        self.par = [-1] * nodes

    def root(self, key):
        if self.par[key] < 0:
            return key
        self.par[key] = self.root(self.par[key])
        return self.par[key]

    def size(self, key):
        return -self.par[self.root(key)]

    def merge(self, a, b):
        a = self.root(a)
        b = self.root(b)
        if a == b:
            return
        if self.size(a) < self.size(b):
            a, b = b, a
        self.par[a] += self.par[b]
        self.par[b] = a

N, M = map(int, input().split())
AB = []
for _ in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    AB.append([a, b])
uni = UnionFind(N)
ans = [0] * M
ans[-1] = N * (N - 1) // 2
for i, (a, b) in enumerate(AB[-1:0:-1], 1):
    ans[-i - 1] = ans[-i]
    if uni.root(a) != uni.root(b):
        ans[-i - 1] -= uni.size(a) * uni.size(b)
        uni.merge(a, b)
print(*ans, sep="\n")

-        self.par = list(range(nodes + 1))

+        self.par[key] = self.root(self.par[key])

+        return -self.par[self.root(key)]

+        if self.size(a) < self.size(b):

-    AB.append(list(map(int, input().split())))

+for i, (a, b) in enumerate(AB[-1:0:-1], 1):

+        ans[-i - 1] -= uni.size(a) * uni.size(b)


Input:
def d_even_relation_dfs(N, Nodes):  # DFSによる

    import sys

    sys.setrecursionlimit(10**6)

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

    for u, v, w in Nodes:  # 0-basedとする

        graph[u - 1].append((v - 1, w))

        graph[v - 1].append((u - 1, w))

    def distance_from_root(parent, current, distance, ret=[0] * N):  # 根(頂点0)から各頂点への距離

        def dfs(p, c, d):

            ret[c] = d

            for next_edge, dist in graph[c]:

                if next_edge != p:  # 木を「逆戻り」しない頂点だけ調べる

                    dfs(c, next_edge, d + dist)

        dfs(parent, current, distance)

        return ret

    ans = (1 if d % 2 == 0 else 0 for d in distance_from_root(-1, 0, 0))  # 根の親は-1番とする

    return ' '.join(map(str, ans))

N = int(eval(input()))

Nodes = [[int(i) for i in input().split()] for j in range(N - 1)]

print((d_even_relation_dfs(N, Nodes)))

def d_even_relation_bfs():

    from collections import deque

    N = int(eval(input()))

    Edges = [[int(i) for i in input().split()] for j in range(N - 1)]

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

    for u, v, w in Edges:  # 頂点は 0-indexed とする

        graph[u - 1].append((v - 1, w))

        graph[v - 1].append((u - 1, w))

    distance_from_root = [0] * N  # 根は頂点 0 とする

    queue = deque([(-1, 0, 0)])  # 親と現在の頂点番号，根から親までの距離

    while queue:

        parent, current, distance = queue.pop()

        distance_from_root[current] = distance

        for next_vertex, dist in graph[current]:

            if parent != next_vertex:  # 木を「逆戻り」しない頂点だけ調べる

                queue.appendleft((current, next_vertex, distance + dist))

    ans = (1 if d % 2 == 0 else 0 for d in distance_from_root)

    return ' '.join(map(str, ans))

print((d_even_relation_bfs()))

def d_even_relation_dfs(N, Nodes):  # DFSによる
    import sys

    sys.setrecursionlimit(10**6)
    graph = [[] for _ in range(N)]
    for u, v, w in Nodes:  # 0-basedとする
        graph[u - 1].append((v - 1, w))
        graph[v - 1].append((u - 1, w))

    def distance_from_root(parent, current, distance, ret=[0] * N):  # 根(頂点0)から各頂点への距離
        def dfs(p, c, d):
            ret[c] = d
            for next_edge, dist in graph[c]:
                if next_edge != p:  # 木を「逆戻り」しない頂点だけ調べる
                    dfs(c, next_edge, d + dist)

        dfs(parent, current, distance)
        return ret

    ans = (1 if d % 2 == 0 else 0 for d in distance_from_root(-1, 0, 0))  # 根の親は-1番とする
    return " ".join(map(str, ans))

N = int(eval(input()))
Nodes = [[int(i) for i in input().split()] for j in range(N - 1)]
print((d_even_relation_dfs(N, Nodes)))

def d_even_relation_bfs():
    from collections import deque

    N = int(eval(input()))
    Edges = [[int(i) for i in input().split()] for j in range(N - 1)]
    graph = [[] for _ in range(N)]
    for u, v, w in Edges:  # 頂点は 0-indexed とする
        graph[u - 1].append((v - 1, w))
        graph[v - 1].append((u - 1, w))
    distance_from_root = [0] * N  # 根は頂点 0 とする
    queue = deque([(-1, 0, 0)])  # 親と現在の頂点番号，根から親までの距離
    while queue:
        parent, current, distance = queue.pop()
        distance_from_root[current] = distance
        for next_vertex, dist in graph[current]:
            if parent != next_vertex:  # 木を「逆戻り」しない頂点だけ調べる
                queue.appendleft((current, next_vertex, distance + dist))
    ans = (1 if d % 2 == 0 else 0 for d in distance_from_root)
    return " ".join(map(str, ans))

print((d_even_relation_bfs()))

-def d_even_relation_dfs(N, Nodes):  # DFSによる

+    Edges = [[int(i) for i in input().split()] for j in range(N - 1)]

-    for u, v, w in Nodes:  # 0-basedとする

+    for u, v, w in Edges:  # 頂点は 0-indexed とする

-    def distance_from_root(parent, current, distance, ret=[0] * N):  # 根(頂点0)から各頂点への距離

-            for next_edge, dist in graph[c]:

-                if next_edge != p:  # 木を「逆戻り」しない頂点だけ調べる

-                    dfs(c, next_edge, d + dist)

-    ans = (1 if d % 2 == 0 else 0 for d in distance_from_root(-1, 0, 0))  # 根の親は-1番とする

+    distance_from_root = [0] * N  # 根は頂点 0 とする

+    queue = deque([(-1, 0, 0)])  # 親と現在の頂点番号，根から親までの距離

+        parent, current, distance = queue.pop()

+        distance_from_root[current] = distance

+        for next_vertex, dist in graph[current]:

+            if parent != next_vertex:  # 木を「逆戻り」しない頂点だけ調べる

+                queue.appendleft((current, next_vertex, distance + dist))

+    ans = (1 if d % 2 == 0 else 0 for d in distance_from_root)

-Nodes = [[int(i) for i in input().split()] for j in range(N - 1)]


Input:
import math

n = int(eval(input()))

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

f.sort()

ans = 0

for i in range(1,n):

    ans += f[n-math.floor(i/2)-1]

print(ans)

n = int(eval(input()))

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

f.sort(reverse = True)

ans = 0

if n%2 == 0:

    for i in range(n//2):

        ans += f[i] * 2

    ans -= f[0]

else:

    for i in range(n//2):

        ans += f[i] * 2

    ans += f[n//2]-f[0]

print(ans)

import math

n = int(eval(input()))
f = list(map(int, input().split()))
f.sort()
ans = 0
for i in range(1, n):
    ans += f[n - math.floor(i / 2) - 1]
print(ans)

n = int(eval(input()))
f = list(map(int, input().split()))
f.sort(reverse=True)
ans = 0
if n % 2 == 0:
    for i in range(n // 2):
        ans += f[i] * 2
    ans -= f[0]
else:
    for i in range(n // 2):
        ans += f[i] * 2
    ans += f[n // 2] - f[0]
print(ans)

-    ans += f[n - math.floor(i / 2) - 1]


Input:
S = eval(input())

cnt0,cnt1 = 0,0

for s in S:

    if s=="0":

        cnt0 += 1

    else:

        cnt1 += 1

print((min(cnt0,cnt1)*2))

S = eval(input())
cnt0, cnt1 = 0, 0
for s in S:
    if s == "0":
        cnt0 += 1
    else:
        cnt1 += 1
print((min(cnt0, cnt1) * 2))

-S = eval(input())
-cnt0, cnt1 = 0, 0
-for s in S:
-    if s == "0":
-        cnt0 += 1
-    else:
-        cnt1 += 1
-print((min(cnt0, cnt1) * 2))
+# Python3 (3.4.3)
+import sys
+
+input = sys.stdin.readline
+# function
+# main
+S = input().rstrip()
+r = S.count("0")
+b = S.count("1")
+print((min(r, b) * 2))


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

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

m = int(eval(input()))

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

d1 = {}

for d in D:

    if d not in d1:

        d1[d] = 1

    else:

        d1[d] += 1

d2 = {}

for t in T:

    if t not in d2:

        d2[t] = 1

    else:

        d2[t] += 1

for k2, v2 in list(d2.items()):

    if k2 not in d1:

        print('NO')

        exit()

    else:

        v1 = d1[k2]

        if v1 < v2:

            print('NO')

            exit()

else:

    print('YES')

n= int(eval(input()))

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

m = int(eval(input()))

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

from collections import Counter

C = Counter(D)

for t in T:

    if t not in C:

        print('NO')

        exit()

    else:

        if C[t] == 0:

            print('NO')

            exit()

        else:

            C[t] -= 1

else:

    print('YES')

n = int(eval(input()))
D = list(map(int, input().split()))
m = int(eval(input()))
T = list(map(int, input().split()))
d1 = {}
for d in D:
    if d not in d1:
        d1[d] = 1
    else:
        d1[d] += 1
d2 = {}
for t in T:
    if t not in d2:
        d2[t] = 1
    else:
        d2[t] += 1
for k2, v2 in list(d2.items()):
    if k2 not in d1:
        print("NO")
        exit()
    else:
        v1 = d1[k2]
        if v1 < v2:
            print("NO")
            exit()
else:
    print("YES")

n = int(eval(input()))
D = list(map(int, input().split()))
m = int(eval(input()))
T = list(map(int, input().split()))
from collections import Counter

C = Counter(D)
for t in T:
    if t not in C:
        print("NO")
        exit()
    else:
        if C[t] == 0:
            print("NO")
            exit()
        else:
            C[t] -= 1
else:
    print("YES")

-d1 = {}
-for d in D:
-    if d not in d1:
-        d1[d] = 1
-    else:
-        d1[d] += 1
-d2 = {}
+from collections import Counter
+
+C = Counter(D)
-    if t not in d2:
-        d2[t] = 1
-    else:
-        d2[t] += 1
-for k2, v2 in list(d2.items()):
-    if k2 not in d1:
+    if t not in C:
-        v1 = d1[k2]
-        if v1 < v2:
+        if C[t] == 0:
+        else:
+            C[t] -= 1


Input:
import numpy as np

N = int(eval(input()))

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

ans = np.argsort(A)

for i in range(N):

    print((ans[i] + 1))

import numpy as np

N = int(eval(input()))

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

tmp = np.argsort(A)

tmp2= tmp + np.ones(N)

tmp3 = [int(_) for _ in tmp2.tolist()]

ans = [str(_) for _ in tmp3]

print((" ".join(ans)))

import numpy as np

N = int(eval(input()))
A = [int(_) for _ in input().split(" ")]
tmp = np.argsort(A)
tmp2 = tmp + np.ones(N)
tmp3 = [int(_) for _ in tmp2.tolist()]
ans = [str(_) for _ in tmp3]
print((" ".join(ans)))

-ans = np.argsort(A)
-for i in range(N):
-    print((ans[i] + 1))
+tmp = np.argsort(A)
+tmp2 = tmp + np.ones(N)
+tmp3 = [int(_) for _ in tmp2.tolist()]
+ans = [str(_) for _ in tmp3]
+print((" ".join(ans)))


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

S = [list(eval(input())) for _ in range(h)]

L = [[0] * w for _ in range(h)]

R = [[0] * w for _ in range(h)]

U = [[0] * w for _ in range(h)]

D = [[0] * w for _ in range(h)]

for i in range(h):

    for j in range(w):

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

            if j == 0:

                L[i][j] = 1

            else:

                L[i][j] = L[i][j-1] + 1

    for j in reversed(list(range(w))):

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

            if j == w-1:

                R[i][j] = 1

            else:

                R[i][j] = R[i][j+1] + 1

for j in range(w):

    for i in range(h):

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

            if i == 0:

                U[i][j] = 1

            else:

                U[i][j] = U[i-1][j] + 1

    for i in reversed(list(range(h))):

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

            if i == h-1:

                D[i][j] = 1

            else:

                D[i][j] = D[i+1][j] + 1

ans = 0

for i in range(h):

    for j in range(w):

        ans = max(ans, L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3)

print(ans)

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

S = [eval(input()) for _ in range(h)]

L = [[0] * w for _ in range(h)]

R = [[0] * w for _ in range(h)]

U = [[0] * w for _ in range(h)]

D = [[0] * w for _ in range(h)]

for i in range(h):

    for j in range(w):

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

            if j == 0:

                L[i][j] = 1

            else:

                L[i][j] = L[i][j-1] + 1

    for j in reversed(list(range(w))):

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

            if j == w-1:

                R[i][j] = 1

            else:

                R[i][j] = R[i][j+1] + 1

for j in range(w):

    for i in range(h):

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

            if i == 0:

                U[i][j] = 1

            else:

                U[i][j] = U[i-1][j] + 1

    for i in reversed(list(range(h))):

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

            if i == h-1:

                D[i][j] = 1

            else:

                D[i][j] = D[i+1][j] + 1

ans = 0

for i in range(h):

    for j in range(w):

        ans = max(ans, L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3)

print(ans)

h, w = list(map(int, input().split()))
S = [list(eval(input())) for _ in range(h)]
L = [[0] * w for _ in range(h)]
R = [[0] * w for _ in range(h)]
U = [[0] * w for _ in range(h)]
D = [[0] * w for _ in range(h)]
for i in range(h):
    for j in range(w):
        if S[i][j] == ".":
            if j == 0:
                L[i][j] = 1
            else:
                L[i][j] = L[i][j - 1] + 1
    for j in reversed(list(range(w))):
        if S[i][j] == ".":
            if j == w - 1:
                R[i][j] = 1
            else:
                R[i][j] = R[i][j + 1] + 1
for j in range(w):
    for i in range(h):
        if S[i][j] == ".":
            if i == 0:
                U[i][j] = 1
            else:
                U[i][j] = U[i - 1][j] + 1
    for i in reversed(list(range(h))):
        if S[i][j] == ".":
            if i == h - 1:
                D[i][j] = 1
            else:
                D[i][j] = D[i + 1][j] + 1
ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans, L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3)
print(ans)

h, w = list(map(int, input().split()))
S = [eval(input()) for _ in range(h)]
L = [[0] * w for _ in range(h)]
R = [[0] * w for _ in range(h)]
U = [[0] * w for _ in range(h)]
D = [[0] * w for _ in range(h)]
for i in range(h):
    for j in range(w):
        if S[i][j] == ".":
            if j == 0:
                L[i][j] = 1
            else:
                L[i][j] = L[i][j - 1] + 1
    for j in reversed(list(range(w))):
        if S[i][j] == ".":
            if j == w - 1:
                R[i][j] = 1
            else:
                R[i][j] = R[i][j + 1] + 1
for j in range(w):
    for i in range(h):
        if S[i][j] == ".":
            if i == 0:
                U[i][j] = 1
            else:
                U[i][j] = U[i - 1][j] + 1
    for i in reversed(list(range(h))):
        if S[i][j] == ".":
            if i == h - 1:
                D[i][j] = 1
            else:
                D[i][j] = D[i + 1][j] + 1
ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans, L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3)
print(ans)

-S = [list(eval(input())) for _ in range(h)]


Input:
s = [int(i) for i in eval(input())]

cnt = [0,0]

for i in s:

    if i==0:

        cnt[0] += 1

    else:

        cnt[1] += 1

print((min(cnt)*2))

s = eval(input())

cnt = [0,0]

cnt[0] = s.count('0')

cnt[1] = s.count('1')

print((min(cnt)*2))

s = [int(i) for i in eval(input())]
cnt = [0, 0]
for i in s:
    if i == 0:
        cnt[0] += 1
    else:
        cnt[1] += 1
print((min(cnt) * 2))

s = eval(input())
cnt = [0, 0]
cnt[0] = s.count("0")
cnt[1] = s.count("1")
print((min(cnt) * 2))

-s = [int(i) for i in eval(input())]
+s = eval(input())
-for i in s:
-    if i == 0:
-        cnt[0] += 1
-    else:
-        cnt[1] += 1
+cnt[0] = s.count("0")
+cnt[1] = s.count("1")


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

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

flag=1

for k in range(N-1):

    if p[k]>p[k+1]:

        flag=0

        break

if flag==1:

    print("YES")

    exit()

for i in range(N):

    for j in range(N):

        if i>=j:

            continue

        q=[p[i] for i in range(N)]

        q[i],q[j]=q[j],q[i]

        flag=1

        for k in range(N-1):

            if q[k]>q[k+1]:

                flag=0

                break

        if flag==1:

            print("YES")

            exit()

print("NO")

N=int(eval(input()))

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

tmp=0

for i in range(N):

    if p[i]!=i+1:

        tmp+=1

if tmp<=2:

    print("YES")

else:

    print("NO")

N = int(eval(input()))
p = [int(i) for i in input().split()]
flag = 1
for k in range(N - 1):
    if p[k] > p[k + 1]:
        flag = 0
        break
if flag == 1:
    print("YES")
    exit()
for i in range(N):
    for j in range(N):
        if i >= j:
            continue
        q = [p[i] for i in range(N)]
        q[i], q[j] = q[j], q[i]
        flag = 1
        for k in range(N - 1):
            if q[k] > q[k + 1]:
                flag = 0
                break
        if flag == 1:
            print("YES")
            exit()
print("NO")

N = int(eval(input()))
p = [int(i) for i in input().split()]
tmp = 0
for i in range(N):
    if p[i] != i + 1:
        tmp += 1
if tmp <= 2:
    print("YES")
else:
    print("NO")

-flag = 1
-for k in range(N - 1):
-    if p[k] > p[k + 1]:
-        flag = 0
-        break
-if flag == 1:
+tmp = 0
+for i in range(N):
+    if p[i] != i + 1:
+        tmp += 1
+if tmp <= 2:
-    exit()
-for i in range(N):
-    for j in range(N):
-        if i >= j:
-            continue
-        q = [p[i] for i in range(N)]
-        q[i], q[j] = q[j], q[i]
-        flag = 1
-        for k in range(N - 1):
-            if q[k] > q[k + 1]:
-                flag = 0
-                break
-        if flag == 1:
-            print("YES")
-            exit()
-print("NO")
+else:
+    print("NO")


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

def dfs(s):

    if int(s)>N:

        return 0

    else:

        if all(s.count(c)>=1 for c in "753"):

            res=1

        else:

            res=0

        for c in "753":

            res+=dfs(s+c)

        return res

print((dfs("0")))

from sys import stdin

from collections import deque

def main():

    #入力

    readline=stdin.readline

    N=int(readline())

    #dfs

    count=0

    stack=deque(["0"])

    while len(stack)>=1:

        t=stack.pop()

        for s in "357":

            now=t+s

            if int(now)>N:

                break

            if ("7" in now) and ("5" in now) and ("3" in now):

                count+=1

            stack.append(now)

    print(count)

if __name__=="__main__":

    main()

N = int(eval(input()))

def dfs(s):
    if int(s) > N:
        return 0
    else:
        if all(s.count(c) >= 1 for c in "753"):
            res = 1
        else:
            res = 0
        for c in "753":
            res += dfs(s + c)
        return res

print((dfs("0")))

from sys import stdin
from collections import deque

def main():
    # 入力
    readline = stdin.readline
    N = int(readline())
    # dfs
    count = 0
    stack = deque(["0"])
    while len(stack) >= 1:
        t = stack.pop()
        for s in "357":
            now = t + s
            if int(now) > N:
                break
            if ("7" in now) and ("5" in now) and ("3" in now):
                count += 1
            stack.append(now)
    print(count)

if __name__ == "__main__":
    main()

-        if all(s.count(c) >= 1 for c in "753"):

+            if ("7" in now) and ("5" in now) and ("3" in now):


Input:
from collections import defaultdict, deque, Counter

from heapq import heappush, heappop, heapify

import math

import bisect

import random

from itertools import permutations, accumulate, combinations, product

import sys

import string

from bisect import bisect_left, bisect_right

from math import factorial, ceil, floor

from operator import mul

from functools import reduce

sys.setrecursionlimit(2147483647)

INF = 10 ** 20

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

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

def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()

def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')

def IR(n): return [I() for i in range(n)]

def LIR(n): return [LI() for i in range(n)]

def SR(n): return [S() for i in range(n)]

def LSR(n): return [LS() for i in range(n)]

def SRL(n): return [list(S()) for i in range(n)]

def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]

mod = 1000000007

from collections import defaultdict, deque, Counter

from heapq import heappush, heappop, heapify

import math

import bisect

import random

from itertools import permutations, accumulate, combinations

import sys

import string

from bisect import bisect_left

INF = float('inf')

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

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

def LIM(): return list([int(x) - 1 for x in sys.stdin.readline().split()])

def LS(): return sys.stdin.readline().split()

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

def IR(n): return [I() for i in range(n)]

def LIR(n): return [LI() for i in range(n)]

def LIRM(n): return [LIM() for i in range(n)]

def SR(n): return [S() for i in range(n)]

def LSR(n): return [LS() for i in range(n)]

def SRL(n): return [list(S()) for i in range(n)]

mod = 1000000007

n =  I()

final_slime = sorted(LI(), reverse=True)

now_slime = [final_slime[0]]

made_or_not = [0] * (2 ** n)

made_or_not[0] = 1

for i in range(n):

    k = 0

    for j in range(len(now_slime)):

        flag = 1

        while flag:

            if k == 2 ** n:

                print('No')

                exit(0)

            if made_or_not[k] == 0 and now_slime[j] - 1 >= final_slime[k]:

                now_slime += [final_slime[k]]

                made_or_not[k] = 1

                flag = 0

            k += 1

    now_slime.sort(reverse=True)

print('Yes')

from collections import defaultdict, deque, Counter

from heapq import heappush, heappop, heapify

from math import gcd

import bisect

import random

from itertools import permutations, accumulate, combinations, product

import sys

import string

from bisect import bisect_left, bisect_right

from math import factorial, ceil, floor, gcd

from operator import mul

from functools import reduce

sys.setrecursionlimit(2147483647)

INF = 10 ** 13

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

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

def LS(): return sys.stdin.readline().rstrip().split()

def S(): return sys.stdin.readline().rstrip()

def IR(n): return [I() for i in range(n)]

def LIR(n): return [LI() for i in range(n)]

def SR(n): return [S() for i in range(n)]

def LSR(n): return [LS() for i in range(n)]

def SRL(n): return [list(S()) for i in range(n)]

def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]

mod=10**9+7

n=I()

F=sorted(LI(),reverse=True)

flg=[0]*len(F)

flg[0]=1

a=1

flg[0]=1

now=[F[0]]

for i in range(n):

    cnt=0

    for j in range(len(F)):

        if flg[j]==0 and F[j]<now[cnt]:

            cnt+=1

            flg[j]=1

            now+=[F[j]]

        if cnt==a:

            now.sort(reverse=True)

            a*=2

            break

    else:

        print("No")

        exit()

print("Yes")

from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce

sys.setrecursionlimit(2147483647)
INF = 10**20

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

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

def LS():
    return sys.stdin.buffer.readline().rstrip().decode("utf-8").split()

def S():
    return sys.stdin.buffer.readline().rstrip().decode("utf-8")

def IR(n):
    return [I() for i in range(n)]

def LIR(n):
    return [LI() for i in range(n)]

def SR(n):
    return [S() for i in range(n)]

def LSR(n):
    return [LS() for i in range(n)]

def SRL(n):
    return [list(S()) for i in range(n)]

def MSRL(n):
    return [[int(j) for j in list(S())] for i in range(n)]

mod = 1000000007
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations
import sys
import string
from bisect import bisect_left

INF = float("inf")

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

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

def LIM():
    return list([int(x) - 1 for x in sys.stdin.readline().split()])

def LS():
    return sys.stdin.readline().split()

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

def IR(n):
    return [I() for i in range(n)]

def LIR(n):
    return [LI() for i in range(n)]

def LIRM(n):
    return [LIM() for i in range(n)]

def SR(n):
    return [S() for i in range(n)]

def LSR(n):
    return [LS() for i in range(n)]

def SRL(n):
    return [list(S()) for i in range(n)]

mod = 1000000007
n = I()
final_slime = sorted(LI(), reverse=True)
now_slime = [final_slime[0]]
made_or_not = [0] * (2**n)
made_or_not[0] = 1
for i in range(n):
    k = 0
    for j in range(len(now_slime)):
        flag = 1
        while flag:
            if k == 2**n:
                print("No")
                exit(0)
            if made_or_not[k] == 0 and now_slime[j] - 1 >= final_slime[k]:
                now_slime += [final_slime[k]]
                made_or_not[k] = 1
                flag = 0
            k += 1
    now_slime.sort(reverse=True)
print("Yes")

from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from math import gcd
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gcd
from operator import mul
from functools import reduce

sys.setrecursionlimit(2147483647)
INF = 10**13

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

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

def LS():
    return sys.stdin.readline().rstrip().split()

def S():
    return sys.stdin.readline().rstrip()

def IR(n):
    return [I() for i in range(n)]

def LIR(n):
    return [LI() for i in range(n)]

def SR(n):
    return [S() for i in range(n)]

def LSR(n):
    return [LS() for i in range(n)]

def SRL(n):
    return [list(S()) for i in range(n)]

def MSRL(n):
    return [[int(j) for j in list(S())] for i in range(n)]

mod = 10**9 + 7
n = I()
F = sorted(LI(), reverse=True)
flg = [0] * len(F)
flg[0] = 1
a = 1
flg[0] = 1
now = [F[0]]
for i in range(n):
    cnt = 0
    for j in range(len(F)):
        if flg[j] == 0 and F[j] < now[cnt]:
            cnt += 1
            flg[j] = 1
            now += [F[j]]
        if cnt == a:
            now.sort(reverse=True)
            a *= 2
            break
    else:
        print("No")
        exit()
print("Yes")

-from math import factorial, ceil, floor

+from math import factorial, ceil, floor, gcd

-    return list(map(int, sys.stdin.buffer.readline().split()))

+    return list(map(int, sys.stdin.readline().split()))

-    return int(sys.stdin.buffer.readline())

-    return sys.stdin.buffer.readline().rstrip().decode("utf-8").split()

+    return sys.stdin.readline().rstrip().split()

+    return sys.stdin.readline().rstrip()

-from collections import defaultdict, deque, Counter

-from heapq import heappush, heappop, heapify

-from itertools import permutations, accumulate, combinations

-    return list(map(int, sys.stdin.readline().split()))

-    return list([int(x) - 1 for x in sys.stdin.readline().split()])

-    return sys.stdin.readline().split()

-    return sys.stdin.readline().strip()

-    return [list(S()) for i in range(n)]

-final_slime = sorted(LI(), reverse=True)

-            if made_or_not[k] == 0 and now_slime[j] - 1 >= final_slime[k]:

-                now_slime += [final_slime[k]]

+        if flg[j] == 0 and F[j] < now[cnt]:


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

task=[]

for _ in range(N):

    task.append([int(i) for i in input().split()])

task=sorted(task, key=lambda x: x[1])

spent_time1=0

spent_time2=0

for i in range(N):

    spent_time2+=task[i][0]

ans='Yes'

for i in range(N):

    spent_time1+=task[i][0]

    deadline1=task[i][1]

    if i!=0:

        spent_time2-=task[N-i][0]

    deadline2=task[N-1-i][1]

    if deadline1<spent_time1:

        ans='No'

        break

    elif deadline2<spent_time2:

        ans='No'

        break

print(ans)

N=int(eval(input()))

task=[]

for _ in range(N):

    task.append([int(i) for i in input().split()])

task=sorted(task, key=lambda x: x[1])

spent_time1=0

ans='Yes'

for i in range(N):

    spent_time1+=task[i][0]

    deadline1=task[i][1]

    if deadline1<spent_time1:

        ans='No'

        break

print(ans)

N = int(eval(input()))
task = []
for _ in range(N):
    task.append([int(i) for i in input().split()])
task = sorted(task, key=lambda x: x[1])
spent_time1 = 0
spent_time2 = 0
for i in range(N):
    spent_time2 += task[i][0]
ans = "Yes"
for i in range(N):
    spent_time1 += task[i][0]
    deadline1 = task[i][1]
    if i != 0:
        spent_time2 -= task[N - i][0]
    deadline2 = task[N - 1 - i][1]
    if deadline1 < spent_time1:
        ans = "No"
        break
    elif deadline2 < spent_time2:
        ans = "No"
        break
print(ans)

N = int(eval(input()))
task = []
for _ in range(N):
    task.append([int(i) for i in input().split()])
task = sorted(task, key=lambda x: x[1])
spent_time1 = 0
ans = "Yes"
for i in range(N):
    spent_time1 += task[i][0]
    deadline1 = task[i][1]
    if deadline1 < spent_time1:
        ans = "No"
        break
print(ans)

-spent_time2 = 0
-for i in range(N):
-    spent_time2 += task[i][0]
-    if i != 0:
-        spent_time2 -= task[N - i][0]
-    deadline2 = task[N - 1 - i][1]
-    elif deadline2 < spent_time2:
-        ans = "No"
-        break


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

class UnionFind():

    # 作りたい要素数nで初期化

    # 使用するインスタンス変数の初期化

    def __init__(self, n):

        self.n = n

        # root[x]<0ならそのノードが根かつその値が木の要素数

        # rootノードでその木の要素数を記録する

        self.root = [-1]*(n+1)

        # 木をくっつける時にアンバランスにならないように調整する

        self.rnk = [0]*(n+1)

    # ノードxのrootノードを見つける

    def Find_Root(self, x):

        if(self.root[x] < 0):

            return x

        else:

            # ここで代入しておくことで、後の繰り返しを避ける

            self.root[x] = self.Find_Root(self.root[x])

        return self.root[x]

    # 木の併合、入力は併合したい各ノード

    def Unite(self, x, y):

        # 入力ノードのrootノードを見つける

        x = self.Find_Root(x)

        y = self.Find_Root(y)

        # すでに同じ木に属していた場合

        if (x == y):

            return

        # 違う木に属していた場合rnkを見てくっつける方を決める

        #rnkが大きい方に結合

        elif (self.rnk[x] > self.rnk[y]):

            self.root[x] += self.root[y]

            self.root[y] = x

        else:

            self.root[y] += self.root[x]

            self.root[x] = y

        # rnkが同じ（深さに差がない場合）は1増やす

        if(self.rnk[x] == self.rnk[y]):

            self.rnk[y] += 1

    # xとyが同じグループに属するか判断

    def isSameGroup(self, x, y):

        return self.Find_Root(x) == self.Find_Root(y)

    # ノードxが属する木のサイズを返す

    def Count(self, x):

        return -self.root[self.Find_Root(x)]

uni=UnionFind(N)

for i in range(M):

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

    a-=1

    b-=1

    uni.Unite(a,b)

ans=0

for i in range(N):

    ans=max(ans, uni.Count(i))

print(ans)

class UnionFind():

    # 作りたい要素数nで初期化

    # 使用するインスタンス変数の初期化

    def __init__(self, n):

        self.n = n

        # root[x]<0ならそのノードが根かつその値が木の要素数

        # rootノードでその木の要素数を記録する

        self.root = [-1]*(n+1)

        # 木をくっつける時にアンバランスにならないように調整する

        self.rnk = [0]*(n+1)

    # ノードxのrootノードを見つける

    def Find_Root(self, x):

        if(self.root[x] < 0):

            return x

        else:

            # ここで代入しておくことで、後の繰り返しを避ける

            self.root[x] = self.Find_Root(self.root[x])

        return self.root[x]

    # 木の併合、入力は併合したい各ノード

    def Unite(self, x, y):

        # 入力ノードのrootノードを見つける

        x = self.Find_Root(x)

        y = self.Find_Root(y)

        # すでに同じ木に属していた場合

        if (x == y):

            return

        # 違う木に属していた場合rnkを見てくっつける方を決める

        #rnkが大きい方に結合

        elif (self.rnk[x] > self.rnk[y]):

            self.root[x] += self.root[y]

            self.root[y] = x

        else:

            self.root[y] += self.root[x]

            self.root[x] = y

        # rnkが同じ（深さに差がない場合）は1増やす

        if(self.rnk[x] == self.rnk[y]):

            self.rnk[y] += 1

    # xとyが同じグループに属するか判断

    def isSameGroup(self, x, y):

        return self.Find_Root(x) == self.Find_Root(y)

    # ノードxが属する木のサイズを返す

    def Count(self, x):

        return -self.root[self.Find_Root(x)]

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

uni=UnionFind(N)

for i in range(M):

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

    uni.Unite(a-1,b-1)

ans=0

for i in range(N):

    ans=max(ans, uni.Count(i))

print(ans)

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

class UnionFind:
    # 作りたい要素数nで初期化
    # 使用するインスタンス変数の初期化
    def __init__(self, n):
        self.n = n
        # root[x]<0ならそのノードが根かつその値が木の要素数
        # rootノードでその木の要素数を記録する
        self.root = [-1] * (n + 1)
        # 木をくっつける時にアンバランスにならないように調整する
        self.rnk = [0] * (n + 1)

    # ノードxのrootノードを見つける
    def Find_Root(self, x):
        if self.root[x] < 0:
            return x
        else:
            # ここで代入しておくことで、後の繰り返しを避ける
            self.root[x] = self.Find_Root(self.root[x])
        return self.root[x]

    # 木の併合、入力は併合したい各ノード
    def Unite(self, x, y):
        # 入力ノードのrootノードを見つける
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        # すでに同じ木に属していた場合
        if x == y:
            return
        # 違う木に属していた場合rnkを見てくっつける方を決める
        # rnkが大きい方に結合
        elif self.rnk[x] > self.rnk[y]:
            self.root[x] += self.root[y]
            self.root[y] = x
        else:
            self.root[y] += self.root[x]
            self.root[x] = y
        # rnkが同じ（深さに差がない場合）は1増やす
        if self.rnk[x] == self.rnk[y]:
            self.rnk[y] += 1

    # xとyが同じグループに属するか判断
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    # ノードxが属する木のサイズを返す
    def Count(self, x):
        return -self.root[self.Find_Root(x)]

uni = UnionFind(N)
for i in range(M):
    a, b = list(map(int, input().split()))
    a -= 1
    b -= 1
    uni.Unite(a, b)
ans = 0
for i in range(N):
    ans = max(ans, uni.Count(i))
print(ans)

class UnionFind:
    # 作りたい要素数nで初期化
    # 使用するインスタンス変数の初期化
    def __init__(self, n):
        self.n = n
        # root[x]<0ならそのノードが根かつその値が木の要素数
        # rootノードでその木の要素数を記録する
        self.root = [-1] * (n + 1)
        # 木をくっつける時にアンバランスにならないように調整する
        self.rnk = [0] * (n + 1)

    # ノードxのrootノードを見つける
    def Find_Root(self, x):
        if self.root[x] < 0:
            return x
        else:
            # ここで代入しておくことで、後の繰り返しを避ける
            self.root[x] = self.Find_Root(self.root[x])
        return self.root[x]

    # 木の併合、入力は併合したい各ノード
    def Unite(self, x, y):
        # 入力ノードのrootノードを見つける
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        # すでに同じ木に属していた場合
        if x == y:
            return
        # 違う木に属していた場合rnkを見てくっつける方を決める
        # rnkが大きい方に結合
        elif self.rnk[x] > self.rnk[y]:
            self.root[x] += self.root[y]
            self.root[y] = x
        else:
            self.root[y] += self.root[x]
            self.root[x] = y
        # rnkが同じ（深さに差がない場合）は1増やす
        if self.rnk[x] == self.rnk[y]:
            self.rnk[y] += 1

    # xとyが同じグループに属するか判断
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    # ノードxが属する木のサイズを返す
    def Count(self, x):
        return -self.root[self.Find_Root(x)]

N, M = list(map(int, input().split()))
uni = UnionFind(N)
for i in range(M):
    a, b = list(map(int, input().split()))
    uni.Unite(a - 1, b - 1)
ans = 0
for i in range(N):
    ans = max(ans, uni.Count(i))
print(ans)

-N, M = list(map(int, input().split()))
+N, M = list(map(int, input().split()))
-    a -= 1
-    b -= 1
-    uni.Unite(a, b)
+    uni.Unite(a - 1, b - 1)


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

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

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

def main():

    mod=10**9+7

    T=I()

    M=60

    def pipo(x):

        cnt=0

        for i in range(M):

            if x==0:

                return cnt

            else:

                x=x//2

                cnt+=1

    for _ in range(T):

        N=I()

        A=LI()

        S=list(eval(input()))

        #後ろから見ていき，S=0の数だけで作れない数が(S=1の時に)出てきたらNG

        Vec=[]

        flag=1

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

            #print(i,S[i])

            if S[i]=="0":

                if Vec==[]:

                    Vec.append((A[i],pipo(A[i])))

                else:

                    now=A[i]

                    p=pipo(A[i])

                    for v in Vec:

                        if v[1]==p:

                            now=now^v[0]

                            p=pipo(now)

                    if now!=0:

                        Vec.append((now,pipo(now)))

                        Vec.sort(reverse=True)

            else:

                #print(Vec)

                now=A[i]

                for v in Vec:

                    if v[1]==pipo(now):

                        now=now^v[0]

                if now!=0:

                    flag=0

        if flag:

            print((0))

        else:

            print((1))

main()

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

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

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

def main():

    mod=10**9+7

    T=I()

    M=60#60桁まで

    #S=1となる全ての数字が，それより後ろのS=0のもので構成できれば良い（それらを組み合わせても，S=0側も同じ組み合わせ方で対応できる）．

    #S=0のものを基底ベクトル(ぽいもの)として持っておく

    #このとき行列の標準形を構成するベクトルをイメージ

    #上位桁が等しいものがある場合，それとxorしておけば良い，これによって上位桁が同じ基底ベクトル(ぽいもの)がなくなる

    def pipo(x):

        #最上位桁が何処か

        cnt=0

        for i in range(M):

            if x==0:

                return cnt

            else:

                x=x//2

                cnt+=1

    for _ in range(T):

        N=I()

        A=LI()

        S=list(eval(input()))

        #後ろから見ていき，S=1の時に「S=0の数だけで作れない数」が出てきたらNG

        Vec=[]#基底管理

        flag=1#ダメなら0になる

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

            #print(i,S[i])

            if S[i]=="0":

                now=A[i]

                p=pipo(A[i])

                for v in Vec:

                    if v[1]==p:

                        now=now^v[0]

                        p=pipo(now)

                if now!=0:

                    Vec.append((now,pipo(now)))

                    Vec.sort(reverse=True)

            else:

                #print(Vec)

                now=A[i]

                for v in Vec:

                    if v[1]==pipo(now):

                        now=now^v[0]

                if now!=0:

                    flag=0

        if flag:

            print((0))

        else:

            print((1))

main()

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

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

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

def main():
    mod = 10**9 + 7
    T = I()
    M = 60

    def pipo(x):
        cnt = 0
        for i in range(M):
            if x == 0:
                return cnt
            else:
                x = x // 2
                cnt += 1

    for _ in range(T):
        N = I()
        A = LI()
        S = list(eval(input()))
        # 後ろから見ていき，S=0の数だけで作れない数が(S=1の時に)出てきたらNG
        Vec = []
        flag = 1
        for i in range(N - 1, -1, -1):
            # print(i,S[i])
            if S[i] == "0":
                if Vec == []:
                    Vec.append((A[i], pipo(A[i])))
                else:
                    now = A[i]
                    p = pipo(A[i])
                    for v in Vec:
                        if v[1] == p:
                            now = now ^ v[0]
                            p = pipo(now)
                    if now != 0:
                        Vec.append((now, pipo(now)))
                        Vec.sort(reverse=True)
            else:
                # print(Vec)
                now = A[i]
                for v in Vec:
                    if v[1] == pipo(now):
                        now = now ^ v[0]
                if now != 0:
                    flag = 0
        if flag:
            print((0))
        else:
            print((1))

main()

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

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

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

def main():
    mod = 10**9 + 7
    T = I()
    M = 60  # 60桁まで
    # S=1となる全ての数字が，それより後ろのS=0のもので構成できれば良い（それらを組み合わせても，S=0側も同じ組み合わせ方で対応できる）．
    # S=0のものを基底ベクトル(ぽいもの)として持っておく
    # このとき行列の標準形を構成するベクトルをイメージ
    # 上位桁が等しいものがある場合，それとxorしておけば良い，これによって上位桁が同じ基底ベクトル(ぽいもの)がなくなる
    def pipo(x):
        # 最上位桁が何処か
        cnt = 0
        for i in range(M):
            if x == 0:
                return cnt
            else:
                x = x // 2
                cnt += 1

    for _ in range(T):
        N = I()
        A = LI()
        S = list(eval(input()))
        # 後ろから見ていき，S=1の時に「S=0の数だけで作れない数」が出てきたらNG
        Vec = []  # 基底管理
        flag = 1  # ダメなら0になる
        for i in range(N - 1, -1, -1):
            # print(i,S[i])
            if S[i] == "0":
                now = A[i]
                p = pipo(A[i])
                for v in Vec:
                    if v[1] == p:
                        now = now ^ v[0]
                        p = pipo(now)
                if now != 0:
                    Vec.append((now, pipo(now)))
                    Vec.sort(reverse=True)
            else:
                # print(Vec)
                now = A[i]
                for v in Vec:
                    if v[1] == pipo(now):
                        now = now ^ v[0]
                if now != 0:
                    flag = 0
        if flag:
            print((0))
        else:
            print((1))

main()

+    # S=1となる全ての数字が，それより後ろのS=0のもので構成できれば良い（それらを組み合わせても，S=0側も同じ組み合わせ方で対応できる）．

+    # S=0のものを基底ベクトル(ぽいもの)として持っておく

+    # このとき行列の標準形を構成するベクトルをイメージ

+    # 上位桁が等しいものがある場合，それとxorしておけば良い，これによって上位桁が同じ基底ベクトル(ぽいもの)がなくなる

+        # 最上位桁が何処か

-        # 後ろから見ていき，S=0の数だけで作れない数が(S=1の時に)出てきたらNG

+        # 後ろから見ていき，S=1の時に「S=0の数だけで作れない数」が出てきたらNG

-                    Vec.append((A[i], pipo(A[i])))

-                            now = now ^ v[0]

-                            p = pipo(now)

-                        Vec.append((now, pipo(now)))

-                        Vec.sort(reverse=True)

+                        now = now ^ v[0]

+                    Vec.append((now, pipo(now)))

+                    Vec.sort(reverse=True)


Input:
# ABC051B - Sum of Three Integers

k, s = list(map(int, input().rstrip().split()))

count = 0

for i in range(k + 1):

    for j in range(k + 1):

        if 0 <= s - i - j <= k:

            count += 1

print(count)

# ABC051B - Sum of Three Integers

def main():

    K, S = tuple(map(int, input().split()))

    ans = 0

    for x in range(K + 1):

        for y in range(K + 1):

            z = S - x - y

            if z < 0:

                break

            if z <= K:

                ans += 1

    print(ans)

if __name__ == "__main__":

    main()

-k, s = list(map(int, input().rstrip().split()))

+    K, S = tuple(map(int, input().split()))


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

xx = (100 * n // 108) + 1

# print(xx)

for x in range(xx + 1):

    nn = int(x * 1.08 // 1)

    if n == nn:

        print(x)

        exit(0)

print(':(')

import math

n = int(eval(input()))

x = math.ceil(n / 1.08)

if n == int(x * 1.08):

  print(x)

else:

  print(':(')

n = int(eval(input()))
xx = (100 * n // 108) + 1
# print(xx)
for x in range(xx + 1):
    nn = int(x * 1.08 // 1)
    if n == nn:
        print(x)
        exit(0)
print(":(")

import math

n = int(eval(input()))
x = math.ceil(n / 1.08)
if n == int(x * 1.08):
    print(x)
else:
    print(":(")

+import math
+
-xx = (100 * n // 108) + 1
-# print(xx)
-for x in range(xx + 1):
-    nn = int(x * 1.08 // 1)
-    if n == nn:
-        print(x)
-        exit(0)
-print(":(")
+x = math.ceil(n / 1.08)
+if n == int(x * 1.08):
+    print(x)
+else:
+    print(":(")


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

from collections import deque

d=deque()

for i in a:

    if i=="0" or i=="1":

        d.append(i)

    else:

        if len(d)==0:

            continue

        d.pop()

print((''.join(list(d))))

s=list(eval(input()))

from collections import deque

d=deque()

for i in s:

    if i=="0":

        d.append(i)

    elif i=="1":

        d.append(i)

    else:

        if len(d)>0:

            d.pop()

print((''.join(list(d))))

a = list(eval(input()))
from collections import deque

d = deque()
for i in a:
    if i == "0" or i == "1":
        d.append(i)
    else:
        if len(d) == 0:
            continue
        d.pop()
print(("".join(list(d))))

s = list(eval(input()))
from collections import deque

d = deque()
for i in s:
    if i == "0":
        d.append(i)
    elif i == "1":
        d.append(i)
    else:
        if len(d) > 0:
            d.pop()
print(("".join(list(d))))

-a = list(eval(input()))
+s = list(eval(input()))
-for i in a:
-    if i == "0" or i == "1":
+for i in s:
+    if i == "0":
+        d.append(i)
+    elif i == "1":
-        if len(d) == 0:
-            continue
-        d.pop()
+        if len(d) > 0:
+            d.pop()


Input:
import sys

input = sys.stdin.readline

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

h = []

for _ in range(N):

  h.append(int(eval(input())))

h.sort()

def explosive(x):

  c = 0

  for i in range(N):

    if h[i] > x * B:

      c += -(-(h[i] - x * B) // (A - B))

  if c <= x: return True

  else: return False

ng = 0

ok = 10 ** 9

m = 0

while ok - ng > 1:

  m = (ng + ok) // 2

  #print(m, explosive(m))

  if explosive(m):

    ok = m

  else:

    ng = m

print(ok)

import sys

input = sys.stdin.readline

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

h = [0] * N

for i in range(N): h[i] = int(eval(input()))

h.sort()

def check(x):

  t = [h[i] - x * B for i in range(N)]

  for i in range(N):

    if t[i] > 0:

      x -= -(-t[i] // (A - B))

      if x < 0: return False

  return x >= 0

ok = 10 ** 9

ng = 0

while ok - ng > 1:

  m = (ok + ng) // 2

  if check(m): ok = m

  else: ng = m

print(ok)

import sys

input = sys.stdin.readline
N, A, B = list(map(int, input().split()))
h = []
for _ in range(N):
    h.append(int(eval(input())))
h.sort()

def explosive(x):
    c = 0
    for i in range(N):
        if h[i] > x * B:
            c += -(-(h[i] - x * B) // (A - B))
    if c <= x:
        return True
    else:
        return False

ng = 0
ok = 10**9
m = 0
while ok - ng > 1:
    m = (ng + ok) // 2
    # print(m, explosive(m))
    if explosive(m):
        ok = m
    else:
        ng = m
print(ok)

import sys

input = sys.stdin.readline
N, A, B = list(map(int, input().split()))
h = [0] * N
for i in range(N):
    h[i] = int(eval(input()))
h.sort()

def check(x):
    t = [h[i] - x * B for i in range(N)]
    for i in range(N):
        if t[i] > 0:
            x -= -(-t[i] // (A - B))
            if x < 0:
                return False
    return x >= 0

ok = 10**9
ng = 0
while ok - ng > 1:
    m = (ok + ng) // 2
    if check(m):
        ok = m
    else:
        ng = m
print(ok)

+    t = [h[i] - x * B for i in range(N)]


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

a,M,d=1,10**9+7,[1]

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

  d.append(((m-n+i-1)*d[i-1]+(i-1)*d[i-2])%M)

  a=a*(m-i+1)%M

print((a*d[-1]%M))

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

a,M,d=1,10**9+7,[1]

for i in range(n):

  d.append(((m-n+i)*d[i]+i*d[i-1])%M)

  a=a*(m-i)%M

print((a*d[-1]%M))

n, m = list(map(int, input().split()))
a, M, d = 1, 10**9 + 7, [1]
for i in range(n):
    d.append(((m - n + i) * d[i] + i * d[i - 1]) % M)
    a = a * (m - i) % M
print((a * d[-1] % M))


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

b = [[int(eval(input())), False]for i in range(a)]

c = 1

d = 0

while True:

    d += 1

    if b[c-1][0] == 2:

        print(d)

        exit()

    else:

        b[c-1][1] = not b[c-1][1]

        if b[c-1][1]:

            c = b[c-1][0]

        else:

            print((-1))

            exit()

a = int(eval(input()))

b = [int(eval(input())) for _ in range(a)]

c = 1

d = 0

e = {}

while True:

    d += 1

    if b[c-1] == 2:

        print(d)

        exit()

    else:

        if (c-1) not in e:

            e.setdefault((c-1), "")

        else:

            print((-1))

            exit()

        c = b[c - 1]

a = int(eval(input()))
b = [[int(eval(input())), False] for i in range(a)]
c = 1
d = 0
while True:
    d += 1
    if b[c - 1][0] == 2:
        print(d)
        exit()
    else:
        b[c - 1][1] = not b[c - 1][1]
        if b[c - 1][1]:
            c = b[c - 1][0]
        else:
            print((-1))
            exit()

a = int(eval(input()))
b = [int(eval(input())) for _ in range(a)]
c = 1
d = 0
e = {}
while True:
    d += 1
    if b[c - 1] == 2:
        print(d)
        exit()
    else:
        if (c - 1) not in e:
            e.setdefault((c - 1), "")
        else:
            print((-1))
            exit()
        c = b[c - 1]

-b = [[int(eval(input())), False] for i in range(a)]

+b = [int(eval(input())) for _ in range(a)]