Tyndex is again well ahead of the rivals! The reaction to the release of Zoozle Chrome browser was the release of a new browser Tyndex.Brome!The popularity of the new browser is growing daily. And the secret is not even the Tyndex.Bar installed (the Tyndex.Bar automatically fills the glass with the finest 1664 cognac after you buy Tyndex.Bottles and insert in into a USB port). It is highly popular due to the well-thought interaction with the user.Let us take, for example, the system of automatic address correction. Have you entered codehorses instead of codeforces? The gloomy Zoozle Chrome will sadly say that the address does not exist. Tyndex.Brome at the same time will automatically find the closest address and sent you there. That's brilliant!How does this splendid function work? That's simple! For each potential address a function of the F error is calculated by the following rules:  for every letter ci from the potential address c the closest position j of the letter ci in the address (s) entered by the user is found. The absolute difference |i - j| of these positions is added to F. So for every i (1 ≤ i ≤ |c|) the position j is chosen such, that ci = sj, and |i - j| is minimal possible.  if no such letter ci exists in the address entered by the user, then the length of the potential address |c| is added to F. After the values of the error function have been calculated for all the potential addresses the most suitable one is found. To understand the special features of the above described method better, it is recommended to realize the algorithm of calculating the F function for an address given by the user and some set of potential addresses. Good luck!

The first line contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 105). They are the number of potential addresses and the length of the address entered by the user. The next line contains k lowercase Latin letters. They are the address entered by the user (s). Each next i-th (1 ≤ i ≤ n) line contains a non-empty sequence of lowercase Latin letters. They are the potential address. It is guaranteed that the total length of all the lines does not exceed 2·105.

On each n line of the output file print a single number: the value of the error function when the current potential address is chosen. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d).

9 9
vkontakte
vcontacte
vkontrakte
vkollapse
vkrokodile
vtopke
vkapuste
vpechke
vk
vcodeforcese

def search_min(a, i)
  x0 = 0
  x1 = a.size - 1

  return 0 if a[x0] == i || a[x1] == i

  while x1-x0 > 1
    x2 = (x0+x1)/2
    if a[x2] == i
      return 0
    elsif a[x2] > i
      x1 = x2
    else
      x0 = x2
    end
  end

  [(a[x0]-i).abs, (a[x1]-i).abs].min
end

n, k = gets.split.map(&:to_i)
base = gets.chomp
tbl = {}
base.each_char.with_index{|c, i| (tbl[c]||=[]) << i}

while l = gets
  l.chomp!
  s = 0
  l.each_char.with_index do |c, i|
    if !tbl[c]
      s += l.size
    else
      s += search_min(tbl[c], i)
    end
  end
  puts s
end


The only difference between the easy and the hard versions is the maximum value of $$$k$$$.You are given an infinite sequence of form "112123123412345$$$\dots$$$" which consist of blocks of all consecutive positive integers written one after another. The first block consists of all numbers from $$$1$$$ to $$$1$$$, the second one — from $$$1$$$ to $$$2$$$, the third one — from $$$1$$$ to $$$3$$$, $$$\dots$$$, the $$$i$$$-th block consists of all numbers from $$$1$$$ to $$$i$$$. So the first $$$56$$$ elements of the sequence are "11212312341234512345612345671234567812345678912345678910". Elements of the sequence are numbered from one. For example, the $$$1$$$-st element of the sequence is $$$1$$$, the $$$3$$$-rd element of the sequence is $$$2$$$, the $$$20$$$-th element of the sequence is $$$5$$$, the $$$38$$$-th element is $$$2$$$, the $$$56$$$-th element of the sequence is $$$0$$$.Your task is to answer $$$q$$$ independent queries. In the $$$i$$$-th query you are given one integer $$$k_i$$$. Calculate the digit at the position $$$k_i$$$ of the sequence.

The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 500$$$) — the number of queries. The $$$i$$$-th of the following $$$q$$$ lines contains one integer $$$k_i$$$ $$$(1 \le k_i \le 10^9)$$$ — the description of the corresponding query.

Print $$$q$$$ lines. In the $$$i$$$-th line print one digit $$$x_i$$$ $$$(0 \le x_i \le 9)$$$ — the answer to the query $$$i$$$, i.e. $$$x_i$$$ should be equal to the element at the position $$$k_i$$$ of the sequence.

NoteAnswers on queries from the first example are described in the problem statement.

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

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

n = inp[0]
n.times do
  d = inp[0]
  keta = 0
  ld = d
  li = 0
  100000.times do |i|
    ld = d
    keta += (i+1).to_s.size
    d -= keta
    li = i
    break if(d <= 0)
  end
  pta = keta
  keta = 0
  d = ld
  while 0 < d
    ld = d
    keta += 1
    d -= (9*(10**(keta-1)))*keta
  end
  ld -= 1
  no = ld % keta
  ka = ld/keta
  puts (ka+10**(keta-1)).to_s[no]
end

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

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

n = inp[0]
n.times do
  d = inp[0]
  keta = 0
  ld = d
  li = 0
  100000.times do |i|
    ld = d
    keta += (i+1).to_s.size
    d -= keta
    li = i
    break if(d <= 0)
  end
  pta = keta
  keta = 0
  d = ld
  while 0 <= d
    ld = d
    keta += 1
    d -= (9*(10**(keta-1)))*keta
  end
  ld -= 1
  no = ld % keta
  ka = ld/keta
  puts (ka+10**(keta-1)).to_s[no]
end


Phone number in Berland is a sequence of n digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three digits.

The first line contains integer n (2 ≤ n ≤ 100) — amount of digits in the phone number. The second line contains n digits — the phone number to divide into groups.

Output any of divisions of the given phone number into groups of two or three digits. Separate groups by single character -. If the answer is not unique, output any.

n = gets.chomp.to_i
s = gets.chomp
first = true
if n % 2 == 0
	while s.length > 0
		print "-" if not first
		print s.slice!(0,2)
		first = false
	end
else
	len = 3
	while s.length > 0
		print "-" if not first
		print s.slice!(0,len)
		first = false
		len = 2
	end
end
puts

#!/usr/bin/ruby
gets;s=gets.chomp
if s.size%3==1
	t=s[-4..-1]
	x=s[0..-5].chars.each_slice(3).map{|e|e*''}*'-'
	puts (x.size>0 ? x+'-' : '')+t[0,2]+'-'+t[2,2]
else
	puts s.chars.each_slice(3).map{|e|e*''}*'-'
end

gets
s = gets.chop
print s.slice!(0..1)+'-' if s.size % 3 == 1
s.gsub!(/.../){$&+'-'}
s.chop! if s =~ /-$/
puts s

n=gets.to_i
m=gets.split[0]
i=0
s=0
if n%3==1 then
        print m[0..1]
        print "-"
        print m[2..3]
        s=1
        i=4
elsif n%3==2 then
        print m[0..1]
        s=1
        i=2
end
while i<n
        if s>0 then
                print "-"
        end
        s=1
        print m[i..(i+2)]
        i+=3
end
puts

n=gets.chomp.to_i
phone=gets.chomp
s=""
if n%2==0
  n.times do |i|
    s+=phone[i,1]
    if i%2 == 1
      s+="-"
    end
  end
  puts s[0,s.length-1]
else
  (n-2).times do |i|
    s+=phone[i,1]
    if i%2 == 1
      s+="-"
    end
  end
  s+=phone[-2,3]
  puts s
end

n = gets.to_i
s = gets.chomp

k = n % 3
r = ''
if k != 0
  r = s[0, 2] + '-'
  s = s[2 ... s.length]
end

for i in 0...n/3
  r = r + s[3 * i, 3] + '-'
end
puts r[0, r.length - 1]

digits = gets.to_i
number = gets.chomp
if digits % 2 == 0
  telephone = number.scan(/.{2}/)
  (0...telephone.size).each do |i|
    if i == telephone.size - 1
      puts telephone[i]
    else
      print "#{telephone[i]}-"
    end
  end
else
  if digits % 3 == 0
    telephone = number.scan(/.{3}/)
    (0...telephone.size).each do |i|
      if i == telephone.size - 1
        puts telephone[i]
      else
        print "#{telephone[i]}-"
      end
    end
  else
    if (digits-3) % 2 == 0
      telephone = number[0...digits-3].scan(/.{2}/)
      (0...telephone.size).each do |i|
          print "#{telephone[i]}-"
      end
      puts number[digits-3...digits]
    end
  end
end

n, phone = gets, gets.chomp
left = phone.length
i=0
s=""
while left>0
  s+="-" if s!=""
  x = left==3?2:1;
  s << phone[i..i+x]
  i = i+x+1
  left = left-x-1
end
puts s

n = gets.to_i
gets.strip.each_char.with_index do |y,i|
  if i > 0 && (i%2 == 0 && i < n-1 || i == n-3 && n%2 != 0)
    print '-';
  end
  print y
end

n = gets.to_i
gets.strip.each_char.with_index do |y,i|
  if i > 0 && (i%2 == 0 && i < n-1 || i == n-3 && n%2 != 0)
    print '-';
  end;
  print y;
end;

n = gets.to_i
gets.strip.each_char.with_index do |y,i|
  if i > 0 && (i%2 == 0 && i < n-1 || i == n-3 && n%2 != 0)
    print '-';
  end;
  print y
end

n = gets.to_i
gets.strip.each_char.with_index do |y,i|
  if i > 0 && (i%2 == 0 && i < n-1 || i == n-3 && n%2 != 0)
    print '-'
  end
  print y
end

n = gets.to_i
gets.strip.each_char.with_index do |y,i|
  if i > 0 && (i%2 == 0 && i < n-1 || i == n-3 && n%2 != 0);
    print '-';
  end;
  print y;
end;

numOfDigits = gets.chomp.to_i
phoneNumber = gets.chomp

div5 = numOfDigits / 5
mod5 = numOfDigits % 5

numOf2 = div5
numOf3 = div5

if mod5 > 0
    if mod5 % 2 == 0
        #2 or 4
        numOf2 = numOf2 + (mod5 / 2)
    elsif mod5 % 3 == 0
        #3
        numOf3 = numOf3 + 1
    else
        #1
        numOf2 = numOf2 - 1
        numOf3 = numOf3 + 1
    end
end

result = ""
index = 0

1.upto(numOf2) do |i|
    result = result + "-" + phoneNumber[index, 2]
    index = index + 2
end

1.upto(numOf3) do |i|
    result = result + "-" + phoneNumber[index, 3]
    index = index + 3
end

if result[0, 1] == "-"
    result = result[1, result.length - 1]
end

puts result

gets
phone = gets.chomp.scan(/./)

res = ""
while phone.size >= 2
  res << phone.shift(2).join << '-'
end
res = res[0..-2]
res << phone.join

puts res

#!/usr/bin/ruby
gets;s=gets.chomp
if s.size%3==1
	t=s[-4..-1]
	puts s[0..-5].chars.each_slice(3).map{|e|e*''}*'-'+'-'+t[0,2]+'-'+t[2,2]
else
	puts s.chars.each_slice(3).map{|e|e*''}*'-'
end


Bob has a permutation of integers from 1 to n. Denote this permutation as p. The i-th element of p will be denoted as pi. For all pairs of distinct integers i, j between 1 and n, he wrote the number ai, j = min(pi, pj). He writes ai, i = 0 for all integer i from 1 to n.Bob gave you all the values of ai, j that he wrote down. Your job is to reconstruct any permutation that could have generated these values. The input will be formed so that it is guaranteed that there is at least one solution that is consistent with the information given.

The first line of the input will contain a single integer n (2 ≤ n ≤ 50). The next n lines will contain the values of ai, j. The j-th number on the i-th line will represent ai, j. The i-th number on the i-th line will be 0. It's guaranteed that ai, j = aj, i and there is at least one solution consistent with the information given.

Print n space separated integers, which represents a permutation that could have generated these values. If there are multiple possible solutions, print any of them.

NoteIn the first case, the answer can be {1, 2} or {2, 1}.In the second case, another possible answer is {2, 4, 5, 1, 3}.

n = gets.to_i
m = (1..n).map{gets.strip.split(" ").map(&:to_i)}

a = [nil] * n

i = 1
while i <= n
    m.each_with_index do |s, k|
        if s.all? {|x| x <= i} && s.any? {|x| x == i-1}
            a[k] = i
            i += 1
        end
    end
end

puts a.join(" ")

n=gets.to_i
a=n.times.map{gets.split.map(&:to_i).max}
a[a.index(n-1)]=n
puts a*' '

# http://codeforces.com/problemset/problem/618/B

n = gets.to_i
ans = []
n.times do |i|
    arr = gets.split.map(&:to_i)
    ans << arr.max
end
ans[ans.index(n - 1)] = n
puts ans * " "

n = gets.chomp.to_i
ps = []
f = false
n.times do
  as = gets.chomp.split.map(&:to_i)
  p = as.sort!.uniq.size - 1
  if p == n - 1
    ps << (f ? p : n)
    f = true
  else
    ps << p
  end
