Harryxun/stf_run huggingface dataset:
import sys
input = sys.stdin.readline

N, W = map(int, input().split())
wv = [[int(i) for i in input().split()] for _ in range(N)]

wv.sort()
s, t = 0, 0
ns, nt = 0, 0
for i in range(N) :
    if s + wv[i][0] <= W :
        s += wv[i][0]
        ns += 1
    else :
        break
for i in range(N-1, -1, -1) :
    if t + wv[i][0] <= W :
        t += wv[i][0]
        nt += 1
    else :
        break
        
if ns == nt :
    wv.sort(key=lambda x: x[1], reverse=True)
    ret = 0
    for w, v in wv :
        if w < W :
            ret += v
            W -= w
    print(ret)
else :
    dp = [[0] * (W + 1) for _ in range(N + 1)]

    for i in range(1, N + 1) :
        w, v = wv[i-1]
        for j in range(W+1) :
            if j < w :
                dp[i][j] = dp[i-1][j]
            else :
                dp[i][j] = max(dp[i-1][j], dp[i-1][j - w] + v)
                
    print(dp[N][W])


### FIXED CODE ###

import sys
input = sys.stdin.readline

N, W = map(int, input().split())
wv = [[int(i) for i in input().split()] for _ in range(N)]

s = [[] for _ in range(4)]
w0 = wv[0][0]
for w, v in wv :
    s[w-w0].append(v)
for i in range(4) :
    s[i].sort(reverse=True)
    s[i] = [0] + s[i]
    for j in range(1, len(s[i])) :
        s[i][j] += s[i][j-1]

M = 0
for i0 in range(len(s[0])) :
    for i1 in range(len(s[1])) :
        for i2 in range(len(s[2])) :
            for i3 in range(len(s[3])) :
                if i0*w0+i1*(w0+1)+i2*(w0+2)+i3*(w0+3) <= W :
                    M = max(M, s[0][i0]+s[1][i1]+s[2][i2]+s[3][i3])
                    
print(M)
n=int(input())
import collections
c=collections.Counter()
def gcd(x,y):
    if y==0:
        return x
    else:
        return gcd(y,x%y)
mod=10**9+7
for _ in range(n):
    a,b=map(int,input().split())
    g=abs(gcd(a,b))
    a//=g
    b//=g
    c[(a,b)]+=1
ans=1
s=set()
for i,j in c:
    if (i,j) not in s:
        s.add((i,j))
        s.add((-i,-j))
        s.add((-j,i))
        s.add((j,-i))
        ans*=(pow(2,c[(i,j)]+c[(-i,-j)],mod)+pow(2,c[(j,-i)]+c[(-j,i)],mod)-1)%mod
print(ans-1)

### FIXED CODE ###

import collections
from math import gcd
import sys
input=sys.stdin.readline
def main():
    n=int(input())
    c=collections.Counter()
    mod=10**9+7
    for _ in range(n):
        a,b=map(int,input().split())
        g=abs(gcd(a,b))
        if g==0:
            g=1
        a//=g
        b//=g
        c[(a,b)]+=1
    ans=1
    s=set()
    for i,j in c:
        if (i,j)==(0,0):
            continue
        if (i,j) not in s:
            s.add((i,j))
            s.add((-i,-j))
            s.add((-j,i))
            s.add((j,-i))
            ans*=(pow(2,c[(i,j)]+c[(-i,-j)],mod)+pow(2,c[(j,-i)]+c[(-j,i)],mod)-1)%mod
    print((ans-1+c[(0,0)])%mod)

if __name__ == "__main__":
    main()
3 1
10 20 10

### FIXED CODE ###

n,k=map(int,input().split())
h=list(map(int,input().split()))
c=[0]*n
for i in range(1,n):
    c[i]=min([cj+abs(h[i]-hj) for cj,hj in zip(c[max(0,i-k):i],h[max(0,i-k):i])])
