Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins.When the numbers of points of both wrestlers are equal, the wrestler whose sequence of points is lexicographically greater, wins.If the sequences of the awarded points coincide, the wrestler who performed the last technique wins. Your task is to determine which wrestler won.

The first line contains number n — the number of techniques that the wrestlers have used (1 ≤ n ≤ 2·105).  The following n lines contain integer numbers ai (|ai| ≤ 109, ai ≠ 0). If ai is positive, that means that the first wrestler performed the technique that was awarded with ai points. And if ai is negative, that means that the second wrestler performed the technique that was awarded with ( - ai) points. The techniques are given in chronological order.

If the first wrestler wins, print string "first", otherwise print "second"

NoteSequence x  =  x1x2... x|x| is lexicographically larger than sequence y  =  y1y2... y|y|, if either |x|  >  |y| and x1  =  y1,  x2  =  y2, ... ,  x|y|  =  y|y|, or there is such number r (r  <  |x|, r  <  |y|), that x1  =  y1,  x2  =  y2,  ... ,  xr  =  yr and xr  +  1  >  yr  +  1.We use notation |a| to denote length of sequence a.

n = STDIN.readline.to_i
a, b = [], []
last = nil
n.times do
  x = STDIN.readline.to_i
  if x > 0
    a.push(x)
    last = 'first'
  else
    b.push(-x)
    last = 'second'
  end
end

sum_a, sum_b = a.inject(0, :+), b.inject(0, :+)
if sum_a > sum_b
  puts 'first'
  exit
end
if sum_a < sum_b
  puts 'second'
  exit
end

if a == b
  puts last
  exit
end

greater = ([a, b].sort)[1]
if greater == a
  puts 'first'
else
  puts 'second'
end

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

n = gets.to_i

t = nil
a = [[0], [0]]
n.times do
  c = gets.to_i
  t = c < 0 ? 1 : 0
  a[t] << c.abs
  a[t][0] += c.abs
end
a[t] << 1
result = [a[0] ,a[1]].max == a[0] ? "first" : "second"
puts result

n=gets.to_i
ar,br,a,b,flag,i,t=Array.new(200001,0),Array.new(200001,0),0,0,0,0,nil
sumA,sumB=0,0
n.times do
	t=gets.to_i
	if t>0
		sumA+=t
		ar[a]=t
		a+=1
	else
		sumB-=t
		br[b]=-t
		b+=1
	end
end
flag=1 if sumA>sumB
flag=2 if sumB>sumA
if flag==0
	while i<a && i<b
		if ar[i]>br[i]
			flag=1
			break
		elsif br[i]>ar[i]
			flag=2
			break
		end
		i+=1
	end
	if flag==0
		flag = (t>0) ? 1 : 2
	end
end
puts (flag==1) ? "first" : "second"

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

class GameProcess
  def initialize(n)
    @n = n
    @f = Wrestler.new
    @s = Wrestler.new
    @f_w = "first"
    @s_w = "second"
    @last = @f_w
    start
  end

  def start
    if @n == 1
      @last = gets.chomp.to_i < 0 ? @s_w : @f_w
      return
    end
    @n.times do |i|
      p = gets.chomp.to_i
      distribute_point(p)
      @last = 0 < p ? @f_w : @s_w
    end
  end

  def distribute_point(p)
    return @f.get_point(p) if 0 < p
    @s.get_point(-1 * p)
  end

  def result
    f_s = @f.sum_points
    s_s = @s.sum_points
    return @f_w if s_s < f_s
    return @s_w if f_s < s_s
    return lexicographic_order
  end

  def lexicographic_order
    f_l = @f.number_of_point
    s_l = @s.number_of_point
    result = @last
    n = 0
    if f_l < s_l
      n = f_l
    else
      n = s_l
    end
    n.times do |i|
      f_p = @f.point_at(i)
      s_p = @s.point_at(i)
      next if f_p == s_p
      if f_p < s_p
        result = @s_w
        break
      else
        result = @f_w
        break
      end
    end
    return result
  end
end

class Wrestler
  def initialize()
    @sum = 0
    @points = []
  end

  def get_point(p)
    @points << p
    @sum += p
  end

  def point_at(i)
    @points[i]
  end

  def sum_points
    @sum
  end

  def number_of_point
    @points.length
  end
end

gp = GameProcess.new(gets.chomp.to_i)
puts gp.result

l=(1..gets.to_i).map{gets.to_i}
a={true=>[0],false=>[0]}.merge(l.group_by{|i|i>0})
a[true]#.sort!
a[false].map!{|i|-i}#.sort!
#a.values.map(&:sort!)
b=Hash[a.map{|k,v|[k,v.inject(:+)]}]
#p a,b
puts (if b[true]==b[false]
  if a[true]==a[false]
    l[-1]>0
  else
    a.keys.max_by{|i|a[i]}
  end
else
  b[true]>b[false]
end)?"first":"second"

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

def cmp(a, b)
    (a < b)? -1 : ((a == b)? 0 : +1)
end

n = gets.to_i
p, u = 0, []
q, v = 0, []
l = 0

for i in 0...n
    x = gets.to_i
    y = x.abs

    if x > 0
        p += y
        u << y
        l = 1
    else
        q += y
        v << y
        l = -1
    end
end

ans = cmp(p, q)

if ans == 0
    min = min(u.size, v.size)

    for i in 0...min
        ans = cmp(u[i], v[i])
        break if ans != 0
    end

    ans = l if ans == 0
end

data = {1 => 'first', -1 => 'second'}

puts data[ans]

def lex(first,second)
	lexi = true
	i = 0
	j = 0
	ans = nil
	while i < first.length && j < second.length
		if first[i] < second[i]
			ans = "second"
			break
		elsif first[i] > second[i]
			ans = "first"
			break
		end
		i += 1
		j += 1
	end
	if !ans && first.length != second.length
		if first.length < second.length
			ans = "second"
		else
			ans = "first"
		end
	end
	ans
end

n = gets.to_i
arr = []
n.times do
	arr << gets.to_i
end
first = arr.select{|a| a > 0}
second = arr.select{|a| a < 0}.map { |e| e.abs  }

first_score = first.inject(0,:+)
second_score = second.inject(0,:+)

if first_score < second_score
	ans = "second"
elsif first_score > second_score
	ans = "first"
else
	ans = lex(first,second)
	unless ans
		if arr[-1] > 0
			ans = "first"
		else
			ans = "second"
		end
	end

end
puts ans

N = gets.to_i
vals = STDIN.read.split.map(&:to_i)
firsts = []
seconds = []
first = 0
second = 0
last_player = nil
vals.each{|val|
    if val>0
        first += val
        last_player = "first"
        firsts << val
    else
        second +=  - val
        last_player = "second"
        seconds << - val
    end
}
seq_first = false
seq_second = false

(0...[firsts.size, seconds.size].max).each{|i|
    if(firsts[i].to_i > seconds[i].to_i)
        seq_first = true
        break
    elsif(firsts[i].to_i < seconds[i].to_i)
        seq_second = true
        break
    end
}
# puts "first=#{first}, second=#{second}"
if first > second then
    puts "first"
    exit 0
elsif second > first then
    puts "second"
    exit 0
end
if seq_first then
    puts "first"
    exit 0
elsif seq_second then
    puts "second"
    exit 0
end
puts last_player

def compare_arrays(f, s)

  for i in f.zip s
    if i[0] > i[1]
      return 1
    elsif i[1] > i[0]
      return 2
    end
  end

  if f.length > s.length
    return 1
  elsif f.length < s.length
    return 2
  end

  0
end

n = gets.to_i

sum = 0
first = []
second = []

for _ in 1..n
  cur = gets.to_i

  sum += cur

  if cur > 0
    first << cur.abs
  else
    second << cur.abs
  end
end

if sum > 0
  puts "first"
elsif sum < 0
  puts "second"
else
  case compare_arrays(first, second)
    when 0
      if cur > 1
        puts "first"
      elsif cur < 2
        puts "second"
      end
    when 1
      puts "first"
    else
      puts "second"
  end

end

# puts "First #{first}"
# puts "Second #{second}"

pa=Array.new
pb=Array.new
x=y=k=sa=sb=0

n=gets.to_i
for i in 0..n-1
  h=gets.to_i
  if h>0
    k=1
    pa[x]=h
    x+=1
    sa+=h
  else
    k=2
    pb[y]=-h
    y+=1
    sb+=-h
  end
end

g=0
if sa>sb
  puts "first"
  g=1
elsif sa<sb
  puts "second"
  g=1
end

if g==0
  i=0
  while i<x&&i<y
    if pa[i]>pb[i]
      puts "first"
      g=1
      break
    elsif pa[i]<pb[i]
      puts "second"
      g=1
      break
    end
    i+=1
  end
end

if g==0
  if k==1
    puts "first"
  elsif k==2
    puts "second"
  end
end

# 493B

a_sum = b_sum = 0
a_ary, b_ary = [], []
val = nil
gets.to_i.times {
  val = gets.to_i
  if val > 0
    a_sum += val
    a_ary << val
  else
    b_sum += -val
    b_ary << -val
  end
}
res = if a_sum > b_sum
        true
      elsif a_sum < b_sum
        false
      else
        res = a_ary <=> b_ary
        if res > 0
          true
        elsif res < 0
          false
        else
          val > 0
        end
      end
puts res ? 'first' : 'second'

n=gets.to_i
ar,br,a,b,flag,i=Array.new(200001,0),Array.new(200001,0),0,0,0,0
sumA,sumB=0,0
n.times do
	t=gets.to_i
	if t>0
		sumA+=t
		ar[a]=t
		a+=1
	else
		sumB-=t
		br[b]=-t
		b+=1
	end
end
flag=1 if sumA>sumB
flag=2 if sumB>sumA
if flag==0
	while i<a && i<b
		if ar[i]>br[i]
			flag=1
			break
		elsif br[i]>ar[i]
			flag=2
			break
		end
		i+=1
	end
end
puts (flag==1) ? "first" : "second"

ans = {}
ans[-1] = 'second'
ans[ 0] = ''
ans[+1] = 'first'

n = gets.to_i
u = []
v = []

for i in 0...n
    x = gets.to_i
    y = x.abs

    if x > 0
        u << y
        ans[0] = 'first'
    else
        v << y
        ans[0] = 'second'
    end
end

u << 0 if u.size == 0
v << 0 if v.size == 0

p = u.map{|x| x.to_i}.reduce(:+)
q = v.map{|x| x.to_i}.reduce(:+)

if p > q
    puts ans[1]
elsif p < q
    puts ans[-1]
else
    puts ans[u.join.casecmp(v.join)]
end

ans = {}
ans[-1] = 'second'
ans[ 0] = ''
ans[+1] = 'first'

n = gets.to_i
u = []
v = []

for i in 0...n
    x = gets.to_i
    y = x.abs

    if x > 0
        u << y
        ans[0] = 'first'
    else
        v << y
        ans[0] = 'second'
    end
end

puts ans[u.join.casecmp(v.join)]

N = gets.to_i
vals = STDIN.read.split.map(&:to_i)
firsts = []
seconds = []
first = 0
second = 0
last_player = nil
vals.each{|val|
    if val>0
        first += val
        last_player = "first"
        firsts << val
    else
        second +=  - val
        last_player = "second"
        seconds << - val
    end
}
seq_first = false
seq_second = false

(0...[firsts.size, seconds.size].max).each{|i|
    if(firsts[i].to_i > seconds[i].to_i)
        seq_first = true
    elsif(firsts[i].to_i < seconds[i].to_i)
        seq_second = true
    end
}
# puts "first=#{first}, second=#{second}"
if first > second then
    puts "first"
    exit 0
elsif second > first then
    puts "second"
    exit 0
end
if seq_first then
    puts "first"
    exit 0
elsif seq_second then
    puts "second"
    exit 0
end
puts last_player

l=(1..gets.to_i).map{gets.to_i}
a=l.group_by{|i|i>0}
a[true].sort!
a[false].map!{|i|-i}.sort!
a.values.map(&:sort!)
b=Hash[a.map{|k,v|[k,v.inject(:+)]}]
puts (if b[true]==b[false]
  if a[true]==a[false]
    l[-1]>0
  else
    a.keys.max_by{|i|a[i]}
  end
else
  a.keys.max_by{|i|b[i]}
end)?"first":"second"

l=(1..gets.to_i).map{gets.to_i}
a=l.group_by{|i|i>0}
#a[true].sort!
a[false].map!{|i|-i}#.sort!
a.values.map(&:sort!)
b=Hash[a.map{|k,v|[k,v.inject(:+)]}]
#p a,b
puts (if b[true]==b[false]
  if a[true]==a[false]
    l[-1]>0
  else
    a.keys.max_by{|i|a[i]}
  end
else
  a.keys.max_by{|i|b[i]}
end)?"first":"second"

l=(1..gets.to_i).map{gets.to_i}
a={true=>[0],false=>[0]}.merge(l.group_by{|i|i>0})
a[true].sort!
a[false].map!{|i|-i}.sort!
a.values.map(&:sort!)
b=Hash[a.map{|k,v|[k,v.inject(:+)]}]
#p a,b
puts (if b[true]==b[false]
  if a[true]==a[false]
    l[-1]>0
  else
    a.keys.max_by{|i|a[i]}
  end
else
  a.keys.max_by{|i|b[i]}
end)?"first":"second"