end

puts ps.*' '

n = gets.to_i
g = []
for _ in 0...n
  a = gets.split(' ').map(&:to_i)
  g << a
end

r = []
for j in 0...n
  for k in 0..j
    if g[j][k] == n-1
      r[j] = n
      r[k] = n-1
    end
  end
end

for i in 2...n
  x = n-i
  for j in 0...n
    for k in 0..j
      if g[j][k] == x && (!r[j] || !r[k])
        if r[k]
          r[j] = x
        else
          r[k] = x
        end
      end
    end
  end
end

puts r.join(' ')

n = gets.chomp.to_i
n.times do |i|
  r = gets.chomp.split(" ")
  if r.uniq.length == n then
    r[i] = n
    puts r.join(" ")
    exit
  end
end

# http://codeforces.com/problemset/problem/618/B

n = gets.to_i
ans = []
n.times do |i|
    arr = gets.split.map(&:to_i)
    ans << arr.max
end
ans[ans.index(n - 1)] = n
p ans * " "


There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other.

The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3).

Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.

NoteIn the example all the numbers equal to 1 and 3 should be replaced by 2.

n = gets.to_i
a = gets.split.map(&:to_i)
puts n - (1..3).map{|x| a.count(x)}.max

def function
a=gets.chomp
b=gets.chomp
b=b.split.map(&:to_i)
puts (b.length-b.count(b.uniq.max_by{ |i| b.count( i ) }))
end
function

n    = gets.chomp.to_i
ints = gets.chomp.split
h = Hash.new(0)
ints.each { |i| h[i] += 1 }
puts n - h.values.max

n = gets
arr = gets

nr1 = 0
nr2 = 0
nr3 = 0

arr.split(" ").map(&:to_i).each do |x|
  if x == 1
    nr1 += 1
  elsif x == 2
    nr2 += 1
  else
    nr3 += 1
  end
end

puts n.to_i - [nr1,nr2, nr3].max

gets
gets
p [*?1..?3].map{|_|$_.count _}.combination(2).map{|a,b|a+b}.min

gets; n = gets.strip
print [n.count("1"), n.count("2"), n.count("3")].sort[0,2].inject(0) { |sum, e| sum += e }

n = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)
puts n - [a.select {|x| x == 3 }.length, a.select{|x| x==2}.length, a.select{|x| x==1}.length].max

def function
a=gets.chomp
b=gets.chomp
b=b.split.map(&:to_i)
print (b.length-b.count(b.uniq.max_by{ |i| b.count( i ) }))
end

def function
a=gets.chomp
b=gets.chomp
b=b.split.map(&:to_i)
puts b.length-b.count(b.uniq.max_by{ |i| b.count( i ) })
end

n = gets
arr = gets

nr1 = 0
nr2 = 0
nr3 = 0

arr.split(" ").map(&:to_i).each do |x|
  if x == 1
    nr1 += 1
  elsif x == 2
    nr2 += 1
  else
    nr3 += 1
  end
end

n.to_i - [nr1,nr2, nr3].max

n = gets
arr = gets

nr1 = 0
nr2 = 0
nr3 = 0

if n.to_i == 0
  puts 0
elsif n.to_i == 1
  puts 0
end

arr.split(" ").map(&:to_i).each do |x|
  if x == 1
    nr1 += 1
  elsif x == 2
    nr2 += 1
  else
    nr3 += 1
  end
end

puts n.to_i - [nr1,nr2, nr3].max

n = gets
arr = gets

nr1 = 0
nr2 = 0
nr3 = 0

if n.to_i == 0
  puts 0
elsif n.to_i == 1
  puts 1
end

arr.split(" ").map(&:to_i).each do |x|
  if x == 1
    nr1 += 1
  elsif x == 2
    nr2 += 1
  else
    nr3 += 1
  end
end

puts n.to_i - [nr1,nr2, nr3].max

n = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)
puts n - [a.select {|x| x == 1 }.length, a.select{|x| x==2}.length, a.select{|x| x==1}.length].max


Marina loves Sasha. But she keeps wondering whether Sasha loves her. Of course, the best way to know it is fortune telling. There are many ways of telling fortune, but Marina has picked the easiest one. She takes in her hand one or several camomiles and tears off the petals one by one. After each petal she pronounces alternatively "Loves" and "Doesn't love", at that Marina always starts with "Loves". There are n camomiles growing in the field, possessing the numbers of petals equal to a1, a2, ... an. Marina wants to pick a bouquet with the maximal possible total number of petals so that the result would still be "Loves". Help her do that; find the maximal number of petals possible in the bouquet.

The first line contains an integer n (1 ≤ n ≤ 100), which is the number of flowers growing in the field. The second line contains n integers ai (1 ≤ ai ≤ 100) which represent the number of petals on a given i-th camomile.

Print a single number which is the maximal number of petals in the bouquet, the fortune telling on which would result in "Loves". If there are no such bouquet, print 0 instead. The bouquet may consist of a single flower.

n=gets.to_i
a=gets.split.map(&:to_i).sort
b,c=[],[]
a.each{|k|
        if k%2==0  then
                b.push(k)
        else
                c.push(k)
        end
}
init=1
if c.length==0 then
        puts 0
        exit
end
ans=0
if c.length%2==0 then
        for i in 1..(c.length-1)
                ans+=c[i]
        end
else
        for i in 0..(c.length-1)
                ans+=c[i]
        end
end
b.each{|k| ans+=k}
p ans

s = gets
odds = []
evens = []

gets.split(" ").each {|e|
  t = e.to_i
  if (t % 2 == 0)
    evens.push t
  else
    odds.push t
  end
}

odds.sort!
evens.sort!

if (odds.size == 0)
  puts 0
else
  t = odds.inject(0) {|r, i| r + i} + evens.inject(0) {|r, i| r + i}
  if (odds.size % 2 == 0)
    t -= odds[0]
  end
  puts t
end

N = gets.to_i
a = gets.split(' ').map {|i| i.to_i}
sum = a.inject(0) {|s, i| s + i}
cntNe = a.inject(0) {|s, i|
  r = s
  r += 1 if i % 2 != 0
  r
}

if cntNe == 0
  puts 0
  exit
end

if cntNe % 2 != 0
  puts sum
  exit
end

puts sum - a.select{|i| i % 2 != 0}.min

n = gets.chomp
input = gets.chomp.split(' ').collect { |i| i.to_i }
sum = 0

smallestOdd = input.collect do |i|
					if i.odd? then i else 101 end
			   end.min
smallestOdd = -1 if smallestOdd == 101
input.each { |i| sum = sum + i }

if sum.odd?
 puts sum
elsif smallestOdd == -1
puts 0
else
puts sum - smallestOdd
end

gets
flowers = gets.chomp.split.map(&:to_i).sort
sum = flowers.inject(0) { |s, v| s + v }

if sum.odd?
  puts sum
  exit
else
  first_odd = flowers.detect{ |f| f.odd? }
  if first_odd
    puts sum - first_odd
    exit
  end
end
puts 0

n=gets.to_i
a=gets.split.map(&:to_i)
b,c=[],[]
a.each{|k|
        if k%2==0  then
                b.push(k)
        else
                c.push(k)
        end
}
init=1
if c.length==0 then
        puts 0
        exit
end
ans=0
if c.length%2==0 then
        for i in 1..(c.length-1)
                ans+=c[i]
        end
else
        for i in 0..(c.length-1)
                ans+=c[i]
        end
end
b.each{|k| ans+=k}
p ans

n = gets.chomp
input = gets.chomp.split(' ').collect { |i| i.to_i }
sum = 0

smallestOdd = input.collect do |i|
					if i.odd? then i else 101 end
			   end.min
smallestOdd = 0 if smallestOdd == 101
input.each { |i| sum = sum + i }

if sum.odd? then puts sum
else puts sum - smallestOdd
end

n = gets.chomp
input = gets.chomp.split(' ').collect { |i| i.to_i }
sum = 0

smallestOdd = input.collect do |i|
					if i.odd? then i else 101 end
			   end.min
input.each { |i| sum = sum + i }

puts sum - smallestOdd if sum.even?
puts sum if sum.odd?

gets
flowers = gets.chomp.split.map(&:to_i).sort
sum = flowers.inject(0) { |s, v| s + v }

if sum.odd?
  puts sum
  exit
else
  while flowers.size > 0
    sum = sum - flowers.shift
    if sum.odd?
      puts sum
      exit
    end
  end
end
puts 0


Riley is a very bad boy, but at the same time, he is a yo-yo master. So, he decided to use his yo-yo skills to annoy his friend Anton.Anton's room can be represented as a grid with $$$n$$$ rows and $$$m$$$ columns. Let $$$(i, j)$$$ denote the cell in row $$$i$$$ and column $$$j$$$. Anton is currently standing at position $$$(i, j)$$$ in his room. To annoy Anton, Riley decided to throw exactly two yo-yos in cells of the room (they can be in the same cell).Because Anton doesn't like yo-yos thrown on the floor, he has to pick up both of them and return back to the initial position. The distance travelled by Anton is the shortest path that goes through the positions of both yo-yos and returns back to $$$(i, j)$$$ by travelling only to adjacent by side cells. That is, if he is in cell $$$(x, y)$$$ then he can travel to the cells $$$(x + 1, y)$$$, $$$(x - 1, y)$$$, $$$(x, y + 1)$$$ and $$$(x, y - 1)$$$ in one step (if a cell with those coordinates exists).Riley is wondering where he should throw these two yo-yos so that the distance travelled by Anton is maximized. But because he is very busy, he asked you to tell him.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of each test case contains four integers $$$n$$$, $$$m$$$, $$$i$$$, $$$j$$$ ($$$1 \leq n, m \leq 10^9$$$, $$$1\le i\le n$$$, $$$1\le j\le m$$$) — the dimensions of the room, and the cell at which Anton is currently standing.

For each test case, print four integers $$$x_1$$$, $$$y_1$$$, $$$x_2$$$, $$$y_2$$$ ($$$1 \leq x_1, x_2 \leq n$$$, $$$1\le y_1, y_2\le m$$$) — the coordinates of where the two yo-yos should be thrown. They will be thrown at coordinates $$$(x_1,y_1)$$$ and $$$(x_2,y_2)$$$. If there are multiple answers, you may print any.

NoteHere is a visualization of the first test case.

t = Integer(gets.chomp)
t.times{
    x, y, i, j = gets.chomp.split().map!{|c| Integer(c)}

    puts "1 1 #{x} #{y}"
}


You are given the array $$$a$$$ consisting of $$$n$$$ positive (greater than zero) integers.In one move, you can choose two indices $$$i$$$ and $$$j$$$ ($$$i \ne j$$$) such that the absolute difference between $$$a_i$$$ and $$$a_j$$$ is no more than one ($$$|a_i - a_j| \le 1$$$) and remove the smallest of these two elements. If two elements are equal, you can remove any of them (but exactly one).Your task is to find if it is possible to obtain the array consisting of only one element using several (possibly, zero) such moves or not.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of $$$a$$$. The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 100$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$.

For each test case, print the answer: "YES" if it is possible to obtain the array consisting of only one element using several (possibly, zero) moves described in the problem statement, or "NO" otherwise.

NoteIn the first test case of the example, we can perform the following sequence of moves:  choose $$$i=1$$$ and $$$j=3$$$ and remove $$$a_i$$$ (so $$$a$$$ becomes $$$[2; 2]$$$);  choose $$$i=1$$$ and $$$j=2$$$ and remove $$$a_j$$$ (so $$$a$$$ becomes $$$[2]$$$). In the second test case of the example, we can choose any possible $$$i$$$ and $$$j$$$ any move and it doesn't matter which element we remove.In the third test case of the example, there is no way to get rid of $$$2$$$ and $$$4$$$.

gets.to_i.times do
  answer = true

  gets
  gets.split(' ').map(&:to_i).sort.each_cons(2) { |a, b| answer &&= b - a <= 1 }

  puts answer ? 'YES' : 'NO'
end

t=gets.chomp.to_i
#p "t= #{t}"
while t!=0

len=gets.chomp.to_i
#p "length= #{len}"
k=0
#while k<=len-1
ar = gets.chomp.split(' ').map!{ |o| o.to_i }
#k+=1
#end
ar.sort!
 #p ar
def func(ar)

l=ar.size
if l==1
 return "YES"
end
 i=0
while i < l-1

if ar[i+1]-ar[i]>1
  return "NO"
end
i+=1
end
return "YES"
end

puts func(ar)

t-=1
end

times = gets.to_i

def resolve(array)
  array.sort.each_cons(2) {|e,n| return "NO" if n-e >1}
  "YES"
end

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

  a = Array.new(array_size)
  a = gets.split(/\s+/).map(&:to_i)
  puts resolve(a)
end