print(c[-1])
s=input()
if len(s)%2:
  s.reverse()
print(s)

### FIXED CODE ###

s=input()
if len(s)%2:
  s = s[::-1]
print(s)
n=int(input())
a=list(map(int,input().split()))]
if 0 not in a:
    ans=1
    for i in range(n):
        ans*=a[i]
        if ans>10**18:
        print("-1")
        exit()
    print(ans)
else:
    print("0")

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
if 0 in a:
    print("0")
    exit()
else:
    ans=1
    for i in range(n):
        ans*=a[i]
        if ans>10**18:
            print("-1")
            exit()
    print(ans)
n = int(input())
h = list(map(int, input().split()))
flag = 0
result = 1
for i in range(n-1):
	if h[i]==h[i+1]+1 and flag==0:
		flag=1
	elif h[i]==h[i+1] and flag==1:
	elif h[i]<=h[i+1]:
		flag=0
	else:
		result = 0
if result:
	print("Yes")
else:
	print("No")

### FIXED CODE ###

n = int(input())
h = list(map(int, input().split()))
flag = 0
result = 1
for i in range(n-1):
	if h[i]==h[i+1]+1 and flag==0:
		flag=1
	elif h[i]==h[i+1] and flag==1:
		continue
	elif h[i]<=h[i+1]:
		flag=0
	else:
		result = 0
if result:
	print("Yes")
else:
	print("No")
import sys
input = sys.stdin.readline

s=input()
l=len(s)
mod = 10**9+7
dp=[[0]*13 for _ in range(l+1)]

dp[0][0]=1 #初期値設定
for i in range(l):
  if s[i]!="?":
    for k in range(13):
      dp[i+1][(k*10+int(s[i]))%13]+=dp[i][k]
  else:
    for j in range(10):
      for k in range(13):
        dp[i+1][(k*10+j)%13]+=dp[i][k]
        
print(dp[-1][5]%mod)

### FIXED CODE ###

def main():
  s=input()
  l=len(s)
  mod = 10**9+7
  dp=[[0]*13 for _ in range(l+1)]
  dp[0][0]=1 #初期値設定
  for i in range(l):
    if s[i]!="?":
      for k in range(13):
        dp[i+1][(k*10+int(s[i]))%13]+=dp[i][k]%mod
    else:
      for j in range(10):
        for k in range(13):
          dp[i+1][(k*10+j)%13]+=dp[i][k]%mod

  print(dp[-1][5]%mod)

if __name__ == "__main__":
    main()
n,m=map(int, input().split())
x=[int(i) for i in input().split()]
x.sort()
dist = abs(x[-1]-x[0])
diff = []

for i in range(m-1):
    diff.append([abs(x[i]-x[i+1]),i])

diff.sort(key = lambda x:x[0],reverse = True)
for i in range(n-1):
    dist-=diff[i][0]
print(dist)


### FIXED CODE ###

import itertools
n,m=map(int, input().split())
x=[int(i) for i in input().split()]
x.sort()
if(n>=m):
    print(0)
    exit()
dist = abs(x[-1]-x[0])

diff = []

for i in range(m-1):
    diff.append([abs(x[i]-x[i+1]),i])

diff.sort(key = lambda x:x[0],reverse = True)
for i in range(n-1):
    dist-=diff[i][0]
print(dist)
from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
#import math
#import time
#import random  # randome is not available at Codeforces
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def StoI():
    return [ord(i)-97 for i in input()]
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
#ts=time.time()
#sys.setrecursionlimit(10**6)
input=lambda: sys.stdin.readline().rstrip()
import sys
sys.setrecursionlimit(10**7)

show_flg=False
show_flg=True

n,m=LI()
a=LI()
g=[[] for _ in range(n)]
ans=0
cmp=0
for i in range(m):
    x,y=LI()
    g[x].append(y)
    g[y].append(x)

