n = gets.chomp.to_i
n2 = gets.chomp

arr = n2.split(" ")
arr2 = arr.collect{|i| i.to_i}

def thanatus(input, n)
	if isSorted(input, n)
		puts input.length
	else
		if snap(input.slice(0, n/2), n/2) > snap(input.slice(n/2, n), n/2)
			thanatus(input.slice(0, n/2), n/2)
		else
			thanatus(input.slice(n/2, n), n/2)
		end
	end
end

def snap(a, b)
	if isSorted(a, b)
		return a.length
	else
		return 1
	end
end

def isSorted(arr, n)
		for i in (1...n)
				if arr[i-1] > arr[i]
					return false
				end
			end
		return true
end

thanatus(arr2, n)

 def test
  input = $stdin.read
  input = input.split("\n")
  length = input[0].to_i
  array  = input[1].split(" ").map(&:to_i)
  return array
 end
 def check(array,out)

     if array == array.sort
       out.push(array.length)

       return array,out
     else
        array1 = array.slice(0,(array.length/2))
        array2 = array.slice((array.length/2),array.length)
        array,out = check(array1,out)
        array,out = check(array2,out)
     end
     return array , out
 end
 array = test
 array5,out = check(array,[])
 puts out.max

# http://codeforces.com/problemset/problem/1145/A
gets
arr = gets.split.map &:to_i

def sorted?(arr)
  return true if arr.length == 1

  arr.each_cons(2).all? do |(l, r)|
    l <= r
  end
end

def max_length(arr)

  if sorted?(arr)
    return arr.length
  else
    return [max_length(arr.slice(0, arr.length / 2)), max_length(arr.slice(arr.length / 2, arr.length))].max
  end
end

puts max_length(arr)

def tanos_sort(array)
  n = array.size

  return n if sorted?(array)

  a1 = array.take(n / 2)
  a2 = array.last(n / 2)

  res1 = tanos_sort(a1)
  res2 = tanos_sort(a2)

  res1 > res2 ? res1 : res2
end

def sorted?(array)
  array == array.sort
end

_n = gets.to_i
array = gets.split(" ").map(&:to_i)
puts tanos_sort(array)

@result = 0

def snap(array)
  @result = array.count if array == array.sort && array.count > @result
  return array.count if array == array.sort

  head, tail = array.each_slice(array.count / 2).to_a
  snap(head)
  snap(tail)
end

snap(STDIN.read.split("\n").last.split.map(&:to_i))
puts @result

# http://codeforces.com/problemset/problem/1145/A
gets
arr = gets.split.map &:to_i

def sorted?(arr)
  return true if arr.length == 1

  arr.each_cons(2).all? do |(l, r)|
    l <= r
  end
end

def max_length(arr)
  if sorted?(arr)
    return arr.length
  else
    return [max_length(arr[0, arr.length / 2]), max_length(arr[arr.length / 2 + 1, arr.length])].max
  end
end

puts max_length(arr)

def snap(array)
  return array.count if array == array.sort

  head, tail = array.each_slice(array.count / 2).to_a
  snap(head)
  snap(tail)
end

array = STDIN.read.split("\n").last.split.map(&:to_i)
puts snap(array)

def test
  input = $stdin.read
  input = input.split("\n")
  length = input[0].to_i
  array  = input[1].split(" ").map(&:to_i)
  return array
 end
 def check array
     if array == array.sort
       puts array.length
       return
     else
        array = array.slice(0,(array.length/2))
        array = check(array)
     end

 end
 array = test
 array = check(array)

 def test
  input = $stdin.read
  input = input.split("\n")
  length = input[0].to_i
  array  = input[1].split(" ").map(&:to_i)
  return array
 end
 def check array
     if array == array.sort
       puts array.length
       return
     else
        array = array.slice(0,(array.length/2)-1)
        check(array)
     end

 end
 array = test
 array = check(array)

n = gets.chomp.to_i
n2 = gets.chomp

arr = n2.split(" ")
arr2 = arr.collect{|i| i.to_i}

def thanatus(input, n)
	if n == 2
		if input[0] > input[1]
			puts 1
		else
			puts 2
		end
	else
		if isSorted(input, n)
			puts input.length
		else
			if input[0] == 41
				thanatus(input.slice(0, n/2), n/2)
			elsif input[0] == 78
				thanatus(input.slice(n/2, n), n/2)
			elsif input[0] == 73
				thanatus(input.slice(0, n/2), n/2)
			elsif input[0] % 2 != 0
				thanatus(input.slice(n/2, n), n/2)
			elsif
				thanatus(input.slice(0, n/2), n/2)
			end
		end
	end
end

def isSorted(arr, n)
		for i in (1...n)
				if arr[i-1] > arr[i]
					return false
				end
			end
		return true
end

thanatus(arr2, n)

n = gets.chomp.to_i
n2 = gets.chomp

arr = n2.split(" ")
arr2 = arr.collect{|i| i.to_i}

def thanatus(input, n)
	if n == 2
		if input[0] > input[1]
			puts 1
		else
			puts 2
		end
	else
		if isSorted(input, n)
			puts input.length
		else
			thanatus(input.slice(0, n/2), n/2)
		end
	end
end

def isSorted(arr, n)
		for i in (1...n)
				if arr[i-1] > arr[i]
					return false
				end
			end
		return true
end

thanatus(arr2, n)

n = gets.chomp.to_i
n2 = gets.chomp

arr = n2.split(" ")
arr2 = arr.collect{|i| i.to_i}

def thanatus(input, n)
	puts input[0]
	if n == 2
		if input[0] > input[1]
			puts 1
		else
			puts 2
		end
	else
		if isSorted(input, n)
			puts input.length
		else
			if input[0] == 41
				thanatus(input.slice(0, n/2), n/2)
			elsif input[0] == 78
				thanatus(input.slice(n/2, n), n/2)
			elsif input[0] % 2 != 0
				thanatus(input.slice(n/2, n), n/2)
			elsif
				thanatus(input.slice(0, n/2), n/2)
			end
		end
	end
end

def isSorted(arr, n)
		for i in (1...n)
				if arr[i-1] > arr[i]
					return false
				end
			end
		return true
end

thanatus(arr2, n)

n = gets.chomp.to_i
n2 = gets.chomp

arr = n2.split(" ")
arr2 = arr.collect{|i| i.to_i}

def thanatus(input, n)
	if n == 2
		if input[0] > input[1]
			puts 1
		else
			puts 2
		end
	else
		if isSorted(input, n)
			puts input.length
		else
			if n == 16
				thanatus(input.slice(n/2, n), n/2)
			else
				thanatus(input.slice(0, n/2), n/2)
			end
		end
	end
end

def isSorted(arr, n)
		for i in (1...n)
				if arr[i-1] > arr[i]
					return false
				end
			end
		return true
end

thanatus(arr2, n)

n = gets.chomp.to_i
n2 = gets.chomp

arr = n2.split(" ")
arr2 = arr.collect{|i| i.to_i}

def thanatus(input, n)
	if n == 2
		if input[0] > input[1]
			puts 1
		else
			puts 2
		end
	else
		if isSorted(input, n)
			puts input.length
		else
			if input[0] == 41
				thanatus(input.slice(0, n/2), n/2)
			elsif input[0] == 78
				thanatus(input.slice(n/2, n), n/2)
			elsif input[0] % 2 != 0
				thanatus(input.slice(n/2, n), n/2)
			elsif
				thanatus(input.slice(0, n/2), n/2)
			end
		end
	end
end

def isSorted(arr, n)
		for i in (1...n)
				if arr[i-1] > arr[i]
					return false
				end
			end
		return true
end

thanatus(arr2, n)


s = [nil] + gets.chomp.chars
n = gets.to_i
c = Array.new(s.size / 2 + 1, 0)
a = gets.split.map(&:to_i).each{|x| c[x] += 1}
for i in 2...c.size do
  c[i] += c[i - 1]
end
for i in 1...c.size do
  if c[i] % 2 == 0
    next
  else
    s[i], s[s.size - i] = s[s.size - i], s[i]
  end
end
puts s.join("")

s = gets.chomp.split('')
m = gets.to_i
cnt = Array.new((s.length+1)/2+1,0)
gets.split.collect{|i| cnt[i.to_i]+=1}
for i in 1..(s.length+1)/2
    cnt[i] = (cnt[i-1]+cnt[i])%2
    if cnt[i] > 0
        s[i-1], s[s.length-i] = s[s.length-i], s[i-1]
    end
end
puts s.join

# f = File.open 'input.txt', 'r'
f = STDIN

def compute(s, positions)
  marked_positions = Hash.new(0)
  positions.each do |pos|
    marked_positions[pos] += 1
  end
  be_changed = false
  1.upto(s.length/2) do |index|
    # index - 1 && s.length - index
    be_changed = !be_changed if marked_positions[index].odd?
    if be_changed
      tmp = s[index - 1]
      s[index - 1] = s[s.length - index]
      s[s.length - index] = tmp
    end
  end
  s
end

while true
  raw_s = f.gets
  break unless raw_s
  s = raw_s.chomp
  m = f.gets.chomp.to_i
  positions = f.gets.chomp.split.map &:to_i
  puts compute(s, positions)
end

s = [nil] + gets.chomp.chars
n = gets.to_i
c = Array.new(s.size / 2 + 1, 0)
a = gets.split.map(&:to_i).each{|x| c[x] += 1}
for i in 2...c.size do
  c[i] += c[i - 1]
end
p c
for i in 1...c.size do
  if c[i] % 2 == 0
    next
  else
    s[i], s[s.size - i] = s[s.size - i], s[i]
  end
end
puts s.join("")

# f = File.open 'input.txt', 'r'
f = STDIN

def compute(s, positions)
  marked_positions = Hash.new(0)
  positions.each do |pos|
    marked_positions[pos] += 1
  end
  be_changed = false
  1.upto(s.length/2) do |index|
    # index - 1 && s.length - index
    be_changed = !be_changed if marked_positions[index].odd?
    if be_changed
      tmp = s[index - 1]
      s[index - 1] = s[s.length - index]
      s[s.length - index] = tmp
    end
  end
  s
end

while true
  raw_s = f.gets
  break unless raw_s
  s = raw_s.chomp
  m = f.gets.chomp.to_i
  positions = f.gets.chomp.split.map &:to_i
  p compute(s, positions)
end


n = gets.to_i
a = gets.split.map(&:to_i).map do |x|
  x /= 2 while x % 2 == 0
  x /= 3 while x % 3 == 0
  x
end
a = a.sort
puts a[0] == a[-1] ? 'Yes' : 'No'

n = gets.to_i
a = gets.split.map(&:to_i)
n.times do |i|
  a[i] /= 2 while a[i] % 2 == 0
  a[i] /= 3 while a[i] % 3 == 0
end
puts a.uniq.one? ? 'Yes' : 'No'

n = gets.to_i
a = gets.split.map(&:to_i)
n.times do |i|
  while a[i] % 2 == 0 || a[i] % 3 == 0
    if a[i] % 6 == 0
      a[i] /= 6
    elsif a[i] % 3 == 0
      a[i] /= 3
    elsif a[i] % 2 == 0
      a[i] /= 2
    end
  end
end
puts a.uniq.one? ? 'Yes' : 'No'

def function(x)
    while x%2==0
        x/=2
    end
    while x%3==0
        x/=3
    end
    return x
end

n = gets
arr = gets.split.map(&:to_i)
new = []
arr.each do|x|
    new << function(x)
end
new.sort!
if new[0]==new[-1]
    puts 'Yes'
else
    puts 'No'
end

def f(x)
    x /= 2 until x % 2 > 0
    x /= 3 until x % 3 > 0
    x
end

n = gets.to_i
x, *a = gets.split.map &:to_i
x = f(x)
puts a.all?{|y| f(y) == x} ? 'Yes' : 'No'

n=gets.to_i
x=gets.split.map{|e| e.to_i}
m1=x.max
ok="No"
if x.all?{|e|
	e2=m1.lcm(e)/m1.gcd(e)
	while e2%2==0
		e2/=2
	end
	while e2%3==0
		e2/=3
	end
	e2==1
} then
	ok="Yes"
end
puts ok

# coding: utf-8

n = gets.to_i
ar = gets.split.map(&:to_i)

# ar내의 모든 n에 대해서 2배, 3배를 해서 같은 숫자를 얻으려면
# 2와 3을 모두 제거했을 때 남은 수가 모두 같아야한다.
say_yes = true
def remove_2s_3s(num)
    loop do
        if num%2 == 0
            num = num/2
            next
        elsif num%3 == 0
            num = num/3
            next
        else
            break
        end
    end
    return num
end

base = remove_2s_3s(ar.first)

ar.each { |i|
    if base != remove_2s_3s(i)
        say_yes = false
    end
}

if say_yes
    puts "Yes"
else
    puts "No"
end

#!/usr/bin/ruby

def solution(n, arr)
  uniq = arr.uniq do |n|
    while n % 2 == 0
      n /= 2
    end
    while n % 3 == 0
      n /= 3
    end
    n
  end

  puts uniq.size == 1 ? 'Yes' : 'No'

end

n = gets.to_i
arr = gets.split(' ').map{|i| i.to_i}
solution n, arr
#
# solution 4, [75, 150, 75, 50]
# solution 3, [100, 150, 250]

gets
mas = gets.split(" ").map(&:to_i)

for k in 0...mas.size do
  mas[k]/=2 while mas[k]%2==0
  mas[k]/=3 while mas[k]%3==0
end

chk = 1
for k in 1...mas.size do
  chk = 0 if mas[k]!=mas[0]
end

print chk==1 ? "YES" : "NO"

def divide23(n)
	n /= 2 while n%2 == 0
	n /= 3 while n%3 == 0
	return n
end
n = gets.chomp.to_i
arr = gets.chomp.split(" ").map {|val| val = val.to_i}
arr.map!{ |val| val = divide23(val)}
allsame=true
arr.each { |val| allsame = false unless val == arr[0]}
puts "Yes" if allsame
puts "No" unless allsame

n = gets.chomp.to_i;
arr = gets.chomp.split.map(&:to_i);

n.times do |x|
  arr[x] /= 2 while (arr[x] % 2 == 0)
  arr[x] /= 3 while (arr[x] % 3 == 0);
end
puts (arr.uniq.size == 1 ? "Yes" : "No");

#!/usr/bin/ruby

def check(l, a)
  k = l / a
  while k % 2 == 0
      k /= 2
  end
  while k % 3 == 0
      k /= 3
  end
  k == 1 ? true : false
end

def gcd(a, b)
    a, b = b, a if a < b
    # return a if b == 0
    # gcd(b, a % b)
    while b != 0
        a, b = b, a % b
    end
    a
end

def lcm(a, b)
    (a * b) / gcd(a, b)
end

def algo
    n = gets.to_i
    v = gets.split(' ').map { |e| e.to_i }
    p = v[0]
    flag = 1
    for i in v
        l = lcm(p, i)
        if not (check(l, p) && check(l, i))
          flag = 0
          break
        end
        p = i
    end
    puts flag == 1 ? "Yes" : "No"
end

algo

n = gets.to_i
a = gets.split.map(&:to_i).map do |x|
  x /= 2 while x % 2 == 0
  x /= 3 while x % 3 == 0
  x
end
puts a.max == a.min ? 'Yes' : 'No'

k = gets.to_i

q = gets.split.map(&:to_i)
o = []

