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

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

def d_cost(L):
    ori = L[0]
    cost = 0
    for i in range(1, len(L)):
        if ori < 0 and L[i] > 0:
            cost += abs(ori) * 2
        elif ori > 0 and L[i] < 0:
            cost += abs(ori) * 2
        elif L[i] == 0:
            cost += abs(ori) * 2
        else:
            pass
        ori = L[i]
    cost += abs(L[-1]) * 2
    print(cost)


for i in range(len(A)):
    d_cost(A[:i]+A[i+1:])


### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
A.insert(0, 0)
A.append(0)
a = 0
cost = 0
for i in A:
    b = i
    cost += abs(a-b)
    a = b
cost += abs(A[-1])

ori = cost
for i in range(1, len(A)-1):
    cost += abs(A[i-1]-A[i+1])
    cost -= abs(A[i-1]-A[i])+abs(A[i+1]-A[i])
    print(cost)
    cost  = ori
### BUGGY CODE ###

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

# In[3]:


N,Q = map(int, input().split())
S = str(input())
data = []
for i in range(Q):
    data.append(list(map(int, input().split())))


# In[17]:


for i in range(Q):
    print(S[data[i][0]-1:data[i][1]].count("AC"))


# In[ ]:






### FIXED CODE ###

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

# In[15]:


N,Q = map(int, input().split())
S = list(input())
mylist = [0]
cnt = 0
for i in range(1,len(S)):
    if S[i-1] == "A" and S[i] == "C":
        cnt += 1
    mylist.append(cnt)
for _ in range(Q):
    l,r = map(int, input().split())
    ans = mylist[r-1] - mylist[l-1]
    print(ans)


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

import numpy as np
import sys

def resolve():
    input = sys.stdin.readline
    sys.setrecursionlimit(10**9)
    N = int(input())
    A = list(map(int,input().split()))
    ans = np.ones(N,dtype=int)
    for i in range(N-1):
        for j in range(i+1,N):
            if A[i] % A[j] == 0:
                ans[i] = 0
                break
    for i in range(N-1):
        for j in range(i+1,N):
            if A[N-1 - i] % A[N-1 -j] == 0:
                ans[N-1 - i] = 0
                break
    print(sum(ans))
resolve()

### FIXED CODE ###

#写経
#https://atcoder.jp/contests/abc170/submissions/14363499
import sys

def resolve():
    it = map(int,sys.stdin.read().split())
    N = next(it)
    A = [next(it) for i in range(N)]
    
    if N == 1:
        print(1)
        return
    ax = max(A) + 1
    dp = [0] * ax
    for ai in A:
        da = dp[ai]
        if da > 1:
            continue
        dp[ai] += 1
        if da == 0:
            for aj in range(2*ai, ax, ai):
                dp[aj] = 2
    ans = 0
    for ai in A:
        if dp[ai] == 1:
            ans += 1
    print(ans)
resolve()
### BUGGY CODE ###

def examC():
    N = I()
    print(0)
    q = SI()
    if q!="Vacant":
        left = 0; right = N-1
        while(True):
            cur = (left+right)//2
            print(cur)
            next = SI()
            if next!="Vacant":
                if (cur%2==1 and next==q) or (cur%2==0 and next!=q):
                    right = cur
                else:
                    left = cur+1
            else:
                break

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()


### FIXED CODE ###

def examC():
    N = I()
    print(0)
    q = input()
    if q=="Vacant":
        exit()
    left = 0; right = N - 1
    for _ in range(20):
        cur = (left + right) // 2
        print(cur)
        next = input()
        if next=="Vacant":
            exit()

        if (cur % 2 == 1 and next == q) or (cur % 2 == 0 and next != q):
            right = cur
        else:
            left = cur + 1

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

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

N = int(input())
a = input().split(' ')
for i in map(str,range(1,N+1)):
    print(a.count(i))

### FIXED CODE ###

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

ans = [0]*N

for i in A:
    ans[i - 1] += 1
print('\n'.join(map(str,ans)))
### BUGGY CODE ###

N = int(input())
X = list(map(int, input()))

Xp = sum(X)
        
# print(Xp)
a = 0
b = 0
# c = 0
for i, x in enumerate(X):
    i_reverse = N-i-1
    if Xp > 1:
        a = (a + x * (1<<i_reverse)) % (Xp-1)
    b = (b + x * (1<<i_reverse)) % (Xp+1)
    # c = (c + x * (1<<i_reverse))
    # print(bin(c))