rest=[]
q=[]
v=[-1]*n

for i in range(n):
    if v[i]>0:
        continue
    p=[]
    cost=[]
    p.append(i)
    heappush(cost,a[i])
    while p:
        c=p.pop()
        v[c]=a[c]
        for nb in g[c]:
            if v[nb]==-1:
                p.append(nb)
                v[nb]=a[nb]
                heappush(cost,a[nb])
    ans+=heappop(cost)
    cmp+=1
    while cost:
        heappush(rest,heappop(cost))
    
if len(rest)<cmp-1:
    ans="Impossible"
    a=[0]
    a[1]
elif cmp==1:
    ans=0
    a=[0]
    a[1]
else:
    for i in range(cmp-2):
        ans+=heappop(rest)

print(ans)


### FIXED CODE ###

from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
#import math
#import time
#import random  # randome is not available at Codeforces
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def StoI():
    return [ord(i)-97 for i in input()]
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
#ts=time.time()
#sys.setrecursionlimit(10**6)
input=lambda: sys.stdin.readline().rstrip()
import sys
sys.setrecursionlimit(10**7)

show_flg=False
show_flg=True


n,m=LI()
a=LI()
g=[[] for _ in range(n)]
ans=0
cmp=0
for i in range(m):
    x,y=LI()
    g[x].append(y)
    g[y].append(x)

rest=[]
q=[]
v=[-1]*n

for i in range(n):
    if v[i]!=-1:
        continue
    p=[]
    cost=[]
    p.append(i)
    heappush(cost,a[i])
    while p:
        c=p.pop()
        v[c]=a[c]
        for nb in g[c]:
            if v[nb]==-1:
                p.append(nb)
                v[nb]=a[nb]
                heappush(cost,a[nb])
    ans+=heappop(cost)
    cmp+=1
    while cost:
        heappush(rest,heappop(cost))

if cmp==1:
    ans=0
elif len(rest)<cmp-2:
    ans="Impossible"
else:# cmp=n-m, n-m-1 edges needed, 2n-2m-2 vers, 2n-2m-2-cmp=n-m-2=cmp-2
    for i in range(cmp-2):
        ans+=heappop(rest)

print(ans)
str = [input() for i in range(2)]
nums = list(map(int, str[1].split()))
maxCount = 0
idx = 0
index = 0
count = 0

for i in range(len(nums)-index-1):
    if nums[index+i] >= nums[index+i+1]:
        count = count + 1
        idx = index+i+1
        index = index + 1
        if count >= maxCount:
            maxCount = count
    else:
        idx = 0
        count = 0
        break
        
print(maxCount)
        


### FIXED CODE ###

str = [input() for i in range(2)]
nums = list(map(int, str[1].split()))
maxCount = 0
index = -1
count = 0

for i in range(len(nums)-1):
    if nums[i] >= nums[i+1]:
        count = count + 1
        if count >= maxCount:
            maxCount = count
    else:
        count = 0
        
print(maxCount)
n, a, b = map(int, input().split())
x = n - (a + b)
y = x % b
print(a + y)

### FIXED CODE ###

n, a, b = map(int, input().split())
ans = n // (a + b) * a
x = n % (a + b)
ans += min(a, x)
print(ans)
n,k = map(int,input().split())
h = list(map(int,input.split()))
dp = [1000000000]＊n

### FIXED CODE ###

N,K = map(int,input().split())
h = list(map(int,input().split()))
dp = [10**15+1 for i in range(N)]
dp[0] = 0
for i in range(N):
    for j in range(1,K+1):
        if i+j<N:
            dp[i+j] = min(dp[i+j],dp[i]+abs(h[i]-h[i+j]))
        
print(dp[-1])
user1 = eval(input())
user2 = eval(input())
user = list(eval(input().replace(" ",",")))
sum = 0
for i in user:
    sum = sum + i
print(user1 - sum)