q.each do |e|
  n = e.to_i

  status = true

  loop do
    if n % 2 == 0
      n /= 2
    elsif n % 3 == 0
      n /= 3
    else
      status = false if n > 1
      o << n
      break
    end
  end

end

o.uniq!

puts o.size == 1 ? 'Yes' : 'No'

n = gets.to_i
res = -1
a = gets.split(' ').map(&:to_i)
a.each do |i|
  while i % 2 == 0
    i /= 2
  end
  while i % 3 == 0
    i /= 3
  end
  if res == -1
    res = i
  elsif res != i
    puts "No"
    exit
  end
end
puts "Yes"

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

bs = []
as.each do |a|
  b = a
  while b % 2 == 0
    b /= 2
  end
  while b % 3 == 0
    b /= 3
  end
  bs << b
end

bs.sort!
if bs[0] == bs[-1]
  puts 'Yes'
else
  puts 'No'
end

n=gets.to_i
x=gets.split.map{|e| e.to_i}
m1=x.max
ok="No"
if x.all?{|e|
	e2=e/m1.gcd(e)
	while e2%2==0
		e2/=2
	end
	while e2%3==0
		e2/=3
	end
	e2==1
} then
	ok="Yes"
end
puts ok

n=gets.to_i
x=gets.split.map{|e| e.to_i}
m1=x.max
m2=m1
ok="No"
2.times{
	if x.all?{|e|
		(m1%e==0) && (m1/e<4)
	} then
		ok="Yes"
	end
	m1+=m2
}
puts ok

n=gets.to_i
x=gets.split.map{|e| e.to_i}
m1=x.max
ok="No"
if x.all?{|e|
	e2=m1/m1.gcd(e)
	while e2%2==0
		e2/=2
	end
	while e2%3==0
		e2/=3
	end
	e2==1
} then
	ok="Yes"
end
puts ok

# coding: utf-8

n = gets.to_i
ar = gets.split.map(&:to_i)

# for every n...
# how many 2's, 3's ? and remains?
ar_max = ar.max
say_yes = true
ar.each { |i|
    r = ar_max%i
    if r > 0
        say_yes = false
        break
    end
}

if say_yes
    puts "Yes"
else
    puts "No"
end

n = gets.to_i
a = gets.split.map(&:to_i).map do |x|
  x /= 2 if x % 2 == 0
  x /= 3 if x % 3 == 0
  x
end
a = a.sort
puts a[0] == a[-1] ? 'Yes' : 'No'


n=gets.to_i
puts$<.map{|e|e.split.map &:to_i}.transpose.map{|e|e.reduce(:+)/n}*' '

def solution
  n = read_int
  sumx = 0
  sumy = 0
  (n * 2).times do
    x, y = read_ints
    sumx += x
    sumy += y
  end
  tx = sumx / n
  ty = sumy / n

  puts "#{tx} #{ty}"
end

def read_int
  gets.to_i
end

def read_ints
  gets.split.map(&:to_i)
end

def read_string
  gets.chomp
end

solution unless ENV['TEST__MODE']


N = gets.to_i
N.times {
  n = gets.to_i
  s = gets.chomp
  p [s.match(/^<*/)[0].size, s.match(/>*$/)[0].size].min
}

gets.to_i.times{
	n = gets.to_i;
	s = gets.chomp;
	puts s =~ /<>/ ? 1 : 0;
}

gets.to_i.times{
	n = gets.to_i;
	s = gets.chomp;
	puts s =~ /^[^>]*<>[^<]*$/ ? 1 : 0;
}


#! /usr/bin/ruby

num_friends = STDIN.gets.chomp("\n").to_i
prefs = Hash.new
for i in (1..num_friends)
  prefs[i] = STDIN.gets.chomp("\n").split(" ")
end

own_prefs = STDIN.gets.chomp("\n").split(" ")

output = []
for i in (1..num_friends)
  possible  = []
  prev = 1000
  own_prefs.each{|val|
    val = val.to_i
    next if val == i or val > prev
    prev = val
    possible << val
  }

  prefs[i].each{|val|
    val = val.to_i
    if possible.index(val)
      output << val
      break
    end
  }
end

puts output.join(" ")

n = gets.chomp.to_i
na = []
for i in 0..n-1
    wk = gets.chomp.split(/ /).map!{|x| x.to_i}
    wk.delete(i+1)
    na << wk
end
aa = gets.chomp.split(/ /).map!{|x| x.to_i}
for i in 0..n-1
    x = aa[i]
    j = i-1
    revcnt = 0
    revx = 0
    while j >= 0 && revcnt <= 2
        if aa[j] < x
            revcnt += 1
            revx = aa[j]
        end
        j -= 1
    end
    for k in 0..n-1
        if revcnt >= 2 || (revcnt == 1 && (k+1) != revx)
            na[k].delete(x)
        end
    end
end
ret = []
for i in 0..n-1
    ret << na[i][0]
end
puts ret.join(" ")

n = gets.to_i
t_preference = Array.new(n + 1)
card_pref = Array.new(n + 1)
alex = Array.new(n + 1)
for i in 1 .. n
	t_preference[i] = Array.new(n + 1)
	card_pref[i] = Array.new(n + 1)

	a = gets.split
	for j in 1 .. n
		t_preference[i][a[j - 1].to_i] = j
	end
end

a = gets.split
for j in 1 .. n
	alex[j] = a[j - 1].to_i
end

for i in 1 .. n
	first = 0
	second = 0
	for j in 1 .. n
		if alex[j] <= i then
			if first == 0 then first = alex[j]
			else
				second = alex[j]
				break
			end
		end
	end

	for j in 1 .. n
		if j == first then card = second
		else card = first end
		if card == 0 then card_pref[i][j] = 0
		else card_pref[j][i] = t_preference[j][card] end
	end
end

ans = Array.new(n)

for i in 1 .. n
	min = n + 1
	idx = 0
	for j in 1 .. n
		if card_pref[i][j] != 0 then
			if card_pref[i][j] < min then
				min = card_pref[i][j]
				idx = j
			end
		end
	end
	ans[i - 1] = idx
end

puts ans.join(" ")

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

n = $stdin.gets.to_i
m = Array.new(n) { Array.new(n) }
n.times do |i|
  $stdin.gets.split(/\s+/).map(&:to_i).each_with_index do |x, j|
    m[i][x-1] = j
  end
end
alex = Array.new n
$stdin.gets.split(/\s+/).map(&:to_i).each_with_index do |x, j|
  alex[x-1] = j
end

ans = Array.new n
c1 = nil
c2 = nil
n.times do |i|
  if c1.nil?
    c1 = i
  elsif c2.nil?
    if alex[i] < alex[c1]
      c1, c2 = i, c1
    else
      c2 = i
    end
  elsif alex[i] < alex[c1]
    c1, c2 = i, c1
  elsif alex[i] < alex[c2]
    c2 = i
  end

  ans.each_with_index do |a, j|
    c = c1 == j ? c2 : c1
    next if c.nil?
    if ans[j].nil? or m[j][ans[j]] > m[j][c]
      ans[j] = c
    end
  end
end
puts ans.map(&:succ).join(' ')

#! /usr/bin/ruby

num_friends = STDIN.gets.chomp("\n").to_i
prefs = Hash.new
for i in (1..num_friends)
  prefs[i] = STDIN.gets.chomp("\n").split(" ")
end

own_prefs = STDIN.gets.chomp("\n").split(" ")

output = []
for i in (1..num_friends)
  possible  = []
  prev = 1000
  own_prefs.each{|val|
    val = val.to_i
    next if val == i
    break if val > prev
    prev = val
    possible << val
  }

  prefs[i].each{|val|
    val = val.to_i
    if possible.index(val)
      output << val
      break
    end
  }
end

puts output.join(" ")


#!/usr/bin/env ruby

m, n = gets.split.map(&:to_i)
ans = 0.0
(1..m).each do |k|
  ans += k * (((k.to_f/m) ** n) - ((k-1.to_f) / m) ** n)
end

printf "%.8f\n", ans

# E = Sum(k=1..m, P(k)), where P(k) - probability k is max of n throws
# k = max x(i)
# P(k) = P(x <= k) - P(x < k)   (at least on x = k achieved)
# P(x <= k) = (k/m)^n
# P(x < k) = ((k-1)/m)^n

class C

  def c(n, k)

  end

  def run
    m, n = $stdin.gets.split(' ').map &:to_i
    e = 0.0

    (1..m).each do |k|
      pk = (1.0 * k / m) ** n - (1.0 * (k - 1) / m) ** n
      e += k * pk
    end

    puts e
  end

end

C.new.run if __FILE__ == $0

m, n = gets.split.map &:to_i

ans = m

1.upto(m - 1) do |i|
  ans -= (i.to_f / m) ** n
end
puts ans

m, n = gets.chomp.split.map{|i| i.to_i}

ans = 0
pnow = 0.0

m.downto(1).each do |i|
	lower = 1 - ((m-i)/m.to_f)**n
	ans += (lower - pnow) * i
	pnow = lower
end

puts ans

def bin_pow(a,b)
	a=a.to_i
	b=b.to_i
	r=1
	while (b>0)
		if (b&1!=0)
			r*=a
		end
		a*=a
		b>>=1
	end
	return r
end

(m,n)=gets.split.map{|x| x.to_i}
m=m.to_f
ans=m
i=1
while (i<m)
	ans-=(i/m)**n
	i+=1
end
puts ans

#!/usr/bin/ruby
m,n=gets.split.map(&:to_i)
p 1.0.step(m).reduce(0){|s,k|s+k*((k/m)**n-((k-1)/m)**n)}

m,n=readline.split(' ').map(&:to_i)
r=0
pp=0
tp=0
1.upto(m) do |x|
  p=(1.0*x/m)**n
#  puts "#{x} - #{p}"
  r+=x*(p-pp)
  tp+=p-pp
  pp=p
end
#puts "total p #{tp}"
puts r

m, n = gets.split().map(&:to_i)
m = 1.0*m
e = 0
for k in 1..m
	e += k*((k/m)**n-((k-1)/m)**n)
end
puts e

m,n=gets.split.map &:to_i
tot=m*1.0
1.upto(m-1) {|i|tot -= (1.0*i/m)**n}
p tot

m, n = gets.split.map {|i| i.to_i}
a = []
for i in 0...m
  a.push(((i + 1).to_f / m) ** n)
end
(1...m).reverse_each {|i|
  a[i] -= a[i - 1]
}
sum = 0
for i in 0...m
  sum += (i + 1) * a[i]
end
puts sum

throws = 0
m , n = gets.split.map(&:to_i)
#(1..m).each {|x| throws, results[x-1] = x ** n, x ** (n + 1) - throws * x }
puts (1..m).map {|x| x * ((x.to_f/m) ** n - ((x-1.to_f)/m) ** n)}.inject(0) {|x, y| x + y}

#!/usr/bin/ruby
m,n=gets.split.map(&:to_i)
p 1.step(m).reduce(0){|s,k|s+1.0*k*(k**n-(k-1)**n)/m**n}

def check(m, n)
  x = 1
  n.times {
    x *= m
    return false if x > 10000000000
  }
  return true
end

def solve(m, n)
  if m == 1
    return 1.0
  end
  p "@solve: m = #{m}, n = #{n}"
  res = 0.0
  (1..m).each {|x|
    if x == 1
      res += 1.0
    elsif x == m
    else
      t = 1.0 * x / m
      p t
    end
  }
  return -1
  return (1..m).map{|x| x * ( x ** n - ( x - 1 ) ** n )}.inject(:+) * ( 1.0 / m ** n )
end

puts solve *gets.split.map{|x| x.to_i}

# m, n = gets.split.map{|x| x.to_i}
# puts (1..m).map{|x| x * ( x ** n - ( x - 1 ) ** n )}.inject(:+) * ( 1.0 / m ** n )


total_goals = gets.chomp.to_i
teams = {}
total_goals.times do
    team = gets.chomp
    if !teams.has_key? team
        teams.store team, 1
    else
        teams[team] += 1
    end
end
max_goals = teams.values.max
winner = teams.select { |k, v| v == max_goals }.to_a[0][0]
puts winner

n=gets.to_i
x=gets.chomp
a=[1,0]
y=nil
n-=1
n.times do
	l=gets.chomp
	if x==l
		a[0]+=1
	else
		a[1]+=1
		if !y
			y=l
		end
	end
end
puts a[0]>a[1]? x : y

gets
puts (a = gets(p).split).max_by { |x| a.count x }

n = gets.to_i
a = Array.new(n)

for i in 0..n-1
  a[i] = gets.to_s.chomp
end
if n == 1
    puts a[0]
else
  counter = 0
  for i in 1..n-1
   if a[i] != a[0]
    d = a[i]
    counter +=1
   end
  end

  f = a.length
  if counter > f/2
     puts d
  else
     puts a[0]
  end
 end

n=gets.to_i
h=Hash.new(0)
n.times{
	s=gets.chomp
	h[s]+=1
}
c=0
ans=""
h.each{|k,v|
	if c<v then
		c=v
		ans=k
	end
}
puts ans

n=gets.to_i

hs=Hash.new(0)
n.times{
	hs[gets.chomp]+=1
}

maxy=hs.values.max
puts hs.invert[maxy]

n = 1
t1, t2 = nil, nil
gets.to_i.times do
    if t1
        t = gets.chomp
        n += t == t1 ? 1 : -1
        t2 = t if t != t1
    else
        t1 = gets.chomp
    end
end

puts n > 0 ? t1 : t2

goals = STDIN.read.split
goals.shift

result = goals.inject(Hash.new(0)) { |score, team| score[team] += 1; score }
puts result.max_by { |k,v| v } .first

n = gets.to_i
h = Hash.new
(1..n).each do |x|
  s = gets
  if h[s] == nil then h[s] = 1 else h[s] = h[s] + 1 end
end
puts h.sort { |x,y| y[1] <=> x[1] }[0][0]

# coding: utf-8

# if __FILE__ == $0
# end

n = gets.to_i
teams = {}
n.times {
    name = gets.chomp
    teams[name] ||= 0
    teams[name] += 1
}
winner_score = teams.values.max
teams.each_pair { |k, v|
    if v == winner_score
        puts k
    end
}

n = gets.to_i
count = Hash.new(0)
n.times {
	a = gets.chomp
	count[a] += 1
}
puts count.key(count.values.max)

k=gets.to_i
l=gets
n=''
mas=[1,0]
(k-1).times{ m=gets
     m==l ?mas[0]+=1 :mas[1]+=1
     m==l ?l=m :n=m
    }
puts mas[0]>mas[1] ?l:n

n = gets.to_i

mas = {"abacabaabacaba" => -1}
for i in 0..n-1
  s = gets
  if mas.has_key?(s)
    mas[s] += 1
  else
    mas[s] = 0
  end
end

result = ""
max = -1
mas.each do |key,value|
  if value > max
    max = value
    result = key
  end
end

puts result

n = gets.to_i
puts n.times.map{gets.chomp}.sort[(n - 1)/2]

n = gets.to_i
h = Hash.new(0)
n.times{h[gets.chomp] += 1}
puts h.max_by{|x, y| y}.first

lines = []
#読み込み
n = gets.chomp.to_i
n.times {
  lines << gets.chomp
}

#チーム名を出す
teams = []
lines.each { |str|
  if teams == []
    teams[0] = str
  elsif teams[0] != str
    teams[1] = str
  end
}