t = gets.chomp.to_i
t.times do
    n = gets.chomp.to_i
    a = gets.chomp.split(" ").map(&:to_i)
    aa = a.sort
    i = 0
    while true
        if n.to_s == "1"
            puts "YES"
            break
        end
        sa = (aa[i+1] - aa[i]).abs
        if sa <= 1
            aa.shift
            i = 0
        else
            puts "NO"
            break
        end
        if aa.size == 1
            puts "YES"
            break
        end
    end
end

gets.to_i.times do
    n = gets.to_i
    a = gets.split.map(&:to_i).sort!
    ok = true
    (1...n).each do |i|
        ok &= a[i] - a[i - 1] <= 1
    end
    puts ok ? "YES" : "NO"
end

t = gets.to_i
ans = []
t.times do
  n = gets.to_i
  a = gets.chomp.split(" ").map(&:to_i).sort
  judge = true
  (n-1).times do |i|
    if a[i+1] - a[i] >= 2
      judge = false
    end
  end
  if judge
    ans << "YES"
  else
    ans << "NO"
  end
end
ans.each do |str|
  puts str
end

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

  p = a.shift
  x = 0

  while a.size > 0
    x += 1 if (a.first - p).abs > 1
    p = a.shift
  end

  puts x.zero? ? "YES" : "NO"
end

test_case = gets.to_i
i = 0
while i < test_case
    result = true
    i += 1
    len_ = gets.to_i
    Acase = gets.chomp.split(' ').map(&:to_i)
    Acase.sort!
    #puts Acase.inspect()
    j = 0
    while j < len_-1

        if Acase[j+1].to_i - Acase[j].to_i >= 2
            result = false
            j += 1
            break
        end
        j += 1
    end
    puts (result) ? "Yes" : "No"

end

tc = gets().to_i
tc.times do
    n = gets().to_i
    arr = gets().split(' ').map(&:to_i).sort
    k = true
    for i in (1..n-1) do
        if arr[i]-arr[i-1] > 1
            puts "NO";
            k = false
            break;
        end
    end
    if (k)
        puts "YES"
    end
end

t=gets.chomp.to_i
#p "t= #{t}"
while t!=0

len=gets.chomp.to_i
#p "length= #{len}"
k=0
#while k<=len-1
ar = gets.chomp.split(' ').map!{ |o| o.to_i }
#k+=1
#end
ar.sort!
 p ar
def func(ar)

l=ar.size
if l==1
 return "YES"
end
 i=0
while i < l-1

if ar[i+1]-ar[i]>1
  return "NO"
end
i+=1
end
return "YES"
end

p func(ar)

t-=1
end

t=gets.chomp.to_i
#p "t= #{t}"
while t!=0

len=gets.chomp.to_i
#p "length= #{len}"
k=0
#while k<=len-1
ar = gets.chomp.split(' ').map!{ |o| o.to_i }
#k+=1
#end
ar.sort!
 #p ar
def func(ar)

l=ar.size
if l==1
 return "YES"
end
 i=0
while i < l-1

if ar[i+1]-ar[i]>1
  return "NO"
end
i+=1
end
return "YES"
end

p func(ar)

t-=1
end

t = gets.chomp.to_i
t.times do
    n = gets.chomp.to_i
    a = gets.chomp.split(" ").map(&:to_i)
    aa = a.sort
    i = 0
    while true
        if n == 1
            puts "YES"
            break
        end
        sa = (a[i+1] - a[i]).abs
        if sa <= 1
            a.shift
            i = 0
        else
            puts "NO"
            break
        end
        if a.size == 1
            puts "YES"
            break
        end
    end
end

def array(arr)
    arr.sort!.each_cons(2) do |a, b|
        b - a > 1 ? 'NO' : 'YES'
    end
end

test_case = gets.to_i
i = 0
while i < test_case
    result = true
    i += 1
    len_ = gets.to_i
    Acase = gets.chomp.split(' ').map(&:to_i)
    Acase.sort!
    #puts Acase.inspect()
    j = 0
    while j < len_-1
        j += 1
        if Acase[j+1].to_i - Acase[j].to_i >= 2
            result = false
            break
        end
    end
    puts (result) ? "Yes" : "No"

end

tc = gets().to_i
tc.times do
    n = gets().to_i
    arr = gets().split(' ').map(&:to_i).sort
    if arr[n-1]-arr[0] > 1
        puts("NO")
    else
        puts("YES")
    end
end

tc = gets().to_i
tc.times do
    n = gets().to_i
    arr = gets().split(' ').map(&:to_i)
    k = true
    for i in (1..n-1) do
        if arr[i]-arr[i-1] > 1
            puts "NO";
            k = false
            break;
        end
    end
    if (k)
        puts "YES"
    end
end


In the Main Berland Bank n people stand in a queue at the cashier, everyone knows his/her height hi, and the heights of the other people in the queue. Each of them keeps in mind number ai — how many people who are taller than him/her and stand in queue in front of him.After a while the cashier has a lunch break and the people in the queue seat on the chairs in the waiting room in a random order.When the lunch break was over, it turned out that nobody can remember the exact order of the people in the queue, but everyone remembers his number ai.Your task is to restore the order in which the people stood in the queue if it is possible. There may be several acceptable orders, but you need to find any of them. Also, you need to print a possible set of numbers hi — the heights of people in the queue, so that the numbers ai are correct.