### FIXED CODE ###

N,M = (input()).split()
task = input().split()
list1 = []
sum = 0
for i in task:
    list1.append(i)
for j in list1:
    sum = sum + int(j)
result = int(N) - sum
if result < 0:
    print(-1)
else:
    print(result)
import math
N = int(input())
A = list(map(int,input().split()))
mod = 10**9+7

kbs = A[0]
for i in range(1,N):
  kbs = kbs*A[i]*pow(math.gcd(kbs,A[i]),mod-2,mod)
  kbs %= mod
  
ans = 0
for i in range(N):
  ans += kbs*pow(A[i],mod-2,mod)
  ans %= mod
print(ans)    

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
MOD = 10**9 + 7

def gcd(n, m):
    if m == 0:
        return n
    return gcd(m, n % m)

def lcm(a, b):
    return a * b // gcd(a, b)

L = 1
for a in A:
    L = lcm(L, a)

L %= MOD
coef = 0
for a in A:
    coef += pow(a, MOD - 2, MOD)
print((L * coef) % MOD)
N = input()
N = int(N[-1])
if N == 3:
    print("bon")
elif N in [0, 1, 6, 8]:
    print("pon")
else:
    p

### FIXED CODE ###

def maiin(S):
    N = int(S[-1])

    if N == 3:
        print("bon")
    elif N in [0, 1, 6, 8]:
        print("pon")
    else:
        print("hon")

if __name__ == "__main__":
    maiin(input())
m, d = map(int, input().split())
if m < 4 or d < 22:
  print("0")
else:
  res=0
  for i in range(22, d+1):
    d1, d2 = int(d/10), d%10
    res += 1 if d1*d2<=m else 0
   print(res)

### FIXED CODE ###

m, d = map(int, input().split())
if m < 4 or d < 22:
  print("0")
else:
  res=0
  for i in range(22, d+1):
    d1, d2 = int(i/10), i%10
    if d2 < 2:
      continue
    res += 1 if d1*d2<=m else 0
  print(res)
import re
import copy
pattern = r'([0-9])'
repatter = re.compile(pattern)

n = str(input())
text = input()

*lists, = text.split(" ")
lists2 = copy.copy(lists)
lists3 = copy.copy(lists)


# バブルソート
def bubble_sort(a):
    flag = 1
    i = 0
    while flag:
        flag = 0
        for j in range(n-1, i, -1):
            x = repatter.findall(a[j])
            y = repatter.findall(a[j-1])
            if x < y:
                a[j], a[j-1] = a[j-1], a[j]
                flag = 1
        i += 1
    print(*a)
    print("Stable")


# 選択ソート
def select_sort(a):
    for i in range(n):
        min_j = i
        for j in range(i+1, n):
            x = repatter.findall(a[j])
            y = repatter.findall(a[min_j])
            if x < y:
                min_j = j
        a[i], a[min_j] = a[min_j], a[i]
    print(*a)


def isStable(before, after):
    for i in range(n):
        for j in range(i+1, n):
            for a in range(n):
                for b in range(a+1, n):
                    x = repatter.findall(before[i])
                    y = repatter.findall(before[j])
                    if x == y and before[i] == after[b] and before[j] == after[a]:
                        print("Not stable")


bubble_sort(lists)
select_sort(lists2)
isStable(lists3, lists2)


### FIXED CODE ###

import re
import copy
pattern = r'([0-9])'
repatter = re.compile(pattern)

n = int(input())
text = input()

*lists, = text.split(" ")
lists2 = copy.copy(lists)
lists3 = copy.copy(lists)


# バブルソート
def bubble_sort(a):
    flag = 1
    i = 0
    while flag:
        flag = 0
        for j in range(n-1, i, -1):
            x = repatter.findall(a[j])
            y = repatter.findall(a[j-1])
            if x < y:
                a[j], a[j-1] = a[j-1], a[j]
                flag = 1
        i += 1
    print(*a)
    print("Stable")