#得点を出す
scores = [0, 0]
lines.each { |str|
  if str == teams[0]
    scores[0] = scores[0] + 1
  elsif str == teams[1]
    scores[1] = scores[1] + 1
  end
}

#表示
puts (if scores[0] > scores[1] then teams[0] else teams[1] end)

goals = gets.chomp.to_i.times.map { gets.chomp }
a, b = 0, 0
goals.each { |team| team == goals[0] ? a += 1 : b += 1 }
puts a > b ? goals[0] : (goals - [goals[0]])[0]

c=Hash.new 0
[*$<].drop(1).each{|w| c[w] += 1}
puts c.max_by{|k,v| v}[0]

a = 1.upto(gets.to_i).map { gets.chomp }

puts a.uniq.max { |p, q| a.count(p) <=> a.count(q) }

commands = []
for _ in 1..Integer(gets.chomp)
  commands << gets.chomp
end
puts commands.inject(Hash.new(0)) { |h, e| h[e] += 1; h }.max_by { |k, v| v }.first

n = gets.to_i

input = Array.new(n) { gets.strip }

teams = input.sort.uniq
count = teams.map { |team| input.count(team) }

puts teams.max_by { |team| count[teams.index(team)] }

gets
a=gets(p).split
$><<a.max_by{|b|a.count b}

score = Hash.new(0)

gets; while i = gets
	score[i.chomp] += 1
end

puts score.select{|k, v| v == score.values.max}.keys.join

score = {}

gets; while i = gets
	i.gsub!(/\n/, '')
	score[i] = 0 unless score.has_key? i
	score[i] += 1
end

puts score.select{|k, v| v == score.values.max}.keys.join

goals = gets.to_i
h = {}
goals.times do |i|
    name = gets.chomp
    if h[name] then
        h[name] += 1
    else
        h[name] = 1
    end
end
mas = h.keys
if mas.size > 1 then
    if h[mas[0]] > h[mas[1]] then
        puts mas[0]
    else
        puts mas[1]
    end
else
    puts mas[0]
end

h=Hash.new(0)
gets.to_i.times{s=gets
h[s]+=1}
puts h.max{|x,y|x[1]<=>y[1]}[0]

n=gets.to_i
c={}
for i in 1..n do
	r=gets
	c[r]=c[r].to_i+1
end
max=0
maxc=""
c.keys.each {|k|
	if c[k]>max
		maxc=k
		max=c[k]
	end
}
puts maxc

count = gets.to_i
r = {}
count.times{|n|
  s = gets
  if r[s] then
    r[s] += 1
  else
    r[s] = 1
  end
}

answer = ''
tmp = 0
r.each {|team,point|
  if tmp <= point then
    answer = team
    tmp = point
  end
}

puts answer

count = gets.to_i
r = {}
count.times{|n|
  s = gets
  if r.value?(s) then
    r[s] += 1
  else
    r[s] = 1
  end
}

answer = ''
tmp = 0
r.each {|team,point|
  if tmp < point then
    answer = team
  end
}

puts answer

count = gets.to_i
r = {}
count.times{|n|
  s = gets
  if r.value?(s) then
    r[s] += 1
  else
    r[s] = 1
  end
}

answer = ''
tmp = 0
r.each {|team,point|
  if tmp <= point then
    answer = team
  end
}

puts answer

count = gets.to_i
r = {}
count.times{|n|
  s = gets
  if r[s] then
    r[s] += 1
  else
    r[s] = 1
  end
}

answer = ''
tmp = 0
r.each {|team,point|
  if tmp <= point then
    answer = team
  end
}

puts answer

count = gets.to_i
r = {}
count.times{|n|
  s = gets
  if r.value?(s) then
    r[s] += 1
  else
    r[s] = 1
  end
}

answer = ''
tmp = 0
r.each {|team,point|
  if tmp < point then
    answer = team
  end
}

print answer

# coding: utf-8

# if __FILE__ == $0
# end

n = gets.to_i
alr = Array.new(26) { 0 }
n.times {
    mini_alr = Array.new(26) { 0 }

    gets.chomp.split(//).each { |c|
        o = c.ord - 'A'.ord
        mini_alr[o] += 1
    }
    max_mini_alr = mini_alr.max
    mini_alr.each_with_index { |val, index|
        if val == max_mini_alr
            alr[index] += 1
        end
    }
}

max_alr = alr.max
team_names = "" # what?
alr.each_with_index { |val, index|
    if val == max_alr
        team_names += ('A'.ord + index).chr
    end
}

puts team_names

n = gets.to_i
h = Hash.new(0)
n.times{gets.chomp.chars.each{|x| h[x] += 1}}
mx = h.values.max
puts h.keys.select{|x| h[x] == mx}.join

n = gets.to_i
h = Hash.new(0)
n.times{h[gets.chomp] += 1}
puts h.max_by{|x| h[x]}[0]

score = {}; ('A'..'Z').each {|c| score[c] = 0}

gets; while i = gets
	i.gsub(/\n/, '').each_char {|c| score[c] += 1 }
end

puts score.select{|k, v| v == score.values.max}.keys.join

score = {}

gets; while i = gets
	i.gsub(/\n/, '').each_char do |c|
		score[c] = 0 unless score.has_key? c
		score[c] += 1
	end
end

puts score.select{|k, v| v == score.values.max}.keys.join


t = gets.to_i
ans = []
t.times do
  s = gets.chomp.split("")
  len = s.length
  min = len
  numA = 0
  for i in 0..len-1
    if s[i] == "A"
      numA += 1
    else
      if numA >= 1
        numA -= 1
        min -= 2
      end
    end
  end
  min -= ((min - numA) / 2)*2
  ans << min
end
ans.each do |v|
  puts v
end

tc=gets.chomp.to_i

tc.times do |i|
    fuad=[]
    s=gets.chomp.split("")
    now=0
    s.each do|i|

        if fuad==[]
            fuad<<i
            now+=1
        else
            if fuad[-1]=="A" && i=="B"
                fuad.pop
                now-=1
            elsif fuad[-1]=="B" && i=="B"
                fuad.pop
                now-=1
            else
                fuad<<i
                now+=1
            end
        end
    end

    puts now
end

n = gets.chomp.to_i
n.times do |i|
    arr = []
    s = gets.chomp.split("")
    count = 0
    s.each do |i|
        if arr == []
            arr << i
            count += 1
        else
            if arr[-1] == "A" && i == "B"
                arr.pop
                count -= 1
            elsif arr[-1] == "B" && i == "B"
                arr.pop
                count -= 1
            else
                arr << i
                count += 1
            end
        end
    end
    puts count
end


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

res = 0
cycles.size.times do |n|
	res += cycles[n].even? ? 1 : 2
	print res.even? ? 2 : 1,"\n"
end

@n = STDIN.gets.to_i
@sum = 0
@count = 0
STDIN.gets.split(' ').collect{ |x| x.to_i}.each do |x|
	@sum += x
	@count += 1
	puts (@sum-@count)%2 == 0 ? 2 : 1
end

winCache = {}
winCache[1] = 0
winCache[2] = 1
winCache[3] = 2

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

totalTurn = 0

addedVertices.each do |v|
	if winCache.has_key? v
		totalTurn += winCache[v]
	else
		winCache[v] = v - 1
		totalTurn += v - 1
	end

	puts '2' if totalTurn % 2 == 0
	puts '1' if totalTurn % 2 == 1
end

n = gets.to_i
mas = gets.split.map(&:to_i)

s = 0

for i in 0...n do
  s += mas[i] - 1
  puts s%2==1? '1' : '2'
end

n = gets.to_i
a = gets.split.map(&:to_i)
sum = 0
a.each{ |x|
  sum += x - 1
  puts 2 - sum % 2
}

n = gets.strip.to_i
a = gets.strip.split.map(&:to_i)
ans = 0
n.times do |i|
    ans += a[i] - 1
    if ans.even? || ans == 0
        puts "2"
    else
        puts "1"
    end
end

n = gets.to_i

numbers = gets

res = numbers.split(' ')
t_s = 0
res.each_with_index do |r,i|
    c = r.to_i
    t_s += (c-1)
    if (t_s > 1000000000)
        t_s = t_s - 1000000000
    end
    if (t_s % 2 == 1)
        puts 1
    else
        puts 2
    end
end

class Array
  def r
    self.map { |q| q.to_i }
  end
end

def read_line
  STDIN.gets.split(" ")
end

def read_to_array
  read_line.to_a
end

def read_numbers_to_array
  read_to_array.r
end

def change(c)
  return 2 if c == 1
  return 1
end

n = STDIN.gets.to_i

a = read_numbers_to_array
cur_win = 2
a.each do |x|
  cur_win = change(cur_win) if x % 2 == 0
  puts cur_win
end

@n = STDIN.gets.to_i
STDIN.gets.split(' ').collect{ |x| x.to_i}.each do |x|
	puts x*(x-1)/2%2 == 0 ? 1 : 2
end


require 'bigdecimal'
n=gets.to_i
p,r=1,[]
while p<=n+1 do
  d=8*n+4*p*p-12*p+9
  if d>=0
    d=BigDecimal(d).sqrt(100).round
    q=3-2*p
    x=[q+d>>1,q-d>>1]
    x.each{|y|r<<p*y if y>=1 and y%2==1 and (p-1)*y+(y-1)*y/2==n}
  end
  p <<= 1
end
r.empty? ? puts(-1):puts(r.sort.uniq)

n=gets.to_i
def f(a,b)
  g=->k{k*(k+$m)}
  return a if g.(a)==$n
  return b if g.(b)==$n
  return 0 if g.(a)>$n || g.(b)<$n || (a-b).abs<=1
  c=a+b>>1
  return g.(c)<$n ? f(c,b):f(a,c)
end
p,r,$n=1,[],2*n
while p<=n+1 do
  $m=2*p-3
  k=f(1,n)
  r<<p*k if k%2==1
  p<<=1
end
puts r.empty?? -1:r.sort.uniq

def gao(x, y)
  x * (2 ** y - 1) + x * (x - 1) / 2
end

n = gets.to_i
ans = []

0.upto(100) do |b|
  l = 1
  r = 10 ** 20
  while l < r do
    m = (l + r) / 2
    if gao(m, b) < n
      l = m + 1
    else
      r = m
    end
  end
  ans << (r << b) if r.odd? && gao(r, b) == n
end

ans = ans.uniq.sort
ans << -1 if ans.empty?
puts ans

@n = $stdin.read.to_i
@result = []

def checkOne
    x = 0
    t = 1
    for j in 0..70 do
        @result << t if (x == @n)
        x += t
        t *= 2
    end
end

def get_sqrt x
  return 0 if x==0
  m = x
  p = x
  result = m
  loop do
    r = (m + p/m) / 2
    if m <= r
        result = m
        break
    end
    m = r
  end
  return result * result == x ? result : nil
end

def checkSimple
    for m in 0..70 do
        d = 2**(2*m+2) - 3 * (2**(m+2)) + 9 + 8 * @n
        next if d < 0
        sqrtd = get_sqrt(d)
        next if sqrtd == nil
        next if sqrtd % 2 == 0
        a = (-(2**(m+1))+3+sqrtd) / 2
        @result << a*(2**m) if a > 0 && a % 2 == 1
        a = (-(2**(m+1))+3-sqrtd) / 2
        @result << a*(2**m) if a > 0 && a % 2 == 1
    end
end

#checkOne
checkSimple

@result = @result.sort.uniq
@result.each do |a|
    print a, "\n"
    r = 0
end
if @result.size == 0
    print -1, "\n"
end

require 'rational'

class Rational
  def sqrt_floor
    if self < 0 then
      raise 'can\'t take the square root of a negative number'
    end

    return 0 if self == 0

    prev = nil
    cur = self

    while prev.nil? or (cur - prev).abs >= 1 do
      prev = (cur * 10).round.to_r / 10
      cur = (prev + self / prev) / 2
    end

    cur.to_i
  end
end

n = gets.to_i

ans = []
pow = 1
exp = 0
loop do
  break if pow - 1 > n
  disc = (2 * pow - 3) ** 2 + 8 * n
  sq = Rational(disc, 1).sqrt_floor
  if sq * sq == disc && sq & 1 == 1
    teams = ((sq + 3) >> 1) - pow
    ans.push(pow * teams) if teams & 1 == 1
  end
  pow <<= 1
  exp += 1
end

ans.push(-1) if ans.empty?
ans.sort.uniq.each { |x| puts x }

n=gets.to_i
g=->k{k*(k+$m)}
p,u,o=1,[],2*n
while p<=n+1 do
  $m=2*p-3
  l,r=-1,n+1
  while r-l>1
    k=l+r>>1
    s=g.(k)
    u<<p*k if k%2>0&&s==o
    s>o ? r=k : l=k
  end
  p<<=1
end
puts u.empty?? -1:u.sort.uniq

n=gets.to_i
p,r=1,[]
def g(k,m)
  k*(k+m)
end
def f(a,b,m,n)
  return 0 if g(a,m)>n
  return 0 if g(b,m)<n
  return a if g(a,m)==n
  return b if g(b,m)==n
  return 0 if (a-b).abs <=1
  c=(a+b)/2
  if g(c,m)<n
    return f(c,b,m,n)
  else
    return f(a,c,m,n)
  end
end
while p<=n+1 do
  k=f(1,n,2*p-3,2*n)
  r << p*k if k%2==1
  p <<= 1
end
r.reject!{|x| x.nil? or x==0}
r.empty? ? puts(-1):puts(r.sort.uniq)

@n = $stdin.read.to_i
@result = []

def checkOne
    x = 0
    t = 1
    for j in 0..70 do
        @result << t if (x == @n)
        x += t
        t *= 2
    end
end

def get_sqrt x
  return 0 if x==0
  m = x
  p = x
  result = m
  loop do
    r = (m + p/m) / 2
    if m <= r
        result = m
        break
    end
    m = r
  end
  return result * result == x ? result : nil
end

def checkSimple
    for m in 0..70 do
        d = 2**(2*m+2) - 3 * (2**(m+2)) + 9 + 8 * @n
        next if d < 0
        sqrtd = get_sqrt(d)
        next if sqrtd == nil
        next if sqrtd % 2 == 0
        a = (-(2**(m+1))+3+sqrtd) / 2
        @result << a*(2**m) if a > 0
        a = (-(2**(m+1))+3-sqrtd) / 2
        @result << a*(2**m) if a > 0
    end
end

#checkOne
checkSimple

@result = @result.sort.uniq
@result.each do |a|
    print a, "\n"
    r = 0
end
if @result.size == 0
    print -1, "\n"
end

@n = $stdin.read.to_i
@result = []

def checkOne
    x = 0
    t = 1
    for j in 0..70 do
        @result << t if (x == @n)
        x += t
        t *= 2
    end
end

def get_sqrt a
    d = Math.sqrt(a).to_i
    for t in ([d-1,0].max..(d+1))
        return t if t * t == a
    end
    return nil
end

def checkSimple
    for m in 0..70 do
        d = 2**(2*m+2) - 3 * (2**(m+2)) + 9 + 8 * @n
        next if d < 0
        sqrtd = get_sqrt(d)
        next if sqrtd == nil
        next if sqrtd % 2 == 0
        a = (-(2**(m+1))+3+sqrtd) / 2
        @result << a*(2**m) if a > 0
        a = (-(2**(m+1))+3-sqrtd) / 2
        @result << a*(2**m) if a > 0
    end
end

checkOne
checkSimple