The first input line contains integer n — the number of people in the queue (1 ≤ n ≤ 3000). Then n lines contain descriptions of the people as "namei ai" (one description on one line), where namei is a non-empty string consisting of lowercase Latin letters whose length does not exceed 10 characters (the i-th person's name), ai is an integer (0 ≤ ai ≤ n - 1), that represents the number of people who are higher and stand in the queue in front of person i. It is guaranteed that all names are different.

If there's no acceptable order of the people in the queue, print the single line containing "-1" without the quotes. Otherwise, print in n lines the people as "namei hi", where hi is the integer from 1 to 109 (inclusive), the possible height of a man whose name is namei. Print the people in the order in which they stand in the queue, starting from the head of the queue and moving to its tail. Numbers hi are not necessarily unique.

n = gets.to_i
a = n.times.map{
    x, y = gets.split
    [y.to_i, x]
}.sort
b = []
a.each do |x, y|
    break if x > b.size
    b.each{|_| _[1] += 1 if _[1] >= x}
    b << [y, x]
end
puts b.size < n ? -1 : b.map{|i, j| "#{i} #{n - j}"} * "\n"

n=gets.to_i
ans=[]
n.times.map{name,a=gets.split;[name,a.to_i]}.sort_by{|name,a|a}.each{|name,a|
	if ans.size<a
		p -1
		exit
	end
	ans.insert(a,[name,n-a])
}
ans.each{|_|puts"%s %d"%_}

def solve(data)
  data.sort_by!{|n,a| a}

  ret = []
  ho = []
  data.each_with_index do |(n, a), i|
    return nil if a > i
    ho[a, 0] = n
  end

  data.each do |n, a|
    ret << [n, data.size-ho.index(n)]
  end
  ret
end

def check(sol)
  hs = []
  sol.map{|n,h| v = [n, hs.count{|x| x > h}]; hs << h; v}
end

def test
  srand(122039)
  100.times do |i|
    p i
    d0 = 30.times.map{|x|["a#{x}", rand(10**9)]}
    input = check(d0)
    out  = solve(input)
    input2 = check(out)
    if input != input2
      p d0, input, input2
      raise
    end
  end
  exit
end

n = gets.to_i
data = n.times.map{ a, b = gets.split; [a, b.to_i]}
ret = solve(data)
if ret
  ret.each{|a| puts a*" "}
else
  puts -1
end

q=gets.to_i.times.map{name,a=gets.split;[name,a.to_i]}
r=[0.0,1e9]
ans=[]
h=q.group_by{|name,a|a}
0.upto(3000){|n|
	hn=h[n]
	next unless hn
	if r.size-2<n
		p -1
		exit
	end
	ins_idx=n+1
	vl,vr=r[ins_idx-1],r[ins_idx]
	d=(vr-vl)/(hn.size+1)
	d_range=(vl+d).step(vr-d,d).to_a
	d_range.each{|v|r.insert(ins_idx,v)}
	0.upto(hn.size-1){|i|ans<<[hn[i][0],d_range[i]]}
}
r.reverse!
ans.each{|name,v|puts"%s %d"%[name,r.index(v)]}


You have n distinct points on a plane, none of them lie on OY axis. Check that there is a point after removal of which the remaining points are located on one side of the OY axis.

The first line contains a single positive integer n (2 ≤ n ≤ 105). The following n lines contain coordinates of the points. The i-th of these lines contains two single integers xi and yi (|xi|, |yi| ≤ 109, xi ≠ 0). No two points coincide.

Print "Yes" if there is such a point, "No" — otherwise. You can print every letter in any case (upper or lower).

NoteIn the first example the second point can be removed.In the second example there is no suitable for the condition point.In the third example any point can be removed.

gets;puts$<.partition{|e|e.to_i<0}.any?{|e|e.size<2} ? :YES : :NO

#!ruby
gets
puts$<.partition{|x|x.to_i<0}.map(&:size).min<2?:yes: :no

n=gets.to_i
x=y=0;
n.times{ gets.to_i<0 ? y+=1 : x+=1 }
puts ([x, y].min<2 ? "Yes" : "No")

n = gets.chomp.to_i
arr = []
pos = 0
neg = 0
for i in (0..n-1)
	arr << gets.chomp.split.map(&:to_i)
	if arr[i][0] > 0
		pos += 1
	else
		neg += 1
	end
end

if pos == arr.size || neg == arr.size
	print "Yes"
else
	if pos == 1 || neg == 1
		print "Yes"
	else
		print "No"
	end
end

puts gets.to_i.times.count{gets.split.map(&:to_i).reduce(:+)<1}<1 ? :YES : :NO

puts gets.to_i.times.count{gets.split.map(&:to_i).reduce(:+)<1}<2 ? :YES : :NO

gets;puts$<.group_by{|e|e.to_i<0}.any?{|k,v|v.size<2} ? :YES : :NO


You are given two positive integers $$$n$$$ ($$$1 \le n \le 10^9$$$) and $$$k$$$ ($$$1 \le k \le 100$$$). Represent the number $$$n$$$ as the sum of $$$k$$$ positive integers of the same parity (have the same remainder when divided by $$$2$$$).In other words, find $$$a_1, a_2, \ldots, a_k$$$ such that all $$$a_i>0$$$, $$$n = a_1 + a_2 + \ldots + a_k$$$ and either all $$$a_i$$$ are even or all $$$a_i$$$ are odd at the same time.If such a representation does not exist, then report it.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases in the input. Next, $$$t$$$ test cases are given, one per line. Each test case is two positive integers $$$n$$$ ($$$1 \le n \le 10^9$$$) and $$$k$$$ ($$$1 \le k \le 100$$$).

For each test case print:   YES and the required values $$$a_i$$$, if the answer exists (if there are several answers, print any of them);  NO if the answer does not exist.  The letters in the words YES and NO can be printed in any case.

  t = gets.to_i
  t.times do
    n, k = gets.split(' ').map(&:to_i)
    if k == 1
      puts 'YES'
      puts n
      next
    end
    res = []
    (k-1).times do |i|
      res << 1
    end
    if((_res = n - res.reduce(&:+)) % 2 != 0 && _res > 0)
        res << _res
        puts 'YES'
        puts res.join(' ')
    else
      res = []
      (k-1).times do |i|
        res << 2
      end
      if((_res = n - res.reduce(&:+)) % 2 == 0 && _res > 0)
          res << _res
          puts 'YES'
          puts res.join(' ')
      else
        puts 'NO'
      end
    end
  end

t = gets.to_i

def all(a,b)
  puts "YES"
  (1..a).each do
    print "#{b} "
  end
  puts
end

def printArr(arr)
  puts "YES"
  arr.each do |x|
    print "#{x} "
  end
  puts
end

(1).upto(t) do
  x = gets.split(' ')
  n = x[0].to_i
  k = x[1].to_i
  val1 = n/k
  val2 = n.modulo(k)
  if val1 ==0
    puts "NO"
    next
  end
  if(val2 == 0)
    all(k,val1)
    next
  end
  arr = []
  (1..k).each do
    arr.push(val1)
  end
  if val2.modulo(2)==0
    arr[0]+=val2
    printArr(arr)
    next
  end
  if k.modulo(2)==0
    puts "NO"
    next
  end
  if arr[0]!=1
    (0.. arr.length-1).each do |i|
      arr[i]-=1
      val2+=1
    end
    arr[0]+=val2
    printArr(arr)
    next
  end
  puts "NO"
end

# Created by IntelliJ IDEA.
# User: gautam.roy
# Date: 5/9/20
# Time: 9:37 PM
# To change this template use File | Settings | File Templates.

t = gets.to_i
for i in 1..t do
  n, k = gets.split(' ').map { |s| s.to_i }
  ret = []
  if n < k
    puts "NO"
    next
  end
  if k == 1
    puts "Yes"
    puts n
    next
  end
  if k.even? && !n.even?
    puts "NO"
    next
  end
  if (k.even? && n.even?) || (!k.even? && !n.even?)
    puts "Yes"
    for j in 1..(k - 1)
      ret << 1
    end
    ret << n - (k - 1)
    puts ret.join(" ")
    next
  end
  # k odd and n even
  if (n - 2 * (k - 1)) > 0
    puts "YES"
    for j in 1..(k - 1)
      ret << 2
    end
    ret << n - 2 * (k - 1)
    puts ret.join(" ")
  else
    puts "NO"
  end
end

gets.to_i.times{
    n,k=gets.split.map &:to_i
    res=[1]*(k-1)
    res<<n-k+1
    if res[-1].even?
        res=[2]*(k-1)
        res<<n-(k-1)*2
    end
    if (res[0]%2!=res[-1]%2) or (res[-1]<=0)
        puts :NO
    else
        puts :YES
        puts res*' '
    end
}

gets.to_i.times do
  n, k = gets.split.map &:to_i
  if n.even? and k.even?
    if k > n
      puts "NO"
    else
      puts "YES"
      puts "1 "*(k - 1) + (n - k + 1).to_s
    end
  elsif n.even? and k.odd?
    if k*2 > n
      puts "NO"
    else
      puts "YES"
      puts "2 "*(k - 1) + (n - (k - 1)*2).to_s
    end
  else
    if k.even? or k > n
      puts "NO"
    else
      puts "YES"
      puts "1 "*(k - 1) + (n - k + 1).to_s
    end
  end
end

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

  f = [1, 2].find do |i|
    delta = n - (k-1)*i
    delta > 0 && (delta.even? == i.even?)
  end

  if f
    puts "YES"
    puts "#{f} " * (k-1) + (n - (k-1)*f).to_s
  else
    puts "NO"
  end
end

n = gets.chomp.to_i

tests = []

n.times do
  tests.push(gets.split(' ').map {|e| e.to_i})
end

tests.each do |test|
  n, k = test

  if n < k then
    puts 'NO'
    next
  end

  if n.odd? && k.even? then
    puts 'NO'
    next
  end

  results = []
  if n.even? && k.odd? then
    if 2 * k > n then
      puts 'NO'
      next
    end
    results.fill(2, 0..k - 2)
    results_sum = results.reduce(0) {|sum, value| sum + value }
    results.push(n - results_sum)
    puts 'YES'
    puts results.join(' ')
  else
    results.fill(1, 0..k - 2)
    results_sum = results.reduce(0) {|sum, value| sum + value }
    results.push(n - results_sum)
    puts 'YES'
    puts results.join(' ')
  end

end

t = gets.to_i
t.times do
  n, k = gets.split(' ').map(&:to_i)
  _res = n / k
  res = []
  if n % k == 0
    k.times { res << _res }
  else
    t_res = _res + 1
    n_res = n - (t_res * (k-1))
    if n_res < 1
    elsif((n_res.odd? && t_res.odd?) || (n_res.even? && t_res.even?))
      (k - 1).times { res << t_res }
      res << n_res
    end
    (2..(k-1)).to_a.each do |i|
      t_res += 1
      n_res = (n - (t_res * (k-i))) / i
      if n_res < 1
      elsif((n_res.odd? && t_res.odd?) || (n_res.even? && t_res.even?))
        (k - i).times { res << t_res }
        i.times { res << n_res }
      end
      if res.length != 0 && res.reduce(&:+) == n
        break
      else
        res = []
      end
    end if res.length == 0
  end
  puts(res.length == 0 ? 'NO' : 'YES')
  next if res.length == 0
  puts(res.join(' '))
end

t = gets.to_i

def all(a,b)
  puts "YES"
  (1..a).each do
    print "#{b} "
  end
  puts
end

def printArr(arr)
  puts "YES"
  arr.each do |x|
    print "#{x} "
  end
  puts
end

(1).upto(t) do
  x = gets.split(' ')
  n = x[0].to_i
  k = x[1].to_i
  val1 = n/k
  val2 = n.modulo(k)
  if(val2 == 0)
    all(k,val1)
    next
  end
  arr = []
  (1..k).each do
    arr.push(val1)
  end
  if val2.modulo(2)==0
    arr[0]+=val2
    printArr(arr)
    next
  end
  if k.modulo(2)==0
    puts "NO"
    next
  end
  if arr[0]!=1
    (0.. arr.length-1).each do |i|
      arr[i]-=1
      val2+=1
    end
    arr[0]+=val2
    printArr(arr)
    next
  end
  puts "NO"
end

def func(n, k)
    res=2**40-1
    a=2**39
    while a>0
        t=res^a
        cnt=t-t/n
        res=t if cnt>=k
        a>>=1
    end
    res
end

gets.to_i.times{
    n, k=gets.split.map &:to_i
    puts func(n, k)
}

gets.to_i.times do
  n, k = gets.split.map &:to_i
  if n.even? and k.even?
    if k > n
      puts "NO"
    else
      puts "YES"
      puts "1 "*(k - 1) + (n - k + 1).to_s
    end
  elsif n.even? and k.odd?
    if k*2 > n
      puts "NO"
    else
      puts "YES"
      puts "2 "*(k - 1) + (n - (k - 1)*2).to_s
    end
  else
    if k.even?
      puts "NO"
    else
      puts "YES"
      puts "1 "*(k - 1) + (n - k + 1).to_s
    end
  end
end

n = gets.chomp.to_i

tests = []

n.times do
  tests.push(gets.split(' ').map {|e| e.to_i})
end

tests.each do |test|
  if test[0] % 2 == 1 && test[1] % 2 == 0 then
    puts 'NO'
    next
  end

  if test[0] < test[1] then
    puts 'NO'
    next
  end

  results = []

  if test[0] == test[1] then
    puts 'YES'
    results.fill(1, 0..test[1])
    puts results.join(' ')
    next
  end

  if test[0] % test[1] == 0 then
    puts 'YES'
    results.fill(test[0] / test[1], 0..test[1]-1)
    puts results.join(' ')
  elsif test[0] % 2 == 0 && test[1] % 2 == 1 then
    division = test[0] / test[1]
    division -= 1
    if division > 0 then
        results.fill(division, 0..test[1]-2)
        sum = results.reduce(0){|sum, value| sum + value}
        results.push(test[0] - sum)
        puts 'YES'
        puts results.join(' ')
    else
        puts 'NO'
    end
  elsif test[0] % 2 == 1 && test[1] % 2 == 1 then
    division = test[0] / test[1]
    results.fill(division, 0..test[1]-2)
    sum = results.reduce(0){|sum, value| sum + value}
    results.push(test[0] - sum)
            puts 'YES'
        puts results.join(' ')
  end
end

n = gets.chomp.to_i

tests = []

n.times do
  tests.push(gets.split(' ').map {|e| e.to_i})
end

tests.each do |test|
  if test[0] % 2 == 1 && test[1] % 2 == 0 then
    puts 'NO'
    next
  end

  if test[0] < test[1] then
    puts 'NO'
    next
  end

  results = []

  if test[0] == test[1] then
    puts 'YES'
    results.fill(1, 0..test[1]-1)
    puts results.join(' ')
    next
  end

  if test[0] % test[1] == 0 then
    puts 'YES'
    results.fill(test[0] / test[1], 0..test[1]-1)
    puts results.join(' ')
  elsif test[0] % 2 == 0 && test[1] % 2 == 1 then
    division = test[0] / test[1]
    division -= 1
    if division > 0 then
        results.fill(division, 0..test[1]-2)
        sum = results.reduce(0){|sum, value| sum + value}
        results.push(test[0] - sum)
        puts 'YES'
        puts results.join(' ')
    else
        puts 'NO'
    end
  elsif test[0] % 2 == 1 && test[1] % 2 == 1 then
    division = test[0] / test[1]
    results.fill(division, 0..test[1]-2)
    sum = results.reduce(0){|sum, value| sum + value}
    results.push(test[0] - sum)
            puts 'YES'
        puts results.join(' ')
  end
end

n = gets.chomp.to_i

tests = []

n.times do
  tests.push(gets.split(' ').map {|e| e.to_i})
end

tests.each do |test|
  n, k = test

  if n < k then
    puts 'NO'
    next
  end

  if n.odd? && k.even? then
    puts 'NO'
    next
  end

  if n - k == 1 && n.even? then
    puts 'NO'
    next
  end

  results = []
  if n.even? && k.odd? then
    results.fill(2, 0..k - 2)
    results_sum = results.reduce(0) {|sum, value| sum + value }
    results.push(n - results_sum)
    puts 'YES'
    puts results.join(' ')
  else
    results.fill(1, 0..k - 2)
    results_sum = results.reduce(0) {|sum, value| sum + value }
    results.push(n - results_sum)
    puts 'YES'
    puts results.join(' ')
  end

end

n = gets.chomp.to_i

tests = []

n.times do
  tests.push(gets.split(' ').map {|e| e.to_i})
end

tests.each do |test|
  n, k = test

  if n < k then
    puts 'NO'
    next
  end

  if n.odd? && k.even? then
    puts 'NO'
    next
  end

  if n - k == 1 && n.even? then
    puts 'NO'
    next
  end

  results = []

  results.fill(1, 0..k - 2)
  results_sum = results.reduce(0) {|sum, value| sum + value }
  results.push(n - results_sum)
  puts 'YES'
  puts results.join(' ')
end


Polycarp doesn't like integers that are divisible by $$$3$$$ or end with the digit $$$3$$$ in their decimal representation. Integers that meet both conditions are disliked by Polycarp, too.Polycarp starts to write out the positive (greater than $$$0$$$) integers which he likes: $$$1, 2, 4, 5, 7, 8, 10, 11, 14, 16, \dots$$$. Output the $$$k$$$-th element of this sequence (the elements are numbered from $$$1$$$).

The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. Each test case consists of one line containing one integer $$$k$$$ ($$$1 \le k \le 1000$$$).

For each test case, output in a separate line one integer $$$x$$$ — the $$$k$$$-th element of the sequence that was written out by Polycarp.

MOD = 10 ** 9 + 7
def gs; gets.chomp; end
def gi; gets.to_i; end
def gli; gets.split.map(&:to_i); end
def cyesno(x); puts x ? :Yes : :No; end
def uyesno(x); puts x ? :YES : :NO; end
def array_to_hash_by_count(c); Hash.new(0).tap { |x| c.each { |z| x[z] += 1 } }; end

a = []
c = 0
i = 1;
while c < 1010
  unless i% 3 == 0 || i % 10 == 3
    a << i
    c += 1
  end
  i += 1
end

gets.to_i.times do
  g = gets.to_i
  puts a[g-1]
end

# 1 2 3 4 5 6 7 8 9 1000
# 1 2 4 5 7 8 10 11 14 1666

t = gets.to_i
k = []
(0..t-1).each do
  x = gets.to_i
  k.push(x)
end

k.each do |i|
  j = 1
  c = 0
  while true
    if j % 3 != 0 && j % 10 != 3
      c += 1
    end
    if c == i
      puts j
      break
    end
    j += 1
  end
  # p arr
  # puts arr.last
end

t = gets.to_i
a = []
i = 1
while a.length() < 1001
  if i % 3 != 0 && i.to_s[-1] != "3"
    a << i
  end
  i += 1
end
while t > 0
  t  -= 1
  n = gets.to_i
  puts a[n - 1]
end

def solve(k)
  cnt = 0
  ptr = 0
  while cnt < k do
    ptr += 1
    next if ptr % 3 == 0 || ptr%10 == 3
    cnt += 1
  end
  ptr
end

t = gets.chomp.to_i

t.times do
  k = gets.chomp.to_i
  puts "#{solve(k)}\n"
end

MOD = 10 ** 9 + 7
def gs; gets.chomp; end
def gi; gets.to_i; end
def gli; gets.split.map(&:to_i); end
def cyesno(x); puts x ? :Yes : :No; end
def uyesno(x); puts x ? :YES : :NO; end
def array_to_hash_by_count(c); Hash.new(0).tap { |x| c.each { |z| x[z] += 1 } }; end

a = []
c = 0
i = 1;
while c < 1010
  unless i% 3 == 0 || i % 10 == 0
    a << i
    c += 1
  end
  i += 1
end

gets.to_i.times do
  g = gets.to_i
  puts a[g-1]
end


Coming up with a new problem isn't as easy as many people think. Sometimes it is hard enough to name it. We'll consider a title original if it doesn't occur as a substring in any titles of recent Codeforces problems. You've got the titles of n last problems — the strings, consisting of lowercase English letters. Your task is to find the shortest original title for the new problem. If there are multiple such titles, choose the lexicographically minimum one. Note, that title of the problem can't be an empty string.A substring s[l... r] (1 ≤ l ≤ r ≤ |s|) of string s = s1s2... s|s| (where |s| is the length of string s) is string slsl + 1... sr.String x = x1x2... xp is lexicographically smaller than string y = y1y2... yq, if either p < q and x1 = y1, x2 = y2, ... , xp = yp, or there exists such number r (r < p, r < q), that x1 = y1, x2 = y2, ... , xr = yr and xr + 1 < yr + 1. The string characters are compared by their ASCII codes.

The first line contains integer n (1 ≤ n ≤ 30) — the number of titles you've got to consider. Then follow n problem titles, one per line. Each title only consists of lowercase English letters (specifically, it doesn't contain any spaces) and has the length from 1 to 20, inclusive.

