strLen = gets.chomp.to_i
str = gets.chomp
inStr = []

until str.index('(').nil?
	open = str.index('(')
	close = str.index(')')

	inStr << str[open + 1..close - 1]
	str = str[0...open] + '_' + str[(close + 1)...str.length]
end

str = str.split('_')

inStr.each_index do |i|
	inStr[i] = inStr[i].split('_')
	inStr[i].delete('')
end

str.delete('')
outLongestWord = 0
inWord = 0

str.sort! do |a, b|
	if a.length > b.length
		-1
	elsif a.length == b.length
		0
	else
		1
	end
end

if str.length > 0
	outLongestWord = str[0].length
end

inStr.each do |is|
	inWord += is.length if is.length > 0
end

puts "#{outLongestWord} #{inWord}"


gets
str = gets.chomp
inside = 0
str.gsub!(/\(\w*\)/) do |m|
  inside += m.split(/[_\(\)]/).select { |s| s != '' }.size
  '_'
end
puts "#{str.split('_').map(&:size).sort.last.to_i} #{inside}"


x = gets.to_i

m = x % 4

if m == 1
  puts "0 A"
elsif m == 2
  puts "1 B"
elsif m == 3
  puts "2 A"
else
  puts "1 A"
end


n = gets.to_i
if n % 4 == 1
  puts "0 A"
elsif n % 4 == 3
  puts "2 A"
elsif n % 4 == 2
  puts "1 B"
else
  puts "1 A"
end


n = gets.to_i%4
if n == 0
    puts "1 A"
elsif n == 1
    puts "0 A"
elsif n == 2
    puts "1 B"
else
    puts "2 A"
end


n,R,r = gets.split.map{|x| x.to_f}

if R-r >= r
	theta = 2*Math.acos(r/(R-r))

	if (n-2)*Math::PI <= n * theta then
		puts "YES"
	else
		puts "NO"
	end
elsif R-r>=0
	puts "YES" if n == 1
	puts "NO" if n != 1
else
	puts "NO"
end


n,R,r=gets.split.map{|_|_.to_i}

if n == 1
  if R>=r
    puts "YES"
  else
    puts "NO"
  end
elsif n == 2
  if R>=r*2
    puts "YES"
  else
    puts "NO"
  end
else
  if r/Math.sin(Math::PI/n)+r<=R+1e-14
    puts "YES"
  else
    puts "NO"
  end
end


n, u, r = gets.split.map { |x| x.to_i }
r_max = u
if n > 1
  s = Math.sin(Math::PI / n).round(10)
  r_max = s * u / (1 + s)
end
puts(r <= r_max ? 'YES' : 'NO')


arr=gets.chomp.split.map(&:to_i)
co = {}
arr.each do |a|
  if co[a].nil?
    co[a] = 1
  else
  co[a] +=1
  end
end

puts 4 - co.keys.length


include Math
require "prime"
require "bigdecimal"
require "bigdecimal/math"
require "matrix"
require "pp"
require "benchmark"

Infinity = 1/0.0
class Matrix;def inspect;empty? ? "Matrix.empty(#{row_size}, #{column_size})":"Matrix[\n#{@rows.map(&:inspect).join("\n")}\n]";end;end
def pbin(obj);case obj;when Integer;puts obj.to_s(2);end;end
class String;def to_a;split("");end;end
class String;def to_ia;split.map(&:to_i);end;end
def getia;gets.to_ia;end
def geti;gets.to_i;end
class Object;def dcopy;Marshal.load(Marshal.dump(self));end;end

def chk(x,y,h,b)
    yy=y.to_a
    xx=x.to_a
    xx.each{|c|b-=1 if yy.include?(c)}
    b+=h
    xx.zip(yy){|s,t|h-=1 if s==t}
    return true if h.zero? && b.zero?
    return false
end

n=geti
a=[]
n.times{
    i=gets.split
    i[1]=i[1].to_i
    i[2]=i[2].to_i
    a<<i
}
arr=[]
ok=[]
[0,1,2,3,4,5,6,7,8,9].permutation(4){|q|arr<<q.join}
arr=arr.find_all{|x|
    a.all?{|y,h,b|
        chk(x,y,h,b)
    }
}
k=arr.size
if k==0
    puts"Incorrect data"
elsif k==1
    puts arr[0]
else
    puts"Need more data"
end


def gao1(a, b)
	c = 0
	4.times{|i| c += 1 if a[i] == b[i]}
	c
end

def gao2(a, b)
	c = 0
	4.times{|i| c += 1 if b.index(a[i])}
	c
end

n = gets.to_i
x = 100.upto(9999).map{|_| '%04d' % _}
x.reject!{|_| _.bytes.sort.uniq.size < 4}
n.times do
	a, b, c = gets.split.map(&:to_i)
	a = '%04d' % a
	c += b
	x.reject!{|_| gao1(_, a) != b || gao2(_, a) != c}
end

if x.empty?
	puts 'Incorrect data'
elsif x.size > 1
	puts 'Need more data'
else
	puts x[0]
end


gets
b=$_.each_char.max.to_i+1
x,y=$_.split.map{|i|i.to_i(b)}
p (x+y).to_s(b).size


n, m, k = gets.strip.split(' ').map(&:to_i)
puts [m, k].min >= n ? "Yes" : "No"


#!usr/bin/env ruby

# https://codeforces.com/problemset/problem/1186/A

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

puts (input[0] <= input[1] && input[0] <= input[2]) ? "Yes" : "No"


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

puts (n <= [m,k].min) ? "Yes" : "No"


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

b = 0
c = 0
(0..n-1).each do |i|
  a = as[i]
  if a > 0
    b += a
  else
    c += a
  end
end
puts b - c


n,*a=$<.read.split.map &:to_i
x,y=a.partition{|e|e>0}
p x.reduce(0,:+)-y.reduce(0,:+)


n = gets.to_i

numbers = gets.split.map(&:to_i)
positive_sum = 0
negative_sum = 0

numbers.each do |number|
  number >= 0 ? positive_sum += number :  negative_sum += number
end

puts positive_sum - negative_sum


def cal(p, t, c)
  sum, sumt = 0, 0
  p.zip(t).each do |pp, tt|
    sumt += tt * c
    if pp > sumt
      sum += (pp - sumt)
    end
  end
  return sum
end

n, c = readline.split(' ').collect(&:to_i)
p = readline.split(' ').collect(&:to_i)
t = readline.split(' ').collect(&:to_i)
diff = cal(p, t, c) - cal(p.reverse, t.reverse, c)
if diff > 0
  puts "Limak"
elsif diff < 0
  puts "Radewoosh"
else
  puts "Tie"
end


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

p1 = 0
t1 = 0
n.times do |i|
    t1 += t[i]
    p1 += [p[i] - c*t1, 0].max
end

p2 = 0
t2 = 0
n.times do |i|
    t2 += t[n-i-1]
    p2 += [p[n-i-1] - c*t2,0].max
end

if p1 > p2
    puts "Limak"
elsif p2 > p1
    puts "Radewoosh"
else
    puts "Tie"
end


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

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

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

def puts_yesno(can) puts(can ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def debug(k,v) puts "#{k}:#{v}" end
########### ( ˘ω˘ )ｽﾔｧ… ###########
require 'prime'
x,n=gsmi
xp = x.prime_division.map{|i|i[0]}
ans = 1

xp.each do |i|
  num = 1

  # nが何乗までできるかしらべる
  cnt=0
  while num<n do
    num = num*i
    cnt+=1 if num<=n
  end

  prev = 0
  rui_cnt = 0
  cnt.downto(1) do |j|
    d = n/(i**j)
    rui_cnt += (d-prev)*j
    prev = d
  end

  #puts rui_cnt
  base = i
  while rui_cnt>0 do
    d = rui_cnt/10
    m = rui_cnt%10
    ans*=(base**m)
    ans%=MOD
    base = (base**10)%MOD
    rui_cnt=d
  end
  #ans*=(i**rui_cnt)
  # rui_cnt.times do |j|
  #   ans *= i
  #   ans %= MOD
  # end
  #ans%=MOD
end
puts ans % MOD


n, m = readline.split.map(&:to_i)
i = 2
cnt = 0
l = Array.new(100)
while i*i<=n
	if n%i == 0
		l[cnt] = i
		cnt += 1
		while n % i == 0 do n/=i end
	end
	i += 1
end
if n > 1
	l[cnt] = n
	cnt += 1
end
ans = 1
$mod = 1000000007
def qp x, y
	ans = 1
	while y>0
		if (y&1)==1 then ans = ans * x % $mod end
		x = x * x % $mod
		y >>= 1
	end
	ans
end
for i in 0..cnt-1
	tmp = m
	while tmp > 0
		ans *= qp(l[i], tmp/l[i])
		ans %= $mod
		tmp/=l[i]
	end
end
puts ans


def check_lucky(num)
	for char in num.split('')
		if char != '4' && char != '7'
			return false
		end
	end
	return true
end

n = gets.to_i
a = gets.chomp

if check_lucky(a) && a.split('').map(&:to_i).slice(0,n/2).sum == a.split('').map(&:to_i).slice(n/2,n).sum
	puts "YES"
else
	puts "NO"
end


input = Array.new
while i = $stdin.gets
  input << i.strip
end

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

if k % 2 == 1
  puts 1
else
  pow_of_two = 0
  while k >= 2 do
    break if k % 2 == 1
    k = k / 2
    pow_of_two += 1
  end
  puts pow_of_two + 1
end


length, index = gets.split.map(&:to_i)
ans = 1

while((index%2)==0)
  ans += 1
  index /= 2
end
puts ans


n, k = gets.chomp.split(" ").map(&:to_i)
ans = 1;(ans +=1; k/=2;) while(k%2==0);
p ans


#!/usr/bin/env ruby

xval = gets.to_i
n = 1
catch(:found) do
  loop do
    field = Array.new(n){Array.new(n, false)}
    cnt = 0
    (1..(n+1)/2).each do |y|
      neigh_y = n-y+1
      next if (y-neigh_y).abs == 1
      (1..(n+1)/2).each do |x|
        neigh_x = n-x+1
        next if (x-neigh_x).abs == 1
        next if (x-1 >= 1 && field[x-1-1][y-1]) || (y-1 >= 1 && field[x-1][y-1-1])

        tmp = nil
        if neigh_x != x && neigh_y != y
          tmp = 4
        elsif neigh_x == x && neigh_y == y
          tmp = 1
        else
          tmp = 2
        end
        #puts "#{x} #{y} #{tmp}" if n == 5
        if cnt+tmp == xval
          throw :found
        elsif cnt+tmp < xval
          cnt += tmp
          field[x-1][y-1] = true
        end
      end
    end
    n += 1
  end
end

p n


s = gets.chomp.to_i
ar = gets.chomp.split.map {|x| x.to_i}
min = []

unless ar.size != s
	(0...ar.size).each do |n|
		if ar[n] != ar.first and ar[n] != ar.last
			comb = (ar - [ar[n]])
			m = []
			(1...comb.size).each do |c|
				if comb[c] != comb.first
					#puts "#{comb[c]} - #{comb[c-1]} = #{(comb[c] - comb[c-1])}"
					m << (comb[c] - comb[c-1])
				end
			end
			min << m.max
		end
		#if ar[n] == ar.first then puts ar.first end
	end
	p min.min
end


n = gets.to_i

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

res = a[n-1] - a[0]

for i in 1..n-2
    mx = 0
    for j in 1..n-1
        if j == i
            next
        elsif j - 1 == i
            mx = a[j] - a[j-2] if a[j] - a[j-2] > mx
        else
            mx = a[j] - a[j-1] if a[j] - a[j-1] > mx
        end
    end
    res = mx if mx < res
end

puts res


n = gets.chomp.to_i;
arr = gets.chomp.split.map(&:to_i);
max = 0;
ans = 0x7fffffff;

(1...n).each {|i| max = [max, arr[i] - arr[i - 1]].max};
(2...n).each {|i| ans = [ans, [max, arr[i] - arr[i - 2]].max].min};
p ans;


def same(pos, p)
  4.times do | i |
    if pos[i] == p then return i end
    if pos[i] == (p[2..3] + p[0..1]) then return i end
  end
  return -1
end
def solve(pos , xmin, xmax, ymin, ymax)
  ans = Array.new
  ans[0] = same(pos, [xmin, ymin, xmin, ymax])
  ans[1] = same(pos, [xmin, ymin, xmax, ymin])
  ans[2] = same(pos, [xmin, ymax, xmax, ymax])
  ans[3] = same(pos, [xmax, ymin, xmax, ymax])
#  p ans
  ans.sort!
  4.times do |i|
    if ans[i] != i then return false end
  end
  return true
end
xmin = 1000000000
ymin = 1000000000
xmax = -1000000000
ymax = -1000000000
pos = Array.new
4.times do
  data = gets.split.map(&:to_i)
  pos.push(data)
  if xmin > data[0] then xmin = data[0] end
  if xmin > data[2] then xmin = data[2] end
  if xmax < data[0] then xmax = data[0] end
  if xmax < data[2] then xmax = data[2] end
  if ymin > data[1] then ymin = data[1] end
  if ymin > data[3] then ymin = data[3] end
  if ymax < data[1] then ymax = data[1] end
  if ymax < data[3] then ymax = data[3] end
end

if solve(pos, xmin, xmax, ymin, ymax) then
  puts "YES"
else
  puts "NO"
end


def solve?
    rec = []
    hen,shu = 0,0
    xx,yy = [],[]
    4.times{
        x1,y1,x2,y2 = gets.split.map(&:to_i)
        if x1 == x2 then
            shu += 1
            xx << x1
        end
        if y1 == y2 then
            hen += 1
            yy << y1
        end
        rec << [x1,y1,x2,y2]
    }
    return false if shu != 2 || hen != 2 || xx[0] == xx[1] || yy[0] == yy[1]
    4.times do |i|
        return false if rec[i][0] == rec[i][2] &&\
        (![rec[i][1],rec[i][3]].include?(yy[0]) ||\
        ![rec[i][1],rec[i][3]].include?(yy[1]))
        return false if rec[i][1] == rec[i][3] &&\
        (![rec[i][0],rec[i][2]].include?(xx[0]) ||\
        ![rec[i][0],rec[i][2]].include?(xx[1]))
    end
    return true
end

puts solve? ? 'YES' : 'NO'


=begin
          ,     \    /      ,
         / \    )\__/(     / \
        /   \  (_\  /_)   /   \
   ____/_____\__\@  @/___/_____\____
  |             |\../|              |
  |              \VV/               |
  |        ------hoi-------         |
  |_________________________________|
   |    /\ /      \\       \ /\    |
   |  /   V        ))       V   \  |
   |/     `       //        '     \|
   `              V                '
=end

require 'set'

vertices = Set.new
segments = Set.new
horizontal, vertical = 0, 0
rectangle = true
4.times do
	x1, y1, x2, y2 = gets.split.map(&:to_i)
	segments << [x1, y1, x2, y2]
	if x1 == x2
		vertical += 1
	elsif y1 == y2
		horizontal += 1
	else
		horizontal, vertical = -1, -1
		break
	end
	vertices << [x1, y1] and vertices << [x2, y2]
end

if vertices.size == 4 && segments.size == 4 && horizontal == 2 && vertical == 2
    puts "YES";
else
    puts "NO";
end


j, count = 0, 0
n = gets.chomp.to_i
s = 0
if n==1
  puts n
else
  for i in 1..n
    j+=i
    s+=j
    break if s>n
    count+=1
  end
  puts count
end


cubes = gets.chomp.to_i
max_height = 0
cube_height = [0, 0]

for num in 1...10000
    cube_height[num] = num + cube_height[num-1]
    cubes -= cube_height[num]
    if cubes >= 0
        max_height += 1
    else
        break
    end
end

puts max_height


n = gets.to_i
i=1;s=1;s1=1
while s1<=n
    i+=1
    s+=i
    s1+=s
end
puts i-1