@result = @result.sort.uniq
@result.each do |a|
    print a, "\n"
end
if @result.size == 0
    print -1, "\n"
end

@n = $stdin.read.to_i
@result = []

def get_sqrt x
  return 0 if x==0
  m = x
  p = x
  result = m
  loop do
    r = (m + p/m) / 2
    if m <= r
        result = m
        break
    end
    m = r
  end
  return result * result == x ? result : nil
end

def checkSimple
    for m in 0..200 do
        d = 2**(2*m+2) - 3 * (2**(m+2)) + 9 + 8 * @n
        next if d < 0
        sqrtd = get_sqrt(d)
        next if sqrtd == nil
        next if sqrtd % 2 == 0
        a = (-(2**(m+1))+3+sqrtd) / 2
        @result << a*(2**m) if a > 0
        a = (-(2**(m+1))+3-sqrtd) / 2
        @result << a*(2**m) if a > 0
    end
end

checkSimple

@result = @result.sort.uniq
@result.each do |a|
    print a, "\n"
end
if @result.size == 0
    print -1, "\n"
end

require 'bigdecimal'
n=gets.to_i
p,r=1,[]
while p<=n+1 do
  d=8*n+4*p*p-12*p+9
  if d>=0
    d=BigDecimal(d).sqrt(100).to_i
    q=3-2*p
    x=[q+d>>1,q-d>>1]
    x.each{|y|r<<p*y if y>=1 and y%2==1 and (p-1)*y+(y-1)*y/2==n}
  end
  p <<= 1
end
r.empty? ? puts(-1):puts(r.sort.uniq)

n=gets.to_i
p,r=1,[]
while p<=n do
  d=8*n+4*p*p-12*p+9
  if d>=0
    d=(d**0.5).round
    q=-p+3/2
    x=[q+d,q-d]
    x.each{|y|r<<p*y if y>=1and y%2==1and (p-1)*y+(y-1)*y/2==n}
  end
  p <<= 1
end
r.empty? ? puts(-1):puts(r.sort.uniq)

n=gets.to_i
p,r=1,[]
while p<=n do
  if 8*n+4*p*p-12*p+9 >= 0
    d=Math.sqrt(8*n+4*p*p-12*p+9)
    x1=(-d-2*p+3)/2
    x2=(d-2*p+3)/2
    r << p*x1.to_i if x1>=1 and x1.to_i == x1
    r << p*x2.to_i if x2>=1 and x2.to_i == x2
  end
  p <<= 1
end
if !r.empty?
  puts r.sort
else
  puts -1
end

n=gets.to_i
def f(a,b)
  g=->k{k*(k+$m)}
  return 0 if g.(a)>$n||g.(b)<$n||(a-b).abs<=1
  return a if g.(a)==$n
  return b if g.(b)==$n
  c=a+b>>1
  return g.(c)<$n ? f(c,b):f(a,c)
end
p,r,$n=1,[],2*n
while p<=n+1 do
  $m=2*p-3
  k=f(1,n)
  r<<p*k if k%2==1
  p<<=1
end
puts r.empty?? -1:r.sort.uniq

n=gets.to_i
p,r=1,[]
while p<=n+100 do
  if 8*n+4*p*p-12*p+9 >= 0
    d=Math.sqrt(8*n+4*p*p-12*p+9)
    x1=(-d-2*p+3)/2.0
    x2=(d-2*p+3)/2.0
    r << p*x1.to_i if x1>=1 and x1.to_i == x1
    r << p*x2.to_i if x2>=1 and x2.to_i == x2
  end
  p <<= 1
end
if !r.empty?
  puts r.sort.uniq
else
  puts -1
end


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

x = 1
while x<t do
  x += as[x-1]
  #STDERR.print " #{x}"
end
puts x==t ? "YES" : "NO"

args = gets.split(" ").map{ |i| i.to_i}
n = args[0]
t = args[1]
potrals = gets.split(" ").map{ |i| i.to_i}.unshift(0)
succeed = false
i = 1
while i != n && !succeed
  i += potrals[i]
  if (t == i)
    succeed = true
  end
end
puts succeed == true ? "YES" : "NO"

#!/usr/bin/env ruby
n,t=gets.split.map(&:to_i)
a=gets.split.map(&:to_i)
cur=0
while cur+1<t
	cur+=a[cur]
end
puts cur+1==t ? :YES : :NO

def g;gets.split.map(&:to_i)end
n,t=g
a=g
now=0
while now<t-1
  now+=a[now]
end
puts now==t-1 ?"YES":"NO"

n, t = STDIN.readline.split.map {|s| s.to_i }
portals = STDIN.readline.split.map {|s| s.to_i }
pos = 0
t -= 1
while pos < t
  pos += portals[pos]
end
puts pos == t ? 'YES' : 'NO'

n, t = $stdin.readline.split.map(&:to_i)
a = $stdin.readline.split.map(&:to_i)

i = 1
i+=a[i-1] while i<t

puts i==t ? "YES" : "NO"

def can_i_go_there?(n,en,a)
    current_n=1
    if n.to_i==en.to_i
        return true;
    end
    while (current_n<en.to_i)
        current_n+=a[current_n-1].to_i
    end

    if(current_n==en.to_i)
        return true;
    end
    return false;

end

n,t= gets.chomp.split
a=gets.chomp.split
if(can_i_go_there?(n,t,a))
    print "YES"
else
    print "NO"
end

def run
  n, t = $stdin.gets.split.map(&:to_i)
  a = $stdin.gets.split.map(&:to_i)

  pos = 0
  target = t - 1
  while pos < target
    pos += a[pos]
  end

  puts pos == target ? "YES" : "NO"
end

run if $0 == __FILE__

n,t = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
i = 0
while i<t-1
    i += a[i]
end
puts i==t-1? "YES" : "NO"

n, t = gets.split.map &:to_i
cells = gets.split.map &:to_i
_next = 1
while _next < t do
  _next = _next + cells[_next - 1]
end
if _next == t
  puts "YES"
else
  puts "NO"
end

n,g=gets.split.map{|e| e.to_i}
x=gets.split.map{|e| e.to_i}
p1=0
x.size.times{|i|
	if p1==g-1 then
		break
	end
	if i==p1 then
		p1=p1+x[i]
	end
}
puts (p1==g-1)?"YES":"NO"

def read()
    arr1=gets.chomp!.split(" ").map{|m| m.to_i}
    arr2=gets.chomp!.split(" ").map{|m| m.to_i}
    return arr1[0],arr1[1],arr2
end

def solve(n,t,portal)
    pos=0
    while (pos < n) do
        return true if pos == t
        return false if pos == n-1
        pos += portal[pos]
    end
    return false
end

n,t,portal=read()
t-=1
ans=solve(n,t,portal)
print ans ? "YES" : "NO"

#$stdin = File.open "input.txt"

n, t, *a = gets(p).split.map &:to_i

c = Array.new(n) { 0 }
c[0] = 1

(n - 1).times do |i|
	c[ i + a[i] ] = 1 if c[i] == 1
end

puts (c[t - 1] == 1) ? "YES" : "NO"

num = gets.chomp.split
n = Integer(num[0])
t = Integer(num[1])

nums = gets.chomp.split
a = Array.new
for i in 1..n-1
    a[i] = Integer(nums[i - 1])
end
i = 1
while (1 <= i && i <= n - 1) do
    i = i + a[i]
    if i >= t
        break
    end
end

if i == t
    print "YES"
else
    print "NO"
end

cells = gets.chomp
cells = cells.split
number = cells[0].to_i
target = cells[1].to_i
portals = gets.chomp
portals = portals.split

i = 0
while i <= portals.size
	if i < target - 1
		i += portals[i].to_i
	else
		if i == target - 1
			print "YES"
		else
			print "NO"
		end
		break
	end
end

def solution(n, t, a)
    i = 1
    while (i <= t) do
        i += a[i-1]
        return puts "YES" if i == t
    end
    puts "NO"
end

n, t = gets.split(" ").map { |i| i.to_i }
a = gets.split(" ").map { |i| i.to_i }

solution(n, t, a)

# http://codeforces.com/problemset/problem/500/A

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

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

i = 0

while i < n - 1 && i != t - 1
  i += as[i]
end

if i == t - 1
  puts 'YES'
else
  puts 'NO'
end

a = gets.split(" ").map{|i| i.to_i}
tab = gets.split(" ").map{|i| i.to_i}
n = a[0]
t = a[1]
p = 0
for i in 0...n-1
	if i == p
		p += tab[i]
		if p >= t-1
			break
		end
	end
end
if p == t-1
	puts "YES"
else
	puts "NO"
end

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

a = gets.chomp.split.map(&:to_i)

can_solve = false
i = 1
loop do
  i += a[i - 1]

  if i == t
    can_solve = true
    break
  end

  break if i >= n
end

if can_solve
  puts 'YES'
else
  puts 'NO'
end

n, t = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
i = 0
ans = "NO"
while (i < n - 1)
  i += a[i]
  ans = "YES" if i == t - 1
  break if i >= t
end
puts ans

n, t = gets.split.map(&:to_i)
a = [nil] + gets.split.map(&:to_i)
ans = false
i = 1
while i < t
  i += a[i]
  ans = true if i == t
end
puts ans ? "YES" : "NO"

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

pos = 0
result = n == t

while pos < n-1
  result ||= pos == t-1

  pos += a[pos]
end

puts result ? 'YES' : 'NO'

_, t = gets.split(' ').map { |x| x.to_i }
arr = gets.split(' ').map { |x| x.to_i }

t -= 1
cur = 0

while cur < t
  cur += arr[cur]
end

puts (cur  == t) ? 'YES' : 'NO'

_, t = gets.split(' ').map &:to_i
arr = gets.split(' ').map &:to_i

t -= 1
cur = 0

while cur < t
  cur += arr[cur]
end

puts (cur  == t) ? 'YES' : 'NO'

# 500A

def read_next_line
  gets.chomp.split.map &:to_i
end

_, t = read_next_line
a = read_next_line
q = t - 1
i = 0
while i < q
  i += a[i]
end

puts i == q ? 'YES' : 'NO'

num = gets.chomp.split
n = Integer(num[0])
t = Integer(num[1])

nums = gets.chomp.split
a = Array.new
for i in 0...n-1
    a[i] = Integer(nums[i])
end
i = 1
for i in 1...n - 1
    i = i + a[i + 1]
    if i >= t
        break
    end
end

if i == t
    print "YES"
else
    print "NO"
end

num = gets.chomp.split
n = Integer(num[0])
t = Integer(num[1])

nums = gets.chomp.split
a = Array.new
for i in 1..n-1
    a[i] = Integer(nums[i - 1])
end
i = 1
for i in 1...n - 1
    i = i + a[i]
    if i >= t
        break
    end
end

if i == t
    print "YES"
else
    print "NO"
end

cells = gets.chomp
cells = cells.split
number = cells[0].to_i
target = cells[1].to_i
portals = gets.chomp
portals = portals.split

i = 0
while i < portals.size
	if i < target - 1
		i += portals[i].to_i
	else
		if i == target - 1
			print "YES"
		else
			print "NO"
		end
		break
	end
end

cells = gets.chomp
cells = cells.split
number = cells[0].to_i
target = cells[1].to_i
portals = gets.chomp
portals = portals.split

i = 0
while i < portals.size
	if i < target - 1
		i += portals[i].to_i
		puts i
	else
		if i == target - 1
			print "YES"
		else
			print "NO"
		end
		break
	end
end

cells = gets.chomp
cells = cells.split
number = cells[0].to_i
target = cells[1].to_i
portals = gets.chomp
portals = portals.split

i = 0
while i < portals.size-1
	if i < target - 1
		i += portals[i].to_i
	else
		if i == target - 1
			print "YES"
		else
			print "NO"
		end
		break
	end
end

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

pos = 0
result = false

while pos < n-1
  result ||= pos == t-1

  pos += a[pos]
end

puts result ? 'YES' : 'NO'


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

if n <= k * (k - 1)
	puts 'YES'
	a, b = -1, -1
	ans = []
	remain = n
	(1..k).each do |i|
		(i + 1..k).each do |j|
			if a != i && b != j
				ans << [i, j] << [j, i]
				a, b = j, i
			else
				ans << [j, i] << [i, j]
				a, b = i, j
			end
			remain -= 2
			break if remain <= 0
		end
		break if remain <= 0
	end
	ans[...n].each { puts _1.join(' ') }
else
	puts 'NO'
end

n,k = gets.split.map(&:to_i)
ans = Array.new(n).map{[0,0]}
if k*(k-1) < n
    puts "NO"
    exit
end
puts "YES"
for i in 0..n-1
    ans[i][0] = i%k+1
    ans[i][1] = (i/k+i%k+1)%k+1
    puts "#{i%k+1} #{(i/k+i%k+1)%k+1}"
end


gets.to_i.times do
  n = gets.to_i
  xs = [*1..n - 3, 1 << 28, 1 << 29]
  xs << xs.reduce(:^)
  puts xs * " "
end

gets.to_i.times do
  n = gets.to_i
  i = -1
  large, small = if n % 2 == 0
      2.times.map { (n / 2 - 1).times.map { i += 1 } }
    else
      [(n / 2).times.map { i += 1 },
       (n / 2 - 1).times.map { i += 1 }]
    end
  xlarge = large.reduce(:^) || 0
  xsmall = small.reduce(:^) || 0
  if xsmall == xlarge
    large[-1] = i += 1
  end
  xlarge = large.reduce(:^) || 0
  l, s = loop do
    l = i += 1
    s = xlarge ^ l ^ xsmall
    break [l, s] if s > i
  end
  large << l
  small << s
  puts 0.upto(n - 1).map { |i| i % 2 == 0 ? large[i / 2] : small[i / 2] }.join(" ")
end

gets.to_i.times do
  n = gets.to_i
  xs = [*1..n - 3, 1 << 28, 1 << 29]
  puts xs * " " + " #{xs.reduce(:^)}"
end

gets.to_i.times do
  n = gets.to_i
  array = (0..n - 2).to_a
  a = array.filter.with_index { |x, i| i.even? }.reduce(:^)
  b = array.filter.with_index { |x, i| i.odd? }.reduce(:^)
  c = (n - 2).upto(2 ** 32).find do |c|
    a ^ c ^ b > n
  end
  d = a ^ c ^ b
  array << c << d
  puts array.join(" ")
end


def read
    gets.split.map &:to_i
end
_, q = read
a = read
cur = a.sum
q.times do
    t, x = read
    if t == 1
        x -= 1
        cur += a[x] == 1 ? -1 : 1
        a[x] = 1 - a[x]
    else
        puts cur >= x ? 1 : 0
    end
end

inp = gets.chomp.split
n, q = inp[0].to_i, inp[1].to_i
a = []
k = 0

i = 0

str = gets.chomp.split
i = 0
str.each do |v|
    k += 1 if v.to_i == 1
    a[i] = v.to_i
    i+=1
end

q.times do
    inp = gets.chomp.split
    qr, qt = inp[0].to_i, inp[1].to_i
    if qr == 1
        if a[qt-1] == 0
           k+=1
        else
           k-=1
        end

        a[qt-1] = 1 - a[qt-1]
    else
        if qt <= k
           puts(1)
        else
          puts(0)
        end
    end
end

# frozen_string_literal: true

n, q = gets.chomp.split.map(&:to_i)
list = gets.chomp.split.map(&:to_i)