Print a string, consisting of lowercase English letters — the lexicographically minimum shortest original title.

5
threehorses
goodsubstrings
secret
primematrix
beautifulyear

NoteIn the first sample the first 9 letters of the English alphabet (a, b, c, d, e, f, g, h, i) occur in the problem titles, so the answer is letter j.In the second sample the titles contain 26 English letters, so the shortest original title cannot have length 1. Title aa occurs as a substring in the first title.

    def nl(x)
        case x[-1]
        when "a"
            return (x[0...-1] + "b")
        when "b"
            return (x[0...-1] + "c")
        when "c"
            return (x[0...-1] + "d")
        when "d"
            return (x[0...-1] + "e")
        when "e"
            return (x[0...-1] + "f")
        when "f"
            return (x[0...-1] + "g")
        when "g"
            return (x[0...-1] + "h")
        when "h"
            return (x[0...-1] + "i")
        when "i"
            return (x[0...-1] + "j")
        when "j"
            return (x[0...-1] + "k")
        when "k"
            return (x[0...-1] + "l")
        when "l"
            return (x[0...-1] + "m")
        when "m"
            return (x[0...-1] + "n")
        when "n"
            return (x[0...-1] + "o")
        when "o"
            return (x[0...-1] + "p")
        when "p"
            return (x[0...-1] + "q")
        when "q"
            return (x[0...-1] + "r")
        when "r"
            return (x[0...-1] + "s")
        when "s"
            return (x[0...-1] + "t")
        when "t"
            return (x[0...-1] + "u")
        when "u"
            return (x[0...-1] + "v")
        when "v"
            return (x[0...-1] + "w")
        when "w"
            return (x[0...-1] + "x")
        when "x"
            return (x[0...-1] + "y")
        when "y"
            return (x[0...-1] + "z")
        when "z"
            return nil
        end
    end

    def func(mas, st,n)
        ans = []
        for s in "a".."z" do
            t = true
            i = 0
            while t && i < n do
                if mas[i].include? (st + s) then
                    t = false
                end
                i += 1
            end
            if t then
                ans << (st + s)
            end
        end
        return ans
    end

    n = gets.to_i

    names = []
    n.times do
        names << gets.chomp
    end

    ans = func(names,"",n)
    st = "a"
    k = 1
    while ans.empty? do
        if !st then
            k += 1
            st = k*"a"
        end
        ans = func(names,st,n)
        st = nl(st)
    end

    puts ans.min

a = ''
n = gets.to_i.times{ a += (gets.to_s.chomp + ' ')}
s = 'a'
while a.index(s) != nil do
	s.next!
end
puts s

def get_str(x)
  abc = " abcdefghijklmnopqrstuvwxyz".split("")
  sn = x.to_s 27
  r = ""
  sn.split("").each do |l|
    r += abc[l.to_i 27]
  end
  r
end

tn = gets.chomp.to_i
titles = []
tn.times do
  titles.push(gets.chomp)
end

n = 0
while true do
  n+=1
  done = true
  if n%27 != 0 then
    str = get_str n
    titles.each do |ttl|
      if ttl.include? str then
        done = false
        break
      end
    end
    puts str if done
    break if done
  end
end

#!/usr/bin/ruby1.9

n = STDIN.readline.to_i
words = []
n.times { words.push(STDIN.readline.strip) }

title = ''

while true
	pos = title.length-1
	while true
		if pos == -1
			title = (title.length+1).times.collect { 'a' }.join
			break
		end
		if title[pos] < 'z'
			suffix = (title.length-1-pos).times.collect { 'a' }.join
			title = title.slice(0, pos) + title[pos].next + suffix
			break
		end
		pos -= 1
	end

	okay = true
	n.times do |i|
		if words[i].index(title) != nil
			okay = false
			break
		end
	end
	if okay
		puts title
		exit
	end
end

#!/usr/bin/ruby1.9

n = STDIN.readline.to_i
hash = {}
n.times do
	word = STDIN.readline.strip
	(0..word.length-1).each do |start|
		(1..word.length-start).each do |length|
			hash[word.slice(start, length)] = true
		end
	end
end

title = 'a'
title = title.next while hash[title] != nil
puts title

#!/usr/bin/ruby1.9

n = STDIN.readline.to_i
words = []
n.times { words.push(STDIN.readline.strip) }

title = 'a'

while true
	okay = true
	n.times do |i|
		if words[i].index(title) != nil
			okay = false
			break
		end
	end
	if okay
		puts title
		exit
	end

	title = title.next
end

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

found=false
res=""
for i in 'a'..'z' do
    ok=true
    s.each do |v|
        ok=false if v.include?(i)
    end
    if !found and ok then
        res=i
        found=true
    end
end

for i in 'a'..'z' do
    for j in 'a'..'z' do
        t=i+j
        ok=true
        s.each do |v|
            ok=false if v.include?(t)
        end
        if !found and ok then
            res=t
            found=true
        end
    end
end
puts res

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

# b.rb

def main()
    n = gets.to_i
    s = []
    n.times do |k|
        s << gets.chomp
    end

    l = 1
    while true do
        m = []
        n.times do |k|
            next if s[k].size < l
            (s[k].size - l + 1).times do |a|
                m << s[k][a, l]
            end
        end
        m = m.sort.uniq
        if m.size == 26 ** l then
            l += 1
            next
        end
        c = [*"a".."z"]
        (26 ** l).times do |i|
            ii = i
            ss = ""
            l.times do |b|
                ss = c[ii % 26] + ss
                ii = (ii - ii % 26) / 26
            end
            if !m.index(ss) then
                puts ss
                return
            end
        end
    end
end

if __FILE__ == $0 then
    main()
end

n=gets.chomp.to_i;
words=[]
for i in 0...n
    words[i]=gets.chomp
end
current="a"
loop do
    result=true
    words.each{|element|
        if element.include?(current)
            result=false
            break
        end
    }
    if result
        print current+"\n"
        break
    else
        current.succ!
    end
end

n = gets.to_i

@s = []
n.times do |i|
	@s[i] = gets
end

@alphabet = "a b c d e f g h i j k l m n o p q r s t u v w x y z".split(' ')

# allstring = s.join('')

def name_include?(str)
	@s.each do |i|
		return true if i.include?(str)
	end
	return false
end

def findname(myname)
	found = false
	@alphabet.each do |let|
		if !name_include?(let)
			myname += let
			found = true
			break
		end
	end
	if !found
		@alphabet.each do |let1|
			@alphabet.each do |let2|
				let = let1 + let2
				if !name_include?(let)
					myname += let
					found = true
					break
				end
			end
			break if found
		end
	end

	return myname
end

myname = findname("")

print myname

def main()
	n=gets.chomp.to_i
	ar=[]
	names=[]
	for i in 0...n
		s=gets.chomp
		names << s;
		for j in 0...(s.length)
			ch=s[j].chr
			if !ar.include?(ch)
				ar << ch;
			end
		end

	end
	alp=[*'a'..'z']
	ar=ar.sort
	if ar.join()==alp.join()
		j=1;f=0;
		while(f==0)
			alpr=alp.map {|i| i*j}
			for i in 0...26
				charc=alp[i]
				for j in 0...26
					newc=charc+(alpr[j])
					if !checkss(names,newc)
						f=1;
						puts newc;
						break;
					end
				end
				if f==1
					break;
				end
			end
		j+=1;
		end
	else
		rr=alp-ar
		puts rr[0]
	end
end

def checkss(names,s)
	for i in names
		if i.include?(s)
			return true;
		end
	end
	return false;
end
main

ns = gets.to_i.times.map { gets.chomp }
start = "a"
while ns.any? { |n| n.index(start) }
  start.succ!
end
puts start

n = gets.chomp.to_i
titles = []
(1..n).each{
   t = gets.chomp
   titles.push t
}
letters = ['']
letters += ('a'..'z').to_a

arr = []
letters.each { |l1|
  #arr.push l1
  letters.each { |l2|
    #arr.push "#{l1}#{l2}"
    letters.each { |l3|
	   arr.push  "#{l1}#{l2}#{l3}"
	}
  }
}
#puts "#{arr}"
arr.each { |t|
	ok = false
	titles.each { |title|
	    #puts "- #{title}"
		if title.include? t
		  ok = true
		end
	}
	if ok==false
		puts t
		break
	end
}

n = gets.to_i;
a = (0..n-1).inject([]) {|acc, y|
  s = gets.chomp
  b = (0..s.length-1).inject([]){ |ai, x|
    (x..s.length-1).inject(ai){ |aj, y|
      aj << s[x..y]
    }
  }
  acc + b
}.sort{ |x, y|
  if x.size < y.size
    -1
  elsif x.size > y.size
    1
  else
    if x <= y then -1 else 1 end
  end
}.uniq
ans="a"
a.each{|x|
  break if x != ans
  ans.succ!
}
puts ans

def titles(prefix = '', len)
  len -= 1
  block = (len == 0) ? lambda { |z| prefix + z } : lambda { |z| titles(prefix + z, len) }
  ('a'..'z').to_a.map &block
end

def solve(used_titles)
  (1..2).each { |i|
    titles(i).flatten.each { |title|
      return title if used_titles.all? { |used_title| !used_title.include? title }
    }
  }
end

if __FILE__ == $0
  puts solve((1..gets.to_i).map { gets.chomp })
end

def titles(prefix = '', len)
  len -= 1
  block = (len == 0) ? lambda { |z| prefix + z } : lambda { |z| titles(prefix + z, len) }
  ('a'..'z').to_a.map &block
end

def solve(used_titles)
  (1..3).each { |i|
    titles(i).flatten.each { |title|
      return title if used_titles.all? { |used_title| !used_title.include? title }
    }
  }
end

if __FILE__ == $0
  puts solve((1..gets.to_i).map { gets.chomp })
end

def get_str(x)
  abc = " abcdefghijklmnopqrstuvwxyz".split("")
  sn = x.to_s 27
  r = ""
  sn.split("").each do |l|
    r += abc[l.to_i 27]
  end
  r
end

n = gets.chomp.to_i
titles = []
n.times do
  titles.push(gets.chomp)
end

n = 0
while true do
  n+=1
  done = true
  if n%27 != 0 then
    str = get_str n
    titles.each do |ttl|
      puts ttl
      if ttl.include? str then
        done = false
        break
      end
    end
    puts str if done
    break if done
  end
end

#!/usr/bin/ruby

n = STDIN.readline.to_i

titles = []
n.times { titles.push(STDIN.readline.strip) }

answer = ''

while true
	('a'..'z').each do |ch|
		candidate = answer+ch
		okay = true
		titles.each do |title|
			if title.index(candidate) != nil
				okay = false
				break
			end
		end
		if okay
			puts candidate
			exit
		end
	end
	answer += 'a'
end

n = gets.to_i

s = []
n.times do |i|
	s[i] = gets
end

alphabet = "a b c d e f g h i j k l m n o p q r s t u v w x y z".split(' ')

myname = "idk"
found = false

allstring = s.join('')

alphabet.each do |let|
	if !allstring.include?(let)
		myname = let
		found = true
		break
	end
end

myname = "a" if !found
while !found do
	alphabet.each do |let|
		# p myname + let
		if !allstring.include?(myname + let)
			myname = myname + let
			found = true
			break
		end

		# myname += "a" if let = "z" && !found
	end
	myname += "a" if !found
end

p  myname

ns = gets.to_i.times.map { gets.chomp }
start = "a"
while ns.any? { |n| n.index(start) }
  start.succ!
end
p start


You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$.

The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters.

Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard.

5
abcdefghijklmnopqrstuvwxyz
hello
abcdefghijklmnopqrstuvwxyz
i
abcdefghijklmnopqrstuvwxyz
codeforces
qwertyuiopasdfghjklzxcvbnm
qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq
qwertyuiopasdfghjklzxcvbnm
abacaba

STDIN.read
  .split(/\n/)
  .drop(1)
  .map!(&:strip)
  .each_slice(2) do |alphabet, word|
    puts word
      .split("")
      .map{ |c| alphabet.index(c) }
      .each_cons(2)
      .map{|a, b| (a - b).abs}
      .sum
  end

t = gets.to_i
t.times do
    dist = {}
    keys = gets.chomp
    s = gets.chomp
    keys.each_char.with_index do |c, i|
        dist[c] = i
    end
    ans = 0
    s.chars.each_cons(2) do |c1, c2|
        ans += (dist[c1] - dist[c2]).abs
    end
    puts ans