l=(1..gets.to_i).map{gets.to_i}
a={true=>[0],false=>[0]}.merge(l.group_by{|i|i>0})
#a[true].sort!
a[false].map!{|i|-i}#.sort!
a.values.map(&:sort!)
b=Hash[a.map{|k,v|[k,v.inject(:+)]}]
#p a,b
puts (if b[true]==b[false]
  if a[true]==a[false]
    l[-1]>0
  else
    a.keys.max_by{|i|a[i]}
  end
else
  a.keys.max_by{|i|b[i]}
end)?"first":"second"

l=(1..gets.to_i).map{gets.to_i}
a={true=>[0],false=>[0]}.merge(l.group_by{|i|i>0})
a[true].sort!
a[false].map!{|i|-i}.sort!
#a.values.map(&:sort!)
b=Hash[a.map{|k,v|[k,v.inject(:+)]}]
#p a,b
puts (if b[true]==b[false]
  if a[true]==a[false]
    l[-1]>0
  else
    a.keys.max_by{|i|a[i]}
  end
else
  b[true]>b[false]
end)?"first":"second"

pa=Array.new
pb=Array.new
x=y=k=sa=sb=0

n=gets.to_i
for i in 0..n-1
  h=gets.to_i
  if h>0
    k=1
    pa[x]=h
    x+=1
    sa+=h
  else
    k=2
    pb[y]=-h
    y+=1
    sb+=-h
  end
end

flag=0
if sa>sb
  puts "first"
  flag=1
elsif sa<sb
  puts "second"
  flag=1
end

if flag==0
  i=0
  while i<x&&i<y
    if x[i]>y[i]
      puts "first"
      flag=1
      break
    elsif x[i]<y[i]
      puts "second"
      puts "jh"
      flag=1
      break
    end
    i+=1
  end
end

if flag==0
  if k==1
    puts "first"
  elsif k==2
    puts "second"
  end
end

pa=Array.new
pb=Array.new
x=y=k=sa=sb=0

n=gets.to_i
for i in 0..n-1
  h=gets.to_i
  if h>0
    k=1
    pa[x]=h
    x+=1
    sa+=h
  else
    k=2
    pb[y]=-h
    y+=1
    sb+=-h
  end
end
sta=pa.join
stb=pb.join

if sa!=sb
  if sa>sb
    puts "first"
  else
    puts "second"
  end
elsif sta!=stb
  if sta>stb
    puts "first"
  else
    puts "second"
  end
else
  if k==1
    puts "first"
  elsif k==2
    puts "second"
  end
end

pa=Array.new
pb=Array.new
x=y=k=sa=sb=0

n=gets.to_i
for i in 0..n-1
  h=gets.to_i
  if h>0
    k=1
    pa[x]=h
    x+=1
    sa+=h
  else
    k=2
    pb[y]=-h
    y+=1
    sb+=-h
  end
end

flag=0
if sa>sb
  puts "first"
  flag=1
else
  puts "second"
  flag=1
end

if flag==0
  i=0
  while i<x and i<y
    if x[i]>y[i]
      puts "first"
      flag=1
      break
    elsif x[i]<y[i]
      puts "second"
      flag=1
      break
    end
    i+=1
  end
end

if flag==0
  if k==1
    puts "first"
  elsif k==2
    puts "second"
  end
end

pa=Array.new
pb=Array.new
x=y=k=sa=sb=0

n=gets.to_i
for i in 0..n-1
  h=gets.to_i
  if h>0
    k=1
    pa[x]=h
    x+=1
    sa+=h
  else
    k=2
    pb[y]=-h
    y+=1
    sb+=-h
  end
end

g=0
if sa>sb
  puts "first"
  g=1
elsif sa<sb
  puts "second"
  g=1
end

if g==0
  i=0
  while i<x&&i<y
    if x[i]>y[i]
      puts "first"
      g=1
      break
    elsif x[i]<y[i]
      puts "second"
      g=1
      break
    end
    i+=1
  end
end

if g==0
  if k==1
    puts "first"
  elsif k==2
    puts "second"
  end
end

# 493B

a_sum = b_sum = 0
a_str = b_str = ''
val = nil
gets.to_i.times {
  val = gets.to_i
  if val > 0
    a_sum += val
    a_str << val
  else
    b_sum += -val
    b_str << -val
  end
}
res = if a_sum > b_sum
        true
      elsif a_sum < b_sum
        false
      elsif a_str > b_str
        true
      elsif a_str < b_str
        false
      else
        val > 0
      end
puts res ? 'first' : 'second'


You are given two integers $$$x$$$ and $$$y$$$ (it is guaranteed that $$$x > y$$$). You may choose any prime integer $$$p$$$ and subtract it any number of times from $$$x$$$. Is it possible to make $$$x$$$ equal to $$$y$$$?Recall that a prime number is a positive integer that has exactly two positive divisors: $$$1$$$ and this integer itself. The sequence of prime numbers starts with $$$2$$$, $$$3$$$, $$$5$$$, $$$7$$$, $$$11$$$.Your program should solve $$$t$$$ independent test cases.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Then $$$t$$$ lines follow, each describing a test case. Each line contains two integers $$$x$$$ and $$$y$$$ ($$$1 \le y < x \le 10^{18}$$$).

For each test case, print YES if it is possible to choose a prime number $$$p$$$ and subtract it any number of times from $$$x$$$ so that $$$x$$$ becomes equal to $$$y$$$. Otherwise, print NO. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes, and YES will all be recognized as positive answer).

NoteIn the first test of the example you may choose $$$p = 2$$$ and subtract it once.In the second test of the example you may choose $$$p = 5$$$ and subtract it twice. Note that you cannot choose $$$p = 7$$$, subtract it, then choose $$$p = 3$$$ and subtract it again.In the third test of the example you may choose $$$p = 3$$$ and subtract it $$$333333333333333333$$$ times.

t = gets.to_i
t.times do
  x, y = gets.split.map(&:to_i)
  d = x - y
  puts d == 1 ? 'NO' : 'YES'
end

gets.to_i.times do
    x,y = gets.split.map(&:to_i)
    puts (x-y > 1) ? "Yes" : "No"
end

# coding: utf-8

# if __FILE__ == $0
# end

t = gets.to_i
primes = [2,3]
t.times {
    x, y = gets.split.map(&:to_i)
    # x > y, guaranteed
    d = x - y
    if d < 2
        puts "NO"
    else
        puts "YES"
    end
}

t = gets.to_i
for i in 1..t
    a,b = gets.split.map(&:to_i);
    flag = 0
    if (a-b>=2)
        print "YES"
        puts "\n"
        flag = 1
    end
    if flag != 1
        print "NO"
        puts "\n"
    end
end

t = gets.to_i
t.times do
  x, y = gets.split.map &:to_i
  puts x - y == 1 ? 'NO' : 'YES'
end

# coding: utf-8

# if __FILE__ == $0
# end

t = gets.to_i
primes = [2,3]
t.times {
    x, y = gets.split.map(&:to_i)
    # x > y, guaranteed
    d = x - y
    if d < 2
        puts "NO"
    else
        if d%2 == 0
            puts "YES"
        else
            # prime sub check
            is_prime_sub = false
            for i in primes
                break if i > d
                if d%i == 0
                    is_prime_sub = true
                    break
                end
            end

            # generate primes and check prime sub
            sqd = Math.sqrt(d).ceil
            if primes.last < sqd
                for i in (primes.last)..sqd
                    is_prime = true
                    for j in primes
                        if i%j == 0
                            is_prime = false
                            break
                        end
                    end

                    primes << i if is_prime

                    if d%i == 0
                        is_prime_sub = true
                        break
                    end
                end
            end

            if is_prime_sub
                puts "YES"
            else
                puts "NO"
            end
        end
    end
}

# coding: utf-8

# if __FILE__ == $0
# end

t = gets.to_i
primes = [2,3]
t.times {
    x, y = gets.split.map(&:to_i)
    # x > y, guaranteed
    d = x - y
    if d < 2
        puts "NO"
    else
        if d%2 == 0
            puts "YES"
        else
            # prime sub check
            is_prime_sub = false
            sqd = Math.sqrt(d).floor

            for j in primes
                break if j > sqd
                if sqd%j == 0
                    is_prime_sub = true
                    break
                end
            end

            if is_prime_sub == false
                for i in (primes.last)..sqd
                    next if i%2 == 0
                    is_prime = true
                    for j in primes
                        if i%j == 0
                            is_prime = false
                            break
                        end
                    end

                    if is_prime
                        primes << i

                        if sqd%i == 0
                            is_prime_sub = true
                            break
                        end
                    end
                end
            end

            # 안되면 끝까지 구해야지 별 수 있나
            # 가즈아! (근데 이걸로는 submission 못해봄.)
            # 1
            # 999984 1

            # p primes
            if is_prime_sub
                puts "YES"
            else
                puts "NO"
            end
        end
    end
}


Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.

The first line contains an integer n (1 ≤ n ≤ 100). Each of the following n lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.

Print n lines. The i-th line should contain the result of replacing of the i-th word from the input data.

4
word
localization
internationalization
pneumonoultramicroscopicsilicovolcanoconiosis

n=gets.to_i

n.times {
i=gets
a=i.length
if (a <= 11)
 puts i
else
 out= i[0] + (a-3).to_s + i[a-2]
 puts out
end
}

n = gets.to_i
a =[]
for i in 0..n-1 do
  a = a + [gets]
  if a[i].size > 11
    a[i] = (a[i][0] + (a[i].size - 3).to_s + a[i][a[i].size - 2])
  end
end
puts a

gets.to_i.times do
s=gets.chomp
	if s.length > 10
	puts s[0] << (s.length - 2).to_s << s[s.length - 1]
	else
	puts s
	end
end

#!/usr/bin/ruby
n = STDIN.gets.chop.to_i

n.times do
  word = STDIN.gets
  word.chop!

  if word.length > 10
    print word[0, 1]
    print word.length-2
    print word[-1, 1]
  else
    print word
  end

  print "\n"
end

#!/usr/bin/env ruby
class Test
	kol = gets.chomp
	ik = kol.to_i
	for num in 1..ik
		str = gets.chomp
	if str.length > 10
	len = str.length - 2
	len = len.to_s
	temp = str[0..0] + len + str[str.length-1..str.length-1]
		puts temp
	else
		puts str
	end
	end
end

(gets.to_i).times do
  ss=gets
  if(ss.length>11)
    ss[1,ss.length-3] = (ss.length-3).to_s
  end
  puts (ss)
end

x = gets.to_i

def check(j)
	if j.length <= 10
		puts j
	else
		puts j[0] + (j.length - 2).to_s + j[-1]
	end
end

for i in 1..x do
	y = gets.chomp
	check(y)
end

n = gets.to_i

a = Array.new(n)
for i in 0..(n - 1)
  a[i] = gets.to_s
end

a.each {|b|
if b.length >= 12
  f = b.split("")[0]
  l = b.split("")[(b.length-2)]
  c = b.split("")[1..(b.length-3)].join("")
  puts "#{f}#{c.length}#{l}"
else
  puts "#{b}"
end
}

n=gets.chomp.strip.to_i
n.times do
	a=gets.chomp.to_s
	num=a.length - 2
	if a.length>10
		word=a[0]+num.to_s+a[num+1]
	else
		word=a
	end
	puts word
end

n = gets.to_i

for i in 0...n
  x = gets;
  if x.size > 11
  print x[0]
  print x.size-3;
  print x[x.size-2].chr;
    puts
  elsif
    puts x;
  end
end

len = 10
n = gets.to_i
while n > 0 do
    word = gets.chomp
    if word.size > len
        puts [word.chars.first, word.size-2, word.chars.last].join
    else
        puts word
    end
    n -= 1
end

gets.to_i.times do
  s = gets.chomp
  puts s.size>10?"#{s[0]}#{s.size-2}#{s[-1]}":s
end

1.upto(gets.to_i) do
  a = gets.chomp
  a = "#{a[0, 1]}#{a.length - 2}#{a[-1, 1]}" if a.length > 10

  puts a
end

m=gets.to_i
m.times do
  s = gets.chomp
  if s.size <= 10
    puts s
  else
    puts "#{s[0]}#{s.size - 2}#{s[-1]}"
  end
end

n = gets.to_i

words = []

n.times do
	curr = gets

	if curr.length > 11
		last = curr[curr.length - 2, 1]
		curr = curr[0] + (curr.length - 3).to_s
		curr = curr + last
	end

	words << curr
end

puts words

t=gets.to_i
t.times{

  s=gets.chomp
  n=s.size
  if n<=10
    puts s
  else
    puts "#{s[0]}#{n-2}#{s[-1]}"
  end

}

num = gets.chomp
num = num.to_i

num.times do
    input = gets.chomp #get the next lines of input
    if (input.size > 10) #if the size of the string is 10 or more..
         firstLetter = input.split("").first
         lastLetter = input.split("").last
         input = input.split("")
         input.pop
         input.shift
         input = input.join
         new_word = "#{firstLetter}#{input.length}#{lastLetter}\n"
         print new_word
    else
        word = "#{input}\n"
        print word
    end
end

number = gets.chomp.to_i

number.times do
word = gets.chomp

if word.length > 10
str = ''
number = word.length - 2
str = word[0] + number.to_s + word[word.length - 1]
puts str
else
puts word
end
end

x = gets.chomp.to_i

for i in 0...x do
   words = gets.chomp.to_s
   if words.length > 10
    puts words[0].to_s + (words.length-2).to_s + words[-1]
   else
    puts words
   end