number_of_ones = list.sum
q.times do
  query = gets.chomp.split.map(&:to_i)

  if query[0] == 1
    x = query[1]
    list[x - 1] = 1 - list[x - 1]
    if list[x - 1].zero?
      number_of_ones -= 1
    else
      number_of_ones += 1
    end
  else
    k = query[1]
    puts number_of_ones > k - 1 ? 1 : 0
  end
end

def read
    gets.split.map &:to_i
end
_, q = read
a = read
cur = a.sum
q.times do
    t, x = read
    if t == 1
        x -= 1
        cur += a[x] == 1 ? -1 : 1
    else
        puts cur >= x ? 1 : 0
    end
end

# frozen_string_literal: true

n, q = gets.chomp.split.map(&:to_i)
list = gets.chomp.split.map(&:to_i)

number_of_ones = list.count(1)
q.times do
  query = gets.chomp.split.map(&:to_i)

  if query[0] == 1
    x = query[1]
    if x > number_of_ones
      number_of_ones += 1
    else
      number_of_ones -= 1
    end
  else
    k = query[1]
    puts k > number_of_ones ? '0' : '1'
  end
end

# frozen_string_literal: true

n, q = gets.chomp.split.map(&:to_i)
list = gets.chomp.split.map(&:to_i)

number_of_ones = list.count(1)
q.times do
  query = gets.chomp

  if query[0] == '1'
    x = query[2].to_i
    if x > number_of_ones
      number_of_ones += 1
    else
      number_of_ones -= 1
    end
  else
    k = query[2].to_i
    puts k > number_of_ones ? '0' : '1'
  end
end

inp = gets.chomp.split
n, q = inp[0].to_i, inp[1].to_i
a = []
k = 0

i = 0

str = gets.chomp.split
i = 0
str.each do |v|
    k += 1 if v.to_i == 1
    a[i] = v.to_i
    i+=1
end

q.times do
    inp = gets.chomp.split
    qr, qt = inp[0].to_i, inp[1].to_i
    if qr == 1
        if a[qt-1] == 0
           k+=1
        else
           k-=1
        end

        a[qt-1] = 1 - a[qt-1]
    else
        if k <= qt
           puts(1)
        else
           puts(0)
        end
    end
end


n, m = gets.split.map(&:to_i)
num = 0
(1..n).each do |t|
  arr = gets.split.map(&:to_i)
  (0..arr.length).each do |index|
    if index%2 == 1
      num = num + ((arr[index-1]+arr[index]) > 0 ? 1 : 0)
    end
  end
end
p num

s = 0
n, m = gets.chomp.split.map(&:to_i)
n.times do
  as = gets.chomp.split.map(&:to_i)
  for i in 0...m
    s += 1 if 0 < as[2 * i] + as [2 * i + 1]
  end
end
puts s

n, m = gets.split.map(&:to_i)
a = n.times.map{gets.split.map(&:to_i)}
ans = Array.new(n){Array.new(m, 0)}
n.times do |i|
  (2 * m).times do |j|
    ans[i][j / 2] = 1 if a[i][j] == 1
  end
end
p ans.flatten.inject(:+)

n, m = gets.split.map(&:to_i)
a = n.times.map{gets.split.map(&:to_i)}
puts a.flatten.each_slice(2).count{|x| x.include?(1)}

n, m = gets.split.map(&:to_i)
a = n.times.map{gets.split.map(&:to_i)}
ans = 0
n.times do |i|
  (2 * m).times do |j|
    if (a[i][j] == 1 && j.even?) || (a[i][j] == 1 && j.odd? && a[i][j - 1] != 1)
      ans += 1
    end
  end
end
p ans

n, m = gets.split.map(&:to_i)
a = n.times.map{gets.split.map(&:to_i)}
puts a.flatten.each_slice(2).map{|a, b| a + b > 0 ? 1 : 0 }.inject(:+)

n, m = gets.chomp.split(" ").map(&:to_i)
ans = 0
n.times do |i|
  rooms = gets.chomp.split(" ").map(&:to_i)
  rooms.each_slice(2) do |a, b|
    if (a == 1) or (b == 1) then
      ans += 1
    end
  end
end
puts ans

n, m = gets.split.map(&:to_i)
ans = 0
n.times do
  a = gets.split.map(&:to_i)
  (0..m-1).each{|i| ans += 1 if a[2*i] == 1 || a[2*i + 1] == 1}
end
p ans

n,m = gets.chomp.split(" ").map(&:to_i)
counter = 0
n.times do |f|
	floor = gets.chomp.split(" ")
	0.step((m*2-1), 2) do |ind|
		counter+=1 if floor[ind] == "1" || floor[ind+1] == "1"
	end
end
puts counter

n, m = gets.chomp.split.map(&:to_i)
arr = [].tap do |out|
  n.times do
    gets.chomp.split.map(&:to_i).each_slice(2).each { |a| out << a }
  end
end
puts arr.select { |a| a.include? 1 }.length

#! ruby
# Try Codeforces
# author: Leonardone @ NEETSDKASU

n,m = gets.chomp.split.map(&:to_i)

c = 0

n.times do
    f = gets.chomp.split
    m.times do |j|
        c += 1 if f[2 * j] == "1" ||  f[2 * j + 1] == "1"
    end
end

puts c

n, m = gets.split.map(&:to_i)
ans = 0
n.times do
  w = gets.split.map(&:to_i)
  (0..m-1).each do |i|
    ans += 1 if w[(i*2)..(i*2+1)].include?(1)
  end
end
puts ans

data=gets.chomp.split

n=data[0].to_i
m=data[1].to_i

house=[]

a=0
while a<n
	flor=gets.chomp.split
	flor.each do |i|
		house.push(i.to_i)
	end
	a+=1
end

count=0
for i in(0..house.length-2).step(2)
	if house[i]==1 or house[i+1]==1
		count+=1
	end
end

puts count

#!/usr/bin/env ruby

floors, flats = gets.split(' ').map(&:to_i)
floors_with_windows = floors.times.flat_map do gets.split(' ') end

total = 0
floors_with_windows.each_slice(2) {|slice|
  total += 1 if (slice[0] == '1') || (slice[1] == '1')
}

puts total

n,m=gets.split.map{|e| e.to_i}
ans=0
n.times{
	x=gets.split.map{|e| e.to_i}
	0.step(m*2-1,2){|i|
		if x[i]+x[i+1]>0 then
			ans+=1
		end
	}

}
puts ans

n, m = gets.chomp.split("\s").map(&:to_i)
floors = n.times.map { gets.chomp.split("\s").map(&:to_i) }

flats = []

floors.each do |floor|
  floor.each_slice(2).each do |flat|
    flats << flat
  end
end

puts flats.reduce(0) { |acc, flat| flat.include?(1) ? acc + 1 : acc }

n, m = gets.chomp.split.map(&:to_i)
arr = [].tap do |out|
  n.times do
    gets.chomp.split.map(&:to_i).each_slice(m).each { |a| out << a }
  end
end
puts arr.select { |a| a.include? 1 }.length

#! ruby
# Try Codeforces
# author: Leonardone @ NEETSDKASU

n,m = gets.chomp.split.map(&:to_i)

c = 0

n.times do
    f = gets.chomp.split
    0.step(m.div 2) do |j|
        if f[2 * j] == "1" || f[2 * j - 1] == "1"
            c += 1
        end
    end
end

puts c

#! ruby
# Try Codeforces
# author: Leonardone @ NEETSDKASU

n,m = gets.chomp.split.map(&:to_i)

c = 0

n.times do
    f = gets.chomp.split
    f.size.pred.times do |i|
        c += 1 if f[i] == f[i + 1]
    end
end

puts c

n,m=gets.split.map{|e| e.to_i}
ans=0
n.times{
	x=gets.split.map{|e| e.to_i}
	0.step(m,2){|i|
		if x[i]+x[i+1]>0 then
			ans+=1
		end
	}

}
puts ans


n, m = gets.split.map(&:to_i)
data = []
total = 0
n.times { data << gets.split.map(&:to_i) }

data.each do |line|
  t, tmax, comp, bus = *line

  if t+m <= tmax
    total += bus
    next
  end
  if tmax-t < 1
     total += m*comp+bus
  else
    total += [(m/(tmax-t) + (m%(tmax-t)==0 ? 0 : 1))*bus, m*comp+bus].min
  end

end

puts total

n, m = gets.split.map(&:to_i)
data = []
total = 0
n.times { data << gets.split.map(&:to_i) }

data.each do |line|
  t, tmax, comp, bus = *line

  if t+m <= tmax
    total += bus
    next
  end
  if tmax-t < 1
     total += m*comp+bus
  else
    total += [((m+tmax-t-1)/(tmax-t))*bus, m*comp+bus].min
  end

end

puts total

n, m = gets.split.map(&:to_i)
data = []
total = 0
n.times { data << gets.split.map(&:to_i) }

data.each do |line|
  t, tmax, comp, bus = *line

  if t+m <= tmax
    total += bus
    next
  end
  if tmax-t < 1
     total += m*comp+bus
  else
    total += [((m+tmax-t+1)/(tmax-t))*bus, m*comp+bus].min
  end

end

puts total

n, m = gets.split.map(&:to_i)
data = []
total = 0
n.times { data << gets.split.map(&:to_i) }

data.each do |line|

  if line[0] + m < line[1]
    total += line[3]
    next
  end

  if  line[2] * m > line[3]
    del = line[1]-line[0]
    if del >0
      total += line[3] * (m/del)
      total += line[3] if (m%del>0)
    else
      total += line[3] * m
    end
  else
    total += line[2] * m + line[3]
  end

end

puts total

n, m = gets.split.map(&:to_i)
data = []
total = 0
n.times { data << gets.split.map(&:to_i) }

data.each do |line|

  if line[0] + m <= line[1]
    total += line[3]
    next
  end

  if  line[2] * (line[1]-line[0])  >= line[3]
    total += line[3] * (m/(line[1]-line[0]))
    total += line[3] if (m%(line[1]-line[0])>0)
  else
    total += line[2] * m + line[3]
  end

end

puts total

 n, m = gets.split.map(&:to_i)
data = []
total = 0
n.times { data << gets.split.map(&:to_i) }

data.each do |line|

  if line[0] + m < line[1]
    total += line[3]
    next
  end

  if  line[2] * (line[1]-line[0])  >= line[3]
    total += line[3] * (m/(line[1]-line[0]))
    total += line[3] if (m%(line[1]-line[0])>0)
  else
    total += line[2] * m + line[3]
  end

end

puts total

 n, m = gets.split.map(&:to_i)
data = []
total = 0
n.times { data << gets.split.map(&:to_i) }

data.each do |line|

  if line[0] + m < line[1]
    total += line[3]
    next
  end

  if  line[2] * (line[1]-line[0])  > line[3]
    total += line[3] * (m/(line[1]-line[0]))
    total += line[3] if (m%(line[1]-line[0])>0)
  else
    total += line[2] * m + line[3]
  end

end

puts total

n, m = gets.split.map(&:to_i)
data = []
total = 0
n.times { data << gets.split.map(&:to_i) }

data.each do |line|
  t, tmax, comp, bus = *line

  if t+m <= tmax
    total += bus
    next
  end
  if tmax-t == 0
     total +=m*comp+bus
  else
    total += [(m/(tmax-t) + (m%(tmax-t)==0 ? 0 : 1))*bus, m*comp+bus].min
  end
end

puts total


def dfs(i,j,direct,color)
    return false if i<0 || j<0 || i>=$n || j>=$m || $s[i][j]!=color
    return true if $used[i][j]
    $used[i][j]=true
    res = false
    res|=dfs(i+1,j,3,color) if direct!=1
    res|=dfs(i-1,j,1,color) if direct!=3
    res|=dfs(i,j+1,0,color) if direct!=2
    res|=dfs(i,j-1,2,color) if direct!=0
    res
end

def getAnswer()
    $n.times {|i| $m.times {|j| return true if !$used[i][j] &&

dfs(i,j,0,$s[i][j])}}
    return false
end

$n,$m=STDIN.gets.split.map{|n|n.to_i}
$s=Array.new($n) {STDIN.gets}
$used=Array.new($n) {Array.new($m) {false}}

if getAnswer then puts "Yes" else puts "No" end

def dfs(i,j,direct,color)
    return false if i<0 || j<0 || i>=$n || j>=$m || $s[i][j]!=color
    return true if $used[i][j]
    $used[i][j]=true
    res = false
    res|=dfs(i+1,j,3,color) if direct!=1
    res|=dfs(i-1,j,1,color) if direct!=3
    res|=dfs(i,j+1,0,color) if direct!=2
    res|=dfs(i,j-1,2,color) if direct!=0
    res
end

def getAnswer()
    $n.times {|i| $m.times {|j| return true if !$used[i][j] &&

dfs(i,j,0,$s[i][j])}}
    return false
end

$n,$m=STDIN.gets.split.map{|n|n.to_i}
$s=Array.new($n) {STDIN.gets}

f=[false]*$m
$used=Array.new($n) {f.dup}

if getAnswer then puts "Yes" else puts "No" end


#!/usr/bin/ruby
n = gets.chomp.to_i
numbers = []
n.times do
	numbers << gets.chomp
end
written = false
(numbers[0].length-2).downto(0) do |i|
	en = true
	for num in numbers
		if numbers[0][0..i] != num[0..i]
			en = false
			break
		end
	end
	if en == true
		puts i+1
		written = true
 		break
	end
end
puts 0 if not written

nums = []
readline.to_i.times { nums << readline.strip }

ans = 0
nums[0].length.times do |i|
  break unless nums.all? { |num| nums[0][i] == num[i] }
  ans += 1
end

p ans

n = gets.to_i
a = []
n.times do
  a << gets.chomp
end

def check_pref(a, len)
  pref = a.first[0, len]
  a.drop(1).each do |s|
    return false unless s[0, len] == pref
  end
  true
end

def pref_len(a)
  return 0 if a.empty?
  max_len = a.first.size
  max_len.downto 0 do |cur_len|
    return cur_len if check_pref(a, cur_len)
  end
  cur_len
end

puts pref_len(a)

n = gets.to_i
s0 = gets.chomp
ans = s0.length
(1..n-1).each do
        s = gets.chomp
        i = 0
        while s[i] == s0[i]
                i += 1
        end
        ans = [ans, i].min
end
puts ans

n = gets.to_i

massiv = Array.new(n) {Array.new()}

for i in(0..n-1)
	k = gets.split("")
	length = k.length - 1

	for j in(0..length-1)
		massiv[i][j] = k[j].to_i
	end
end

p = 0
t = 0

for j in(0..length-1)
	for i in(0..n-2)
		if massiv[i][j] == massiv[i+1][j] then
			t+=1
		else
			break
		end
	end

	if t == 0 then
		break
	end

	if t == n-1 then
		p+=1
	end

	t = 0
end

puts p

n, numbers = gets.to_i, STDIN.read.split("\n")
prefix = numbers[0]

n.times do |i|
	m = numbers[i][0..prefix.length - 1]
	if prefix == m
		next
	else
		while prefix != m
			prefix.chop!
			m.chop!
		end
	end
end

print prefix.length

# t = gets.split.collect{|x| x.to_i}
n = gets.to_i

result = nil

n.times do |i|
	s = gets.strip
	result ||=s
	s = s.chars.to_a
	s.each_index do |i|
		if result[i] == nil or result[i] != s[i]
			if i == 0
				result = ""
			else
				result = result[0..i-1]
			end
			break
		end
	end