end

n = gets.to_i
a = []

def find_ans(s,w)
  i = 0
  time = 0
  while (i < w.length - 1)
    if (w[i] == w[i+1])
      time += 0
    else
      time += (s.index(w[i]) - s.index(w[i+1])).abs
    end
    i += 1
  end
  time
end

(0..n-1).each do |x|
	s = gets.chomp
  w = gets.chomp
	a.append(find_ans(s,w))
end

a.each do |x|
 p x
end

gets.to_i.times do
  xs = gets.chomp.chars
  puts gets.chomp.chars.each_cons(2).map { |a, b| (xs.index(a) - xs.index(b)).abs }.sum
end

for _ in 0...gets.chomp.to_i
  keyboard = gets.chomp
  word = gets.chomp
  time = 0
  if word.length() <= 1
    puts time
  else
    for i in 0...(word.length() - 1)
      time += (keyboard.index(word[i]) - keyboard.index(word[i + 1])).abs
    end
    puts time
  end
end

arr = []
t = gets.chomp.to_i
index = 0
while t>index
    s1 = gets.chomp.chars
    s2 = gets.chomp.chars
    kol_s2 = s2.length.to_i-1
    summa =0;
    i=1;
    while kol_s2>=1
        if s2.length>1
            summa = summa + ((s1.index(s2[i]))-(s1.index(s2[i-1]))).abs
            kol_s2-=1
            i+=1
        else
            summa = 0
        end
    end
    arr[index] = summa
    index+=1
end
arr.each{|a| puts a}

gets.to_i.times do
  a=gets.chomp.chars
  h={}
  26.times do |i|
    h[a[i]]=i
  end
  c=0
  s=gets.chomp.chars
  (s.size-1).times do |i|
    c+=(h[s[i+1]]-h[s[i]]).abs
  end
  puts c
end


Little Vasya likes very much to play with sets consisting of positive integers. To make the game more interesting, Vasya chose n non-empty sets in such a way, that no two of them have common elements.One day he wanted to show his friends just how interesting playing with numbers is. For that he wrote out all possible unions of two different sets on n·(n - 1) / 2 pieces of paper. Then he shuffled the pieces of paper. He had written out the numbers in the unions in an arbitrary order.For example, if n = 4, and the actual sets have the following form {1, 3}, {5}, {2, 4}, {7}, then the number of set pairs equals to six. The six pieces of paper can contain the following numbers:   2, 7, 4.  1, 7, 3;  5, 4, 2;  1, 3, 5;  3, 1, 2, 4;  5, 7. Then Vasya showed the pieces of paper to his friends, but kept the n sets secret from them. His friends managed to calculate which sets Vasya had thought of in the first place. And how about you, can you restore the sets by the given pieces of paper?

The first input file line contains a number n (2 ≤ n ≤ 200), n is the number of sets at Vasya's disposal. Then follow sets of numbers from the pieces of paper written on n·(n - 1) / 2 lines. Each set starts with the number ki (2 ≤ ki ≤ 200), which is the number of numbers written of the i-th piece of paper, and then follow ki numbers aij (1 ≤ aij ≤ 200). All the numbers on the lines are separated by exactly one space. It is guaranteed that the input data is constructed according to the above given rules from n non-intersecting sets.

Print on n lines Vasya's sets' description. The first number on the line shows how many numbers the current set has. Then the set should be recorded by listing its elements. Separate the numbers by spaces. Each number and each set should be printed exactly once. Print the sets and the numbers in the sets in any order. If there are several answers to that problem, print any of them. It is guaranteed that there is a solution.

require 'set'
n = gets.to_i
m = n * (n - 1) / 2
b = m.times.map{gets.split.map(&:to_i)[1..-1].to_set}
if n == 2
	a = [b[0].to_a[0..0], b[0].to_a[1..-1]]
else
	a = []
	1.upto(b.size - 1) do |i|
		unless (b[0] & b[i]).empty?
			a << (b[0] & b[i])
			break
		end
	end
	b.each do |c|
		unless (c & a[0]).empty?
			a << (c - a[0])
		end
	end
end
a.each do |c|
	puts "#{c.size} #{c.to_a * ' '}"
end

def and_(x,y_)
        b=0
        res=[]
        y=y_+[9999999999]
        x.length.times{|a|
                while x[a]>y[b]
                        b+=1
                end
                if x[a]==y[b] then
                        res.push(x[a])
                end
        }
        return res
end

sets=[]
n=gets.to_i
(n*(n-1)/2).times{
        k=gets.split.map(&:to_i)
        k.shift
        k.sort!
        sets.push(k)

}
if n==2 then
        printf "1 %d\n",sets[0][0]
        printf "%d ",sets[0].length-1
        1.upto(sets[0].length-1){|i|
                printf "%d ",sets[0][i]
        }
        puts
        exit
end
ans={}
loop do
        i=rand(sets.length)
        j=rand(sets.length)
        if i==j then
                next
        end
        t=and_(sets[i],sets[j])

                if t.length==0 then
                        next
                end
                ans[t]=1

        if ans.length==n then
                break
        end
end
ans=ans.keys
ans.each{|a|
        printf "%d ",a.length
        a.each{|x|
                printf "%d ",x
        }
        puts
}

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

N = gets.to_i
h = Hash.new

(N * (N-1) / 2).times do |i|
  k, *as = gets.chomp.split.map{|e| e.to_i }

  as.each {|a|
    h[a] ||= []
    h[a].push i
  }
end

warn h

nh = Hash.new
h.each do |k, v|
  nh[v] ||= []
  nh[v].push k
end

if N != 2
  nh.each do |k,v|
    puts "#{v.size} #{v.join(" ")}"
  end
else
  tmp = nh[[0]]
  puts "1 #{tmp.pop}"
  puts "#{tmp.size} #{tmp.join(" ")}"
end

N = gets.to_i

h = Hash.new
(N * (N - 1) / 2).times do |i|
  k, *as = gets.chomp.split.map{|e| e.to_i}
  as.each {|a|
    h[a] ||= []
    h[a].push i
  }
end

new_hash = Hash.new
h.each {|k, v|
  new_hash[v] ||= []
  new_hash[v].push k
}

if N != 2
  new_hash.each {|k, v|
    puts "#{v.size} #{v.join(" ")}"
  }
else
  tmp = new_hash[[0]]
  puts "1 #{tmp.pop}"
  puts "#{tmp.size} #{tmp.join(" ")}"
end

#=================================
require 'prime'
include Math

if ARGV.include?("ONLINE_JUDGE")
	$stdin = File.open("./input.txt", "r")
	ARGV.delete("ONLINE_JUDGE")
end
#=================================

n=gets.to_i

sets=[]
all_sets=n*(n-1)/2

all_sets.times{
	set=gets.split.map(&:to_i)[1..-1]
	sets << set.sort
}

sets.sort!

if all_sets==1
	puts "1 #{sets[0][0]}"
	puts "#{sets[0][1..-1].size} #{sets[0][1..-1].join(" ")}"
	exit
end

resulting_sets=Hash.new(nil)
for i in 0...sets.size-1
	a, b=sets[i], sets[i+1]
	union=a&b

	if !union.empty?
		tmp_sets=[a-union, b-union, union]

		tmp_sets.each{|s| resulting_sets[s.sort]=1 if !resulting_sets.has_key?(s.sort)}
	end
end

resulting_sets.keys.each{|v|
	puts "#{v.size} #{v.join(" ")}"
}

n = gets.to_i
h = Hash.new { |hash, key| hash[key] = [] }
(n * (n - 1) / 2).times do |i|
  t, *v = gets.split.map(&:to_i)
  v.each do |x|
    h[x].push << i
  end
end

hash2 = Hash.new { |hash, key| hash[key] = [] }
h.each do |k, v|
  hash2[v] << k
end

if n != 2
  hash2.each do |k, v|
    puts "#{v.size} #{v.join(" ")}"
  end
else
  tmp = hash2[[0]]
  puts "1 #{tmp.pop}"
  puts "#{tmp.size} #{tmp.join(" ")}"
end

def and_(x,y_)
        b=0
        res=[]
        y=y_+[9999999999]
        x.length.times{|a|
                while x[a]>y[b]
                        b+=1
                end
                if x[a]==y[b] then
                        res.push(x[a])
                end
        }
        return res
end

sets=[]
n=gets.to_i
(n*(n-1)/2).times{
        k=gets.split.map(&:to_i)
        k.shift
        k.sort!
        sets.push(k)

}
if n==2 then
        printf "1 %d\n",sets[0][1]
        printf "%d ",sets[0].length-1
        1.upto(sets[0].length-1){|i|
                printf "%d ",sets[0][i]
        }
        puts
        exit
end
ans={}
loop do
        i=rand(sets.length)
        j=rand(sets.length)
        if i==j then
                next
        end
        t=and_(sets[i],sets[j])

                if t.length==0 then
                        next
                end
                ans[t]=1

        if ans.length==n then
                break
        end
end
ans=ans.keys
ans.each{|a|
        printf "%d ",a.length
        a.each{|x|
                printf "%d ",x
        }
        puts
}

def and(x,y_)
        b=0
        res=[]
        y=y_+[9999999999]
        x.length.times{|a|
                while x[a]<y[b]
                        b+=1
                end
                if x[a]==y[b] then
                        res.push(x[a])
                end
        }
        return res
end

sets=[]
n=gets.to_i
(n*(n-1)/2).times{
        k=gets.split.map(&:to_i)
        k.shift
        k.sort!
        sets.push(k)

}

ans={}
for i in 0..sets.length-2
        j=i+1
                t=sets[i]&sets[j]

                if t.length==0 then
                        next
                end
                ans[t]=1

        if ans.length==n then
                break
        end
end
ans=ans.keys
ans.each{|a|
        printf "%d ",a.length
        a.each{|x|
                printf "%d ",x
        }
        puts
}

def and_(x,y_)
        b=0
        res=[]
        y=y_+[9999999999]
        x.length.times{|a|
                while x[a]>y[b]
                        b+=1
                end
                if x[a]==y[b] then
                        res.push(x[a])
                end
        }
        return res
end

sets=[]
n=gets.to_i
(n*(n-1)/2).times{
        k=gets.split.map(&:to_i)
        k.shift
        k.sort!
        sets.push(k)

}
if n==2 then
        printf "1 %d\n",sets[0][1]
        printf "1 %d\n",sets[0][0]
        exit
end
ans={}
loop do
        i=rand(sets.length)
        j=rand(sets.length)
        if i==j then
                next
        end
        t=and_(sets[i],sets[j])

                if t.length==0 then
                        next
                end
                ans[t]=1

        if ans.length==n then
                break
        end
end
ans=ans.keys
ans.each{|a|
        printf "%d ",a.length
        a.each{|x|
                printf "%d ",x
        }
        puts
}

def and_(x,y_)
        b=0
        res=[]
        y=y_+[9999999999]
        x.length.times{|a|
                while x[a]>y[b]
                        b+=1
                end
                if x[a]==y[b] then
                        res.push(x[a])
                end
        }
        return res
end

sets=[]
n=gets.to_i
(n*(n-1)/2).times{
        k=gets.split.map(&:to_i)
        k.shift
        k.sort!
        sets.push(k)

}
if n==2 then
        printf "1 %d\n",sets[0][1]
        printf "2 %d\n",sets[0][0]
        exit
end
ans={}
loop do
        i=rand(sets.length)
        j=rand(sets.length)
        if i==j then
                next
        end
        t=and_(sets[i],sets[j])

                if t.length==0 then
                        next
                end
                ans[t]=1

        if ans.length==n then
                break
        end
end
ans=ans.keys
ans.each{|a|
        printf "%d ",a.length
        a.each{|x|
                printf "%d ",x
        }
        puts
}

#=================================
require 'prime'
include Math

if ARGV.include?("ONLINE_JUDGE")
	$stdin = File.open("./input.txt", "r")
	ARGV.delete("ONLINE_JUDGE")
end
#=================================

n=gets.to_i

sets=[]
all_sets=n*(n-1)/2
all_sets.times{
	set=gets.split.map(&:to_i)[1..-1]
	sets << set.sort
}

sets.sort!

resulting_sets=Hash.new(nil)
for i in 0...sets.size-1
	a, b=sets[i], sets[i+1]
	union=a&b

	if !union.empty?
		tmp_sets=[a-union, b-union, union]

		tmp_sets.each{|s| resulting_sets[s]=1 if !resulting_sets.has_key?(s)}
	end
end

resulting_sets.keys.each{|v|
	puts "#{v.size} #{v.join(" ")}"
}

#=================================
require 'prime'
include Math

if ARGV.include?("ONLINE_JUDGE")
	$stdin = File.open("./input.txt", "r")
	ARGV.delete("ONLINE_JUDGE")
end
#=================================

n=gets.to_i

sets=[]
all_sets=n*(n-1)/2
all_sets.times{
	set=gets.split.map(&:to_i)[1..-1]
	sets << set.sort
}

