n = gets.chomp.to_i
str = gets.chomp

i = 0
c = 0
while i * n < str.length do
  i+=1
  next if i*n < 3 || i*n >= str.length
  if str[i*n - 1] == str[i*n - 2] &&
    str[i*n - 1] == str[i*n - 3]
    c += 1
  end
end
puts c

n=gets.to_i
s=gets.chomp
l=s.size
c=0
p
for i in (n..l-1).step(n) do
  c+=1 if s[i-1]==s[i-2] and s[i-1]==s[i-3]
end
p c

n = gets.to_i
s = gets.chomp
c=0;
for i in (n..s.length-1).step(n)
	if(s[i-1]==s[i-2] && s[i-3]==s[i-1])
		c+=1;
	end
end
p c

n = gets.to_i
ar = gets.chomp
c = 0;
for i in (n..ar.length-1).step(n)
	if(ar[i-1]==ar[i-2] && ar[i-1]==ar[i-3])
		c+=1
	end
end
p c;

n = gets.to_i
s = gets.chomp
i = n
c = 0
while i < s.size
  c += 1 if s[i - 1] == s[i - 2] && s[i - 2] == s[i - 3]
  i += n
end
puts c

n = gets.to_i
puts gets.chomp.slice(1,2000).chars.each_slice(n).select{|x|
  x.length == n && x[-4] == x[-3] && x[-3] == x[-2]
}.length

n = gets.to_i
seq = gets.chomp!
ret = 0
for i in 0...seq.size
  if i >= 4 && i % n == 0
    if seq[i-1] == seq[i-2] && seq[i-2] == seq[i-3]
      ret += 1
    end
  end
end
puts ret

n = STDIN.readline.to_i
s = STDIN.readline.strip
pos = n
count = 0
while pos < s.length
	count += 1 if s[pos-1] == s[pos-2] and s[pos-2] == s[pos-3]
	pos += n
end
puts count