end

n = gets.to_i
n.times do
a = gets.chomp
d = Array.new
b = a[0]
c = a[-1, 1]
x = a[1..-2]
s = x.size.to_i
 if s > 8
 d << b << s << c
 d.map { |sammy| sammy}
 puts d.join
 else
 puts a
 end
 end

n = gets.to_i
a =[]
for i in 0..n-1 do
  a = a + [gets]
  if a[i].size > 11
    a[i] = (a[i][0] + (a[i].size - 3).to_s + a[i][a[i].size - 2])
  end
end
puts a

n = gets.to_i
n.times do
  str = gets.chomp
  if str.length>10
    puts str[0]+(str.length-2).to_s+str[-1]
  else
    puts str
  end

end

n = gets.strip.to_i
n.times do |i|
  word = gets.strip
  result = ""
  if word.length > 10 then
    result = "#{word[0]}#{word[1..-2].length}#{word[-1]}"
  else
    result = word
  end
  puts result
end

n = gets.to_i
while n > 0 do
    word = gets.chomp
    if (s = word.size - 2) > 8
        puts [word[0], s, word[-1]].join
    else
        puts word
    end
    n -= 1
end

n=gets.chomp.to_i.times{a=gets.chomp.to_s;o=a.length;if o>10 then printf("%c%d%c\n",a[0],o-2,a[o-1]);else puts(a)end}

class LongWord
  def initialize(word)
    @word = word
  end

  def short_version
    return @word if @word.size <= 10

    first_char = @word[0]
    last_char = @word[-1]
    rest_word_count = @word[1..-2].size

    "#{first_char}#{rest_word_count}#{last_char}"
  end
end

# Main
count_of_input = gets.strip.to_i
word_collection = []
count_of_input.times do
  word = gets.strip
  word_collection << word
end

word_collection.each do |word|
  long_word = LongWord.new(word)
  puts long_word.short_version
end

n = gets.to_i
n.times do
  s = gets.chomp
  if s.size <= 10
    puts s
  else
    puts "#{s[0]}#{s.size - 2}#{s[-1]}"
  end
end

array = STDIN
array.each { |x| if x.size > 11 then puts "#{x[0]}#{x.size - 3}#{x[-2]}" elsif x =~ /[0-9]/ then nil else puts x end }

t = gets.to_i

lines = []
t.times do
  current = gets.chomp
  if current.length > 10
    lines.push(current[0] + (current.length - 2).to_s + current[current.length-1])
  else
    lines.push(current)
  end
end

lines.each do |line|
  puts line
end

input = STDIN.read

n, lines = input.split("\n", 2)

lines = lines.split("\n")
# n = n.to_i
lines.each do |line|
  if line.length < 11
    puts line
  else
    puts "#{line[0]}#{line.length - 2}#{line[line.length - 1]}"
  end
end

a=Array.new;
n=gets;
n.to_i.times{|i|a[i]=gets.chop}
a=a.map{|i|if i.size>10 then i=i[0..0]+(i.size-2).to_s+i[-1..-1] else i=i end}
a.each{|i|puts i}

a = gets.split(" ")
n = a[0].to_i
for i in 1..n
  s = gets.chomp
  if(s.size > 10)
    s1 = s[0]+(s.size-2).to_s+s[s.size - 1]
    puts(s1)
  else puts(s)
  end
end

x=gets.to_i
x.times do
n=gets.chomp
z=n.length
if z > 10
print n[0]
print z-2
print n[z-1]
print "\n"
else
print n
print "\n"
end
end

gets.chomp.to_i.times {
	s=gets.chomp
	if(s.length<=10)
		puts s
	elsif
		puts "#{s[0]}#{s.length-2.to_i}#{s[-1]}"
	end
}

gets.to_i.times do
  s = gets.chomp
  puts s.size>10?"#{s[0]}#{s.size-2}#{s[-1]}":s
end

n=gets.to_i
a= []
for i in 0..n-1
	a[i] = gets
end
a.each do |val|
	val = val.gsub("\n","")
	len = val.length
	puts  len <= 10 ? val : "#{val[0]}#{len-2}#{val[len-1]}"
end

n=gets.to_i

n.times {
i=gets
a=i.length
if (a <= 11)
 puts i
else
 out= i[0] + (a-3).to_s + i[a-2]
 puts out
end
}

def abb ()
    n = gets.to_i
  words = Array.new(n)
    for i in 0...n
      word = gets.to_s
      words[i] = word.chomp!
    end
  words.each{ |word|
        if word.length <= 10
            puts word
        else
            puts "#{word[0]}#{word.length-2}#{word[-1]}"
        end
  }
end

abb

a = gets.to_i

for arr in (1..a)
  arr = gets.to_s
  if arr.length > 11
    startLetter = arr[0]
    lastLetter = arr[arr.length - 2]
    puts arr = startLetter + (arr.length.to_i - 3).to_s + lastLetter.to_s
  else
    puts arr.to_s
  end
end

n = gets.chomp.to_i
words = []
(1..n).each do |_i|
  words << gets.chomp
end

words.each do |w|
  if w.size < 11
    puts w
  else
    puts "#{w[0]}#{w.size - 2}#{w[-1]}"
  end
end

n=gets.chomp.to_i
n.times do
	a=gets.chomp.to_s
	num=a.length - 2
	if a.length>10
		word=a[0]+num.to_s+a[num+1]
	else
		word=a
	end
	puts word
end

a = gets.to_i
for i in 1..a
    b = gets
    c = b.length
    c = c - 1
    if c <= 10
        puts b
    else
        d = c - 2
        print b[0]
        print d
        print b[c-1]
        puts
    end
end

n = gets.to_i

$i = 0

while $i < n
    s = gets
    if s.length < 12
        puts s
    elsif
        puts "#{s[0]}#{s.length - 3}#{s[s.length - 2]}"
    end

    $i += 1
end

gets.chomp.to_i.times do
  str = gets.chomp
  puts str.length > 10 ? "#{str[0]}#{str.length - 2}#{str[-1]}" : str
end

gets.chomp.to_i.times do |_|
  word = gets.chomp.each_char
  printf(word.size > 10 ? "#{word.first}#{word.size-2}#{word.to_a.last}\n" : "#{word.to_a.join}\n")
end

n = gets.to_i
a =[]
for i in 0..n-1 do
  a = a + [gets]
  if a[i].size > 11
    a[i] = (a[i][0] + (a[i].size - 3).to_s + a[i][a[i].size - 2])
  end
end
puts a

lines = STDIN.read.split("\n")
if 2 <= lines.size
  lines[1..(lines.size - 1)].each do |word|
    puts word.length <= 10 ? word : "#{word[0]}#{word.length - 2}#{word[word.length - 1]}"
  end
end

# frozen_string_literal: true

n = gets.to_i

1.upto(n).each do |_i|
  str = gets.strip
  if str.length <= 10
    puts str
    next
  end
  len = str.length - 2
  puts "#{str[0]}#{len}#{str[str.length - 1]}"
end

n = gets.to_i
words = n.times.map { gets.chomp }
words.map do |word|
    if (s = word.size - 2) > 8
        "#{word[0]}#{s}#{word[-1]}"
    else
        word
    end
end.each { |w| puts w }

n = gets.to_i
n.times do |i|
  l = gets.strip
  s = l.size
  puts s>10 ? l[0]+(s-2).to_s+l[s-1] : l
end

#!/usr/bin/ruby

n = gets.chomp.to_i

n.times do
  s = gets.chomp.to_s

  if s.length > 10
    first_letter = s[0]
    last_letter = s[s.length-1]
    abbr = (s.length - 2).to_s
    puts (first_letter + abbr + last_letter)
  else
    puts s
  end
end

n = gets.chomp.to_i.times do |i| a = gets.chomp.to_s; if a.length>10 then print(a[0]); print(a.length-2); puts(a[a.length-1]); else puts(a) end end

limit =gets.chomp()
limit = limit.to_i
while limit>0
	word = gets.chomp()
	if word.length>10
		print word[0],word.length-2,word[-1]
		print "\n"
	else
		puts word
	end
	limit-=1
end

n = gets.chomp.to_i
0.upto n-1 do |i|
  w = gets.chomp
  if w.length > 10 then
	ww = "#{w[0]}#{w.length-2}#{w[w.length-1]}"
	puts ww
  else
    puts w
  end
end

t=gets.to_i
t.times{

  s=gets.chomp
  n=s.size
  if n<=10
    puts s
  else
    puts "#{s[0]}#{n-2}#{s[-1]}"
  end

}

n = gets.to_i

n.times do
  input = gets.chomp
  if input.size > 10
    puts "#{input.chars.first}#{input.length - 2}#{input.chars.last}"
  else
    puts input
  end
end

n = gets.chomp.to_i
for i in(0...n)
    s = gets.chomp
    if s.length() < 11
        puts s
    else
        print s[0],s.length()-2,s[s.length()-1]
        puts
    end
end

a=Array.new;
n=gets;
n.to_i.times{|i|a[i]=gets.chop}
a=a.map{|i|if i.size>10 then i=i[0..0]+(i.size-2).to_s+i[-1..-1] else i=i end}
a.each{|i|puts i}

n = gets.to_i
n.times.map { gets.chomp }.each do |word|
    if (s = word.size - 2) > 8
        puts "#{word[0]}#{s}#{word[-1]}"
    else
        puts word
    end
end

number = gets.chomp.to_i
number.times do
  word = gets.chomp

  if word.size > 10
    puts word[0] + (word.size - 2).to_s + word[-1]
  else
    puts word
  end
end

n = gets.to_i

n.times{
  s = gets
  n = s.length-1
  if n <= 10
    puts s
   else
    puts s[0] + (s[1..n-2].length.to_s) + s[n-1]
  end
}

n=gets.chomp.to_i.times{a=gets.chomp.to_s;o=a.length;if o>10 then printf("%c%d%c\n",a[0],o-2,a[o-1]);else puts(a)end}

def too_long_word (word)
    x = 0
    n = gets
    num = n.to_i

    while x < num
      word = gets
      char = word.chomp.split('')
      sum_char = char.size
      char_min = ((sum_char) - 2).to_s
        if sum_char <= 10
          puts word
        else
          puts char.first + char_min + char.last
        end
    x+=1
    end
end

too_long_word ()

(gets.to_i).times do
  ss=gets
  if(ss.length>11)
    ss[1,ss.length-3] = (ss.length-3).to_s
  end
  puts (ss)
end

n = gets.chomp.to_i

n.times do
  word = gets.chomp
  if word.size > 10
    n = word.size
    puts "#{word[0]}#{n - 2}#{word[n-1]}"
  else
    puts word
  end
end

gets.to_i.times do
	word = gets.chomp
	if word.length <= 10
		puts word
	else
		print word[0], word.length - 2, word[-1], "\n"
	end
end

n = readline.to_i

i = 0
a = Array.new()

while i < n do
  begin
    a[i] = readline
    i += 1
  end
end
a.each do
  |i|
  if (i.size > 11)
    puts i[0] + (i.size - 3).to_s + i[i.size - 2]
  else
    puts i
  end
end

n = gets.to_i
while n > 0 do
    word = gets.chomp
    if word.size > 10
        puts [word[0], word.size-2, word[-1]].join
    else
        puts word
    end
    n -= 1
end

T = gets.chomp.to_i
for i in (0...T)
  a = gets.chomp
  if(a.length > 10)
    puts a[0] + (a.length - 2).to_s + a[a.length - 1]
  else
    puts a
  end
end

1.upto(gets.to_i) do
  a = gets.chomp
  a = "#{a[0, 1]}#{a.length - 2}#{a[-1, 1]}" if a.length > 10

  puts a
end

gets.chomp.to_i.times do
    word = gets.chomp
    if word.length > 10
        print word[0], ((word.length)-2).to_s, word[-1], "\n"
    else
        print word, "\n"
    end
end

ans=Array.new
gets.to_i.times{s=gets; s.size>11? (ans<<"#{s[0]}#{s.size-3}#{s[-2]}"):(ans<<s)};
puts ans

a = gets.split(" ")
n = a[0].to_i
for i in 1..n
  s = gets.chomp
  if(s.size > 10)
    s1 = s[0]+(s.size-2).to_s+s[s.size - 1]
    puts(s1)
  else puts(s)
  end
end

n = gets.chomp.to_i
i = 0
while i < n  do
   s = gets.chomp
   t = s.size
   if t > 10
    print s[0]
    print t - 2
    puts s[t-1]
   else
    puts s
   end
   i += 1
 end

n = gets.to_i

n.times{
  s = gets
  n = s.length-1
  if n <= 10
    puts s
   else
    puts s[0] + (n-2).to_s + s[n-1]
  end
}

a = Array.new
n = gets.to_i
n.times do
 a << gets.to_s.chop
end
a.each do |i|
 if i.size <= 10
  p i
 else
  p "#{i[0]}#{i.size-2}#{i[(i.size-1)]}"
  end
end

n = gets.chomp.to_i
(0...n).each do |i|
	word = gets.chomp
	if word.length > 4
		print word[0], (word.length - 2), word[(word.length - 1)], "\n"
	else puts word
	end
end

(gets.to_i).times do
  str=gets
   if str.length > 10 then
     str[1,str.length - 2] = (str.length - 2).to_s
   end
   puts str
 end