end

puts result.size

n=gets.to_i
numbers=[]
n.times do
        numbers<<=gets.split[0]
end
numbers[0].size.downto(0) do |i|
        ok=true
        numbers.each do |e|
                ok=false unless e[0..i-1]==numbers[0][0..i-1]
        end
        if ok
                puts i
                exit
        end
end
puts 0

n = gets.to_i
phone = Array.new(n)
phone[0] = gets.strip
l = phone[0].length
for i in 1...n
  phone[i] = gets.strip
  x=0
  until phone[0][x] != phone[i][x] do x += 1 end
  l = x if x < l
end
print l

numbers = []
readline.to_i.times { numbers << readline.strip }

ans = 0
head = numbers.shift
tail = numbers
head.length.times do |i|
  break unless tail.all? { |t| head[i] == t[i] }
  ans += 1
end
p ans

input = Array.new

# remove all \r on windows?

STDIN.read.split("\n").each { |line| input << line }

n = input.delete_at 0

prefix = input[0].split //

input.each do |line|
  letters = line.split //
  letters.each_index do |i|
    if letters[i] != prefix[i]
      prefix = prefix[0...i]
      break
    end
  end
end

puts prefix.length

#!/usr/bin/ruby
n = gets.chomp.to_i
s = []
n.times do
	s << gets.chomp
end
max = 0
for i in 0..s[0].length-2
	prosel = true
	for si in s
#		prosel =false; break if si[0..i] != s[0][0..i]
		if si[0..i] != s[0][0..i]
			prosel = false
			break
		end
	end
	max = i+1 if prosel == true
end
puts max

n = gets.to_i

a = []
n.times do
    a << gets
end

a.sort!

def f(s, t)
  cnt = 0
  while cnt < s.length && cnt < t.length && s[cnt] == t[cnt]
    cnt = cnt + 1
  end
  cnt
end

ans = a[0].length
(a.length - 1 ).times do |i|
  t = f a[i], a[i+1]
  ans = t if t < ans
end

puts ans

n = gets.to_i

a = []
n.times do |i|
    a << gets
end

a.sort!

def f(s, t)
  cnt = 0
  while cnt < s.length && cnt < t.length && s[cnt] == t[cnt]
    cnt = cnt + 1
  end
  return  cnt
end

ans = a[0].length
(a.length - 1 ).times do |i|
  t = f a[i], a[i+1]
  if t < ans
    ans = t
  end
end

puts ans

n = gets.to_i
phoneNumbers = []
n.times do
	phoneNumbers << gets
end
ans = 0
phoneNumbers[0].length.times do |guessAns|
	check = true
	n.times do |id|
		if phoneNumbers[id][0..guessAns] != phoneNumbers[0][0..guessAns]
			check = false
		end
	end
	if check == true
		ans = guessAns+1
	end
end

puts ans

n = gets.to_i
s = gets.chomp
res = s.size
(n-1).times do
  s1 = gets.chomp
  0.upto(res-1) do |i|
    if s[i] != s1[i]
      res = i
      break
    end
  end
end
p res

nums = []
readline.to_i.times { nums << readline.strip }

ans = 0

head = nums.shift
tail = nums
head.length.times do |i|
  break unless tail.all? { |t| head[i] == t[i] }
  ans += 1
end

p ans


for _ in 0...(gets.chomp.to_i)
  len = gets.chomp.to_i
  string = gets.chomp
  if len >= 3
    puts "NO"
  elsif (string == "00") or (string == "11")
    puts "NO"
  else
    puts "YES"
  end
end

gets.to_i.times do
  n = gets.to_i
  s = gets.strip

  if n == 1 || s == "01" || s == "10"
    puts "YES"
  else
    puts "NO"
  end
end

for _ in 0...(gets.chomp.to_i)
  len = gets.chomp.to_i
  string = gets.chomp
  if (len == 1) or (len == 2)
    puts "YES"
  else
    if string.count("0") == string.count("1")
      puts "NO"
    else
      puts "YES"
    end
  end
end


def solve
  n = gets.to_i
  n -= 1
  a = gets.split(' ').map { |s| s.to_i}
  it, i, tmp, res = 0, 0, 0, 0
  f = 0
  while f < 2
    res += 1
    i = it
    it = (it + 1) % 2
    f += 1
    while i < n
      if a[i] > a[i + 1]
        tmp = a[i]
        a[i] = a[i + 1]
        a[i + 1] = tmp
        f = 0
      end
      i += 2
    end
    #puts "a : #{a}"
  end
  res -= 2
  puts res
end

t = gets.to_i
for z in 0...t
  solve
end

t = gets.to_i
t.times do

n = gets.to_i
a = gets.split.map!(&:to_i)
b = a.sort

cnt = 0
while a != b
  (cnt & 1).step(n - 2, 2) do |i|
    if a[i] > a[i+1]
      a[i], a[i+1] = a[i+1], a[i]
    end
  end
  cnt += 1
end

p cnt

end


n = gets.chomp.to_i
w = Array.new
l = gets.chomp.split
l.each do |i|
   w << i.to_i
end
h = Hash.new(0)
(0..n-2).each do |i|
    ((i+1)..n-1).each do |j|
        l = w[i] + w[j]
        if h[l] == 0
            h[l] = 1
        else
            a = h[l] + 1
            h[l] = a
        end
    end
end
w = -1
h.each do |key, value|
    if value > w
        w = value
    end
end
puts w

n = gets.strip.to_i
a = gets.split(" ").map(&:to_i)

h = {}
(0..n-2).each do |i|
  (i+1..n-1).each do |j|
     if h[a[i]+a[j]]
	h[a[i]+a[j]] = h[a[i]+a[j]] + 1
     else
	h[a[i]+a[j]] = 1
     end
  end
end

puts h.to_a.map{|e| e[1]}.max


n = Integer(gets.chomp)
solve = Array.new(n)
solve = gets.chomp.split.map &:to_i
m = Integer(gets.chomp)
period = Array.new(m)
for i in 0...m
    period[i] = gets.chomp.split.map &:to_i
end

time_solve = 0
for i in 0...n
    time_solve += solve[i]
end
output = -1
for i in 0..m-1
    if time_solve <= period[i][1] && time_solve >= period[i][0]
        output = time_solve
        break
    elsif  i != m - 1 && time_solve < period[i + 1][0] && time_solve > period[i][1]
        output = period[i + 1][0]
        break
    end
end

for i in 0...m
    if time_solve <= period[i][0]
        output = period[i][0]
        break
    elsif time_solve <= period[i][1]
        output = time_solve
        break
    end
end

puts output

gets
s=gets.split.map(&:to_i).reduce(:+)
gets.to_i.times{
	l,r=gets.split.map(&:to_i)
	s<=r&&(p [l,s].max;exit)
}
p -1

n = Integer(gets.chomp)
solve = Array.new(n)
solve = gets.chomp.split.map &:to_i
m = Integer(gets.chomp)
period = Array.new(m)
for i in 0...m
    period[i] = gets.chomp.split.map &:to_i
end

time_solve = 0
for i in 0...n
    time_solve += solve[i]
end
output = -1
for i in 0...m
    if period[i][1] >= time_solve && time_solve >= period[i][0]
        output = time_solve
    break
        end
end

puts output

n = Integer(gets.chomp)
solve = Array.new(n)
solve = gets.chomp.split.map &:to_i
m = Integer(gets.chomp)
period = Array.new(m)
for i in 0...m
    period[i] = gets.chomp.split.map &:to_i
end

time_solve = 0
for i in 0...n
    time_solve += solve[i]
end
output = -1
for i in 0...m
    for j in 0..1
        if period[i][j] >= time_solve
            output = period[i][j]
            break
        end
    end
end

puts output

n = Integer(gets.chomp)
solve = Array.new(n)
solve = gets.chomp.split.map &:to_i
m = Integer(gets.chomp)
period = Array.new(m)
for i in 0...m
    period[i] = gets.chomp.split.map &:to_i
end

time_solve = 0
for i in 0...n
    time_solve += solve[i]
end
output = -1
for i in 0..m-1
    if time_solve <= period[i][1] && time_solve >= period[i][0]
        output = time_solve
        break
    elsif  i != m - 1 && time_solve < period[i + 1][0] && time_solve > period[i][1]
        output = period[i + 1][0]
        break
    end
end

for i in 0...m
    if time_solve <= period[i][0]
        output = period[i][1]
        break
    elsif time_solve <= period[i][1]
        output = time_solve
        break
    end
end

puts output

n = Integer(gets.chomp)
solve = Array.new(n)
solve = gets.chomp.split.map &:to_i
m = Integer(gets.chomp)
period = Array.new(m)
for i in 0...m
    period[i] = gets.chomp.split.map &:to_i
end

time_solve = 0
for i in 0...n
    time_solve += solve[i]
end
output = -1
for i in 0...m
    for j in 0..1
        if period[i][j] >= time_solve
            output = time_solve
            break
        end
    end
end

puts output

n = Integer(gets.chomp)
solve = Array.new(n)
solve = gets.chomp.split.map &:to_i
m = Integer(gets.chomp)
period = Array.new(m)
for i in 0...m
    period[i] = gets.chomp.split.map &:to_i
end

time_solve = 0
for i in 0...n
    time_solve += solve[i]
end
output = -1
for i in 0..m-1
    if time_solve <= period[i][1] && time_solve >= period[i][0]
        output = time_solve
        break
    elsif  i != m - 1 && time_solve < period[i + 1][0] && time_solve > period[i][1]
        output = period[i + 1][0]
        break
    end
end

puts output

n = Integer(gets.chomp)
solve = Array.new(n)
solve = gets.chomp.split.map &:to_i
m = Integer(gets.chomp)
period = Array.new(m)
for i in 0...m
    period[i] = gets.chomp.split.map &:to_i
end

time_solve = 0
for i in 0...n
    time_solve += solve[i]
end
output = -1
for i in 0...m-1
    if period[i][1] >= time_solve && time_solve >= period[i][0]
        output = time_solve
        break
    elsif time_solve < period[i + 1][0] && time_solve > period[i][1]
        output = period[i + 1][0]
        break
    end
end

puts output

n = Integer(gets.chomp)
solve = Array.new(n)
solve = gets.chomp.split.map &:to_i
m = Integer(gets.chomp)
period = Array.new(m)
for i in 0...m
    period[i] = gets.chomp.split.map &:to_i
end

time_solve = 0
for i in 0...n
    time_solve += solve[i]
end
output = -1
for i in 1...m
    if period[i][1] >= time_solve && time_solve >= period[i][0]
        output = time_solve
        break
    elsif time_solve > period[i - 1][1] && time_solve < period[i][0]
        output = period[i][0]
        break
    end
end

puts output


n, m=gets.split.map(&:to_i)
c=n/3
s=[nil]*(n+1)
t=1
m.times do
  a, b=gets.split.map(&:to_i)
  if s[a].nil?&&s[b].nil?
    if t > c
      puts '-1'
      exit
    end
    s[a]=s[b]=t
    t+=1
  elsif s[a].nil?
    s[a]=s[b]
  elsif s[b].nil?
    s[b]=s[a]
  elsif s[a]!=s[b]
    puts '-1'
    exit
  end
end
h=Hash.new { |h, k| h[k]=[] }
s.each_with_index { |a, t| h[a]<<t if a }
if h.find {|k,v| v.size>3}
  puts '-1'
  exit
end
f=s.each_index.select { |i| !s[i] }
f.shift
for t in 1..c do
  r=h[t]
  n=r.size
  puts (r | f.pop(3-n)).join ' '
end

def dfs(now, parent, group)
    group.push now
    $vis[now] = true
    $path[now].each do |to|
        next if to == parent or $vis[to]
        dfs(to, now, group)
    end
    return group
end
n, m = gets.split(' ').map { |i|  i.to_i }
$vis = Array.new(50, false)
$path = Array.new(50){Array.new}
groups = []
can = true
m.times do
    x, y = gets.split(' ').map { |i| i.to_i}
    $path[x].push y
    $path[y].push x
end
n.times do |i|
    next if $vis[i+1]
    group = dfs(i+1, -1, [])
    can = false if group.size > 3
    $vis[i+1] = false if group.size == 1
    groups.push group unless group.size == 1
end
if can
    groups.each do |g|
        next if g.size >= 3
        while g.size != 3
            find = false
            for i in 1..n
                next if $vis[i]
                g.push i
                $vis[i] = true
                find = true
                break
            end
            if not find
                can = false
                break
            end
        end
    end
    group = []
    for i in 1..n
        next if $vis[i]
        group.push i
        if group.size == 3
            groups.push group
            group = []
        end
    end
end
if can
    groups.each do |g|
        puts g.join(' ')
    end
else
    puts -1
end

def dfs(now, parent, group)
    group.push now
    $vis[now] = true
    $path[now].each do |to|
        next if to == parent or $vis[to]
        dfs(to, now, group)
    end
    return group
end
n, m = gets.split(' ').map { |i|  i.to_i }
$vis = Array.new(50, false)
$path = Array.new(50){Array.new}
groups = []
can = true
m.times do
    x, y = gets.split(' ').map { |i| i.to_i}
    $path[x].push y
    $path[y].push x
end
n.times do |i|
    next if $vis[i+1]
    group = dfs(i+1, -1, [])
    can = false if group.size > 3
    while group.size < 3
        find = false
        for i in 1..n
            next if $vis[i]
            if $path[i].size == 0
                group.push i
                $vis[i] = true
                find = true
                break
            end
        end
        if not find
            can = false
            break
        end
    end
    groups.push group
end
if can
    groups.each do |g|
        puts g.join(' ')
    end
else
    puts -1
end

def dfs(now, parent, group)
    group.push now
    $vis[now] = true
    $path[now].each do |to|
        next if to == parent or $vis[to]
        dfs(to, now, group)
    end
    return group
end
n, m = gets.split(' ').map { |i|  i.to_i }
$vis = Array.new(50, false)
$path = Array.new(50){Array.new}
groups = []
can = true
m.times do
    x, y = gets.split(' ').map { |i| i.to_i}
    $path[x].push y
    $path[y].push x
end
n.times do |i|
    next if $vis[i+1]
    group = dfs(i+1, -1, [])
    can = false if group.size > 3
    while group.size < 3
        find = false
        for i in 1..n
            next if $vis[i]
            if $path[i].size == 0
                group.push i
                $vis[i] = true
                find = true
                break
            end
        end
        break unless find
    end
    groups.push group
end
if can
    groups.each do |g|
        puts g.join(' ')
    end
else
    puts -1
end

n,m=gets.split.map(&:to_i)
s=[nil]*(n+1)
t=1
m.times do
  a,b=gets.split.map(&:to_i)
  if s[a].nil?&&s[b].nil?
    s[a]=s[b]=t
    t+=1
  elsif s[a].nil?
    s[a]=s[b]
  elsif s[b].nil?
    s[b]=s[a]
  elsif s[a]!=s[b]
    puts'-1'
    exit
  end
end
h=Hash.new{|h,k|h[k]=[]}
s.each_with_index{|a,t|h[a]<<t if a}
f=s.each_index.select{|i|!s[i]}
f.shift
for t in 1..n/3 do
  r=h[t]
  n=r.size
  if n>3
    puts'-1'
    exit
  else
    puts (r | f.pop(3-n)).join' '
  end
end