sets.sort!

resulting_sets=Hash.new(nil)
for i in 0...sets.size-1
	a, b=sets[i], sets[i+1]
	union=a&b

	if !union.empty?
		tmp_sets=[a-union, b-union, union]

		tmp_sets.each{|s| resulting_sets[s.sort]=1 if !resulting_sets.has_key?(s.sort)}
	end
end

resulting_sets.keys.each{|v|
	puts "#{v.size} #{v.join(" ")}"
}

#=================================
require 'prime'
include Math

if ARGV.include?("ONLINE_JUDGE")
	$stdin = File.open("./input.txt", "r")
	ARGV.delete("ONLINE_JUDGE")
end
#=================================

n=gets.to_i

sets=[]
all_sets=n*(n-1)/2

all_sets.times{
	set=gets.split.map(&:to_i)[1..-1]
	sets << set.sort
}

sets.sort!

if all_sets==1
	puts "1 #{sets[0][0]}"
	puts "1 #{sets[0][1]}"
	exit
end

resulting_sets=Hash.new(nil)
for i in 0...sets.size-1
	a, b=sets[i], sets[i+1]
	union=a&b

	if !union.empty?
		tmp_sets=[a-union, b-union, union]

		tmp_sets.each{|s| resulting_sets[s.sort]=1 if !resulting_sets.has_key?(s.sort)}
	end
end

resulting_sets.keys.each{|v|
	puts "#{v.size} #{v.join(" ")}"
}

#=================================
require 'prime'
include Math

if ARGV.include?("ONLINE_JUDGE")
	$stdin = File.open("./input.txt", "r")
	ARGV.delete("ONLINE_JUDGE")
end
#=================================

n=gets.to_i

sets=[]
all_sets=n*(n-1)/2

all_sets.times{
	set=gets.split.map(&:to_i)[1..-1]
	sets << set.sort
}

sets.sort!

if all_sets==1
	puts "1 #{sets[0][0]}"
	puts "1 #{sets[0][1..-1]}"
	exit
end

resulting_sets=Hash.new(nil)
for i in 0...sets.size-1
	a, b=sets[i], sets[i+1]
	union=a&b

	if !union.empty?
		tmp_sets=[a-union, b-union, union]

		tmp_sets.each{|s| resulting_sets[s.sort]=1 if !resulting_sets.has_key?(s.sort)}
	end
end

resulting_sets.keys.each{|v|
	puts "#{v.size} #{v.join(" ")}"
}

#=================================
require 'prime'
include Math

if ARGV.include?("ONLINE_JUDGE")
	$stdin = File.open("./input.txt", "r")
	ARGV.delete("ONLINE_JUDGE")
end
#=================================

n=gets.to_i

sets=[]
all_sets=n*(n-1)/2

all_sets.times{
	set=gets.split.map(&:to_i)[1..-1]
	sets << set.sort
}

sets.sort!

if all_sets==1
	puts "1 #{sets[0][0]}"
	puts "1 #{sets[0][1..-1].join(" ")}"
	exit
end

resulting_sets=Hash.new(nil)
for i in 0...sets.size-1
	a, b=sets[i], sets[i+1]
	union=a&b

	if !union.empty?
		tmp_sets=[a-union, b-union, union]

		tmp_sets.each{|s| resulting_sets[s.sort]=1 if !resulting_sets.has_key?(s.sort)}
	end
end

resulting_sets.keys.each{|v|
	puts "#{v.size} #{v.join(" ")}"
}

require 'set'

n = gets.to_i
sets = []
(n * (n - 1) / 2).times do
  t, *x = gets.split.map(&:to_i)
  sets << Set.new(x)
end

$EMPTY = Set.new

sol = Array.new
for i in 0...sets.size
  next if sets[i].empty?

  for j in (i + 1)...sets.size
    next if sets[j].empty?

    t = sets[i] & sets[j]
    unless t.empty?
      sol << t
      sets[i] -= t
      sets[j] -= t
      sol << sets[i] unless sets[i].empty?
      sol << sets[j] unless sets[j].empty?

      for k in (j + 1)...sets.size
        next if sets[k].empty?
        sets[k] -= sets[i]
        sets[k] -= sets[j]
        tt = sets[k] & t
        unless tt.empty?
          uu = sets[k] - t
          sol << sets[k] unless sets[k].empty?
          sets[k] = $EMPTY
        end
      end
      sets[i] = $EMPTY
      sets[j] = $EMPTY
    end
  end
end

sol.each do |x|
  print "#{x.size}"
  x.each do |t|
    print " #{t}"
  end
  puts ""
end


The problem describes the properties of a command line. The description somehow resembles the one you usually see in real operating systems. However, there are differences in the behavior. Please make sure you've read the statement attentively and use it as a formal document.In the Pindows operating system a strings are the lexemes of the command line — the first of them is understood as the name of the program to run and the following lexemes are its arguments. For example, as we execute the command " run.exe one, two . ", we give four lexemes to the Pindows command line: "run.exe", "one,", "two", ".". More formally, if we run a command that can be represented as string s (that has no quotes), then the command line lexemes are maximal by inclusion substrings of string s that contain no spaces.To send a string with spaces or an empty string as a command line lexeme, we can use double quotes. The block of characters that should be considered as one lexeme goes inside the quotes. Embedded quotes are prohibited — that is, for each occurrence of character """ we should be able to say clearly that the quotes are opening or closing. For example, as we run the command ""run.exe o" "" " ne, " two . " " ", we give six lexemes to the Pindows command line: "run.exe o", "" (an empty string), " ne, ", "two", ".", " " (a single space).It is guaranteed that each lexeme of the command line is either surrounded by spaces on both sides or touches the corresponding command border. One of its consequences is: the opening brackets are either the first character of the string or there is a space to the left of them.You have a string that consists of uppercase and lowercase English letters, digits, characters ".,?!"" and spaces. It is guaranteed that this string is a correct OS Pindows command line string. Print all lexemes of this command line string. Consider the character """ to be used only in order to denote a single block of characters into one command line lexeme. In particular, the consequence is that the given string has got an even number of such characters.

The single line contains a non-empty string s. String s consists of at most 105 characters. Each character is either an uppercase or a lowercase English letter, or a digit, or one of the ".,?!"" signs, or a space. It is guaranteed that the given string is some correct command line string of the OS Pindows. It is guaranteed that the given command line string contains at least one lexeme.

In the first line print the first lexeme, in the second line print the second one and so on. To make the output clearer, print the "<" (less) character to the left of your lexemes and the ">" (more) character to the right. Print the lexemes in the order in which they occur in the command. Please, follow the given output format strictly. For more clarifications on the output format see the test samples.

"RUn.exe O" "" "   2ne, " two! . " "
firstarg   second   ""