a = gets.to_s
d = []
b = a[0]
c = a[-1, 1]
x = a[1..-2]
s = x.size.to_i
y = s.to_s
 d << b << y << c
 if s > 10
 puts d.join
 else
 puts a
 end

n = gets.to_i

$i = 0

while $i < n
    s = gets
    if s.size < 11
        puts s
    elsif
        puts "#{s[0]}#{s.size - 3}#{s[s.size - 2]}"
    end

    $i += 1
end

n = gets.chomp.to_i
for i in(0...n)
    s = gets.chomp
    if s.length() < 10
        puts s
    else
        print s[0],s.length()-2,s[s.length()-1]
        puts
    end
end

a = gets.to_s
b = a[0]
c = a[-1]
s = a.size
x = s - 2
z = x.to_s
 if s > 10
 puts b + z + c
 else
 puts a
 end

a = gets.to_i

for arr in (1..a)
  arr = gets.to_s
  if arr.length > 10
    startLetter = arr[0]
    lastLetter = arr[arr.length - 2]
    puts arr = startLetter + (arr.length.to_i - 3).to_s + lastLetter.to_s
  else
    puts arr.to_s
  end
end

def abb ()
    n = gets.to_i
    for i in 0...n
    word = gets.to_s
    word.chomp!
        if word.length < 10
            puts word
        else
            puts "#{word[0]}#{word.length-2}#{word[-1]}"
end
end
end

abb

#!/usr/bin/env ruby
class Test
	kol = gets.chomp
	ik = kol.to_i
	for num in 1..ik
		str = gets.chomp
	if str.length > 10
	len = str.length.to_s
	temp = str[0..0] + len + str[str.length-1..str.length-1]
		puts temp
	else
		puts str
	end
	end
end

n = gets.chomp.to_i

n.times do
    s = gets.chomp
    if s.length >= 10
        p "#{s[0]}#{s.length-2}#{s[s.length-1]}"
    else
        p s
    end
end

n = gets.chomp.to_i
for i in(0...n)
    s = gets.chomp
    if s.length() < 11
        puts s
    else
        print s[0],s.length()-2,s[s.length()-1]
    end
end

n = gets.to_i
n.times do |i|
	temp = gets
	if (temp.size < 11)
		puts temp
	else
		k = temp.size - 2
		curr = temp[0] + k.to_s + temp[k]
		puts curr
	end
end

a = gets.to_s
b = a[0]
c = a[-1]
d = a[1...-2]
 if a.length > 10
 puts b + d + c
 else
 puts a
 end

array = STDIN
array.each { |x| if x.size > 10 then puts "#{x[0]}#{x.size - 2}#{x[-1]}" elsif x =~ /[0-9]/ then nil else puts x end }

counter = gets.chomp.to_i

counter.times do
  word = gets.chomp.to_s

  if word.length > 10
    word = word[0,1] + ( word.length - 2 ).to_s + word[word.length-1, 1]
  end

  p word
end

n = gets.chomp.to_i
for i in(0...n)
    s = gets.chomp
    if s.length() < 10
        puts s
    else
        puts s[0],s.length(),s[s.length()-1]
    end
end

x = gets.to_i

def check(j)
	if j.length <= 10
		puts j
	else
		puts j[0] + j.length.to_s + j[-1]
	end
end

for i in 1..x do
	y = gets.chomp
	check(y)
end

n = gets.to_i

$i = 0

while $i < n
    s = gets
    puts s.length
    if s.length < 12
        puts s
    elsif
        puts "#{s[0]}#{s.length - 3}#{s[s.length - 2]}"
    end

    $i += 1
end

#!/usr/bin/env ruby
str = ARGF.read

if str.scan(/\D/).empty?
    exit
elsif str.size <= 10
    puts str
else
    puts str[0] + (str.length - 2).to_s + str[str.length - 1]
end

n = gets.to_i
n.times do
a = gets.chomp
d = Array.new
b = a[0]
c = a[-1, 1]
x = a[1..-2]
s = x.size.to_i
 if s >= 10
 d << b << s << c
 d.map { |sammy| sammy}
 puts d.join
 else
 puts a
 end
 end

a = gets.to_i
for i in 1..a
    b = gets
    c = b.length
    c = c - 1
    if c <=4
        puts b
    else
        d = c - 2
        print b[0]
        print d
        print b[c-1]
    end
end

n = gets.split.map &:to_i
n.each do |i|
    word = gets.split.map
    if word.count > 10
        p w[0] + w.count-2 + w[-1]
    else
        p word
    end
end

string = gets.chomp
puts (string[0] + (string.length-2).to_s + string[-1])

n = gets.to_i
n.times do
a = gets.chomp
d = Array.new
b = a[0]
c = a[-1, 1]
x = a[1..-2]
s = x.size.to_i
 if s > 10
 d << b << s << c
 d.map { |sammy| sammy}
 puts d.join
 else
 puts a
 end
 end

i=gets
a=i.length
if (a <= 11)
 puts i
else
 out= i[0] + (a-2).to_s + i[a-2]
 puts out
end

c, arr = gets.to_i, []
c.times { arr << gets }

arr.map! do |w|
  w.length > 10 ? "#{w[0]}#{w.length-3}#{w[-2]}" : w
end

puts arr

n = gets.to_i

a = Array.new(n)
for i in 0..(n - 1)
  a[i] = gets.to_s
end

a.each {|b|

if b.length >= 10
  f = b.split("")[0]
  l = b.split("")[(b.length-2)]
  c = b.split("")[1..(b.length-3)].join("")
  puts "#{f}#{c.length}#{l}"
else
  puts "#{b}"
end
}

a = gets.to_s
b = a[0]
c = a[-1]
s = a.size
z = s.to_s
 if s > 10
 puts b z c
 else
 puts a
 end

a = String.new
a = gets
b = a[0]
c = a[-1]
d = a[1..-2]
 s = a.size.to_i
 if s >= 10
 puts b + d + c
 else
 puts a
 end

n = gets.split.map &:to_i
n.each do |i|
    w = gets.strip
    if w.size > 10
        puts w[0] + w.size-2 + w[-1]
    else
        puts w
    end
end

n = gets.to_i
n.times do
  s = gets.chomp
  if s.size < 10
    puts s
  else
    puts "#{s[0]}#{s.size - 2}#{s[-1]}"
  end
end

n=gets.to_i
n.times do
str=gets.chomp.to_s
puts "#{str[0]}#{str.size-2}#{str[str.size-1]}"
end

x=gets.to_i
x.times do
n=gets.chomp
z=n.length
if z > 10
print n[0]
print z-2
print n[z-1]
else
print n
end
end

x=gets.to_i
x.times do
n=gets.chomp
z=n.length
if z > 10
print n[0]
print z-2
print n[z-1]
else
print n
print "\n"
end
end

n = Integer(gets)
a = Array.new
for i in 0...n
	a[i] = gets
end
		def word_to_long(b)
			l = b.length
			if l > 10
				return b[0] + "#{l - 3}"+ b[l-2]
			else
				return b
			end
		end

	for i in 0...n
		puts word_to_long(a[i])
	end

t = gets.chomp.to_i

for i in 1..t
  s = gets.chomp
  if s.length < 5
    puts s
    next
  end
  print s[0];print s.length-2; puts s[-1]
end

line_count = gets.to_i

for i in 1..line_count
    line = gets
    if line.length > 10
        p line[0] + (line.length-2).to_s + line[-1,1]
    else
        p line
    end
end

n = gets
n.to_i.times do
    word = gets.chomp
    l = word.size
    puts l
    if l > 10
        puts "#{word[0]}#{l-2}#{word[-1]}"
    else
        puts word
    end
end

a = gets.to_s
b = a[0]
c = a[-1]
s = a.size
x = s - 2
z = x.to_s
 if x >= 10
 puts b + z + c
 else
 puts a
 end

a = gets.to_s
b = a[0]
c = a[-1]
s = a.size
x = s - 2
z = x.to_s
 if s >= 10
 puts b + z + c
 else
 puts a
 end

line_count = gets.to_i

for i in 1..line_count
    line = gets.chomp
    if line.length > 10
        p line[0] + (line.length-2).to_s + line[-1,1]
    else
        p line
    end
end

n = gets.chomp.to_i
(0...n).each do |i|
	word = gets.chomp
	if word.length >= 4
		print word[0], (word.length - 2), word[(word.length - 1)], "\n"
	else puts i
	end
end

class LongWord
  def initialize(word)
    @word = word
  end

  def short_version
    return @word if @word.size <= 10

    first_char = @word[0]
    last_char = @word[-1]
    rest_word_count = @word[1..-2].size

    "#{first_char}#{rest_word_count}#{last_char}"
  end
end

# Main
word = gets.strip
short_version = LongWord.new(word).short_version
puts short_version

n = gets.to_i
while n > 0 do
    word = gets.chomp
    if (s = word.size - 2) >= 10
        puts [word[0], s, word[-1]].join
    else
        puts word
    end
    n -= 1
end

a = Array.new
n = gets.to_i
n.times do
 a << gets.to_s.chop
end
a.each do |i|
 if i.size < 10
  p i
 else
  p "#{i[0]}#{i.size-2}#{i[(i.size-1)]}"
  end
end

#!/usr/bin/env ruby
str = gets

if str.scan(/\D/).empty?
 return
end

if str.size <= 10
    puts str
    return
end

puts str[0] + (str.length - 2).to_s + str[str.length - 1]

puts "How many words would ou like to abreviate?"
words = gets.to_i
puts "Write down below #{words} words"

abreviadas = []
for number in 1..words
	palavra = gets.strip
	tamanho = (palavra.size) -2
	if palavra.size > 10
		palavras = palavra[0] + tamanho.to_s + palavra[(palavra.size)-1]
	else
		palavras = palavra
	end
		abreviadas<<palavras
end

puts "Your words are:"

puts abreviadas

STDIN.read.split("\n").drop(1).each do |w|
  puts res =  w.size < 10 ? w : w[0] + "#{(w.size - 2)}" + w[-1]
end

a = gets.to_s
b = a[0]
c = a[-1]
s = a[1...-2].to_i
 if s >= 10
 puts b s c
 else
 puts a
 end

a = gets.split(" ")
n = a[0].to_i
for i in 1..n
  s = gets.chomp
  if(s.size > 10)
    s1 = s[0]+(s.size-2).to_s+s[s.size - 1]
    p(s1)
  else p(s)
  end
end

lines = []
while line =(ARGV.shift or (!STDIN.tty? and STDIN.gets) )
  lines.push(line)
end

puts lines

a = Array.new
n = gets.to_i
n.times do
 a << gets.to_s.chop
end
a.each do |i|
 if i.size <= 10
  p i
 else
  p "#{i[0]}#{i.size-2}#{i[(i.size-1)]}"
  end
end

num_line = gets.to_i()
num_line.times {
  str = gets()
  puts str.length()>10 ? str[0]+(str.length()-3).to_s+str[str.length()-2] : str
}

n=gets.to_i
a= []
for i in 0..n-1
	a[i] = gets
end
a.each do |val|
	len = val.length
	puts  len <= 10 ? val : "#{val[0]}#{len-3}#{val[len-2]}"
end

n=gets.to_i
a= []
for i in 0..n-1
	a[i] = gets
end
a.each do |val|
	len = val.length
	puts  len < 10 ? val : "#{val[0]}#{len-3}#{val[len-2]}"
end

a = gets.to_s
b = a[0]
c = a[-1]
s = a.size
x = s - 2
z = x.to_s
 if s > 10
 puts b + z + c
 else
 puts a
 end

x = gets.chomp.to_i

for i in 0...x do
   words = gets.chomp.to_s
   if words.length >= 10
    puts words[0].to_s + (words.length-2).to_s + words[-1]
   else
    puts words
   end
end

(gets.to_i).times do
  ss=gets
  ss[1,ss.length-3] = ss.length>10? (ss.length-3).to_s : ss[1,ss.length-3]
  puts (ss)
end

gets.chomp.to_i.times do
    a = gets.chomp
    if a.length<10
        puts a
    else
        print a[0],a.length-2,a[a.length-1],"\n"
    end
end

len = 10
n = gets.to_i
while n > 0 do
    word = gets.chomp
    if word.size > len
        p [word.chars.first, word.size-2, word.chars.last].join
    else
        p word
    end
    n -= 1
end

n = gets
n = n.to_i

for i in (1..n)
	string = gets
	if(string.size()<11)
		puts string
	else
		stringFinal = string[0]
		numero = string.size - 3
		stringFinal << numero.to_s
		stringFinal << string[string.size - 2]
		puts stringFinal
	end
end

n = STDIN.gets
while word = STDIN.gets
  word.strip!
  if word.length > 10
    puts "#{word[0,1]}#{word.length - 2}#{word[word.length-1,1]}"
  end
end

n = gets.to_i

$i = 0

while $i < n
    s = gets
    if s.size < 11
        puts s
    elsif
        puts "#{s[0]}#{s.size - 3}#{s[s.size - 2]}"
    end

    $i += 1
end

number_of_words = gets.to_i

words = []

number_of_words.times do |n|
    word = gets
    words.push(word)
end

words.each do |word|
    if word.length <= 10
        puts word
    else
        number_of_letters_between = word.length - 3
        fist_letter = word[0]
        last_letter = word[-2]
        puts "#{fist_letter}#{number_of_letters_between}#{last_letter}"
    end
end