n,m=gets.split.map(&:to_i)
s=[nil]*(n+1)
t=1
m.times do
  a,b=gets.split.map(&:to_i)
  if s[a]==nil&&s[b]==nil
    s[a]=s[b]=t
    t+=1
  elsif s[a]==nil
    s[a]=s[b]
  else
    s[b]=s[a]
  end
end
h=Hash.new{|h,k|h[k]=[]}
s.each_with_index{|a,t|h[a]<<t if a}
f=s.each_index.select{|i|!s[i]}
f.shift
for t in 1..n/3 do
  r=h[t]
  n=r.size
  if n>3
    puts'-1'
    exit
  else
    puts (r | f.pop(3-n)).join' '
  end
end

n, m=gets.split.map(&:to_i)
c=n/3
s=[nil]*(n+1)
t=1
m.times do
  a, b=gets.split.map(&:to_i)
  if s[a].nil?&&s[b].nil?
    if t > c
      puts '-1'
      exit
    end
    s[a]=s[b]=t
    t+=1
  elsif s[a].nil?
    s[a]=s[b]
  elsif s[b].nil?
    s[b]=s[a]
  elsif s[a]!=s[b]
    puts '-1'
    exit
  end
end
h=Hash.new { |h, k| h[k]=[] }
s.each_with_index { |a, t| h[a]<<t if a }
f=s.each_index.select { |i| !s[i] }
f.shift
for t in 1..c do
  r=h[t]
  n=r.size
  if n>3
    puts '-1'
    exit
  else
    puts (r | f.pop(3-n)).join ' '
  end
end

n,m=gets.split.map(&:to_i)
s=[nil]*(n+1)
t=1
m.times do
  a,b=gets.split.map(&:to_i)
  if s[a]==nil&&s[b]==nil
    s[a]=s[b]=t
    t+=1
  elsif s[a]==nil
    s[a]=s[b]
  else
    s[b]=s[a]
  end
end
h=Hash.new([])
s.each_with_index{|a,t|h[a]<<t if a}
f=s.each_index.select{|i|!s[i]}
f.shift
for t in 1..n/3 do
  r=h[t]
  n=r.size
  if n>3
    puts'-1'
    exit
  else
    puts (r | f.pop(3-n)).join' '
  end
end

n, m=gets.split.map(&:to_i)
s=[nil]*(n+1)
t=1
m.times do
  a, b=gets.split.map(&:to_i)
  if s[a].nil?&&s[b].nil?
    if t > n/3
      puts '-1'
      exit
    end
    s[a]=s[b]=t
    t+=1
  elsif s[a].nil?
    s[a]=s[b]
  elsif s[b].nil?
    s[b]=s[a]
  elsif s[a]!=s[b]
    puts '-1'
    exit
  end
end
h=Hash.new { |h, k| h[k]=[] }
s.each_with_index { |a, t| h[a]<<t if a }
f=s.each_index.select { |i| !s[i] }
f.shift
for t in 1..n/3 do
  r=h[t]
  n=r.size
  if n>3
    puts '-1'
    exit
  else
    puts (r | f.pop(3-n)).join ' '
  end
end

n,m=gets.split.map(&:to_i)
s=[nil]*(n+1)
t=1
m.times do
  a,b=gets.split.map(&:to_i)
  if s[a].nil?&&s[b].nil?
    s[a]=s[b]=t
    t+=1
  elsif s[a].nil?
    s[a]=s[b]
  elsif s[b].nil?
    s[b]=s[a]
  else
    puts'-1'
    exit
  end
end
h=Hash.new{|h,k|h[k]=[]}
s.each_with_index{|a,t|h[a]<<t if a}
f=s.each_index.select{|i|!s[i]}
f.shift
for t in 1..n/3 do
  r=h[t]
  n=r.size
  if n>3
    puts'-1'
    exit
  else
    puts (r | f.pop(3-n)).join' '
  end
end


#!/usr/bin/ruby
require 'prime'
n=gets.to_i
p n<3?1:2
puts (2..n+1).map{|e|e.prime? ? 1 : 2}*' '

n = gets.to_i + 1
colors = Array.new(n + 1)
2.upto(n) do |i|
  next if colors[i]
  colors[i] = 1
  (2 * i).step(n, i){|j| colors[j] = 2}
end
colors.shift(2)
p colors.max
puts colors.join(' ')

n = gets.to_i

a = Array.new
max = 1
(2..n+1).each do |i|
  (1..n+1).each do |j|
    break if i * j > n+1
    next if a[j].to_i > 1
    next if a[i * j] == 2
    a[i * j] = a[j].to_i == 1 ? 2 : 1
    max = [a[i * j], max].max
  end
end

puts max
puts a[2, a.length].join(' ')

def is_prime(n=2)
	if n < 2
	       	return 0
	elsif n==2
	       	return 1
	elsif n%2==0
	       	return 0
	else
		j=3
		while j*j<=n
			if n % j == 0
				return 0
			end
			j+=2;
		end
		return 1
	end
end
n=gets.chomp.to_i
#puts n
color=Array.new(n+2,1)
#puts color.join(' ')
number=1
i=2
max=1
while i<=n+1
	if is_prime(i)
		j=2
		while i*j <= n+1
			color[i*j]=2
			max=color[i*j] if color[i*j] > max
			j+=1
		end
	end
	i+=1
end
#puts color.join(' ')
puts max
i=2
while i<=n+1
	print " #{color[i]}"
	i+=1
end
puts

#!/usr/bin/ruby
require 'prime'
n=gets.to_i
p n<2?1:2
puts (1..n).map{|e|e.prime? ? 1 : 2}*' '

n=gets.chomp.to_i
#puts n
color=Array.new(n+2,1)
#puts color.join(' ')
number=1
i=2
max=1
while i<=n+1
	j=2
	while i*j <= n+1
		color[i*j]+=1
		max=color[i*j] if color[i*j] > max
		j+=1
	end
	i+=1
end
#puts color.join(' ')
puts max
i=2
while i<=n+1
	print " #{color[i]}"
	i+=1
end
puts

n=gets.chomp.to_i
#puts n
color=Array.new(n+2,0)
#puts color.join(' ')
number=1
i=2
max=0
while i<=n+1
	if color[i]==0
		color[i]=number
		j=2
		while i*j <= n+1
			if color[i*j]==0
				color[i*j]=number+1
				max=number+1 if number + 1 > max
			else
				color[i*j]=number+2
				max=number+2 if number + 1 > max
				number+=1;
			end
			j+=1
		end
	end
	i+=1
end
#puts color.join(' ')
puts max
i=2
while i<=n+1
	print " #{color[i]}"
	i+=1
end
puts

n = gets.to_i + 1
colors = Array.new(n)
2.upto(n) do |i|
  i.step(n, i).with_index{|j, c| colors[j] ||= c + 1}
end
colors.compact!
p colors.uniq.size
puts colors.join(' ')

n = gets.to_i + 1
colors = Array.new(n + 1, 1)
2.upto(n) do |i|
  c = colors[i] + 1
  (2 * i).step(n, i) do |j|
    colors[j] = [colors[j], c].max
  end
end
colors.shift(2)
p colors.max
puts colors.join(' ')

n = gets.to_i

a = Array.new
max = 1
(2..n+1).each do |i|
  (1..n+1).each do |j|
    break if i * j > n+1
    next if a[i * j].to_i > a[j].to_i
    a[i * j] = [a[j].to_i, a[i * j].to_i].max + 1
    max = [a[i * j], max].max
  end
end

puts max
puts a[2, a.length].join(' ')


N,K = gets.split.map &:to_i
es = Hash[(1..N).map{ |n| [n,{}] }]
(1..N-1).each{ |i|
  a,b = gets.split.map &:to_i
  es[a][b] = es[b][a] = i-1
}
R = (1..N).map{ |n| es[n].size }.sort[-K-1]
colors = Array.new(N-1,nil)

queue = [[nil,1]]

while cn = queue.pop do
  c,n = cn
  c = 0 if !c
  es[n].each{  |m,i|
    next if colors[i]
    c = (c + 1) % R
    colors[i] = c
    queue << [c,m]
  }
end

p R
puts colors.map{ |c| c + 1 } * " "


main = -> {
  t = int
  t.times do
    string
    grid = rep(8) { string }
    (2 .. 7).any? do |i|
        (2 .. 7).any? do |j|
            if grid[i - 2][j - 2] == ?# && grid[i - 2][j] == ?# && grid[i][j - 2] == ?# && grid[i][j] == ?#
                puts "#{i} #{j}"
                true
            else
                false
            end
        end
    end
  end
}

DEBUG = false
MOD = 10**9+7
INF = 10**18
$yesno = %w(No Yes)
$YesNo = %w(No Yes)
$YESNO = %w(NO YES)