n, k = gets.split.map(&:to_i)
k.times do
  if n % 10 == 0
    n /= 10
  else
    n -= 1
  end
end
puts n


first = gets.chomp.split(" ")

number = first[0].to_i
n = first[1].to_i

for i in (1...n+1)
  if number%10 == 0
    number /= 10
  else
    number -= 1
  end
end

puts number


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

k.times do
  if n % 10 == 0
    n /= 10
  else
    n -= 1
  end
end
puts n


gets
h={}
gets.split.map(&:to_i).each{|e| h[e] ? h[e]+=1 : h[e]=1}
f=->(n){n*(n+1)/2}
res=0
x=10**9*2
h.sort.reverse.each{|k,v|
    a=f[x=[k, x].min]
    b=f[[x-v, 0].max]
    res+=a-b
    x=[x-v, 0].max
}
puts res


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

as.sort!.reverse!
b = as[0]
as.each do |a|
  ans += [a, b].min
  b = [[a - 1, b - 1].min, 0].max
end

puts ans


gets
a=gets.split.map &:to_i
h = {}
a.sort.each{|x|
  x -= 1 while h[x]
  h[x] = true
}
p h.map{|k,v|[k,0].max}.inject :+


vp = gets.to_f
vd = gets.to_f
t = gets.to_f
f = gets.to_f
c = gets.to_f

dist = vp * t
count = 0
while (dist + 0.0000000000001) < c
  catch = (dist / (vd - vp)) * vd
  if (catch + 0.0000000000001) >= c
    break
  else
    count += 1
	dist = catch + (((catch / vd) + f) * vp)
  end
end

if(vd > vp)
  puts count
 else
  puts 0
 end


def escape
  vp, vd, t, f, c = 5.times.map{gets.to_f}
  d, b = vp * t, 0

  if vd > vp
    while true
      d += d / (vd - vp) * vp

      break if d >= c

      d += (d / vd + f) * vp
      b += 1
    end
  end

  puts b
end

escape


vp = gets.to_f
vd = gets.to_f
t = gets.to_f
f = gets.to_f
c = gets.to_f

if vp >= vd
    dem = 0
else
    mile = c/vp
    dem = 0
    T = []
    T[dem] = t*vp/(vd-vp)

    while t < mile do
        t += T[dem]
        if t < mile
            t += T[dem] + f
            dem += 1
            T[dem] = t*vp/(vd-vp)
        end
    end
end

puts dem


$n, $k = gets.split.map(&:to_i)
def calc(v)
  base = $k
  sum = v
  t = v / base
  while t > 0
    sum += t
    base *= $k
    t = v / base
  end
  sum
end

def binary_search(l, r)
  return l if l > r
  m = (l + r) / 2
  t = calc(m)
  if t > $n
    return binary_search(l, m-1)
  elsif t < $n
    return binary_search(m+1, r)
  else
    return m
  end
end

puts binary_search(1, $n)


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

def line(v)
	ret=v
	m=$k
	31.times{
		ret+=v/m
		m*=$k
	}
	ret
end

def bin_search(l,r)
	return -1 if l>r
	if l==r
		return line(l)<$n ? -1 : l
	end
	m=(l+r)/2
	lines=line(m)
	if lines<$n
		return bin_search(m+1,r)
	else
		bs=bin_search(l,m-1)
		return bs==-1 ? m : bs
	end
end

p bin_search(1,10**9)


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

def search n,h,k
  i = 0
  s = 0
  loop do
    return false if h.zero?
    s += h
    return true if s >= n
    h /= k
  end
end
l = 1
u = n
h = (l+u)/2
loop do
  if search n,h,k
    u = h
  else
    l = h
  end
  break if u-l < 5
  h = (l+u)/2
end
l.upto u do |h|
  if search n,h,k
    p h
    break
  end
end


def run
  m, n = $stdin.gets.split.map(&:to_i)
  b = $stdin.gets.split.map(&:to_i)
  # a = [nil] * m
  a = []
  b.each_with_index do |v, i|
    v.upto(m) do |j|
      a[j - 1] = v unless a[j - 1]
    end
  end
  puts a.join(" ")
end

run if $0 == __FILE__


n, m = gets.chomp.split(/\s+/).map(&:to_i)
b = gets.chomp.split(/\s+/).map(&:to_i)
n.times do |i|
    print b.select{ |t| (t - 1) <= i }.first
    print " "
end


n, m = gets.split(' ').map {|x| x.to_i}
arr_true = Array.new(n, 0)
arr = Array.new
arr = gets.split(' ').map {|x| x.to_i}
for i in 0..m-1
	for j in arr[i]..n
		if (arr_true[j-1] == 0)
			arr_true[j-1] = arr[i]
		end
	end
end

arr_true.each do |x|
	print (x)
	print (' ')
end


count = gets.to_i
word = gets.downcase.chomp
if count < 26
    puts 'NO'
else
    mas = Array.new(26) { |i| 0 }
    word.each_char{ |i| mas[i.ord - 97] = 1 }
    puts mas.inject(0){ |result, elem| result + elem} == 26 ? "YES" : "NO"
end


a,b=gets.split.map &:to_i
p (1..[a,b].min).reduce :*


t, a, b = gets.split(" ").map &:to_i
gcab = a.gcd(b)
nok = a * b / gcab
noks = t / nok
tmk = t - nok * noks
minab = [a,b].min
ans = (noks+1) * minab - 1 - [0, minab - 1 - tmk].max
gc = ans.gcd(t)
puts "#{ans/gc}/#{t/gc}"


#! /usr/bin/env ruby

t,w,b = $stdin.gets.split.map {|v| v.to_i}

lcm = w.lcm(b)
cnt = (t / lcm) * [w,b].min
cnt += [w, b, t % lcm + 1].min
cnt -= 1    # L = 0 doesn't count

tmp = t.gcd(cnt)
puts "#{cnt/tmp}/#{t/tmp}"


t, w, b = gets.split(" ").map &:to_i
x = [w, b].min * (t / w.lcm(b)) + ([w, b, 1 + t - t / w.lcm(b) * w.lcm(b)].min - 1)
y = t
puts Rational(x, y)


s = gets.strip

upc = s.scan(/[A-Z]/).size
downc = s.scan(/[a-z]/).size

puts s.upcase if upc > downc
puts s.downcase if upc <= downc


s = gets
if s.scan(/[a-z]/).size >= s.scan(/[A-Z]/).size
	puts s.downcase
else
	puts s.upcase
end


puts (gets.scan(/[A-Z]/).size>$_.scan(/[a-z]/).size)?$_.upcase : $_.downcase


#!/usr/bin/ruby

x, y, z = STDIN.readline.split.collect {|s| s.to_i }
a = (x*z/y)**0.5
b = x/a
c = z/a
puts 4*(a + b + c).to_i


s1, s2, s3 = gets.chomp.split.map { |x| x.to_i }
puts 4*(Math.sqrt(s1*s2/s3) + Math.sqrt(s1*s3/s2) + Math.sqrt(s2*s3/s1)).to_i


include Math

def calculate(s1, s2, s3)
  a = sqrt(s1*s3/s2).round
  b = sqrt(s1*s2/s3).round
  c = sqrt(s2*s3/s1).round

  puts 4*(a+b+c)
end

n,m,p = gets.chomp.split(/\s/).map(&:to_i)
calculate(n,m,p)


n,m=gets.split.map(&:to_i)
a=gets.split.map(&:to_i).reverse
o=0
while !a.empty?
	d=m
	while !a.empty?&&d>=a[-1]
		d-=a.pop
	end
	o+=1
end
p o


#!/usr/bin/ruby
n,m=gets.split.map(&:to_i)
r=0
x=0
gets.split.map(&:to_i).each{|e|
	if x<e
		r+=1
		x=m
	end
	x-=e
}
p r


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

_, m = read_next_line
count, bus = [1, 0]
read_next_line.each { |x|
  bus += x
  if bus > m
    bus = x
    count += 1
  end
}
puts count


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

if k<=n
  ans = k/2
  ans -= 1 if k%2==0
  puts ans
else
  mp = k/2
  ans = n-mp
  # ans -= 1 if k%2==0
  puts [0,ans].max
end


n, k=gets.split.map &:to_i
if n+n-1<k
    puts 0
elsif n<k
    puts (n+n-k+(n+n-k)%2)/2
else
    puts (k-(1-k%2))/2
end


N, K = gets.split.map(&:to_i)
ans = [N, K-1].min - K/2
puts [ans, 0].max


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

def calc(n, arr)
  i = 0
  while i < n
    if arr[i] == 'B' and arr[i+1] == 'G'
      t = arr[i]
      arr[i] = arr[i+1]
      arr[i+1] = t
      i += 1
    end
    i += 1
    # p arr
  end

  arr
end

t.times.each do
  arr = calc(n, arr)
end

puts arr.join('')


$stdin = File.open("./input.txt", "r") if ENV["USER"] == "new"
# ====================================

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

t.times do
  start_index = 0

  while start_index + 1 < queue.length do
    if queue[start_index] == "B" && queue[start_index+1] == "G" then
      queue[start_index] = "G"
      queue[start_index + 1] = "B"
      start_index += 2
      next
    end

    start_index += 1
  end
end

print queue


n,t = gets.split(' ').map(&:to_i)
a = gets.chomp
t.times{a.gsub!("BG","GB")}
puts a


n=gets(' ').to_i
t=gets.to_i

s=gets.chomp

t.times {

kolejka=[]

for i in 0..s.length-2
if ( s[i] == ?B ) && ( s[i+1] == ?G )
kolejka.push i
end
end

for i in kolejka
s[i]=?G
s[i+1]=?B
end

}

print s
print "\n"


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

t.times do
	i = 0
	while i < s.length-1
		if s[i] == 'B' && s[i+1] == 'G'
			s[i],s[i+1] = s[i+1],s[i]
			i += 2
		else
			i += 1
		end
	end
end

puts s


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

t.times do
  i = 0
  while i <= n-2 do
    if s[i] == 'B' && s[i+1] == 'G'
      s[i] = 'G'
      s[i+1] = 'B'
      i += 2
      next
    end
    i += 1
  end
end
puts s


n, t = STDIN.readline.split(' ').map(&:to_i)
q = STDIN.readline.chomp.chars.to_a

def boy?(c)
  c == 'B'
end

def girl?(c)
  c == 'G'
end

def swap(qu)
  i = 0
  while i < qu.size
    if boy?(qu[i]) && girl?(qu[i+1])
      tmp = qu[i]
      qu[i] = qu[i+1]
      qu[i+1] = tmp
      i += 1
    end
    i += 1
  end
end

t.times do
  swap(q)
end

puts q.join('')