n = gets.to_i
i = 0
y = []
while i < n
  x = gets
  if x.length > 10
    x[1...x.length-2] = (x.length-2).to_s
  end
  y << x
  i +=1
end

puts y

gets.chomp.to_i.times do
    word = gets.chomp
    if word.length >= 10
        print word[0], ((word.length)-2).to_s, word[-1], "\n"
    else
        print word, "\n"
    end
end

n = gets.to_i

words = []

n.times do
	curr = gets

	if curr.length > 10
		last = curr[curr.length - 2, 1]
		curr = curr[0] + (curr.length - 3).to_s
		curr = curr + last
	end

	words << curr
end

puts words

len = gets.to_i

while word = gets do
    word = word.chomp
    if word.size > len
        p [word.chars.first, word.size-2, word.chars.last].join
    else
        p word
    end
end

a = gets
b = []
c = a[0]
b << c
d = a[1..-2].length
b << d
e = a[-1]
b << e
f = b.join

if d > 10
puts f

else
puts a

end

(gets.to_i).times do
  str = gets
   if str.length > 10 then
     str= str[0..0] + (str.length - 2).to_s + str[-1..-1]
   end
   p str
end

number_of_words = gets.to_i

words = []

number_of_words.times do |n|
    word = gets
    words.push(word)
end

words.each do |word|
    if word.length < 10
        puts word
    else
        number_of_letters_between = word.length - 3
        fist_letter = word[0]
        last_letter = word[-2]
        puts "#{fist_letter}#{number_of_letters_between}#{last_letter}"
    end
end

n = gets.chomp.to_i
for i in(0...n)
    s = gets.chomp
    if s.length() < 10
        puts s
    else
        print s[0],s.length()-2,s[s.length()-1]
        puts
    end
end

n=gets.chomp.to_i.times{a=gets.chomp.to_s;o=a.length;if o>10 then printf("%c%d%c",a[0],o-2,a[o-1]);else puts(a)end}

n=gets.to_i
a= []
for i in 0..n-1
	a[i] = gets
end
a.each do |val|
	len = val.length
	puts  len <= 10 ? val : "#{val[0]}#{len-3}#{val[len-2]}"
end

array = STDIN
array.each { |x| if x.size > 10 then puts "#{x[0]}#{x.size - 2}#{x[-1]}" elsif x =~ /[0-9]/ then nil else puts x end }

n = gets.to_i
i = 0
y = []
while i < n
  x = gets
  if x.length > 10
    x[1...x.length-2] = (x.length-3).to_s
  end
  y << x
  i +=1
end

puts y

array = [4, "word", "localization", "internationalization", "pneumonoultramicroscopicsilicovolcanoconiosis"]
array.each { |x| if x.size > 10 then puts "#{x[0]}#{x.size - 2}#{x[-1]}" elsif x == x.to_s then puts x end }

n = gets.to_i
a =[]
for i in 0..n-1 do
  a = a + [gets]
  if a[i].size >= 10
    a[i] = (a[i][0] + (a[i].size - 3).to_s + a[i][a[i].size - 2])
  end
end
puts a

x = gets.to_i

def check(j)
	if j.length <= 10
		puts j
	else
		puts j[0] + j.length.to_s + j[-1]
	end
end

for i in 1..x do
	y = gets.chomp
	check(y)
end

x=gets.to_i
x.times do
n=gets.chomp
z=n.length
if z > 10
print n[0]
print z-2
print n[z-1]
else
print n
print "\n"
end
end

b = /[0-9]/
x = gets.chomp
if x.size > 10
  puts "#{x[0]}#{x.size - 2}#{x[-1]}"
elsif x =~ /[0-9]/
 nil
else
  puts x
end

a = gets.to_s
b = a[0]
c = a[-1]
s = a.size
 if s >= 12
 puts b
 puts s
 puts c
 else
 puts a
 end

n = gets.to_i
n.times do |i|
	temp = gets
	if (temp.size < 11)
		puts temp
	else
		k = temp.size - 2
		curr = temp[0] + k.to_s + temp[k]
		puts curr
	end
end

a = gets.to_s
b = a[0]
c = a[-1]
s = a.size
x = s - 2
z = x.to_s
 if x >= 10
 puts b + z + c
 else
 puts a
 end

n = gets.chomp.to_i

n.times do
    s = gets.chomp
    if s.length >= 10
        p "#{s[0]}#{s.length-2}#{s[s.length-1]}"
    else
        p s
    end
end

def abb ()
    n = gets.to_i
  words = Array.new(n)
    for i in 0...n
      word = gets.to_s
      words[i] = word.chomp!
    end
  words.each{ |word|
        if word.length < 10
            puts word
        else
            puts "#{word[0]}#{word.length-2}#{word[-1]}"
        end
  }
end

abb

gets.to_i.times do
  s=gets
  puts s.size>10 ? "#{s[0]}#{s.size-1}#{s[-1]}": s
end


On the well-known testing system MathForces, a draw of $$$n$$$ rating units is arranged. The rating will be distributed according to the following algorithm: if $$$k$$$ participants take part in this event, then the $$$n$$$ rating is evenly distributed between them and rounded to the nearest lower integer, At the end of the drawing, an unused rating may remain — it is not given to any of the participants.For example, if $$$n = 5$$$ and $$$k = 3$$$, then each participant will recieve an $$$1$$$ rating unit, and also $$$2$$$ rating units will remain unused. If $$$n = 5$$$, and $$$k = 6$$$, then none of the participants will increase their rating.Vasya participates in this rating draw but does not have information on the total number of participants in this event. Therefore, he wants to know what different values of the rating increment are possible to get as a result of this draw and asks you for help.For example, if $$$n=5$$$, then the answer is equal to the sequence $$$0, 1, 2, 5$$$. Each of the sequence values (and only them) can be obtained as $$$\lfloor n/k \rfloor$$$ for some positive integer $$$k$$$ (where $$$\lfloor x \rfloor$$$ is the value of $$$x$$$ rounded down): $$$0 = \lfloor 5/7 \rfloor$$$, $$$1 = \lfloor 5/5 \rfloor$$$, $$$2 = \lfloor 5/2 \rfloor$$$, $$$5 = \lfloor 5/1 \rfloor$$$.Write a program that, for a given $$$n$$$, finds a sequence of all possible rating increments.

The first line contains integer number $$$t$$$ ($$$1 \le t \le 10$$$) — the number of test cases in the input. Then $$$t$$$ test cases follow. Each line contains an integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the total number of the rating units being drawn.

Output the answers for each of $$$t$$$ test cases. Each answer should be contained in two lines. In the first line print a single integer $$$m$$$ — the number of different rating increment values that Vasya can get. In the following line print $$$m$$$ integers in ascending order — the values of possible rating increments.

#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']

require 'prime'

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

def big(a,b) return (a>b)? a:b end

def small(a,b) return (a<b)? a:b end

t = inp[0]
t.times do
  n = inp[0]
  ans = []
  (0...((n**0.5).ceil)).each do |d|
    ans.push(d)
  end
  mae = ans[-1]
  (1..((n**0.5).ceil)).reverse_each do |d|
    if n/d > mae
      mae = n/d
      ans.push(mae)
    end
  end
  p ans.size
  puts ans.join(" ")
end

gets.strip.to_i.times {
	n = gets.strip.to_i
	sq = Math.sqrt(n).to_i
	an = []
	sq.times { |i|
		an << i + 1
		an << n / (i + 1)
	}
	an << 0
	an = an.uniq.sort
	puts an.size
	puts an.join(' ')
}

#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']

require 'prime'

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

def big(a,b) return (a>b)? a:b end

def small(a,b) return (a<b)? a:b end

t = inp[0]
t.times do
  n = inp[0]
  mae = 0
  mae = 1
  ans = [0,1]
  (1..((n**0.5).ceil)).reverse_each do |d|
    if n/d > mae
      mae = n/d
      ans.push(mae)
    end
  end
  puts ans.size
  puts ans.join(" ")
end

gets.strip.to_i.times {
	n = gets.strip.to_i
	sq = Math.sqrt(n).to_i
	an = []
	sq.times { |i|
		next if i == 0
		an << i
		an << n / i
	}
	an << 0
	puts an.size
	print an.uniq.sort.join(' ')
}

gets.strip.to_i.times {
	n = gets.strip.to_i
	sq = Math.sqrt(n).to_i
	an = []
	sq.times { |i|
		next if i == 0
		an << i
		an << n / i
	}
	an << 0
	puts an.uniq.sort.join(' ')
}

gets.strip.to_i.times {
	n = gets.strip.to_i
	sq = Math.sqrt(n).to_i
	an = []
	sq.times { |i|
		an << i + 1
		an << n / (i + 1)
	}
	an << 0
	puts an.size
	puts an.uniq.sort.join(' ')
}


Bertown is a city with $$$n$$$ buildings in a straight line.The city's security service discovered that some buildings were mined. A map was compiled, which is a string of length $$$n$$$, where the $$$i$$$-th character is "1" if there is a mine under the building number $$$i$$$ and "0" otherwise.Bertown's best sapper knows how to activate mines so that the buildings above them are not damaged. When a mine under the building numbered $$$x$$$ is activated, it explodes and activates two adjacent mines under the buildings numbered $$$x-1$$$ and $$$x+1$$$ (if there were no mines under the building, then nothing happens). Thus, it is enough to activate any one mine on a continuous segment of mines to activate all the mines of this segment. For manual activation of one mine, the sapper takes $$$a$$$ coins. He can repeat this operation as many times as you want.Also, a sapper can place a mine under a building if it wasn't there. For such an operation, he takes $$$b$$$ coins. He can also repeat this operation as many times as you want.The sapper can carry out operations in any order.You want to blow up all the mines in the city to make it safe. Find the minimum number of coins that the sapper will have to pay so that after his actions there are no mines left in the city.

The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Then $$$t$$$ test cases follow. Each test case begins with a line containing two integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 1000$$$) — the cost of activating and placing one mine, respectively. The next line contains a map of mines in the city — a string consisting of zeros and ones. The sum of the string lengths for all test cases does not exceed $$$10^5$$$.

For each test case, output one integer — the minimum number of coins that the sapper will have to pay.

NoteIn the second test case, if we place a mine under the fourth building and then activate it, then all mines on the field are activated. The cost of such operations is six, $$$b=1$$$ coin for placing a mine and $$$a=5$$$ coins for activating.

t = gets.chomp.to_i
t.times do
  a, b = gets.chomp.split(' ').map(&:to_i)
  s = gets.chomp.split('')
  del = []
  cur = 0
  s.each do |el|
    if el == '1'
      del << cur if cur > 0
      cur = 0
    else
      cur += 1
    end
  end
  del.shift if s[0] == '0'

  sum = a
  del.each do |el|
    sum += [a, b * el].min
  end
  if s.count('1') >= 1
    puts sum
  else
    puts 0
  end
end

t = gets.chomp.to_i
t.times do
    a, b = gets.chomp.split(" ").map(&:to_i)
    x = gets.chomp.split("")
    ookisa = x.size
    dp = Array.new(ookisa+1,Float::INFINITY)
    dp[0] = 0
    cost = 0
    i = 1
    renzoku = 0
    zero = 0
    first = 0
    until x == []
        me = x.shift
        #p me
        #p renzoku
        if me == "1"
           #p renzoku
            if renzoku >= 1
                dp[i] = dp[i-1]
            else
                #p dp
                #p zero
                if first >= 1
                    dp[i] = [zero*b+dp[i-1],dp[i-1]+a].min
                else
                    dp[i] = a
                    first += 1
                end
            end
            # p renzoku
            # p zero
            zero = 0
            renzoku += 1
        else
            zero += 1
            renzoku = 0
            dp[i] = dp[i-1]
        end
        i += 1
        #p zero
        #p dp
    end
    puts dp.pop
end

t = gets.chomp.to_i
t.times do
  a, b = gets.chomp.split(' ').map(&:to_i)
  s = gets.chomp.split('')
  del = []
  cur = 0
  s.each do |el|
    if el == '1'
      del << cur if cur > 0
      cur = 0
    else
      cur += 1
    end
  end
  del.shift if s[0] == '0'

  sum = a
  del.each do |el|
    sum += [a, b * el].min
  end
  if s.count('1') > 1
    puts sum
  else
    puts 0
  end
end

t = gets.chomp.to_i
t.times do
  a, b = gets.chomp.split(' ').map(&:to_i)
  s = gets.chomp.split('')
  del = []
  cur = 0
  s.each do |el|
    if el == '1'
      del << cur if cur > 0
      cur = 0
    else
      cur += 1
    end
  end
  puts "s = " + s.to_s
  del.shift if s[0] == '0'

  sum = a
  del.each do |el|
    sum += [a, b * el].min
  end
  if s.count('1') >= 1
    puts sum
  else
    puts 0
  end
end


Polycarp loves geometric progressions very much. Since he was only three years old, he loves only the progressions of length three. He also has a favorite integer k and a sequence a, consisting of n integers.He wants to know how many subsequences of length three can be selected from a, so that they form a geometric progression with common ratio k.A subsequence of length three is a combination of three such indexes i1, i2, i3, that 1 ≤ i1 < i2 < i3 ≤ n. That is, a subsequence of length three are such groups of three elements that are not necessarily consecutive in the sequence, but their indexes are strictly increasing.A geometric progression with common ratio k is a sequence of numbers of the form b·k0, b·k1, ..., b·kr - 1.Polycarp is only three years old, so he can not calculate this number himself. Help him to do it.

