Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

n, m = map(int, input().split())
list_open = []
for i in range(m):
  list_open.append(list((int(i) for i in input().split())))
dict_open = {}
for i in range(m):
  for j in range(list_open[i][0], list_open[i][1] + 1):
    try:
      dict_open[j] += 1
      if dict_open[j] < i:
        del dict_open[j]
    except:
      if i == 0:
      	dict_open[j] = 1
print(list(dict_open.values()).count(m))

### FIXED CODE ###

n, m = map(int, input().split())
min_num = 0
max_num = 10**5
           
for i in range(m):
  min_temp, max_temp = map(int, input().split())
  if min_temp > min_num:
    min_num = min_temp
  if max_temp < max_num:
    max_num = max_temp
print(max(max_num - min_num + 1, 0))
### BUGGY CODE ###

from heapq import heappush, heappop

x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

A = 10 ** 9
B = 10 ** 6
C = 10 ** 3

ans = 0

h = []

s = [[[0 for _ in range(z+1)] for _ in range(y+1)] for _ in range(x+1)]

t = a[0] + b[0] + c[0]

s[0][0][0] = 1

heappush(h, - t * A)

for _ in range(k):
    temp = - heappop(h)
    r = temp % C
    temp //= C
    q = temp % C
    temp //= C
    p = temp % C
    print(temp // C)
    if p < x-1 and s[p+1][q][r] == 0:
        heappush(h, - ((a[p+1] + b[q] + c[r]) * A + (p+1) * B + q * C + r))
        s[p + 1][q][r] = 1
    if q < y-1 and s[p][q+1][r] == 0:
        heappush(h, - ((a[p] + b[q+1] + c[r]) * A + p * B + (q+1) * C + r))
        s[p][q + 1][r] = 1
    if r < z-1 and s[p][q][r+1] == 0:
        heappush(h, - ((a[p] + b[q] + c[r+1]) * A + p * B + q * C + r + 1))
        s[p][q][r + 1] = 1




### FIXED CODE ###

x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ab = []

for s in a:
    for t in b:
       ab.append(s + t)

ab.sort(reverse=True)
c.sort(reverse=True)

ans = []

for i in range(min(k, len(ab))):
    for u in c:
        ans.append(ab[i] + u)

ans.sort(reverse=True)

for i in range(k):
    print(ans[i])
### BUGGY CODE ###

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

d = [[False]*N for _ in range(N)]
cnt = 0
for i in range(N):
  j = S[i] - 1
  d[i][j] = True
  if d[j][i]:
    cnt += 1
  
print(cnt)
         
        

### FIXED CODE ###

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

d = {}
cnt = 0
for i in range(N):
  j = S[i] - 1
  d[i] = j
  if j in d:
    if d[j] == i: 
      cnt += 1
  
print(cnt)
### BUGGY CODE ###

N,T = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
ind = 0
rieki = []
if N == 2:
    print(1)
    exit()
sairi = 0
while True:
    ma = max(a[ind+1:N])
    kioku = ind+1
    ind = a.index(ma)
    if kioku != ind:
        mi = min(a[kioku:ind])
        if ma - mi > sairi:
            sairi = ma- mi
            ans = 1 
        elif ma - mi == sairi:
            ans += 1 
    if ind == N-1:
        break
print(ans)

### FIXED CODE ###

N,T = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
ans = []
mi = 10**9
for i in range(N):
    mi = min(mi,a[i])
    ans.append(a[i]-mi)
print(ans.count(max(ans)))
### BUGGY CODE ###

from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
AtoZ = [chr(i) for i in range(65,65+26)]
atoz = [chr(i) for i in range(97,97+26)]

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

N = int(input())

lines = defaultdict(set)

for i in range(N-1):
	a,b,c = inpl() #a -> b コスト:c の経路
	lines[a].add((b,c))
	lines[b].add((a,c))

Q,s = inpl()

weight = [-1]*(N+1)
weight[s] = 0

q = [[0,s]]
heapq.heapify(q)

while q:
	w0,s = heapq.heappop(q)
	for line in list(lines[s]):
		t = line[0]
		w = w0 + line[1]
		if weight[t] == -1 or weight[t] > w: #未探索orより小さい
			heapq.heappush(q, [w,t])
			weight[t] = w

for i in range(Q):
	x,y = inpl()
	print(weight[x]+weight[y])


### FIXED CODE ###

from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
AtoZ = [chr(i) for i in range(65,65+26)]
atoz = [chr(i) for i in range(97,97+26)]

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

N = int(input())

lines = defaultdict(set)
for i in range(N-1):
	a,b,c = inpl()
	a -= 1
	b -= 1
	lines[a].add((b,c))
	lines[b].add((a,c))

Q,s = inpl()
s -= 1
ss = [-1]*N
ss[s] = 0

def check(a,w):
	global ss
	for b,c in lines[a]:
		if ss[b] == -1:
			ss[b] = w + c
			check(b,w+c)

check(s,0)

for i in range(Q):
	x,y = inpl()
	print(ss[x-1]+ss[y-1])
### BUGGY CODE ###

import sys
import math
import itertools
import collections

def solve(N,M,X,C,A):
    lis = [i for i in range(N)]
    ans = []
    for k,_ in enumerate(lis,1):
        for c in itertools.permutations(lis,r=k):
            tmp = 0
            dic = {key:0 for key in range(M)}
            for i in set(c):
                tmp += C[i]
                for n,a in enumerate(A[i]):
                    dic[n] += a
            for m in range(M):
                if(dic[m] < X):
                    break
            else:
                ans.append(tmp)
    return min(ans) if(ans != []) else -1
def main():
    N,M,X = map(int,input().split())
    C = []
    A = []
    for _ in range(N):
        tmp = list(map(int,input().split()))
        C.append(tmp.pop(0))
        A.append(tmp)
    # solve()
    print(solve(N,M,X,C,A))

if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
import math
import itertools
import collections

def solve(N,M,X,C,A):
    lis = [i for i in range(N)]
    ans = []
    for k,_ in enumerate(lis,1):
        for c in itertools.combinations(lis,r=k):
            tmp = 0
            dic = {key:0 for key in range(M)}
            for i in set(c):
                tmp += C[i]
                for n,a in enumerate(A[i]):
                    dic[n] += a
            for m in range(M):
                if(dic[m] < X):
                    break
            else:
                ans.append(tmp)
    return min(ans) if(ans != []) else -1
def main():
    N,M,X = map(int,input().split())
    C = []
    A = []
    for _ in range(N):
        tmp = list(map(int,input().split()))
        C.append(tmp.pop(0))
        A.append(tmp)
    # solve()
    print(solve(N,M,X,C,A))

if __name__ == "__main__":
    main()
### BUGGY CODE ###

from itertools import product

def sol():
    N = int(input())
    XYP = [tuple(map(int, input().split())) for _ in range(N)]
    X = [x for x, _, _ in XYP]
    Y = [y for _, y, _ in XYP]
    INF = 10**18

    def calcCost(AP, A):
        ret = [[INF] * N for _ in range(1 << N)]
        for state in range(1 << N):
            useA = [a for i, a in enumerate(A) if (state & (1 << i)) != 0]
            for i, (a, p) in enumerate(AP):
                cost = abs(a)
                for z in useA:
                    cost = min(cost, abs(a - z))
                ret[state][i] = cost * p
        return ret

    costX = calcCost([(x, p) for x, _, p in XYP], X)
    costY = calcCost([(y, p) for _, y, p in XYP], Y)

    def makeState(state, sign):
        ret = 0
        for s in state[::-1]:
            ret <<= 1
            if s == sign:
                ret |= 1
        return ret

    ans = [INF] * (N + 1)
    for state in product((0, 1, 2), repeat=N):
        stateX = makeState(state, 1)
        stateY = makeState(state, 2)

        cost = 0
        for i in range(N):
            cost += min(costX[stateX][i], costY[stateY][i])

        M = N - state.count(0)
        if ans[M] > cost:
            ans[M] = cost

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

sol()

### FIXED CODE ###

import sys
input = sys.stdin.buffer.readline
from numba import njit
import numpy as np
INF = 10**18

@njit('(i8, i8[:,:])')
def solve(N, XYP):
    X = XYP[:, 0]
    Y = XYP[:, 1]

    def calcCost(sign, A):
        ret = np.ones((1 << N, N), dtype=np.int64) * INF
        for state in range(1 << N):
            useA = [a for i, a in enumerate(A) if (state & (1 << i)) != 0]
            for i in range(N):
                xyp = XYP[i]
                cost = abs(xyp[sign])
                for z in useA:
                    cost = min(cost, abs(xyp[sign] - z))
                ret[state][i] = cost * xyp[2]
        return ret

    costX = calcCost(0, X)
    costY = calcCost(1, Y)
    ans = np.ones(N + 1, dtype=np.int64) * INF

    for state in range(pow(3, N)):
        stateX = 0
        stateY = 0
        M = N
        for _ in range(N):
            state, r = divmod(state, 3)
            stateX <<= 1
            stateY <<= 1
            if r == 0: M -= 1
            if r == 1: stateX |= 1
            if r == 2: stateY |= 1

        cx, cy = costX[stateX], costY[stateY]
        cost = 0
        for i in range(N):
            cost += min(cx[i], cy[i])
        ans[M] = min(ans[M], cost)

    for a in ans:
        print(a)

def sol():
    N = int(input())
    XYP = np.asarray([list(map(int, input().split())) for _ in range(N)])
    solve(N, XYP)

sol()
### BUGGY CODE ###

A, B = map(int, input().split())
ans = 0
for i in range(B - A + 1):
    ans = A + i ^ ans
print(int(ans))


### FIXED CODE ###

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

# 0~B → b
# 0~A-1 → a
# A~B → c　とすると
# a^c = b
#c = a^b (両辺^a)
# 0から並べると、4個置きにXORの累積が0になる
B_ans = 0
for i in range(B % 4+1):
    B_ans = B_ans ^ (B - i)
    # print(bin(B-i))
A_ans = 0
for i in range((A - 1) % 4 + 1):
    # print(bin(A-i))
    A_ans = A_ans ^ (A-1 - i)
#print(A_ans, B_ans)
print(A_ans ^ B_ans)
### BUGGY CODE ###

# 入力
S = input()
Q = int(input())

counter = 0

for i in range(Q):
    # i+1 回目のinput
    proc = input().split()

    if proc[0] == "1":
        counter += 1
    else:
        # 先頭に文字列を足す場合
        if (counter%2 == 0 and proc[1] == "1") or (counter%2 == 1 and proc[1] == "2"):
            S = proc[2] + S
        else:
            S = S + proc[2]

if counter%2 == 0:
    print(S)
else:
    print(S[::-1])



### FIXED CODE ###

#!/usr/bin/python
# -*- coding: utf-8 -*-

# 入力はstringで入る．
# intにしたければ int(input())
# floatで受け取ると 1.0 になる．

# 入力
S = input()
Q = int(input())

Change = " "
counter = 0

for i in range(Q):
    # i+1 回目のinput
    proc = input().split()

    if proc[0] == "1":
        counter += 1
    else:
        # 先頭に文字列を足す場合
        if (counter%2 == 0 and proc[1] == "1") or (counter%2 == 1 and proc[1] == "2"):
            Change = proc[2] + Change
        else:
            Change = Change + proc[2]

if counter%2 == 0:
    print(Change.replace(" ",S))
else:
    print(Change.replace(" ",S)[::-1])
### BUGGY CODE ###

import math

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

movableFlag = False

for x in range(X):
	y = X-x*2
	if x*2+y*1==X and x*1+y*2==Y:
		movableFlag = True
		break
	
if movableFlag:
	if x==0 or y==0:
		print(1)
	else:
		print(math.factorial(X-1) // (math.factorial(x) // math.factorial((X-1)-x)))
else:
	print(0)

### FIXED CODE ###

# (+1,+2)をn回，(+2,+1)をm回とすると
#  n + 2m = X
# 2n +  m = Y でn,mが求まる．
# このとき答えは(n+m)Cn通り

def combination(n,r):
	"""
    高速な組み合わせの計算．
	nCrは必ず整数になるため分母を全部約分で1にしてから残った分子の積を求める．
	[参考]https://kadzus.hatenadiary.org/entry/20081211/1229023326
    """

	if n-r < r: r = n-r
	if r == 0: return 1
	if r == 1: return int(n)

	numerator = [i+1 for i in range(n-r, n)]
	denominator = [i+1 for i in range(r)]

	for p in range(2,r+1):
		pivot = denominator[p-1]
		if pivot > 1:
			offset = (n-r)%p
			for k in range(p-1, r, p):
				numerator[k-offset] /= pivot
				denominator[k] /= pivot
	
	ans = 1
	for i in range(r):
		if numerator[i] > 1:
			ans *= numerator[i]
			ans %= 1e9+7
	
	return int(ans)

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

if (X+Y)%3 != 0:
	ans = 0
else:
	n = int((2*Y-X)/3)
	m = int(Y-2*n)
	if n<0 or m<0:
		ans = 0
	else:
		ans = combination(n+m, n)

print(ans)
### BUGGY CODE ###

n, m = map(int,input().split())
 
l = [""] * m

for i in range(m):
    s,t = map(int,input().split())
    if i == 0:
        ans2 = [s,t+1]
    try:
        ans2 = [j for j in range(max(min(ans2),s),min(max(ans2)+1,t+1)) if s <= j <= t]
    except:
        break


print(len(ans2))


### FIXED CODE ###

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

left_max = -1
right_min = n+1

for i in range(m):
    s,t = map(int,input().split())
    left_max = max(left_max,s)
    right_min = min(right_min, t)
    
print(max(0, right_min - left_max +1))
### BUGGY CODE ###

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

# In[8]:


import numpy as np


# In[ ]:


N, K, Q = map(int, input().split())
As = [int(input()) for i in range(Q)]
"""
6 3 4
3
1
3
2
"""


# In[11]:


points = np.array([K]*N)
args = np.arange(1, N+1)


# In[13]:


for i in range(Q):
    #points[args!= int(input())] -= 1
    points[args != As[i]] -= 1


# In[14]:


#print(points)


# In[16]:


for b in points >= 1:
    if b:
        print('Yes')
    else:
        print('No')


# In[ ]:






### FIXED CODE ###

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

# In[8]:


import numpy as np


# In[ ]:


N, K, Q = map(int, input().split())
As = [int(input()) for i in range(Q)]
"""
6 3 4
3
1
3
2
"""


# In[17]:


#points = np.array([K]*N)
points = np.array([0]*N)
args = np.arange(1, N+1)


# In[18]:


for i in range(Q):
    #points[args!= int(input())] -= 1
    points[As[i]-1] += 1


# In[22]:


points = points-Q+K


# In[23]:


for b in points >= 1:
    if b:
        print('Yes')
    else:
        print('No')


# In[ ]:
### BUGGY CODE ###

import sys

n = int(sys.stdin.readline())
a_list = [int(x) for x in sys.stdin.readlines()]
a_list_index = list(set(a_list))
count = 0
for i in a_list_index:
    if a_list.count(i) % 2 == 0:
        continue
    else:
        count += 1

print(count)


### FIXED CODE ###

import sys
import collections

n = int(sys.stdin.readline())
a_list = [int(x) for x in sys.stdin.readlines()]
a_list_counter = collections.Counter(a_list)
count = 0
for i in a_list_counter:
    if a_list_counter[i] % 2 != 0:
        count += 1
    else:
        continue
print(count)
### BUGGY CODE ###

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

N,Q = map(int,input().split())
AB = [[int(x) for x in input().split()] for _ in range(N-1)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]

graph = [[] for _ in range(N+1)]
for a,b in AB:
    graph[a].append(b)
    graph[b].append(a)

value = [0] * (N+1)
for p,x in PX:
    value[p] += x

def dfs(v,parent,add):
    value[v] += add
    for x in graph[v]:
        if x == parent:
            continue
        dfs(x,v,value[v])

dfs(1,0,0)

answer = ' '.join(map(str,value[1:]))
print(answer)


### FIXED CODE ###

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

N,Q = map(int,input().split())
AB = [[int(x) for x in input().split()] for _ in range(N-1)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]

graph = [[] for _ in range(N+1)]
for a,b in AB:
    graph[a].append(b)
    graph[b].append(a)

value = [0] * (N+1)
for p,x in PX:
    value[p] += x

def dfs(v,parent,add):
    value[v] += add
    for x in graph[v]:
        if x == parent:
            continue
        dfs(x,v,value[v])

dfs(1,0,0)

answer = ' '.join(map(str,value[1:]))
print(answer)
### BUGGY CODE ###


def solve(N,S,A):
    dp = [[0]*(S+1) for _ in range(N+1)]
    dp[0][0] = 1
    mod = 998244353
    for i, a in enumerate(A, 1):
        for s in range(S+1):
            if s-a >= 0:
                dp[i][s] = (dp[i-1][s] * 2 + dp[i-1][s-a]) % mod
            else:
                dp[i][s] = dp[i-1][s] * 2 % mod
    print(dp[N][S])

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


### FIXED CODE ###


def solve(N,S,A):
    dp = [[0]*(S+1) for _ in range(N+1)]
    dp[0][0] = 1
    mod = 998244353
    for i, a in enumerate(A, 1):
        for s in range(S+1):
            if s-a >= 0:
                dp[i][s] = (dp[i-1][s] * 2 + dp[i-1][s-a]) % mod
            else:
                dp[i][s] = dp[i-1][s] * 2 % mod
    print(dp[N][S])

N, S = map(int, input().split())
A = list(map(int, input().split()))
solve(N,S,A)
### BUGGY CODE ###

N = int(input())
P = input().split()
counter = 0
for i in range(N):
    k = i+1
    for j in range(k):
        if int(P[i]) > int(P[j]):
            break
    if (i == j ):
        counter += 1
print(counter)


### FIXED CODE ###

N = int(input())
P = input().split()
counter = 0
m = N
for p in P:
    if int(m) >= int(p):
        counter +=1
        m = p
print(counter)
### BUGGY CODE ###

def LI():return list(map(int,input().split()))
def yes():print("Yes")
def no():print("No")
from collections import deque
n,m=LI()
edge=[[]*n for i in range(n)]
for i in range(m):
    a,b=LI()
    a-=1;b-=1
    edge[a].append(b)
    edge[b].append(a)
# print(edge)

ans=[-1]*n
goal=deque([0])
while (-1 in ans):
    g=goal.popleft()
    # print(ans)
    for i in edge[g]:
        if ans[i]==-1:
            ans[i]=g+1
            goal.append(i)
            


# goal=deque([0])
# while (-1 in ans):
#     g=goal.popleft()
#     for i,v in enumerate(edge):
#         if v==-1:continue
#         if g in v:
#             ans[i]=g+1
#             edge[i]=-1
#             goal.append(i)

if (-1 in ans):
    no()
    exit()
    
yes()
for i in ans[1:]:
    print(i)



### FIXED CODE ###

def LI():return list(map(int,input().split()))
def yes():print("Yes")
def no():print("No")
from collections import deque

def main():
    n,m=LI()
    edge=[[] for i in range(n)]
    for i in range(m):
        a,b=LI()
        a-=1;b-=1
        edge[a].append(b)
        edge[b].append(a)    
    ans=[-1]*(n)
    goal=deque([0])
    while goal:
        g=goal.popleft()
        for i in edge[g]:
            if ans[i]==-1:
                ans[i]=g+1
                goal.append(i)
    yes()
    print(*ans[1:])
main()
### BUGGY CODE ###

import bisect

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

cnt = {}
for x in a:
    if x in cnt:
        cnt[x] += 1
    else:
        cnt[x] = 1

ans = 0
for i in range(n - 1, -1, -1):
    for d in range(30, -1, -1):
        k = bisect.bisect_left(a, (1 << d) - a[i])
        if k < n and a[i] + a[k] == (1 << d) and (a[i] == a[k] and cnt[a[i]] >= 2 or a[i] != a[k] and cnt[a[i]] >= 1 and cnt[a[k]] >= 1):
            ans += 1
            cnt[a[i]] -= 1
            cnt[a[k]] -= 1

print(ans)

### FIXED CODE ###

import bisect

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

cnt = {}
for x in a:
    if x in cnt:
        cnt[x] += 1
    else:
        cnt[x] = 1

ans = 0
for i in range(n - 1, -1, -1):
    for d in range(30, -1, -1):
        k = bisect.bisect_left(a, (1 << d) - a[i])
        if k < n and a[i] + a[k] == (1 << d) and (a[i] == a[k] and cnt[a[i]] >= 2 or a[i] != a[k] and cnt[a[i]] >= 1 and cnt[a[k]] >= 1):
            ans += 1
            cnt[a[i]] -= 1
            cnt[a[k]] -= 1

print(ans)
### BUGGY CODE ###

N, M, K = map(int, input().split())
mod = 998244353

def comb(a, b):
    global mod
    l, r = 1, 1
    for i in range(b):
        l = l*(b-i)%mod
        r = r*(a-i)%mod
    return (r*pow(l, mod-2, mod))%mod

ans = 0
for i in range(K+1):
    ans += comb(N-1, i)*M*pow((M-1), (N-1-i), mod)%mod

print(ans%mod)


### FIXED CODE ###

N, M, K = map(int, input().split())
mod = 998244353

l_lis = [1]
r_lis = [1]

l, r = 1, 1
for j in range(K+1):
    l = l*(j+1)%mod
    r = r*(N-j-1)%mod
    l_lis.append(l)
    r_lis.append(r)

def comb(a, b):
    global mod
    l = l_lis[b]
    r = r_lis[b]
    return (r*pow(l, mod-2, mod))%mod
 
ans = 0
for i in range(K+1):
    ans += comb(N-1, i)*M*pow((M-1), (N-1-i), mod)%mod

print(ans%mod)
### BUGGY CODE ###



D = int(input())
C = list(map(int, input().split()))
S = []
N = 26
for d in range(D):
    S += [list(map(int, input().split()))]
#print(C)
#print(S)
myans = [d%N for d in range(D)]
print(myans)

def estimate(mylist):
    mycost = 0
    dayflag = [0 for n in range(N)]
    for d in range(1,D+1):
        mycontest = mylist[d-1]
        mycost += S[d-1][mycontest]
        dayflag[mycontest] = d
        #print(mycontest, d, dayflag)
        for i in range(26):
             mycost -= C[mycontest] * (d - dayflag[i])
    return mycost

import random
import copy
times = 10**4
bestcost = 0
random.seed(1)
for i in range(times):
    a = random.randrange(D)
    b = random.randrange(D)
    mylist = copy.deepcopy(myans)
    #print(a,b, mylist)
    mylist[a] = myans[b]
    mylist[b] = myans[a]
    #print(mylist)
    #estimate
    mycost = estimate(mylist)
    if  bestcost < mycost:
        bestcost = mycost
        myans = mylist
        #print(i, bestcost)
for d in range(N):
    print(myans[d]+1)

### FIXED CODE ###

D = int(input())
C = list(map(int, input().split()))
S = []
N = 26
for d in range(D):
    S += [list(map(int, input().split()))]
#print(C)
#print(S)
myans = [d%N for d in range(D)]
for d in range(D):
  print(myans[d]+1)
### BUGGY CODE ###

n, q = map(int, input().split())
query = []
for _ in range(q):
    t, x = map(int, input().split())
    query.append((t-1, x))
black = (n-2)**2
rc = [[n, n] for _ in range(n)]
mrc = [n, n]
for t, x in query:
    black -= rc[x][t]-2
    if x < mrc[t]:
        mrc[t] = x
        for i in range(rc[x][t]):
            rc[i][1-t] = x 
print(black)

### FIXED CODE ###

from collections import deque
n, q = map(int, input().split())
query = []
for _ in range(q):
    t, x = map(int, input().split())
    query.append((t-1, x))
black = (n-2)**2
rc = [deque([(n, n)]), deque([(n, n)])]
mrc = [n, n]

def bisect(li, x):
    ok = -1
    ng = len(li)
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if li[mid][0]<x:
            ok = mid
        else:
            ng = mid
    return ok+1

for t, x in query:
    tmp = rc[t][bisect(rc[t], x)][1]
    black -= tmp-2
    if x < mrc[t]:
        mrc[t] = x
        rc[1-t].appendleft((tmp, x))
print(black)
### BUGGY CODE ###

N = int(input())
A, B = [], []
AB = []
for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
    AB.append([a, b])

AB.sort(key=lambda x: x[1])

time = 0
while (len(AB) > 0):
    flag = True
    for i in range(len(AB)):
        if time + AB[i][0] <= AB[i][1]:
            time += AB[i][0]
            AB.pop(i)
            flag = False
            break
    if flag:
        break

if len(AB) == 0:
    print('Yes')
else:
    print('No')


### FIXED CODE ###

def main():
    N = int(input())
    A, B = [], []
    AB = []
    for i in range(N):
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)
        AB.append([a, b])

    AB.sort(key=lambda x: x[1])

    time = 0
    count = 0
    for i in range(N):
        flag = True
        a, b = AB[i]
        if time + a <= b:
            time += a
            count += 1
            flag = False
        if flag:
            break

    if count == N:
        print('Yes')
    else:
        print('No')    

if __name__ == "__main__":
    main()
### BUGGY CODE ###

def solve():
  N = int(input())
  X = input()
  bl = X.count('1')
  bit = 0
  for i in range(N):
    bit += int(X[i])*pow(2,N-1-i)
  ans = [0]*N
  dp = [0]*(N+1)
  for i in range(1,N+1):
    dp[i] = dp[i%sum(map(int,list(bin(i)[2:])))]+1
  for i in range(N):
    if X[i]=='1':
      bit1 = bit - pow(2,N-1-i)
      bl1 = bl-1
      if bl1==0:
        ans[i] = 0
        continue
    else:
      bit1 = bit + pow(2,N-1-i)
      bl1 = bl+1
    ans[i] = dp[bit1%bl1]+1
  return ans
print(*solve(),sep='\n')

### FIXED CODE ###

def solve():
  N = int(input())
  X = input()
  x = sum(map(int,list(X)))
  dp = [0]*N
  for i in range(1,N):
    dp[i] = dp[i%sum(map(int,list(bin(i)[2:])))]+1
  cnt1 = 0
  if x>1:
    for i in range(N):
      cnt1 += int(X[-i-1])*pow(2,i,x-1)
      cnt1 %= x-1
  cnt2 = 0
  for i in range(N):
    cnt2 += int(X[-i-1])*pow(2,i,x+1)
    cnt2 %= x+1
  
  ans = [0]*N
  for i in range(N):
    if X[i]=='1':
      if x==1:
        ans[i] = 0
      else:
        num = (cnt1-pow(2,N-i-1,x-1))%(x-1)
        ans[i] = dp[num]+1
    else:
      num = (cnt2+pow(2,N-i-1,x+1))%(x+1)
      ans[i] = dp[num]+1
  return ans
print(*solve(),sep='\n')