# print(a, b)

for i in range(N):
    i_reverse = N-i-1
    if Xp > 1:
        m = ([a, b][X[i]==0] + [-1, 1][X[i]==0] * (1<<i_reverse)) % [Xp-1, Xp+1][X[i]==0]
    else:
        if X[i]==0:
            m = (b + (1<<i_reverse)) % (Xp+1)
        else:
            print(0)
            continue
    count = 1
    # print(i, ([a, b][X[i]==0], [-1, 1][X[i]==0]*(1<<i_reverse)), [Xp-1, Xp+1][X[i]==0], X[i]==0)
    # print(m)
    while m > 0:
        p = sum([int(c) for c in str(bin(m)[2:])])
        m = m % p
        count += 1
    print(count)


### FIXED CODE ###

N = int(input())
X = list(map(int, input()))
# N = 2*10**5
# X = list(map(int, "10"*(N//2)))

Xp = sum(X)
        
# print(Xp)
a = 0
b = 0
# c = 0
# :N
for i, x in enumerate(X):
    i_reverse = N-i-1
    if Xp > 1:
        a = (a + x * pow(2, i_reverse, Xp-1)) % (Xp-1)
    b = (b + x * pow(2, i_reverse, Xp+1)) % (Xp+1)
    # c = (c + x * (1<<i_reverse))
    # print(bin(c))

# print(a, b)

# :N
for i in range(N):
    i_reverse = N-i-1
    if Xp > 1:
        m = ([a, b][X[i]==0] + [-1, 1][X[i]==0] * pow(2, i_reverse, [Xp-1, Xp+1][X[i]==0])) % [Xp-1, Xp+1][X[i]==0]
    else:
        if X[i]==0:
            m = (b + pow(2, i_reverse, Xp+1)) % (Xp+1)
        else:
            print(0)
            continue
    count = 1
    # print(i, ([a, b][X[i]==0], [-1, 1][X[i]==0]*(1<<i_reverse)), [Xp-1, Xp+1][X[i]==0], X[i]==0)
    # print(m)
    while m > 0:
        p = sum([int(c) for c in str(bin(m)[2:])])
        m = m % p
        count += 1
    print(count)
### BUGGY CODE ###

a, b, x = map(int, input().split())
count = [num for num in range(a, b+1) if num % x == 0]

print(len(count))

### FIXED CODE ###