# 選択ソート
def select_sort(a):
    for i in range(n):
        min_j = i
        for j in range(i+1, n):
            x = repatter.findall(a[j])
            y = repatter.findall(a[min_j])
            if x < y:
                min_j = j
        a[i], a[min_j] = a[min_j], a[i]
    print(*a)


def isStable(before, after):
    flag = True
    for i in range(n):
        for j in range(i+1, n):
            for a in range(n):
                for b in range(a+1, n):
                    x = repatter.findall(before[i])
                    y = repatter.findall(before[j])
                    if x == y and before[i] == after[b] and before[j] == after[a]:
                        flag = False
    if flag is True:
        print("Stable")
    else:
        print("Not stable")


bubble_sort(lists)
select_sort(lists2)
isStable(lists3, lists2)
from collections import deque

def main():
    n, m = map(int, input().split())

    dag = [[] for _ in range(n+1)]
    for _ in range(m):
        src, dst = map(int, input().split())
        dag[src].append(dst)
    for arr in dag:
        arr = sorted(arr)

    # Distance of longest path starting at node i
    dists = [0] * (n+1)

    def longest(v):
        if dists[v]:
            return dists[v]
        for to in dag[v]:
            dists[v] = max(dists[i], longest(to) + 1)
        return dists[v]

    ans = 0
    for i in range(1, n+1):
        ans = max(ans, longest(i))

    print(ans)


if __name__ == '__main__':
    main()



### FIXED CODE ###

from collections import deque

def main():
    n, m = map(int, input().split())
    graph = [[] for _ in range(n+1)]
    parents = [0] * (n+1)
    for _ in range(m):
        src, dst = map(int, input().split())
        graph[src].append(dst)
        parents[dst] += 1

    q = deque()
    for i in range(1, n+1):
        if parents[i] == 0:
            q.append(i)

    dists = [0] * (n+1)
    for i in q:
        dists[0] = 0

    while q:
        at = q.popleft()
        for to in graph[at]:
            parents[to] -= 1
            if parents[to] == 0:
                q.append(to)
                dists[to] = dists[at] + 1

    print(max(dists[1:]))


if __name__ == '__main__':
    main()
import sys
sys.setrecursionlimit(10000)

def tasu(a):
  if a == 1:
    return 1
  else:
    return a + tasu(a-1)
  
N, K = map(int, input().split())
A_list = list(map(int, input().split()))
count = 0

for i in range(N):
  for j in range(N):
    if i == j:
      continue
    elif (i<j) & (A_list[i] > A_list[j]):
      count += tasu(K)
    elif (i>j) & (A_list[i] > A_list[j]):
      count += tasu(K - 1)
print(count%(10**9 + 7))

### FIXED CODE ###

def tasu(a):
  out = (a*(a-1))//2 + a
  return out%(10**9 + 7)
    
  
N, K = map(int, input().split())
A_list = list(map(int, input().split()))
count = 0
count1 = 0

for i in range(N):
  for j in range(N):
    if i == j:
      continue
    elif (i<j) & (A_list[i] > A_list[j]):
      count += 1
    elif (i>j) & (A_list[i] > A_list[j]):
      count1 += 1

ans = (tasu(K) * count) + (tasu(K-1) * count1) 
print(ans%(10**9 + 7))
from sys import stdin
a = stdin.readline().rstrip()
print(a+a**2+a**3)

### FIXED CODE ###

from sys import stdin
a = int(stdin.readline().rstrip())
print(a+a**2+a**3)
l = [a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z]
s = input()
for i in range(25):
  if s = l[i]:
    print(l[i+1])

### FIXED CODE ###

l = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
s = input()
for i in range(25):
  if s == l[i]:
    print(l[i+1])
for i in range(10):
      print str(i) + 'x' + str(i)+'='+str(i*i)

### FIXED CODE ###