The first line of the input contains two integers, n and k (1 ≤ n, k ≤ 2·105), showing how many numbers Polycarp's sequence has and his favorite number. The second line contains n integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109) — elements of the sequence.

Output a single number — the number of ways to choose a subsequence of length three, such that it forms a geometric progression with a common ratio k.

NoteIn the first sample test the answer is four, as any of the two 1s can be chosen as the first element, the second element can be any of the 2s, and the third element of the subsequence must be equal to 4.

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

rs = Hash.new(0)
ls = Hash.new(0)

ls[as[0]] += 1

for i in 1..n-1
  rs[as[i]] += 1
end

cnt = 0
for i in 1..n-2
  a = as[i]
  rs[a] -= 1
  cnt += ls[a/k] * rs[a*k] if a % k == 0
  ls[a] += 1
end

puts cnt

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

rs = Hash.new(0)
ls = Hash.new(0)

ls[as[0]] += 1

for i in 2..n-1
  rs[as[i]] += 1
end

cnt = 0
for i in 1..n-2
  a = as[i]
  if a % k == 0
    cnt += ls[a/k] * rs[a*k]
  end
  ls[a] += 1
  rs[a] -= 1
end

puts cnt


Recently Polycarpus has learned the "bitwise AND" operation (which is also called "AND") of non-negative integers. Now he wants to demonstrate the school IT teacher his superb manipulation with the learned operation.For that Polycarpus came to school a little earlier and wrote on the board a sequence of non-negative integers a1, a2, ..., an. He also wrote a square matrix b of size n × n. The element of matrix b that sits in the i-th row in the j-th column (we'll denote it as bij) equals:  the "bitwise AND" of numbers ai and aj (that is, bij = ai & aj), if i ≠ j;  -1, if i = j. Having written out matrix b, Polycarpus got very happy and wiped a off the blackboard. But the thing is, the teacher will want this sequence to check whether Polycarpus' calculations were correct. Polycarus urgently needs to restore the removed sequence of integers, or else he won't prove that he can count correctly.Help Polycarpus, given matrix b, restore the sequence of numbers a1, a2, ..., an, that he has removed from the board. Polycarpus doesn't like large numbers, so any number in the restored sequence mustn't exceed 109.

The first line contains a single integer n (1 ≤ n ≤ 100) — the size of square matrix b. Next n lines contain matrix b. The i-th of these lines contains n space-separated integers: the j-th number represents the element of matrix bij. It is guaranteed, that for all i (1 ≤ i ≤ n) the following condition fulfills: bii = -1. It is guaranteed that for all i, j (1 ≤ i, j ≤ n; i ≠ j) the following condition fulfills: 0 ≤ bij ≤ 109, bij = bji.

Print n non-negative integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the sequence that Polycarpus wiped off the board. Separate the numbers by whitespaces.  It is guaranteed that there is sequence a that satisfies the problem conditions. If there are multiple such sequences, you are allowed to print any of them.

NoteIf you do not know what is the "bitwise AND" operation please read: http://en.wikipedia.org/wiki/Bitwise_operation.

gets.to_i.times{
  a=gets.split.map(&:to_i)-[-1]
  ans=a.inject(0,:|)
  print ans.to_s+' '
}

gets.to_i.times{
  a=gets.split.map(&:to_i)-[-1]
  p a.inject(0,:|)
}

gets.to_i.times{
  a=gets.split.map(&:to_i)-[-1]
  ans=a.inject(:|)
  print ans.to_s+' '
}


Mahmoud and Ehab are on the third stage of their adventures now. As you know, Dr. Evil likes sets. This time he won't show them any set from his large collection, but will ask them to create a new set to replenish his beautiful collection of sets.Dr. Evil has his favorite evil integer x. He asks Mahmoud and Ehab to find a set of n distinct non-negative integers such the bitwise-xor sum of the integers in it is exactly x. Dr. Evil doesn't like big numbers, so any number in the set shouldn't be greater than 106.

The only line contains two integers n and x (1 ≤ n ≤ 105, 0 ≤ x ≤ 105) — the number of elements in the set and the desired bitwise-xor, respectively.

If there is no such set, print "NO" (without quotes). Otherwise, on the first line print "YES" (without quotes) and on the second line print n distinct integers, denoting the elements in the set is any order. If there are multiple solutions you can print any of them.

NoteYou can read more about the bitwise-xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XORFor the first sample .For the second sample .

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

z = 1 << 18

case n
	when 1
		puts "YES\n" + x.to_s
	when 2
		puts x != 0 ? "YES\n" + x.to_s + " 0" : "NO"
	else
		puts "YES"

		sum = 0
		1.upto(n - 3) do |i|
			print i, " "
			sum ^= i
		end

		if sum == x
			print z, " ", z << 1, " ", z ^ z << 1
		else
			print 0, " ", z + x, " ", z + sum
		end
end

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

z = 1 << 18

case n
	when 1
		puts "YES\n" + x.to_s
	when 2
		puts x != 0 ? "YES\n" + x.to_s + "0" : "NO"
	else
		puts "YES"

		sum = 0
		1.upto(n - 3) do |i|
			print i, " "
			sum ^= i
		end

		if sum == x
			print z, " ", z << 1, " ", z ^ z << 1
		else
			print 0, " ", z + x, " ", z + sum
		end
end


RedDreamer has an array $$$a$$$ consisting of $$$n$$$ non-negative integers, and an unlucky integer $$$T$$$.Let's denote the misfortune of array $$$b$$$ having length $$$m$$$ as $$$f(b)$$$ — the number of pairs of integers $$$(i, j)$$$ such that $$$1 \le i < j \le m$$$ and $$$b_i + b_j = T$$$. RedDreamer has to paint each element of $$$a$$$ into one of two colors, white and black (for each element, the color is chosen independently), and then create two arrays $$$c$$$ and $$$d$$$ so that all white elements belong to $$$c$$$, and all black elements belong to $$$d$$$ (it is possible that one of these two arrays becomes empty). RedDreamer wants to paint the elements in such a way that $$$f(c) + f(d)$$$ is minimum possible.For example:  if $$$n = 6$$$, $$$T = 7$$$ and $$$a = [1, 2, 3, 4, 5, 6]$$$, it is possible to paint the $$$1$$$-st, the $$$4$$$-th and the $$$5$$$-th elements white, and all other elements black. So $$$c = [1, 4, 5]$$$, $$$d = [2, 3, 6]$$$, and $$$f(c) + f(d) = 0 + 0 = 0$$$;  if $$$n = 3$$$, $$$T = 6$$$ and $$$a = [3, 3, 3]$$$, it is possible to paint the $$$1$$$-st element white, and all other elements black. So $$$c = [3]$$$, $$$d = [3, 3]$$$, and $$$f(c) + f(d) = 0 + 1 = 1$$$. Help RedDreamer to paint the array optimally!

The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains two integers $$$n$$$ and $$$T$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le T \le 10^9$$$) — the number of elements in the array and the unlucky integer, respectively.  The second line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($$$0 \le a_i \le 10^9$$$) — the elements of the array.  The sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For each test case print $$$n$$$ integers: $$$p_1$$$, $$$p_2$$$, ..., $$$p_n$$$ (each $$$p_i$$$ is either $$$0$$$ or $$$1$$$) denoting the colors. If $$$p_i$$$ is $$$0$$$, then $$$a_i$$$ is white and belongs to the array $$$c$$$, otherwise it is black and belongs to the array $$$d$$$. If there are multiple answers that minimize the value of $$$f(c) + f(d)$$$, print any of them.

T = gets.to_i

T.times do
  n, t = gets.split.map(&:to_i)
  a = gets.split.map(&:to_i)
  ans = Array.new(n, 0)
  counter_0 = Hash.new(0)
  counter_1 = Hash.new(0)
  z = (t % 2 == 0) ? t / 2 : -1

  a.each_with_index do |x, idx|
    y = t - x

    if y == z
      if counter_0[y] < counter_1[y]
        counter_0[y] += 1
      else
        counter_1[y] += 1
        ans[idx] = 1
      end
    else
      if counter_0[y] > 0
        counter_1[x] += 1
        ans[idx] = 1
      else
        counter_0[x] += 1
      end
    end
  end

  puts ans.join(' ')
end


Marian is at a casino. The game at the casino works like this.Before each round, the player selects a number between $$$1$$$ and $$$10^9$$$. After that, a dice with $$$10^9$$$ faces is rolled so that a random number between $$$1$$$ and $$$10^9$$$ appears. If the player guesses the number correctly their total money is doubled, else their total money is halved. Marian predicted the future and knows all the numbers $$$x_1, x_2, \dots, x_n$$$ that the dice will show in the next $$$n$$$ rounds. He will pick three integers $$$a$$$, $$$l$$$ and $$$r$$$ ($$$l \leq r$$$). He will play $$$r-l+1$$$ rounds (rounds between $$$l$$$ and $$$r$$$ inclusive). In each of these rounds, he will guess the same number $$$a$$$. At the start (before the round $$$l$$$) he has $$$1$$$ dollar.Marian asks you to determine the integers $$$a$$$, $$$l$$$ and $$$r$$$ ($$$1 \leq a \leq 10^9$$$, $$$1 \leq l \leq r \leq n$$$) such that he makes the most money at the end.Note that during halving and multiplying there is no rounding and there are no precision errors. So, for example during a game, Marian could have money equal to $$$\dfrac{1}{1024}$$$, $$$\dfrac{1}{128}$$$, $$$\dfrac{1}{2}$$$, $$$1$$$, $$$2$$$, $$$4$$$, etc. (any value of $$$2^t$$$, where $$$t$$$ is an integer of any sign).

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 2\cdot 10^5$$$) — the number of rounds. The second line of each test case contains $$$n$$$ integers $$$x_1, x_2, \dots, x_n$$$ ($$$1 \leq x_i \leq 10^9$$$), where $$$x_i$$$ is the number that will fall on the dice in the $$$i$$$-th round. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot10^5$$$.

For each test case, output three integers $$$a$$$, $$$l$$$, and $$$r$$$ such that Marian makes the most amount of money gambling with his strategy. If there are multiple answers, you may output any of them.

NoteFor the first test case, the best choice is $$$a=4$$$, $$$l=1$$$, $$$r=5$$$, and the game would go as follows.   Marian starts with one dollar.  After the first round, he ends up with $$$2$$$ dollars because the numbers coincide with the chosen one.  After the second round, he ends up with $$$4$$$ dollars because the numbers coincide again.  After the third round, he ends up with $$$2$$$ dollars because he guesses $$$4$$$ even though $$$3$$$ is the correct choice.  After the fourth round, he ends up with $$$4$$$ dollars again.  In the final round, he ends up $$$8$$$ dollars because he again guessed correctly. There are many possible answers for the second test case, but it can be proven that Marian will not end up with more than $$$2$$$ dollars, so any choice with $$$l = r$$$ with the appropriate $$$a$$$ is acceptable.

gets.to_i.times do
  n = gets.to_i
  a = gets.split.map(&:to_i)
  vis = Array.new(n, false)

  l = 1
  cnt = 1
  max = 1

  num = a[0]
  a_l = 0
  a_r = 0

  n_l = nil
  n_r = 0

  while l < n
    next l += 1 if vis[l-1] && vis[l]
    if a[l-1] == a[l]
      n_l ||= l-1
      n_r = l
      cnt += 1
    else
      if cnt > 1
        r = l
        cnt1 = cnt
        while r < n
          if a[r] == a[n_l]
            vis[r] = true
            cnt1 += 1
          else
            cnt1 -= 1
          end
          if cnt1 > cnt
            cnt = cnt1
            n_r = r
          end
          break if cnt1 <= 0
          r += 1
        end
      end
      if cnt > max
        a_l = n_l
        a_r = n_r
        max = cnt
        num = a[a_l]
      end
      n_l = nil
      n_r = 0
      cnt = 1
    end
    l += 1
  end
  if cnt > max
    a_l = n_l
    a_r = n_r
    max = cnt
    num = a[n_l]
  end

  puts [num, a_l+1, a_r+1].join(" ")
end

gets.to_i.times do
  n = gets.to_i
  a = gets.split.map(&:to_i)
  index = {}

  a.each_with_index do |e, i|
    index[e] ||= []
    index[e] << i
  end

  cnt = 1

  ans = a[0]
  l = 1
  r = 1
  index.each do |k, v|
    sum = 1
    first = v[0]
    prev = v[0]

    v[1..].each do |i|
      sum = sum-(i-prev)+2
      prev = i
      if sum < 1
        sum = 1
        first = i
      end

      if cnt < sum
        cnt = sum
        ans = k
        l = first+1
        r = i+1
      end
    end
  end

  puts [ans, l, r].join(" ")
end

t = gets.to_i
t.times do
  n = gets.to_i
  x = gets.split.map(&:to_i)
  indices = {}
  x.each_with_index do |a, i|
    (indices[a] ||= []) << i
  end

  ans = 1
  ans_value = [x[0], 1, 1]
  indices.each do |a, row|
    b = [1]
    row.each_cons(2) do |i, j|
      b << (i - j + 1) << 1
    end

    l = 0
    sum = 0
    b.each_with_index do |x, r|
      if sum < 0
        l = r
        sum = x
      else
        sum += x
      end
      if sum > ans
        ans = sum
        ans_value = [a, row[l / 2] + 1, row[r / 2] + 1]
      end
    end
  end

  puts ans_value.join(" ")