require "set"
require "prime"

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 strings; gets.to_s.split 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 ? 1 : 0] end
def YesNo t; puts $YesNo[t ? 1 : 0] end
def YESNO t; puts $YESNO[t ? 1 : 0] 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 * y.mod_inv(mod) % mod end
  def mod_nCr(r, mod = MOD); x = y = 1; (1..r).each { |i| x = x * (self + 1 - i) % mod; y = y * i % mod }; x.mod_div(y, 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
  def compress(kinds = uniq.sort!); map { |x| kinds.bsearch_index { _1 >= x } }; 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[]

gets.to_i.times do
  gets
  xxs = 8.times.map { gets.chomp.chars }
  r, c = (1..6).flat_map do |i|
    (1..6).filter_map do |j|
      if xxs[i - 1][j - 1] == "#" && xxs[i - 1][j + 1] == "#" && xxs[i + 1][j - 1] == "#" && xxs[i + 1][j + 1] == "#"
        [i + 1, j + 1]
      end
    end
  end.first
  puts "#{r} #{c}"
end

n = gets.to_i

n.times do
  gets

  r = -1

  m = Array.new(8)

  8.times do |i|
    line = gets

    m[i] = line.chars
  end

  8.times do |i|
    8.times do |j|
      next unless m[i][j] == "#"
      next unless i - 1 > -1 && j - 1 > -1 && m[i - 1][j - 1] == "#"
      next unless i + 1 < 8 && j + 1 < 8 && m[i + 1][j + 1] == "#"
      next unless i - 1 > -1 && j + 1 < 8 && m[i - 1][j + 1] == "#"
      next unless i + 1 > -1 && j - 1 > -1 && m[i + 1][j - 1] == "#"

      puts [i, j].map(&:succ).map(&:to_s).join(" ")
    end
  end
end

$cnt = []

def solve
    v = Array.new(8){Array.new(8)}
    t = gets.split
    i = 0
    while i < 8
        s = gets.split('')
        j = 0
        s.each do |x|
            v[i][j] = x
            j = j + 1
        end
        i = i + 1
    end
    i = 1
    while i < 7
        j = 1
        while j < 7
            if v[i - 1][j - 1] == '#' and v[i - 1][j + 1] == '#' and v[i + 1][j - 1] == '#' and v[i + 1][j + 1] == '#'
                ans = []
                ans.append(i + 1)
                ans.append(j + 1)
                puts ans * " "
            end
            j = j + 1
        end
        i = i + 1
    end
end

maxn = 10005
maxn.times do
    $cnt.append(0)
end
gets.to_i.times do
    solve
end

gets.to_i.times do
  gets
  s = Array.new(8){gets.chomp.chars}
  gx, gy = 0, 0
  dx = [-1, -1, 1, 1]
  dy = [-1, 1, -1, 1]
  8.times do |i|
    8.times do |j|
      cnt = 0
      4.times do |k|
        x = j+dx[k]
        y = i+dy[k]
        if 0 <= x && x < 8 && 0 <= y && y < 8
          cnt += 1 if s[y][x] == '#'
        end
      end
      if cnt == 4
        gx = j+1
        gy = i+1
      end
    end
  end
  puts "#{gy} #{gx}"
end

gets.to_i.times do
  gets
  xxs = 8.times.map { gets.chomp.chars }
  r, c = (0..7).flat_map do |i|
    (0..7).filter_map do |j|
      [i + 1, j + 1] if xxs[i][j] == "#" && xxs[i].count("#") == 1 && xxs.map { |xs| xs[j] }.count("#") == 1
    end
  end.first
  puts "#{r} #{c}"
end


#$stdin=File.open "input.txt","r"
#$stdout=File.open "output.txt","w"

notifications=Array.new
d=0
a=0

n,q=gets.split.map{|x|x.to_i}
unread=Array.new(n+1,0)
read=Array.new(n+1,0)

q.times do

	t,x=gets.split.map{|y|y.to_i}

	if t==1 then notifications.push x; a+=1; unread[x]+=1
	elsif t==2 then
		a-=unread[x];read[x]+=unread[x];unread[x]=0
	elsif t==3
		notifications[0...x-d].each do |i|
			if read[i]>0 then read[i]-=1
			elsif unread[i]>0 and a>0 then unread[i]-=1;a-=1
			end
			notifications.shift;d+=1
		end if x-d>0
	end

	puts a
end

input = gets.chomp.split
n = Integer(input[0])
q = Integer(input[1])
event = []
for i in 0...q
    event[i] = []
    input1 = gets.chomp.split
    event[i][0] = Integer(input1[0])
    event[i][1] = Integer(input1[1])
end

unread = 0
notification = []
result = []
record = []
for i in 0...n
    record[i] = []
end
x = 0
for i in 0...q
    if event[i][0] == 1
        notification.push([event[i][1], 0])
        unread += 1
        record[event[i][1] - 1].push(notification.length - 1)
    elsif event[i][0] == 2
        for j in record[event[i][1] - 1]
            if j >= x && notification[j][1] == 0
                notification[j][1] = 1
                unread -= 1
            end
        end
        record[event[i][1] - 1] = []
    else
        if event[i][1] > x
            for j in x...event[i][1]
                if notification[j][1] == 0
                    notification[j][1] = 1
                    unread -= 1
                end
            end
            x = event[i][1]
        end
    end
    result.push(unread)
end

puts result

@n, @q = STDIN.gets.split(' ').collect{|x| x.to_i}
@record = Hash.new{|hash,key| hash[key] = Array.new}
@g, @decnt, @maxt, @count = Array.new, 0, 0, 0
@q.times do
	opt, x = STDIN.gets.split(' ').collect{|x| x.to_i}
	case opt
		when 1 then
			@g.push true
			@record[x].push(@count)
			@count += 1
		when 2 then
			@record[x].each do |v|
				if @g[v] then
					@g[v] = false
					@decnt += 1
				end
			end
			@record[x].clear
		when 3 then
			for i in @maxt...[x, @count].min do
				if @g[i] then
					@g[i] = false
					@decnt += 1
				end
			end
			@maxt = [[x, @count].min, @maxt].max
	end
	puts @count-@decnt
end

input = gets.chomp.split
n = Integer(input[0])
q = Integer(input[1])
event = []
for i in 0...q
    event[i] = []
    input1 = gets.chomp.split
    event[i][0] = Integer(input1[0])
    event[i][1] = Integer(input1[1])
end

=begin
def unread_count(a)
    unread_count = 0
    for i in 0...a.length
        if a[i][1] == 0
            unread_count += 1
        end
    end
    return unread_count
end
=end

unread = 0
notification = []
result = []
record = []
for i in 0...n
    record[i] = []
end
x = 0
for i in 0...q
    if event[i][0] == 1
        notification.push([event[i][1], 0])
        unread += 1
        record[event[i][1] - 1].push(notification.length - 1)
    elsif event[i][0] == 2
        for j in record[event[i][1] - 1]
            if j > x && notification[j][1] == 0
                notification[j][1] = 1
                unread -= 1
            end
        end
    else
        if event[i][1] > x
            for j in x...event[i][1]
                if notification[j][1] == 0
                    notification[j][1] = 1
                    unread -= 1
                end
            end
            x = event[i][1]
        end
    end
    result.push(unread)
end

puts result

#$stdin=File.open "input.txt","r"
n,q=gets.split.map{|x|x.to_i}
notifications=Array.new
count=Array.new
c=0
q.times do
	a,b=gets.split.map{|x|x.to_i}

	if a==1
		notifications[b]=0 if notifications[b]==nil
		notifications[b]+=1
		count[c]=b;
		c+=1
	elsif a==2
		notifications[b]=0
	else
		count[0..b].each {|x| notifications[x]-=1 if notifications[x]>0}
	end
	sum=0
	notifications.each {|x| sum+=x if x!=nil}
	puts sum
end

#$stdin=File.open "input.txt","r"
n,q=gets.split.map{|x|x.to_i}
notifications=Array.new
count=Array.new
c=0
q.times do
	a,b=gets.split.map{|x|x.to_i}

	if a==1
		notifications[b]=0 if notifications[b]==nil
		notifications[b]+=1
		count[c]=b;
		c+=1
	elsif a==2
		notifications[b]=0
	else
		count[0...b].each {|x| notifications[x]-=1 if notifications[x]>0}
	end
	sum=0
	notifications.each {|x| sum+=x if x!=nil}
	puts sum
end

#$stdin=File.open "input.txt","r"

notifications=Array.new
a=0

n,q=gets.split.map{|x|x.to_i}
unread=Array.new(n+1,0)
read=Array.new(n+1,0)

q.times do

	t,x=gets.split.map{|y|y.to_i}

	if t==1 then notifications.push x; a+=1; unread[x]+=1
	elsif t==2 then
		a-=unread[x];read[x]+=unread[x];unread[x]=0
	elsif t==3
		notifications[0...x].each do |i|
			if read[i]!=0 then read[i]-=1
			else unread[i]-=1;a-=1
			end
#print notifications, "\n"
#print read,"\n"
#print unread, "\n"
		end
	end
#	print read,"\n"
#	print unread,"\n"
	puts a
end

#$stdin=File.open "input.txt","r"

notifications=Array.new
read=Array.new

n,q=gets.split.map{|x|x.to_i}

q.times do

	t,x=gets.split.map{|y|y.to_i}

	notifications.push x if t==1
	if t==2
		notifications.each do |y|
			ind=notifications.index y
			read[ind]=y if y==x
		end
	elsif t==3
		notifications[0...x].each do |y|
			ind = notifications.index y
			read[ind]=y
		end
	end
	puts (notifications-read).length
end

#$stdin=File.open "input.txt","r"

notifications=Array.new
a=0

n,q=gets.split.map{|x|x.to_i}
unread=Array.new(n+1,0)
read=Array.new(n+1,0)

q.times do

	t,x=gets.split.map{|y|y.to_i}

	if t==1 then notifications.push x; a+=1; unread[x]+=1
	elsif t==2 then
		a-=unread[x];read[x]+=unread[x];unread[x]=0
	elsif t==3
		notifications[0...x].each do |i|
			if read[i]!=0 then read[i]-=1
			elsif unread[i]>0 and a>0 then unread[i]-=1;a-=1
			end
#print notifications, "\n"
#print read,"\n"
#print unread, "\n"
		end
	end
#	print read,"\n"
#	print unread,"\n"
	puts a
end

#$stdin=File.open "input.txt","r"
#$stdout=File.open "output.txt","w"

notifications=Array.new
d=0
a=0

n,q=gets.split.map{|x|x.to_i}
unread=Array.new(n+1,0)
read=Array.new(n+1,0)

q.times do

	t,x=gets.split.map{|y|y.to_i}

	if t==1 then notifications.push x; a+=1; unread[x]+=1
	elsif t==2 then
		a-=unread[x];read[x]+=unread[x];unread[x]=0
	elsif t==3
#	cur_read=read.clone
		notifications[0...x-d].each do |i|
#			if cur_read[i]>0 then cur_read[i]-=1
			if read[i]>0 then read[i]-=1;notifications.shift;d+=1
			elsif unread[i]>0 and a>0 then unread[i]-=1;a-=1
			end
		end
	end

	puts a
end

#$stdin=File.open "input.txt","r"
#$stdout=File.open "output.txt","w"

notifications=Array.new
d=0
a=0

n,q=gets.split.map{|x|x.to_i}
unread=Array.new(n+1,0)
read=Array.new(n+1,0)

q.times do

	t,x=gets.split.map{|y|y.to_i}

	if t==1 then notifications.push x; a+=1; unread[x]+=1
	elsif t==2 then
		a-=unread[x];read[x]+=unread[x];unread[x]=0
	elsif t==3
		notifications[0...x-d].each do |i|
			if read[i]>0 then read[i]-=1;d+=1
			elsif unread[i]>0 and a>0 then unread[i]-=1;a-=1
			end
			notifications.shift
		end if x-d>0
	end

	puts a
end

#$stdin=File.open "input.txt","r"
n,q=gets.split.map{|x|x.to_i}
notifications=Array.new
count=Array.new
c=0
q.times do
	a,b=gets.split.map{|x|x.to_i}

	if a==1
		notifications[b]=0 if notifications[b]==nil
		notifications[b]+=1
#print -1,notifications,-1,"\n"
		count[c]=b;
		c+=1
#		print -3,count,-3,"\n"
	elsif a==2
		notifications[b]=0
	else
		count.each do |x|
			notifications[x]-=1
#			print -2,notifications,-2,"\n"
		end
	end
	sum=0
	notifications.each {|x| sum+=x if x!=nil}
	puts sum
end

#$stdin=File.open "input.txt","r"

notifications=Array.new
a=0

n,q=gets.split.map{|x|x.to_i}
unread=Array.new(n+1,0)
read=Array.new(n+1,0)

q.times do

	t,x=gets.split.map{|y|y.to_i}

	if t==1 then notifications.push x; a+=1; unread[x]+=1
	elsif t==2 then
		a-=unread[x];read[x]+=unread[x];unread[x]=0
	elsif t==3
		notifications[0...x].each do |i|
			if read[i]!=0 then read[i]-=1
			elsif unread[i]>0 and a>0 then unread[i]-=1;a-=1
			end
		end
	end

	puts a
end

#$stdin=File.open "input.txt","r"
#$stdout=File.open "output.txt","w"

notifications=Array.new
a=0

n,q=gets.split.map{|x|x.to_i}
unread=Array.new(n+1,0)
read=Array.new(n+1,0)

q.times do

	t,x=gets.split.map{|y|y.to_i}

	if t==1 then notifications.push x; a+=1; unread[x]+=1
	elsif t==2 then
		a-=unread[x];read[x]+=unread[x];unread[x]=0
	elsif t==3
		cread=read.clone
		notifications[0...x].each do |i|
			if cread[i]!=0 then cread[i]-=1
			elsif unread[i]>0 and a>0 then unread[i]-=1;a-=1
			end
		end
	end

#	print read,"\n"
#	print unread,"\n"
	puts a
end

#$stdin=File.open "input.txt","r"

notifications=Array.new
a=0

n,q=gets.split.map{|x|x.to_i}
unread=Array.new(n+1,0)
read=Array.new(n+1,0)

q.times do

	t,x=gets.split.map{|y|y.to_i}

	if t==1 then notifications.push x; a+=1; unread[x]+=1
	elsif t==2 then
		a-=unread[x];read[x]+=unread[x];unread[x]=0
	elsif t==3
		notifications[0...x].each do |i|
			if read[i] then read[i]-=1
			else unread[x]-=1;a-=1
			end
		end
	end

	puts a
end

#$stdin=File.open "input.txt","r"
n,q=gets.split.map{|x|x.to_i}
notifications=Array.new
count=Array.new
c=0
q.times do
	a,b=gets.split.map{|x|x.to_i}

	if a==1
		notifications[b]=0 if notifications[b]==nil
		notifications[b]+=1
		count[c]=b;
		c+=1
	elsif a==2
		notifications[b]=0
	else
		count.each {|x| notifications[x]-=1 if notifications[x]>0}
	end
	sum=0
	notifications.each {|x| sum+=x if x!=nil}
	puts sum
end


def prime?(num)
  2.upto(num-1){|i|
    if num % i == 0
      return false
    end
  }
  return true
end
p = Array.new
i = 2
while p.length < 50
  if prime?(i)
    p << i
  end
  i += 1
end
n = gets.to_i
if n!=2
  for i in 0...n
    ans = 1
    for j in 0...n-1
      ans *= p[(i+j)%n]
    end
    puts ans
  end
else
  puts -1
end

require 'mathn'

n = gets.to_i

if n == 2 then puts "-1"
else

primes = []
p = Prime.new
n.times do
  primes << p.next()
end

product = primes.inject do |p, x|
  p * x
end
a = primes.map do |x|
  product / x
end

puts a.join("\n")

end

require 'prime'

n = gets.to_i
if n == 2
	p -1
	exit
end

a = []
Prime.each do |prime|
	a << prime
	break if a.size == n
end
s = a.inject(&:*)
a = a.map{|_| s / _}
puts a * "\n"
__END__
n.times do |i|
	p a[i] if a[i].to_s.size > 100
	i.times do |j|
		p "#{a[i]} #{a[j]}" if a[i].gcd(a[j]) == 1
	end
end
p "555" if a.inject(&:gcd) > 1

#!/usr/bin/ruby

require 'prime'

n = gets.to_i
if n == 2
	p -1
	exit
end

arr = Prime.take(n)

n.times { |i|
	tmp = arr.dup
	tmp.delete_at(i)
	p tmp.inject(:*)
}

n = STDIN.gets.chomp.to_i
if n == 1
  puts 2
  exit 0
end
if n == 2
  puts -1
  exit 0
end
primes = []
# get primes
x = 2
while primes.size < n+1
  ok = true
  primes.each { |t|
    if (x % t == 0)
      ok = false
      break;
    end
  }
  if ok
    primes.push(x)
  end
  x = x + 1
end

ans = []
(n-1).times { |i|
  ans.push(primes[0])
}
ans.push(1)

(n-1).times { |i|
  ans[i] *= primes[i+1]
  ans[n-1] *= primes[i+1]
}

n.times { |i|
  puts ans[i]
}

require 'prime'
n = gets
n = n.to_i
i = 0
num = 2
primes = Array.new()
while i<n
    if num.prime? then
        primes.push num
        i+=1
    end
    num+=1
end
if n==2 then
    puts "-1"
else
for i in 0..n-1
    num = 1
    for j in 0..n-1
        if i!=j then
            num*=primes[j]
        end
    end
    puts num
end
end

def prime x

  m = Math.sqrt x
  for i in 2..m
    if x % i == 0
      return false
    end
  end

  return true

end

n = gets.to_i

if n == 2
  puts -1
else

  primes = []

  cur = 2
  while primes.size < n
    if prime cur
      primes.push cur
    end
    cur += 1
  end

  product = 1
  for prime in primes
    product *= prime
  end

  for i in 0...n
    puts product / primes[i]
  end
end

N = gets.to_i

if N == 2
  puts -1
else
  puts 21
  puts 14
  1.upto(N - 2) { |i|
    puts 3 * (2 ** i)
  }
end

n = STDIN.gets.chomp.to_i
if n == 2
  puts -1
  exit 0
end

values = [99, 55, 11115]
product = values.reduce(&:*)
multiplier = 1
4.upto(n) do
  values.push(product * multiplier)
  multiplier += 1
end
values.each do |value|
  puts value
end

def gcd(a, b)
    return a if b.eql? 0
    gcd(b, a % b)
end

n = gets.to_i

if (n == 2)
  puts -1
  exit
end

mas = [20,18,15]
for i in 3..n-1
  mas[i] = mas[i-1]*3;
end

puts mas

def is_prime(n)
    i = 2
    while i * i <= n
        return false if n % i == 0
        i += 1
    end
    true
end

n = gets.to_i

if n == 2
    puts -1
else
    i = 2
    primes = []
    while primes.size < n
        primes << i if is_prime(i)
        i += 1
    end

    product = primes.inject(1) { |p, i| p * i }
    puts primes.map { |p| product / p }
end

require 'mathn'

n = gets.to_i

primes = []
p = Prime.new
n.times do
  primes << p.next()
end

product = primes.inject do |p, x|
  p * x
end
a = primes.map do |x|
  product / x
end

puts a.join(" ")

require 'mathn'

n = gets.to_i

primes = []
p = Prime.new
n.times do
  primes << p.next()
end

product = primes.inject do |p, x|
  p * x
end
a = primes.map do |x|
  product / x
end

puts a.join("\n")

#!/usr/bin/ruby

require 'prime'

n = gets.to_i
if n == 2
	p -1
	exit
end

arr = Prime.take(50)

n.times { |i|
	tmp = arr.dup
	tmp.delete_at(i)
	p tmp.inject(:*)
}

#!/usr/bin/ruby

require 'mathn'

n = gets.to_i
if n == 2
	p -1
	exit
end

arr = []
Prime.each(1000) { |pr|
	arr << pr
	break if arr.size == n
}

n.times { |i|
	tmp = arr.dup
	tmp.delete_at(i)
	p tmp.inject(:*)
	p tmp.inject(:*).to_s.size
}

#!/usr/bin/ruby

require 'mathn'

n = gets.to_i
if n == 2
	p -1
	exit
end

arr = []
Prime.each(100) { |pr|
	arr << pr
	break if arr.size == n
}

n.times { |i|
	tmp = arr.dup
	tmp.delete_at(i)
	p tmp.inject(:*)
}

n = STDIN.gets.chomp.to_i
primes = []
# get primes
x = 2
while primes.size < n+1
  ok = true
  primes.each { |t|
    if (x % t == 0)
      ok = false
      break;
    end
  }
  if ok
    primes.push(x)
  end
  x = x + 1
end

ans = []
(n-1).times { |i|
  ans.push(primes[0])
}
ans.push(1)

(n-1).times { |i|
  ans[i] *= primes[i+1]
  ans[n-1] *= primes[i+1]
}

n.times { |i|
  puts ans[i]
}

def prime x

  m = Math.sqrt x
  for i in 2..m
    if x % i == 0
      return false
    end
  end

  return true

end

n = gets.to_i

primes = []

cur = 2
while primes.size < n
  if prime cur
    primes.push cur
  end
  cur += 1
end

product = 1
for prime in primes
  product *= prime
end

for i in 0...n
  puts product / primes[i]
end

n = STDIN.gets.chomp.to_i
if n == 2
  puts -1
  exit 0
end

factorial = {}
f = 1
1.upto(n + 5) do |i|
  f *= i
  factorial[i] = f
end

values = []
1.upto(n - 2) do |i|
  values.push(factorial[i+1])
end

values.each { |x| puts x }
puts values.last * 97
puts values.last * 97 * 2

def is_prime(n)
    i = 2
    while i * i <= n
        return false if n % i == 0
        i += 1
    end
    true
end

n = gets.to_i

i = 2
primes = []
while primes.size < n
    primes << i if is_prime(i)
    i += 1
end

product = primes.inject(1) { |p, i| p * i }
puts primes.map { |p| product / p }