for i in range(1,10):
        for j in range(1,10):
                print(str(i) + 'x' + str(j)+'='+str(i*j))
def comb(n, k):
    ans = 1
    for i in range(k):
        ans *= (n-i)
    for i in range(k):
        ans //= (k-i)
    return ans

def count(n, k):
    if k == 0:
        return 1
    if int(n) == 0:
        return 0
    if n[0] == "0":
        return count(n[1:], k)
    return count(n[1:], k-1) + comb(len(n)-1, k)*9**(k) + (int(n[0])-1)*comb(len(n)-1, k-1)*9**(k-1)

n = input()
k = int(input())
print(count(n, k))

### FIXED CODE ###

def comb(n, k):
    ans = 1
    for i in range(k):
        ans *= (n-i)
    for i in range(k):
        ans //= (k-i)
    return ans

def count(n, k):
    if len(n) < k:
        return 0
    if k == 0:
        return 1
    if int(n) == 0:
        return 0
    if n[0] == "0":
        return count(n[1:], k)
    return count(n[1:], k-1) + comb(len(n)-1, k)*9**(k) + (int(n[0])-1)*comb(len(n)-1, k-1)*9**(k-1)

n = input()
k = int(input())
print(count(n, k))
N = int(input())
s = [int(input()) for _ in range(N)]
s0 = sorted(s)[::-1]
tot = sum(s)
i = 0
while tot%10 == 0:
    tot -= s[i]
    i += 1
print(tot)

### FIXED CODE ###

a=sorted([int(input()) for _ in[0]*int(input())]);b=sum(a)
for x in a:
    if b%10!=0:break
    elif x%10!=0:b-=x
print([0,b][b%10!=0])
n=int(input())
a=[int(input()) for _ in range(n)]
as=sorted(a)
m=as[-1]
for i in range(n):
    print(m if m!=a[i] else a[-2])

### FIXED CODE ###

n=int(input())
a=[int(input()) for _ in range(n)]
a1=sorted(a)
m=a1[-1]
for i in range(n):
    print(m if m!=a[i] else a1[-2])
import sys
N, M = map(int, sys.stdin.readline().rstrip().split())
h_i = [int(x) for x in sys.stdin.readline().rstrip().split()]
ab = [list(map(int, sys.stdin.readline().rstrip().split())) for _ in range(M)]

J = [1 for i in range(N)]
for li in ab:
  if h_i[li[0]] < h_i[li[1]]:
    J[li[0]] = 0
  elif h_i[li[0]] == h_i[li[1]]:
    J[li[0]] = J[li[1]] = 0
  else:
    J[li[1]] = 0
print(J)

### FIXED CODE ###

import sys
N, M = map(int, sys.stdin.readline().rstrip().split())
h_i = [int(x) for x in sys.stdin.readline().rstrip().split()]
ab = [list(map(int, sys.stdin.readline().rstrip().split())) for _ in range(M)]
 
J = [1 for i in range(N)]
#print(ab,J)

for li in ab:
  #print(li)
  if h_i[li[0]-1] < h_i[li[1]-1]:
    J[li[0]-1] = 0
  elif h_i[li[0]-1] == h_i[li[1]-1]:
    J[li[0]-1] = J[li[1]-1] = 0
  else:
    J[li[1]-1] = 0
print(J.count(1))
A = int(input())
B = int(input())
if A < 9 and B < 9:
  print('Yay!')
else:
  print(':(')

### FIXED CODE ###

[A, B] = [int(x) for x in input().split()]
if A < 9 and B < 9:
  print('Yay!')
else:
  print(':(')
a, b = map(int, input().split())

if a * b % 2 == 0
    print("Even")
else:
    print("Odd")


### FIXED CODE ###

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

if (a * b) % 2 == 0:
    print("Even")
else:
    print("Odd")
n=int(input())
n2=0
if n%2==1:
	print(0)