from sys import stdin
a, b, x = [int(x) for x in stdin.readline().rstrip().split()]
print((b//x) - (a-1)//x)
### BUGGY CODE ###

from sys import stdin
from sys import setrecursionlimit
from collections import Counter

setrecursionlimit(10 ** 7)

n = int(stdin.readline().rstrip())
a = list(map(int,stdin.readline().rstrip().split()))
a.sort()
c = Counter(a)

se = set()

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

for i in a:
    k = make_divisors(i)
    flag = True
    for j in k:
        if j in se:
            flag = False
    if flag:
        se.add(i)

point = len(se)

for i in se:
    if c[i] > 1:
        point -= 1

print(point)

### FIXED CODE ###

from sys import stdin
from sys import setrecursionlimit
from collections import Counter
from numba import jit

setrecursionlimit(10 ** 7)

n = int(stdin.readline().rstrip())
a = list(map(int,stdin.readline().rstrip().split()))
a.sort()
b = list(set(a))
b.sort()
c = Counter(a)

se = set()

@jit
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

for i in b:
    k = make_divisors(i)
    flag = True
    for j in k:
        if j in se:
            flag = False
            break
    if flag:
        se.add(i)

point = len(se)

for i in se:
    if c[i] > 1:
        point -= 1

print(point)
### BUGGY CODE ###

class Union:
    def __init__(self, n):
        self.root = True
        self.parent = n
        self.size = 1

    def update(self, n, size):
        self.root = False
        self.parent = n
        self.size += size

def search(n):
    global A

    while not A[n-1].root:
        n = A[n-1].parent

    return n, A[n-1].size

N, M = list(map(int, input().split()))
A = [Union(i) for i in range(1, N+1)]
ans = 0

for i in range(M):
    X, Y, Z = list(map(int, input().split()))
    X_root, X_size = search(X)
    Y_root, Y_size = search(Y)

    if X_root != Y_root:
        if X_size < Y_size:
            a, b, size = X_root, Y_root, Y_size
        else:
            a, b, size = Y_root, X_root, X_size

        A[a-1].update(b, size)
        ans += 1

print(N-ans)

### FIXED CODE ###

def search(n):
    idx = n
    while A[n-1] != n:
        n = A[n-1]
    A[idx-1] = n

    return n

N, M = list(map(int, input().split()))
A = [i for i in range(1, N+1)]
ans = 0

for i in range(M):
    X, Y, Z = list(map(int, input().split()))
    X_root, Y_root = search(X), search(Y)

    if X_root != Y_root:
        A[X_root-1] = Y_root
        ans += 1

print(N-ans)
### BUGGY CODE ###

n = int(input())
a_lst = list(map(int, input().split()))
res_lst = []

for i in range(n):
  cnt = (a_lst.count(i+1))
  print(cnt)

### FIXED CODE ###

import collections

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

cnt = collections.Counter(a_lst)  
for i in range(n):
  print(cnt[i+1])
### BUGGY CODE ###

import sys
input = sys.stdin.readline

n, m = [int(x) for x in input().split()]
g = [[] for _ in range(n)]

for _ in range(m):
    l, r, d = map(int, input().split())
    g[l - 1].append((r - 1, d))
    g[r - 1].append((l - 1, -d))

d = [0] * n

for i in range(n):
    if d[i] != 0:
        continue
    stack = [i]
    while stack:
        u = stack.pop()
        for v, d_ in g[u]:
            if d[v] == 0 and v != i:
                d[v] = d[u] + d_
                stack.append(v)
            else:
                if d[v] != d[u] + d_:
                    print("No")
                    sys.exit()
    d[i] = 1
print("Yes")


### FIXED CODE ###

n, m = map(int, input().split())
ed = [[] for _ in range(n)]  # グラフ
v = [None] * n
for _ in range(m):
  l, r, d = map(int, input().split())
  ed[l-1].append((r-1, d))  # l -> r
  ed[r-1].append((l-1, -d))  # r -> l

visited = [False] * n  # 訪問フラグ（非連結の可能性の為）

def dfs(start):
  s = [start]
  v[start] = 0
  while s:
    label = s.pop()
    if visited[label] == False:
      visited[label] = True
      for to, dist in ed[label]:
        if v[to] is None:
          v[to] = v[label] + dist
          s.append(to)
        else:
          if v[to] != v[label] + dist:
            return False
  return True

is_exist = True
for i in range(n):
  if v[i] is None:
    if not dfs(i):
      print('No')
      is_exist = False
      break
if is_exist:
  print("Yes")
### BUGGY CODE ###

import copy

inf = 10 ** 8


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

def tolist(n):
    nn = n
    ret = [0] * N
    for i in range(N):
        ret[i] = nn % 2
        nn //= 2
    return ret

def tonum(l):
    ret = 0
    for i in range(N):
        ret += l[i] * (2**i)
    return ret

def union(l1,l2):
    ret = [0] * N
    for i in range(N):
        ret[i] = min(l1[i] + l2[i],1) 
    return tonum(ret)



cost = [0] * M
data = [[0]*N for i in range(M)]

for i in range(M):
    a,b = map(int,input().split())
    cost[i] = a
    c = list(map(int,input().split()))
    for x in c:
        x -= 1
        data[i][x] = 1

dp = [inf]*(2**N)


for j in range(2**N):
    if union(tolist(j),data[0]) == tonum(data[0]):
        dp[j] = cost[0]

dp[0] = 0

for i in range(1,M):
    #print(dp)
    for j in range(2**N):
        #print(dp)
        ###このjは一つ前のiのものであることに注意
        l = tolist(j)
        dp[union(l,data[i])] = min(dp[union(l,data[i])], dp[j]+cost[i])
        

#print(dp)
if dp[2**N -1] == inf:
    print(-1)
else:
    print(dp[2**N -1])


### FIXED CODE ###

### 提出 #10098255

##頭良すぎて草

##x | y    x と y のビット単位 論理和
##x ^ y    x と y のビット単位 排他的論理和
##x & y    x と y のビット単位 論理積
##x << n   x の n ビット左シフト
##x >> n   x の n ビット右シフト
##~x       x のビット反転

n,m=map(int,input().split())
p=2**n
inf=10**9
dp=[inf]*p
dp[0]=0
for i in range(m):
    a,b=map(int,input().split())
    c=sum([2**(j-1) for j in list(map(int,input().split()))])
    for k in range(p):
        if dp[k|c]>dp[k]+a:
            dp[k|c]=dp[k]+a
print(dp[-1] if dp[-1]!=inf else -1)
### BUGGY CODE ###

n, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
h = [0] * (n + k)
for i in range(n):
    h[i] = a[i]

dp = [float('inf')] * (n + k)
dp[0] = 0

for i in range(n):
    for j in range(1, k + 1):
        dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]))