def run
  n = $stdin.gets.to_i
  a = $stdin.gets.chomp.split(//)

  cnt = 0
  cur = 0
  while cur < a.length
    cnt += 1 if cur >= 3 and a[cur - 1] == a[cur - 2] and a[cur - 1] == a[cur - 3]
    cur += n
  end

  puts cnt
end

run if $0 == __FILE__

n = gets.to_i
s = gets.chomp
ans = 0
(n...s.size).step(n).each{|i| ans += 1 if s[i-3]==s[i-2] and s[i-2]==s[i-1]}
puts ans

n = gets.to_i
s = gets.chomp
r = 0
i = n
while i < s.length
  if (s[i-3,3] == 'aaa') or (s[i-3,3] == 'bbb')
    r += 1
  end
  i += n
end
puts "#{r}"

n = gets.to_i
s = gets.chomp
c=0;
for i in (n..s.length).step(n)
	if(s[i-1]==s[i-2] && s[i-3]==s[i-1])
		c+=1;
	end
end
p c

def run
  n = $stdin.gets.to_i
  a = $stdin.gets.split(//)

  cnt = 0
  cur = 0
  while cur < a.length
    cnt += 1 if cur >= 3 and a[cur - 1] == a[cur - 2] and a[cur - 1] == a[cur - 3]
    cur += n
  end

  puts cnt
end

run if $0 == __FILE__

n=gets.to_i
s=gets.chomp
l=s.size
c=0
for i in (n..l-1).step(n) do
  c+=1 if s[i-1]==s[i-2] and s[i-1]==s[i-2]
end
p c

n=gets.to_i
s=gets.chomp
l=s.size
c=0
for i in (n..l).step(n) do
  c+=1 if s[i-1]==s[i-2] and s[i-1]==s[i-2]
end
p c


times = gets.to_i

(1..times).each do |i|
  array_size = gets.to_i

  a = Array.new(array_size)
  a = gets.split(/\s+/).reverse.join(" ")
  puts a
end

gets.to_i.times{gets
puts gets.split.reverse.join ' '}

T = gets.to_i

T.times do
  n = gets.to_i
  a = gets.split.map(&:to_i)

  puts a.reverse.join(' ')
end

gets.to_i.times do
  n=gets.to_i
  a=gets.split(" ").map(&:to_i)
  a.reverse!
  puts a.join(" ")
end

t = gets.to_i
t.times do
    n = gets.to_i
    a = gets.split.map &:to_i
    puts a.reverse.join(" ")
end


gets.to_i.times{n=gets.to_i;a=(gets.split.map &:to_i).sort;x=s=i=0;(x+=s-a[i]*i;s+=a[i];i+=1)while i<n;p x+a[-1]}

def I()gets.split.map &:to_i end
I()[0].times{n,=I();a=I().sort;x=s=i=0;(x+=s-a[i]*i;s+=a[i];i+=1)while i<n;p x+a[-1]}

def I
gets.split.map &:to_i
end
I()[0].times{n,=I();a=I().sort;x=s=i=0;(x+=s-a[i]*i;s+=a[i];i+=1)while i<n;p x+a[-1]}

gets.to_i.times{gets;a=gets.split.map &:to_i;r=i=0;for(x,y)in a.zip(a[1..])
(i+=1;r-=(y-x)*(i*(a.length-i)-1))if y
end;p r}


gets.to_i.times do
  n = gets.to_i
  ans = 0
  while n != 1 do
    if n % 2 == 0
      n = n / 2
      ans += 1
    elsif n % 3 == 0
      n = 2 * n / 3
      ans += 1
    elsif n % 5 == 0
      n = 4 * n / 5
      ans += 1
    else
      ans = -1
      break
    end
  end
  puts ans
end

# coding: utf-8

q = gets.to_i
q.times {
    n = gets.to_i
    break_noops = false
    loop_counter = 0
    while n > 1
        if n%2 == 0
            n /= 2
            loop_counter += 1
        elsif n%3 == 0
            n /= 3
            n *= 2
            loop_counter += 1
        elsif n%5 == 0
            n /= 5
            n *= 4
            loop_counter += 1
        else
            break_noops = true
            break
        end
    end

    if n == 1
        puts loop_counter
    else
        puts -1
    end
}

q = gets.to_i
q.times do
  n = gets.to_i
  cnt = 0
  while n != 1
    if n % 2 == 0
      n /= 2
    elsif n % 3 == 0
      n = 2*n/3
    elsif n % 5 == 0
      n = 4*n/5
    else
      break
    end
    cnt += 1
  end
  p n == 1 ? cnt : -1
end

def valid?(n)
  n % 3 == 0 || n % 5 == 0 || n % 2 == 0
end

def solve(n)
  steps = 0
  while valid?(n)
    n = if n % 2 == 0
          n / 2
        elsif n % 3 == 0
          (2 * n) / 3
        else
          (4 * n) / 5
        end
    steps += 1
  end
  n == 1 ? steps : -1
end

gets.strip.to_i.times do
  n = gets.strip.to_i
  puts solve(n)
end

queries = gets.chomp.to_i
while(queries > 0)
    num = gets.chomp.to_i
    count = 0
    while(num%2 == 0 || num%3 == 0 || num%5 == 0)
        if num%2 == 0
            num /= 2;
        elsif num%3 == 0
            num = (num/3)*2;
        else
            num = (num/5)*4
        end
        count += 1
    end
    queries -= 1
    puts -1 if num != 1
    puts count if num == 1
end


n = gets.chomp.to_i
(1..n).each do
    a,b,c = gets.chomp.split(" ").map(&:to_i)
    if a < c && b >= 2
        x = 1
    end
    if a >= c && b >= 1
        x = -1
    end
    if a < c && b == 1
        x = 1
    end
    # kari = a * b
    # if kari <= c
    #     y = -1
    # end
    amari = c % a
    kotae = c / a
    # if kari > c && amari == 0
    #     y = kotae
    # elsif kari > c && amari != 0
    #     y = kotae + 1
    # end
    if a >= c
        y = b
    elsif a < c && amari == 0 && b > kotae
        y = kotae + 1
    elsif a < c && amari == 0 && b == kotae
        y = -1
    elsif a < c && amari != 0 && b > kotae
        y = kotae + 1
    elsif a < c && amari != 0 && b == kotae
        y = -1
    elsif a < c && amari == 0 && b < kotae
        y = -1
    elsif a < c && amari != 0 && b < kotae
        y = -1
    end

    print x
    print " "
    print y
    print "\n"
end

t = gets.to_i
t.times do
    a, b, c = gets.split.map &:to_i

    if c <= a or b == 1
        x = -1
    else
        x = 1
    end

    if a*b <= c
        y = -1
    else
        y = b
    end

    puts "#{x} #{y}"
end

def run
  a, b, c = gets.chomp.split(" ").map(&:to_i)

  s = if a < c
    "1 "
  else
    "-1 "
  end

  if a * b > c
    s << "#{b}"
  else
    s << "-1"
  end
  puts s
end

def main
  t = gets.chomp.to_i

  t.times do
    run
  end
end

main

n = gets.chomp.to_i
(1..n).each do |i|
    a,b,c = gets.chomp.split(" ").map(&:to_i)
    if a < c && b >= 2
        x = 1
    end
    if a >= c && b >= 1
        x = -1
    end
    if a < c && b == 1
        x = 1
    end
    kari = a * b
    if kari <= c
        y = -1
    end
    if kari > c
        y = a
    end
    print x
    print " "
    print y
    print "\n"
end

n = gets.chomp.to_i
(1..n).each do
    a,b,c = gets.chomp.split(" ").map(&:to_i)
    if a < c && b >= 2
        x = 1
    end
    if a >= c && b >= 1
        x = -1
    end
    if a < c && b == 1
        x = 1
    end
    kari = a * b
    if kari <= c
        y = -1
    end
    if kari > c
        y = a
    end
    print x
    print " "
    print y
    print "\n"
end

n = gets.chomp.to_i
(1..n).each do
    a,b,c = gets.chomp.split(" ").map(&:to_i)
    if a < c && b >= 2
        x = 1
    end
    if a >= c && b >= 1
        x = -1
    end
    if a < c && b == 1
        x = 1
    end
    kari = a * b
    if kari <= c
        y = -1
    end
    amari = c % a
    kotae = c / a
    if kari > c && amari == 0
        y = kotae
    elsif kari > c && amari != 0
        y = kotae + 1
    end
    print x
    print " "
    print y
    print "\n"
end


#! ruby
# Try Codeforces
# author: Leonardone @ NEETSDKASU
############################################################
def gs() gets.chomp end
def gi() gets.to_i end
def gss() gs.split end
def gis() gss.map(&:to_i) end
def nmapf(n,f) n.times.map{ __send__ f } end
def ngs(n) nmapf n,:gs end
def ngi(n) nmapf n,:gi end
def ngss(n) nmapf n,:gss end
def ngis(n) nmapf n,:gis end
def arr2d(h,w,v=0) h.times.map{[v] * w} end
def for2p(hr,wr,&pr) hr.each{|i|wr.each{|j| yield(i,j)}} end
def nsum(n) n * (n + 1) / 2 end
def vcount(d,r=Hash.new(0)) d.inject(r){|m,e| m[e]+=1;m} end
############################################################

N = gi
S = gs

f = Hash.new 0

c = S.each_char.to_a.uniq.size

a = N
j = 0
k = 0
N.times do |i|
    ch = S[i]
    if f[ch] == 0
        k += 1
    end
    f[ch] += 1
    while f[S[j]] > 1 do
        f[S[j]] -= 1
        j += 1
    end
    a = [a, i - j].min if k == c
end

p a + 1

#!/usr/bin/ruby

require 'set'

n = gets.chomp.to_i
c = gets.chomp

h = Hash.new(0)
s = Set.new

for i in 0...n do
  s << c[i]
end
nd = s.size
iterr = 0
got = 0
ans = n
for iterl in 0...n do
  while iterr < n && got < nd do
    if h[ c[iterr] ] == 0
      got += 1
    end
    h[ c[iterr] ] += 1
    iterr += 1
  end
  if got < nd
    break
  end
  if iterr - iterl < ans
    ans = iterr - iterl
  end
  h[ c[iterl] ] -= 1
  if h[ c[iterl] ] == 0
    got -= 1
  end
end
puts ans

gets
house = gets.chomp

selected = Hash.new
house.each_char { |flat| selected[flat] = 0 }

if selected.length < 2
  puts selected.length
  exit
end

result = house.length
left, right = 0, 0

selected[house[0]] = 1
current = 1

while true do
  if current == selected.length
    result = 1+right-left if 1+right-left < result

    selected[house[left]] -= 1
    current -= 1 if selected[house[left]] == 0
    left += 1
  else
    right += 1
    break if right == house.length
    current += 1 if selected[house[right]] == 0
    selected[house[right]] += 1
  end
end

puts result


h,n = gets.split.map(&:to_i)
d = gets.split.map(&:to_i)
sum = d.inject(:+)
a = 0
mn = 0
n.times do |i|
    a += d[i]
    mn = a if mn > a
end
if sum >= 0 && h+mn > 0
    puts -1
    exit
end
ans = 0
if h+mn > 0
    ans += (h+mn-sum-1)/(-sum)*n
    h += ans/n*sum
end
n.times do |i|
    h += d[i]
    ans += 1
    if h <= 0
        puts ans
        exit
    end
end

H,N = gets.split.map &:to_i
D = gets.split.map &:to_i
ss = [0]
(1..N).each{ |i|
  d = D[i-1]
  ss << (ss[-1] + d)
  if ss[-1] + H <= 0
    p i; exit
  end
}

if ss[-1] >= 0
  p -1; exit
end

td = ss[-1]
t = nil
k = (0..H/(-td)).bsearch{ |n|
  h0 = H + n*td
  h = h0
  j = 0
  ss.each{ |s|
    h = h0 + s
    break if h <= 0
    j += 1
  }
  t = j if h <= 0
  h <= 0
}
p N*k + t


# http://codeforces.com/contest/569/problem/B
n = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)

array = Array.new(n + 1) { 0 }
a.each { |e| array[e] += 1 if e <= n }

stack = [].tap do |out|
  (1..n).each { |idx| out << idx if array[idx] == 0 }
end

ans = a.map do |e|
  case
  when e > n
    stack.pop
  when array[e] > 1
    array[e] -= 1
    stack.pop
  else
    e
  end
end

puts ans.join(' ')

n = gets.chomp.to_i
arr = gets.chomp.split.map{|x| x.to_i}

ref = Array.new(n+1){0}

arr.each do |v|
	if v<=n
		ref[v]+=1
	end
end
stack = []
(1..n).each do |i|
	if ref[i] == 0
	stack.push(i)
	end
end

arr.each do |v|
	if v>n
		print "#{stack.pop} "
	elsif ref[v] > 1
		print "#{stack.pop} "
		ref[v]-=1
	else
			print "#{v} "
	end
end

require 'set'
n = STDIN.gets.chomp
input = STDIN.gets.chomp

def remap(n, input)
  order = Set.new
  n.to_i.times {|n| order << n+1}

  input = input.split.map(&:to_i)
  output = []

  reworked_input = []
  positions = []

  input.length.times do |position|
    key = input[position]
    unless order.include? key
      positions << position
    else
      order.delete key
    end
  end

  counter = 0

  order.each do |element|
    input[positions[counter]] = element
    counter += 1
  end

  return input.join(" ")
end

puts remap(n, input)

#!/usr/bin/ruby
N=gets.to_i
A=[]
h={}
gets.split.each_with_index{|e,i|
	n=e.to_i-1
	if !A[n]&&n<N
		A[n]=i
		h[i]=n
	end
}
x=0
N.times{|i|
	if !A[i]
		x+=1 while h[x]
		A[i]=x
		h[x]=i
	end
}
B=[]
A.each_with_index{|e,i|B[e]=i+1}
puts B*' '

def read_ints; gets.chomp.split.map(&:to_i) end
n = read_ints[0]
a_elems = read_ints
bad_a_elems = Array.new(n)
positions = Array.new(n)
a_elems.each_with_index do |a,i|
	a-=1
	if positions[a].nil? && a<n
		positions[a]=true
	else
		bad_a_elems[i]=true
	end
end
current_free_postition = positions.find_index(nil)
bad_a_elems.each_with_index do |bad_a, i|
	if bad_a
		a_elems[i] = current_free_postition+1
		begin current_free_postition+=1
		end while positions[current_free_postition]
	end
end
puts a_elems.join(' ')

gets
nums = gets.split(' ').map(&:to_i)

used = {}
nums.each do |n|
	used[n] = true
end

f = 0
free = Array.new(nums.size)
(1..nums.size).each do |n|
	next if used[n]

	free[f] = n
	f += 1
end

f = 0
res = Array.new(nums.size)
used = {}
nums.each_with_index do |n, i|
	if used[n] || n > nums.size
		res[i] = free[f]
		f += 1
	else
		res[i] = n
		used[n] = true
	end
end

puts res.join(' ')

n = gets.chomp.to_i
as = gets.chomp.split(' ').map(&:to_i)

bs = Array.new(n+1, false)
cs = Array.new(n+1, false)

for i in 0..n-1
  a = as[i]
  if 1 <= a && a <= n && !bs[a]
    bs[a] = true
    cs[i] = true
  end
end

j = 1
for i in 0..n-1
  a = as[i]
  while bs[j]
    j += 1
  end
  if cs[i]
    print as[i]
  else
    print j
    j += 1
  end
  print ' '
end
print "\n"

#!/usr/bin/ruby

n = ARGF.gets.to_i
a = ARGF.gets.split(' ').map { |s| s.to_i }

b = Array.new(n + 1, 0)
b[0] = 1

a.each do |e|
    if e <= n then b[e] += 1 end
end

c = Array.new
b.each_with_index do |e, i|
    if b[i] == 0 then c << i end
end

a.each_with_index do |e, i|
    if a[i] > n
       a[i] = c.shift
    elsif b[a[i]] > 1
       b[a[i]] -= 1
       a[i] = c.shift
    end
end

print a.shift
a.each do |e| print(" #{e}") end
print "\n"

#n = STDIN.gets.chomp
#input = STDIN.gets.chomp

def remap(n, input)
  order = []
  n.to_i.times {|n| order << n+1}

  input = input.split.map(&:to_i)
  output = []

  reworked_input = []

  input.each do |key|
    unless order.include? key
      reworked_input << [key, false]
    else
      index = order.index key
      order[index] = nil
      reworked_input << [key, true]
    end
  end

  order = order.compact
  counter = 0

  reworked_input.each do |element|
    key, value = element
    if value == false
      output << order[counter]
      counter += 1
    else
      output << key
    end
  end

  return output.join(" ")
end

#puts remap(n, input)

#!/usr/bin/ruby
N=gets.to_i
A=[]
h={}
gets.split.each_with_index{|e,i|
	n=e.to_i-1
	if !A[n]&&n<N
		A[n]=i
		h[i]=n
	end
}
x=0
N.times{|i|
	if !A[i]
		x+=1 while h[x]
		A[i]=x
		h[x]=i
	end
}
puts A[0,N].map{|e|e+1}*' '

gets
nums = gets.split(' ').map(&:to_i)

used = {}
nums.each do |n|
	used[n] = true
end

f = 0
free = Array.new(nums.size)
(1..nums.size).each do |n|
	next if used[n]

	free[f] = n
	f += 1
end

f = 0
res = Array.new(nums.size)
used = {}
nums.each_with_index do |n, i|
	if used[n] || n >= nums.size
		res[i] = free[f]
		f += 1
	else
		res[i] = n
		used[n] = true
	end
end

puts res.join(' ')

#!/usr/bin/ruby

n = ARGF.gets.to_i
a = ARGF.gets.split(' ').map { |s| s.to_i }

b = Array.new(n + 1, 0)
b[0] = 1

a.each do |e|
    if e < n then b[e] += 1 end
end

c = Array.new
b.each_with_index do |e, i|
    if b[i] == 0 then c << i end
end

a.each_with_index do |e, i|
    if a[i] > n
       a[i] = c.shift
    elsif b[a[i]] > 1
       b[a[i]] -= 1
       a[i] = c.shift
    end
end

print a.shift
a.each do |e| print(" #{e}") end
print "\n"


def r
  gets.split.map(&:to_i)
end
def rook(p)
  "RQ".match(p[1])
end
def bish(p)
  "BQ".match(p[1])
end
gets
kx, ky = r

rl = cl = d1l = d2l = [-1e10, "dummy"]
rh = ch = d1h = d2h = [+1e10, "dummy"]

$<.each_line do |l|
  op, x, y = l.split
  x = x.to_i
  y = y.to_i

  if 1
    rl = [rl, [y, op]].max if x == kx && y < ky
  end
  if 1
  rh = [rh, [y, op]].min if x == kx && y > ky
  end
  if 1
  cl = [cl, [x, op]].max if y == ky && x < kx
  end
  if 1
  ch = [ch, [x, op]].min if y == ky && x > kx
  end

  d1l = [d1l, [x, op]].max if x+y == kx+ky && x < kx
  d1h = [d1h, [x, op]].min if x+y == kx+ky && x > kx
  d2l = [d2l, [x, op]].max if x-y == kx-ky && x < kx
  d2h = [d2h, [x, op]].min if x-y == kx-ky && x > kx
end
puts [rl, rh, cl, ch].any?{|x| rook(x)} || [d1l, d1h, d2l, d2h].any?{|x| bish(x)} ? "YES" : "NO"

def r
  gets.split.map(&:to_i)
end
def rook(p)
  "RQ".match(p[1])
end
def bish(p)
  "BQ".match(p[1])
end
gets
kx, ky = r

rl = cl = d1l = d2l = [-1e10, "dummy"]
rh = ch = d1h = d2h = [+1e10, "dummy"]

$<.each_line do |l|
  op, x, y = l.split
  x = x.to_i
  y = y.to_i

  rl = [rl, [y, op]].max if x == kx && y < ky
  rh = [rh, [y, op]].min if x == kx && y > ky
  cl = [cl, [x, op]].max if y == ky && x < kx
  ch = [ch, [x, op]].min if y == ky && x > kx

  d1l = [d1l, [x, op]].max if x+y == kx+ky && x < kx
  d1h = [d1h, [x, op]].min if x+y == kx+ky && x > kx
  d2l = [d2l, [x, op]].max if x-y == kx-ky && x < kx
  d2h = [d2h, [x, op]].min if x-y == kx-ky && x > kx
end
puts [rl, rh, cl, ch].any?{|x| rook(x)} || [d1l, d1h, d2l, d2h].any?{|x| bish(x)} ? "YES" : "NO"

vert = []
hori = []
psdiag = []
nsdiag = []

n = gets.to_i
kx, ky = gets.strip.split.map(&:to_i)

pieces = []
n.times do |i|
  p, x, y = gets.strip.split
  x = x.to_i
  y = y.to_i
  pieces << [p, x, y]
  vert << i if x == kx
  hori << i if y == ky
  psdiag << i if (y-x) == (ky-kx)
  nsdiag << i if (y+x) == (ky+kx)
end

under_attack = false

near_top = [10**10, nil]
near_bot = [-1 * (10**10), nil]
vert.each do |pi|
  p = pieces[pi]
  if p[2] > ky && p[2] < near_top[0]
    near_top[0] = p[2]
    near_top[1] = pi
  end
  if p[2] < ky && p[2] > near_bot[0]
    near_bot[0] = p[2]
    near_bot[1] = pi
  end
end
under_attack ||= pieces[near_top[1]][0] == "R" || pieces[near_top[1]][0] == "Q" if near_top[1]
under_attack ||= pieces[near_bot[1]][0] == "R" || pieces[near_bot[1]][0] == "Q" if near_bot[1]

if under_attack == false
  near_rgt = [10**10, nil]
  near_lft = [-1 * (10**10), nil]
  hori.each do |pi|
    p = pieces[pi]
    if p[1] > kx && p[1] < near_rgt[0]
      near_rgt[0] = p[1]
      near_rgt[1] = pi
    end
    if p[1] < kx && p[1] > near_lft[0]
      near_lft[0] = p[1]
      near_lft[1] = pi
    end
  end
  under_attack ||= pieces[near_rgt[1]][0] == "R" || pieces[near_rgt[1]][0] == "Q" if near_rgt[1]
  under_attack ||= pieces[near_lft[1]][0] == "R" || pieces[near_lft[1]][0] == "Q" if near_lft[1]
end

if under_attack == false
  near_tr = [10**10, nil]
  near_bl = [-1 * (10**10), nil]
  psdiag.each do |pi|
    p = pieces[pi]
    if p[2] > ky && p[2] < near_tr[0]
      near_tr[0] = p[2]
      near_tr[1] = pi
    end
    if p[2] < ky && p[2] > near_bl[0]
      near_bl[0] = p[2]
      near_bl[1] = pi
    end
  end
  under_attack ||= pieces[near_tr[1]][0] == "B" || pieces[near_tr[1]][0] == "Q" if near_tr[1]
  under_attack ||= pieces[near_bl[1]][0] == "B" || pieces[near_bl[1]][0] == "Q" if near_bl[1]
end

if under_attack == false
  near_br = [10**10, nil]
  near_bl = [-1 * (10**10), nil]
  nsdiag.each do |pi|
    p = pieces[pi]
    if p[1] > kx && p[1] < near_br[0]
      near_br[0] = p[1]
      near_br[1] = pi
    end
    if p[1] < kx && p[1] > near_bl[0]
      near_bl[0] = p[1]
      near_bl[1] = pi
    end
  end
  under_attack ||= pieces[near_br[1]][0] == "B" || pieces[near_br[1]][0] == "Q" if near_br[1]
  under_attack ||= pieces[near_bl[1]][0] == "B" || pieces[near_bl[1]][0] == "Q" if near_bl[1]
end

puts (under_attack ? "YES" : "NO")

# Try Codeforces
# author: Leonardone @ NEETSDKASU
############################################################
def gs() gets.strip end
def gi() gets.to_i end
def gss() gs.split end
def gis() gss.map(&:to_i) end
def nmapf(n,f) n.times.map{ __send__ f } end
def ngs(n) nmapf n,:gs end
def ngi(n) nmapf n,:gi end
def ngss(n) nmapf n,:gss end
def ngis(n) nmapf n,:gis end
def arr2d(h,w,v=0) h.times.map{[v] * w} end
def for2p(hr,wr,&pr) hr.each{|i|wr.each{|j| yield(i,j)}} end
def nsum(n) n * (n + 1) / 2 end
def vcount(d,r=Hash.new(0)) d.inject(r){|m,e| m[e]+=1;m} end
############################################################

n = gi
x, y = gis

ps = [nil] * 8

n.times do
    c, xi_s, yi_s = gss
    xi, yi = xi_s.to_i, yi_s.to_i
    dx = xi - x
    dy = yi - y
    d = dx.abs + dy.abs
    if x == xi
        if y < yi && (ps[6].nil? || d < ps[6][1])
            ps[6] = [c, d]
        elsif y > yi && (ps[1].nil? || d < ps[1][1])
            ps[1] = [c, d]
        end
    elsif y == yi
        if x < xi && (ps[4].nil? || d < ps[4][1])
            ps[4] = [c, d]
        elsif x > xi && (ps[3].nil? || d < ps[3][1])
            ps[3] = [c, d]
        end
    elsif dx.abs == dy.abs
        if dy < 0 && dx < 0 && (ps[0].nil? || d < ps[0][1])
            ps[0] = [c, d]
        elsif dy < 0 && dx > 0 && (ps[2].nil? || d < ps[2][1])
            ps[2] = [c, d]
        elsif dy > 0 && dx < 0 && (ps[5].nil? || d < ps[5][1])
            ps[5] = [c, d]
        elsif dy > 0 && dx > 0 && (ps[7].nil? || d < ps[7][1])
            ps[7] = [c, d]
        end
    end
end

case
when !ps[1].nil? && ps[1][0] != 'B'
    puts :YES
when !ps[3].nil? && ps[3][0] != 'B'
    puts :YES
when !ps[4].nil? && ps[4][0] != 'B'
    puts :YES
when !ps[6].nil? && ps[6][0] != 'B'
    puts :YES
when !ps[0].nil? && ps[0][0] != 'R'
    puts :YES
when !ps[2].nil? && ps[2][0] != 'R'
    puts :YES
when !ps[5].nil? && ps[5][0] != 'R'
    puts :YES
when !ps[7].nil? && ps[7][0] != 'R'
    puts :YES
else
    puts :NO
end

def r
  gets.split.map(&:to_i)
end
def rook(p)
  "RQ".match(p[1])
end
def bish(p)
  "BQ".match(p[1])
end
gets
kx, ky = r

rl = cl = d1l = d2l = [-1e10, "dummy"]
rh = ch = d1h = d2h = [+1e10, "dummy"]

$<.each_line do |l|
  op, x, y = l.split
  x = x.to_i
  y = y.to_i

  if x == kx
    rl = [rl, [y, op]].max if y < ky
    rh = [rh, [y, op]].min if y > ky
  end
  if y == ky
    cl = [cl, [x, op]].max if x < kx
    ch = [ch, [x, op]].min if x > kx
  end
  if x+y == kx+ky
    d1l = [d1l, [x, op]].max if x < kx
    d1h = [d1h, [x, op]].min if x > kx
  end
  if x-y == kx-ky
    d2l = [d2l, [x, op]].max if x < kx
    d2h = [d2h, [x, op]].min if x > kx
  end
end
puts [rl, rh, cl, ch].any?{|x| rook(x)} || [d1l, d1h, d2l, d2h].any?{|x| bish(x)} ? "YES" : "NO"

def r
  gets.split.map(&:to_i)
end
def rook(o)
  "RQ".match(o)
end
def bish(o)
  "BQ".match(o)
end
gets
kx, ky = r

rl = cl = d1l = d2l = [-1e10, "dummy"]
rh = ch = d1h = d2h = [+1e10, "dummy"]

$<.each_line do |l|
  op, x, y = l.split
  x = x.to_i
  y = y.to_i

  if x == kx
    rl = [rl, [y, op]].max if y < ky
    rh = [rh, [y, op]].min if y > ky
  end
  if y == ky
    cl = [cl, [x, op]].max if x < kx
    ch = [ch, [x, op]].min if x > kx
  end
  if x+y == kx+ky
    d1l = [d1l, [x, op]].max if x < kx
    d1h = [d1h, [x, op]].min if x > kx
  end
  if x-y == kx-ky
    d2l = [d2l, [x, op]].max if x < kx
    d2h = [d2h, [x, op]].min if x > kx
  end
end
puts [rl, rh, cl, ch].any?{|x,o| rook(o)} || [d1l, d1h, d2l, d2h].any?{|x,o| bish(o)} ? "YES" : "NO"


n = gets.to_i
cnt = Array.new(2 ** 18, 0)
n.times do
  c, s = gets.split
  a = s.tr('0-9', '0101010101').to_i(2)
  case c
  when '+'
    cnt[a] += 1
  when '-'
    cnt[a] -= 1
  when '?'
    puts cnt[a]
  end
end

n = gets.to_i
h = Hash.new(0)
n.times do |i|
  x, num = gets.split(" ")
  a =  num.tr('0-9', '0101010101').to_i
  if x.ord == 43
    h[a] += 1
  elsif x.ord == 45
    h[a] -= 1
  elsif x.ord == 63
    puts h[a]
  end
end

n = gets.to_i
h = Hash.new(0)
n.times.map do |i|
  x, s = gets.split
  s = s.tr('13579', '1').tr('24680', '0')
  case x
  when '+'
    h[s.rjust(18, '0')] += 1
  when '-'
    h[s.rjust(18, '0')] -= 1
  when '?'
    puts h[s.rjust(18, '0')]
  end
end

n = gets.to_i
h = Hash.new(0)
n.times.map do |i|
  x, s = gets.split
  a = s.tr('0-9', '0101010101').to_i
  case x
  when '+'
    h[a] += 1
  when '-'
    h[a] -= 1
  when '?'
    puts h[a]
  end
end

n = readline.to_i
h = {}
h.default = 0
(1..n).each do
  q_type, q_key = readline.split.map(&:strip)

  t=0
  (0...q_key.size).each do |i|
    t *= 2
    t += q_key[i].ord % 2
  end

  if q_type == '+'
    h[t] += 1
  elsif q_type == '-'
    h[t] -= 1
  else
    puts h[t]
  end
end

n = gets.to_i
h = Hash.new(0)
n.times.map do |i|
  x, s = gets.split
  s = s.tr('13579', '1').tr('24680', '1')
  case x
  when '+'
    h[s.rjust(18, '0')] += 1
  when '-'
    h[s.rjust(18, '0')] -= 1
  when '?'
    puts h[s.rjust(18, '0')]
  end
end

n = gets.to_i
h = Hash.new(0)
n.times do |x|
  c, n = gets.split
  case c
  when '+'
    h[n] += 1
  when '-'
    h[n] -= 1
  when '?'
    a = n.chars.map do |x|
      if x == '1'
        "[1|3|5|7]"
      elsif x == '0'
        "[2|4|6|8|0]"
      end
    end.join
    a << '$'
    puts h.keys.select{|x| x.rjust(5, '0').match(Regexp.new(a))}.inject(0){|s, x| s + h[x]}
  end
end

n = gets.to_i
h = Hash.new(0)
n.times do |x|
  c, n = gets.split
  case c
  when '+'
    h[n] += 1
  when '-'
    h[n] -= 1
  when '?'
    a = n.chars.map{|x| x == '1' ? '[1|3|5|7|9]' : '[2|4|6|8|0]'}.join
    a << '$'
    puts h.keys.select{|x| x.rjust(18, '0').match(Regexp.new(a))}.inject(0){|s, x| s + h[x]}
  end
end


gets.strip.to_i.times {
    n, s = gets.strip.split(' ').map(&:to_i)
    a = gets.strip.split(' ').map(&:to_i)
    mx = -1
    sum = 0
    done = false
    $part
    a.each_with_index { |e, i|
        if mx <= e
            mx = e
            $part = i + 1
        end
        sum += e
        if sum > s
            puts $part
            done = true
            break
        end
    }
    puts 0 if !done
}

def solve(n, s, vals)
  sum = 0
  max_so_far = vals[0]
  vals.each_with_index do |e, i|
    max_so_far = [max_so_far, e].max
    sum += e
    if sum > s
      return vals.index { |x| x == max_so_far } + 1
    end
  end
  0
end

# gets.strip.split(' ').map(&:to_i)
gets.strip.to_i.times do
  n, s = gets.strip.split(' ').map(&:to_i)
  vals = gets.strip.split(' ').map(&:to_i)
  puts solve(n, s, vals)
end


gets.to_i.times {
  n, k = gets.split(' ').map(&:to_i)
  if n % 4 == 0
    a = n / 2
    b = a / 2
    puts [a, b, b].join(' ')
  else
    a = (n - 1) / 2
    rem = n - 2 * a
    while a > 0
      if a % rem == 0
        puts [a, a, rem].join(' ')
        break
      end
      a -= 1
      rem += 2
    end
  end
}

def fn(n,k)
  m = n / 2
  if n % 2  == 1
    x = (n - 1)/2
    ret = [x,x, 1]
  else
     if m % 2 == 0
       ret = [m,m/2,m/2]
     else
      ret = [2, m-1, m-1]
     end
  end

  puts ret.join(' ')
end

tt = gets.to_i
tt.times {
  (n, k)= gets.chomp!.split(' ').map &:to_i
  fn(n,k)
}

def solve(n, k)
    a = n / 4
    case n % 4
    when 0
        [a*2, a, a]
    when 1
        [a*2, a*2, 1]
    when 2
        [a*2, a*2, 2]
    when 3
        [a*2+1, a*2+1, 1]
    end
end

def main
    t = int
    t.times do
        n, k = ints
        a, b, c = solve(n, k)
        raise "not satisfied: #{a} + #{b} + #{c} == #{n}" unless a + b + c == n
        raise "not satisfied: LCM(#{a}, #{b}, #{c}) <= #{n}/2" unless 2 * a.lcm(b).lcm(c) <= n
        puts "#{a} #{b} #{c}"
    end
end

DEBUG = true
MOD = 10**9+7
YESNO = %w(No Yes)
INF = 10**9

def int; gets.to_s.to_i end
def ints; gets.to_s.split.map { |s| s.to_i } end
def int1s; gets.to_s.split.map { |s| s.to_i - 1 } end
def float; gets.to_s.to_f end
def floats; gets.to_s.split.map { |s| s.to_f } end
def array_of(&convert); gets.to_s.split.map(&convert) end
def string; gets.to_s.chomp end
def rep(n, &b); Array.new(n, &b) end
def yes; puts YESNO[1] end
def no; puts YESNO[0] end
def yesno t; puts YESNO[t] end
def zip(xs, *yss); Enumerator.new { |y| xs.zip(*yss) { |a| y.yield(*a) } } end
def max(*xs, &block); block_given? ? xs.max_by(&block) : xs.max end
def min(*xs, &block); block_given? ? xs.min_by(&block) : xs.min end
def minmax(*xs, &block); block_given? ? xs.minmax_by(&block) : xs.minmax end
def gcd(*xs); xs.inject(0, :gcd) end
def matrix(h, w, fill=nil, &block); return Array.new(h) { Array.new(w, &block) } if block_given?; Array.new(h) { [fill] * w } end
def debug(x = nil); STDERR.puts (block_given? ? yield(x) : x).inspect if DEBUG; x end
def debug_grid(grid, width = 1); grid.each { |row| STDERR.puts row.map { |x| x.inspect.ljust(width) }.join("") } if DEBUG; grid end
def if_debug; yield if DEBUG end

module Boolean
def coerce(other); [other, to_i] end
def +@; to_i end
def to_int; to_i end
def *(other); to_i * other end
end

class TrueClass
include Boolean
def to_i; 1 end
end

class FalseClass
include Boolean
def to_i; 0 end
end

class Integer
def div_ceil(y); (self + y - 1) / y end
def mod_inv(mod = MOD); pow(mod-2, mod) end
def mod_div(y, mod = MOD); self * mod_inv(y, mod) % mod end
def factorial(mod = MOD); (2..self).inject(1) { |f, x| f * x % mod } end
def popcount; x = self; c = 0; while x > 0; c += 1 if x & 1 == 1; x >>= 1 end; c end #TODO: faster
def bitbrute(&block); (1<<self).times(&block) end
def nCr(r); x = 1; (1..r).each { |i| x *= self + 1 - i; x /= i }; x; end
def each_divisor; return Enumerator.new { |y| each_divisor { |k| y << k } } unless block_given?; k = 1; while k * k < self; if self % k == 0; yield k; yield self / k end; k += 1; end; yield k if k * k == self end
def divisors; each_divisor.to_a end
end

class Range
def end_open; exclude_end? ? self.end : self.end + 1 end
def end_close; exclude_end? ? self.end - 1 : self.end end
def upper_bound; ac, wa = self.begin, self.end_open; while wa - ac > 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end
def lower_bound; ac, wa = self.end_open, self.begin; while ac - wa > 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end
def shakutori(r2, &pred); Enumerator.new { |y| j, r = r2.begin, r2.end_open; each { |i| j += 1 while j + 1 < r and pred[i, j+1]; y.yield(i, j) } }; end
def widest(&block); Enumerator.new { |y| j, n = self.begin, self.end_open; each { |i| j += 1 while j < n and block[i, j]; y.yield(i, j) if block[i, j] } } end
end

class Array
def power(&block); (0 ... 1 << size).each(&block) end
def sorted_merge(other); a = []; i = j = 0; n, m = size, other.size; if j < m and other[j] < self[i]; a << other[j]; j += 1 else; a << self[i]; i += 1 end while i < n; a.push(*other[j..-1]) if j < m; a end
def upper_bound; ac, wa = 0, size; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end
def lower_bound; ac, wa = size, 0; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end
def cum(*xs, &op); a = []; a << xs[0] if xs.size > 0; a << x = self[0]; (1...size).each { |i| a << x = op[x, self[i]] }; a end
def cumdiff(range); self[range.end_open] - self[range.begin]; end
end

module Enumerable
def sorted_uniq; x = nil; filter { |y| c = x === y; x = y; !c } end
def cumsum; ys = [0]; each { |x| ys << x + ys[-1] }; ys end
end

main


T = gets.to_i

T.times do
  x, y, k = gets.split.map(&:to_i)

  ok = Rational(k * (1 + y) - 1, x - 1).ceil

  puts ok + k
end

t = gets.chomp.to_i
need = 0
kaisuu = 0
t.times do
    x, y, k = gets.chomp.split(" ").map(&:to_i)
    need = k + y * k #必要(松)
    sa = x - 1
    kaisuu = (need - 1) / sa
    amari = (need - 1) % sa
    if amari != 0
        kaisuu += 1
    end
    sekitan = (need - k)/ y
     puts kaisuu +  sekitan
end

gets.to_i.times do
  x, y, k = gets.split.map &:to_i
  puts ((y + 1) * k + x - 3) / (x - 1) + k
end

gets.to_i.times do
  a, b, k = gets.strip.split(" ").map(&:to_i)
  cn = k
  csn = cn*b
  tsn = csn + k
  dsn = tsn - 1
  iop = dsn / (a-1)
  iop += 1 if (dsn % (a-1)) > 0
  puts iop + cn
end


#!/usr/bin/env ruby

n, k, t = gets.chomp.split(/\s/).map{|s| s.to_i}
ret = []

max = n * k
value = (max * (t / 100.0)).to_i
(value / k).times do
  ret << k
end

ret << value % k

(n - (value.to_i / k) - 1).times do
  ret << 0
end

puts ret.slice(0, n).join(' ')

#!/usr/bin/ruby
n,k,t=gets.chop.split(" ").map{|i|i.to_i}
x=n*t/100
y=t*n*k/100-x*k
n.times{|i|if i<x then print k.to_s+" " elsif i==x then print y.to_s+" " else print 0.to_s; if i<n-1 then print " " end; end}

input = gets.split.map(&:to_i)

points = (input[2]*input[0]*input[1]) / 100

counter = 0
for counter in 1..(points/input[1])
  if counter != 1
    print ' '
  end
  print input[1].to_s
end

balance = points - (points/input[1]) * input[1]

if balance > 0
  print ' ' + balance.to_s
  counter += 1
end

for fcounter in 1 .. input[0]-counter
  print ' ' + 0.to_s
end

n, k, t = gets.split(' ').map &:to_i
p, bar = n * k * t / 100, []

n.times do |i|
	bar.push [p, k].min
	p -= bar.last
end

puts bar.join " "

n, k, t = gets.chop.split.map(&:to_i)

#n, k, t = 11, 13, 37

progress = (n.to_f * k / (100 / t.to_f)).truncate
nulls    = (n.to_f * k - progress).truncate

arr = []
while progress > 0 do
  if progress >= k then
    arr << k
    progress -= k
  else
    arr << progress
    progress = 0
  end
end

arr << 0 while arr.length < n

puts arr

input=gets.split.map(&:to_i)

n=input[0]
m=input[1]
t=input[2]

res=0
0.upto(n*m){|i|
    if i*100<=n*m*t then
        res=i
    end
}
for i in 1..n
    if m<=res then
        printf "%d ",m
        res-=m
    else
        printf "%d ",res
        res-=res
    end
end
puts

input = STDIN.gets
n,k,t = input.strip.split(' ').map{|w| w.to_i}
a = Array.new(n).fill(0)
saturated = (t/(100.0/n)).to_i
sum_saturated = saturated * k
last_saturation = (t * n * k / 100) - sum_saturated
saturated.times do |i|
  a[i] = k.to_i
end
if saturated >= n
  print a.join(' ')
else
  a[saturated] = last_saturation.to_i
  print a.join(' ')
end

n, k, t = gets.split.map(&:to_i)
s = n * k * t / 100
a = []
n.times do
	a << [s, k].min
	s -= a[-1]
end
puts a * ' '

input = gets.split.map(&:to_i)
l = (input[2] * input[0]*input[1]/100.0).floor
full = l/input[1]
full.times {print input[1], ' '}
if full != input[0]
    print l % input[1]
    (input[0] - full - 1).times {print ' ', 0}
end

n, k, t = gets.split.map(&:to_i)

val = Rational(100, n*k)

s = 0
s += 1 while (s+1)*val <= t
o = [k] * (s/k)
o << s%k if s%k > 0
o = (o + [0]*n)[0,n]
puts o*" "

n,k,t = gets.split.map(&:to_i)
all = n*k
val = (t*n*k/100.0).to_i
arr = [0] * n
n.times do |i|
	arr[i] = [k, val].min
	val = [val-k, 0].max
end
puts arr.join(' ')

input = STDIN.gets
n,k,t = input.strip.split(' ').map{|w| w.to_i}
a = Array.new(n).fill(0)
if(t <= k)
  a[0] = t
  print a.join(' ')
else
  saturated = t / (100/n)
  sum_saturated = saturated * k
  last_saturation = (t * n * k / 100) - sum_saturated
  saturated.times do |i|
    a[i] = k.to_i
  end
  if saturated >= n
    print a.join(' ')
  else
    a[saturated] = last_saturation.to_i
    print a.join(' ')
  end
end

input = STDIN.gets
n,k,t = input.strip.split(' ').map{|w| w.to_i}
a = Array.new(n).fill(0)
#if(t <= k)
#  a[0] = t
#  print a.join(' ')
#else
  p = t*n/100
  q = (t - (p*(100.0/n))).to_i
  p.times do |i|
    a[i] = k
  end
  if(q >= (100.0/n.to_f/k.to_f))
    a[p] = q * n * k / 100
  end
  print a.join(' ')
  #saturated = t / (100/n)
  #sum_saturated = saturated * k
  #last_saturation = (t * n * k / 100) - sum_saturated
  #saturated.times do |i|
  #  a[i] = k.to_i
  #end
  #if saturated >= n
  #  print a.join(' ')
  #else
  #  a[saturated] = last_saturation.to_i
  #  print a.join(' ')
  #end
#end

#!/usr/bin/env ruby

n, k, t = gets.chomp.split(/\s/).map{|s| s.to_i}
ret = []

max = n * k
value = (max * (t / 100.0)).to_i
(value / k).times do
  ret << k
end

ret << value % k

(n - (value.to_i / k) - 1).times do
  p :hoge
  ret << 0
end

puts ret.slice(0, n).join(' ')

#!/usr/bin/env ruby

n, k, t = gets.chomp.split(/\s/).map{|s| s.to_i}
ret = []

max = n * k
value = (max * (t / 100.0)).to_i
(value / k).times do
  ret << k
end

ret << value % k

(n - (value.to_i / k) - 1).times do
  ret << 0
end

puts ret.join(' ')

n,k,t=gets.chop.split(" ").map{|i|i.to_i}
x,y=t.divmod(k)
n.times{|i|if i<x then print k.to_s+" " elsif i==x then print y.to_s+" " else print 0.to_s+" " end}
puts

n,k,t=gets.chop.split(" ").map{|i|i.to_i}
x,y=t.divmod(k)
n.times{|i|if i<x then print k.to_s+" " elsif i==x then print y.to_s+" " else print 0.to_s; if i<n-1 then print " " end; end}

#!/usr/bin/ruby
n,k,t=gets.chop.split(" ").map{|i|i.to_i}
x=n*t/100
y=t.modulo(k)
n.times{|i|if i<x then print k.to_s+" " elsif i==x then print y.to_s+" " else print 0.to_s; if i<n-1 then print " " end; end}

input=gets.split.map(&:to_i)

n=input[0]
m=input[1]
t=input[2]

res=0
0.upto(n*m){|i|
	if i*100<=n*m*t then
		res=i
	end
}
for i in 0..n
	if m<=res then
		printf "%d ",m
		res-=m
	else
		printf "%d ",res
		res-=res
	end
end
puts

input = gets.split.map(&:to_i)

points = (input[2]*input[0]*input[1]) / 100

for counter in 1..(points/input[1])
  print input[1].to_s + ' '
end

print points - (points/input[1]) * input[1]

for fcounter in (points/input[1])+2 .. input[0]
  print ' ' + 0.to_s
end

input = gets.split.map(&:to_i)

points = (input[2]*input[0]*input[1]) / 100

for counter in 1..(points/input[1])
  print input[1].to_s + ' '
end

balance = points - (points/input[1]) * input[1]

print balance if balance > 0

for fcounter in (points/input[1])+1 .. input[0]
  print ' ' + 0.to_s
end

input = gets.split.map(&:to_i)

points = (input[2]*input[0]*input[1]) / 100

for counter in 1..(points/input[1])
  print input[1].to_s + ' '
end

balance = points - (points/input[1]) * input[1]

print balance if balance > 0

for fcounter in (points/input[1])+2 .. input[0]
  print ' ' + 0.to_s
end

n, k, t = gets.chop.split.map(&:to_i)

#n, k, t = 10, 10, 54

progress = (n.to_f * k / (100 / t.to_f)).truncate

arr = []
while progress > 0 do
  if progress >= k then
    arr << k
    progress -= k
  else
    arr << progress
    progress = 0
  end
end

puts arr

n, k, t = gets.chop.split.map(&:to_i)

#n, k, t = 11, 13, 37

progress = (n.to_f * k / (100 / t.to_f)).truncate
nulls    = n.to_f * k - progress

arr = []
while progress > 0 do
  if progress >= k then
    arr << k
    progress -= k
  else
    arr << progress
    progress = 0
  end
end

begin arr << 0; nulls -= k end while nulls > k

puts arr

input = STDIN.gets
n,k,t = input.strip.split(' ').map{|w| w.to_i}
a = Array.new(n).fill(0)
if(t <= k)
  a[0] = t
  print a.join(' ')
else
  p = t * n / 100
  q = (t - (p*(100.0/n))).to_i
  p.times do |i|
    a[i] = k
  end
  if(q > 0)
    a[p] = q * n * k / 100
  end
  print a.join(' ')
  #saturated = t / (100/n)
  #sum_saturated = saturated * k
  #last_saturation = (t * n * k / 100) - sum_saturated
  #saturated.times do |i|
  #  a[i] = k.to_i
  #end
  #if saturated >= n
  #  print a.join(' ')
  #else
  #  a[saturated] = last_saturation.to_i
  #  print a.join(' ')
  #end
end

input = STDIN.gets
n,k,t = input.strip.split(' ').map{|w| w.to_i}
a = Array.new(n).fill(0)
saturated = t / (100/n)
sum_saturated = saturated * k
last_saturation = (t * n * k / 100) - sum_saturated
saturated.times do |i|
  a[i] = k
end
if saturated >= n
  print a.join(' ')
else
  a[saturated] = last_saturation
  if(saturated + 1 < n)
    ((saturated + 1)..n).each do |i|
      a[i] = 0
    end
  end
  print a.join(' ')
end

input = STDIN.gets
n,k,t = input.strip.split(' ').map{|w| w.to_i}
a = Array.new(n).fill(0)
if(t <= k)
  a[0] = t
  print a.join(' ')
else
  saturated = t / (100/n)
  sum_saturated = saturated * k
  last_saturation = t * n * k / 100 - sum_saturated
  saturated.times do |i|
    a[i] = k.to_i
  end
  if saturated >= n
    print a.join(' ')
  else
    a[saturated] = last_saturation.to_i
    if(saturated + 1 < n)
      ((saturated + 1)..n-1).each do |i|
        a[i] = 0
      end
    end
    print a.join(' ')
  end
end

input = STDIN.gets
n,k,t = input.strip.split(' ').map{|w| w.to_i}
a = Array.new(n).fill(0)
if(t <= k)
  a[0] = t
  print a.join(' ')
else
  saturated = t / (100/n)
  sum_saturated = saturated * k
  last_saturation = t * n * k / 100 - sum_saturated
  saturated.times do |i|
    a[i] = k.to_i
  end
  if saturated >= n
    print a.join(' ')
  else
    a[saturated] = last_saturation.to_i
    print a.join(' ')
  end
end

input = STDIN.gets
n,k,t = input.strip.split(' ').map{|w| w.to_i}
a = Array.new(n).fill(0)
if(t <= k)
  a[0] = t
  print a.join(' ')
else
  p = t*n/100
  q = (t - (p*(100.0/n))).to_i
  p.times do |i|
    a[i] = k
  end
  if(q >= (100.0/n.to_f/k.to_f))
    a[p] = q * n * k / 100
  end
  print a.join(' ')
  #saturated = t / (100/n)
  #sum_saturated = saturated * k
  #last_saturation = (t * n * k / 100) - sum_saturated
  #saturated.times do |i|
  #  a[i] = k.to_i
  #end
  #if saturated >= n
  #  print a.join(' ')
  #else
  #  a[saturated] = last_saturation.to_i
  #  print a.join(' ')
  #end
end

input = STDIN.gets
n,k,t = input.strip.split(' ').map{|w| w.to_i}
a = Array.new(n).fill(0)
if(t <= k)
  a[0] = k
  print a.join(' ')
else
  saturated = t / (100/n)
  sum_saturated = saturated * k
  last_saturation = t * n * k / 100 - sum_saturated
  saturated.times do |i|
    a[i] = k.to_i
  end
  if saturated >= n
    print a.join(' ')
  else
    a[saturated] = last_saturation.to_i
    if(saturated + 1 < n)
      ((saturated + 1)..n-1).each do |i|
        a[i] = 0
      end
    end
    print a.join(' ')
  end
end

input = STDIN.gets
n,k,t = input.strip.split(' ').map{|w| w.to_i}
a = Array.new(n).fill(0)
#if(t <= k)
#  a[0] = t
#  print a.join(' ')
#else
  #p = t*n/100
  #q = (t - (p*(100.0/n))).to_i
  #p.times do |i|
  #  a[i] = k
  #end
  #if(q >= (100.0/n.to_f/k.to_f))
  #  a[p] = q * n * k / 100
  #end
  #print a.join(' ')
  saturated = t / (100/n)
  sum_saturated = saturated * k
  last_saturation = (t * n * k / 100) - sum_saturated
  saturated.times do |i|
    a[i] = k.to_i
  end
  if saturated >= n
    print a.join(' ')
  else
    a[saturated] = last_saturation.to_i
    print a.join(' ')
  end
#end

input = STDIN.gets
n,k,t = input.strip.split(' ').map{|w| w.to_i}
a = Array.new(n).fill(0)
saturated = t / (100/n)
sum_saturated = saturated * k
last_saturation = (t * n * k / 100) - sum_saturated
saturated.times do |i|
  a[i] = k
end
if saturated >= n
  print a.join(' ')
else
  a[saturated] = last_saturation
  if(saturated + 1 < n)
    ((saturated + 1)..n-1).each do |i|
      a[i] = 0
    end
  end
  print a.join(' ')
end

input = STDIN.gets
n,k,t = input.strip.split(' ').map{|w| w.to_i}
a = Array.new(n).fill(0)
saturated = t / (100/n)
sum_saturated = saturated * k
last_saturation = (t * n * k / 100) - sum_saturated
saturated.times do |i|
  a[i] = k
end
if saturated >= n
  puts a
else
  a[saturated] = last_saturation
  if(saturated + 1 < n)
    ((saturated + 1)..n).each do |i|
      a[i] = 0
    end
  end
  puts a
end

input = STDIN.gets
n,k,t = input.strip.split(' ').map{|w| w.to_i}
a = Array.new(n).fill(0)
if(t <= k)
  a[0] = t
  print a.join(' ')
else
  p = t * n / 100
  q = (t - (p*(100.0/n))).to_i
  puts p,q
  p.times do |i|
    a[i] = k
  end
  if(q > 0)
    a[p] = q * n * k / 100
  end
  print a.join(' ')
  #saturated = t / (100/n)
  #sum_saturated = saturated * k
  #last_saturation = (t * n * k / 100) - sum_saturated
  #saturated.times do |i|
  #  a[i] = k.to_i
  #end
  #if saturated >= n
  #  print a.join(' ')
  #else
  #  a[saturated] = last_saturation.to_i
  #  print a.join(' ')
  #end
end


n = gets.to_i
cnt0 = 0
cnt1 = 0
old = -1
ans = 1

arr = gets.split(" ").map(&:to_i)
for i in 0..n-1 do
    if (old == (-1))
        old = arr[i]
        cnt1 = cnt1 + 1
    elsif (arr[i] == old)
        cnt1 = cnt1 + 1
    elsif (arr[i] != old and cnt0 == 0)
        old = 1 - old
        cnt0 = cnt1
        cnt1 = 1
    elsif (arr[i] != old && cnt1 == cnt0)
        old = 1 - old
        cnt1 = 1
    elsif (arr[i] != old and cnt1 != cnt0)
            ans = 0

    end

end
if (cnt1 != cnt0 and cnt0 != 0)
    ans = 0
end
if (ans == 0)
  puts "NO"
else
  puts "YES"
end

n=gets.to_i()
s=gets.split()
p=0
q=0
h=0
f=1
for i in s
	if(i!=p)
		if(q!=h && h!=0)
			f=0
			break
		end
		h=q
		p=i
		q=1
	else
		q+=1
	end
end
if(q!=h && h!=0)
	f=0
end
if(f==1)
	puts('YES')
else
	puts('NO')
end

n = gets.chomp().to_i
prv = -1
len = -1
target = -1
ok = 1
gets.split.map(&:to_i).each do |a|
	if a != prv
		prv = a
		if target != -1 and len != target
			ok = 0
		end
		target = len
		len = 0
	else
		len = len + 1
	end
end
if target != -1 and len != target
	ok = 0
end
if ok == 1
	puts "Yes"
else
	puts "No"
end

gets
puts gets.split.map(&:to_i).chunk{|n| n==0}.map{|b,a| a.size}.uniq.length==1 ? "Yes" : "No"

n = gets.chomp.to_i

a = []
gets.chomp.split.each do |i|
  a << i.to_i
end
l = -1
pv = a[0]
cl = 0
fl = 0
a.each do |x|
    if (x != pv)
        if (l == -1)
            l = cl
        end
        if (l != cl)
            fl = 1
        end
        cl = 0
    end
    pv = x
    cl += 1
end
if (l == -1)
    l = cl
end
if (l != cl)
    fl = 1
end
if fl == 1
    puts "NO"
else
    puts "YES"
end

n = gets.chomp.to_i
a = gets.chomp.split(" ").map{|x| x.to_i}
kek = 0
kek2 = 0
tt = a[0]
ans = "YES"
flag = true
for i in a do
  if i == tt
    kek += 1
  else
    flag = false
    if kek2 == kek
      tt = i
      kek = 1
    elsif kek2 == 0 then
      tt = i
      kek2 = kek
      kek = 1
    else
      ans = "NO"
      break
    end
  end
end
if kek != kek2
  ans = "NO"
end
if flag
  ans = "YES"
end
puts ans

n = gets.to_i

A = gets.split

len = 1
for i in 1..(n - 1)
	if (A[i - 1] != A[i])
		break
		end
	len += 1
end

x = 1

for i in 1..(n - 1)
	if (A[i - 1] != A[i] && i % len != 0)
		x = 0
		end
	if (A[i - 1] == A[i] && i % len == 0)
		x = 0
		end
end

if (x == 0 || n % len > 0)
	puts "NO"
else
	puts "YES"
end

n = gets.to_i
a = gets.chomp.split()
b = Array.new
lst = a.at(0)
c = 1
for i in 1..(n-1)
        if a.at(i) == lst
                c = c+1
        else
                b.push(c)
                c = 1
                lst = a.at(i)
        end
end
b.push(c)
ans = "NO"
if b.uniq.size == 1
        ans = "YES"
end
puts ans

r=->{gets.split.map &:to_i}
n=r[]
a=r[] + [2]

color = a[0]
l = 1
whitelen = -1
blacklen = -1

good = true

for i in 1 ... a.size
  if a[i] != color
    if color == 1
      if whitelen == -1 or whitelen == l
        whitelen = l
      else
        good = false
      end
    else
      if blacklen == -1 or blacklen == l
        blacklen = l
      else
        good = false
      end
    end
    color = a[i]
    l = 0
  end
  l += 1
end

if blacklen != -1 and whitelen != -1 and whitelen != blacklen
  good = false
end

if good
  puts "YES"
else
  puts "NO"
end

n = gets().split(' ').map{|x| Integer(x)}[0]
a = gets().split(' ').map{|x| Integer(x)}

cur = 1
st = -1
flag = true

(1...n).each do |i|
    if i == 0 or a[i] != a[i - 1] then
    	if st == -1 then
    		st = cur
    	elsif cur != st
    		flag = false
    	end
    	cur = 1
    else
    	cur += 1
    end
end

if st == -1 then
	st = cur
elsif cur != st
	flag = false
end

if flag then
	puts("YES")
else
	puts("NO")
end

# your code goes here

# fo = open("input.txt", 'r')
n = gets.to_i

res = gets.split()
cnt = -1
cur = 1
ans = 'Yes'
(n - 1).times do |i|
    if (res[i] == res[i + 1])
        cur += 1
    else
        if (cnt == -1)
            cnt = cur
        else
            if (cnt != cur)
                ans = 'No'
            end
        end
        cur = 1
    end
end

if (cnt != cur and cnt != -1)
    ans = 'No'
end

puts(ans)

n = gets
ar = gets.chomp.split.map(&:to_i)
combed = Hash.new
old = ar[0]
i = 1
(1..ar.length).each do |x|
    cur = ar[x]
    if old == cur
        i+=1
    else
        combed[i] = 1
        i = 1
        old = cur
    end
end

puts combed.size <= 1 ? "YES" : "NO"

n = gets.to_i
photo = gets.split

current_color = photo.first
first_strip_width = 0
current_strip_width = 0
photo.each do |pixel|
  if pixel == current_color
    current_strip_width += 1
  else
    first_strip_width = current_strip_width if first_strip_width == 0
    if current_strip_width != first_strip_width
      break
    end
    current_strip_width = 1
    current_color = pixel
  end
end

first_strip_width = current_strip_width if first_strip_width == 0
if current_strip_width == first_strip_width
  puts "YES"
else
  puts "NO"
end

n = gets.to_i
cnt0 = 0
cnt1 = 0
old = -1
ans = 1

arr = gets.split(" ").map(&:to_i)
for i in 0..n-1 do
    if (old == (-1))
        old = arr[i]
        cnt1 = cnt1 + 1
    elsif (arr[i] == old)
        cnt1 = cnt1 + 1
     elsif (arr[i] == 1 - old and cnt0 == 0)
            old = 1 - old
            cnt0 = cnt1
            cnt1 = 1

    elsif (arr[i] == 1 - old and cnt1 != cnt0)
            ans = 0

    end

end
if (cnt1 != cnt0 and cnt0 != 0)
    ans = 0
end
if (ans == 0)
  puts "NO"
else
  puts "YES"
end

n = gets.to_i

A = gets.split

len = 1
for i in 1..(n - 1)
	if (A[i - 1] != A[i])
		break
		end
	len += 1
end

x = 1

for i in 1..(n - 1)
	if (A[i - 1] != A[i] && i % len != 0)
		x = 0
		end
end

if (x == 0 || n % len > 0)
	puts "NO"
else
	puts "YES"
end

n = gets.to_i
a = gets.chomp.split()
puts a
b = Array.new
lst = a.at(0)
c = 1
for i in 1..(n-1)

        if a.at(i) == lst
                c = c+1
        else
                b.push(c)
                c = 1
                lst = a.at(i)
        end
end
b.push(c)
ans = "NO"
if b.uniq.size == 1
        ans = "YES"
end
puts ans


I = ->{gets.split.map &:to_i}
n, m = I[]
m -= 1
a = I[].sort
h = Hash.new(0)
a.each{|_| h[_] += 1}
h.sort.each{|k, v|
    if m < v * n
        m /= v
        puts "#{k} #{a[m]}"
        break
    else
        m -= v * n
    end
}

n,k=gets.split.map(&:to_i)
a=gets.split.map(&:to_i)

a.sort!
k-=1
input=[]
n.times{|i|
        if i>0&&a[i]==a[i-1]
                input[input.length-1][1]+=1
        else
                input.push([a[i],1])
        end
}
input.each{|t|
        if k<t[1]*n
                p t[0]
                p a[k/t[1]]
                exit
        else
                k-=n*t[1]
        end
}

n, k = STDIN.readline.split.map {|s| s.to_i }
k -= 1
data = STDIN.readline.split.map {|s| s.to_i }.sort
ai = k/n
a = data[ai]
low = ai
while low-1 >= 0 and data[low-1] == a
  low -= 1
end
high = ai
while high+1 < n and data[high+1] == a
  high += 1
end
b = data[(k - low*n)/(high-low+1)]
puts '%d %d' % [a, b]

n,k = gets.split.map(&:to_i)
k -= 1
a = gets.split.map(&:to_i).sort

d,m = k.divmod n

s = a.select{|e|e == a[d] }.size

if s > 1
  f = a.index(a[d])*n
  m = (k-f)/s
end

print a[d], " ",a[m]

#!/usr/bin/ruby
# coding: utf-8

n, k = *$stdin.gets.chomp.split.map(&:to_i)
as = $stdin.gets.chomp.split.map(&:to_i)

h = Hash.new { 0 }
as.each do |a|
  h[a] += 1
end

h.keys.sort.each do |a1|
  c1 = h[a1]
  if k-c1*n <= 0
    h.keys.sort.each do |a2|
      c2 = h[a2]
      if k-c1*c2 <= 0
        puts [a1, a2].join(' ')
        exit 0
      end
      k -= c1*c2
    end
  end
  k -= c1*n
end

n,k=gets.chomp.split.collect{|a| a.to_i}
arr=gets.chomp.split.collect{|a| a.to_i}.sort
k=k-1
if arr[k/n] == arr[k/n+1] || arr[k/n]==arr[k/n-1]
m=arr.count arr[k/n]
z=arr.index arr[k/n]

print arr[k/n]," ",arr[(k-z*n)/m]
else
print arr[k/n]," " , arr[k%(n)].to_s
end

n, k = gets.split.collect{|i| i.to_i}
numbers = gets.split.collect{|i| i.to_i}.sort

k -= 1
f_idx = k / n
s_idx = k % n

fl = numbers.index(numbers[f_idx])
fr = numbers.rindex(numbers[f_idx])

if not fl == fr
  rem = k - fl * n
  s_idx = rem / (fr - fl + 1)
end

puts [numbers[f_idx], numbers[s_idx]].join(" ")

n,k=gets.split.map(&:to_i)
a=gets.split.map(&:to_i)

a.sort!
k-=1
n.times{|i|
        if k<n
                p a[i]
                p a[k]
                exit
        else
                k-=n
        end
}

n, k = STDIN.readline.split.map {|s| s.to_i }
k -= 1
data = STDIN.readline.split.map {|s| s.to_i }.sort
ai = k/n
a = data[ai]
low = ai-1
while low >= 0 and data[low] == a
  low -= 1
end
high = ai+1
while high < n and data[high] == a
  high += 1
end
b = data[(k - low*n)/(high-low+1)]
puts '%d %d' % [a, b]

n, k = STDIN.readline.split.map {|s| s.to_i }
data = STDIN.readline.split.map {|s| s.to_i }.sort
k -= 1
a = data[k/n]
b = data[k%n]
puts '%d %d' % [a, b]

n,k = gets.split.map(&:to_i)
k -= 1
a = gets.split.map(&:to_i).uniq.sort

d,m = k.divmod n

print a[d], " ",a[m]

#!/usr/bin/ruby
# coding: utf-8

n, k = *$stdin.gets.chomp.split.map(&:to_i)
as = $stdin.gets.chomp.split.map(&:to_i).sort

k -= 1
puts [as[k/n], as[k%n]].join(' ')

n,k=gets.chomp.split.collect{|a| a.to_i}
arr=gets.chomp.split.collect{|a| a.to_i}.sort
k=k-1
print arr[k/n]," " , arr[k%(n)].to_s

n,k=gets.chomp.split.collect{|a| a.to_i}
arr=gets.chomp.split.collect{|a| a.to_i}.sort
k=k-1
if arr[k/n] == arr[k/n+1] || arr[k/n]==arr[k/n-1]
print arr[k/n]," ",arr[k/n]
else
print arr[k/n]," " , arr[k%(n)].to_s
end

n,k=gets.chomp.split.collect{|a| a.to_i}
arr=gets.chomp.split.collect{|a| a.to_i}.sort
k=k-1
if arr[k/n] == arr[k/n+1] || arr[k/n]==arr[k/n-1]
m=arr.count arr[k/n]
print arr[k/n]," ",arr[(k/m)]
else
print arr[k/n]," " , arr[k%(n)].to_s
end

n, k = gets.split.collect{|i| i.to_i}
numbers = gets.split.collect{|i| i.to_i}.sort

k -= 1
f_idx = k / n
s_idx = k % n

puts [numbers[f_idx], numbers[s_idx]].join(" ")


t=gets.to_i
t.times do
  n=gets.to_i
  an=gets.chomp.split(' ').map(&:to_i)
  start = an.find_index {|ai|ai!=0}
  last =n-1-an.reverse.find_index{|ai|ai!=0}
  gapc=an[start..last].count do |ai|
    ai==0
  end
  p gapc
end

T = gets.to_i

T.times do
  n = gets.to_i
  a = gets.split.map(&:to_i)

  books = []

  a.each_with_index do |x, i|
    next if x == 0

    books << i
  end

  ans = 0

  books.each_cons(2) do |a, b|
    ans += b - a - 1
  end

  puts ans
end

t = gets.chomp.to_i
t.times do
  n = gets.chomp.to_i
  arr = gets.chomp.split(' ').map(&:to_i)
  st = -1
  res = 0
  arr.each_with_index do |el, ind|
    if el == 1 && st != -1
      res += ind - st - 1
      st = ind
    end
    if el == 1 && st == -1
      st = ind
    end
  end
  puts res
end

t = gets.chomp.to_i
t.times do
    n = gets.chomp.to_i
    a = gets.chomp.split(" ").map(&:to_i)
    ans = 0
    count = 0
    an = 0
    a.each do |i|
        if i == 0 && count >= 1
            an += 1
        elsif i == 1
            count += 1
            ans += an
            an = 0
        end
    end
    puts ans
end

gets.to_i.times do
  n = gets.to_i
  v = gets.split.map(&:to_i)
  seen = false
  cur = 0
  r = 0
  v.each do |x|
    cur += 1 if seen && x == 0
    if x == 1
      seen = true
      r += cur
      cur = 0
    end
  end
  puts r
end

t = gets.to_i
ans = []
t.times do
  n = gets.to_i
  a = gets.chomp.split(" ").map(&:to_i)
  cnt = 0
  left = -1
  right = -1
  n.times do |i|
    if left == -1 && a[i] == 1
      left = i
    end
    if right == -1 && a[n-1-i] == 1
      right = n-1-i
    end
  end
  for i in left..right
    if a[i] == 0
      cnt += 1
    end
  end
  ans << cnt
end
puts ans

gets.to_i.times do
  _ = gets
  a = gets.split.map(&:to_i)
  puts a.rindex(1) - a.index(1) - a.count(1) + 1
end


n = gets.to_i
g = 0
a = gets.strip.split.map(&:to_i)
a.each do |x|
  g  = g.gcd(x)
end
res = 0
i = 1
while i ** 2 <= g
  if g % i == 0
    res += 1
    res += 1 if i != g / i
  end
  i += 1
end
puts res

class NemiLib
  # 素因数分解ハッシュ形式
  # (例)100なら{2=>2,5=>2}
  def prime_factorization(num, result = Hash.new(0))
    return {} if num < 1
    return {1=>1} if num == 1

    divides = false
    to = Math.sqrt(num).floor
    # ２だけ別処理
    # 再起で呼び出すので1メソッド中に1回だけしか割らないようにする
    if num % 2 == 0
      result[2] += 1
      prime_factorization(num / 2, result)
      divides = true
    else
      3.step(to, 2) do |item|
        if num % item == 0
          result[item] += 1
          prime_factorization(num / item, result)
          divides = true
          break
        end
      end
    end
    # 何も割れないなら、その数を入れる
    result[num] += 1 unless divides

    result
  end

  # 約数
  def divisors(num)
    return [1] if num == 1

    pows = []
    # 0乗、1乗・・・した値を入れる
    prime_factorization(num).each_pair do |key, value|
      pow = []
      0.upto(value).each do |nn|
        pow << key ** nn
      end

      pows << pow
    end

    first_array = pows.delete_at(0)
    return first_array if pows.size == 0

    result = first_array.product(*pows)
    result.map do |item|
      item.inject { |sum, i| sum * i }
    end.sort
  end
end

n = gets.to_i
aa = gets.split.map(&:to_i)
gcd = aa.inject(:gcd)
pf = NemiLib.new.prime_factorization(gcd)
puts (pf[1]==1 ? 1 : pf.each_value.inject(1){|sum,i| sum*(i+1)})

def divs(n)
  i = 1
  sq = Math.sqrt(n).ceil.to_i
  div = []

  while i <= sq
    if (n % i).zero?
      if (n / i) == i
        div << i
      else
        div << i
        div << n / i
      end
    end
    i += 1
  end
  div.uniq
end

n = gets.strip.to_i
a = gets.strip.split(' ').map(&:to_i).uniq
g = 0
a.each do |e|
  g = e.gcd(g)
end
puts divs(g).size

require 'prime'
class Integer
	def divisors
		self.prime_division.reduce([1]) do |a, (p, e)|
			(0..e).map { p**_1 }.product(a).map { _1 * _2 }
		end.sort
	end
	def divisor_count
		self.prime_division.reduce(1) { |acc, (p, e)| acc *= e + 1 }
	end
end

gets
puts gets.split.map(&:to_i).reduce(&:gcd).divisor_count

def factors(n)
  facts = [1]

  while (n % 2).zero?
    facts << 2
    n = n / 2
  end
  i = 3
  sq = Math.sqrt(n).ceil.to_i
  while i <= sq
    while (n % i).zero?
      facts << i
      n = n / i
    end
    i += 2
  end
  facts << n

  facts.uniq
end

n = gets.strip.to_i
a = gets.strip.split(' ').map(&:to_i)
mn = a.min
mx = a.max
facts = (factors(mn) + factors(mx) + [mn, mx]).uniq
# puts facts.inspect

res = 0
facts.each do |f|
  res += 1 if a.all? { |e| e % f == 0 }
end
puts res

def factors(n)
  facts = [1]

  while (n % 2).zero?
    facts << 2
    n = n / 2
  end
  i = 3
  sq = Math.sqrt(n).ceil.to_i
  while i <= sq
    while (n % i).zero?
      facts << i
      n = n / i
    end
    i += 1
  end
  facts << n if n > 2

  facts.uniq
end

n = gets.strip.to_i
a = gets.strip.split(' ').map(&:to_i)
mn = a.min
facts = (factors(mn) + [mn]).uniq

res = 0
facts.each do |f|
  res += 1 if a.all? { |e| e % f == 0 }
end
puts res

class NemiLib
  # 素因数分解ハッシュ形式
  # (例)100なら{2=>2,5=>2}
  def prime_factorization(num, result = Hash.new(0))
    return {} if num < 1
    return {1=>1} if num == 1

    divides = false
    to = Math.sqrt(num).floor
    # ２だけ別処理
    # 再起で呼び出すので1メソッド中に1回だけしか割らないようにする
    if num % 2 == 0
      result[2] += 1
      prime_factorization(num / 2, result)
      divides = true
    else
      3.step(to, 2) do |item|
        if num % item == 0
          result[item] += 1
          prime_factorization(num / item, result)
          divides = true
          break
        end
      end
    end
    # 何も割れないなら、その数を入れる
    result[num] += 1 unless divides

    result
  end

  # 約数
  def divisors(num)
    return [1] if num == 1

    pows = []
    # 0乗、1乗・・・した値を入れる
    prime_factorization(num).each_pair do |key, value|
      pow = []
      0.upto(value).each do |nn|
        pow << key ** nn
      end

      pows << pow
    end

    first_array = pows.delete_at(0)
    return first_array if pows.size == 0

    result = first_array.product(*pows)
    result.map do |item|
      item.inject { |sum, i| sum * i }
    end.sort
  end
end

n = gets.to_i
aa = gets.split.map(&:to_i)
gcd = aa.inject(:gcd)
pf = NemiLib.new.prime_factorization(gcd)
puts (pf.size==1 ? 1 : pf.each_value.inject(1){|sum,i| sum*(i+1)})

class NemiLib
  # 素因数分解ハッシュ形式
  # (例)100なら{2=>2,5=>2}
  def prime_factorization(num, result = Hash.new(0))
    return {} if num < 1
    return {1=>1} if num == 1

    divides = false
    to = Math.sqrt(num).floor
    # TODO うまくかきたい。２だけ別処理
    if num % 2 == 0
      result[2] += 1
      prime_factorization(num / 2, result)
      divides = true
    end
    3.step(to, 2) do |item|
      if num % item == 0
        result[item] += 1
        prime_factorization(num / item, result)
        divides = true
        break
      end
    end
    # 何も割れないなら、その数を入れる
    result[num] += 1 unless divides

    result
  end

  # 約数
  def divisors(num)
    return [1] if num == 1

    pows = []
    # 0乗、1乗・・・した値を入れる
    prime_factorization(num).each_pair do |key, value|
      pow = []
      0.upto(value).each do |nn|
        pow << key ** nn
      end

      pows << pow
    end

    first_array = pows.delete_at(0)
    return first_array if pows.size == 0

    result = first_array.product(*pows)
    result.map do |item|
      item.inject { |sum, i| sum * i }
    end.sort
  end
end

n = gets.to_i
aa = gets.split.map(&:to_i)
gcd = aa.inject(:gcd)
pf = NemiLib.new.prime_factorization(gcd)
puts pf.each_value.inject(1){|sum,i| sum*(i+1)}

class NemiLib
  # 素因数分解ハッシュ形式
  # (例)100なら{2=>2,5=>2}
  def prime_factorization(num, result = Hash.new(0))
    return {} if num < 1
    return {1=>1} if num == 1

    divides = false
    to = Math.sqrt(num).floor
    # TODO うまくかきたい。２だけ別処理
    if num % 2 == 0
      result[2] += 1
      prime_factorization(num / 2, result)
      divides = true
    end
    3.step(to, 2) do |item|
      if num % item == 0
        result[item] += 1
        prime_factorization(num / item, result)
        divides = true
        break
      end
    end
    # 何も割れないなら、その数を入れる
    result[num] += 1 unless divides

    result
  end

  # 約数
  def divisors(num)
    return [1] if num == 1

    pows = []
    # 0乗、1乗・・・した値を入れる
    prime_factorization(num).each_pair do |key, value|
      pow = []
      0.upto(value).each do |nn|
        pow << key ** nn
      end

      pows << pow
    end

    first_array = pows.delete_at(0)
    return first_array if pows.size == 0

    result = first_array.product(*pows)
    result.map do |item|
      item.inject { |sum, i| sum * i }
    end.sort
  end
end

n = gets.to_i
aa = gets.split.map(&:to_i)
gcd = aa.inject(:gcd)
pf = NemiLib.new.prime_factorization(gcd)
puts (pf.size==1 ? 1 : pf.each_value.inject(1){|sum,i| sum*(i+1)})


count = gets.to_i
mas_width = Array.new(count)
mas_height = Array.new(count)
for i in 0..(count - 1)
    string = gets
    mas_width[i] = string.split(' ')[0].to_i
    mas_height[i] = string.split(' ')[1].to_i
end

all_width = 0
for i in 0..(count - 1)
    all_width += mas_width[i]
end

new_mas_height = Array.new(mas_height).sort

max = new_mas_height[count - 1]
max2 = new_mas_height[count - 2]

index_max = mas_height.index(max)

for i in 0..(count - 1)
    unless i == index_max
        print (all_width - mas_width[i]) * max
    else
        print (all_width - mas_width[i]) * max2
    end
    print ' ' unless i == count - 1
end

amount = gets.chomp.to_i

friends = []
sum = 0
max1 = 0
max2 = 0

amount.times {
	x = gets.chomp.split(" ")
	x[0] = x[0].to_i
	x[1] = x[1].to_i
	friends.push(x)
	sum = sum + x[0]

	if x[1] >= max1
		max1 = x[1]
	end

	if x[1] >= max2
		max1 = max2
		max2 = x[1]
	end
}

friends.each { |x|
	if x[1] == max2
		print max1 * (sum - x[0]), " "
	else
		print max2 * (sum - x[0]), " "
	end
}

@data = $stdin.read.split
n = @data.shift.to_i
w = []
h = []
sum_w = 0
prf_h = []
suf_h = []
n.times do
	w << @data.shift.to_i
	h << @data.shift.to_i
	prf_h << h.last
	if h.size > 1
		prf_h[-1] = [prf_h.last, prf_h[-2]].max
	end
	suf_h << h.last
	sum_w += w.last
end

n.times do |i|
	next if i == 0
	suf_h[n - i - 1] = [suf_h[n-i-1], suf_h[n-i]].max
end

result = []
n.times do |i|
	h_left = i == 0 ? 0 : prf_h[i - 1]
	h_right = i == n - 1 ? 0 : suf_h[i + 1]
	result << (sum_w - w[i]) * [h_left, h_right].max
end

puts result.join(' ')

friends = gets.strip.to_i
fr_sizes = Array.new(friends)

w = 0
h1,h2 = 0,0

#read
friends.times do |n|
    pair = gets.strip.split(' ').map(&:to_i)
    w += pair[0]
    if h1 < pair[1] then
        h2 = h1
        h1 = pair[1]
    elsif h2 < pair[1] then
        h2 = pair[1]
    end
    fr_sizes[n] = pair
end

fr_sizes.each do |wf, hf|
    width = w - wf
    height = (hf == h1 ? h2 : h1)
    print "#{width * height} "
end


n = gets.to_i
n.times do
  x,y,z = gets.chomp.split(" ").map(&:to_i)
  max = [x,y,z].max
  if x == max && y == max && z == max
    puts "YES"
    puts "#{max} #{max} #{max}"
  elsif x == max && y == max
    puts "YES"
    puts "#{z} #{max} #{z}"
  elsif x == max && z == max
    puts "YES"
    puts "#{max} #{y} #{y}"
  elsif y == max && z == max
    puts "YES"
    puts "#{x} #{x} #{max}"
  else
    puts "NO"
  end
end

t = gets.chomp.to_i
t.times do
    atai = gets.chomp.split(" ").map(&:to_i)
    atai = atai.sort
    if  atai[0] != atai[1] && atai[1] != atai[2] && atai[0] != atai[2]
        puts "NO"
    elsif atai[0] == atai[1] && atai[1] == atai[2]
        puts "YES"
        print atai[0]
        print " "
        print atai[1]
        print " "
        print atai[2]
        print "\n"
    elsif atai[0] == atai[1] && atai[1] != atai[2]
        puts "NO"
    elsif atai[2] == atai[1] && atai[1] != atai[0]
        puts "YES"
        print atai[0]
        print " "
        print atai[0]
        print " "
        print atai[2]
        print "\n"
    end

end

tc = gets.to_i

tc.times do
    a = gets.split().map{|i| i.to_i }
    maxi = a.max
    b = a.uniq()
    if(a.count(maxi) > 1)
        puts "YES"
        if(b.size == 2)
            print "1 #{b[0]} #{b[1]}"
        else
            print "#{b[0]} "*3
        end
        puts ""
    else
        puts "NO"
    end
end

def solve
  x, y, z = gets.strip.split(' ').map(&:to_i)
  mx = [x , y, z].max
  c = 0; nt = -1
  if mx == x
    c += 1
  else
    nt = x
  end
  if mx == y
    c += 1
  else
    nt = y
  end
  if mx == z
    c += 1
  else
    nt = z
  end

  if c >= 2
    puts "YES"
    if nt == -1
      puts "#{x} #{y} #{z}"
    else
      puts "#{nt} #{nt} #{mx}"
    end
  else
    puts "NO"
  end
end

gets.strip.to_i.times { solve }

$, = ' '
gets.to_i.times do
    a = gets.split.map(&:to_i).sort
    if a[1] != a[2]
        puts "NO"
    else
        print "YES", a[0], a[0], a[2], "\n"
    end
end

gets.to_i.times do
  a = gets.split.map(&:to_i).sort
  puts 'NO' if a[1] != a[2]
  puts "YES\n#{a[2]}" + (" #{a[0]}" * 2) if a[1] == a[2]
end

gets.to_i.times do
  a = gets.split(' ').map(&:to_i).sort.reverse

  if a[0] != a[1]
    puts "NO"
    next
  end

  puts "YES"
  puts "#{a.first} #{a.last} 1"
end

gets.to_i.times do
	a = gets.split.map(&:to_i)
	x, y, z = a
	min, max = a.minmax
	case a.count(max)
	when 3
		puts 'YES', a.join(' ')
	when 2
		puts 'YES',
		     (
				if x != max
					[min, min, max]
				elsif y != max
					[min, max, min]
				else
					[max, min, min]
				end
		     ).join(' ')
	else
		puts 'NO'
	end
end

# frozen_string_literal: true

lines = gets.to_i
lines.times do
  xyz = gets.split(' ').map(&:to_i).sort.reverse
  if xyz[0] == xyz[1]
    print 'YES', "\n"
    print "#{xyz[0]} #{xyz[2]} 1", "\n"
  else
    print 'NO', "\n"
  end
end

# frozen_string_literal: true

lines = gets.to_i
lines.times do
  xyz = gets.split(' ').map(&:to_i).sort.reverse
  if xyz[0] == xyz[1]
    print 'YES', "\n"
    print "#{xyz[0]} 1 1", "\n"
  else
    print 'NO', "\n"
  end
end

# frozen_string_literal: true

lines = gets.to_i
lines.times do
  xyz = gets.split(' ').map(&:to_i).sort.reverse
  if xyz[0] == xyz[1]
    print 'YES', "\n"
    print "#{xyz[0]} #{xyz[1]} 1", "\n"
  else
    print 'NO', "\n"
  end
end

t = gets.chomp.to_i
t.times do
    x, y ,z = gets.chomp.split(" ").map(&:to_i)
    if x != y && y != z
        puts "NO"
    elsif x == y && y == z
        puts "YES"
        puts "#{x}" +" " + "#{y}" + " " + "#{z}"
    elsif x == y && y != z && x > z
        puts "YES"
        puts "#{z}" +" " + "#{y}" + " " + "#{z}"
    elsif x == y && y != z && x < z
        puts "NO"
    elsif x == z && y != z && x > y
        puts "YES"
        puts "#{x}" +" " + "#{y}" + " " + "#{y}"
    elsif x == z && y != z && x < y
        puts "NO"
    elsif y == z && x != z && y > x
        puts "YES"
        puts "#{x}" +" " + "#{x}" + " " + "#{z}"
    elsif y == z && x != z && y < x
        puts "NO"
    end
end

t = gets.chomp.to_i
t.times do
    atai = gets.chomp.split(" ").map(&:to_i)
    atai = atai.sort
    if  atai[0] != atai[1] && atai[1] != atai[2] && atai[0] != atai[2]
        puts "NO"
    elsif atai[0] != atai[1] && atai[1] != atai[2]
        puts "YES"
        print atai[0]
        print " "
        print atai[1]
        print " "
        print atai[2]
        print "\n"
    elsif atai[0] == atai[1] && atai[1] != atai[2]
        puts "NO"
    elsif atai[2] == atai[1] && atai[1] != atai[0]
        puts "YES"
        print atai[0]
        print " "
        print atai[0]
        print " "
        print atai[2]
        print "\n"
    end

end


n = gets.to_i
a = gets.split(' ').map(&:to_i)
a.insert(0, 0)
dp = []
dp[0] = 0
pos = {}
for i in 1..n
  pos[a[i]] = [] if pos[a[i]].nil?
  pos[a[i]] << i
  dp[i] = dp[i-1]
  dp[i] += a[i] if a[i] > 0
end
hash = Hash.new(false)
ret = nil
seg = nil
for i in 1..n
  next if hash[a[i]]
  hash[a[i]] = true
  ind = pos[a[i]][-1]
  if ind != i
    result = dp[ind] - dp[i-1]
    result += a[i] * 2 if a[i] < 0
    if ret == nil || ret < result
      ret = result
      seg = [i, ind]
    end
  end
end
tree = []
for i in 1...seg[0]
  tree << i
end
for i in seg[0] + 1 ... seg[1]
  tree << i if a[i] < 0
end
for i in seg[1] + 1 ..n
  tree << i
end
puts "#{ret} #{tree.size}"
puts tree.join(' ')

n=gets.to_i
a=gets.split.map(&:to_i)
o={}
s=[0]
m=-10**10
m1,m2=0
for i in 1..n do
  b=a[i-1]
  s[i]=s[i-1]+[0,b].max
  if o[b].nil?
    o[b]=i
  else
    c=s[i]-s[o[b]-1]+[2*b,0].min
    m,m1,m2=c,o[b],i if c>=m
  end
end
d=a.each_with_index.map {|x,i| i+1 if i<m1-1||x<0&&i>=m1&&i<m2-1||i>=m2 }.compact
#puts m1,m2
puts "#{m} #{d.size}"
puts d.join(' ')

n=gets.to_i
a=gets.split.map(&:to_i)
o={}
s=[0]
m=-10**10
m1,m2=0
for i in 1..n do
  b=a[i-1]
  oo=o[b]
  s[i]=s[i-1]+(b>0?b:0)
  if oo.nil?
    o[b]=i
  else
    c=s[i]-s[oo-1]+(b>0?0:2*b)
    m,m1,m2=c,oo-1,i-1 if c>m
  end
end
d=(1..m1).to_a+(m2+2..n).to_a+a[m1+1..m2-1].each_with_index.map {|x,i| i+2+m1 if x<0 }.compact
#puts m1,m2
puts "#{m} #{d.size}"
puts d.join(' ')

n = gets.to_i
a = gets.split(' ').map(&:to_i)
a.insert(0, 0)
dp = []
dp[0] = 0
for i in 1..n
  dp[i] = dp[i-1]
  dp[i] += a[i] if a[i] > 0
end
hash = Hash.new(false)
ret = nil
seg = nil
for i in 1..n
  next if hash[a[i]]
  hash[a[i]] = true
  ind = a.rindex(a[i])
  if ind != i
    result = dp[ind] - dp[i-1]
    result += a[i] * 2 if a[i] < 0
    if ret == nil || ret < result
      ret = result
      seg = [i, ind]
    end
  end
end
tree = []
for i in 1...seg[0]
  tree << i
end
for i in seg[0] + 1 ... seg[1]
  tree << i if a[i] < 0
end
for i in seg[1] + 1 ..n
  tree << i
end
puts "#{ret} #{tree.size}"
puts tree.join(' ')

n = gets.to_i
a = gets.split(' ').map(&:to_i)
a.insert(0, 0)
seg = {}
for i in 1..n
  sum = a[i]
  for j in i + 1..n
    sum += a[j] unless a[j] < 0
    if a[i] == a[j]
      sum += a[j] if a[j] < 0
      seg[[i, j]] = sum
      sum -= a[j] if a[j] < 0
    end
  end
end
ret = nil
key = nil
seg.each do |k, v|
  if ret.nil? || v > ret
    key = k
    ret = v
  end
end
tree = []
for i in 1...key[0]
  tree << i
end
for i in key[0] + 1...key[1]
  tree << i if a[i] <= 0
end
for i in key[1] + 1..n
  tree << i
end
puts "#{ret} #{tree.size}"

puts tree.join(' ')

n = gets.to_i
a = gets.split(' ').map(&:to_i)
a.insert(0, 0)
seg = {}
for i in 1..n
  sum = a[i]
  for j in i + 1...a.size
    sum += a[j] unless a[j] < 0
    if a[i] == a[j]
      sum += a[j] if a[j] < 0
      seg[[i, j]] = sum
    end
  end
end
ret = nil
key = nil
seg.each do |k, v|
  if ret.nil? || v > ret
    key = k
    ret = v
  end
end
tree = []
for i in 1...key[0]
  tree << i
end
for i in key[0] + 1...key[1]
  tree << i if a[i] <= 0
end
for i in key[1] + 1..n
  tree << i
end
puts "#{ret} #{tree.size}"

puts tree.join(' ')

n = gets.to_i
a = gets.split(' ').map(&:to_i)
seg = {}
for i in 0...a.size
  sum = a[i]
  for j in i + 1...a.size
    sum += a[j] unless a[j] < 0
    if a[i] == a[j]
      sum += a[j] if a[j] < 0
      seg[[i+1, j+1]] = sum
    end
  end
end
ret = nil
key = nil
seg.each do |k, v|
  if ret.nil? || v > ret
    key = k
    ret = v
  end
end
tree = []
for i in 1...key[0]
  tree << i
end

for i in key[0] + 1...key[1]
  tree << i if a[i - 1] <= 0
end
for i in key[1] + 1..n
  tree << i
end
puts "#{ret} #{tree.size}"

puts tree.join(' ')

n = gets.to_i
a = gets.split(' ').map(&:to_i)
a.insert(0, 0)
dp = []
dp[0] = 0
for i in 1..n
  dp[i] = dp[i-1]
  dp[i] += a[i] if a[i] > 0
end
hash = Hash.new(false)
ret = nil
seg = nil
for i in 1..n
  next if hash[a[i]]
  hash[a[i]] = true
  ind = a.rindex(a[i])
  if ind != i
    result = dp[ind] - dp[i-1]
    if ret == nil || ret < result
      ret = result
      seg = [i, ind]
    end
  end
end
tree = []
for i in 1...seg[0]
  tree << i
end
for i in seg[0] + 1 ... seg[1]
  tree << i if a[i] < 0
end
for i in seg[1] + 1 ..n
  tree << i
end
puts "#{ret} #{tree.size}"
puts tree.join(' ')

n = gets.to_i
a = gets.split(' ').map(&:to_i)
seg = {}
for i in 0...a.size
  sum = a[i]
  for j in i + 1...a.size
    sum += a[j] unless a[j] < 0
    if a[i] == a[j]
      sum += a[j] if a[j] < 0
      seg[[i+1, j+1]] = sum
    end
  end
end
ret = nil
key = nil
seg.each do |k, v|
  if ret.nil? || v > ret
    key = k
    ret = v
  end
end
tree = []
for i in 1...key[0]
  tree << i
end
for i in key[0]...key[1]
  tree << i if a[i - 1] <= 0
end
for i in key[1]..n
  tree << i
end
puts "#{ret} #{tree.size}"

puts tree.join(' ')

n=gets.to_i
a=gets.split.map(&:to_i)
o={}
s=[0]
m=-10**10
m1,m2=0
for i in 1..n do
  b=a[i-1]
  oo=o[b]
  s[i]=s[i-1]+b>0?b:0
  if oo.nil?
    o[b]=i
  else
    c=s[i]-s[oo-1]+b>0?0:2*b
    m,m1,m2=c,oo-1,i-1 if c>m
  end
end
d=(0..m1).to_a+(m2..n-1).to_a+a[m1+1..m2-1].each_with_index.map {|x,i| i+1 if x<0 }.compact
puts "#{m} #{d.size}"
puts d.join(' ')


N = gets.to_i
C = gets.split.map(&:to_i)

d1 = C.rindex { |c| C[0] != c }
d2 = N - C.index { |c| C[-1] != c } - 1

puts [d1, d2].max

n = gets.to_i
c = gets.split.map(&:to_i)
l = []
r = []
n.times do |i|
  break if l.length == 2
  if l.length == 0
    l << [c[i],i]
  elsif l.length == 1 && l[0][0] != c[i]
    l << [c[i],i]
  end
end
n.times do |i|
  break if r.length == 2
  if r.length == 0
    r << [c[-i-1],n-i-1]
  elsif r.length == 1 && r[0][0] != c[-i-1]
    r << [c[-i-1],n-i-1]
  end
end
ans = 0
if l[0][0] != r[0][0]
  ans = r[0][1] - l[0][1]
else
  ans = [r[1][1] - l[0][1],r[0][1] - l[1][1]].max
end
p ans

n = gets.to_i
c = gets.split.map(&:to_i)
ans = 0
for i in 1..n-1
    if c[0] != c[i]
        ans = i
    end
end
(n-2).downto(0) do |i|
    if c[-1] != c[i] && ans < n-1-i
        ans = n-1-i
    end
end
puts ans


#!/usr/bin/ruby
class Counter < Hash
	def initialize(a=[])
		super
		self.default=0
		a.each{|e|self[e]+=1}
	end
	def self.[](*a)
		new(a)
	end
end
def Counter(a=[]) Counter.new(a) end

n=gets.to_i
b=Counter(gets.split.map(&:to_i))
m=gets.to_i
p gets.split.map(&:to_i).zip(gets.split.map(&:to_i)).each_with_index.map{|(k,l),z|[b[k],b[l],z+1]}.max[2]

n = readline.to_i
arr = readline.split(' ').collect(&:to_i)
map = Hash.new(0)
arr.each{|n| map[n] = map[n] + 1}

m = readline.to_i
b = readline.split(' ').collect(&:to_i)
c = readline.split(' ').collect(&:to_i)
besti, bestb, bestc = -1, -1, -1
b.zip(c).each_with_index do |item, ind|
  bb, cc = item
  thisb, thisc = map[bb], map[cc]
  if thisb > bestb || thisb == bestb && thisc > bestc
    besti, bestb, bestc = ind, thisb, thisc
  end
end

puts besti + 1

parse_int = lambda { gets.split.map{|x| x.to_i} }

scientists = gets.to_i
sc_langs = parse_int.call
films = gets.to_i
film_voice = parse_int.call
film_sub = parse_int.call

#p film_voice.to_s
#p film_sub.to_s

ppl_in_lang = Hash.new
ppl_in_lang.default = 0

sc_langs.each { |_|
  if ppl_in_lang[_] == 0
    ppl_in_lang[_]=1
  else
    ppl_in_lang[_]+=1
  end
}

#p ppl_in_lang.to_s

film_good, film_ok = [0]*films, [0]*films

films.times { |_|
  film_good[_] += ppl_in_lang[film_voice[_]]
  film_ok[_]   += ppl_in_lang[film_sub[_]  ]
}
#p sc_langs.to_s
#p sc_langs[3]

best = 0
films.times { |_|
  best = _ if film_good[_] > film_good[best]
  best = _ if (film_good[_] == film_good[best]) and (film_ok[_] > film_ok[best])
}
#p film_good.to_s
#p film_ok.to_s

p best+1


gets.to_i.times{n,a,b,c,d=gets.split.map &:to_i
h=Hash.new{[]}
(2..n).map{p,q=gets.split.map &:to_i;h[p]<<=q;h[q]<<=p}
e=->s{z={};v=-1
f=->c{z[c]||(z[c]=v+=1;h[c].map &f;v-=1)}
f[s];z}
i=e[a]
puts i[b]>c&&e[i.max_by{|k,v|v}[0]].values.max>2*c&&d>2*c ?"Bob":"Alice"}


t = gets.chomp.to_i
t.times do
  n = gets.chomp.to_i
  arr = gets.chomp.split(' ').map(&:to_i)
  dp = Hash.new(0)
  min = 10 ** 10
  arr.each do |el|
    dp[el] += 1
  end
  dp.each do |k, v|
    if v == 1
      min = [min, k].min
    end
  end
  puts (arr.index(min) || -2) + 1
end

t = gets.to_i

1.upto t do
  n = gets.to_i
  a = gets.split.map(&:to_i)
  list = a.tally.keep_if {|_, v| v == 1}.keys
  if list.empty?
    puts -1
  else
    puts a.index(list.min)+1
  end
end

t = gets.chomp.to_i
t.times do
    n = gets.chomp.to_i
    a = gets.chomp.split(" ").map(&:to_i)
    count = Hash.new(0)
    index = Hash.new(0)
    ans = []
    a.each_with_index do |i,j|
        count[i] += 1
    end
    #p index
    min = Float::INFINITY
    count.each do |i,j|
        if j == 1
            min = [min,i].min
        end
    end
    if min == Float::INFINITY
        puts "-1"
    else
        a.each_with_index do |i,j|
            if i == min
                puts j+1
            end
        end
    end
end


n, k = gets.split.map(&:to_i)
id = gets.split.map(&:to_i)
ans = []
id.each {|idi|
  unless ans.include?(idi)
    ans.pop if ans.size == k
    ans.unshift(idi)
  end
}
p ans.size
puts ans.join(" ")

MOD=10**9+7
cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

#def bs(ar,eq,n) en=(eq==1 ? :>= : :>); ar.bsearch_index{|x|x.send(en,n)} end
def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end

def puts_yesno(can) puts(can ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def debug(k,v) puts "#{k}:#{v}" end
########### ( ˘ω˘ )ｽﾔｧ… ###########
n, k = gsmi
ids = gsmi

dis = []

ids.each do |id|
  if h[id]==0
    dis.unshift(id)
    h[id]=1
  end
  if dis.size>k
    nn = dis.pop
    h[nn]=0
  end
end

puts "#{dis.size}\n#{dis.join(' ')}"

MOD=10**9+7
cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

#def bs(ar,eq,n) en=(eq==1 ? :>= : :>); ar.bsearch_index{|x|x.send(en,n)} end
def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end

def puts_yesno(can) puts(can ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def debug(k,v) puts "#{k}:#{v}" end
########### ( ˘ω˘ )ｽﾔｧ… ###########
n, k = gsmi
ids = gsmi

dis = []

ids.each do |id|
  dis.unshift(id) if dis.index(id).nil?
  dis.pop if dis.size>k
end

puts "#{dis.size}\n#{dis.join(' ')}"


n = gets.to_i
rects = []
n.times do
  mn, mx = gets.strip.split.map(&:to_i)
  rects << [mn, mx].sort
end

mxh = rects[0][1]
possible = true
1.upto(n-1).each do |i|
  if rects[i][0] > mxh
    possible = false
    break
  else
    if rects[i][1] <= mxh
      mxh = rects[i][1]
    else
      mxh = rects[i][0]
    end
  end
end

puts (possible ? "YES" : "NO")

x = gets.chomp.to_i

best = Integer(1e9+100)
f = true
for i in 0... x
  y =  gets.strip.split(' ').map(&:to_i);
  mx = [y[0], y[1]].max
  mn = [y[0] , y[1]].min
  if mx <= best
    best = mx;
  elsif mn <= best
    best = mn
  else
    f = false
  end

end
unless f
  print "NO"
else
  print "YES"
end

def can_arrage_non_ascending(rects)

  limit = 10**10

  rects.each do |w, h|
    a, b = [w, h].sort
    if b <= limit
      limit = b
    elsif a <= limit
      limit = a
    else
      return false
    end
  end

  true

end

def solution
  count = read_int
  rects = []
  count.times do
    rects << read_ints
  end

  puts can_arrage_non_ascending(rects) ? "YES" : "NO"
end

def read_int
  gets.to_i
end

def read_ints
  gets.split.map &:to_i
end

def read_string
  gets.chomp
end

solution

N = gets.to_i
wh = N.times.map{gets.split.map(&:to_i)}

num = 10**10
wh.each do |arr|
    num = arr.select{|e| e <= num}.max
    unless num
        puts 'NO'
        exit
    end
end
puts 'YES'


t = gets.to_i
(1..t).each do
  n = gets.to_i
  a = gets.split(' ')
  mp = Hash.new(0)
  a.each do |i|
    mp[i]+=1
  end
  if mp.length == 1
    puts 1
    (1..n).each do
      print "1 "
    end
    puts ""
  elsif n.modulo(2)==0
    puts "2"
    (1..n).each do |i|
      print "#{i.modulo(2)+1} "
    end
    puts ""
    elsif a[0]==a[n-1]
      puts "2"
      (1..n).each do |i|
        print "#{i.modulo(2)+1} "
      end
      puts ""
    else
      x = -1
      (1..n-1).each do |i|
        if(a[i]==a[i-1])
          x = i
          break
        end
      end
      if x!=-1
        puts "2"
        (0..n-1).each do |i|
          if i<x
            print "#{i.modulo(2)+1} "
          else
            print "#{(i+1).modulo(2)+1} "
          end
        end
        puts ""
      else
        puts "3"
        (1..n-1).each do |i|
          print "#{i.modulo(2)+1} "
        end
        puts "3"
      end
    end
  end

gets.to_i.times do
	n = gets.to_i
	a = gets.split.map(&:to_i)
	ans = Array.new(n, 0)
	if a.count(a[0]) == n
		ans = Array.new(n, 1)
	elsif a[0] == a[n - 1] || n % 2 == 0
		ans = (0...n).map{|i| i % 2 + 1}
	else
		ans = (0...n).map{|i| i % 2 + 1}
		pos = (0...(n - 1)).to_a.index{|i| a[i] == a[i + 1]}
		if pos
			((pos + 1)...n).each{|i| ans[i] = (ans[i] == 1 ? 2 : 1)}
		else
			ans[n - 1] = 3
		end
	end

	puts ans.uniq.size
	puts ans.join(' ')
end

gets.to_i.times do
	n = gets.to_i
	a = gets.split.map(&:to_i)
	b = a.sort.uniq
	ans = a.map do |i|
		l, r = -1, b.size
		while r - l > 1
			mid = (r + l) / 2
			if b[mid] >= i
				r = mid
			else
				l = mid
			end
		end
		r + 1
	end
	puts ans.uniq.size
	puts ans.join(' ')
end


def solve(io)
    n = io.gets.to_i
    arr = 2.times.map{ io.gets.split(" ").map{|s| s.to_i} }
    max = n.times.inject([0, 0, 0]) do |prev, i|
        [[prev[1], prev[2]].max, [prev[0], prev[2]].max + arr[0][i], [prev[0], prev[1]].max + arr[1][i]]
    end.max
    puts max
end

solve(STDIN)

def check(num, team, row, column, opp_row)
    max = team[ row ][ column ]
    if column + 1 < num
        max += team[ opp_row ][ column + 1 ]
    end
    if column + 2 < num
        sum2 = team[ row ][ column ] + team[ opp_row ][ column + 2 ]
        if(max < sum2)
            max = sum2;
        end
    end
    team[ row ][ column ] = max
end
def start(num, team)
    column = num - 1
    while column >= 0 do
        check(num, team, 0, column, 1)
        check(num, team, 1, column, 0)
        column -= 1;
    end
    if(team[ 0 ][ 0 ] > team[ 1 ][ 0 ])
        return team[ 0 ][ 0 ]
    end
    return team[ 1 ][ 0 ]
end
team = []
num = gets.chomp.to_i
team.push(gets.chomp.split(' ').collect{|var| var.to_i})
team.push(gets.chomp.split(' ').collect{|var| var.to_i})
puts start(num,team.clone)

def recur(num,team,row,column)
    sum1 = 0
    if(column == num)
        return 0
    else
        if row == 1
            sum_1 = team[row][column] + recur(num,team,0,column + 1)
            sum_2 = recur(num,team,row,column + 1)
            if(sum_1 > sum_2)
                sum1 = sum_1
            else
                sum1 = sum_2
            end
        else
            sum_1 = team[row][column] + recur(num,team,1,column + 1)
            sum_2 = recur(num,team,row,column + 1)
            if(sum_1 > sum_2)
                sum1 = sum_1
            else
                sum1 = sum_2
            end
        end
        return sum1
    end
end
def start(num, team)
    sum1 = team[1][0] + recur(num,team,0,1)
    sum2 = team[0][0] + recur(num,team,1,1)
    if(sum1 > sum2)
        return sum1
    end
    return sum2
end
team = []
num = gets.chomp.to_i
team.push(gets.chomp.split(' ').collect{|var| var.to_i})
team.push(gets.chomp.split(' ').collect{|var| var.to_i})

def recur(num,team,row,column)
    sum1 = 0
    if(column == num)
        return 0
    else
        if row == 1
            sum_1 = team[row][column] + recur(num,team,0,column + 1)
            sum_2 = recur(num,team,row,column)
            if(sum_1 > sum_2)
                sum1 = sum_1
            else
                sum1 = sum_2
            end
        else
            sum_1 = team[row][column] + recur(num,team,1,column + 1)
            sum_2 = recur(num,team,row,column)
            if(sum_1 > sum_2)
                sum1 = sum_1
            else
                sum1 = sum_2
            end
        end
        return sum1
    end
end
def start(num, team)
    sum1 = team[1][0] + recur(num,team,0,1)
    sum2 = team[0][0] + recur(num,team,1,1)
    if(sum1 > sum2)
        return sum1
    end
    return sum2
end
team = []
num = gets.chomp.to_i
team.push(gets.chomp.split(' ').collect{|var| var.to_i})
team.push(gets.chomp.split(' ').collect{|var| var.to_i})


def g(r, n)
    d = (2 * r * r) ** 0.5

    return 0 if n == 0
    return 2 * r + d if n == 1

    2 * r + d + (2 * d + r * n) * (n - 1)
end

m, r = gets.chomp.split(' ').map { |x| x.to_i }

total = 0.0

for n in 1..m
    total += g(r, n - 1) + g(r, m - n) + 2 * r
end

puts total / m ** 2

#def f(n, r)
#  return 2 * r if n == 0
#  return 2 * n * r + (2 * r ** 2) ** 0.5
#end

def g(n, r)
  return 0 if n == 0
  (r * (n + 1) + (2 * r ** 2) ** 0.5) * n
end

m, r = gets.chomp.split(' ').map { |x| x.to_i }
total_sum = 0
for n in 1..m
  total_sum += g(n - 1, r) + g(m - n, r) + 2 * r
end

puts total_sum * 1.0 / m ** 2
=begin
if f(0, 1) != 2
  puts "Error"
  exit
end

if f(2, 1) != 4 * 1 + 2 ** 0.5
  puts "Error"
  exit
end

if g(2, 1) != 4 * 1 + 2 ** 0.5
  puts "Error"
  exit
end
=end

def g(n, r)
  return 0 if n == 0
  (r * (n + 1) + (2 * r ** 2) ** 0.5) * n
end

m, r = gets.chomp.split(' ').map { |x| x.to_i }
total_sum = 0.0
for n in 1..m
  total_sum += g(n - 1, r) + g(m - n, r) + 2 * r
end

puts total_sum / m ** 2


N=STDIN.gets.strip.to_i
(0..N-1).each do |i|
  s,t=STDIN.gets.strip.split
  if s<t
    puts s
  else
    sorteds=s.chars.sort.join

    #puts sorteds

    changeindex=-1
    (0..s.size-1).each do |i|
      if sorteds[i]!=s[i]
        changeindex=i
        break
      end
    end
    if changeindex==-1
      puts '---'
      next
    end
    #p changeindex

    ss=sorteds[changeindex]
    index=-1
    c=0
    s.chars do |i|
      if i==ss
        index=c
      end
      c+=1
    end
    tmp=s[index]
    s[index]=s[changeindex]
    s[changeindex]=tmp
    if s<t
      puts s
    else
      puts '---'
    end
  end
end

def solution
  n = gets.chomp.to_i
  mi = Array.new(n-1)
  n.times do
    s, c = gets.chomp.split(' ')
    n = s.size
    mi[n-1] = n-1
    (n-2).downto(0) do |i|
      mi[i] = s[i] < s[mi[i+1]] ? i : mi[i+1]
    end
    0.upto(n-1) do |i|
      if s[i] > s[mi[i]]
        s[i], s[mi[i]] = s[mi[i]], s[i]
        break
      end
    end
    puts (s < c ? s : '---')
  end
end

solution

def smallest(w)
  ary = w.chars
  ary_with_index = ary.each_with_index.sort
  ary_with_index.each_with_index do |(a, i), j|
    if i > j
      a = ary[i]
      _, i = ary_with_index.select { |(x, y)| x == a }.max_by { |x, y| y}
      ary[i], ary[j] = ary[j], ary[i]
      return ary.join('')
    end
  end
  ary.join('')
end

nb = gets.to_i
nb.times do
  w1, w2 = gets.chomp.split
  w = smallest(w1)
  puts w < w2 ? w : '---'
end

def smallest(w)
  ary = w.chars
  ary_with_index = ary.each_with_index.sort
  ary_with_index.each_with_index do |(a, i), j|
    if i > j
      ary[i], ary[j] = ary[j], ary[i]
      break
    end
  end
  ary.join('')
end

nb = gets.to_i
nb.times do
  w1, w2 = gets.chomp.split
  w = smallest(w1)
  puts w < w2 ? w : '---'
end

def smallest(w)
  ary = w.chars
  ary_with_index = ary.each_with_index.sort
  ary_with_index.each_with_index do |(a, i), j|
    if i > j
      ary[i], ary[j] = ary[j], ary[i]
      return ary.join('')
    end
  end
  ary.join('')
end

nb = gets.to_i
nb.times do
  w1, w2 = gets.chomp.split
  w = smallest(w1)
  puts w < w2 ? w : '---'
end

def smallest(w)
  ary = w.chars
  ary_with_index = ary.each_with_index.sort
  ary_with_index.each_with_index do |(a, i), j|
    if i > j
      ary[i], ary[j] = ary[j], ary[i]
      break
    end
  end
  ary.join('')
end

nb = gets.to_i
nb.times do
  w1, w2 = gets.chomp.split
  w = smallest(w1)
  print w < w2 ? w : '---'
end


n = gets.to_i;
c = gets.split(' ').map(&:to_i);
idx = (0..n-1).to_a.sort{|x, y|
  c[x] <=> c[y]
}
a = Array.new(n); b = Array.new(n);
cnt = (n+2)/3;

n.times{|i|
  j = idx[i];
  if i < cnt
    a[j] = i; b[j] = c[j] - a[j];
  elsif i < 2*cnt
    b[j] = i; a[j] = c[j] - b[j];
  else
    b[j] = n - i - 1; a[j] = c[j] - b[j];
  end
}
puts "YES"
puts a.map(&:to_s).join(' ')
puts b.map(&:to_s).join(' ')

n = gets.to_i;
c = gets.split(' ').map(&:to_i);
idx = (0..n-1).to_a.sort{|x, y|
  c[x] <=> c[y]
}
a = Array.new(n); b = Array.new(n);
cnt = (n+2)/3;

n.times{|i|
  j = idx[i];
  if i < cnt
    a[j] = i; b[j] = c[j] - a[j];
  elsif i < 2*cnt
    b[j] = i; a[j] = c[j] - b[j];
  else
    b[j] = n - i; a[j] = c[j] - b[j];
  end
}
puts "YES"
puts a.map(&:to_s).join(' ')
puts b.map(&:to_s).join(' ')

n = gets.to_i;
c = gets.split(' ').map(&:to_i);
idx = (0..n-1).to_a.sort{|x, y|
  c[x] <=> c[y]
}
a = Array.new(n); b = Array.new(n);
cnt = (n+2)/3;

n.times{|i|
  j = idx[i];
  if i < cnt
    a[j] = i; b[j] = c[j] - a[j];
  elsif i < 2*cnt
    b[j] = i; a[j] = c[j] - b[j];
  else
    b[j] = n - i; a[j] = c[j] - b[j];
  end
}
puts a.map(&:to_s).join(' ')
puts b.map(&:to_s).join(' ')


n = gets.to_i
a = gets.split.map(&:to_i)
count = 0
neg = 0
files = Array.new
for i in a
  if i < 0 then neg += 1 end
  if neg == 3
    files << count
    count = 0
    neg = 1
  end
  count += 1
end
files << count
puts files.count
files.each {|x| print x, " "}

n = gets.to_i
nums = gets.split.map{|i| i.to_i}

i = 0
folder = []
while i < n do
    folder << 1
    if nums[i] >= 0 then
        k = 0
    else
        k = 1
    end
    i += 1
    while k < 2 && i < n do
        folder[-1] += 1
        if nums[i] < 0 then
            k += 1
        end
        i += 1
    end
    while i < n && nums[i] >= 0 do
        folder[-1] += 1
        i += 1
    end
end

puts folder.size
puts folder.join(" ")

e = []
nn = 1
gets
ns = gets.chomp.split.map{|a| Integer(a)}
ns.each.with_index{|x,i| if x < 0 then e.insert(-1,i+1) end }
e=e.each_slice(2).map{|x| x.last}
if e.length == 0 then
  puts [1,ns.length]
else
  puts e.length
  e[e.length-1]=ns.length
  e.insert(0,0)
  puts e[1..e.length-1].zip(e[0..e.length-2]).map{|a,b| a-b}.join(" ")
end

n=gets.to_i
a=gets.split.map(&:to_i)
res=[]
c=k=0
a.each do |v|
    c+=1
    k+=1 if v<0
    if k==2 then
        res.push(c)
        c=k=0
    end
end
if res.empty? then
    puts 1
    puts n
else
    if k > 0 then
        res.push(c)
    else
        res[res.size()-1]+=c
    end
    puts res.size
    puts res*' '
end

def main()
	n=gets.chomp.to_i;
	ar=gets.chomp.split(" ");
	ar=ar.map{|i| i.to_i};
	nof=0;non=0;noeinf=[];
	noe=0;
	for i in 0...(ar.length)
		if ar[i]<0
			non+=1
		else
			noe+=1;
		end
		if non==3
			noeinf << noe+2;
			nof+=1;
			non=1;
			noe=0;
		end
	end
	if non>0 || noe >0
		nof+=1;
		noeinf << (non+noe);
	end
	puts nof;
	puts noeinf.join(" ")
end
main()

n=readline.to_i
a=gets.chomp.split.map{|i| i.to_i}
counter=0
num=0
res=[]

a.each do |i|
if i<0 then
 counter=counter+1
end
if counter==3 then
 res.push num
 num=0
counter=1
end
num=num+1
end

if num>0
 res.push num
end

puts res.size
res.each do |i|
 print i.to_s+' '
end
print "\n"

n=gets.to_i
a=gets.split.collect{|e| e.to_i}
b=[]
k=0
l=0
for i in 0..n-1 do
  l+=1
  if (a[i]<0) then
    if (k==2) then
      b<<l-1
      l=1
      k=0
    end
    k+=1
  end
end
b<<l
puts b.size
b.each{|e| print e," "}
puts

e = []
nn = 1
gets
ns = gets.chomp.split.map{|a| Integer(a)}
ns.each.with_index{|x,i| if x < 0 then e.insert(-1,i+1) end }
e=e.each_slice(2).map{|x| x.last}
if e.length == 0 then
  puts [1,1]
else
  puts e.length
  e[e.length-1]=ns.length
  e.insert(0,0)
  puts e[1..e.length-1].zip(e[0..e.length-2]).map{|a,b| a-b}.join(" ")
end

n=gets.to_i
a=gets.split.map(&:to_i)
res=[]
c=k=0
a.each do |v|
    c+=1
    k+=1 if v<0
    if k==2 then
        res.push(c)
        c=k=0
    end
end
if res.empty? then
    puts 1
    puts n
else
    res[res.size()-1]+=c
    puts res.size
    puts res*' '
end

def main()
	n=gets.chomp.to_i;
	ar=gets.chomp.split(" ");
	ar=ar.map{|i| i.to_i};
	nof=0;non=0;noeinf=[];
	noe=0;
	for i in 0...(ar.length)
		if ar[i]<0
			non+=1
		else
			noe+=1;
		end
		if non==3
			noeinf << noe+non;
			nof+=1;
			non=0;
			noe=0;
		end
	end
	if non>0 || noe >0
		nof+=1;
		noeinf << (non+noe);
	end
	puts nof;
	puts noeinf.join(" ")
end
main()

def main()
	n=gets.chomp.to_i;
	ar=gets.chomp.split(" ");
	ar=ar.map{|i| i.to_i};
	nof=0;non=0;noeinf=[];
	noe=0;
	for i in 0...(ar.length)
		if ar[i]<0
			non+=1
		else
			noe+=1;
		end
		if non==2 && noe>=1
			noeinf << noe+non;
			nof+=1;
			non=0;
			noe=0;
		end
	end
	if non>0 || noe >0
		nof+=1;
		noeinf << (non+noe);
	end
	puts nof;
	puts noeinf.join(" ")
end
main()

def main()
	n=gets.chomp.to_i;
	ar=gets.chomp.split(" ");
	ar=ar.map{|i| i.to_i};
	ar=ar.sort
	nof=0;non=0;noeinf=[];
	for i in 0...(ar.length)
		if ar[i]<0
			non+=1
		else
			nof+=1;
			noef=(ar.length)-i;
			noeinf << noef+non;
 			break;
		end
		if non==3
			non=0;
			nof+=1;
			noeinf << 3;
		end
	end
	puts nof;
	puts noeinf.join(" ")
end
main()

def main()
	n=gets.chomp.to_i;
	ar=gets.chomp.split(" ");
	ar=ar.map{|i| i.to_i};
	ar=ar.sort
	nof=0;non=0;noeinf=[];
	for i in 0...(ar.length)
		if ar[i]<0
			non+=1
		else
			nof+=1;
			noef=(ar.length)-i;
			noeinf << noef+non;
 			break;
		end
		if non==3
			non=0;
			nof+=1;
			noeinf << 3;
		end
	end
	puts nof;
	noeinf=noeinf.sort
	puts noeinf.join(" ")
end
main()

def main()
	n=gets.chomp.to_i;
	ar=gets.chomp.split(" ");
	ar=ar.map{|i| i.to_i};
	nof=0;non=0;noeinf=[];
	noe=0;
	for i in 0...(ar.length)
		if ar[i]<0
			non+=1
		else
			noe+=1;
		end
		if non==2
			noeinf << noe+non;
			nof+=1;
			non=0;
			noe=0;
		end
	end
	if non>0 || noe >0
		nof+=1;
		noeinf << (non+noe);
	end
	puts nof;
	puts noeinf.join(" ")
end
main()


gets.to_i.times do
  s = gets.chomp
  puts s.chars.chunk { |a| a }.map(&:last).map(&:size).min == 1 ? "NO" : "YES"
end

gets.to_i.times do
  s = gets.chomp.split('')
  c = 1
  flag = true
  1.upto(s.size-1) do |i|
    if s[i]==s[i-1] then
      c += 1
    else
      flag = false if c < 2
      c = 1
    end
  end
  flag = false if c < 2
  puts flag ? "YES":"NO"
end


n = gets.to_f
x = Math.log(n,2)

count = 0
expon = 0
curr = 2**expon

minicount = 0

while (count < n-2)
  print "#{curr} "
  count += 1
  minicount += 1
  if minicount == (n/(curr*2)).round(0)
    minicount = 0
    expon += 1
    curr = 2**expon
  end
end

thisthing = 2**((x.floor)-1)
if n==1
  puts 1
  exit
end
print "#{thisthing} "
puts "#{(n.to_i/thisthing)*thisthing}"

# require 'prime'

def gcd(a, b)
  (b==0 ? a : gcd(b, a%b))
end

def arygcd(ary)
  ans = ary[0]
  ary.each do |x|
    ans = gcd(ans, x)
  end
  ans
end

n = gets.to_i

def solve(ary)
  n = ary.size
  if n==1
    return [1]
  elsif n==2
    return [1, 2]
  elsif n==3
    return [1, 1, 3]
  end
  ans = []
  nary = []
  ary.each do |x|
    if x%2 != 0
      ans << 1
    else
      nary << x/2
    end
  end
  solve(nary).each do |x|
    ans << 2*x
  end
  ans
end

ary = (1..n).to_a
puts solve(ary).join(" ")

n = gets.to_f
x = Math.log(n,2)

count = 0
expon = 0
curr = 2**expon

minicount = 0

while (count < n-2)
  print "#{curr} "
  count += 1
  minicount += 1
  if minicount == (n/(curr*2)).round(0)
    minicount = 0
    expon += 1
    curr = 2**expon
  end
end

thisthing = 2**((x.floor)-1)
if n==1
  exit
end
print "#{thisthing} "
puts "#{(n.to_i/thisthing)*thisthing}"


$\ = "\n"
gets.to_i.times do
    n = gets.to_i
    a = gets.split.map &:to_i
    s = a.sum
    if s < n
        print 1
    else
        print s - n
    end
end

gets.to_i.times do
    n = gets.to_i
    a = gets.split.map &:to_i
    s = a.sum
    puts s < n ? 1 : s - n
end

t = Integer(gets.chomp)
t.times{
    n = Integer(gets.chomp)
    a = gets.chomp.split().map!{|c| Integer(c)}

    som = a.sum()
    len = a.size()

    if(som < len)
        puts 1
    elsif(som == len)
        puts 0
    else
        puts som - len
    end
}

gets.to_i.times do
    n = gets.to_i
    a = gets.split.map &:to_i
    s = a.sum
    if s < n
        puts 1
    else
        puts s - n
    end
end