else:
	n2=int(n/2)
	ans=0
	while n2>0:
		n2=int(n2//5)
		ans+=n2
print(ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline

def main():
    n=int(input())
    cnt=5
    ans=0
    if n%2==0:
        n=n//2
        while cnt<=n:
            ans+=n//cnt
            cnt*=5
    print(ans)                
    
if __name__ == '__main__':
    main()
def read():
	return [int(i) for i in input().split(" ")]
N = int(input())
T = read()
A = read()
L = [0] * N
unknowL = [0] * N
tempT, tempA = 0, 0
for i in range(N):
	if(T[i] > tempT):
		tempT = L[i] = T[i]
	else:
		unknowL[i] = T[i]
for i in range(N-1, -1, -1):
	if(A[i] > tempA):
		if(L[i] != 0 and L[i] != A[i]):
			print(0)
			exit()
		tempA = L[i] = A[i]
		unknowL[i] = 0
	else:
		unknowL[i] = min(unknowL[i], A[i])
P = 1 
for i in unknowL:
	if(i != 0):
		P *= i	
print(P % (10**9 +7))

### FIXED CODE ###

import re
s = input()
pattern = re.compile(r'C.*F')
match = pattern.search(s)
if match:
	print('Yes')
else:
	print('No')
while (1):
    n=int(raw_input())
    if n==0:
        break
    else:
        top=-1
        fault=[0]
        S=0
        for i in range(n/2): #i=0,2,... is othello i=1,3,...is donothing
            s=int(raw_input()) #oddstone
            if top!=s: 
                fault.append(i)
                top=s
            s=int(raw_input()) #evenstone
            if top!=s:
                fault.pop()
                top=s
        i=len(fault)-1
        while i>0:
            S=S+(fault[i]-fault[i-1])*2
            i=i-2
        if not top:
            S=2*(n/2)-S
        if n%2==1:
            s=int(raw_input())
            S=S+(1-s)
        print S

### FIXED CODE ###

while (1):
    n=int(raw_input())
    if n==0:
        break
    else:
        top=-1
        fault=[0]
        S=0
        for i in range(n/2): #i=0,2,... is othello i=1,3,...is donothing
            s=int(raw_input()) #oddstone
            if top!=s: 
                fault.append(i)
                top=s
            s=int(raw_input()) #evenstone
            if top!=s:
                fault.pop()
                top=s
            if fault==[]:
                fault=[0]
        i=len(fault)-1
        while i>0:
            S=S+(fault[i]-fault[i-1])*2
            i=i-2
        if not top:
            S=2*(n/2)-S
        if n%2==1:
            s=int(raw_input())
            S=S+(1-s)
        print S
import sys
w = raw_input().lower()

for t in stdin.sys.read().split():
    if  t == "END_OF_TEXT":
        break
    t.lower()
    count = 0
    if t == w:
        count += 1
    print count

### FIXED CODE ###

w = raw_input().lower()
sum = 0
while True:
    t = raw_input().split()
    if t[0] == "END_OF_TEXT":
        break
    else:
        for ti in t:
            if ti.lower() == w:
                sum += 1
print sum
a = int(input())
b = int(input())

if a > 8 or b > 8:
	print(':(')
else:
	print('Yey!')

### FIXED CODE ###

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

if a > 8 or b > 8:
	print(':(')
else:
	print('Yay!')
n = input()
b = ['{0:b}'.format(int(x)) for x in input().split()]
a = 0
for c in b:
    m = re.match(r'.*(10*)$',c)
    if m is None:
      continue
    a = max(a,len(m[1])-1)
print(a)

### FIXED CODE ###

n = input()
b = [int(x) for x in input().split()]
c = 0
flg = True
while flg:
    for i,x in enumerate(b):
        if x!=0 and x%2 != 0:
            flg=False
            break
        b[i] = int(x/2)
    c += 1
print(c-1)