print(dp[n-1])


### FIXED CODE ###

n, k = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]
for i in range(k):
    h.append(0)

dp = [float('inf')] * (n + k)
dp[0] = 0

for i in range(n):
    for j in range(1, k + 1):
        dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]))

print(dp[n-1])
### BUGGY CODE ###

def resolve():
    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)
resolve()

### FIXED CODE ###

def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    ans = []
    for _ in range(N):
        ans.append("0")
    for i in range(N):
        ans[A[i]-1] = i+1
    print(*ans)
resolve()
### BUGGY CODE ###

n,m=map(int,input().split())
A=[int(input()) for _ in range(m)]
dp=[0]*(n+1)
dp[0]=1
for i in range(1,n+1):
  dp[i]=(dp[i-1]+dp[i-2])%(10**9+7)
  if i in A:dp[i]=0
print(dp[n])

### FIXED CODE ###

n,m=map(int,input().split())
a=[int(input()) for _ in range(m)]
dp=[1]*(n+1)
for i in a:
  dp[i]=0
for i in range(2,n+1):
  dp[i]=(dp[i-1]+dp[i-2])%1000000007*dp[i]
print(dp[-1])
### BUGGY CODE ###

import math


def inputIntList():
    return [int(s) for s in input().split()]


def inputInt():
    return int(input())


def main():
    N = inputInt()
    a = inputIntList()
    ans = 0
    index = 0
    while index < len(a):
        if a[index] - 1 != index:
            a.remove(a[index])
            ans += 1
        else:
            index += 1
    return ans if ans != N else -1


if __name__ == "__main__":
    print(main())


### FIXED CODE ###

import math


def inputIntList():
    return [int(s) for s in input().split()]


def inputInt():
    return int(input())


def main():
    N = inputInt()
    a = inputIntList()
    ans = 0
    look = 1
    for i in a:
        if look == i:
            look += 1
        else:
            ans += 1

    return ans if ans != N else -1


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

import collections

N = int(input())

Tree = collections.defaultdict(list)

for i in range(N - 1):
    a, b, c = map(int, input().split())
    Tree[a].append((b, c))
    Tree[b].append((a, c))

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

def bfs(tree, s, distance):
    queue = [s]
    distance[s] = 0

    while queue:
        v = queue.pop(0)
        for child in tree[v]:
            if distance[child[0]] == -1:
                distance[child[0]] = distance[v] + child[1]
                queue.append(child[0])

distance = collections.defaultdict(lambda : -1)
bfs(Tree, k, distance)

for i in range(q):
    x, y = map(int, input().split())
    print(distance[x] + distance[y])


### FIXED CODE ###

import sys
import collections

sys.setrecursionlimit(int(1e7))

def dfs(node, parent, distance):
    depth[node] = distance
    for next_node, cost in Tree[node]:
        if next_node != parent:
            dfs(next_node, node, distance + cost)

N = int(input())

Tree = collections.defaultdict(list)

for i in range(N - 1):
    a, b, c = map(int, input().split())
    Tree[a].append((b, c))
    Tree[b].append((a, c))

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

depth = {}
dfs(k, -1, 0)

for i in range(q):
    x, y = map(int, input().split())
    print(depth[x] + depth[y])
### BUGGY CODE ###

mod = int(1e9 + 7)
N = int(input())
A = [format(i, '060b') for i in map(int, input().split())]
S = 0
for k in range(60):
  s = [A[i][59-k] for i in range(N)]
  v = s.count('0')*s.count('1')
  S += (v<<k) % mod
  S %= mod
S %= mod
print(S)

### FIXED CODE ###

mod = int(1e9 + 7)
N = int(input())
A = [format(i, '060b') for i in map(int, input().split())]
S = 0
for k in range(60):
  s = [b[59-k] for b in A]
  v = s.count('0')*s.count('1')
  S += (v<<k)
S %= mod
print(S)
### BUGGY CODE ###

n = int(input())
T = []
for _ in range(n-1):
    T += [list(map(int, input().split()))]
P = [0]+[-1]*(n-1)
T_sub = []
while T:
    for t in T:
        u, v, w = t
        pu, pv = P[u-1], P[v-1]
        if (pu < 0) & (pv < 0):
            T_sub += [t]
        elif (pu >= 0) & (pv < 0):
            P[v-1] = (pu+(w%2))%2
        else:
            P[u-1] = (pv+(w%2))%2
    T, T_sub = T_sub, []