str = gets
regsplit = str.scan(/(\"[^\""]*\"|[^\"\s]+)/).flatten
lex = []
lex = regsplit.collect do |e|
    if e[0] == '"' then
        e = "<#{e[1,e.length-2]}>"
    else
        e = "<#{e}>"
    end
end
puts lex

s = gets.chomp
quote = false
t = ""
s.each_char do |c|
  if c == '"'
    quote = !quote
    if quote == false
      puts "<#{t}>"
      t=''
    end
  else
    if quote == false
      if c == ' '
        puts "<#{t}>" if t!=''
        t=""
      else
        t<<c
      end
    else
      t<<c
    end
  end
end

puts "<#{t}>" if t.size > 0

class Command
  attr_accessor :commands

  def initialize
    @commands = []
  end

  def read_commands command_string
    this_lexume = ''
    in_lexume = false
    block_mode = false
    command_string.each_char do |c|

      # Handle opening block
      if not in_lexume
        # New lexume if the char is not a space
        if c != ' '
          in_lexume = true
          block_mode = (c == '"')
          this_lexume = ''
          this_lexume << c if not block_mode
        end
        next
      end

      # Handle closing block
      if in_lexume
        if block_mode and c == '"'
          in_lexume = false
        end

        if not block_mode and c == ' '
          in_lexume = false
        end

        if not in_lexume
          @commands.push(this_lexume)
          next
        end

      end

      # Add char to this lexume
      this_lexume << c if in_lexume
    end

    # Handle the last lexume
    @commands.push(this_lexume) if in_lexume
  end

  def print_commands
    @commands.each do |command|
      puts "<#{command}>"
    end
  end
end

def main
  input = gets.chomp
  c = Command.new
  c.read_commands(input)
  c.print_commands
end

main

class Command
  attr_accessor :commands

  def initialize
    @commands = []
  end

  def read_commands command_string
    this_lexume = ''
    in_lexume = false
    block_mode = false
    command_string.each_char do |c|

      # Handle opening block
      if not in_lexume
        # New lexume if the char is not a space
        if c != ' '
          in_lexume = true
          block_mode = (c == '"')
          this_lexume = ''
          this_lexume << c if not block_mode
        end
        next
      end

      # Handle closing block
      if in_lexume
        in_lexume = false if block_mode and c == '"'
        in_lexume = false if not block_mode and c == ' '

        if in_lexume # If still in lexume, append the char
          this_lexume << c
        else # Else, save this lexume
          @commands.push(this_lexume)
          next
        end

      end
    end

    # Handle the last lexume
    @commands.push(this_lexume) if in_lexume
  end

  def print_commands
    @commands.each do |command|
      puts "<#{command}>"
    end
  end
end

def main
  input = gets.chomp
  c = Command.new
  c.read_commands(input)
  c.print_commands
end

main

class Command
  attr_accessor :commands

  def initialize
    @commands = []
  end

  def read_commands command_string
    this_lexume = ''
    in_lexume = false
    quote_mode = false
    command_string.each_char do |c|

      # Handle opening block
      if not in_lexume
        # New lexume if the char is not a space
        if c != ' '
          in_lexume = true
          quote_mode = (c == '"')
          this_lexume = ''
          this_lexume << c if not quote_mode
        end
        next
      end

      # Handle closing block
      if in_lexume
        in_lexume = false if quote_mode and c == '"'
        in_lexume = false if not quote_mode and c == ' '

        if in_lexume # If still in lexume, append the char
          this_lexume << c
        else # Else, save this lexume
          @commands.push(this_lexume)
          next
        end

      end
    end

    # Handle the last lexume
    @commands.push(this_lexume) if in_lexume
  end

  def print_commands
    @commands.each do |command|
      puts "<#{command}>"
    end
  end
end

def main
  input = gets.chomp
  c = Command.new
  c.read_commands(input)
  c.print_commands
end

main

class B
  def initialize
    str = $stdin.gets.chomp
    list = parse(str)

    list.each do |elem|
      puts "<#{elem}>"
    end
  end

  def parse(str)
    list = []
    elem = ""
    elem2 = ""
    flag = false
    str.each_char do |ch|
      if ch == '"'
        flag ^= true
        unless flag
          list << elem
          elem = ""
        end
        next
      end

      if ch != ' ' && !flag
        elem2 += ch
      elsif !flag
        list << elem2 if elem2.size > 0
        elem2 = ""
      end

      if flag && ch != '"'
        elem += ch
        next
      end
    end

    list << elem2 if elem2.size > 0
    list
  end
end

b = B.new

def parse_command(command)
  regex = /"(.*?)"|\s*([a-zA-Z0-9.,?!]+)\s*/
  command.scan(regex).map { |quoted, spaced| quoted || spaced }
end

command = STDIN.read
lexemes = parse_command(command)
lexemes.each { |lexeme| puts "<#{lexeme}>" }

s = gets.chomp

start = s.length
for i in 0...s.length
    if s[i] != " "
        start = i
        break
    end
end

i = start
if s.length - start > 1
    while i < s.length
        if s[i] != " "
            if s[i] == "\""
                #for j in i+1...s.length
                j = i + 1
                while j < s.length
                    if s[j] == "\""
                        stop = j
                        if start + 1 == stop
                            print "<>\n"
                        else
                            print "<", s[start+1..stop-1], ">\n"
                        end
                        start = j + 1
                        break
                    elsif j == s.length - 1
                        print "<", s[start], ">\n"
                        start += 1
                        break
                    end
                    j += 1
                end
            else
                #for j in i+1...s.length
                if i == s.length - 1
                    print "<", s[i], ">\n"
                    start = s.length
                else
                    j = i + 1
                    while j < s.length
                        if s[j] == " "
                            stop = j
                            print "<", s[start..stop-1], ">\n"
                            start = j + 1
                            break
                        elsif j == s.length - 1 && s[j] != " "
                            print "<", s[start..j], ">\n"
                            start = j + 1
                            break
                        end
                        j += 1
                    end
                end
            end
        else
            start += 1
        end
        i = start
    end
else
    print "<", s[start], ">\n"
end

s = gets.chomp

i = 0
state = 0
while i < s.length
    if state == 2
        if s[i].ord == 34
            print ">\n"
            state = 0
        else
            print s[i]
        end
    elsif state == 0
        if s[i].ord == 34
            state = 2
            print "<"
        elsif s[i].ord == 32
        else
            state = 1
            print "<"
            print s[i]
        end
    else
        if s[i].ord == 34
            state = 2
            print ">\n"
        elsif s[i].ord == 32
            print ">\n"
            state = 0
        else
            print s[i]
        end
    end
    i += 1
end
if state == 1
    print ">\n"
    state = 0
end

def output(str)
  puts "<#{str}>"
end

(" " << gets).split('"').each_with_index do |str, i|
  if i.even?
    str.split.each(&method(:output))
  else
    output(str)
  end
end

str=gets.chomp
q_flag=false
buf=""
str.each_char do |c|
    if c=='"' then
        if q_flag then
            print '<'
            print buf
            puts '>'
            buf=""
        end
        q_flag=!q_flag
        next
    end
    if q_flag
        buf=buf+c
    else
        if c==' ' && !buf.empty? then
            print '<'
            print buf
            puts '>'
            buf=""
        end
        if c!=' '
            buf=buf+c
        end
    end
end
if !buf.empty? then
    print '<'
    print buf
    puts '>'
end

result = []
i  = 0
qmode = false
(ARGF.readlines.last || '').strip.each_char do |c|
	result[i] = result[i] || ''
	case c
	when ' ' then
	if qmode
			result[i] << c
		else
			i+=1 unless result[i].empty?
		end
	when '"' then
		qmode = !qmode
		i+=1 unless (qmode && result[i].empty?)
	else
		result[i] << c
	end
end

puts result.map{|x| '<'+x+'>'}

s = gets.chomp
s += ' '
s.split(/"/).each_with_index do |l, i|
    if i%2 == 1
    puts "<#{l}>"
  else
    l.split(/ /).each do |w|
      puts "<#{w}>" unless w.size == 0
    end
  end
end

str = gets.chomp
ts = []
s = 0
p = ' '
word = false
for i in 0...str.size
  if word
    if str[i] == p
      ts << str[s...i]
      word = false
    end
  elsif str[i] != ' '
    if str[i] == '"'
      s = i + 1
      p = '"'
    else
      s = i
      p = ' '
    end
    word = true
  end
end
ts << str[s...str.size] if word
puts(ts.map { |t| "<#{t}>" })

str = gets.strip
lexems = []
state = :init
lexem = ''
str.chars.each do |char|
  case char
    when ' '
      if state == :quote_lexem
        lexem += char
      else
        state = :end_lexem
        lexems << lexem unless lexem.empty?
        lexem = ''
      end
    when '"'
      if state == :quote_lexem
        state = :end_lexem
        lexems << lexem
        lexem = ''
      else
        state = :quote_lexem
      end
    else
      lexem += char
  end
end
lexems << lexem unless lexem.empty?

lexems.each do |lexem|
  puts '<'+lexem+'>'
end

class B
  def initialize
    str = $stdin.gets.chomp
    list = parse(str)

    list.each do |elem|
      puts "<#{elem}>"
    end
  end

  def parse(str)
    list = []
    elem = ""
    elem2 = ""
    flag = false
    str.each_char do |ch|
      if ch == '"'
        flag ^= true
        unless flag
          list << elem
          elem = ""
        end
      end

      if ch != ' ' && ch != '"' && !flag
        elem2 += ch
      else
        list << elem2 if elem2.size > 0
        elem2 = ""
      end

      if flag && ch != '"'
        elem += ch
      end
    end

    list
  end
end

b = B.new

class B
  def initialize
    str = $stdin.gets.chomp
    list = parse(str)

    list.each do |elem|
      puts "<#{elem}>"
    end
  end

  def parse(str)
    list = []
    elem = ""
    elem2 = ""
    flag = false
    str.each_char do |ch|
      if ch == '"'
        flag ^= true
        unless flag
          list << elem
          elem = ""
        end
        next
      end

      if ch != ' ' && !flag
        elem2 += ch
        next
      elsif !flag
        list << elem2 if elem2.size > 0
        elem2 = ""
      end

      if flag && ch != '"'
        elem += ch
        next
      end
    end

    list
  end
end

b = B.new

s = gets.chomp

start = 0
for i in 0...s.length
    if s[i] != " "
        start = i
        break
    end
end

i = start
while i < s.length
    if s.length - start > 1
        if s[i] != " "
            if s[i] == "\""
                for j in i+1...s.length
                    if s[j] == "\""
                        stop = j
                        if start + 1 == stop
                            print "<>"
                            puts
                        else
                            print "<", s[start+1..stop-1], ">"
                            puts
                        end
                        start = j + 1
                        break
                    end
                end
            else
                for j in i+1...s.length
                    if s[j] == " "
                        stop = j
                        print "<", s[start..stop-1], ">"
                        puts
                        start = j + 1
                        break
                    end
                end
            end
        else
            start += 1
        end
        i = start
    else
        print "<", s[start], ">"
        break
    end
end

str = gets.chomp

str.scan(/(?:\.|"[^"]*")+/).each do |arg|
  puts "<#{arg.gsub /"/, ''}>"
end

str = gets.chomp

str.scan(/(?:\w|"[^"]*")+/).each do |arg|
  puts "<#{arg.gsub /"/, ''}>"
end

s = gets.chomp
if s=='""'
  puts "<>"
  exit
end
s.split(/"/).each_with_index do |l, i|
    if i%2 == 1
    puts "<#{l}>"
  else
    l.split(/ /).each do |w|
      puts "<#{w}>" unless w.size == 0
    end
  end
end

s = gets.chomp
s += ' '
puts s.split(/"/).inspect
s.split(/"/).each_with_index do |l, i|
    if i%2 == 1
    puts "<#{l}>"
  else
    l.split(/ /).each do |w|
      puts "<#{w}>" unless w.size == 0
    end
  end
end

str = gets.chomp
ts = []
s = 0
p = ' '
word = false
for i in 0...str.size
  if word
    if str[i] == p
      ts << str[s...i]
      word = false
    end
  elsif str[i] != ' '
    if str[i] == '"'
      s = i + 1
      p = '"'
    else
      s = i
      p = ' '
    end
    word = true
  end
end
puts(ts.map { |t| "<#{t}>" })

str = gets.strip
lexems = []
state = :init
lexem = ''
str.chars.each do |char|
  case char
    when ' '
      if state == :quote_lexem
        lexem += char
      else
        state = :end_lexem
        lexems << lexem unless lexem.empty?
        lexem = ''
      end
    when '"'
      if state == :quote_lexem
        state = :end_lexem
        lexems << lexem
        lexem = ''
      else
        state = :quote_lexem
      end
    else
      lexem += char
  end
end

lexems.each do |lexem|
  puts '<'+lexem+'>'
end


Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked.

The first line contains an integer n (1 ≤ n ≤ 100) — the number of leaves Alyona has found. The next n lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no more than 10 lowercase Latin letters. A name can not be an empty string. The species of a tree and the color are given in each line separated by a space.

Output the single number — the number of Alyona's leaves.

5
birch yellow
maple red
birch yellow
maple yellow
maple green

Leaf = Struct.new("Leaf", :tree, :color)

collection = {}

gets.to_i.times do
  collection[Leaf.new(*gets.split)] = true
end

puts collection.size

n = gets.to_i

t = {}
l = 0

n.times do |i|
    tree,color = gets.split
    if t[tree] then
        if !(t[tree].include? color) then
            t[tree] << color
            l += 1
        end
    else
        t[tree] = [color]
        l += 1
    end
end

puts l

n = gets.chomp.to_i
h = Hash.new
for i in 0..n-1
	h[gets.chomp] = true
end
puts h.length

#!/usr/bin/ruby
h={}
gets.to_i.times{h[gets]=1}
p h.size

n = gets.to_i

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

puts mas.uniq.size

ls = Hash.new { |a, b| a[b] = [] }
n, count = gets.to_i, 0

n.times do
	l, c = gets.strip.split(" ").map &:to_sym
	unless ls[l].include? c
		ls[l].push c
		count += 1
	end
end

print count


Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.

The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.

Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters. If there are multiple solutions, print any of them.

NoteThe second valid answer to the test from the statement is "heloo".

string = gets.chomp
length = string.length

character_old = nil
character_current = nil
count_old = 0
count_current = 0
i = 0
str = ""
while i < length do
  if string[i] != character_current
    print character_old * count_old if character_old
    character_old = character_current
    character_current = string[i]
    count_old = count_current
    count_current = 1
  else
    count_current += 1
    if count_current == 3
      count_current -= 1
    elsif count_current == 2
      if count_old == 2
        count_current -=1
      end
    else
    end
  end
  i += 1
end

print character_old * count_old if character_old
print character_current * count_current

s = gets.strip

a = Array.new(s.size + 5)
pos = 0

x = '*'
y = '!'
z = '~'

s.each_char do |c|
    next if y == z and z == c
    next if x == y and z == c

    pos += 1
    a[pos] = c

    x = y
    y = z
    z = c
end

1.upto(pos) do |i|
    print a[i]
end
puts ""

string = gets.chomp
length = string.length

character_old = nil
character_current = nil
count_old = 0
count_current = 0
i = 0
remove_indexes = []
while i < length do
  if string[i] != character_current
    character_old = character_current
    character_current = string[i]

    count_old = count_current
    count_current = 1
  else
    count_current += 1
    if count_current == 3
      remove_indexes << i - 1
      count_current -= 1
    elsif count_current == 2
      if count_old == 2
        remove_indexes << i - 2
        count_old -=1
      end
    else
    end
  end
  i += 1
end

str = ""
length.times do |i|
  str += string[i] unless remove_indexes.include?(i)
end

puts str

s = gets.chomp
ans = ""
s.each_char do |a|
	if (a == ans[-1] && a == ans[-2]) || ((a == ans[-1]) && (ans[-2] == ans[-3]))
	else
		ans << a
	end
end
puts ans

s = gets.strip

a = Array.new(s.size + 5)
pos = 0

x = '*'
y = '*'
z = '*'

s.each_char do |c|
    next if y == z and z == c
    next if x == y and z == c

    pos += 1
    a[pos] = c

    x = y
    y = z
    z = c
end

1.upto(pos) do |i|
    print a[i]
end
puts ""


You have $$$r$$$ red and $$$b$$$ blue beans. You'd like to distribute them among several (maybe, one) packets in such a way that each packet:   has at least one red bean (or the number of red beans $$$r_i \ge 1$$$);  has at least one blue bean (or the number of blue beans $$$b_i \ge 1$$$);  the number of red and blue beans should differ in no more than $$$d$$$ (or $$$|r_i - b_i| \le d$$$) Can you distribute all beans?

The first line contains the single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first and only line of each test case contains three integers $$$r$$$, $$$b$$$, and $$$d$$$ ($$$1 \le r, b \le 10^9$$$; $$$0 \le d \le 10^9$$$) — the number of red and blue beans and the maximum absolute difference in each packet.

For each test case, if you can distribute all beans, print YES. Otherwise, print NO. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as positive answer).

NoteIn the first test case, you can form one packet with $$$1$$$ red and $$$1$$$ blue bean. The absolute difference $$$|1 - 1| = 0 \le d$$$.In the second test case, you can form two packets: $$$1$$$ red and $$$4$$$ blue beans in the first packet and $$$1$$$ red and $$$3$$$ blue beans in the second one.In the third test case, since $$$b = 1$$$, you can form only one packet with $$$6$$$ red and $$$1$$$ blue beans. The absolute difference $$$|6 - 1| = 5 > d$$$.In the fourth test case, since $$$d = 0$$$ so each packet should contain the same number of red and blue beans, but $$$r \neq b$$$.

gets.to_i.times{
    r,b,d = gets.split.map(&:to_i)
    r,b = [r,b].sort
	b = (b.to_f/r.to_f).ceil
    if b-1>d
        puts "NO"
    else
        puts "YES"
    end
}

test_cases = gets.chomp.to_i
for i in 1..test_cases do
    line = gets.chomp.split(" ")
    r = line[0].to_i
    b = line[1].to_i
    d = line[2].to_i
    puts [r, b].min * (d + 1) >= [r, b].max ? "Yes" : "No"
end

t = gets.to_s.to_i

def solve(r, b, d)
  if d == 0
    return r == b
  end

  maxb = b + b * d
  return maxb >= r
end

1.upto(t) do |casenum|
  r, b, d = gets.to_s.split.map {|x| x.to_i }
  printf("%s\n", solve([r, b].max, [r, b].min, d) ? "YES" : "NO")
end

gets.to_i.times{
    r,b,d = gets.split.map(&:to_i)
    r,b = [r,b].sort
	b = (b/r)+b%r
    if b-1>d
        puts "NO"
    else
        puts "YES"
    end
}

gets.to_i.times{
    r,b,d = gets.split.map(&:to_i)
    r,b = [r,b].sort
	b = (b/r)+b%r
	p b
    if b-1>d
        puts "NO"
    else
        puts "YES"
    end
}