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

def popcount(x):
    bitx = bin(x)
    cnt = bitx.count('1')
    return x % cnt

n = int(input())
x = list(input())
for i in range(n):
    tmp = x.copy()
    if tmp[i] == '1':
        tmp[i] = '0'
    else:
        tmp[i] = '1'
    tmp = int(''.join(tmp), 2)
    cnt = 0
    while True:
        if tmp == 0:
            break
        tmp = popcount(tmp)
        cnt += 1
    print(cnt)

### FIXED CODE ###

import sys
# import math
# import bisect
# import numpy as np
# from decimal import Decimal
# from numba import njit, i8, u1, b1 #JIT compiler
# from itertools import combinations, product
# from collections import Counter, deque, defaultdict

# sys.setrecursionlimit(10 ** 6)
MOD = 10 ** 9 + 7
INF = 10 ** 9
PI = 3.14159265358979323846

def read_str():      return sys.stdin.readline().strip()
def read_int():      return int(sys.stdin.readline().strip())
def read_ints():     return map(int, sys.stdin.readline().strip().split())
def read_ints2(x):   return map(lambda num: int(num) - x, sys.stdin.readline().strip().split())
def read_str_list(): return list(sys.stdin.readline().strip().split())
def read_int_list(): return list(map(int, sys.stdin.readline().strip().split()))
def GCD(a: int, b: int) -> int: return b if a%b==0 else GCD(b, a%b)
def LCM(a: int, b: int) -> int: return (a * b) // GCD(a, b)

def popcount(num):
    cnt = 0
    while num > 0:
        num %= bin(num).count('1')
        cnt += 1
    return cnt

def Main():
    n = read_int()
    x = read_str()
    x_int = int(x, 2)

    cnt = x.count('1')
    minus_cnt = cnt - 1
    plus_cnt = cnt + 1
    
    minus_mod = x_int % minus_cnt if minus_cnt != 0 else 0
    plus_mod = x_int % plus_cnt

    for i in range(n):
        if x[i] == '0':
            print(popcount((plus_mod + pow(2, n - 1 - i, plus_cnt)) % plus_cnt) + 1)
        elif minus_cnt != 0:
            print(popcount((minus_mod - pow(2, n - 1 - i, minus_cnt)) % minus_cnt) + 1)
        else:
            print(0)

if __name__ == '__main__':
    Main()
### BUGGY CODE ###

s = '0' + input()
n = len(s)
cnt = 0

for i in range(1, n-2):
	for j in range(i+3, n+1):
		tmp = int(s[i:j])
		if tmp % 2019 == 0:
			cnt += 1

print(cnt)

### FIXED CODE ###

s = input()
n = len(s)

MOD = 2019
T = [1] + [0] * 2018
d, p = 0, 1
for c in reversed(s):
	d = (d + p * int(c)) % MOD
	p = p * 10 % 2019
	T[d] += 1