for p in P: print(p)

### FIXED CODE ###

n = int(input())
L = [[] for _ in range(n+1)]
R = [[] for _ in range(n+1)]
for _ in range(n-1):
    u, v, w = map(int, input().split())
    w %= 2
    L[u] += [[u, v, w]]
    R[v] += [[v, u, w]]
P = [[] for _ in range(2*n+2)]
P[1] += (L[1]+R[1])
L[1] = R[1] = []
for i in range(1, 2*n):
    for _, v, w in P[i]:
        P[i+2-w] += (L[v]+R[v])
        L[v] = R[v] = []
A = []
for p in P[1::2]: A += p
B = set([u for u, *_ in A])
for i in range(1, n+1): print(1 if i in B else 0)
### BUGGY CODE ###

from sys import stdin, setrecursionlimit as srl
from threading import stack_size, Thread
srl(int(1e9)+7)
stack_size(int(1e8))

def f(d):
    ans = 0
    if sum(d)==0:
        return 0
    try:
        return stored[(d[0],d[1],d[2])]
    except:
        pass
    ans += n/(d[0]+d[1]+d[2])
    if d[0]:
        x = d[0]/(d[0]+d[1]+d[2])
        ans += x*f([d[0]-1,d[1],d[2]])
    if d[1]:
        x = d[1]/(d[0]+d[1]+d[2])
        ans += x*f([d[0]+1,d[1]-1,d[2]])
    if d[2]:
        x = d[2]/(d[0]+d[1]+d[2])
        ans += x*f([d[0],d[1]+1,d[2]-1])
    stored[(d[0],d[1],d[2])] = ans
    return ans
 
 
n = int(input())
a = list(map(int,input().split()))
d = [0 for i in range(3)]
stored = {}
 
for i in a:
    d[i-1] +=1

print(f(d))

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
d = [0 for i in range(3)]
dp = [[[0 for i in range(n+1)] for j in range(n+1)] for k in range(n+1)] 
for i in a:
    d[i-1] +=1
for k in range(n+1):
    for j in range(n+1):
        for i in range(n+1):
            if i+j+k==0 or i+j+k>n:
                continue
            ans = n/(i+j+k)
            x = i/(i+j+k)
            if x:
                ans += x*dp[k][j][i-1]
            x = j/(i+j+k)
            if x:
                ans += x*dp[k][j-1][i+1]
            x = k/(i+j+k)
            if x:
                ans += x*dp[k-1][j+1][i]
            dp[k][j][i] = ans
print(dp[d[2]][d[1]][d[0]])
### BUGGY CODE ###

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

ans = 0
for i in range(len(A)):
    for j in range(i + 1, len(A)):
        ans = (ans + (A[i] * A[j]) % 1000000007) % 1000000007
print(ans)

### FIXED CODE ###

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

sum_a  = sum(A)
ans = 0
for i in range(len(A)):
    sum_a -= A[i]
    ans = (ans + (A[i] * sum_a) % 1000000007) % 1000000007
print(ans)
### BUGGY CODE ###

import fractions
from functools import reduce
import copy
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
n=int(input())
a_o=list(map(int,input().split()))
g=[1]*n
for i in range(n):
  a=copy.copy(a_o)
  a.pop(i)
  g[i]=gcd_list(a)
print(max(g))

### FIXED CODE ###

def gcd(x, y):
  if y == 0:
    return x
  else:
    return gcd(y, x % y) #再帰定義
n=int(input())
a=list(map(int,input().split()))
l=[0]*n
r=[0]*n
for i in range(1,n):
  if i==1:
    l[1]=a[0]
    r[-2]=a[-1]
  else:
    l[i]=gcd(l[i-1],a[i-1])
    r[-i-1]=gcd(r[-i],a[-i])
g=[0]*n
for i in range(n):
  if l[i]==0 or r[i]==0:
    g[i]=l[i]+r[i]
  else:
    g[i]=gcd(l[i],r[i])
print(max(g))
### BUGGY CODE ###