end

main = -> {
    t = int
    t.times do
        n = int
        a = ints

        indices = {}
        a.each_with_index do |x, i|
            (indices[x] ||= []) << i
        end

        ans = 1
        ans_value = [a[0], 1, 1]
        indices.each do |x, row|
            sum = 1
            first = row[0]
            prev = row[0]
            row[1..].each do |i|
                sum = sum - (i - prev) + 2
                prev = i
                # p [x, first, i, sum]
                if sum < 1
                    sum = 1
                    first = i
                end
                if ans < sum
                    ans = sum
                    ans_value = [x, first + 1, i + 1]
                end
            end
        end

        puts ans_value * " "
    end
}

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

require "set"
require "prime"

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

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

class TrueClass
  include Boolean
  def to_i; 1 end
end

class FalseClass
  include Boolean
  def to_i; 0 end
end

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

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

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

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

main[]

gets.to_i.times do
  gets
  xs = gets.split.map(&:to_i)
  last = {}
  dp = [0] * xs.size
  xs.each.with_index do |x, i|
    if y = last[x]
      dp[i] = [dp[y] - (i - y) + 2, 1].max
    else
      dp[i] = 1
    end
    last[x] = i
  end
  max = dp.max
  l = r = dp.index(max)
  a = xs[l]
  count = 1
  until count == max
    l -= 1
    count += xs[l] == a ? 1 : -1
  end
  puts "#{a} #{l + 1} #{r + 1}"
end

gets.to_i.times do
  n = gets.to_i
  a = gets.split.map(&:to_i)
  vis = Array.new(n, false)

  l = 1
  cnt = 1
  max = 1

  num = a[0]
  a_l = 0
  a_r = 0

  n_l = nil
  n_r = 0

  while l < n
    next l += 1 if vis[l-1] && vis[l]
    if a[l-1] == a[l]
      n_l ||= l-1
      n_r = l
      cnt += 1
    else
      if cnt > 1
        r = l
        cnt1 = cnt
        while r < n
          if a[r] == a[n_l]
            vis[r] = true
            cnt1 += 1
          else
            cnt1 -= 1
          end
          if cnt1 > cnt
            cnt = cnt1
            n_r = r
          end
          break if cnt1 <= 0
          r += 1
        end
      end
      if cnt > max
        a_l = n_l
        a_r = n_r
        max = cnt
      end
      n_l = nil
      n_r = 0
      cnt = 1
    end
    l += 1
  end
  if cnt > max
    a_l = n_l
    a_r = n_r
    max = cnt
    num = a[n_l]
  end

  puts [num, a_l+1, a_r+1].join(" ")
end

gets.to_i.times do
  n = gets.to_i
  a = gets.split.map(&:to_i)
  vis = Array.new(n, false)

  l = 1
  cnt = 1
  max = 1

  num = a[0]
  a_l = 0
  a_r = 0

  n_l = nil
  n_r = 0

  while l < n
    next l += 1 if vis[l]
    vis[l] = true

    if a[l-1] == a[l]
      n_l ||= l-1
      n_r = l
      cnt += 1
    else
      if cnt > 1
        r = l
        cnt1 = cnt
        while r < n
          if a[r] == a[l-1]
            vis[r] = true
            cnt1 += 1
          else
            cnt1 -= 1
          end
          if cnt1 > cnt
            cnt = cnt1
            n_r = r
          end
          break if cnt1 <= 0
          r += 1
        end
      end
      if cnt > max
        a_l = n_l
        a_r = n_r
        max = cnt
        num = a[l-1]
      end
      n_l = nil
      n_r = 0
      cnt = 1
    end
    l += 1
  end
  if cnt > max
    a_l = n_l
    a_r = n_r
    max = cnt
    num = a[n_l]
  end

  puts [num, a_l+1, a_r+1].join(" ")
end

gets.to_i.times do
  n = gets.to_i
  a = gets.split.map(&:to_i)
  vis = Array.new(n, false)

  l = 1
  cnt = 1
  max = 1

  num = a[0]
  a_l = 0
  a_r = 0

  n_l = nil
  n_r = 0

  while l < n
    next l += 1 if vis[l]
    vis[l] = true

    if a[l-1] == a[l]
      n_l ||= l-1
      n_r = l
      cnt += 1
    else
      if cnt > 1
        r = l
        cnt1 = cnt
        while r < n
          if a[r] == a[l-1]
            vis[r] = true
            cnt1 += 1
          else
            cnt1 -= 1
          end
          if cnt1 > cnt
            cnt = cnt1
            n_r = r
          end
          break if cnt1 < 0
          r += 1
        end
      end
      if cnt > max
        a_l = n_l
        a_r = n_r
        max = cnt
        num = a[l-1]
      end
      n_l = nil
      n_r = 0
      cnt = 1
    end
    l += 1
  end
  if cnt > max
    a_l = n_l
    a_r = n_r
    max = cnt
    num = a[n_l]
  end

  puts [num, a_l+1, a_r+1].join(" ")
end

gets.to_i.times do
  n = gets.to_i
  a = gets.split.map(&:to_i)
  vis = Array.new(n, false)

  l = 1
  cnt = 0
  max = 0
  num = -1

  n_l = nil
  n_r = 0

  a_l = -1
  a_r = -1

  while l < n
    next l += 1 if vis[l]
    vis[l] = true

    if a[l-1] == a[l]
      n_l ||= l-1
      n_r = l
      cnt += 1
    else
      if cnt > 0
        r = l
        cnt1 = cnt
        while r < n
          if a[r] == a[l-1]
            vis[r] = true
            cnt1 += 1
          else
            cnt1 -= 1
          end
          if cnt1 > cnt
            cnt = cnt1
            n_r = r
          end
          break if cnt1 < 0
          r += 1
        end
      end
      if cnt > max
        a_l = n_l
        a_r = n_r
        max = cnt
        num = a[l-1]
      end
      n_l = nil
      n_r = 0
      cnt = 0
    end
    l += 1
  end
  if cnt > max
    a_l = n_l
    a_r = n_r
    max = cnt
    num = a[n_l]
  end

  if n == 1 || num == -1
    num = a[0]
    a_l = 0
    a_r = 0
  end
  puts [num, a_l+1, a_r+1].join(" ")
end

gets.to_i.times do
  n = gets.to_i
  a = gets.split.map(&:to_i)
  vis = Array.new(n, false)

  l = 1
  cnt = 0
  max = 0
  num = -1

  n_l = nil
  n_r = 0

  a_l = -1
  a_r = -1

  while l < n
    next l += 1 if vis[l]
    vis[l] = true

    if a[l-1] == a[l]
      n_l ||= l-1
      n_r = l
      cnt += 1
    else
      if cnt > 0
        r = l
        cnt1 = cnt
        while r < n
          if a[r] == a[l-1]
            vis[r] = true
            cnt1 += 1
          else
            cnt1 -= 1
          end
          if cnt1 > cnt
            cnt = cnt1
            n_r = r
          end
          break if cnt1 < 0
          r += 1
        end
      end
      if cnt > max
        a_l = n_l
        a_r = n_r
        max = cnt
        num = a[l-1]
      end
      n_l = nil
      n_r = 0
      cnt = 0
    end
    l += 1
  end
  if cnt > max
    a_l = n_l
    a_r = n_r
    max = cnt
    num = a[l-1]
  end
  if n == 1 || num == -1
    num = a[0]
    a_l = 0
    a_r = 0
  end
  puts [num, a_l+1, a_r+1].join(" ")
end

gets.to_i.times do
  n = gets.to_i
  a = gets.split.map(&:to_i)
  vis = Array.new(n, false)

  l = 1
  cnt = 0
  max = 0
  num = 0

  n_l = nil
  n_r = 0

  a_l = -1
  a_r = -1

  while l < n
    next l += 1 if vis[l]
    vis[l] = true

    if a[l-1] == a[l]
      n_l ||= l-1
      cnt += 1
    else
      if cnt > 0
        r = l
        n_r = r-1
        cnt1 = cnt
        while r < n
          if a[r] == a[l-1]
            vis[r] = true
            cnt1 += 1
          else
            cnt1 -= 1
          end
          if cnt1 > cnt
            cnt = cnt1
            n_r = r
          end
          break if cnt1 < 0
          r += 1
        end
      end
      if cnt > max
        a_l = n_l
        a_r = n_r
        max = cnt
        num = a[l-1]
      end
      n_l = nil
      n_r = 0
      cnt = 0
    end
    l += 1
  end
  if n == 1 || a_l == -1
    num = a[0]
    a_l = 0
    a_r = 0
  end
  puts [num, a_l+1, a_r+1].join(" ")
end

t = gets.to_i
t.times do
  n = gets.to_i
  x = gets.split.map(&:to_i)
  indices = {}
  x.each_with_index do |a, i|
    (indices[a] ||= []) << i
  end

  ans = 1
  ans_value = [x[0], 1, 1]
  indices.each do |a, row|
    b = [1]
    row.each_cons(2) do |i, j|
      b << (i - j + 1) << 1
    end

    l = 0
    sum = 1
    b.each_with_index do |x, r|
      if sum < 0
        l = r
        sum = x
      else
        sum += x
      end
      if sum > ans
        ans = sum
        ans_value = [a, row[l / 2] + 1, row[r / 2] + 1]
      end
    end
  end

  p ans
  puts ans_value.join(" ")
end

t = gets.to_i
t.times do
  n = gets.to_i
  x = gets.split.map(&:to_i)
  indices = {}
  x.each_with_index do |a, i|
    (indices[a] ||= []) << i
  end

  ans = 1
  ans_value = [x[0], 1, 1]
  indices.each do |a, row|
    b = [1]
    row.each_cons(2) do |i, j|
      b << (i - j + 1) << 1
    end

    l = 0
    sum = 1
    b.each_with_index do |x, r|
      if sum < 0
        l = r
        sum = x
      else
        sum += x
      end
      if sum > ans
        ans = sum
        ans_value = [a, row[l / 2] + 1, row[r / 2] + 1]
      end
    end
  end

  puts ans_value.join(" ")
end

t = gets.to_i
t.times do
  n = gets.to_i
  x = gets.split.map(&:to_i)
  indices = {}
  x.each_with_index do |a, i|
    (indices[a] ||= []) << i
  end

  ans = 0
  ans_value = nil
  indices.each do |a, row|
    b = [1]
    row.each_cons(2) do |i, j|
      b << (i - j + 1) << 1
    end

    l = 0
    sum = 1
    b.each_with_index do |x, r|
      if sum < 0
        l = r
        sum = x
      else
        sum += x
      end
      if sum > ans
        ans = sum
        ans_value = [a, row[l / 2] + 1, row[r / 2] + 1]
      end
    end
  end

  puts ans_value.join(" ")
end

t = gets.to_i
t.times do
  n = gets.to_i
  x = gets.split.map(&:to_i)
  indices = {}
  x.each_with_index do |a, i|
    (indices[a] ||= []) << i
  end

  ans = 0
  ans_value = nil
  indices.each do |a, row|
    b = [1]
    row.each_cons(2) do |i, j|
      b << (j - i + 1) << 1
    end

    l = 0
    sum = 1
    b.each_with_index do |x, r|
      if sum < 0
        l = r
	sum = x
      else
        sum += x
      end
      if sum > ans
        ans = sum
	ans_value = [a, row[l / 2] + 1, row[r / 2] + 1]
      end
    end
  end

  puts ans_value.join(" ")
end


There is a robot in a warehouse and $$$n$$$ packages he wants to collect. The warehouse can be represented as a coordinate grid. Initially, the robot stays at the point $$$(0, 0)$$$. The $$$i$$$-th package is at the point $$$(x_i, y_i)$$$. It is guaranteed that there are no two packages at the same point. It is also guaranteed that the point $$$(0, 0)$$$ doesn't contain a package.The robot is semi-broken and only can move up ('U') and right ('R'). In other words, in one move the robot can go from the point $$$(x, y)$$$ to the point ($$$x + 1, y$$$) or to the point $$$(x, y + 1)$$$.As we say above, the robot wants to collect all $$$n$$$ packages (in arbitrary order). He wants to do it with the minimum possible number of moves. If there are several possible traversals, the robot wants to choose the lexicographically smallest path.The string $$$s$$$ of length $$$n$$$ is lexicographically less than the string $$$t$$$ of length $$$n$$$ if there is some index $$$1 \le j \le n$$$ that for all $$$i$$$ from $$$1$$$ to $$$j-1$$$ $$$s_i = t_i$$$ and $$$s_j < t_j$$$. It is the standard comparison of string, like in a dictionary. Most programming languages compare strings in this way.

The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then test cases follow. The first line of a test case contains one integer $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of packages. The next $$$n$$$ lines contain descriptions of packages. The $$$i$$$-th package is given as two integers $$$x_i$$$ and $$$y_i$$$ ($$$0 \le x_i, y_i \le 1000$$$) — the $$$x$$$-coordinate of the package and the $$$y$$$-coordinate of the package. It is guaranteed that there are no two packages at the same point. It is also guaranteed that the point $$$(0, 0)$$$ doesn't contain a package. The sum of all values $$$n$$$ over test cases in the test doesn't exceed $$$1000$$$.

Print the answer for each test case. If it is impossible to collect all $$$n$$$ packages in some order starting from ($$$0,0$$$), print "NO" on the first line. Otherwise, print "YES" in the first line. Then print the shortest path — a string consisting of characters 'R' and 'U'. Among all such paths choose the lexicographically smallest path. Note that in this problem "YES" and "NO" can be only uppercase words, i.e. "Yes", "no" and "YeS" are not acceptable.