print(sum(x * (x - 1) // 2 for x in T))
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
y = [0 for _ in range(n)]
suma = sum(a)
ans = []
for i in range(n):
	t = 2*sum([a[j%n] for j in range(i, i+n, 2)])-suma
	ans.append(str(t))
print(" ".join(ans))

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
y = [0 for _ in range(n)]
suma = sum(a)
ans = []
memo1 = 2*sum([a[j%n] for j in range(0, 0+n, 2)])-suma
memo2 = 2*sum([a[j%n] for j in range(1, 1+n, 2)])-suma
ans.append(str(memo1))
ans.append(str(memo2))
# (i+n-2)%n - (i-2)%n
for i in range(2,n):
	if i%2 == 0:
		memo1 = memo1 + 2*(a[(i+n-1)%n] - a[(i-2)%n])
		ans.append(str(memo1))
	else:
		memo2 = memo2 + 2*(a[(i+n-1)%n] - a[(i-2)%n])
		ans.append(str(memo2))
print(" ".join(ans))
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import sys
S=sys.stdin.readline().strip()
N=len(S)
mod=10**9+7

dp=[ [ 0 for j in range(13) ] for i in range(N) ]

for i,x in enumerate(S[::-1]):  #i桁目
    if i==0:
        if x!="?":
            x=int(x)
            dp[i][(x*10**i)%13]=1
        else:
            for x in range(10):
                dp[i][(x*10**i)%13]=1
    else:
        if x!="?":
            x=int(x)
            for j in range(13):
                dp[i][(x*10**i+j)%13]+=dp[i-1][j]
                dp[i][(x*10**i+j)%13]%=mod
        else:
            for j in range(13):
                for x in range(10):
                    dp[i][(x*10**i+j)%13]+=dp[i-1][j]
                    dp[i][(x*10**i+j)%13]%=mod
print dp[N-1][5]%mod


### FIXED CODE ###

S=raw_input()
S=S[::-1]
l=len(S)

dp=[ 0 for j in range(13) ]
dp[0]=1

mod=10**9+7

dp2=[ 0 for _ in range(13) ]

keta=1

for i in range(1,l+1):
	dp2=[0]*13
	for j in range(13):
		if dp[j]!=0:
			if S[i-1]=="?":
				for k in range(10):
					next=(k*keta+j)%13 
					dp2[next]+=dp[j]
					dp2[next]%=mod
			else:
				k=int(S[i-1])
				next=(k*keta+j)%13
				dp2[next]+=dp[j]
				dp2[next]%=mod

	dp=dp2
	keta=(keta*10)%13

print dp[5]
### BUGGY CODE ###

K, S = map(int, input().split())
count = 0

for X in range(K+1):
    for Y in range(K+1):
        for Z in range(K+1):
            if X+Y+Z == S:
                count += 1

print(count)


### FIXED CODE ###

K, S = map(int, input().split())
count = 0

for X in range(K+1):
    for Y in range(K+1):
        if (0 <= S-(X+Y)) and (S-(X+Y) <= K) :
            count += 1

print(count)
### BUGGY CODE ###

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

def Count(j,k,s):
	if(j==0 and k==0 and s==0):
		return 1
	elif(j >= 1 and s < x[j-1]):
		return Count(j-1,k,s)
	elif(j >= 1 and k>=1 and s >= x[j-1]):
		return Count(j-1,k,s) + Count(j-1,k-1,s-x[j-1])
	elif(j < k):
		return 0
	else:
		return 0

sum=0
for i in range(1,n+1):
	sum += Count(n,i,i*a)
print(sum)

### FIXED CODE ###

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

def Count(n,k,a):
	s = sum(x)
	dp=[[[0 for l in range(s+1)] for j in range(k+1)] for i in range(n+1)]
	dp[0][0][0]=1
	Sum=0
	for i in range(n):
		for j in range(k+1):
			for l in range(s+1):
				if l < x[i]:
					dp[i+1][j][l] = dp[i][j][l]
				if j >=1 and l >= x[i]:
					dp[i+1][j][l] = dp[i][j][l] + dp[i][j-1][l-x[i]]
				if j <= i+1 and l ==j*a and j >= 1:
					if dp[i+1][j][l]>=1:	
						Sum += dp[i+1][j][l]-dp[i][j][l]
	return Sum

print(Count(n,n,a))
### BUGGY CODE ###

n=int(input())
A=list(map(int,input().split()))
ans=[]
for i in range(1,n+1):
    ans.append(A.index(i)+1)
print(*ans)
    

### FIXED CODE ###

n=int(input())
A=list(map(int,input().split()))
ans=[None for i in range(n)]
for i in range(n):
    ans[A[i]-1]=str(i+1)
print(" ".join(ans))
### BUGGY CODE ###

R, G, B, N = map(int, input().split())
counter = 0
r_max = N//R+1
g_max = N//G+1
for r in range(r_max+1):
  temp = N - R*r
  for g in range(g_max+1):
    now = temp - G*g
    if now% B == 0 and now//B >= 0:
      counter +=1
print(counter)

### FIXED CODE ###

R, G, B, N = map(int, input().split())
counter = 0
r_max = N//R+1
for r in range(r_max+1):
  temp = N - R*r
  for g in range(temp//G+1):
    now = temp - G*g
    if now% B == 0 and now//B >= 0:
      counter +=1
print(counter)
### BUGGY CODE ###

[N,M]=[int(i) for i in input().split()]
lis=[-1 for i in range(N)]
flg=0
for m in range(M):
  [s,c]=[int(i) for i in input().split()]
  if lis[s-1]==-1 or lis[s-1]==c:
    lis[s-1]=c
  else:
    flg=1
    break
x=""
if flg==1:
  print("-1")
else:
  for i in range(len(lis)):
    if i==0 and lis[i]==0 and len(lis)!=1:#先頭0排除
      print("-1")
      break
    if lis[i]==-1:#指定なし
      if flg==0 and i==0:
        x+="1"
        flg=2
        for i in range(10**10):
        	flg+=i
      else:
        x+="0"
    else:#指定あり
      x+=str(lis[i])
      flg="2"
    if i==len(lis)-1:print(x)

### FIXED CODE ###

[N,M]=[int(i) for i in input().split()]
lis=[-1 for i in range(N)]
flg=0
for m in range(M):
  [s,c]=[int(i) for i in input().split()]
  if lis[s-1]==-1 or lis[s-1]==c:
    lis[s-1]=c
  else:
    flg=1
    break
x=""
if flg==1:
  print("-1")
else:
  for i in range(len(lis)):
    if i==0 and lis[i]==0 and len(lis)!=1:#先頭0排除
      print("-1")
      break
    if lis[i]==-1:#指定なし
      if flg==0 and i==0 and len(lis)!=1:
        x+="1"
        flg=2
      else:
        x+="0"
    else:#指定あり
      x+=str(lis[i])
      flg=2
    if i==len(lis)-1:print(x)
### BUGGY CODE ###

from collections import defaultdict
import numpy as np

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

friend_list = defaultdict(list)
for _ in range(M):
    a, b = map(int, input().split(' '))
    a, b = a - 1, b - 1
    friend_list[a].append(b)
    friend_list[b].append(a)

block_list = defaultdict(list)
for _ in range(K):
    c, d = map(int, input().split(' '))
    c, d = c - 1, d - 1
    block_list[c].append(d)
    block_list[d].append(c)


def dfs(s, adj_list):
    cand_list = [s]
    vis_list = []

    while len(cand_list) > 0:
        vis = cand_list.pop(-1)
        vis_list.append(vis)
        pre_cand_list = adj_list[vis]
        for cand in pre_cand_list:
            if cand in vis_list:
                continue
            if cand in cand_list:
                continue
            cand_list.append(cand)

    return vis_list


num_friend_candidate_array = np.zeros(N, dtype=np.uint8)
visited_user_list = []

for i in range(N):
    if i in visited_user_list:
        continue

    connected_components = dfs(i, friend_list)
    visited_user_list += connected_components

    for j in connected_components:
        friend_candidates = set(connected_components) - \
            set(friend_list[j]) - set(block_list[j]) - {j}
        num_friend_candidate_array[j] = max(len(friend_candidates), 0)

print(' '.join(num_friend_candidate_array.astype(str)))


### FIXED CODE ###

from collections import defaultdict


class UnionFind:
    def __init__(self, n=0):
        self.d = {i: -1 for i in range(n)}

    def find(self, x):
        if self.d[x] < 0:
            return x
        else:
            self.d[x] = self.find(self.d[x])
            return self.d[x]

    def unite(self, x, y):
        x, y = self.find(x), self.find(y)
        if (x == y):
            return False
        if (self.d[x] > self.d[y]):
            x, y = y, x
        self.d[x] += self.d[y]
        self.d[y] = x
        return True

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return -self.d[self.find(x)]


N, M, K = map(int, input().split(' '))
deg = defaultdict(int)
to = defaultdict(list)
uf = UnionFind(N)

for _ in range(M):
    a, b = map(int, input().split(' '))
    a -= 1
    b -= 1
    deg[a] += 1
    deg[b] += 1
    uf.unite(a, b)

for _ in range(K):
    c, d = map(int, input().split(' '))
    c -= 1
    d -= 1
    to[c].append(d)
    to[d].append(c)

for i in range(N):
    ans = uf.size(i) - 1 - deg[i]
    for u in to[i]:
        if uf.same(i, u):
            ans -= 1
    print(ans, end=' ' if i != (N - 1) else '\n')
### BUGGY CODE ###

import sys

sys.setrecursionlimit(1000000)


def dfs(v, parent):
    for tail, weight in adj[v]:
        if tail == parent:
            continue
        dist[tail] = dist[v] + weight
        dfs(tail, v)


n = int(input())
adj = [[] for i in range(n + 1)]
for i in range(n - 1):
    a, b, c = [int(x) for x in input().split()]
    adj[a].append((b, c))
    adj[b].append((a, c))
q, k = [int(x) for x in input().split()]
dist = [0] * (n + 1)
dfs(k, k)
for j in range(q):
    l, r = [int(x) for x in input().split()]
    print(dist[l] + dist[r])
# print(*data, sep='\n')


### FIXED CODE ###

import sys
import collections

n = int(input())
adj = [[] for i in range(n + 1)]
for i in range(n - 1):
    a, b, c = [int(x) for x in input().split()]
    adj[a].append((b, c))
    adj[b].append((a, c))
q, k = [int(x) for x in input().split()]
dist = [0] * (n + 1)
queue = collections.deque()
queue.append(k)
while len(queue) > 0:
    u = queue.popleft()
    for v, weight in adj[u]:
        if dist[v] == 0:
            queue.append(v)
            dist[v] = dist[u] + weight
for j in range(q):
    l, r = [int(x) for x in input().split()]
    print(dist[l] + dist[r])
# print(*data, sep='\n')
### BUGGY CODE ###

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

total = 0
target = 0

for i in range(len(P)-K+1):
    c = sum(P[i:i+K])
    if c > total:
        total = c
        target = i

ans = 0
for i in range(target, target+K):
    e = (P[i]+1)/2
    ans += e

print(ans)

### FIXED CODE ###

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


ans = 0
for i in range(len(P)-K+1):
    if i == 0:
        c = sum(P[:K])
    else:
        c = c + P[i+K-1] - P[i-1]
    if c > ans:
        ans = c


print((ans+K)/2)
### BUGGY CODE ###

import sys
n,y = map(lambda x:int(x),input().split())

for i in range(n+1) :
    for j in range(n+1) :
        nokori = y - i*10000 - j*5000
        if nokori < 0 :
            continue
        if nokori % 1000 == 0:
            k = int(nokori / 1000)
            if n == i + j + k :
                print(i,j,k)
                sys.exit()
print(-1,-1,-1)


### FIXED CODE ###

import sys
n,y = map(lambda x:int(x),input().split())

for i in range(n+1) :
    for j in range(n+1) :
        if n - (i + j) < 0 :
            continue
        nokori = y - i*10000 - j*5000
        if nokori % 1000 == 0:
            k = int(nokori / 1000)
            if n == i + j + k :
                print(i,j,k)
                sys.exit()
print(-1,-1,-1)
### BUGGY CODE ###


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

icnt=0
for i in range(n):
    for j in range(i+1,n):
        if j-i==a[j]+a[i]:
            icnt+=1
            
print(icnt)


### FIXED CODE ###


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

#icnt=0
#for i in range(n):
#    for j in range(i+1,n):
#        if j-i==a[j]+a[i]:
#            icnt+=1

ip=[0]*n
jm=dict()
for i in range(n):
    ip[i]=i+a[i]
    if i-a[i] in jm:
        jm[i-a[i]]+=1
    else:
        jm[i-a[i]]=1

icnt=0
for i in range(n):
    if ip[i] in jm:
        icnt+=jm[ip[i]]
            
print(icnt)
### BUGGY CODE ###

s=int("".join(map(str,input().split())))

i=1
while i<s:
    if s==i**2:
        print("Yes")
    else:
         i=i+1

else:
    print("No")


### FIXED CODE ###

s=int("".join(map(str,input().split())))

i=1
while i<s:
    if s==i**2:
        print("Yes")
        break
    else:
         i=i+1

else:
    print("No")
### BUGGY CODE ###

N,W = input().split()
aArr = list()
ans = 0
tmp = int(N)
MOD = 10**9+7
for i in range(int(W)):
    inputInt = int(input())
    aArr.append(inputInt)
    if inputInt - tmp == 1:
        print(ans)
        exit()
    tmp = inputInt

tmp = 0
tmpB = 0
ans = 1
for i in range(int(N)):
    if(i in aArr):
        tmp = 0
    elif i < 2:
        tmp = 1
    else:
        tmp = ans
    ans = (tmp + tmpB) % MOD
    tmpB = tmp
print(ans)

### FIXED CODE ###

import sys
N, W = input().split()
aArr = list()
ans = 0
tmp = int(N)
MOD = 10 ** 9 + 7
aArr = set(map(int, sys.stdin))

tmp = 0
tmpB = 0
ans = 1
for i in range(int(N)):
    if (i in aArr):
        tmp = 0
    elif i < 2:
        tmp = 1
    else:
        tmp = ans
    ans = (tmp + tmpB) % MOD
    tmpB = tmp
print(ans)
### BUGGY CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

x = int(readline())
for i in range(100000):
    for j in range(-2000, i):
        v = i ** 5 - j ** 5
        if x == v:
            print(i, j)
            exit()
        if len(str(v)) >= 10 and j > 0:
            break


### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

x = int(readline())
for i in range(-118, 119):
    for j in range(-119, 118):
        a = i ** 5 - j ** 5
        b = j ** 5 - i ** 5
        if x == a:
            print(i, j)
            exit()
        if x == b:
            print(j, i)
            exit()
### BUGGY CODE ###

# ABC068C - Cat Snuke and a Voyage (ARC079C)
# DFS O(N + M)
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)


def dfs(v: int) -> None:
    for u in G[v]:  # search vertices available from v recursively
        if dist[u] > dist[v] + 1:
            dist[u] = dist[v] + 1
            dfs(u)


def main():
    global G, dist
    N, M = tuple(map(int, input().split()))  # vertices and edges
    E = tuple(tuple(map(int, input().split())) for _ in range(M))
    G = [[] for _ in range(N + 1)]  # graph, N+1: 1-idx
    for v, u in E:  # construct a graph according to edges' info
        G[v] += [u]
        G[u] += [v]
    dist = [float("inf")] * (N + 1)  # distance from vertex 1
    dist[1] = 0
    dfs(1)  # search from vertex 1
    flg = dist[-1] <= 2
    print("POSSIBLE" if flg else "IMPOSSIBLE")


if __name__ == "__main__":
    main()

### FIXED CODE ###

# ARC079C - Cat Snuke and a Voyage (ABC068C)
import sys
input = sys.stdin.readline

def main():
    n, m = list(map(int, input().rstrip().split()))
    s, d = set(), set()
    for _ in range(m):
        a, b = list(map(int, input().rstrip().split()))
        if a == 1:
            s.add(b)
        elif b == n:
            d.add(a)
    ans = len(s & d)
    print("POSSIBLE" if ans else "IMPOSSIBLE")


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

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

cnt=0
for i in range(n):
    tem=0
    for j in range(0,i+1):
        if p[i]>p[j]:
            tem=0
            break
        tem+=1
    if tem>=1:
        cnt+=1

print(cnt)

### FIXED CODE ###

#C
n=int(input())
p=list(map(int,input().split()))
ans=1
m=p[0]
for i in range(1,n):
    if m>=p[i]:
        ans+=1
        m=p[i]
    
print(ans)
### BUGGY CODE ###

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


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

    ans = A[0]
    for i in range(1, N):
        ans *= A[i]

    print(-1 if ans > 10**18 else ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###

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


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

    A.sort(reverse=True)

    if 0 in A:
        print(0)
        exit()

    ans = A[0]
    for i in range(1, N):
        ans *= A[i]
        if ans > 10**18:
            print(-1)
            exit()


    print(ans)


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

N,M=map(int, input().split()) 
a=[0]*M
for i in range(M):
  a[i]=int(input())

dp=[0]*(N+1)
dp[0]=1
if 1 in a:
  dp[1]=0
else:
  dp[1]=1
  
for j in range(2,N+1):
  if j in a:
    dp[j]=0
  else:
    dp[j]=dp[j-2]+dp[j-1]

#print(dp)
print(dp[-1]%1000000007)

### FIXED CODE ###

N,M=map(int, input().split()) 
a=[0]*M
for i in range(M):
  a[i]=int(input())
b=set(a)

dp=[0]*(N+1)
dp[0]=1
if 1 in b:
  dp[1]=0
else:
  dp[1]=1
  
for j in range(2,N+1):
  if j in b:
    dp[j]=0
  else:
    dp[j]=dp[j-2]+dp[j-1]

#print(dp)
print(dp[-1]%1000000007)
### BUGGY CODE ###

from fractions import gcd
import sys
input = sys.stdin.readline

N,M=map(int,input().split())
List=list(map(lambda x:int(x)/2,input().split()))

def main():
    LCM=1
    
    for i in List:
        LCM*=i/gcd(LCM,i)

    for i in List:
        if LCM/i%2==0:
            print(0)
            exit()

    print(int(M//(LCM*2)+M%(LCM*2)//LCM))


if __name__ == '__main__':
    main()

### FIXED CODE ###

from fractions import gcd
import sys
input = sys.stdin.readline

N,M=map(int,input().split())
List=list(map(lambda x:int(x)//2,map(int, set(input().split()))))

def main():
    LCM=1

    for i in List:
        LCM*=i//gcd(LCM,i)

    for i in List:
        if LCM//i%2==0:
            print(0)
            exit()

    print(int(M//(LCM*2)+M%(LCM*2)//LCM))


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

A = input()

S = 0
dic = {i: 0 for i in range(2019)}
dic[0] += 1
l = len(A)+1

for n in range(1, l):
    S += (int(A[-n])*(10**(n-1)))
    sm = S % 2019
    dic[sm] += 1

result = 0

for n in dic.values():
    result += (n*(n-1)/2)


print(int(result))


### FIXED CODE ###

S = input()
 
res = [0] * 2019
res[0] = 1
 
d = 1
a = 0
 
for c in reversed(S):
    a += int(c) * d
    a %= 2019
    res[a] += 1
    d *= 10
    d %= 2019
 
ans = 0
for r in res:
    ans += r*(r-1) // 2
print(ans)
### BUGGY CODE ###

#E re
H, N = map(int, input().split())
A = [0] * N
B = [0] * N
for i in range(N):
    A[i], B[i] = map(int, input().split())
DP = [0] * H

for i in range(H):
    minM = float('inf')
    for j in range(N):
        if i+1 - A[j] >= 0:
            M = DP[i-A[j]] + B[j]
        else:
            M = B[j]
        if minM > M:
            minM = M
    DP[i] = minM

print(int(DP[H-1]))

### FIXED CODE ###

#E re
H, N = map(int, input().split())
A = [0] * N
B = [0] * N
for i in range(N):
    A[i], B[i] = map(int, input().split())
DP = [float('inf')] * (H+1)
DP[0] = 0

for i in range(N):
    for j in range(H):
        nj = min(j+A[i], H)
        DP[nj] = min(DP[nj], DP[j]+B[i])

print(int(DP[H]))
### BUGGY CODE ###

K, S = map(int, input().split())
ans = 0
for X in range(K+1):
    for Y in range(K+1):
        for Z in range(K+1):
            if (X + Y + Z == S):
                ans += 1
print(ans)

### FIXED CODE ###

K, S = map(int, input().split())
ans = 0
for X in range(K+1):
    for Y in range(K+1):
        if (S- X - Y >=  0 and S - X - Y <= K):
            ans += 1
print(ans)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
cnt = 0
for aa in a:
    for bb in b:
        for cc in c:
            if aa < bb < cc:
                cnt += 1
print(cnt)

### FIXED CODE ###

import bisect
n = int(input())
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))
c = sorted(list(map(int, input().split())))
cnt = 0
for bb in b:
    anum = bisect.bisect_left(a, bb)
    cnum = n - bisect.bisect_right(c, bb)
    cnt += (anum * cnum)
print(cnt)
### BUGGY CODE ###

def solve():
  while True:
    n,m = map(int,input().split())
    if not n and not m: break
    lst = []
    lst2 = []
    for i in range(n):
      lst.append(int(input()))
    for i in lst:
      for j in lst:
        lst2.append(i + j)
    lst2 = list(set(lst2 + lst))
    lst2.sort()
    ans = 0
    def binary(x, left, right):
      center = (left + right) // 2
      length = right - left + 1
      if length <= 0:
        return -100
      elif length == 1:
        if lst2[center] > x:
          return center - 1
        else:
          return center
      elif length == 2:
        if lst2[center] > x:
          return center - 1
        else:
          return center
      elif lst2[center] == x: return x
      elif lst2[center] < x: return binary(x, center, right)
      elif lst2[center] > x: return binary(x, left, center)
      
    for i in lst2:
      if i <= m:
        ans = max(ans, i + lst2[binary(m - i, 0, len(lst2) - 1)])
      else:
        break
    print(ans)
solve()




### FIXED CODE ###

def solve():
  while True:
    n,m = map(int,input().split())
    if not n and not m: break
    
    lst = [int(input()) for _ in range(n)]
    lst.append(0)
    lst = sorted(lst)
    lst2 = [i + j for i in lst for j in lst if i <= j]
    lst2 = sorted(lst2)
    A = []
    index = len(lst2) - 1
    for i in lst2:
      if i + lst2[-1] <= m:
        A.append(i + lst2[-1])
      elif i <= m:
        while True:
          if i + lst2[index] <= m:
            break
          index -= 1
        A.append(i + lst2[index])
      else:
        break
    print(max(A))
solve()
### BUGGY CODE ###

N = int(input())
R = [list(map(int, input().split())) for i in range(N)]
T = [[R[i][0] + R[i][1], R[i][0] - R[i][1]] for i in range(N)]
T.sort()
while len(T) - 1 > 0:
    t = T.pop(0)
    i = 1
    while len(T) and t[0] > T[0][1]:
        N -= 1
        i += 1
        T.pop(0)
print(N)


### FIXED CODE ###

N = int(input())
X = [list(map(int, input().split())) for i in range(N)]
LR = [[x[0]-x[1], x[0] + x[1]] for x in X]
LR.sort(key=lambda x:x[1])

A = 1
right = LR[0][1]
for i in range(1, N):
    if right <= LR[i][0]:
        A += 1
        right = LR[i][1]
print(A)
### BUGGY CODE ###

n = int(input())
s = input()
ssp = s.split('.')
num = min(s.count('.'),s.count('#') - len(ssp[-1]))
if s.count('#') == 0 or s.count('.') == 0:
    print(0)
    exit()
for i in range(n):
    if s[i - 1] == s[i]:
        continue
    num = min(num,s[:i].count('#') + s[i:].count('.'))
print(num)

### FIXED CODE ###

n = int(input())
s = input()
cnt = 0
narabi = []
befores = '#'
for S in s:
    if S == befores:
        cnt += 1
    else:
        narabi.append(cnt)
        befores = S
        cnt = 1
narabi.append(cnt)
if s[-1] == '#':
    narabi.append(0)
hennkann = s.count('.')
saishou = s.count('.')
hashu = 0
dot = 1
for i in range(int(len(narabi) / 2)):
    hennkann = hennkann - narabi[dot] + narabi[hashu]
    saishou = min(saishou,hennkann)
    dot += 2
    hashu += 2
print(saishou)