N = int(input())
S = input()
cnt = 0
for i in range(1000):
    l = list()
    l.append(i // 100)
    l.append((i // 10) % 10)
    l.append(i % 10)
    f = 0
    for j in range(N):
        if int(S[j]) == l[f]:
            f += 1
        if f == 3:
            break
    if f == 3:
        cnt += 1
print(cnt)

### FIXED CODE ###

N = int(input())
S = input()
cnt = 0
for i in range(1000):
    num = ''
    num += str(i // 100)
    num += str((i // 10) % 10)
    num += str(i % 10)
    j = 0
    for n in range(N):
        if S[n] == num[j]:
            j += 1
        if j == 3:
            break
    if j == 3:
        cnt += 1
print(cnt)
### BUGGY CODE ###

import sys

# input処理を高速化する
input = sys.stdin.readline

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

    # dp[i][j] := 最初の i 枚のコインを投げたときに、表が j 枚となる確率
    # 次のコインが表: dp[i+1][j+1] += dp[i][j]∗p[i]
    # 次のコインが裏: dp[i+1][j] += dp[i][j]∗(1.0−p[i])
    dp = [[0] * (N+1) for i in range(N+1)]

    # 初期条件
    dp[0][0] = 1.0

    for i in range(N):
        for j in range(N):
            dp[i+1][j+1] += dp[i][j] * lst_p[i]
            dp[i+1][j] += dp[i][j] * (1.0 - lst_p[i])
    
    ans = 0
    for i in range((N+1)//2, N+1):
        ans += dp[N][i]

    print(ans)

main()

### FIXED CODE ###

import sys

# input処理を高速化する
input = sys.stdin.readline

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

    # dp[i][j] := 最初の i 枚のコインを投げたときに、表が j 枚となる確率
    # 次のコインが表: dp[i+1][j+1] += dp[i][j]∗p[i]
    # 次のコインが裏: dp[i+1][j] += dp[i][j]∗(1.0−p[i])
    dp = [[0] * (N+1) for i in range(N+1)]

    # 初期条件
    dp[0][0] = 1.0

    for i in range(N):
        for j in range(N):
            dp[i+1][j+1] += dp[i][j] * lst_p[i]
            dp[i+1][j] += dp[i][j] * (1.0 - lst_p[i])
    
    ans = 0
    for i in range((N+1)//2, N+1):
        ans += dp[N][i]

    print(ans)

main()
### BUGGY CODE ###

def main():
  N,P = map(int,input().split())
  S = list(map(int,list(input())))
  S=S[::-1]
  ans = 0
  if P==2:
    l = [0,2,4,6,8]
    for i,s in enumerate(S):
      if s in l:
        ans+=N-i
  elif P==5:
    l=[0,5]
    for i,s in enumerate(S):
      if s in l:
        ans+=N-i

  else:
    l = [0]*P
    a=0
    for i in range(N):
      a+=(S[i]*10**i)%P
      a%=P
      l[a]+=1
    ans+=l[0]
    for i in l:
      ans+=i*(i-1)//2

  print(ans)
  
main()

### FIXED CODE ###

def main():
  N,P = map(int,input().split())
  S = list(map(int,list(input())))
  S=S[::-1]
  ans = 0
  if P==2:
    l = [0,2,4,6,8]
    for i,s in enumerate(S):
      if s in l:
        ans+=N-i
  elif P==5:
    l=[0,5]
    for i,s in enumerate(S):
      if s in l:
        ans+=N-i

  else:
    l = [0]*P
    a=0
    for i in range(N):
      b = pow(10,i,P)
      b *= S[i]
      b %= P
      a+=b
      a%=P
      l[a]+=1
    ans+=l[0]
    for i in l:
      ans+=i*(i-1)//2

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

def dfs(p, c, s):
    if c==n:
        return not s
    if p==-1:
        return 0
    if memo[s][p][c] != -1:
        return memo[s][p][c]
    ret = 0
    for i in xrange(min(p, s), -1, -1):
        ret += dfs(i-1, c+1, s-i)
    memo[s][p][c] = ret
    return ret

while 1:
    n, s = map(int, raw_input().split())
    if n==0:
        break
    memo = [[[-1]*(n+1) for i in xrange(101)] for j in xrange(s+1)]
    print dfs(min(s, 100), 0, s)

### FIXED CODE ###

dp = [[0]*(1001) for _ in xrange(10)]
dp[0][0] = 1
for i in xrange(101):
    si1 = 1001-i
    for k in xrange(9, 0, -1):
        dp_k = dp[k]; dp_k1 = dp[k-1]
        for j in xrange(si1):
            dp_k[i+j] += dp_k1[j]
while 1:
    n, s = map(int, raw_input().split())
    if n==0:
        exit(0)
    print dp[n][s]