n, t = gets.split.map &:to_i
q = gets.split(//)
t.times do
  i = 0
  while (i <= n-2) do
    if q[i] == 'B' && q[i+1] == 'G'
      q[i] = 'G'
      q[i+1] = 'B'
      i+=2
    else
      i+=1
    end
  end
  #puts q.join
end

puts q.join


t = gets.split.collect{|x| x.to_i}
n,k = t[0], t[1]
s = gets.strip.chars.to_a

k.times do |i|
	t = Array.new s

	s.each_index do |j|
		if j > 0 and s[j-1] == 'B' and s[j] == 'G'
			t[j-1], t[j] = 'G', 'B'
		end
	end
	s = Array.new t
end

puts s.join


n, t = gets.chomp.split(' ').map {|x| x.to_i}
s = gets.chomp
t.times do
  i = 0
  while i < n
    if s[i] == 'B' && s[i+1] == 'G'
      s[i], s[i+1] = s[i+1], s[i]
      i += 1
    end
    i += 1
  end
end
puts s


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

counter = 0
for j in 0..n-1
 i = 0
 while i < n
   if co[i+1]=="G" && co[i]=="B"
     co[i],co[i+1] = co[i+1],co[i]
     i+=1
   end
   i+=1
 end
  counter+=1
  break if counter == t
end

puts co.join('')


BEGIN{
	def gint()
		return gets.split.map(&:to_i)
	end
	def main()
		n, t = gint
		s = gets.to_s
		t.times do |item|
			i = 0
			while i <= s.length - 2 do
				c = s[i]
				if c == 'B' && s[i + 1] == 'G' then
					s[i] = "G"
					s[i + 1] = "B"
					i += 1
				end
				i += 1
			end
		end
		puts s
	end
	Test_case = 1
	Test_case.times do
		main()
	end
}


a,b=gets.split.map{|e| e.to_i}
c=gets.chomp

b.times{
	p=0
	while p<c.size-1
		if c[p]=='B' && c[p+1]=='G' then
			c[p]='G'
			c[p+1]='B'
			p=p+2
		else
			p=p+1
		end
	end
}
puts c


line_length, time = gets.strip.split(' ').map &:to_i
line = gets.strip.upcase.split('')

1.upto(time).each do |_|
  runner = line.length - 1
  # The first one at the line cannot be swap anywhere
  while runner > 0
    if line[runner] == 'G' && line[runner-1] == 'B'
      line[runner], line[runner-1] = line[runner-1], line[runner]
      runner -= 1
    end
    runner -= 1
  end
end

puts line.join


n, t = gets.split.map(&:to_i)
s = gets.strip
t.times do
	s.gsub!("BG","GB")
end
puts s


input = gets.chomp
nums = input.split
n = Integer(nums[0])
t = Integer(nums[1])
s = Array.new
s = gets.chomp

j = 0
for j in 0...t
    if j < t
        a = Array.new
        for i in 0...n
            if s[i] == "B" && s[i + 1] == "G"
                a.push(i)
            end
        end
        for i in 0...a.length
            s[a[i]] = "G"
            s[a[i] + 1] = "B"
        end
        j += 1
    end

end

print s


n, t = gets.strip.split.map(&:to_i)
s = gets.strip
t.times do |j|
  s2 = s.clone
  s.length.times do |i|
    if i < s.length - 1 && s[i] == "B" && s[i + 1] == "G"
      s2[i] = "G"
      s2[i + 1] = "B"
    end
  end
  s = s2.clone
end
puts s


n, t = gets.split(' ').map(&:to_i)
ar = gets
t.times do
  ar = ar.split(/(?=BG)/).map{|x| x.sub(/BG/,"GB")}.join
end
puts ar


n,t = gets.split(" ").map(&:to_i)
q = gets
t.times{
	i=0
	while i<n do
		if q[i] == 'B' && q[i+1] == 'G' then
			q[i] = 'G'
			q[i+1] = 'B'
			i=i+1
		end
		i=i+1
	end
}
puts q


input_data = gets.chomp.split
queue = gets.chomp
input_data = input_data.map{|e| e.to_i }
i = 0
while i < input_data[1]
  j = 0
  while j < queue.length
    if queue[j] == "B" && queue[j+1] == "G" then
      queue[j], queue[j+1] = queue[j+1], queue[j]
      j = j+1
    end
    j = j+1
  end
  i = i+1
end
print queue


#!/usr/bin/ruby1.9

n, t = STDIN.readline.split.collect {|s| s.to_i }
line = STDIN.readline.strip
chars = line.split('')
t.times do
	new_chars = []
	i = n-1
	while i >= 0 do
		if chars[i] == 'G' and i-1 >= 0 and chars[i-1] == 'B'
			new_chars.insert(0, 'B')
			new_chars.insert(0, 'G')
			i -= 2
		else
			new_chars.insert(0, chars[i])
			i -= 1
		end
	end
	chars = new_chars
end
puts chars.join('')


n, t = gets.split.map(&:to_i)
s = gets.to_s.chomp
for i in 1..t do
    i = 0
	while i < n-1 do
		if s[i] == 'B' and s[i+1] == 'G' then
			s[i], s[i+1] = s[i+1], s[i]
			i += 2
		else
			i += 1
		end
	end
end
puts s


n, t = gets.chomp.split
present_queue = gets.chomp

g_indexs = []

t.to_i.times do
  (0...(n.to_i)).each do |i|
    if i != 0
      if present_queue[i] == 'G' && present_queue[i - 1] == 'B'
        g_indexs << i
      end
    end
  end

  g_indexs.each do |i|
    present_queue[i], present_queue[i - 1] = present_queue[i - 1], present_queue[i]
  end

  g_indexs = []
end

puts "#{present_queue}"


n, t = gets.split.map{ |e| e.to_i}
q = gets.chomp

for i in 1..t
  q += ' '
  s = q.split('BG')
  q = s[0]
  for i in 1..s.size-1
    q += 'GB' + s[i]
  end
end

puts q


childrens, time = gets.split(' ').map(&:to_i)
queue = gets.chomp

time.times do
  i = 0
  while i < (queue.length - 1) do
    if queue[i] == 'B' && queue[i + 1] == 'G'
      queue[i], queue[i + 1] =  queue[i + 1], queue[i]
      i = i + 1
    end
    i = i + 1
  end
end

puts queue


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

t.times do
  i = 0
  while i < s.size-1 do
    if s[i] + s[i+1] == "BG"
      s[i] = "G"
      s[i+1] = "B"
      i += 1
    end
    i += 1
  end
end

puts s


n, t = gets.split(" ").map(&:to_i)
arr = gets.split("")
length = arr.length
(1..t).each do |i_t|
  index = 0
  while index < (length-1) do
    if arr[index] == 'B' && arr[index +1] == 'G'
      arr[index + 1] = 'B'
      arr[index] = 'G'
      index += 1
    end
    index += 1
  end
end
puts arr.join("")


BEGIN{
	def gint()
		return gets.split.map(&:to_i)
	end
	def main()
		n, t = gint
		s = gets.to_s
		l = s.length - 1
		t.times do |item|
			flag = false
			(0..l).each do |i|
				if flag then
					flag = false
					next
				end
				if s[i] == 'B' and s[i + 1] == 'G' then
					s[i], s[i + 1] = s[i + 1], s[i]
					flag = true
				end
			end
		end
		puts s
	end
	Test_case = 1
	Test_case.times do
		main()
	end
}


n, s = gets.split.map &:to_i
q = gets
s.times { q.gsub!("BG", "GB") }
puts q


# cook your code here

n,t = gets.chomp.split
n = n.to_i
t = t.to_i

q = gets

for j in 0...t
    i=0
    while i < n-1
        if(q[i]=='B' and q[i+1]=='G')
            q[i],q[i+1]=q[i+1],q[i]
            #puts q + i.to_s
            i+=1
        end
        i+=1
    end
end

puts q


#!/usr/bin/ruby1.9

n, t = STDIN.readline.split.collect {|s| s.to_i }
line = STDIN.readline.strip
chars = line.split('').reverse
t.times do
	new_chars = []
	i = 0
	while i < n do
		if chars[i] == 'G' and i+1 < n and chars[i+1] == 'B'
			new_chars.push('B')
			new_chars.push('G')
			i += 2
		else
			new_chars.push(chars[i])
			i += 1
		end
	end
	chars = new_chars
end
puts chars.reverse.join('')


def switch(a, n)
  b = Array.new(n)
  n.times do |i|
    if a[i] == "B" && a[i + 1] == "G"
      b[i] = "G"
      b[i + 1] = "B"
    elsif b[i] == nil
      b[i] = a[i]
    end
  end
  b
end
n, t = gets.split.map(&:to_i)
a = gets.chomp.chars
t.times do
  a = switch(a, n)
end
puts a.join("")


n, t = gets.chomp.split.map &:to_i
f = gets.chomp
t.times do |i|
    f.gsub!(/BG/) { |x| 'GB' }
end
puts f


a = gets.split(' ')[1].to_i
s = gets

a.times do
  s.gsub!(/BG/, 'GB')
end
puts s


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

t.times do
  s.gsub!(/BG/, 'GB')
end

puts s


childrens, time = gets.split(' ').map(&:to_i)
queue = gets.chomp

time.times do
  queue.gsub!(/BG/, 'GB')
end

puts queue


nt=gets.split(' ')
s=gets.split('')

@n = nt[0].to_i
t = nt[1].to_i

def menyaem(str)
	j = 0
	@n.times do
		break if j >= @n
		if str[j] == 'B' && str[j+1] == 'G'
			str[j] = 'G'
			str[j+1] = 'B'
			j += 2
		else
			j += 1
		end
	end
	return str
end

t.times do |i|
	s = menyaem(s)
end

puts s.join('')


n, t = $stdin.readline.split.map(&:to_i)
q = $stdin.readline.scan(/./)

k = 0
while k<t
    j = 0
    qq = Array.new(q.count)
    while j<q.count
        if j<q.count-1 && (q[j]=="B" && q[j+1]=="G")
            qq[j], qq[j+1] = "G", "B"
            j += 2
        else
            qq[j]= q[j]
            j += 1
        end
    end
    q = qq
    k+=1
end

puts q.join('')


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

t.times do
	i = 0
	while i < s.length-1
		if s[i] == 'B' && s[i+1] == 'G'
			s[i],s[i+1] = s[i+1],s[i]
			i += 2
		else
			i += 1
		end
	end
end
#
puts s


t = gets.split[1].to_i
input = gets.split(//)
for i in 1..t
  j = 0
  while j < input.size-1
    if input[j] == "B" and input[j+1] == "G"
      input[j], input[j+1] = input[j+1], input[j]
      j += 1
    end
    j += 1
  end
end
puts input.join


n, t = gets.split(' ').map(&:to_i)
ar = gets
t.times do
  ar = ar.scan(/BG|.*?(?=BG)|.+/).map{|x| x=~/BG/?"GB":x}.join
end
puts ar


n, i = gets.split
str = gets.chomp
i.to_i.times { str.gsub!(/BG/,'GB') }
puts str


a=gets.chomp.split(" ")
len=a[0].to_i
time=a[1].to_i
b=gets.chomp.split("")

(time).times do
i=0
c=b.join
loop do
	p=0
    if (b[i]=="B" && b[i+1]=="G")
        b[i]="G"
        b[i+1]="B"
		p=1
    end
	if p==1
    i+=2
	else
	i+=1
	end

    break if i>=len
end
end
puts "#{b.join}"


def run
  n, t = ARGF.readline.chomp.split.map(&:to_i)
  s = ARGF.readline.chomp
  l = s.length

  t.times do
    ns = []
    i = 0
    while i < l
      if i < l - 1 and s[i] == 'B' and s[i + 1] == 'G'
        ns[i] = 'G'
        ns[i + 1] = 'B'
        i += 1
      else
        ns[i] = s[i]
      end

      i += 1
    end
    s = ns.join("")
  end

  puts s
end

run if $0 == __FILE__


n, t = gets.chomp.split(/ /).map(&:to_i)
line = gets.chomp
(1..t).each do |time|
    student = 0
    while student <= n
        first = line[student]
        nxt = line[student + 1]
        if nxt == 'G' && first == 'B'
            line[student + 1] = 'B'
            line[student] = 'G'
            student += 2
            next
        end
        student += 1
    end
end
puts line


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

while t > 0 do
    i = 0
    while i < n-1 do
        if initial[i] == "B" && initial[i+1] == "G"
            initial[i] = "G"
            initial[i+1] = "B"
            i += 2
        else
            i += 1
        end
    end
    t -= 1
end
print initial


n,t=gets.chomp.split.map(&:to_i)
s=gets.chomp
t.times do
	i=n-1
	while i>0
		if s[i]=='G' && s[i-1]=='B'
			s[i]='B'
			s[i-1]='G'
			i-=1
		end
		i-=1
	end
end
puts s


buf=gets.split(" ")
n,k=buf[0].to_i,buf[1].to_i
n-=1
ans=0
while n>0&&k>0
	ans+=n*2-1
	n-=2
	k-=1
end
puts ans


n=gets
n.chomp!
memo=[]
n.length.times do |i|
  memo << n[i].to_i
end
memo.sort!
if memo[0] == 0
  j=0
  while memo[j]==0
    j+=1
  end
  if j!=memo.length
    memo[0],memo[j]=memo[j],memo[0]
  end
end
t=gets
t.chomp!
memo2=[]
t.length.times do |i|
  memo2 << t[i].to_i
end
if memo2 == memo
  puts "OK"
else
  puts "WRONG_ANSWER"
end


count=0;str=''
a = gets().chomp().split("").each {|x| (x=='0') ? count+=1 : x.to_i }
a.sort!{|x,y| x<=>y}
if (count!=0); str=""+a[count].to_s;a.delete(a[count]) end
a.each {|x| str+=x.to_s}
b=gets().chomp()
if(str==b)
  print 'OK'
else print 'WRONG_ANSWER'
end


n = gets.chomp.to_s
m = gets.chomp.to_s
index = 0
if m.length != n.length
  puts "WRONG_ANSWER"
else
  n = n.chars.sort.join
  if n[0] == "0"
    for i in 0...n.length
      if n[i] > "0"
        inicio = n.index(n[i])
        fin = n.rindex(n[i])
        alta = n[inicio+1..n.length]
        baja = n[0..inicio-1]
        n = n[inicio..fin] + baja + alta
        break
      end
    end
  end
  if m == n
    puts "OK"
  else
    puts "WRONG_ANSWER"
  end
end


s = gets.chomp.split('')
x = 'a'
c = 0
s.each do |y|
  v = (y.ord - x.ord).abs
  v = 26 - v if v > 13
  c += v
  x = y
end
puts c


s = gets.strip
count = 0
current = 'a'
(0...s.length).each do |i|
    clockwise = current.ord - s[i].ord
    counterclock = s[i].ord - current.ord
    clockwise = 26 + clockwise if clockwise < 0
    counterclock = 26 + counterclock if counterclock < 0
    min_count = [clockwise, counterclock].min
    count += min_count
    current = s[i]
end
puts count


s = gets.strip

mp = {}
(0..25).each do |i|
  mp[('a'.ord + i).chr] = i
end

cnt = 0
curr = 'a'
s.split('').each do |l|
  i = mp[curr]
  j = mp[curr]
  while(1)
    if i == mp[l] || j == mp[l]
      break
    end
    i -= 1
    j += 1
    j = 0 if j >= 26
    i = 25 if i < 0
  end
  if (mp[curr] - i).abs < (mp[curr] - j).abs
    cnt += (mp[curr] - i).abs
  else
    cnt += (mp[curr] - j).abs
  end

  curr = l

end

printf("%d\n", cnt)


x,y,a,b=gets.split.map(&:to_i)
q=x.lcm y
p b/q-(a-1)/q


input = gets.split(" ").map {|e| e.to_i}
x = input[0]
y = input[1]
a = input[2]
b = input[3]

div = x.lcm(y)
puts (b / (div) - (a.to_f / (div).to_f).ceil + 1)


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

if n%2==0
    if k <= n/2
        puts 2*(k-1)+1
    else
        k -= n/2
        puts 2*(k)
    end
else
    if k <= n/2+1
        puts 2*(k-1)+1
    else
        k -= n/2+1
        puts 2*(k)
    end
end


require "date"

m = Date.new(*gets.split(":").map(&:to_i))
n = Date.new(*gets.split(":").map(&:to_i))

p (n - m).to_i.abs


require 'date'
puts (Date.parse(gets.gsub(":","-"))-Date.parse(gets.gsub(":","-"))).to_i.abs


#!/usr/bin/env ruby

require 'date'
puts (Date.parse(gets.gsub(':','-')).ld - Date.parse(gets.gsub(':','-')).ld).abs


#!/usr/bin/env ruby
#codeforces.com/problemset/problem/16/C

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

a = input[0]
b = input[1]
x = input[2]
y = input[3]

def gcd(a1, b1)
  b1 == 0 ? a1 : gcd(b1, a1.modulo(b1))
end

gcdd = gcd(x,y)
x = x/gcdd
y = y/gcdd

multiply = [a/x, b/y].min

puts (x*multiply).to_s + " " +(y*multiply).to_s


a,b,x,y=gets.split.map(&:to_i)
x,y=x/x.gcd(y),y/x.gcd(y)
sc=(1..2*10**9).bsearch{|i| i*x > a || i*y > b}-1
print(x*sc, " ", y*sc, "\n")


#!/usr/bin/ruby

primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]

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

puts primes.include?( m ) && primes.index(m) == primes.index(n)+1 ? "YES" : "NO"


gets
p gets.split.uniq.delete_if{|x| x == "0"}.size


n = gets.to_i
a = gets.split.map &:to_i
puts a.uniq.size - (a.any? { |x| x == 0 } ? 1 : 0)


gets
a = gets.split(' ').map! {|x| x.to_i} << 0
a.unshift(0)
ans = 0

a.size.times do |i|
    ans += 1 if (a[i] == 1.to_i) || ((a[i - 1] == 1) && (a[i + 1] == 1))
end

p ans


n = gets.to_i
v = gets.split.map(&:to_i)
cont = 0
sw = 0
c = 0
for i in(0..(n-1))
    if v[i] == 1
        sw = 1
    end
    if sw == 1
        if(v[i]==0)
            c+=1
        elsif c < 2
            cont=cont+1+c
            c=0
        else
            cont+=1
            c=0
        end
    end
end
p cont


n, pairs = gets.chomp.to_i, gets.chomp.split(" ").join("")
pairs.gsub! /(^0+|00+|0+$)/, ""
puts pairs.length


require 'date'
a, b = 2.times.map{gets.split('.').map(&:to_i).reverse}
a[0] += 2000
puts b.permutation.map{|c|
	c[0] += 2000
	begin
		Date.new(*a) >= Date.new(*c).next_year(18)
	rescue ArgumentError
		nil
	end
}.any? ? :YES : :NO


require 'date'
a, b = 2.times.map{gets.split('.').map(&:to_i).reverse}
a[0] += 2000
puts b.permutation.map{|c|
 c[0] += 2000
 begin
  Date.new(*a) >= Date.new(*c).next_year(18)
 rescue ArgumentError
  nil
 end
}.any? ? :YES : :NO


a=gets.chomp.to_i
b=gets.chomp.to_i
c=gets.chomp.to_i
d=gets.chomp.to_i
e=gets.chomp.to_i
k=a.lcm(b)
l=a.lcm(c)
m=a.lcm(d)
i=b.lcm(c)
n=b.lcm(d)
j=c.lcm(d)
g=[a,b,c].reduce(:lcm)
h=[a,b,d].reduce(:lcm)
o=[a,d,c].reduce(:lcm)
p=[d,b,c].reduce(:lcm)
q=[a,b,c,d].reduce(:lcm)

f=(e/a)+(e/b)+(e/c)+(e/d)-e/k-e/l-e/m-e/i-e/n-e/j+e/g+e/h+e/o+e/p-e/q
puts "#{f}"


k = gets.to_f
l = gets.to_f
m = gets.to_f
n = gets.to_f
d = gets.to_i

result = 0
d.times do |i|
  i = i + 1
  result += 1 if i%k == 0 or i%l == 0 or i%m == 0 or i%n == 0
end

puts result


ar = []
4.times {ar << gets.to_i}
n = gets.to_i
puts (1..n).to_a.count{|i| ar.index{|x| i%x == 0}}


x,y=2.times.map{n,a=gets.split.map(&:to_i)
gets.split.map(&:to_i).inject{|x, y|x*=a;x+=y}}
puts'=><'[x<=>y]


x, y = 2.times.map {
  n, b = gets.split.map(&:to_i)
  gets.split.map(&:to_i).inject{|x,y| x *= b ; x+y}
}
puts '<' if x < y
puts '>' if x > y
puts '=' if x == y


x_i=gets.chomp.split(" ")
0.upto(1) {|i| x_i[i]=x_i[i].to_i}
x=gets.chomp.split(" ")
0.upto(x_i[0]-1) {|i| x[i]=x[i].to_i}
y_i=gets.chomp.split(" ")
0.upto(1) {|i| y_i[i]=y_i[i].to_i}
y=gets.chomp.split(" ")
0.upto(y_i[0]-1) {|i| y[i]=y[i].to_i}
y.reverse!
x.reverse!
def Con(a,b)
k=0
0.upto(a.length-1){|i| k=k+(a[i]*(b**i)) }
return k
end
X=Con(x,x_i[1])
Y=Con(y,y_i[1])
d=X<=>Y
if d==0
	puts "="
elsif d==-1
	puts "<"
else
	puts ">"
end


n=gets.to_i
for i in 1..n-1
	print i
	for j in 2..n-1
		print (i*j).to_s(n).rjust(3, ' ')
	end
	puts
end


def min(n, m)
  if n >= m
    n
  else
    (m - n) + n
  end
end

def max(n, m)
  if m > 0
    (m - 1) + n
  else
    n
  end
end

n, m = gets.chomp.split(" ").map{|e| e.to_i}

if n == 0 and m > 0
  puts "Impossible"
else
  puts "#{min(n, m)} #{max(n,m)}"
end


#!/usr/bin/ruby
include Math

data = gets.split.map{ |x| x.to_i}
otona = data[0]
kodomo = data[1]

if otona == 0
  if kodomo != 0 then puts "Impossible" else puts "#{0} #{0}"end
else
  m_max = otona+kodomo
  m_max -= 1 if kodomo > 0
  kodomo -= [otona,kodomo].min
  m_min = otona+kodomo
  puts "#{m_min} #{m_max}"
end


n,m=gets.split.map(&:to_i)
if n==0 && m!=0
  puts "Impossible"
elsif m==0
  puts "#{n} #{n}"
elsif n<m
  puts "#{m} #{n+m-1}"
else
  puts "#{n} #{n+m-1}"
end


c = gets.chomp
cc = gets.chomp.split(' ')
puts(
  cc.any? { |card| card[0] == c[0] || card[1] == c[1] } ? 'YES' : 'NO'
)


a, b = gets.chomp, gets.chomp
bool = {true => "YES", false => "NO" }
puts bool[b.count(a) > 0]


n = gets.chomp.chars
puts [n[0...n.size - 1].join.to_i, (n[0...n.size - 2] + n[n.size - 1..n.size - 1]).join.to_i, n.join.to_i].max


n = gets.chomp.to_i
if n>=0
    puts n
else
    n *= -1
    dig1,dig2 = n%10, (n/10)%10
    n1= n/10
    n1*=-1
    n2 = n1-dig1+dig2
    if n1>n2
        puts n1
    else
        puts n2
    end
end


n = gets.to_i

if n >= 0
  puts n
  exit
end

n *= -1

candidates = []

candidates << n / 10
candidates << n / 100 * 10 + n % 10

puts -candidates.min


all = []
1.upto(9) do |x|
  4.times do |i|
    all << (x.to_s * (i + 1))
  end
end
gets.to_i.times do
  n = gets.chomp
  puts (all.inject(0) do |acc, s|
    acc += s.length
    break acc if s == n
    acc
  end)
end


t = gets.chomp.to_i
t.times do
    x = gets.chomp.split("")
    ookisa = x.size
    count = 0
    if x[0] == "1"
        me = 1 + ookisa
        kazu = ookisa * me
        count += kazu / 2
    else
        mezi = (x[0].to_i - 1) * 10
        me = 1 + ookisa
        kazu = ookisa * me
        count += kazu / 2
        count += mezi
    end
    puts count
end


T = gets.to_i

T.times do
  x = gets.chomp
  d = x[0].to_i

  puts 10 * (d - 1) + (1..x.size).sum
end


PLAYERS = %w[F M S]
RANKS   = %w[rock paper scissors]

def winner?(g1, g2)
  r1 = RANKS.rindex(g1)
  r2 = RANKS.rindex(g2)
  return true  if r1 == 0 and r2 == 2
  return false if r1 == 2 and r2 == 0
  return true  if r1 > r2
  false
end

gestures = []
3.times { gestures << STDIN.gets.chomp }
winners = []

gestures.each_index do |i|
  gestures.each_index do |j|
    g1, g2 = gestures[i], gestures[j]
    next if g1 == g2
    winners << PLAYERS[i] if winner?(g1, g2)
  end
end

puts (winners.uniq.count == 1) ? winners[0] : "?"


#!/usr/bin/ruby

def win?(me, him)
  return true if (me == "rock" && him == "scissors")
  return true if (me == "paper" && him == "rock")
  return true if (me == "scissors" && him == "paper")
  return false
end

f = gets.chomp
m = gets.chomp
s = gets.chomp

if (win?(f, m) && win?(f, s))
  puts "F"
elsif (win?(m, f) && win?(m, s))
  puts "M"
elsif (win?(s, f) && win?(s, m))
  puts "S"
else
  puts "?"
end


n,k,l,c,d,p,nl,np=gets.split.map{|e| e.to_i}

a1=(k*l)/nl
a2=c*d
a3=p/np
puts ([a1,a2,a3].min)/n


arr = gets.chomp.split.map(&:to_i)
array = []
array[0] = (arr[1] * arr[2])/arr[6]
array[1] = arr[3] * arr[4]
array[2] = arr[5] / arr[7]

print array.min / arr[0]


n, k, l, c, d,  p, nl, np = gets.split(' ').map(&:to_i)
x = []
x << k * l / nl
x << c * d
x << p / np
p x.min / n


j=gets.to_i.abs;i=0;j-=i+=1 while j>0||j&1>0;puts i


n=gets.to_i.abs;s=i=0;s+=i+=1 while s<n||(s-n)%2>0;p i


s = gets.chomp

ans = 0
ve = %w(a i u e o 1 3 5 7 9)
s.each_char do |c|
  ans += 1 if  ve.include?(c)
end

puts ans


a = "aoeui13579"
s = gets.chomp
ans = 0;
for i in (0...s.length)
  ans += a.count(s[i])
end
puts ans


n = gets.chomp.to_i
s = gets.chomp

sf = 0
fs = 0
(n-1).times do |i|
	sf += 1 if s[i] == "S" && s[i + 1] == "F"
	fs += 1 if s[i] == "F" && s[i + 1] == "S"
end
puts sf > fs ? "YES" : "NO"


n = gets.to_i
s = gets.chomp
ssf = 0
sfs = 0
(0..n-2).each do |i|
  if s[i] == 'S' && s[i+1] == 'F'
    ssf += 1
  end
  if s[i] == 'F' && s[i+1] == 'S'
    sfs += 1
  end
end
puts ssf > sfs ? 'YES' : 'NO'


n = gets.chomp.to_i
s = gets.chomp

if s[0] == 'S' && s[-1] == 'F'
     puts "YES"
else
     puts "NO"
end


n, k = gets.chomp.split().map { |x| x.to_i }
path = gets.chomp
posT = -1; posG = -1
for i in 0 ... n
    if path[i] == "G"
        posG = i
    elsif path[i] == "T"
        posT = i
    end
    if posG != -1 and posT != -1
        break
    end
end

answer = true
if ( posG - posT ).abs % k != 0
    answer = false
else
    if posG > posT
        posG, posT = posT, posG
    end
    i = posG + k
    while i < posT
        if path[i] == "#"
            answer = false
            break
        end
        i += k
    end
end

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


n,k=gets.split.map{|e| e.to_i}
s=gets.chomp
p1=s.index("G")
p2=s.index("T")

if p1>p2 then
	p1,p2=p2,p1
end

if (p2-p1)%k!=0 then
	puts "NO"
else
	ok="YES"
	p1.step(p2,k){|i|
		ok="NO" if s[i]=="#"
	}
	puts ok
end


n, k = gets.strip.split.map(&:to_i)
path = gets.strip
start = path.index 'G'
target = path.index 'T'
i = start
ans = "NO"
while i < n && ans == "NO"
    i += k
    break if path[i] == '#'
    ans = "YES" if i == target
end
while i >= 0 && ans == "NO"
    i -= k
    break if path[i] == '#'
    ans = "YES" if i == target
end
puts ans


n = gets.chomp.to_i
bills = [100, 20, 10, 5]
sum = 0
bills.each do |b|
	while n >= b
		sum += n / b
		n %= b
		#puts "#{n} #{b}"
	end
end
puts sum + n


#!usr/bin/env ruby

# https://codeforces.com/problemset/problem/996/A

amount = gets.to_i

bills = [100, 20, 10, 5, 1]

answer = 0

bills.each do |bill|
  current_bill_count = amount / bill
  answer += current_bill_count
  amount -= current_bill_count * bill
end

puts answer


cash = gets.to_i
bills = [100,20,10,5,1]
x = 0
t = 0

while cash > 0
    if cash/bills[x] >= 0
        t+=cash/bills[x]
        cash = cash%bills[x]
        x+=1
    end
end

puts t


a, b = gets.strip, gets.strip
puts a.reverse == b ? "YES" : "NO"


string1 = gets.chomp
string2 = gets.chomp
if string1 == string2.reverse then
    puts "YES"
else
    puts "NO"
end


a,b = gets.split.map(&:to_i)
x = [ a , b ].min
y = [ a , b ].max
print  x,' ',(y-x)/2


line = gets.chomp.split(/ /)
res = 0
if line.length == 2
    red_socks = line[0].to_i
    blue_socks = line[1].to_i
    if red_socks > blue_socks
        print blue_socks," "

        res = (red_socks-blue_socks)/2
        puts res
    elsif red_socks < blue_socks
        print red_socks, " "
        res = (blue_socks-red_socks)/2
        puts res
    else
        print red_socks," ", "0"
        print "\n"
    end
end


a, b = gets.split(' ').map(&:to_i).sort

puts "#{a} #{(b-a).div(2)}"


a, b=gets.split.map &:to_i
res=0
while a<=b
    res+=1
    a*=3
    b*=2
end
puts res


l, b = gets.chomp.split.map(&:to_i)
y = 0
until l > b
    l *= 3
    b *= 2
    y += 1
end
puts y


$a = gets
$a,$b = $a.split(' ').to_a
$k = 0
$a = $a.to_i
$b = $b.to_i
until $a > $b
	$a *= 3
	$b *= 2
	$k += 1
end
print $k


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

n, k = read_next_line
a = read_next_line

r = Array.new(k) { Array.new(2, 0) }
(0...n).each { |i|
  r[i % k][a[i] - 1] += 1
}

puts r.inject(0) { |s, x| s + x.min }


def solve arr, k
  one = Array.new(k) {0}
  two = Array.new(k) {0}
  (0...arr.length).each do |i|
    if arr[i] == 1
      one[i % k] += 1
    else
      two[i % k] += 1
    end
  end
  tot = 0
  (0...k).each do |i|
    tot += [one[i], two[i]].min
  end
  tot
end

n, k = STDIN.gets.chomp.split.map {|i| i.to_i}
arr = STDIN.gets.chomp.split.map {|i| i.to_i}

puts solve arr, k


n, k = gets.split.collect{|i| i.to_i}
a = gets.split.collect{|i| i.to_i}
ans = 0
(0...k).each do |i|
    j = 0
    tmp = Array.new
    while i+j < n
        tmp.push(a[i+j])
        j += k
    end
    ans += [tmp.count(1), tmp.count(2)].min
end
puts ans


n = gets.to_i
if n == 3
  print 6
elsif n <= 2
  print n
else
n -= 1 if n%6 == 0
a = n-2
a -= 1 if n%2 == 0
print n*(n-1)*a
end


n = gets.chomp.to_i
if n <= 2
  puts n
elsif n % 6 == 0
  puts (n-1) * (n-2) * (n-3)
elsif n % 2 == 0
  puts n * (n-1) * (n-3)
else
  puts n * (n-1) * (n-2)
end


a, b, c, d = gets.split.map{|i| i.to_i}
puts a > b ? 'First' : 'Second'


n1, n2, k1, k2 = $stdin.readline.split.map(&:to_i)

if n1>n2
    puts "First"
else
    puts "Second"
end


arr = $stdin.readline.split(" ")
n1=  arr[0].to_i
n2 = arr[1].to_i
if (n2 + 1 > n1 )
    puts "Second"
else
    puts "First"
end


n,a,x,b,y = gets.split.map(&:to_i)
flag = false
while a != x && b != y
    a += 1
    a = 1 if a > n
    b -= 1
    b = n if b <= 0
    if a == b
        flag = true
        break
    end
end
if flag
    puts("YES")
else
    puts("NO")
end


n,a,x,b,y = gets.split.map(&:to_i)
f = false
while a != x && b != y
    a += 1
    a = 1 if a > n
    b -= 1
    b = n if b <= 0
    if a == b
        f = true
        break
    end
end
puts (f ? "YES" : "NO")


a=gets
str="qwertyuiopasdfghjkl;zxcvbnm,./"
strk=gets
if a=="R\n"
 for i in 0...strk.size-1
  strk[i]=str[str.index(strk[i])-1]
 end
end
if a=="L\n"
 for i in 0...strk.size-1
  strk[i]=str[str.index(strk[i])+1]
 end
end
puts strk


$normal = [["q", "w", "e", "r", "t", "y", "u", "i", "o", "p"],
           ["a", "s", "d", "f", "g", "h", "j", "k", "l", ";"],
            ["z", "x", "c", "v", "b", "n", "m", ",", ".", "/"]]
d = gets.chomp
s = gets.chomp.split("")
def right(c)
  for i in 0...3
    for j in 0...10
      if c == $normal[i][j]
        return $normal[i][j+1]
      end
    end
  end
end

def left(c)
  for i in 0...3
    for j in 0...10
      if c == $normal[i][j]
        if j == 0
          return nil
        else
          return $normal[i][j-1]
        end
      end
    end
  end
end
for i in 0...s.size
  if d == "L"
    print right(s[i])
  elsif d == "R"
    print left(s[i])
  end
end
print "\n"


s = "qwertyuiopasdfghjkl;zxcvbnm,./"
k = gets.chomp == "L" ? 1 : -1
puts gets.chomp.split('').map{|x|s[s.index(x)+k]}.join


def conv(a,b)
  if b > a/2
    b = a - b
  end
  ans = 1
  div = 1
  b.times do |i|
    ans *= a - i
    div *= (i+1)
  end
  ans = ans / div
  ans
end

n = gets.to_i
x = conv(n,n/2) / 2
for i in 2..((n/2)-1)
  x *= i
  x *= i
end
puts x


def factorial(n)
  return (1..n).inject(:*)
end

n = gets.to_i
puts factorial(n) / (n / 2) ** 2 / 2


N=STDIN.gets.to_i
ans=1
(1..N-1).each do |i|
	ans*=i
end
ans/=(N+1)/2
puts ans


# coding: utf-8

# if __FILE__ == $0
# end

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

if (n/k).odd?
    puts "YES"
else
    puts "NO"
end


# Try Codeforces
# author: Leonardone @ NEETSDKASU

n, k = gets.strip.split.map &:to_i

v = n / k

if v.even?
    puts :NO
else
    puts :YES
end


# https://codeforces.com/problemset/problem/832/A
s = gets.chomp
arr = s.split(' ')

n = arr[0].to_i
k = arr[1].to_i
if ((n % k == 0) && (n / k % 2 != 0)) || ((n % k != 0) && (n / k % 2 != 0))
  puts 'YES'
else
  puts 'NO'
end


code=gets.strip.scan(/.{10}/)

hs={}
10.times{|i|
	hs[gets.strip] = i
}

code.each{|digit|
	print hs[digit]
}


# your code goes here
a, b = gets.chomp.split.map(&:to_i)

result = 1
if b - a > 10
	puts "0"
else
	(1..(b-a)).each do |i|
		result = result * (b + 1 - i)
	end
	puts result%10
end


a, b = gets.split.map{|x| x.to_i}

case b - a
	when 0..4
		ans = 1
		(b - a).times {|i| ans *= (b - i) % 10}
		p ans % 10
	else
		p 0
end


a,b=gets.split.map &:to_i;z=1;(a+1..b).each{|i|z=z*i%10;if z==0 then break end};p z


n, m = gets.split.map { |x| x.to_i }
need = gets.split.map.with_index { |x, i| [(x.to_i+m-1)/m, i+1] }
puts need.reverse.max[1]


n, m = gets.split.map &:to_i
arr = gets.split.map &:to_i
if m >= arr.max
  puts arr.size
else
  arr.map! { |x| x = (x / m.to_f).ceil }
  puts arr.rindex(arr.max) + 1
end


rts = Array.new(5)
for i in 0..4
  rts[i] = Hash.new
  for j in 1..5
    rts[i][j] = 0
  end
end

n = gets.chomp.to_i
for i in 1..n
  a,b = gets.chomp.split(/ /).map!{|x| x.to_i}
  rts[a-1][b] = 1
  rts[b-1][a] = 1
end

ret = "FAIL"
for i in 0..2
  for j in i+1..3
    for k in j+1..4
      wk = rts[i][j+1] + rts[i][k+1] + rts[j][k+1]
      if wk == 3 || wk == 0 then
        ret = "WIN"
        break
      end
    end
  end
end
puts ret


acs = []
gets.strip.to_i.times do
  acs << gets.strip.split(/\s/).map(&:to_i).sort
end

[1,2,3,4,5].combination(3).each do |m|
  count = 0
  m.combination(2).each do |n|
    count += 1 if acs.include?(n)
  end
  if count == 0 || count == 3
    puts 'WIN'
    exit
  end
end
puts 'FAIL'


n=gets.to_i;d=Array.new(6){Array.new(6){0}}
n.times{f,t=gets.split.map(&:to_i);d[f][t]=d[t][f]=1}
for i in 1..5
        for j in 1..5
                next if i==j

                for k in 1..5
                        next if i==j || j==k || i==k

                        if d[i][j]+d[j][k]+d[k][i]==3 || d[i][j]+d[j][k]+d[k][i]==0
                                puts :WIN;exit
                        end
                end
        end
end
puts :FAIL


gets p
puts [*1..5].combination(3).any?{|x|x.permutation(2).select{|a,b|$_=~/#{a} #{b}/}.size%3<1} ? "WIN" : "FAIL"


n = gets.to_i
a = Array.new(5){[false] * 5}
n.times do
	x, y = gets.split.map{|_| _.to_i - 1}
	a[x][y] = a[y][x] = true
end
5.times do |i|
	i.times do |j|
		j.times do |k|
			if (a[i][j] && a[j][k] && a[k][i]) || !(a[i][j] || a[j][k] || a[k][i])
				puts :WIN
				exit
			end
		end
	end
end
puts :FAIL


m=gets.to_i
k=Array.new(5){Array.new(5,0)}
m.times{
    input=gets.split.map(&:to_i)
    k[input[0]-1][input[1]-1]=1
    k[input[1]-1][input[0]-1]=1
}
5.times{|i|
    5.times{|j|
        5.times{|x|
            if i==j || j==x || x==i then
                next
            end
            if k[i][j]==1 && k[j][x]==1 && k[x][i]==1 then
                puts "WIN"
                exit
            end
            if k[i][j]==0 && k[j][x]==0 && k[x][i]==0 then
                puts "WIN"
                exit
            end
        }
    }
}
puts "FAIL"


n = gets.to_i
count = Hash.new(0)
n.times do
	a,b = gets.split(" ").map(&:to_i)
	count[a] += 1
	count[b] += 1
end

ans = false

(1..5).each do |i|
	a = count[i]
	if a >= 3 || a <= 1
		ans = true
		break
	end
end

puts ans ? "WIN" : "FAIL"


rgb=gets.split.map(&:to_i); s=rgb.inject(0, :+); puts [s/3, s-rgb.max].min


r, g, b = STDIN.readline.split.map{|x| x.to_i}
n = [r + g + b - [r,g,b].max, (r + g + b) / 3].min
puts (n.to_s)


n = gets.to_i
ans = n
s = gets.chomp
while n > 1
	pair = s[n - 2.. n - 1]
	if pair[/(RU|UR)/] != nil
		ans -= 1
		n -= 2
	else
		n -= 1
	end
end
puts ans


require 'prime'

def sub(b, s)
  if b.empty?
    v = (s[0]+1)*(s[1]+2)*(s[2]+2) - s[0]*s[1]*s[2]
    return [v, v]
  end

  b = b.dup
  k, v = b.pop

  result = [1e100, 0]
  0.upto(v) do |i|
    0.upto(v-i) do |j|
      mn, mx = sub(b, [s[0]*k**i, s[1]*k**j, s[2]*k**(v-i-j)])
      result[0] = [result[0], mn].min
      result[1] = [result[1], mx].max
    end
  end

  result
end

def solve(n)
  a = Prime.prime_division(n)

  s1 = sub(a, [1, 1, 1])

=begin
  b = a.map{|k,v| [k]*v}.flatten
  r = []
  (3**b.size).times do |i|
    o = [1]*3
    ("0"*b.size+i.to_s(3))[-b.size,b.size].each_char.zip(b) do |j, k|
      o[j.to_i] *= k
    end
    r << [(o[0]+1)*(o[1]+2)*(o[2]+2) - o[0]*o[1]*o[2], o]
  end
  s2 = [r.min[0], r.max[0]]
=end
  s1
end

n = gets.to_i
puts solve(n)*" "


n,a,b=gets.split.map(&:to_i)
ans=0
(1..n).each{|_| ans+=1 if (_-1)>=a && (n-_)<=b}
puts ans


n,a,b = gets.split.map &:to_i

result = 0

for i in a..n-1
	for j in 0..b
		if i+j+1 == n
			result +=1
		end
	end
end

puts result


gets
s = gets
result = 0

while s.include? 'xxx'
  s.slice!(s.index('xxx'))
  result += 1
end

puts result


class Main
  #def get_problem_link
  #  problem_link = "https://codeforces.com/contest/978/problem/B"
  #  return problem_link
  #end

  #def get_submission_link
  #  submission_link = ''
  #  return submisson_link
  #end

  #begin
  #of codeforces interface
  def run_interface
    n = gets.to_i
    k = gets.chomp
    puts solution(n, k)
  end
  #end
  #of codeforces interface

  def solution(n, string)
      res = 0
      for i in 0...n do
          if string[i..i+2] === 'xxx'
            res+=1
          end
      end
      return res
  end

end

#then upload to codeforces uncomment this line:
Main.new.run_interface


n = gets.to_i
s = gets.chomp
ans = 0
(0..n-3).each do |i|
  if s[i..(i+2)] == "xxx"
    ans += 1
  end
end
puts ans


n, x, y = gets.split(" ").map(&:to_i)
d =  x + (-n * y / 100)
d = 0 if d > 0
puts -d


inp=gets.chomp.split.collect{|a| a.to_i}
res=(Float((inp[2]*inp[0]))/100.0).ceil.to_i-inp[1]
if res>0
  puts res
else
 puts 0
end


n,x,p = gets.split.map(&:to_i)
k = ((n/100.0*p).ceil - x)
puts k >= 0 ? k : 0


r = gets.split.map{|e| e.to_i}
n = r[0]
c = r[1..3]
l = []
for i in (0..8000) do l[i] = 0 end
c.each do |e|
 l[e]=1
end

for i in (1..n) do
  c.each do |e|
    if l[i]==0 then next end
    l[i+e] = [l[i+e],l[i]+1].max
  end
end
puts l[n]


n, a, b, c = gets.split(' ').map(&:to_i)
a, b, c = [a, b, c].sort

result = 0

(n.div a).downto(0) do |k|
  m = n-k*a
  (m.div b).downto(0) do |l|
    d, m = (n - k*a - l*b).divmod(c)
    if m.zero?
      result = [result, d + k + l].max
      break
    end
  end
end

puts result


input = gets.chomp
input = input.split

n = input[0].to_i
a = input[1].to_i
b = input[2].to_i
c = input[3].to_i

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

(1..n).each do |i|
  do_a = dp[i - a] if i - a >= 0
  do_b = dp[i - b] if i - b >= 0
  do_c = dp[i - c] if i - c >= 0

  dp[i] = [dp[i], do_a + 1].max if do_a && do_a != -1
  dp[i] = [dp[i], do_b + 1].max if do_b && do_b != -1
  dp[i] = [dp[i], do_c + 1].max if do_c && do_c != -1
end

puts dp[n]


x1,x2,x3 = gets.split.map(&:to_i).sort

puts x3-x1


xs = gets.split.map(&:to_i)
puts ((1..100).map do |i|
  xs.map { |x| (x - i).abs }.inject(&:+)
end.min)


a=gets.chomp.split(" ")
b=gets.chomp.split(" ")
sum=0
0.upto(1) do |i|
a[i]=a[i].to_i
end
0.upto(a[0]-1) do |i|
b[i]=b[i].to_i
sum=sum+b[i]
end
trig=1
0.upto(a[0]-1) do |i|
if sum-b[i]<=a[1]
	puts "YES"
	trig=0
	break
end
end
if trig==1
puts "NO"
end


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

if mugs.sort.slice(0,n-1).sum <= s
	puts "YES"
else
	puts "NO"
end


n, s = gets.split.map(&:to_i)
a = gets.split.map(&:to_i).sort
a.pop
puts a.inject(:+) > s ? 'NO' : 'YES'


str = gets.chomp

str =~ /^(\d)\.(\d+)e(\d+)$/
a = $1
d = $2
b = $3.to_i

while 0 < d.size && d[-1] == '0'
  d = d[0...d.size - 1]
end

if b < d.size
  ans0 = a + d[0...b]
  if ans0 =~ /([1-9]\d*)$/
    ans0 = $1
  else
    ans0 = '0'
  end
  ans1 = d[b...d.size]
  if ans1 == ''
    puts ans0
  else
    puts ans0 + '.' + ans1
  end
else
  ans =  a + d + '0' * (b - d.size)
  if ans =~ /([1-9]\d*)$/
    ans = $1
  else
    ans = '0'
  end
  puts ans
end


inp = gets
a,b = inp.split('e')
c,d = a.split('.')
if b.to_i >= d.length
  out = c + d
  add_zeros = b.to_i - d.length
  out += '0' * add_zeros
else
  out = c + d[0,b.to_i]
  out +=  ('.' + d[b.to_i,a.length]) if d[b.to_i,a.length].to_i != 0
end
puts out


input = gets
output = ""
e_index = input.index("e")
d_index = input.index(".")
factor = input[(e_index + 1)..-1].to_i
output = input[0..(e_index-1)]
output[d_index] = ""
factor.times do |i|
  unless output[d_index + i]
    output[d_index + i] = "0"
  end
end
output.insert(d_index + factor, ".") if (d_index + factor) < output.length
output[(d_index + factor)..-1] = "" if output[(d_index + factor + 1)..-1].to_i == 0
puts output


#!/usr/bin/ruby
n = gets.to_i - 1
p (gets.index('0') || n) + 1


a=gets.chomp.split(" ")
week_arry=[0,0]
month_arry=[0,0]
0.upto(6) do |i|
	week_arry[i]=52
	if i==4 || i==5
		week_arry[i]=53
	end
end
0.upto(30) do |i|
	month_arry[i]=12
	if i==29
		month_arry[i]=11
	elsif i==30
		month_arry[i]=7
	end
end
if a[2]=="week"
   puts week_arry[a[0].to_i-1]
elsif a[2]=="month"
   puts month_arry[a[0].to_i-1]
end


require "date"

d = Date.new(2016, 1, 1)
e = Date.new(2017, 1, 1)

s = gets

ans = 0
if s =~ /week/
  x = s.split[0].to_i
  x = 0 if x == 7
  while d != e
    if d.wday == x
      ans = ans+1
    end
    d = d+1
  end
else
  x = s.split[0].to_i
  while d != e
    if d.day == x
      ans = ans+1
    end
    d = d+1
  end
end

puts ans


n = gets.to_i
p gets.split.map(&:to_i).inject(:gcd) * n


n=gets.to_i
a=gets.chomp.split.map(&:to_i)
ans=a[0]
for i in a do
	ans=ans.gcd(i)
end
puts ans*n


def gcd a, b
	return a if b == 0
	gcd b, a % b
end

n = gets.to_i
a = gets.split.map { |x| x.to_i }

g = a[0]
a.each do |x|
	g = gcd g, x
end
puts g * n


#!/usr/bin/ruby
# -*- coding: utf-8 -*-
include Math

def solve xs
  return xs[1]*xs[2] if xs[0]==1
  xs.map!{ |x| x-1}
  return xs.inject(:+)*2 + solve(xs)
end
puts solve (gets.split.map{ |x| x.to_i}.sort)


a,b,c = gets.split.map(&:to_i)
puts a*b+b*c+a*c - a - b - c + 1


def generate_lucky(i,n,arr)
	if i >= n
		@no_list << arr
		return
	end

	four_count = arr.count("4")
	seven_count = arr.count("7")
	expected = n/2

	if four_count < expected
		arr[i] = "4"
		generate_lucky(i+1,n,arr.dup)
	end

	if seven_count < expected
		arr[i] = "7"
		generate_lucky(i+1,n,arr.dup)
	end
end

@no_list = []
# generate_lucky(0,2,"")
# generate_lucky(0,4,"")

n = gets.to_i

l = n.to_s.length

if l.odd?
	generate_lucky(0,l+1,"")
else
	generate_lucky(0,l,"")
	generate_lucky(0,l+2,"")
end

@no_list = @no_list.map(&:to_i)
@no_list.sort!
ans = @no_list.detect { |e| e >= n  }
puts ans


digits = STDIN.readline.strip.split('').map {|s| s.to_i }.reverse

pos = 0
while pos < digits.length
  digit = digits[pos]
  if digit == 4 or digit == 7
    pos += 1
    next
  end
  (0..pos-1).each {|i| digits[i] = 4 }
  if digit < 4
    digits[pos] = 4
  elsif digit < 7
    digits[pos] = 7
  else
    digits[pos] = 4
    seek = pos+1
    while seek < digits.length and digits[seek] == 9
      digits[seek] = 0
      seek += 1
    end
    if seek < digits.length
      digits[seek] += 1
    else
      digits = (digits.length + 1).times.map { 4 }
      break
    end
  end
  pos += 1
end

while digits.count(4) != digits.count(7)
  pos = 0
  while pos < digits.length and digits[pos] == 7
    digits[pos] = 4
    pos += 1
  end
  if pos < digits.length
    digits[pos] = 7
  else
    digits.push(4)
  end
end

puts digits.reverse.map {|i| i.to_s }.join


n, m = gets.split.map(&:to_i)
puts n == 1 ? 1 : n - m > m - 1 ? m + 1 : m - 1


#http://codeforces.com/contest/570/problem/B

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

if n== 1
  puts 1

elsif 2*m <=n
  puts m+1
else
  puts m-1
end


#!/usr/bin/ruby
N,M=gets.split.map(&:to_i)
p N==1 ? 1 : M-1<N-M ? M+1 : M-1


n = gets.chomp.to_i
ans = Array.new(n + 1, 0)
ans[1] = 1
ans[2] = 2
(3..n).each do |i|
  ans[i] = ans[i - 2] + i
end
print ans[n]


n,t,k,d=gets.split.map &:to_i
t1=(n+k-1)/k*t
t2=0
o1=0
o2=0
while n>0
    t2+=1
    o1+=1
    if o1==t
        o1=0
        n-=k
    end
    if t2>d
        o2+=1
        if o2==t
            o2=0
            n-=k
        end
    end
end
puts (t2<t1 ? "YES" : "NO")


N,T,K,D=gets.split.map &:to_i
puts (N-1)/K*T > D ? :YES : :NO


n,m,i,j,a,b=gets.chomp.split.map(&:to_i)
c=[n,m].max
p,q=[1,1,n,n],[1,m,1,m]
4.times do |x|
	dy,dx=(q[x]-j).abs,(p[x]-i).abs
	if dy%b==0 && dx%a==0 && dy/b %2 == dx/a %2
		break if (a > [i-1,n-i].max && dy > 0) || (b > [j-1,m-j].max and dx > 0)
		c=[c,[dy/b,dx/a].max].min
	end
end
puts (c<[n,m].max) ? "#{c}" : "Poor Inna and pony!"


b = [1]
12.times { b << b.last * 9 }

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

m = a.reduce(:*)

a.count.times do |i|
  r = a[0..i].join.to_i - 1
  r = 1 if r == 0

  r = r.to_s.split('').map(&:to_i).reduce(:*)
  rem_digits = a.count - i - 1
  r *= b[rem_digits]
  m = [r, m].max
end

puts m


s = gets.chomp.split("").map(&:to_i).reverse
ans = s.inject(:*)
n = s.size
(n-1).times do |i|
    if i != n-2 || (s[-1] != 1)
        s[i+1] -= 1
    elsif i == n-2 && s[-1] == 1
        s.pop
    end
    s[i] = 9
    ans = [ans,s.inject(:*)].max
end
puts ans


n, m = gets.split.map(&:to_i)
ds = [[-1,0],[1,0],[0,-1],[0,1]]
data = Array.new(n){|_| ["."]*m}
res = 0
n.times { |i|
  line = gets.strip
  line.length.times { |j| data[i][j] = line[j] }
}

n.times { |i|
  m.times{ |j|
    next if data[i][j] != "W"
    ds.each { |x, y|
      if i+x>=0 && i+x<n && j+y>=0 && j+y<m && data[i+x][j+y]=='P'
        res+=1
        break
      end
    }
  }
}

puts res


line = gets.split
n = line[0].to_i
m = line[1].to_i
field = []

0.upto(n - 1) do |i|
  field[i] = gets.chomp.split('')
end

pigs = 0
pos = []

0.upto(n - 1) do |x|
  0.upto(m - 1) do |y|
    if field[x][y] == "W"
      if x > 0 and field[x - 1][y] == "P"
        pos = [x - 1, y]

      elsif x < n - 1 and field[x + 1][y] == "P"
        pos = [x + 1, y]

      elsif y > 0 and field[x][y - 1] == "P"
        pos = [x, y - 1]

      elsif y < m - 1 and field[x][y + 1] == "P"
        pos = [x, y + 1]
      end
    end

    unless pos.empty?
      field[pos[0]][pos[1]] = ""
      pigs = pigs + 1
      pos = []
    end
  end
end

puts pigs


n, m = gets.split.collect{|i| i.to_i}
mm = Array.new
(1..n).each{mm.push(gets.chomp.split(''))}
ans = 0
for i in 0...n
    for j in 0...m
        next unless  mm[i][j] == 'P'
        if i-1 >= 0 and mm[i-1][j] == 'W'
            mm[i-1][j] = '.'
            ans += 1
            next
        end
        if i+1 < n and mm[i+1][j] == 'W'
            mm[i+1][j] = '.'
            ans += 1
            next
        end
        if j-1 >= 0 and mm[i][j-1] == 'W'
            mm[i][j-1] = '.'
            ans += 1
            next
        end
        if j+1 < m and mm[i][j+1] == 'W'
            mm[i][j+1] = '.'
            ans += 1
            next
        end
    end
end
puts ans


n,l,r = gets.split.map(&:to_i)
mn = n-l
mx = (n-r)*(2**(r-1))
l.times do |i|
    mn += 2**i
end
r.times do |i|
    mx += 2**i
end
puts "#{mn} #{mx}"


N = gets.to_i
R = gets.split.map(&:to_i)
B = gets.split.map(&:to_i)

only_cnt = 0
fail_cnt = 0

N.times do |i|
  r = R[i]
  b = B[i]

  next if r == b

  if r == 1
    only_cnt += 1
  else
    fail_cnt += 1
  end
end

if only_cnt == 0
  puts -1
  exit
end

ng = 0
ok = 1000

while (ok - ng).abs > 1
  x = (ok + ng) / 2

  if only_cnt * x > fail_cnt
    ok = x
  else
    ng = x
  end
end

puts ok


t = gets.to_i(2)
k = 0
while 4**k < t
  k += 1
end
puts k


a=Array.new(gets.split.map(&:to_i))
b=Array.new(gets.split.map(&:to_i))
n=gets.to_i

n1=((a[0]+a[1]+a[2]).to_f/5).ceil
n2=((b[0]+b[1]+b[2]).to_f/10).ceil

if(n1+n2<=n)
    puts "YES"
else
    puts "NO"
end


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

na = a.inject(&:+)
nb = b.inject(&:+)

k = (na/5 + (((na%5)>0)?1:0)) + (nb/10 + (((nb%10)>0)?1:0))

puts (k<=n) ? "YES" : "NO"


a=gets.split.inject(0){|sum,e| sum+=e.to_i}
b=gets.split.inject(0){|sum,e| sum+=e.to_i}
c=gets.to_i
a=-(-a/5)
b=-(-b/10)
puts (c-a-b>=0)?"YES":"NO"


# 489C

m, s = gets.chomp.split.map &:to_i
if m == 1 && s == 0
  puts '0 0'
  exit
end
if (s - 1) / (m * 9) > 0 || s == 0
  puts '-1 -1'
  exit
end

a = Array.new(m, 0)
a[-1] = 1
(s - 1).times do |i|
  a[i / 9] += 1
end
print a.reverse.join ''
print ' '

a = Array.new(m, 0)
s.times do |i|
  a[i / 9] += 1
end
print a.join ''


m, s = gets.split(' ').map(&:to_i)

k = s
num = ''
num = '0' if s == 0
9.downto(1) do |i|
  next if k.div(i).zero?

  num += i.to_s * k.div(i)
  k = k.modulo(i)
end

if num.length > m || (num.length < m && num == '0')
  puts '-1 -1'
elsif num.length == m
  puts "#{num.reverse} #{num}"
else
  # Doing MIN
  min = '1' + '0' * (m - num.length - 1) + (num.reverse[0].to_i - 1).to_s  + num.reverse[1..-1]
  # Doing MAX
  max = num + '0' * (m - num.length)

  puts "#{min} #{max}"
end


def fmin(m,s)
	if m==1 then
		return [s]
	else
		d=[s-1,9].min
		return fmin(m-1,s-d)<<d
	end
end
def fmax(m,s)
	if m==1 then
		return [s]
	else
		d=[s,9].min
		return fmax(m-1,s-d)<<d
	end
end

m,s=gets.split.map{|e| e.to_i}
if s==0 then
	if m==1 then
		puts "0 0"
	else
		puts "-1 -1"
	end
elsif s<=m*9
	t1=fmin(m,s)
	t2=fmax(m,s)
	ans1=t1.inject(0){|sum,e|
		sum=sum*10+e
	}
	ans2=t2.reverse.inject(0){|sum,e|
		sum=sum*10+e
	}
	puts [ans1,ans2]*" "
else
	puts "-1 -1"
end


l,r,a=gets.split.collect!{|t|t.to_i}
ttl=(l+r+a)/2*2
res=0
if l<r
  if l+a<r
    ttl=(l+a)*2
  end
else
  if l>r+a
    ttl=(r+a)*2
  end
end
puts ttl


a,b,c=gets.split.map &:to_i
r=[a,b].min
a-=r
b-=r
a+=b
s=[a,c].min
a-=s
c-=s
p r*2+s*2+c/2*2


l, r, a = gets.split.map(&:to_i)
ar = [l, r].sort
while a != 0
ar[0] += 1
a -= 1
ar.sort!
end
puts ar.min * 2


t=gets.chomp.to_i
l=0
t.times do
    n=gets.chomp.to_i
    puts 2**n-1
end


main = -> {
  t = int
  t.times do
    n = int
    puts 2**n - 1
  end
}

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

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] end
def YesNo t; puts YesNo[t] end
def YESNO t; puts YESNO[t] end
def zip(xs, *yss); Enumerator.new { |y| xs.zip(*yss) { |a| y.yield(*a) } } end
def max(*xs, &block); block_given? ? xs.max_by(&block) : xs.max end
def min(*xs, &block); block_given? ? xs.min_by(&block) : xs.min end
def minmax(*xs, &block); block_given? ? xs.minmax_by(&block) : xs.minmax end
def gcd(*xs); xs.inject(0, :gcd) end
def matrix(h, w, fill=nil, &block); return Array.new(h) { Array.new(w, &block) } if block_given?; Array.new(h) { [fill] * w } end
def debug(x = nil); STDERR.puts (block_given? ? yield(x) : x).inspect if DEBUG; x end
def debug_grid(grid, width = 1); grid.each { |row| STDERR.puts row.map { |x| x.inspect.ljust(width) }.join("") } if DEBUG; grid end
def if_debug; yield if DEBUG end

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

class TrueClass
  include Boolean
  def to_i; 1 end
end

class FalseClass
  include Boolean
  def to_i; 0 end
end

class Integer
  def div_ceil(y); (self + y - 1) / y end
  def mod_inv(mod = MOD); pow(mod-2, mod) end
  def mod_div(y, mod = MOD); self * 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[]


a = gets.to_i
b = gets.to_i
d = a>b ? a-b : b-a
steps, rem = d.divmod 2
sum = steps*(steps+1) + (steps+1)*rem
puts sum


n = gets.to_i
m = gets.to_i
x = ((n - m ).abs)/2
rmendX = ((n - m ).abs)%2
y = ((x*(x+1))/2)*2
if rmendX > 0
  y += x+1
end
p y


n=gets.to_i
a=gets.split.map(&:to_i)
#m,n=gets.split.map(&:to_i)
i=0
if n<=3 then
    puts "chest" if a.max==a[0]
    puts "biceps" if a.max==a[1]
    puts "back" if a.max==a[2]
else
k,b,c=0,0,0
while i< n do
    k+=a[i]
    i+=3
end
i=1
while i<n do
    b+=a[i]
    i+=3
end
i=2
while i<n do
    c+=a[i]
    i+=3
end
puts "chest" if [k,b,c].max==k
puts "biceps" if [k,b,c].max==b
puts "back" if [k,b,c].max==c
end


n=gets.to_i
a=gets.chomp.split.map(&:to_i)
chest,biceps,back=0,0,0
n.times do |i|
	#puts i
	if i%3==0
		chest+=a[i]
	elsif i%3==1
		biceps+=a[i]
	else
		back+=a[i]
	end
end
#x=[chest,biceps,back]
#print x
#puts
if chest>biceps && chest>back
	puts "chest"
elsif biceps>chest && biceps>back
	puts "biceps"
else
	puts "back"
end


n = gets.chomp.to_i
exercises = gets.chomp.split(/ /).map(&:to_i)
ans = {}
index = 0
(0...n).each do |step|
    index = 0 if index == 3
    if !ans.keys.include? index
        ans.store index, exercises[step]
    else
        ans[index] += exercises[step]
    end
    index += 1
end
max = ans.values.max
exercise = ans.select { |key, value| value == max }.to_a[0][0]
case exercise
when 0
    puts "chest"
when 1
    puts "biceps"
when 2
    puts "back"
end


s = gets.chomp
str = ""
if s.start_with? "ftp" then
    str += "ftp://"
    s = s[3..-1]
else
    str += "http://"
    s = s[4..-1]
end
k = s.index("ru")
if k == 0 then k = s.index("ru", 1)
end
str = str + s[0...k] + ".ru"
s = s[k+2..-1]
if s.size != 0 then
    str = str + "/" + s
end
puts "#{str}"


# http://codeforces.com/problemset/problem/3/C

class Grid
  def initialize(gridStr)
    @numX = gridStr.count('X')
    @num0 = gridStr.count('0')
    @numP = gridStr.count('.')
    split = gridStr.split("\n")
    @lines = split.map { |line| line.split("") }
    @num_winning_rows = how_many_in_a_row?
  end

  def analyze
    return "illegal" if is_illegal?
    return "draw" if is_draw?
    return "the second player won" if second_won?
    return "the first player won" if first_won?
    return "second" if second_turn?
    return "first" if first_turn?
  end

  def is_illegal?
    return true if @num0 > @numX
    return true if @numX > @num0 + 1
    return true unless @numX + @num0 + @numP == 9
    return true if too_many_wins?
    return true if move_after_win?
  end

  def is_draw?
    return false if @num_winning_rows > 0
    return true if @numX + @num0 == 9
  end

  def second_won?
    return false if too_many_wins?
    return @ohWins
  end

  def first_won?
    return false if too_many_wins?
    return @xWins
  end

  def second_turn?
    @numX == @num0 + 1
  end

  def first_turn?
    @numX == @num0
  end

  def move_after_win?
    return true if first_won? && @num0 >= @numX
    return true if second_won? && @numX > @num0
  end

  def how_many_in_a_row?
    num = 0
    (0..2).each { |col| num += 1 if horizontal_win(col) }
    (0..2).each { |row| num += 1 if vertical_win(row) }
    num += 1 if left_right_win
    num += 1 if right_left_win
    num
  end

  def horizontal_win(xPos)
    return false unless @lines[xPos][0] == "X" || @lines[xPos][0] == "0"
    if @lines[xPos][0] == @lines[xPos][1] && @lines[xPos][1] == @lines[xPos][2]
      set_winner(@lines[xPos][0])
      @horizontal_winner = true
      return true
    end
  end

  def vertical_win(yPos)
    return false unless @lines[0][yPos] == "X" || @lines[0][yPos] == "0"
    if @lines[0][yPos] == @lines[1][yPos] && @lines[1][yPos] == @lines[2][yPos]
      set_winner(@lines[0][yPos])
      @vertical_winner = true
      return true
    end
  end

  def left_right_win
    return false unless @lines[0][0] == "X" || @lines[0][0] == "0"
    if @lines[0][0] == @lines[1][1] && @lines[1][1] == @lines[2][2]
      set_winner(@lines[0][0])
      @diag_winner = true
      return true
    end
  end

  def right_left_win
    return false unless @lines[2][0] == "X" || @lines[2][0] == "0"
    if @lines[2][0] == @lines[1][1] && @lines[1][1] == @lines[0][2]
      set_winner(@lines[2][0])
      @diag_winner = true
      return true
    end
  end

  def set_winner(player)
    @xWins = true if player == "X"
    @ohWins = true if player == "0"
  end

  def too_many_wins?
    return false if @num_winning_rows == 1 || @num_winning_rows == 0
    return true if @num_winning_rows > 2
    winner = @xWins ? "X" : "0"
    return true if @horizontal_winner && !@diag_winner && !@vertical_winner
    return true if @vertical_winner && !@diag_winner && !@horizontal_winner
    return false
  end
end

def solve
  l1 = gets.chomp
  l2 = gets.chomp
  l3 = gets.chomp
  grid = Grid.new([l1, l2, l3].join("\n"))
  puts grid.analyze()
end

solve()


def winning(x)
    result = []
    3.times do |i|
        if x[i][0] == x[i][1] && x[i][1] == x[i][2] then
            if x[i][0] == "X" then
                result << 1
            elsif x[i][0] == "0"
#               puts "horiz"
                result << 0
            end
        end
        if x[0][i] == x[1][i] && x[1][i] == x[2][i] then
            if x[0][i] == "X" then
                result << 1
            elsif x[0][i] == "0"
#               puts "vert"
#               p i
                result << 0
            end
        end
    end
    if x[0][0] == x[1][1] && x[1][1] == x[2][2] then
        if x[0][0] == "X" then
            result << 1
        elsif x[0][0] == "0"
#           puts "main di"
            result << 0
        end
    end
    if x[0][2] == x[1][1] && x[1][1] == x[2][0] then
        if x[0][2] == "X" then
            result << 1
        elsif x[0][2] == "0"
#           puts "second di"
            result << 0
        end
    end
    if result.size == 1 then
        return result[0]
    elsif result.size > 1 then
        t = true
        i = 1
        while i < result.size do
            if result[i] != result[i-1] then
                t = false
            end
            i += 1
        end
        if t then
            return result[0]
        else
            return "illegal"
        end
    else
        return false
    end
end

field = []
x = 0
o = 0
dots = 0

3.times do |i|
    s = gets.chomp
#   p s
    3.times do |j|
        field[i] = s
#       p field[i]
#       p field[i][j]
        if field[i][j] == "X" then
            x += 1
        elsif field[i][j] == "0" then
            o += 1
        else
            dots += 1
        end
    end
end

if (x-o).abs > 1 || o > x then
    puts "illegal"
else
    t = true
    k = winning(field)
    if k == "illegal" then
        puts k
        t = false
    elsif k == 0 then
        if x > o then
            puts "illegal"
        else
            puts "the second player won"
        end
        t = false
    elsif k == 1 then
        if x == o then
            puts "illegal"
        else
            puts "the first player won"
        end
        t = false
    end
    if x == o && t && dots != 0 then
        puts "first"
        t = false
    elsif t && dots != 0 then
        puts "second"
        t = false
    end
    if !k && t then
        puts "draw"
    end
end


# 3C

def read_line
  gets.chomp.split('')
end

def count(grid, p)
  grid.map { |line|
    line.count p
  }.inject(:+)
end

def won?(grid, p)
  grid.any? { |line|
    line.count(p) == 3
  } || (0...3).any? { |i|
    grid[0][i] == p && grid[1][i] == p && grid[2][i] == p
  } || (grid[0][0] == p && grid[1][1] == p && grid[2][2] == p) ||
      (grid[0][2] == p && grid[1][1] == p && grid[2][0] == p)
end

def has?(grid, p)
  grid.any? { |line|
    line.include? p
  }
end

a = (0...3).map { read_line }
diff = count(a, 'X') - count(a, '0')
unless diff == 1 || diff == 0
  puts 'illegal'
  exit
end
x_won, o_won = won?(a, 'X'), won?(a, '0')
if x_won && o_won
  puts 'illegal'
  exit
end
if x_won
  puts(diff == 1 ? 'the first player won' : 'illegal')
  exit
end
if o_won
  puts(diff == 0 ? 'the second player won' : 'illegal')
  exit
end
if has?(a, '.')
  puts(diff == 0 ? 'first' : 'second')
else
  puts 'draw'
end


def fact(n)
	return @dp[n] if @dp[n]
	i = 1
	(2..n).each do |a|
		i *= a
	end
	@dp[n] = i
	i
end

def comb(n,r=2)
	return 0 if n < r
    return 1 if n == r
    return n if r == 1
    return 1 if n == 0
 #    comb(n-1,r) + comb(n-1,r-1)
 # num = fact(n)
 # denom = fact(r) * fact(n-r)
 # num / denom
 	(n * (n-1))/2
end
@dp = {}
n,m = gets.split(" ").map(&:to_i)
max = comb(n-m+1,2)

q = n / m
r = n % m
min = 1
min = (r * comb(q+1,2)) + ((m-r) * comb(q,2))

puts "#{min} #{max}"


def pairs(r)
	return (r*r-r)/2
end
n, m = STDIN.readline.split().map {|q| q.to_i}
r = n - m + 1
mod = n % m
div = n / m
min = (m - mod) * pairs(div) + mod * pairs(div + 1)
puts(min.to_s + " " + (pairs(r).to_s))


n=gets.to_i
(p 1;exit)if n<10
x=10**Math.log10(n).to_i
n=(x-n)%x
p n<1 ? x : n


def scan;gets.split.map(&:to_i);end
s = gets.chomp
sn = s[0].succ + '0'*s[1..-1].size
p sn.to_i - s.to_i


n=gets.to_i
(p 1;exit)if n<10
x=10**Math.log10(n).to_i
p (x-n-1)%x+1


#!/Users/mike/.rvm/rubies/ruby-1.9.3-p327/bin/ruby

redNum, blueNum = STDIN.readline.split.collect {|s| s.to_i}

def msg s=''
	#puts s
end

def simulate(red, redCount, blueCount, petyaMove)
	petya, vasya = 0, 0
	while redCount+blueCount > 0
		if petyaMove
			if red and redCount > 0
				redCount -= 1
				petya += 1
			elsif not red and blueCount > 0
				blueCount -= 1
				petya += 1
			elsif redCount > 0
				red = true
				redCount -= 1
				vasya += 1
			else
				red = false
				blueCount -= 1
				vasya += 1
			end
		else
			if red and blueCount > 0
				red = false
				blueCount -= 1
				vasya += 1
			elsif not red and redCount > 0
				red = true
				redCount -= 1
				vasya += 1
			elsif redCount > 0
				red = true
				redCount -= 1
				petya += 1
			else
				red = false
				blueCount -= 1
				petya += 1
			end
		end
		if red
			msg 'red'
		else
			msg 'blue'
		end
		petyaMove = !petyaMove
	end
	return [petya, vasya]
end

msg 'red'
petya0, vasya0 = simulate(true, redNum-1, blueNum, false)
msg
msg 'blue'
petya1, vasya1 = simulate(false, redNum, blueNum-1, false)
msg

if (petya0 > petya1)
	puts '%s %s' % [petya0, vasya0]
else (petya1 > petya0)
	puts '%s %s' % [petya1, vasya1]
end


#!/Users/mike/.rvm/rubies/ruby-1.9.3-p327/bin/ruby

redNum, blueNum = STDIN.readline.split.collect {|s| s.to_i}

def msg s=''
	#puts s
end

def simulate(red, redCount, blueCount, petyaMove)
	petya, vasya = 0, 0
	while redCount+blueCount > 0
		wasRed = red
		if petyaMove and red and redCount > 0
			red = true
		elsif petyaMove and !red and blueCount > 0
			red = false
		elsif !petyaMove and red and blueCount > 0
			red = false
		elsif !petyaMove and !red and redCount > 0
			red = true
		elsif redCount > 0
			red = true
		else
			red = false
		end
		if red
			redCount -= 1
			if wasRed
				petya += 1
			else
				vasya += 1
			end
			msg 'red'
		else
			blueCount -= 1
			if wasRed
				vasya += 1
			else
				petya += 1
			end
			msg 'blue'
		end
		petyaMove = !petyaMove
	end
	return [petya, vasya]
end

msg 'red'
petya0, vasya0 = simulate(true, redNum-1, blueNum, false)
msg
msg 'blue'
petya1, vasya1 = simulate(false, redNum, blueNum-1, false)
msg

if (petya0 > petya1)
	puts '%s %s' % [petya0, vasya0]
else (petya1 > petya0)
	puts '%s %s' % [petya1, vasya1]
end


def max(x,y)
    if x > y then
        return x
    else
        return y
    end
end

def min(x,y)
    if x < y then
        return x
    else
        return y
    end
end

st = gets.split
red = st[0].to_i
blue = st[1].to_i
points = []

if red == blue then
    points << red - 1 << red
else
    points << max(red,blue) - 1 << min(red,blue)
end

result = points.join(" ")
puts result


#!/usr/bin/ruby
hash = {'9' => '0', '8' => '1','7' => '2','6' => '3','5' => '4'}
input_line = gets
res = ''
input_line.each_char do |ch|
    if hash[ch].nil?
        res+=ch;
    else
        if (ch == '9' && res == '')
            res+=ch
        else
            res+=hash[ch]
        end
    end
end

puts res


arr = gets.chomp.split("")
arr.each_with_index do |item, index|
  print item.to_i <= 4 ? item : index.to_i == 0 && item.to_i == 9 ? item : 9 - item.to_i
end


x = gets.chomp.chars.map(&:to_i)

tmp = x[0]
x = x[1..-1]

tmp = 9 - tmp if tmp > 4 and tmp < 9

x = x.map { |i|
  if i > 4
    9 - i
  else
    i
  end }

puts ([tmp] + x).join("")


n, d = gets.split.map(&:to_i)
a = gets.split.map(&:to_i).sort
m = gets.to_i

profit = 0

m.times { a << -d }
m.times { |i| profit += a[i] }

puts profit


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

  sum = a[0, [n, m].min].reduce(0) {|x, sum| sum + x}
  sum -= (m - n) * d if m >= n
  puts sum
end

run if $0 == __FILE__


n, pnlt = gets.split(" ").map{|s| s.to_i}
cost =  gets.split(" ").map{|s| s.to_i}
m = gets.to_i
ret = 0
cost = cost.sort()
if (m<=n)
	m.times {|i| ret += cost[i]}
else
	n.times {|i| ret += cost[i]}
	ret -= (m-n)*pnlt
end
puts ret


a,b,c = gets.split.map(&:to_i)
x = [a,b].min
y = [a,b].max
puts x + [a + b,c].min + [y,x + c].min


a=gets.chomp.split(" ")
0.upto(2){|i| a[i]=a[i].to_i}
a.sort!
k=(a[0]*2+a[1]*2)
l=0
a.each{|i| l=l+i }
if l>k
	puts k
else
   puts l
end


def delegate_boxes
  n, m, a, b = gets.split.map(&:to_i)
  l = n % m
  return 0 if l == 0

  if n < m
    return min(n * b, (m - n) * a)
  end

  min(l * b, (m - l) * a)
end

def min(a, b)
  a <= b ? a : b
end

puts delegate_boxes


n, m, a, b = gets.strip.split.map(&:to_i)
td = n % m
tb = m - td
puts [td*b, tb*a].min


n, m, a, b = gets.split.map &:to_i
x = [n / m - 1, 0].max
ans = Float::INFINITY
x.upto(x + 2) do |i|
  ans = [ans, i * m < n ? (n - i * m) * b : (i * m - n) * a].min
end
puts ans


n, m, k = gets.strip.split.map(&:to_i)
pos = k.odd? ? "L" : "R"
col_sum = m * 2
mod = k % col_sum
div = k / col_sum
mod += 1 if k.odd?
desk = (mod / 2).ceil
desk = m if mod == 0
lane = div + (mod > 0 ? 1 : 0)
puts "#{lane} #{desk} #{pos}"


N, S = gets.split(" ").map(&:to_i)
lb, ub = 0, N + 1
until lb + 1 == ub do
  mid = lb + ub >> 1
  mid - mid.to_s.chars.map(&:to_i).reduce(:+) >= S ? ub = mid : lb = mid
end
puts N - ub + 1


n = gets.chomp.to_i
s = gets.chomp
ans = s.chars.chunk { |chr| chr == 'B' }.select(&:first).map { |chunk| chunk.last.length }
puts ans.length
puts ans.join(" ")


gets
a = []
c = 0
gets.strip.split('').each do |x|
    if x == 'B'
        c += 1
    else
        a << c if c > 0
        c = 0
    end
end
a << c if c > 0
puts(a.size, a.join(' '))


n = gets.strip.to_i
s = gets.strip
ans = []
prev = ''
count = prev == 'B' ? 1 : 0
(0...n).each do |i|
    curr = s[i]
    if (curr == prev && curr == 'B') || (curr != prev && curr == 'B')
        count += 1
    else
        ans << count if count > 0
        count = curr == 'B' ? 1 : 0
    end
    prev = curr
end
ans << count if count > 0
puts ans.length
puts ans.join(" ") if ans.length > 0


input=gets.chomp.to_i
if input>5 && input%2==0
puts (input-2)/4
elsif input>5 && input%2==1
puts 0
else
puts 0
end


n=gets.to_i
if n%2==1 then
	puts 0
else
	n=n/2
	ans=n/2-(1-n%2)
	ans=0 if ans<0
	puts ans
end


I=gets(p).split.map &:to_i
[*1..9].permutation(4){|a,b,c,d|(puts"%d %d\n%d %d"%[a,b,c,d];exit)if[a+b,c+d,a+c,b+d,a+d,b+c]==I}
p -1


r1, r2 = gets.split.map(&:to_i)
c1, c2 = gets.split.map(&:to_i)
d1, d2 = gets.split.map(&:to_i)

1.upto(9) do |a|
  b = r1 - a
  c = c1 - a
  d = d1 - a

  if [a,b,c,d].all?{|x|(1..9).include?(x)} && [a,b,c,d].uniq.size==4 && b+c == d2 && b+d == c2 && c+d == r2
    puts [a, b]*" "
    puts [c, d]*" "
    exit
  end
end
puts -1


require 'matrix'

a1, b1, c1 = gets.split.map { |v| v.to_i }
a2, b2, c2 = gets.split.map { |v| v.to_i }
a3,b3,c3=0,0,0

rank_a = Matrix[ [a1, b1], [a2, b2] ].rank
rank_b = Matrix[ [a1, b1, c1], [a2, b2, c2], [a3, b3, c3] ].rank

result = 0

if rank_a == rank_b
  result = rank_a == 2 ? 1 : -1;
end

puts result


def num_solutions(a1, b1, c1, a2, b2, c2)
  if a2 == 0 and b2 == 0
    if c2 != 0
      return 0
    else
      if a1 == 0 and b1 == 0
        return (c1 == 0 ? -1 : 0)
      else
        return -1
      end
    end
  end
  det = a1*b2-a2*b1
  return 1 if det != 0
  det2 = a1*c2-a2*c1
  det3 = b1*c2-b2*c1
  return ((det2 == 0  and det3 == 0) ? -1 : 0)
end

a1, b1, c1 = gets.split.map(&:to_i)
a2, b2, c2 = gets.split.map(&:to_i)

if a1 == 0 and b1 == 0
  a1, b1, c1, a2, b2, c2 = a2, b2, c2, a1, b1, c1
end

puts num_solutions(a1, b1, c1, a2, b2, c2)


n = gets.chomp.to_s
r = n[-1]
x = n.to_i

if(r=='f')
    ans=1
end
if(r=='e')
    ans=2
end
if(r=='d')
    ans=3
end
if(r=='a')
    ans=4
end
if(r=='b')
    ans=5
end
if(r=='c')
    ans=6
end

f = (x-1)/4
ans+=f*16
f = x%4
if(f==2 || f==0)
    ans+=7
end
p ans


def ab a, b
  result = []
  cant_do_it = false
  while a < b
    result << b
    if b % 2 == 0
      b /= 2
    elsif b % 10 == 1
      b = (b - 1) / 10
    else
      cant_do_it = true
      break
    end
  end
  result << a if a == b
  result unless cant_do_it || a != b
end

def ab_print(a, b)
  result = ab(a, b)
  if result.nil?
    puts "NO"
  else
    puts "YES"
    puts result.size
    puts(result.reverse*' ')
  end
end

# ab_print(2, 162)
# ab_print(4, 42)
# ab_print(100, 40021)
a, b = gets.chomp.split(/\s+/, 2).map {|x| x.to_i}
ab_print(a, b)


a,b=gets.split.map(&:to_i)
prev={a=>nil}
q=[a]
while !q.empty?
	cur=q.shift
	[cur*10+1,cur*2].each{|e|
		next if e>b
		if !prev.has_key?(e)
			prev[e]=cur
			q<<e
		end
	}
end
if prev[b]
	puts :YES
	x=[]
	while prev[b]
		x<<b
		b=prev[b]
	end
	x<<b
	p x.size
	puts x.reverse*' '
else
	puts :NO
end


a, b = gets.split.map &:to_i
s = []
while b > a do
	s << b
	if b % 2 == 0 then
		b /= 2
	elsif b % 10 == 1 then
		b /= 10
	else
		break
	end
end
if b == a then
	s << b
	puts 'YES'
	puts s.size
	puts (s.reverse.map &:to_s) * ' '
elsif
	puts 'NO'
end


x, y, n = gets.split(' ').collect!{|i| i.to_i}

k = x.to_f/y
# p k
a = 0
b = 0
min = 100000

(1..n).each do |i|
	j = k*i

	if j - j.to_i > 0.5
		j = j.round.to_i
	else
		j = j.to_i
	end

	cur = (k - j/i.to_f).abs
	# p j if j == 38236
	# p i if j == 38236
	# p j/i.to_f if j == 38236
	if cur < min
		a = j
		b = i
		min = cur
	end
end

print a, "/", b


#!/usr/bin/ruby1.9

x, y, n = STDIN.readline.split.collect {|s| s.to_i }

best_diff = x
best_a = -1
best_b = -1

(1..n).each do |b|
	a = (x*b)/y
	a += 1 if (x*b)%y > y/2
	diff = ((x*b - a*y)*1.0/(y*b)).abs
	if diff < best_diff
		best_diff = diff
		best_a = a
		best_b = b
	end
end

puts '%d/%d' % [best_a, best_b]


x, y, n = gets.split
x = x.to_f
y = y.to_f
n = n.to_i

val = x/y

min = (0x7FFFFFFF).to_f
a = 0
b = 0

for i in 1..n
  k = val*i
  if (k - k.floor) > 0.5
    k = k.ceil.to_f
  else
    k = k.floor.to_f
  end
  s = (k/i - x/y).abs
  if s < min then
    min = s
    a = k.to_i
    b = i
  end
end

print a, "/", b


x,y,n = gets.split(' ').map{ |e| e.to_i }
a = x
b = y

	z = x.to_f / y
	min_diff = nil
	(1..n).each do |i|
		aa = -((-i.to_f * x / y - 0.5).floor) - 1
		diff = (aa.to_f / i - z).abs
		if (!min_diff || min_diff > diff)
			min_diff = diff
			a = aa
			b = i
		end
		if min_diff == 0
			break
		end
	end

puts "#{a}/#{b}"


x,y,n = gets.split(" ").map(&:to_i)
# if y < n
# 	puts "#{x}/#{y}"
# else
	min_diff = n
	given_div = x/y.to_f
	val1 = nil
	val2 = nil
	n.downto(0) do |b|
		a1 = (given_div * b).floor
		a2 = a1 + 1
		# puts "a #{a} b #{b} #{div} #{min_diff}"
		[a1,a2].each do |a|
			div = (a/b.to_f)
			diff = (given_div - div).abs.round(15)
			if diff < min_diff || (diff == min_diff && a < val1)
				# puts "#{a} #{b} #{(given_div - div).abs} #{min_diff}"
				val1 = a
				val2 = b
				min_diff = diff
			end
		end
	end

	puts "#{val1}/#{val2}"
# end


n = gets.to_i
a = gets.strip.split.map{|s| s.to_i}

x = a.select{|i| i == 200}.length
y = a.length - x

ox = x % 2
oy1 = y % 2
oy2 = ([y,1].max - 2) % 2

verdict = (1 - oy1)**(1 - ox) * (1 - oy2)**ox

puts "YES" if verdict == 1
puts "NO" if verdict == 0


n=gets().to_i
line=gets().split(" ")
c100=0
c200=0
for i in 0...line.size
  c100+=1 if line[i].to_i==100
  c200+=1 if line[i].to_i==200
end
if c100%2==0 and c100>=2 or c200%2==0 and c100%2==0
  puts "YES"
else
  puts "NO"
end


n = gets.chomp.to_i
puts n % 2 == 0 ? 2 : 1


c, d = gets.split.map {|x| Integer x}
n, m = gets.split.map {|x| Integer x}
k = Integer gets
a = n * m - k
puts [[a / n * c + (a % n) * d, a * d, (a + n - 1) / n * c].min, 0].max


a = gets.chomp.to_i
b = gets.chomp.to_i
c = gets.chomp.to_i
array = []
array << (a + ( b * c ))
array << (a * ( b + c ))
array <<  (a * b * c)
array << (( a + b ) * c)
array << a + b + c

puts array.max


n = gets.to_i
as = gets.split.map(&:to_i).sort
ans = 0
(0..(n/2-1)).each do |i|
  ans += (as[2*i] - as[2*i+1]).abs
end
puts ans


n = gets.to_i
arr = gets.split.map(&:to_i).sort
res = 0
arr.each_slice(2) do |slice|
  res += slice[1] - slice[0]
end
puts res


N = gets.to_i
x = gets.split.map(&:to_i).inject(:+)
y = gets.split.map(&:to_i).inject(:+)
puts x >= y ? 'Yes' : 'No'


n = gets.to_i
xs = gets.split.map(&:to_i)
ys = gets.split.map(&:to_i)
puts xs.inject(:+) >= ys.inject(:+) ? 'Yes' : 'No'


n = gets.to_i
x = gets.split.map &:to_i
y = gets.split.map &:to_i
puts x.inject(0) { |s, x| s + x } >= y.inject(0) { |s, x| s + x} ? 'Yes' : 'No'


arr = gets.split.map(&:reverse).sort
STDERR.puts "#{arr}"
set = arr.uniq
if set.size == 1
	# 已经是koutsu
	puts 0
	exit
elsif set.size == 2
	# 有重复，再摸牌就可凑齐刻子
	puts 1
	exit
end
if arr[0].succ == arr[1] && arr[1].succ == arr[2]
	# 已经是shuntsu
	puts 0
	exit
end
for k in 0..1
	if arr[k][0] == arr[k+1][0]
		# 花色相同才有可能凑顺子；由于arr排序过，花色相同的牌相邻
		if arr[k+1][1].to_i - arr[k][1].to_i <= 2
			# 花色相同的牌若差值小于等于2，可以摸牌凑顺子
			puts 1
			exit
		end
	end
end
puts 2
# 不属于以上情况，就必须摸两次牌才可以凑齐刻或顺


def neighbor(a,b)
  return (a[1].to_i - b[1].to_i).abs == 1 && a[0] == b[0]
end
def neighbor2(a,b)
  return (a[1].to_i - b[1].to_i).abs == 2 && a[0] == b[0]
end

t = gets.split
t.each do |s|
  s.reverse!
end
t.sort!

if t[0] == t[1] && t[1] == t[2]
  p 0
elsif neighbor(t[0],t[1]) && neighbor(t[1],t[2])
  p 0
elsif t[0] == t[1] || t[1] == t[2]
  p 1
elsif neighbor(t[0],t[1]) || neighbor(t[1],t[2])
  p 1
elsif neighbor2(t[0],t[1]) || neighbor2(t[0],t[2]) || neighbor2(t[1],t[2])
  p 1
else
  p 2
end


s = gets.chomp.split.sort
ans = 2
if s[0] == s[1]
    if s[1] == s[2]
        ans = 0
    else
        ans = 1
    end
elsif s[1] == s[2]
    ans = 1
else
    a = Hash.new
    a["s"] = 0
    a["p"] = 1
    a["m"] = 2
    b = Array.new(3).map{Array.new(10,0)}
    3.times do |i|
        b[a[s[i][1]]][s[i][0].to_i] += 1
    end
    3.times do |i|
        c = 1
        (2..9).each do |j|
            if b[i][j] == 1 && b[i][j-1] == 1
                c += 1
                ans = [ans,3-c].min
            else
                c = 1
            end
        end
        (2..8).each do |j|
            if b[i][j-1] == 1 && b[i][j+1] == 1
                ans = [ans,1].min
            end
        end
    end
end
puts ans


#!/usr/bin/ruby

input_line = gets

params = input_line.split(' ')
n = params[0].to_i
m = params[1].to_i

parr = (1..n).to_a.permutation.map(&:join)

def sum_arg param
    arr = param.to_s.chars.map{|x| x.to_i}
    res = 0
    i = 0;
    j = 0;
    while i < param.length do
        j = i
        while j < param.length do
            p = (arr.slice(i,j-i+1)).min
            res += p
            j = j + 1
        end
        i = i + 1
    end
    res
end

max = 0
permutations = []

parr.each do |pp|
    current_sum = sum_arg(pp)
    if (current_sum > max)
        max = current_sum;
        permutations = []
        permutations << pp
    elsif (current_sum == max)
        permutations << pp
    end

end

res = permutations[m-1]
sres = ''
res.to_s.chars.each do |x|
    sres+= x + ' '
end
puts sres.strip


n, k = $stdin.read.split.map(&:to_i)
@pow = []
# puts n
# puts k
(n + 1).times do |i|
	@pow << 2**(i-1)
end
# puts @pow
def find(n, k)
	# puts "observing #{n} #{k}"
	if (n == 1)
		raise "#{k}" unless k == 1
		return [1]
	end
	if @pow[n - 1] >= k
		res = find(n - 1, k)
		[1] + res.map{|i| i + 1}
	else
		res = find(n - 1, k - @pow[n - 1])
		res.map{|i| i + 1} + [1]
	end
end

puts find(n, k).join(" ")


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

n, m = gets.split.map &:to_i
def f(n, i, m)
  if i == n
    return i.to_s
  elsif m > 2 ** (n - i - 1)
    return f(n, i + 1, m - 2 ** (n - i - 1)) + ' ' +  i.to_s
  else
    return i.to_s + ' ' + f(n, i + 1, m)
  end
end
puts f(n, 1, m)


k,r = gets.split.map(&:to_i)
1.upto(10) do |n|
	if (k * n) % 10 == 0 or (k * n) % 10 == r
		puts n
		break
	end
end


# 3
kr = gets.chomp
kr = kr.split
k = kr[0].to_i
r = kr[1].to_i

i = 1
while i > 0
	if ((i*k) - r) % 10 == 0 || (i*k) % 10 == 0
		print i
		break
	end
	i+= 1
end


def dp(idx , bool)
    if idx == $n
	return 0
    end
    ret = $mem[bool][idx]
    if ret != -100000
	return ret
    end
    if bool == 1
	ret = [dp(idx+1,1)+$number[idx],0].max
    else
	ret = [dp(idx+1,0),dp(idx+1,1)+$number[idx]].max
    end
    $mem[bool][idx] = ret
    return ret
end

$n = gets.to_i
$mem =  Array.new(2){Array.new($n,-100000)}
$number = gets.split.collect {|element| element.to_i}
sum = 0
$number.each{|x| sum += (x==1?1:0)}
for i in 0...$n do
   $number[i] = ($number[i]==1?-1:1)
end
if sum == $n
   puts sum-1
else
   puts "#{sum+dp(0,0)}"
end


N = Integer(gets)

str = gets
nums = str.split.map! {|a| Integer(a)}
total = 0
for i in 0...nums.length
  total += nums[i]
end

dp = Array.new
count = Array.new

dp.push(1 - nums[0])
count.push(nums[0])
for i in 1...nums.length
  dp.push([count[i-1], dp[i-1]].max + 1 - nums[i])
  count.push(count[i-1] + nums[i])
end

ans = 0
for i in 0...nums.length
  if ans < total - count[i] + dp[i]
    ans = total - count[i] + dp[i]
  end
end

puts ans


n = Integer(gets)
input = gets.chomp
nums = input.split
number = Array.new
number1 = Array.new

for i in 0...n
    number[i] = number1[i] = Integer(nums[i])
end

def sum(a)
    x = 0
    for i in 0...a.length
        x += a[i]
    end
    return x
end
def restore(number1,number)
    for i in 0...number.length
        number1[i] = number[i]
    end
end

c = 0
for i in 0...n
    for j in i...n
        for x in i..j
            if number[x] == 1
                number1[x] = 0
            else
                number1[x] = 1
            end
        end
        if sum(number1) > c
            c = sum(number1)
        end
        restore(number1,number)
    end
end
if sum(number) == n
    puts n - 1
else

    if c > sum(number)
        puts c
    else
        puts sum(number)
    end
end


a, b, c = gets.split.map(&:to_i)
if a == b
  puts a + b + c * 2
else
  puts [a, b].min * 2 + 1 + c * 2
end


a, b, c = gets.split.map(&:to_i)
puts c * 2 + [a, b].min * 2 + (a != b ? 1 : 0)


n = gets.to_i
ans = 2*n-1
(n-1).times do |i|
  ans += (i*2+1)*2
end
p ans


n = gets.chomp.to_i

def solve(n)
  dp = [0] * (n + 1)
  dp[1] = 1
  for i in 2...n+1 do
    dp[i] = dp[i-1] + 4*(i-1)
  end
  return dp[n]
end

puts solve(n)


# coding: utf-8

# if __FILE__ == $0
# end

n = gets.to_i

puts n*n*2 - (2*n - 1)


n,m=gets.split.map &:to_i;x=gets.to_i-1
p [n,m].min>2*x ?[n+m-4*x-2,1].max: 0


n, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
v = []
(0...(2E5+11).to_i).each do |i|
  v << []
end
(0...n).each do |i|
  cur = a[i]
  res = 0
  while cur > 0
    v[cur] << res
    res += 1
    cur /= 2
  end
end
res = 1E9.to_i
(0..2E5.to_i).each do |i|
  v[i].sort!
  next if v[i].length < k
  sum = 0
  (0...k).each do |j|
    sum += v[i][j]
  end
  res = [res, sum].min
end
puts res


n=gets.to_i
if n%2==1
puts 0
else
puts 2**(n/2)
end


n=gets.to_i
if n.odd?
  p 0
else
  p 2**(n/2)
end


n,c = gets.split.map(&:to_i)
x =gets.split.map(&:to_i)
dx = []

0.upto(n-2) do |i|
  dx << x[i] - x[i+1]
end

mdx = dx.max
puts [mdx - c, 0].max


n, c = gets.split.map &:to_i
x = gets.split.map &:to_i
ans = 0
(1...x.size).step(1) { |i|
  temp = x[i - 1] - x[i] - c
  ans = temp if temp > ans
}
p ans


n, c = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
diff = a.drop(1).zip(a).map{|x, y| y - x}.max
puts [diff - c, 0].max


d=0
o="WBWBWBWB"
p="BWBWBWBW"
8.times do |i|
j=gets.chomp
if j==o
    d+=1
elsif j==p
    d+=1
else
    d=-1
end
end
if d!=8
    puts "NO"
else
    puts "YES"
end


puts [*$<].map{|s| s=~/WW|BB/}.any? ? :NO : :YES


f = true
8.times do
  b = nil
  gets.each_char do |c|
    f = false if b == c
    b = c
  end
end

if f
  puts 'YES'
else
  puts 'NO'
end


h, m = gets.chomp.split(":").map do |s|
  s.sub(/^0+(.)/, '\1').bytes.to_a.map do |s|
    if s <= 57
      s - 48
    else
      s - 55
    end
  end
end

if h.size == 1 && m.size == 1 && h.first < 24 && m.first < 60
  puts -1
  exit
end

def cand(a, n)
  sum = 0
  a.reverse.each_with_index do |i, index|
    sum += i * (n ** index)
  end
  sum
end

hh = []
mm = []
(2..60).each do |n|
  hh << n if h.all?{|i| i < n} && cand(h, n) < 24
  mm << n if m.all?{|i| i < n} && cand(m, n) < 60
end
r = hh & mm
puts r.empty? ? 0 : r.join(" ")
exit


$d0='0'.ord
$d9='9'.ord
$A='A'.ord
def value (c)
   if(c>=$d0 && c<=$d9)
      return c-$d0
   else
       c-$A+10
   end
end

s=gets
s=s.chop
t=s.split(/:/)
list=[]
for radix in (2..1000)

  ok=true
  for i in (0..1)
    max=0
    num=0
    if i==0
      max=23
    else
      max=59
    end
    for j in(0..t[i].length-1)
      w=value(t[i][j].ord)
      if(w>=radix)
        ok=false
      end
      num=radix*num+w

    end
    if(num>max)
      ok=false
    end
  end
  if(ok)
    list.insert(list.size,radix)
  end

end
if(list.size==0)
  puts 0
elsif(list.size>500)
  puts -1
else
  for x in list
    print x
    print ' '
  end
end


S = [*'0'..'9'] + [*'A'..'Z']
def gao(s, b)
    x = 0
    s.each_char do |c|
        x *= b
        i = S.index(c)
        return nil unless i && i < b
        x += i
    end
    return x
end

a, b = gets.chop.split(/:/).map{|_| _.gsub(/^0*(?=.)/, '')}
c = []
2.upto(100) do |d|
    x = gao(a, d)
    y = gao(b, d)
    c << d if x && x < 24 && y && y < 60
end

if c.empty?
    p 0
elsif c[-1] > 60
    p -1
else
    puts c * ' '
end