NoteFor the first test case in the example the optimal path RUUURRRRUU is shown below:

#!usr/bin/env ruby

# https://codeforces.com/contest/1294/problem/B

require 'set'

n = gets.to_i

n.times do
 size = gets.to_i
 pkgs = {}
 size.times do
  cords = gets.split(' ').map(&:to_i)

  pkgs[cords[0]] ||= []
  pkgs[cords[0]] << cords[1]
 end

 x = y = 0
 answer = ""
 failed = false

 while !pkgs.empty? do
  if pkgs[x].nil?
   x += 1
   answer += "R"
  else
   mini = pkgs[x].min
   maxi = pkgs[x].max

   if mini < y
    failed = true
    break
   else
    answer += "U" * (maxi - y)
    y = maxi
    pkgs.delete x
   end
  end
 end

 if failed
  puts "NO"
 else
  puts "YES"
  puts answer
 end
end

#!usr/bin/env ruby

# https://codeforces.com/contest/1294/problem/B

n = gets.to_i

n.times do
 size = gets.to_i
 pkgs = {}
 size.times do
  cords = gets.split(' ').map(&:to_i)

  pkgs[cords[0]] ||= []
  pkgs[cords[0]] << cords[1]
 end

 x = y = 0
 answer = ""
 failed = false

 while !pkgs.empty? do
  if pkgs[x].nil?
   x += 1
   answer += "R"
  else
   mini = maxi = y

   pkgs[x].each do |val|
    mini = val if val < mini
    maxi = val if val > maxi
   end

   if mini < y
    failed = true
    break
   else
    answer += "U" * (maxi - y)
    y = maxi
    pkgs.delete x
   end
  end
 end

 if failed
  puts "NO"
 else
  puts "YES"
  puts answer
 end
end

#!usr/bin/env ruby

# https://codeforces.com/contest/1294/problem/B

n = gets.to_i

n.times do
 size = gets.to_i
 pkgs = []
 size.times do
  pkgs << gets.split(' ').map(&:to_i)
 end

 pkgs.sort!

 x = y = 0
 failed = false
 answer = ""

 pkgs.each do |p|
  dx = p[0] - x
  dy = p[1] - y

  if dx < 0 || dy < 0
   failed = true
   break
  else
   answer += "R" * dx + "U" * dy
   x = p[0]
   y = p[1]
  end
 end

 if failed
  puts "NO"
 else
  puts "YES"
  puts answer
 end
end

T = gets.to_i

T.times do
  n = gets.to_i

  packages = n.times.map { gets.split.map(&:to_i) }

  packages.sort_by! { |x, y| [x, y] }

  ans = ''
  cx = 0
  cy = 0
  success = true

  packages.each do |x, y|
    dx = x - cx
    dy = y - cy

    if dx < 0 || dy < 0
      success = false
      break
    end

    ans += 'R' * dx + 'U' * dy
    cx = x
    cy = y
  end

  if success
    puts 'YES'
    puts ans
  else
    puts 'NO'
  end
end

# coding: utf-8

# if __FILE__ == $0
# end
C = Struct.new(:x, :y)
t = gets.to_i
t.times {
    n = gets.to_i
    ar = []
    n.times {
        ar << C.new(*gets.split.map(&:to_i))
    }
    ar.sort! { |a, b|
        if a.x != b.x
            a.x - b.x
        else
            a.y - b.y
        end
    }
    possible = true
    commands = []
    cx, cy = 0, 0
    ar.each { |c|
        # p ar
        if cx <= c.x && cy <= c.y
            # lexicographical move
            # ABCDEFG.....OPQ'R'ST'U'
            # R first, U last
            commands << 'R'*(c.x-cx)
            commands << 'U'*(c.y-cy)
            cx = c.x
            cy = c.y
        else
            possible = false
            break
        end
    }

    if possible
        puts "YES"
        puts commands.join('')
    else
        puts "NO"
    end
}

# coding: utf-8

# if __FILE__ == $0
# end
C = Struct.new(:x, :y)
t = gets.to_i
t.times {
    n = gets.to_i
    ar = []
    n.times {
        ar << gets.chomp
    }
    ar.sort!
    possible = true
    commands = []
    cx, cy = 0, 0
    ar.each { |c|
        x, y = c.split.map(&:to_i)
        if cx <= x && cy <= y
            commands << 'R'*(x-cx)
            commands << 'U'*(y-cy)
            cx = x
            cy = y
        else
            possible = false
            break
        end
    }

    if possible
        puts "YES"
        puts commands.join('')
    else
        puts "NO"
    end
}


You might have remembered Theatre square from the problem 1A. Now it's finally getting repaved.The square still has a rectangular shape of $$$n \times m$$$ meters. However, the picture is about to get more complicated now. Let $$$a_{i,j}$$$ be the $$$j$$$-th square in the $$$i$$$-th row of the pavement.You are given the picture of the squares:  if $$$a_{i,j} = $$$ "*", then the $$$j$$$-th square in the $$$i$$$-th row should be black;  if $$$a_{i,j} = $$$ ".", then the $$$j$$$-th square in the $$$i$$$-th row should be white. The black squares are paved already. You have to pave the white squares. There are two options for pavement tiles:  $$$1 \times 1$$$ tiles — each tile costs $$$x$$$ burles and covers exactly $$$1$$$ square;  $$$1 \times 2$$$ tiles — each tile costs $$$y$$$ burles and covers exactly $$$2$$$ adjacent squares of the same row. Note that you are not allowed to rotate these tiles or cut them into $$$1 \times 1$$$ tiles. You should cover all the white squares, no two tiles should overlap and no black squares should be covered by tiles.What is the smallest total price of the tiles needed to cover all the white squares?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 500$$$) — the number of testcases. Then the description of $$$t$$$ testcases follow. The first line of each testcase contains four integers $$$n$$$, $$$m$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 100$$$; $$$1 \le m \le 1000$$$; $$$1 \le x, y \le 1000$$$) — the size of the Theatre square, the price of the $$$1 \times 1$$$ tile and the price of the $$$1 \times 2$$$ tile. Each of the next $$$n$$$ lines contains $$$m$$$ characters. The $$$j$$$-th character in the $$$i$$$-th line is $$$a_{i,j}$$$. If $$$a_{i,j} = $$$ "*", then the $$$j$$$-th square in the $$$i$$$-th row should be black, and if $$$a_{i,j} = $$$ ".", then the $$$j$$$-th square in the $$$i$$$-th row should be white. It's guaranteed that the sum of $$$n \times m$$$ over all testcases doesn't exceed $$$10^5$$$.

For each testcase print a single integer — the smallest total price of the tiles needed to cover all the white squares in burles.

NoteIn the first testcase you are required to use a single $$$1 \times 1$$$ tile, even though $$$1 \times 2$$$ tile is cheaper. So the total price is $$$10$$$ burles.In the second testcase you can either use two $$$1 \times 1$$$ tiles and spend $$$20$$$ burles or use a single $$$1 \times 2$$$ tile and spend $$$1$$$ burle. The second option is cheaper, thus the answer is $$$1$$$.The third testcase shows that you can't rotate $$$1 \times 2$$$ tiles. You still have to use two $$$1 \times 1$$$ tiles for the total price of $$$20$$$.In the fourth testcase the cheapest way is to use $$$1 \times 1$$$ tiles everywhere. The total cost is $$$6 \cdot 3 = 18$$$.

def solve
  n, m, x, y = gets.strip.split(' ').map(&:to_i)
  an = 0
  n.times {
    str = gets.strip.split('')
    count = 0
    str.each_with_index { |e, i|
      if e == '.' && i < str.size - 1
        count += 1
      else
        count += 1 if e == '.'
        two = (count / 2).floor
        if two * y < two * 2 * x && !two.zero?
          an += (two * y)
        else
          an += (two * 2 * x)
        end
        an += x if count.odd?
        count = 0
      end
    }
  }
  puts an
end

gets.strip.to_i.times { solve }

  q = gets.chomp.to_i

  q.times {

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

    table = []
    n.times {
      row = gets.chomp
      table << row
    }

    d = []
    n.times { |i|
      d << []
      m.times {
        d[i] << 0
      }
    }

    n.times { |i|
      m.times { |j|

        if j == 0

          if table[i][j] == '.'
            d[i][j] = x
          end

          next
        end

        d[i][j] = d[i][j - 1]

        if table[i][j] == '*'
          next
        end

        d[i][j] = d[i][j - 1] + x

        if table[i][j - 1] == '.'
          curVal = 0
          if j == 1
            curVal = y
          else
            curVal = d[i][j - 2] + y
          end

          d[i][j] = [d[i][j], curVal].min
        end
      }
    }

    sum = 0
    d.each { |row|
      sum += row.last
    }

    puts sum
  }

def solve
  n, m, x, y = gets.strip.split(' ').map(&:to_i)
  an = 0
  n.times {
    str = gets.strip.split('')
    count = 0
    str.each_with_index { |e, i|
      if e == '.' && i < str.size - 1
        count += 1
      else
        count += 1 if e == '.'
        two = (count / 2).floor
        if two * y < two * 2 * x && !two.zero?
          an += (two * y)
        else
          an += (two * 2 * x)
          an += x if count.odd?
        end
        count = 0
      end
    }
  }
    puts an
end

gets.strip.to_i.times { solve }

def solve
  n, m, x, y = gets.strip.split(' ').map(&:to_i)
  an = 0
  n.times {
    str = gets.strip.split('')
    count = 0
    str.each_with_index { |e, i|
      if e == '.' && i < str.size - 1
        count += 1
      else
        count += 1 if e == '.'
        two = (count / 2).to_i
        if two * y < count * x && !two.zero?
          an += (two * y)
        else
          an += (count * x)
        end
        count = 0
      end
    }
  }
    puts an
end

gets.strip.to_i.times { solve }

def solve
  n, m, x, y = gets.strip.split(' ').map(&:to_i)
  an = 0
  n.times {
    str = gets.strip.split('')
    count = 0
    str.each_with_index { |e, i|
      if e == '.' && i < str.size - 1
        count += 1
      else
        count += 1 if e == '.'
        two = (count / 2).to_i
        if two * y < two * 2 * x && !two.zero?
          an += (two * y)
        else
          an += (two * 2 * x)
          an += x if count.odd?
        end
        count = 0
      end
    }
  }
    puts an
end

gets.strip.to_i.times { solve }

def solve
  n, m, x, y = gets.strip.split(' ').map(&:to_i)
  an = 0
  n.times {
    str = gets.strip.split('')
    count = 0
    p str
    str.each_with_index { |e, i|
      if e == '.' && i < str.size - 1
        count += 1
      else
        count += 1 if e == '.'
        two = (count / 2).to_i
        if two * y < count * x && !two.zero?
          an += (two * y)
        else
          an += (count * x)
        end
        count = 0
      end
    }
  }
    puts an
end

gets.strip.to_i.times { solve }


A revolution took place on the Buka Island. New government replaced the old one. The new government includes n parties and each of them is entitled to some part of the island according to their contribution to the revolution. However, they can't divide the island.The island can be conventionally represented as two rectangles a × b and c × d unit squares in size correspondingly. The rectangles are located close to each other. At that, one of the sides with the length of a and one of the sides with the length of c lie on one line. You can see this in more details on the picture.  The i-th party is entitled to a part of the island equal to xi unit squares. Every such part should fully cover several squares of the island (it is not allowed to cover the squares partially) and be a connected figure. A "connected figure" presupposes that from any square of this party one can move to any other square of the same party moving through edge-adjacent squares also belonging to that party.Your task is to divide the island between parties.

The first line contains 5 space-separated integers — a, b, c, d and n (1 ≤ a, b, c, d ≤ 50, b ≠ d, 1 ≤ n ≤ 26). The second line contains n space-separated numbers. The i-th of them is equal to number xi (1 ≤ xi ≤ a × b + c × d). It is guaranteed that .

If dividing the island between parties in the required manner is impossible, print "NO" (without the quotes). Otherwise, print "YES" (also without the quotes) and, starting from the next line, print max(b, d) lines each containing a + c characters. To mark what square should belong to what party, use lowercase Latin letters. For the party that is first in order in the input data, use "a", for the second one use "b" and so on. Use "." for the squares that belong to the sea. The first symbol of the second line of the output data should correspond to the square that belongs to the rectangle a × b. The last symbol of the second line should correspond to the square that belongs to the rectangle c × d. If there are several solutions output any.

a, b, c, d, n = gets.split.map(&:to_i)
areas = gets.split.map(&:to_i)

mp = Array.new([b, d].max+2){"."*(a+c+2)}

b.times do |y|
  mp[y+1][1,a] = " "*a
end

d.times do |y|
  mp[y+1][a+1,c] = " "*c
end

if a%2 == 0
  pos = [1,1]
  yp = 1
else
  pos = [b,1]
  yp = -1
end

areas.each_with_index do |area, idx|
  chr = ("a".."z").to_a[idx]
  area.times do
    mp[pos[0]][pos[1]] = chr
    if (mp[pos[0]+yp][pos[1]] == '.')
      pos[1] += 1
      yp = -yp
    else
      pos[0] += yp
    end
  end
end

puts "YES"
mp[1..-2].each{|s| puts s[1..-2]}