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

#=================================
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
(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 '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

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


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

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}>" }

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


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

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


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 ""


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

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
}

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
}


# http://codeforces.com/contest/1207/problem/A

def maximum_profit
  q = gets.chomp.to_i
  results = Array.new
  until q.zero? do
    ingredients = gets.chomp
    ingredients = get_each(ingredients)
    prices = gets.chomp
    prices = get_each(prices)
    results << get_maximum(ingredients, prices)
    q -= 1
  end
  results
end
$burger_num = 0

def get_maximum(ingredients, prices)
  $burger_num = ingredients[0]/2
  ham_num = ingredients[1]
  chicken_num = ingredients[2]
  pay = 0
  if prices[0] >= prices[1]
    pay += payment(prices[0], ham_num)
    pay += payment(prices[1], chicken_num)
  else
    pay += payment(prices[1], chicken_num)
    pay += payment(prices[0], ham_num)
  end
  pay
end

def payment(price, ingredient)
  pay = 0
  if $burger_num >= ingredient
    pay = price * ingredient
    $burger_num -= ingredient
  else
    pay = price * $burger_num
    $burger_num = 0
  end
  pay
end

def get_each(str)
  arr = Array.new
  num = 0
  str.each_char do |e|
    if e == ' '
      arr << num
      num = 0
    else
      num = num * 10 + e.to_i
    end
  end
  arr << num unless num.zero?
  arr
end

puts maximum_profit

t = readline.to_i

t.times do
  b,p,f = readline.split.map(&:to_i)
  h,c = readline.split.map(&:to_i)
  if h >= c
    p1 = [b/2,p].min
    p2 = [(b - 2*p1)/2,f].min
  else
    p2 = [b/2,f].min
    p1 = [(b - 2*p2)/2,p].min
  end
  puts h*p1 + c*p2
end

q = gets.to_i
q.times do
  n,a,b = gets.split.map(&:to_i)
  h,c = gets.split.map(&:to_i)
  ans = 0
  if h > c
    t = [n/2,a].min
    ans += t*h
    n -= t*2
    ans += c*[n/2,b].min
  else
    t = [n/2,b].min
    ans += t*c
    n -= t*2
    ans += h*[n/2,a].min
  end
  p ans
end

t=gets.to_i
while t > 0
  total = 0
  b, p, f = gets.split.map(&:to_i)
  h, c= gets.split.map(&:to_i)
  t-=1
  if h > c
      total += ([(b/2).to_i, p].min) * h
      b -= ([(b/2).to_i, p].min)*2
      total += ([(b/2).to_i, f].min) * c
  else
      total += ([(b/2).to_i, f].min) * c
      b -= ([(b/2).to_i, f].min)*2
      total += ([(b/2).to_i, p].min) * h
  end
  puts(total)
end

gets.to_i.times do
  b, p, f = gets.split.map(&:to_i)
  h, c = gets.split.map(&:to_i)
  ans = 0
  if h >= c
    p_num = [b/2, p].min
    b -= p_num * 2
    ans += p_num * h
    ans += [b/2, f].min * c
  else
    f_num = [b/2, f].min
    b -= f_num * 2
    ans += f_num * c
    ans += [b/2, p].min * h
  end
  puts ans
end

t = gets.to_i
bpf = []
hc = []
t.times do|_x|
   bpf << gets.split.map(&:to_i)
   hc << gets.split.map(&:to_i)
end

max = []
0.upto(t-1) do |i|
  price = 0
  buns = bpf[i][0]
  beef = bpf[i][1]
  chi = bpf[i][2]
  price1 = hc[i][0]
  price2 = hc[i][1]

  if price1 >= price2
    # ハンバーガーを優先して作る
    if beef*2 > buns
      # beefが多いならbunsが足りるまで使う
      price =  buns / 2 * price1
    else
      buns -= beef * 2
      price = beef*price1 + (chi*2>buns ? buns/2 : chi)*price2
    end
  else
    # チキンバーガーを優先して作る
    if chi*2 > buns
      # chiが多いならbunsが足りるまで使う
      price =  buns / 2 * price2
    else
      buns -= chi * 2
      price = chi*price2 + (beef*2>buns ? buns/2 : beef)*price1
    end
  end
  max << price
end
puts max.join("\n")

t = gets.to_i
t.times do
  b, p, f = gets.split.map &:to_i
  h, c = gets.split.map &:to_i
  if h > c
    hs = [b/2, p].min
    cs = [(b - hs*2)/2, f].min
  else
    cs = [b/2, f].min
    hs = [(b - cs*2)/2, p].min
  end
  puts hs*h + cs*c
end

1.upto(gets.to_i) do
  b, p, f = gets.split(' ').map(&:to_i)
  h, c = gets.split(' ').map(&:to_i)

  puts (0..b/2).map { |x| [x, p].min*h + [(b/2 - x), f].min*c }.max
end


n,m = gets.split.map &:to_i
a = [nil]*(n+m)
0.upto(n+m) {|i| a[i] = []}

0.upto(n-1) do |i|
  s = gets.chomp
  len = s.size
  0.upto(len) do |j|
    if s[j] == '#'
      a[i] << n+j
      a[n+j] << i
    end
  end
end

d = [100500] * 2100
q = []
d[0] = 0
q << 0
while !q.empty? do
  x = q.shift
  a[x].each do |y|
    if d[y] == 100500
      d[y] = d[x] + 1
      q << y
    end
  end
end

if d[n-1] == 100500
  puts -1
  exit
end
puts d[n-1]


gets.to_i.times {
  gets
  s = gets.strip
  n = s.count '0'
  if s.size.odd? && s[s.size / 2] == '0'
    puts(n > 1 ? 'ALICE' : 'BOB')
  else
    #puts(n % 4 == 0 ? 'DRAW' : 'BOB')
    puts 'BOB'
  end
}

gets.to_i.times{|c|
	n = gets.to_i
	s = gets.chomp
	if s.count(?0)==1 then
		puts 'BOB'
		next
	elsif s.count(?0)==0 then
		puts 'DRAW'
		next
	end
	puts (n%2==1&&s[n/2]=='0') ? 'ALICE' : 'BOB'
}

gets.to_i.times do
    gets
    s = gets.chomp
    cnt = s.count '0'
    if cnt == 1
        puts "BOB"
    elsif cnt % 2 == 1
        puts "ALICE"
    else
        puts "BOB"
    end
end

gets.to_i.times {
  gets
  n = gets.strip.count '0'
  puts(n % 4 == 0 ? 'DRAW' : 'BOB')
}


n, m = gets.split(' ').map(&:to_i)
l = gets.split(' ')
sa, r = l[0], []
a = sa.to_i
(1...n).each do |i|
  sb = l[i]
  b = sb.to_i
  l[i] = "#{a} #{b}"
  a, sa, sb = b, sb, sa, a if a < b
  r.push sb
end
n -= 1
m.times do
  q = gets.to_i
  puts n < q ? "#{a} #{r[(q - 1) % n]}" : l[q]
end

n, m = gets.split(' ').map(&:to_i)
l = gets.split(' ')
sa, r = l[0], []
a = sa.to_i
(1...n).each do |i|
  sb = l[i]
  b = sb.to_i
  l[i] = "#{a} #{b}"
  a, sa, sb = b, sb, sa, a if a < b
  r.push sb
end
n -= 1
m.times do
  q = gets.to_i
  puts n < q ? "#{sa} #{r[(q - 1) % n]}" : l[q]
end

inp = gets
n, q = inp.split(' ').map(&:to_i)

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

i_max = 0
deque = []
n_deque = 0

for i in 0..n-1
    if a[i] > a[i_max]
        i_max = i
    end
end

for i in i_max+1..n-1
    deque[n_deque] = a[i]
    n_deque += 1
end

st = []
ed = []
n_query = 0
i1 = 0
i2 = 1

while i1 != i_max
    st[n_query] = a[i1]
    ed[n_query] = a[i2]
    if a[i1] > a[i2]
        deque[n_deque] = a[i2]
        i2 += 1
    else
        deque[n_deque] = a[i1]
        i1 = i2
        i2 += 1
    end
    n_deque += 1
    n_query += 1
end

for i in 0..q-1
    inp = gets
    q_i = inp.to_i
    if q_i <= n_query
        puts "#{st[q_i-1]} #{ed[q_i-1]}"
    else
        puts "#{a[i_max]} #{deque[(q_i - i_max + n_deque) % n_deque - 1]}"
    end
end

n, m = gets.split(' ').map(&:to_i)
l = gets.split(' ').map(&:to_i)
a, r = l[0], []
(1...n).each do |i|
  b = l[i]
  l[i] = "#{a} #{b}"
  a, b = b, a if a < b
  r.push b
end
n -= 1
m.times do
  q = gets.to_i
  puts n < q ? "#{a} #{r[(q - 1) % n]}" : l[q]
end

inp = gets
n, q = inp.split(' ').map(&:to_i)

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

i_max = 0
deque = []
n_deque = 0

for i in 0..n-1
    if a[i] > a[i_max]
        i_max = i
    end
end

for i in i_max+1..n-1
    deque[n_deque] = a[i]
    n_deque += 1
end

st = []
ed = []
n_query = 0
i1 = 0
i2 = 1

while i1 != i_max
    st[n_query] = a[i1]
    ed[n_query] = a[i2]
    if a[i1] > a[i2]
        deque[n_deque] = a[i2]
        i2 += 1
    else
        deque[n_deque] = a[i1]
        i1 = i2
        i2 += 1
    end
    n_deque += 1
    n_query += 1
end

for i in 0..q-1
    inp = gets
    q_i = inp.to_i
    if q_i <= n_query
        puts "#{st[q_i-1]} #{ed[q_i-1]}"
    else
        puts i_max
        puts q_i
        puts n_deque
        puts "#{a[i_max]} #{deque[(q_i - i_max + n_deque) % n_deque - 1]}"
    end
end

n, m = gets.split(' ').map(&:to_i)
l = gets.split(' ').map(&:to_i)
a, buf, res = l.shift, [], []
l.each do |b|
  buf.push "#{a} #{b}"
  a, b = b, a if a < b
  res.push b
end
n -= 1
m.times do
  q = gets.to_i
  puts q < n ? buf[q - 1] : "#{a} #{res[(q - 1) % n]}"
end


n, m = gets.chomp.split(/ /).map(&:to_i)
ans = 4
n.times do |i|
    line = gets.chomp.split(/ /).map(&:to_i)
    m.times do |j|
        if line[j] == 1
            ans = 2 if i == 0 || i == n - 1
            ans = 2 if j == 0 || j == m - 1
        end
    end
end
puts ans

n, m = gets.split.map(&:to_i)
n.times do |i|
  a = gets.split(' ')
  if i == 0 || i == n-1
    if a.any? { |e| e == '1' }
      puts 2
      exit
    end
  elsif a.first == '1' || a.last == '1'
    puts 2
    exit
  end
end
puts 4

n,m=gets.chomp.split.map(&:to_i)
a=gets.chomp.split.include? '1'
for i in 0..n-3 do
	x=gets.chomp.split
	if x[-1]=='1' || x[0]=='1'
		b=true
	end
end
c=gets.chomp.split.include? '1'
puts (a||c||b)? "2" : "4"

def run
  m, n = $stdin.gets.split.map(&:to_i)
  a = $stdin.readlines.map {|line| line.split.map(&:to_i) }
  min = 4
  a.each_with_index do |x, i|
    x.each_with_index do |y, j|
      if y == 1
        cnt = 0
        cnt += 1 if i == 0 or i == m - 1
        cnt += 1 if j == 0 or j == n - 1

        if cnt == 1
          min = [2, min].min
        elsif cnt == 2
          min = [1, min].min
        end
      end
    end
  end

  puts min
end

run if $0 == __FILE__

m,n = gets.split(" ").map(&:to_i)
arr = []
m.times do
	arr << gets.split(" ").map(&:to_i)
end
ans = nil
ans = 2 if arr[0].include?(1) || arr[m-1].include?(1)
unless ans
	j = 0
	(0..m-1).each do |i|
		if arr[i][j] == 1
			ans = 2
			break
		end
	end
end

unless ans
	j = n - 1
	(0..m-1).each do |i|
		if arr[i][j] == 1
			ans = 2
			break
		end
	end
end

ans = 4 unless ans
puts ans

n, m = gets.split.collect{|i| i.to_i}
a = Array.new(n)
(0...n).each do |i|
    a[i] = gets.split
end
if a[0].count("1") > 0 or a[n-1].count("1") > 0 or\
   a.transpose[0].count("1") > 0 or a.transpose[m-1].count("1") > 0
    puts 2
else
    puts 4
end

def parse(s)
    s = s.split
    for i in 0...s.length do s[i] = s[i].to_i end
    s
end

n,m = parse gets
a = []
(0...n).each { |i|
    a << []
    (parse gets).each { |val|
        a[-1] << val
    }
}

(a[0]+a[-1]).each do |i| if i == 1 then puts 2; exit 0 end end
(0...n).each do |i| if a[i][-1] == 1 or a[i][0] == 1 then puts 2; exit 0 end end
puts 4

n,m=gets.split.map(&:to_i)
d=false
n.times do |i|
  r=gets.split.map(&:to_i)
  if (i==0||i==n-1)&&r.include?(1)||r[0]==1|| r[m-1]==1
    d=true
    break
  end
end
p d ? 2:4

line = gets.chomp.split(" ").map {|e| e.to_i}

side = false

table = []
line[0].times do
  row = gets.chomp.split(" ").map {|e| e.to_i}
  if ((table.length == 0 || table.length == (line[0] - 1)) && row.include?(1))
    side = true
  end

  if row[0] == 1 || row[line[1] - 1] == 1
    side = true
  end

  table.push(row)
end

if side
  puts 2
else
  puts 4
end

def main
    n, m = STDIN.readline.chomp.split.map{|x| x.to_i}
  lis = []
  n.times do |i|
    lis << STDIN.readline.chomp.split.map{|x|x.to_i}
  end

  if (not lis.first.select{|x| x == 1}.empty?) or (not lis.last.select{|x| x == 1}.empty?) then
    puts 2
    return
  else
    lis.each do |x|
      if x.first == 1 or x.last == 1 then
        puts 2
        return
      end
    end
  end
  puts 4
end

if __FILE__ == $0
  main
end

n, m = gets.split.map(&:to_i)
n.times do
  a = gets.split(' ')
  if a.first == '1' || a.last == '1'
    puts 2
    exit
  end
end
puts 4

n,m=gets.chomp.split.map(&:to_i)
a=gets.chomp.split.include? '1'
for i in 0..n-3 do
	x=gets.chomp.split
	if x[-1]=='1'
		b=true
	end
end
c=gets.chomp.split.include? '1'
puts (a||c||b)? "2" : "4"

n, m = gets.chomp.split(/ /).map(&:to_i)
good_cells = []
n.times do |i|
    line = gets.chomp.split(/ /).map(&:to_i)
    line.each do |j|
        good_cells << [i, j] if line[j] == 1
    end
end
ans = 4
good_cells.each do |cell|
    x = cell[0]
    y = cell[1]
    if x == 0 || y == 0 || x == n - 1 || y == m - 1
        ans = 2
        break
    end
end
puts ans

n, m = gets.chomp.split(/ /).map(&:to_i)
table = []
good_cells = []
n.times do |i|
    line = gets.chomp.split(/ /).map(&:to_i)
    line.each do |j|
        good_cells << [i, j] if line[j] == 1
    end
    table << line
end
ans = 4
good_cells.each do |cell|
    x = cell[0]
    y = cell[1]
    ans = 2 if x == 0 || y == 0 || x == n - 1 || y == m - 1
end
puts ans

n, m = gets.chomp.split(/ /).map(&:to_i)
table = []
good_cells = []
n.times do |i|
    line = gets.chomp.split(/ /).map(&:to_i)
    line.each do |j|
        good_cells << [i, j] if line[j] == 1
    end
    table << line
end
ans = 4
good_cells.each do |cell|
    x = cell[0]
    y = cell[1]
    ans = 2 if x == 0 || x == n - 1
    ans = 2 if y == 0 || y == m - 1
end
puts ans


require 'openssl'
require 'prime'

$stdout.sync = true

def ask(x)
  puts "sqrt #{x}"
  gets.to_i
end

def run(n)
  loop do
    a = rand(2..n - 1)
    g = n.gcd(a)
    return g if g != 1
    a2 = a * a % n
    next if a2.gcd(n) != 1
    r = ask(a2) % n
    next if r == -1 || r == a || r == n - a
    g = n.gcd(n + r - a)
    next if g == 1
    return g
  end
end

n = gets.to_i
fac = [n]

until fac.all?{|f| f.to_bn.prime?}
  x = run(n)
  nfac = []
  fac.each do |y|
    g = x.gcd(y)
    if g == 1 || g == y
      nfac << y
    else
      nfac << g << y / g
      x /= g
    end
  end
  fac << x if x > 1
  fac = nfac
end

puts "! #{fac.size} #{fac * ' '}"

def modpow(a,b,m)
  r = 1
  while b > 0
    r = r * a % m if b % 2 == 1
    a = a * a % m
    b >>= 1
  end
  return r
end

def isprime(n)
  return true if n == 2
  return false if n == 1 || n & 1 == 0
  d = n-1
  d >>= 1 while d & 1 == 0
  20.times do
    a = rand(n-2) + 1
    t = d
    y = modpow(a,t,n)
    while t != n-1 && y != 1 && y != n-1
      y = (y * y) % n
      t <<= 1
    end
    return false if y != n-1 && t & 1 == 0
  end
  return true
end

def solve(n,gn)
  # puts "solve #{n}"
  while true
    x = rand(1...n)
    x2 = x * x % gn
    puts "sqrt #{x2}"
    STDOUT.flush
    y = gets.chomp.to_i % n
    next if x == y
    gg = x - y
    gg = -gg if gg < 0
    q = n.gcd(gg)
    next if q == 1 or q == n
    # ok
    ret = []
    if isprime(q)
      ret.push(q)
    else
      ret = solve(q,gn)
    end
    q = n/q
    if isprime(q)
      ret.push(q)
    else
      ret.concat(solve(q,gn))
    end
    return ret
  end
end

n = gets.chomp.to_i
ans = solve(n,n)
ansstr = "! #{ans.length} #{ans.join(' ')}"
puts ansstr
STDOUT.flush

def modpow(a,b,m)
  r = 1
  while b > 0
    r = r * a % m if b % 2 == 1
    a = a * a % m
    b >>= 1
  end
  return r
end

def isprime(n)
  return true if n == 2
  return false if n == 1 || n & 1 == 0
  d = n-1
  d >>= 1 while d & 1 == 0
  20.times do
    a = rand(n-2) + 1
    t = d
    y = modpow(a,t,n)
    while t != n-1 && y != 1 && y != n-1
      y = (y * y) % n
      t <<= 1
    end
    return false if y != n-1 && t & 1 == 0
  end
  return true
end

def solve(n,gn)
  # puts "solve #{n}"
  while true
    x = rand(1...n)
    x2 = x * x % n
    puts "sqrt #{x2}"
    STDOUT.flush
    y = gets.chomp.to_i % n
    next if x == y
    gg = x - y
    gg = -gg if gg < 0
    q = n.gcd(gg)
    next if q == 1 or q == n
    # ok
    ret = []
    if isprime(q)
      ret.push(q)
    else
      ret = solve(q,gn)
    end
    q = n/q
    if isprime(q)
      ret.push(q)
    else
      ret.concat(solve(q,gn))
    end
    return ret
  end
end

n = gets.chomp.to_i
ans = solve(n,n)
ansstr = "! #{ans.length} #{ans.join(' ')}"
puts ansstr
STDOUT.flush

def modpow(a,b,m)
  r = 1
  while b > 0
    r = r * a % m if b % 2 == 1
    a = a * a % m
    b >>= 1
  end
  return r
end

def isprime(n)
  return true if n == 2
  return false if n == 1 || n & 1 == 0
  d = n-1
  d >>= 1 while d & 1 == 0
  20.times do
    a = rand(n-2) + 1
    t = d
    y = modpow(a,t,n)
    while t != n-1 && y != 1 && y != n-1
      y = (y * y) % n
      t <<= 1
    end
    return false if y != n-1 && t & 1 == 0
  end
  return true
end

def solve(n)
  while true
    x = rand(1...n)
    x2 = x * x % n
    puts "sqrt #{x2}"
    STDOUT.flush
    y = gets.chomp.to_i
    next if x == y
    gg = x - y
    gg = -gg if gg < 0
    q = n.gcd(gg)
    next if q == 1 or q == n
    # ok
    ret = []
    if isprime(q)
      ret.push(q)
    else
      ret = solve(q)
    end
    q = n/q
    if isprime(q)
      ret.push(q)
    else
      ret.concat(solve(q))
    end
    return ret
  end
end

n = gets.chomp.to_i
ans = solve(n)
m = 1
for i in 0...ans.length
  m = m * ans[i]
end
if m != n
  exit(1)
end
ansstr = "! #{ans.length} #{ans.join(' ')}"
puts ansstr
STDOUT.flush

def modpow(a,b,m)
  r = 1
  while b > 0
    r = r * a % m if b % 2 == 1
    a = a * a % m
    b >>= 1
  end
  return r
end

def isprime(n)
  return true if n == 2
  return false if n == 1 || n & 1 == 0
  d = n-1
  d >>= 1 while d & 1 == 0
  20.times do
    a = rand(n-2) + 1
    t = d
    y = modpow(a,t,n)
    while t != n-1 && y != 1 && y != n-1
      y = (y * y) % n
      t <<= 1
    end
    return false if y != n-1 && t & 1 == 0
  end
  return true
end

def solve(n)
  while true
    x = rand(1...n)
    x2 = x * x % n
    puts "sqrt #{x2}"
    STDOUT.flush
    y = gets.chomp.to_i
    next if x == y
    gg = x - y
    gg = -gg if gg < 0
    q = n.gcd(gg)
    next if q == 1 or q == n
    # ok
    ret = []
    if isprime(q)
      ret.push(q)
    else
      ret = solve(q)
    end
    q = n/q
    if isprime(q)
      ret.push(q)
    else
      ret.concat(solve(q))
    end
    return ret
  end
end

n = gets.chomp.to_i
ans = solve(n)
ansstr = "! #{ans.length} #{ans.join(' ')}"
puts ansstr

def modpow(a,b,m)
  r = 1
  while b > 0
    r = r * a % m if b % 2 == 1
    a = a * a % m
    b >>= 1
  end
  return r
end

def fa()
  n = 30
  while true
    n = n * n
    n = n % 252521
  end
  return n
end
cnt = 0

def isprime(n)
  return true if n == 2
  return false if n == 1 || n & 1 == 0
  d = n-1
  d >>= 1 while d & 1 == 0
  20.times do
    a = rand(n-2) + 1
    t = d
    y = modpow(a,t,n)
    while t != n-1 && y != 1 && y != n-1
      y = (y * y) % n
      t <<= 1
    end
    return false if y != n-1 && t & 1 == 0
  end
  return true
end

def solve(n)
  while true
    x = rand(1...n)
    x2 = x * x % n
    puts "sqrt #{x2}"
    STDOUT.flush
    y = gets.chomp.to_i % n
    next if x == y
    gg = x - y
    gg = -gg if gg < 0
    q = n.gcd(gg)
    next if q == 1 or q == n
    # ok
    ret = []
    if isprime(q)
      ret.push(q)
    else
      ret = solve(q)
    end
    q = n/q
    if isprime(q)
      ret.push(q)
    else
      ret.concat(solve(q))
    end
    return ret
  end
end

n = gets.chomp.to_i
ans = solve(n)
ansstr = "! #{ans.length} #{ans.join(' ')}"
puts ansstr
STDOUT.flush

require 'openssl'
require 'prime'

$stdout.sync = true
$sol = []
$memo = {}

def ask(x)
  return -1 if x.gcd($n) != 1
  return -1 if x < 0 || x >= $n
  return $memo[x] if $memo.include?(x)
  puts "sqrt #{x}"
  ans = gets.to_i
  $memo[x] = ans
  ans
end

def go(n)
  if n.to_bn.prime?
    $sol << n
    return
  end

  if n < 100000
    $sol += n.prime_division.map(&:first)
    return
  end

  loop do
    a = rand(2..n-1)
    g = n.gcd(a)
    if g != 1 && g != n
      go(g)
      go(n / g)
      break
    end
    a2 = a * a % n
    r = ask(a2)
    next if r == -1
    r %= n
    next unless r * r % n == a2
    next if r == a || r == n - a
    g = n.gcd(n + r - a)
    next if g == 1 || g == n
    go(g)
    go(n / g)
    break
  end
end

n = gets.to_i
$n = n
go(n)
puts "! #{$sol.size} #{$sol.sort.join(' ')}"

require 'openssl'
require 'prime'

$stdout.sync = true

def ask(x)
  puts "sqrt #{x}"
  gets.to_i
end

def run(n)
  loop do
    a = rand(2..n - 1)
    g = n.gcd(a)
    return g if g != 1
    a2 = a * a % n
    next if a2.gcd(n) != 1
    r = ask(a2) % n
    next if r == -1 || r == a || r == n - a
    g = n.gcd(n + r - a)
    next if g == 1
    return g
  end
end

n = gets.to_i
fac = [n]

until fac.all?{|f| f.to_bn.prime?}
  x = run(n)
  nfac = []
  fac.each do |y|
    g = x.gcd(y)
    if g == 1
      nfac << y
    else
      nfac << g << y / g
      x /= g
    end
  end
  fac = nfac
end

puts "! #{fac.size} #{fac * ' '}"

require 'openssl'
require 'prime'

$stdout.sync = true
$sol = []

def go(n)
  if n.to_bn.prime?
    $sol << n
    return
  end

  if n < 100000
    $sol += n.prime_division.map(&:first)
    return
  end

  loop do
    a = rand(2..n-1)
    g = n.gcd(a)
    if g != 1 && g != n
      go(g)
      go(n / g)
      break
    end
    a2 = a * a % n
    puts "sqrt #{a2}"
    r = gets.to_i
    next if r == -1
    r %= n
    next unless r * r % n == a2
    next if r == a || r == n - a
    g = n.gcd(n + r - a)
    next if g == 1 || g == n
    go(g)
    go(n / g)
    break
  end
end

n = gets.to_i
go(n)
puts "! #{$sol.size} #{$sol.sort.join(' ')}"

require 'openssl'
require 'prime'

$stdout.sync = true
$sol = []

def go(n)
  if n.to_bn.prime?
    $sol << n
    return
  end

  # if n < 100000
  #   $sol += n.prime_division.map(&:first)
  #   return
  # end

  loop do
    a = rand(2..n-1)
    a2 = a * a % n
    if a2 == 0
      g = n.gcd(a)
      next if g == 1 || g == n
      go(g)
      go(n / g)
      break
    end
    puts "sqrt #{a2}"
    r = gets.to_i
    next if r == -1
    r %= n
    next unless r * r % n == a2
    next if r == a || r == n - a
    g = n.gcd(n + r - a)
    next if g == 1 || g == n
    go(g)
    go(n / g)
    break
  end
end

n = gets.to_i
go(n)
puts "! #{$sol.size} #{$sol.sort.join(' ')}"

require 'openssl'
require 'prime'

$stdout.sync = true
$sol = []
$memo = {}

def ask(x)
  return -1 if x.gcd($n) != 1
  return $memo[x] if $memo.include?(x)
  puts "sqrt #{x}"
  ans = gets.to_i
  $memo[x] = ans
  ans
end

def go(n)
  if n.to_bn.prime?
    $sol << n
    return
  end

  if n < 100000
    $sol += n.prime_division.map(&:first)
    return
  end

  loop do
    a = rand(2..n-1)
    g = n.gcd(a)
    if g != 1 && g != n
      go(g)
      go(n / g)
      break
    end
    a2 = a * a % n
    r = ask(a2)
    next if r == -1
    r %= n
    next unless r * r % n == a2
    next if r == a || r == n - a
    g = n.gcd(n + r - a)
    next if g == 1 || g == n
    go(g)
    go(n / g)
    break
  end
end

n = gets.to_i
$n = n
go(n)
puts "! #{$sol.size} #{$sol.sort.join(' ')}"

require 'openssl'
require 'prime'

$stdout.sync = true
$sol = []

def ask(x)
  return -1 if x.gcd($n) != 1
  puts "sqrt #{x}"
  gets.to_i
end

def go(n)
  if n.to_bn.prime?
    $sol << n
    return
  end

  if n < 100000
    $sol += n.prime_division.map(&:first)
    return
  end

  loop do
    a = rand(2..n-1)
    g = n.gcd(a)
    if g != 1 && g != n
      go(g)
      go(n / g)
      break
    end
    a2 = a * a % n
    r = ask(a2)
    next if r == -1
    r %= n
    next unless r * r % n == a2
    next if r == a || r == n - a
    g = n.gcd(n + r - a)
    next if g == 1 || g == n
    go(g)
    go(n / g)
    break
  end
end

n = gets.to_i
$n = n
go(n)
puts "! #{$sol.size} #{$sol.sort.join(' ')}"

require 'openssl'
require 'prime'

$stdout.sync = true
$sol = []
$memo = {}

def ask(x)
  return -1 if x.gcd($n) != 1
  return -1 if x < 0 || x >= $n
  return $memo[x] if $memo.include?(x)
  puts "sqrt #{x}"
  ans = gets.to_i
  $memo[x] = ans
  ans
end

def go(n)
  if n.to_bn.prime?
    $sol << n
    return
  end

  if n < 1000000
    $sol += n.prime_division.map(&:first)
    return
  end

  loop do
    a = rand(2..n-1)
    g = n.gcd(a)
    if g != 1 && g != n
      go(g)
      go(n / g)
      break
    end
    a2 = a * a % n
    r = ask(a2)
    next if r == -1
    r %= n
    next unless r * r % n == a2
    next if r == a || r == n - a
    g = n.gcd(n + r - a)
    next if g == 1 || g == n
    go(g)
    go(n / g)
    break
  end
end

n = gets.to_i
$n = n
go(n)
puts "! #{$sol.size} #{$sol.sort.join(' ')}"

require 'openssl'
require 'prime'

$stdout.sync = true
$sol = []
$memo = {}

def ask(x)
  return -1 if x.gcd($n) != 1
  return -1 if x < 0 || x >= $n
  return $memo[x] if $memo.include?(x)
  puts "sqrt #{x}"
  ans = gets.to_i
  $memo[x] = ans
  ans
end

n = gets.to_i
$n = n

def chk(x)
  if x.to_bn.prime?
    $sol << x
    $sol.uniq!
    m = 1
    $sol.each{|t| m *= t}
    if m == $n
      puts "! #{$sol.size} #{$sol.sort.join(' ')}"
      exit
    end
  end
end

loop do
  a = rand(2..n-1)
  g = n.gcd(a)
  if g != 1 && g != n
    chk(g)
    chk(n / g)
    next
  end
  a2 = a * a % n
  r = ask(a2)
  next if r == -1
  r %= n
  next unless r * r % n == a2
  next if r == a || r == n - a
  g = n.gcd(n + r - a)
  next if g == 1 || g == n
  chk(g)
  chk(n / g)
end
puts "! #{$sol.size} #{$sol.sort.join(' ')}"

require 'openssl'
require 'prime'

$stdout.sync = true
$sol = []

def go(n)
  if n.to_bn.prime?
    $sol << n
    return
  end

  if n < 10000
    $sol += n.prime_division.map(&:first)
    return
  end

  loop do
    a = rand(2..n-1)
    a2 = a * a % n
    puts "sqrt #{a2}"
    r = gets.to_i
    next if r == -1 || r == a || r == n - a
    g = n.gcd(n + r - a)
    next if g == 1 || g == n
    go(g)
    go(n / g)
    break
  end
end

n = gets.to_i
go(n)
puts "! #{$sol.size} #{$sol.sort.join(' ')}"

require 'openssl'
require 'prime'

$stdout.sync = true
$sol = []

def go(n)
  if n.to_bn.prime?
    $sol << n
    return
  end

  if n < 10000
    $sol += n.prime_division.map(&:first)
    return
  end

  loop do
    a = rand(2..n-1)
    a2 = a * a % n
    puts "sqrt #{a2}"
    r = gets.to_i
    next if r == -1 || r == a || r == n - a
    g = n.gcd(n + r - a)
    next if g == 1 || g == n
    go(g)
    go(n / g)
    break
  end
end

n = gets.to_i
go(n)
puts "! #{$sol.sort.join(' ')}"


t = gets.chomp.to_i

def count_em(string, substring)
  string.scan(/(?=#{substring})/).count
end

vars = Hash.new

(1..t).each do
  n = gets.chomp.to_i
  (1..n).each do |j|
    inp = gets.chomp.split(" ")
    if inp[1] == ":="
      l = inp[2].length
      vars[inp[0]] = {cnt: count_em(inp[2], "haha"),
                      s: inp[2][0..2], end: inp[2][[l - 3, 0].max..l - 1]}
    else
      tmp = (vars[inp[2]][:end] + vars[inp[4]][:s])
      sum = vars[inp[2]][:cnt] + vars[inp[4]][:cnt]
      cont = count_em(tmp, "haha")
      l = tmp.length
      s = vars[inp[2]][:s]
      if s.length < 3 then s = (s + vars[inp[4]][:s])[0..2] end
      endd = vars[inp[4]][:end]
      if endd.length < 3
        endd = vars[inp[2]][:end] + endd
        l = endd.length
        endd = endd[[l - 3, 0].max..l - 1]
      end
      vars[inp[0]] = {cnt: sum + cont,
                      s: s,
                      end: endd}
    end
    puts vars[inp[0]][:cnt] if j == n
  end
end

def o (s)
  (0..(s.size - 1)).map {|i| s[i..i+3]}.select {|a| a == "haha"}.size
end

def add (s)
  [s, o(s)]
end

def m (s, t)
  x = s + t
  x = s[0..2] + 'x' + t.reverse[0..2].reverse if x.size > 6
  x
end

def cs (s, t)
  s.reverse[0..2].reverse + t[0..2]
end

def c (s, t)
  [m(s[0], t[0]), s[1] + t[1] + o(cs(s[0], t[0]))]
end

def solve (n, a)
  h = Hash.new
  last = []
  a.each {|s| last = h[s[0]] = (s[1] == ':=' ? add(s[2]) : c(h[s[2]], h[s[4]]))}
  last[1]
end

(1..(gets.to_i)).each { puts solve(n = gets.to_i, (1..n).map {|i| gets.split(' ')})}

def get_occ (s)
  (0..(s.size - 1)).map {|i| s[i..i+3]}.select {|a| a == "haha"}.size
end

def add (s)
  [s, get_occ(s)]
end

def merge_chars (s, t)
  x = s + t
  x = s[0..2] + 'x' + t[(t.size - [t.size, 3].min)..(t.size - 1)] if x.size >= 7
  x
end

def concat_sub_strings (s, t)
  s[(s.size - [s.size, 3].min)..(s.size - 1)] + t[0..2]
end

def concat (s, t)
  [merge_chars(s[0], t[0]), s[1] + t[1] + get_occ(concat_sub_strings(s[0], t[0]))]
end

def solve (n, a)
  mp = Hash.new
  last = []
  a.each {|s| last = mp[s[0]] = (s[1] == ':=' ? add(s[2]) : concat(mp[s[2]], mp[s[4]]))}
  last[1]
end

t = gets.to_i

(1..t).each do
  n = gets.to_i
  a = (1..n).map {|i| gets.split(' ')}
  puts solve(n, a)
end

def get_occ (s)
  (0..(s.size - 1)).map {|i| s[i..i+3]}.select {|a| a =="haha"}.size
end

def add (s)
  [s, get_occ(s)]
end

def merge_chars (s, t)
  x = s + t
  x = s[0..2] + 'x' + t[(t.size - [t.size, 3].min)..(t.size - 1)] if x.size > 6
  x
end

def concat (s, t)
  [merge_chars(s[0], t[0]), s[1] + t[1] + [1, get_occ(s[0] + t[0])].min]
end

def solve (n, a)
  mp = Hash.new
  last = []
  a.each {|s| last = mp[s[0]] = (s[1] == ':=' ? add(s[2]):concat(mp[s[2]], mp[s[4]]))}
  last[1]
end

t = gets.to_i

(1..t).each do
  n = gets.to_i
  a = (1..n).map {|i| gets.split(' ')}
  puts solve(n, a)
end

def get_occ (s)
  result = 0
  (0..(s.size - 1)).each do |i|
    a = s[i..i+3]
    result += 1 if a =="haha"
  end
  result
end

def add (s)
  [s, get_occ(s), s]
end

def merge_chars (s, t)
  x = s + t
  x = s[0..3] + 'x' + t[(t.size - [t.size, 3].min)..(t.size - 1)] if x.size > 6
  [x, x]
end

def concat (s, t)
  pref, suff = merge_chars(s[0], t[-1])
  [pref, s[1] + t[1] + get_occ(s[-1] + t[0]), suff]
end

def solve (n, a)
  mp = Hash.new
  last = []
  a.each do |s|
    if s[1] == ':='
      mp[s[0]] = add(s[2])
    else
      mp[s[0]] = concat(mp[s[2]], mp[s[4]])
    end
    last = mp[s[0]]
  end
  last[1] + 1
end

t = gets.to_i

(1..t).each do
  n = gets.to_i
  a = (1..n).map{|i| gets.split(' ')}
  puts solve(n, a) >> 1

end


N, M = gets.split.map(&:to_i)
min, max = 0, 0
N.times do |i|
    min += (i-N/2).abs
    max += i
end

ans = 0
M.times do
    x, d = gets.split.map(&:to_i)
    ans += N * x + d * (d>0 ? max : min)
end
puts ans.to_f/N

n, m = gets.strip.split.map(&:to_i)
aps = []
m.times do
  aps << gets.strip.split.map(&:to_i)
end

ps=0
po=0
aps.each do |ap|
  if ap[1]>=0
    po += ap[0]
    ps += ap[1]
  end
end

sum = 0
sum += (po * n)
sum += (ps * ((n*(n-1))/2))

ns=0
no=0
aps.each do |ap|
  if ap[1]<0
    no += ap[0]
    ns += ap[1]
  end
end

sum += (no * n)
if n%2==0
  an = n/2
  sum += (ns * ((an*(an+1))/2))
  sum += (ns * ((an*(an-1))/2))
else
  an = n/2
  sum += (ns * ((an*(an+1))/2))
  sum += (ns * ((an*(an+1))/2))
end

puts (1.0*sum)/(1.0*n)


gets.to_i.times.each do
  w0, h0 = gets.split.map(&:to_i)
  x1, y1, x2, y2 = gets.split.map(&:to_i)
  w, h = gets.split.map(&:to_i)
  dw = [w - [x1, w0 - x2].max, 0].max
  dh = [h - [y1, h0 - y2].max, 0].max
  nw = w0 < x2 - x1 + w
  nh = h0 < y2 - y1 + h
  puts case
    when nw && nh then -1
    when nw then dh
    when nh then dw
    else [dw, dh].min
  end
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

def solve
  w, h = gli
  x1, y1, x2, y2 = gli
  wq, hq = gli
  w1 = x2 - x1
  h1 = y2 - y1
  if w1 + wq > w && h1 + hq > h
    puts (-1) ** 1
  else
    d = []
    d << [wq - x1, 0].max if w1 + wq <= w
    d << [hq - y1, 0].max if h1 + hq <= h
    d << [y2 - (h - hq), 0].max if h1 + hq <= h
    d << [x2 - (w - wq), 0].max if w1 + wq <= w
    puts d.min
  end
end

def main
  gi.times { solve }
end

main

gets.to_i.times.each do
  w0, h0 = gets.split.map(&:to_i)
  x1, y1, x2, y2 = gets.split.map(&:to_i)
  w, h = gets.split.map(&:to_i)
  dw = w - [x1, w0 - x2].max
  dh = h - [y1, h0 - y2].max
  nw = w0 < x2 - x1 + w
  nh = h0 < y2 - y1 + h
  puts case
    when nw && nh then -1
    when nw then dh
    when nh then dw
    else [dh, dw].min
  end
end


n = gets
n = n.to_i

while n > 0 do
  a = gets
  a = a.split
  a[0] = a[0].to_f
  a[1] = a[1].to_f

  area1 = a[0] * a[1]
  #puts area1

  b = gets
  b = b.split

  b[0] = b[0].to_f
  b[1] = b[1].to_f

  area2 = b[0] * b[1]

  area_total = area1 + area2

  if a[0] + b[0] == a[1] and a[0] + b[0] == b[1]
    puts "Yes"
  elsif a[0] + b[1] == a[1] and a[0] + b[1] == b[0]
    puts "Yes"
  elsif a[1] + b[0] == a[0] and a[1] + b[0] == b[1]
    puts "Yes"
  elsif a[1] + b[1] == a[0] and a[1] + b[1] == b[0]
    puts "Yes"
  else
    puts "No"
  end
  n = n - 1
end

gets.to_i.times do
    a = gets.split.map(&:to_i).sort
    b = gets.split.map(&:to_i).sort
    puts a[0] + b[0] == a[1] && a[1] == b[1] ? :Yes : :No
end

t = gets.to_i
t.times do
	a, b = gets.split.map(&:to_i)
	c, d = gets.split.map(&:to_i)
	if (a == d && a == b + c) || (b == c && b == a + d) || (a == c && a == b + d) || (b == d && b == a + c)
		puts "Yes"
	else
		puts "No"
	end
end

i = gets.chomp.to_i

def isCube(b, c, d, e)
  if b + d == c && b + d == e
    return 1
  end

  if b + e == c && b + e == d
    return 1
  end

  if c + d == b && c + d == e
    return 1
  end

  if c + e == b && c + e == d
    return 1
  end

  return 0
end

while (i > 0)
  a1, a2 = gets.split.map(&:to_i)
  b1, b2 = gets.split.map(&:to_i)

  if isCube(a1, a2, b1, b2) == 1
    puts 'Yes'
  else
    puts 'No'
  end

  i -= 1
end

1.upto(gets.chomp.to_i) do

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

  if ([a,b].max == [c,d].max) && ([a,b].min + [c,d].min == [a,b].max)
    puts 'Yes'
  else
    puts 'No'
  end

end

t = gets.chomp.to_i
while t > 0
  r1 = gets.chomp.split(' ').map { |x| x.to_i }.sort
  r2 = gets.chomp.split(' ').map { |x| x.to_i }.sort

  if r1.last != r2.last
    puts 'No'
  elsif r1.last == r1.first + r2.first
    puts 'Yes'
  else
    puts 'No'
  end

  t -= 1
end

n = gets
n = n.to_i

while n > 0 do
  a = gets
  a = a.split
  a[0] = a[0].to_f
  a[1] = a[1].to_f

  area1 = a[0] * a[1]
  #puts area1

  b = gets
  b = b.split

  b[0] = b[0].to_f
  b[1] = b[1].to_f

  if a[0] + b[0] == a[1]
    puts "yes"
  elsif a[0] + b[1] == a[1]
    puts "yes"
  elsif a[1] + b[0] == a[0]
    puts "yes"
  elsif a[1] + b[1] == a[0]
    puts "yes"
  else
    puts "no"
  end
  n = n - 1
end

n = gets
n = n.to_i

while n > 0 do
  a = gets
  a = a.split
  a[0] = a[0].to_f
  a[1] = a[1].to_f

  area1 = a[0] * a[1]
  #puts area1

  b = gets
  b = b.split

  b[0] = b[0].to_f
  b[1] = b[1].to_f

  area2 = b[0] * b[1]

  area_total = area1 + area2

  if a[0] + b[0] == a[1] and a[0] + b[0] == b[1]
    puts "Yes"
  elsif a[0] + b[1] == a[1] and a[0] + b[1] == b[1]
    puts "Yes"
  elsif a[1] + b[0] == a[0] and a[1] + b[0] == b[0]
    puts "Yes"
  elsif a[1] + b[1] == a[0] and a[1] + b[1] == b[0]
    puts "Yes"
  else
    puts "No"
  end
  n = n - 1
end

n = gets
n = n.to_i

while n > 0 do
  a = gets
  a = a.split
  a[0] = a[0].to_f
  a[1] = a[1].to_f

  area1 = a[0] * a[1]
  #puts area1

  b = gets
  b = b.split

  b[0] = b[0].to_f
  b[1] = b[1].to_f

  if a[0] + b[0] == a[1]
    puts "Yes"
  elsif a[0] + b[1] == a[1]
    puts "Yes"
  elsif a[1] + b[0] == a[0]
    puts "Yes"
  elsif a[1] + b[1] == a[0]
    puts "Yes"
  else
    puts "No"
  end
  n = n - 1
end

n = gets
n = n.to_i

while n > 0 do
  a = gets
  a = a.split
  a[0] = a[0].to_f
  a[1] = a[1].to_f

  area1 = a[0] * a[1]

  b = gets
  b = b.split

  b[0] = b[0].to_f
  b[1] = b[1].to_f

  area2 = b[0] * b[1]

  area_total = area1 + area2

  if Math.sqrt(area_total) % 1 == 0
    if ( a[0] + b[0] != a[1] + b[1] ) or ( a[0] + b[1] != a[1] + b[0] )
      puts "no"
      break
    end
    puts "yes"
  else
    puts "no"
  end
  n = n - 1
end

n = gets
n = n.to_i

while n > 0 do
  a = gets
  a = a.split
  a[0] = a[0].to_f
  a[1] = a[1].to_f

  area1 = a[0] * a[1]
  #puts area1

  b = gets
  b = b.split

  b[0] = b[0].to_f
  b[1] = b[1].to_f

  area2 = b[0] * b[1]

  area_total = area1 + area2

  if Math.sqrt(area_total) % 1 == 0
    if (( a[0] + b[0] != a[1] + b[1] ) and ( a[0] + b[1] != a[1] + b[0] )) and Math.sqrt(area_total) % 2 == 0
      puts "no"
    else
      puts "yes"
    end

  else
    puts "no"
  end
  n = n - 1
end

n = gets
n = n.to_i

while n > 0 do
  a = gets
  a = a.split
  a[0] = a[0].to_f
  a[1] = a[1].to_f

  area1 = a[0] * a[1]
  #puts area1

  b = gets
  b = b.split

  b[0] = b[0].to_f
  b[1] = b[1].to_f

  area2 = b[0] * b[1]

  area_total = area1 + area2

  if Math.sqrt(area_total) % 1 == 0
    if ( a[0] + b[0] != a[1] + b[1] ) or ( a[0] + b[1] != a[1] + b[0] )
      puts "no"
      break
    end
    puts "yes"
  else
    puts "no"
  end
  n = n - 1
end

n = gets
n = n.to_i

while n > 0 do
  a = gets
  a = a.split
  a[0] = a[0].to_f
  a[1] = a[1].to_f

  area1 = a[0] * a[1]
  #puts area1

  b = gets
  b = b.split

  b[0] = b[0].to_f
  b[1] = b[1].to_f

  area2 = b[0] * b[1]

  area_total = area1 + area2

  if Math.sqrt(area_total) % 1 == 0
    if ( a[0] + b[0] != a[1] + b[1] ) or ( a[0] + b[1] != a[1] + b[0] )
      puts "no"
    else
      puts "yes"
    end

  else
    puts "no"
  end
  n = n - 1
end

n = gets
n = n.to_i

while n > 0 do
  a = gets
  a = a.split
  a[0] = a[0].to_f
  a[1] = a[1].to_f

  area1 = a[0] * a[1]
  #puts area1

  b = gets
  b = b.split

  b[0] = b[0].to_f
  b[1] = b[1].to_f

  area2 = b[0] * b[1]

  area_total = area1 + area2

  if Math.sqrt(area_total) % 1 == 0
    puts "yes"
  else
    puts "no"
  end
  n = n - 1
end

n = gets
n = n.to_i

while n > 0 do
  a = gets
  a = a.split
  a[0] = a[0].to_f
  a[1] = a[1].to_f

  area1 = a[0] * a[1]
  #puts area1

  b = gets
  b = b.split

  b[0] = b[0].to_f
  b[1] = b[1].to_f

  area2 = b[0] * b[1]

  area_total = area1 + area2

  if Math.sqrt(area_total) % 1 == 0
    if (( a[0] + b[0] != a[1] + b[1] ) or ( a[0] + b[1] != a[1] + b[0] )) and Math.sqrt(area_total) % 2 == 0
      puts "no"
    else
      puts "yes"
    end

  else
    puts "no"
  end
  n = n - 1
end

t = gets.to_i
t.times do
	a, b = gets.split.map(&:to_i)
	c, d = gets.split.map(&:to_i)
	if (a == d && a == b + c) || (b == c && b == a + d)
		puts "Yes"
	else
		puts "No"
	end
end

t = gets.to_i
t.times do
	a, b = gets.split.map(&:to_i)
	c, d = gets.split.map(&:to_i)
	if (a == d && a == b + c) || (b == c && b == a + d) || (a == c && a == b + d)
		puts "Yes"
	else
		puts "No"
	end
end

n = gets.to_i
for i in 1..n
    a1, b1 = gets.chomp.split(' ').map(&:to_i)
    a2, b2 = gets.chomp.split(' ').map(&:to_i)
    if a1 == a2
        if b1 + b2 == a1
            puts "YES"
        else
            puts "NO"
        end
    elsif a1 == b2
        if b1 + a2 == a1
            puts "YES"
        else
            puts "NO"
        end
    elsif a2 == b1
        if a1 + b2 == a2
            puts "YES"
        else
            puts "NO"
        end
    elsif b1 == b2
        if a1 + a2 == b2
            puts "YES"
        else
            puts "NO"
        end
    else
        puts "NO"
    end
end


def is_white?(x, y)
    (x + y)%2 == 0
end

def is_black?(x, y)
    (x + y)%2 != 0
end

def white(x1, y1, x2, y2)
    return 0 if x2 < x1 || y2 < y1
    o = 1 + (x2 - x1)/2
    e = (x2 - x1 + 1)/2
    no = 1 + (y2 - y1)/2
    ne = (y2 - y1 + 1)/2

    if is_white?(x1, y1)
        no*o + ne*e
    else
        ne*o + no*e
    end
end

def black(x1, y1, x2, y2)
    return 0 if x2 < x1 || y2 < y1
    o = 1 + (x2 - x1)/2
    e = (x2 - x1 + 1)/2
    no = 1 + (y2 - y1)/2
    ne = (y2 - y1 + 1)/2

    if is_black?(x1, y1)
        no*o + ne*e
    else
        ne*o + no*e
    end
end

def intersect(x1, y1, x2, y2, x3, y3, x4, y4)
    f, s = [x1, y1, x2, y2], [x3, y3, x4, y4]
    f, s = s, f if x3 < x1
    return nil if s[1] > f[3] || s[0] > f[2] || s[3] < f[1]
    xi1, yi1 = [f[2], s[0]].min, [f[1], s[1]].max
    xi2, yi2 = [s[2], f[2]].min, [s[3], f[3]].min
    [xi1, yi1, xi2, yi2]
end

t = gets.to_i
t.times do
    n, m = gets.split.map{|x| x.to_i}
    x1, y1, x2, y2 = gets.split.map{|x| x.to_i}
    x3, y3, x4, y4 = gets.split.map{|x| x.to_i}
    nwhite = white(1, 1, m, n)
    nblack = black(1, 1, m, n)
    #p [nwhite, nblack]
    nwhite += black(x1, y1, x2, y2)
    nblack -= black(x1, y1, x2, y2)
    #p [nwhite, nblack]
    inter = intersect(x1, y1, x2, y2, x3, y3, x4, y4)
    #p inter
    if inter
        ab = black(inter[0], inter[1], inter[2], inter[3])
    else
        ab = 0
    end
    nwhite -= white(x3, y3, x4, y4) + ab
    nblack += white(x3, y3, x4, y4) + ab
    puts nwhite.to_s + ' ' + nblack.to_s
end

t = gets.to_i

def colorsin(a,b,n,m)

  squares = (n-a+1)*(m-b+1)
  if (a+b)%2 == 0 #bottom left square is white (more whites)
    black = squares/2
    white = squares-black
  else
    white = squares/2
    black = squares-white
  end

  return [white,black]
end

t.times do
  nm = gets.chomp.split(" ").map(&:to_i)
  rec1 = gets.chomp.split(" ").map(&:to_i)
  rec2 = gets.chomp.split(" ").map(&:to_i)

  n = nm[0]
  m = nm[1]

  x1 = rec1[0]
  y1 = rec1[1]
  x2 = rec1[2]
  y2 = rec1[3]

  x3 = rec2[0]
  y3 = rec2[1]
  x4 = rec2[2]
  y4 = rec2[3]

  squares = n*m
  blacks = (squares)/2
  whites = squares-blacks

  overlap = true
  if (x3>x2 || x4<x1 || y3>y2 || y4<y1)
    overlap = false
  end

  if overlap
    if (x3<=x1)
      x5 = x1
      if (x4<=x2)
        x6 = x4
      else
        x6 = x2
      end
    else
      x5 = x3
      if (x4<=x2)
        x6 = x4
      else
        x6 = x2
      end
    end

    if (y3<=y1)
      y5 = y1
      if (y4<=y2)
        y6 = y4
      else
        y6 = y2
      end
    else
      y5 = y3
      if (y4<=y2)
        y6 = y4
      else
        y6 = y2
      end
    end
  end

  #do for white paint
  colorone = colorsin(x1,y1,x2,y2)
  whites += colorone[1]
  blacks -= colorone[1]

  #do for black paint

  colortwo = colorsin(x3,y3,x4,y4)
  blacks += colortwo[0]
  whites -= colortwo[0]

  if overlap
    colorthree = colorsin(x5,y5,x6,y6)
    blacks += colorthree[1]
    whites -= colorthree[1]
  end

  puts "#{whites} #{blacks}"
end


t = gets.to_i
ans = []
t.times do
  n = gets.to_i
  a = gets.chomp.split(" ").map(&:to_i)
  max = a.max
  index = -1
  n.times do |i|
    if a[i] == max
      if (i-1 >= 0 && a[i-1] != max) || (i+1 < n && a[i+1] != max)
        index = i+1
      end
    end
  end
  ans << index
end
puts ans

T = gets.to_i

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

  ans = -1

  n.times do |i|
    next if a[i] != m

    if i - 1 >= 0 && a[i - 1] < m
      ans = i + 1
    end

    if i + 1 < n && a[i + 1] < m
      ans = i + 1
    end
  end

  puts ans
end

t = gets.chomp.to_i
t.times do
    n = gets.chomp.to_i
    a = gets.chomp.split(" ").map(&:to_i)
    max = 0
    arr = []
    count = 0
    a.each_with_index do |i,j|
        max = [max,i].max
        if n >= 3
            if i >= max && j >= 1 && j <= n - 2
                if i != a[j-1] || i != a[j+1]
                    arr << j
                end
            elsif i >= max && j == 0
                # p i
                # puts "I"
                if i != a[j+1]
                    # p i
                    # p j
                    # puts "Iiiii"
                    arr << j
                end
            elsif i >= max && j == n - 1
                if i != a[j-1]
                    arr << j
                end
            #max = [max,i].max
            #arr << j
            #count += 1
            end
        end
        # puts "OOOOO"
        # p max
        # puts "IIIIIIIII"
    end
    if n == 2
        big = a.max
        a.each_with_index do |i,j|
            if i == big
                arr << j
            end
        end
    end
    a = a.map(&:to_s)
    a = a.uniq
    if a.size == 1
        puts "-1"
    else
        ans = arr.pop + 1
        puts ans
    end
end

gets.to_i.times do
  n = gets.to_i
  v = gets.split.map(&:to_i)
  max = v.max
  r = (0...n).find do |i|
    v[i] == max && ((i > 0 && v[i] > v[i-1]) || (i+1 < n && v[i] > v[i+1]))
  end
  puts r.nil? ? -1 : r+1
end

gets.to_i.times do
  n = gets.to_i
  v = gets.split.map(&:to_i)
  max = v.max
  r = (0...n).find { |i| v[i] == max && ((i > 0 && v[i] > v[i - 1]) || (i + 1 < n && v[i] > v[i + 1])) }
  puts r.nil? ? -1 : r + 1
end

gets.to_i.times do
  n = gets.to_i
  a = gets.split.map(&:to_i)
  ma = a.max
  next puts(-1) if a.count(ma) == a.length
  puts (n.times do |i|
    break i + 1 if i > 0 and a[i] == ma and a[i] > a[i - 1]
    break i + 1 if a[i] == ma and a[i] > a[i + 1]
    end
  )
end

gets.to_i.times do
  n = gets.to_i
  a = gets.split.map(&:to_i)
  ma = a.max
  if a.count(ma) == a.length
    puts(-1)
  else
    puts (n.times do |i|
      break i + 1 if i > 0 and a[i] == ma and a[i] > a[i - 1]
      break i + 1 if a[i] == ma and a[i] > a[i + 1]
      end
    )
  end
end

t=gets.to_i
t.times do
  n=gets.to_i
  if n==1
    p 1
    next
  end
  an=gets.chomp.split(' ').map(&:to_i)
  maxi = an.max
  flag = false
  catch(:break_loop) do
    n.times do |i|
      if an[i]==maxi && (i!=0 && an[i-1]<maxi || i!=n-1 && an[i+1]<maxi)
        p i+1
        flag=true
        throw :break_loop
      end
    end
  end
  p -1 unless flag
end


require 'set'

def f(nbrs)
  d = Array.new(nbrs.size)

  q = []
  nbrs.each_with_index do |nbr, i|
    next if nbr.size > 1
    q << i
    d[i] = 1
  end
  q.each { |v| nbrs[v].delete(v) }

  while (v = q.shift)
    dv = d[v]
    nbrs[v].each do |u|
      nbrs[u].delete(v)
      next if nbrs[u].size > 1
      next if d[u]
      d[u] = dv + 1
      q << u
    end
  end

  d[0] = 0
  d
end

gets.to_i.times do

gets  # empty line
n, k = gets.split.map!(&:to_i)
nbrs = Array.new(n + 1) { Set.new }
n.pred.times do
  u, v = gets.split.map!(&:to_i)
  nbrs[u] << v
  nbrs[v] << u
end

d = f(nbrs)
puts d.count { |di| di > k }

end

require 'set'

def f(a)
    d = Array.new(a.size)
    q = []
    a.each_with_index do |j, i|
        next if j.size > 1
        q << i
        d[i] = 1
    end
    q.each { |v| a[v].delete(v) }
    while (v = q.shift)
        dv = d[v]
        a[v].each do |u|
            a[u].delete(v)
            next if a[u].size > 1
            next if d[u]
            d[u] = dv + 1
            q << u
        end
    end
    d[0] = 0
    d
end

gets.to_i.times do
    gets
    n, k = gets.split.map!(&:to_i)
    a = Array.new(n + 1) { Set.new }
    n.pred.times do
        u, v = gets.split.map!(&:to_i)
        a[u] << v
        a[v] << u
    end
    d = f(a)
    puts d.count { |di| di > k }
end

require 'set'

def f(nbrs)
  d = Array.new(nbrs.size)

  q = []
  nbrs.each_with_index do |nbr, i|
    next if nbr.size > 1
    q << i
    d[i] = 1
  end
  q.each { |v| nbrs[v].delete(v) }

  while (v = q.shift)
    dv = d[v]
    nbrs[v].each do |u|
      nbrs[u].delete(v)
      next if nbrs[u].size > 1
      d[u] = dv + 1
      q << u
    end
  end

  d[0] = 0
  d
end

gets.to_i.times do

gets  # empty line
n, k = gets.split.map!(&:to_i)
nbrs = Array.new(n + 1) { Set.new }
n.pred.times do
  u, v = gets.split.map!(&:to_i)
  nbrs[u] << v
  nbrs[v] << u
end

d = f(nbrs)
puts d.count { |di| di > k }

end


def min(x, lim)
  (lim.."2011").each do |s|
    d = 0
    for i in 0..3
       d += (s[i] == x[i]) ? 0 : 1
    end
    next if d > 1

    return s
  end

  return false
end

lim = "1000"
o = []
gets.to_i.times do
  s = gets.chomp
  r = min(s, lim)
  unless r
    puts "No solution"
    exit
  end
  o << r
  lim = r
end
puts o

N = gets.to_i
years = []
ans = []

N.times {
  tmp = []
  year = gets.chomp
  0.upto(3) { |i|
    0.upto(9) {|j|
      changed = year.dup
      changed[i, 1] = j.to_s
      changed = changed.to_i
      if (changed >= 1000 && changed <= 2011)
        tmp.push changed
      end
    }
  }
  tmp.sort!
  years.push tmp
}

failed = false
ans.push years[0][0]

1.upto(N - 1) {|i|
  ans[i] = -1
  years[i].each {|e|
    if (e >= ans[i - 1])
      ans[i] = e
      break
    end
  }
  if (ans[i] == -1)
    puts "No solution"
    exit
  end
}

ans.each {|e| puts e}

def find_min(x, lim)
  return false if lim > "2011"

  (lim.."2011").each do |s|
    sum = (s[0] == x[0]) ? 0 : 1
    sum += (s[1] == x[1]) ? 0 : 1
    next if sum > 1
    sum += (s[2] == x[2]) ? 0 : 1
    next if sum > 1
    sum += (s[3] == x[3]) ? 0 : 1
    next if sum > 1

    return s
  end

  return false
end

n = gets.to_i
lim = "1000"
o = []
n.times do
  s = gets.chomp
  r = find_min(s, lim)
  unless r
    puts "No solution"
    exit
  end
  o << r
  lim = r
end

puts o


n = Integer(gets.chomp)
a = []
a = gets.chomp.split.map &:to_i
b = []
b = gets.chomp.split.map &:to_i

x = Array.new(n) { |i| i + 1}
position = 0
position_other = 0
for i in 0...n
    if x.include?(a[i])
        x.delete(a[i])
    else
        position = i
    end
end
left = x[0]

for i in 0...n
    if a[i] == a[position]
        position_other = i
        break
    end
end
output1 = []
output1.replace(a)
output1[position_other] = left
output2 = []
output2.replace(a)
output2[position] = left
count = 0
for i in 0...n
    if b[i] != output1[i]
        count += 1
    end
end
if count == 1
    print output1.join(" ")
else
    print output2.join(" ")
end

n = gets.chomp.to_i

ax = ay = missing = -1
a = gets.chomp.split.map &:to_i
for i in 0...n
  for j in 0...i
    if a[i] == a[j]
      ax = i
      ay = j
    end
  end
end
for i in 1..n
  has = false
  for j in 0...n
    if a[j] == i
      has = true
    end
  end
  if !has
    missing = i
  end
end

b = gets.chomp.split.map &:to_i

if a[ax] == b[ax] || b[ay] == missing
  a[ay] = missing
else
  a[ax] = missing
end
puts a.join " "

def ok(a, b, p)
  n = p.length
  x = 0
  y = 0
  for i in 0...n
    x += 1 if a[i] == p[i]
    y += 1 if b[i] == p[i]
  end
  return x == n - 1 && y == n - 1
end

def solve(a, b)
  x = -1
  y = -1
  n = a.length

  mrk = Hash.new(0)

  p = []
  for i in 0...n
    if a[i] != b[i]
      if x == -1
        x = i
        p.push(-1)
      else
        y = i
        p.push(-1)
      end
    else
      mrk[a[i]] = 1
      p.push(a[i])
    end
  end

  if y == -1
    for i in 1..n
      if mrk[i] == 0
        p[x] = i
      end
    end

    return p
  end

  lst = []
  for i in 1..n
    if mrk[i] == 0
      lst.push(i)
    end
  end

  p[x] = lst[0]
  p[y] = lst[1]

  return p if ok(a, b, p)

  p[x] = lst[1]
  p[y] = lst[0]

  return p
end

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

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

line = gets.chomp
b = line.split.map(&:to_i)

p = solve(a, b)
p.each { |x| print x.to_s + " " }
puts

n = gets.chomp.to_i

ax = ay = missing = -1
a = gets.chomp.split.map &:to_i
for i in 0...n
  for j in 0...i
    if a[i] == a[j]
      ax = i
      ay = j
    end
  end
end
for i in 1..n
  has = false
  for j in 0...n
    if a[j] == i
      has = true
    end
  end
  if !has
    missing = i
  end
end

b = gets.chomp.split.map &:to_i

if a[ax] == b[ax]
  a[ay] = missing
else
  a[ax] = missing
end
puts a.join " "

n = gets.chomp.to_i

ax = ay = missing = -1
a = gets.chomp.split.map &:to_i
for i in 0...n
  for j in 0...i
    if a[i] == a[j]
      ax = i
      ay = j
    end
  end
end
for i in 1..n
  has = false
  for j in 0...n
    if a[j] == i
      has = true
    end
  end
  if !has
    missing = i
  end
end

bx = by = -1
b = gets.chomp.split.map &:to_i
for i in 0...n
  for j in 0...i
    if b[i] == b[j]
      bx = i
      by = j
    end
  end
end

if ax == bx || ax == by
  a[ax] = missing
elsif
  a[ay] = missing
end

puts a.join " "

n = Integer(gets.chomp)
a = []
a = gets.chomp.split.map &:to_i
b = []
b = gets.chomp.split.map &:to_i

x = Array.new(n) { |i| i + 1}
position = 0
position_other = 0
for i in 0...n
    if x.include?(a[i])
        x.delete(a[i])
    else
        position = i
    end
end
left = x[0]

for i in 0...n
    if a[i] == a[position]
        position_other = i
        break
    end
end
output1 = []
output1.replace(a)
output1[position_other] = left
output2 = []
output2.replace(a)
output2[position] = left
count = 0
for i in 0...n
    if b[i] != output1[i]
        count += 1
    end
end
if count == 1
    print output1
else
    print output2
end

def solve(a, b)
  x = -1
  y = -1
  n = a.length

  mrk = Hash.new(0)

  p = []
  i = 0

  while i < n
    if a[i] != b[i]
      if x == -1
        x = i
        p.push(-1)
      else
        y = i
        p.push(-1)
      end
    else
      mrk[a[i]] = 1
      p.push(a[i])
    end
    i += 1
  end

  if y == -1
    for i in 1..n
      if mrk[i] == 0
        p[x] = i
      end
    end

    return p
  end

  for i in 1..n
    if mrk[i] == 0
      if (a[x] == i || b[x] == i) && x != -1
        p[x] = i
        x = -1
      else
        p[y] = i
      end
    end
  end

  return p
end

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

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

line = gets.chomp
b = line.split.map(&:to_i)

p = solve(a, b)
p.each { |x| print x.to_s + " " }
puts


len = gets.strip.to_i
str = gets.strip

diff = false

last_char = str[0]
skip = true
out = nil
str.each_char do |c|
    if skip
        skip = false
        next
    end
    if c != last_char
        out = last_char + c
        break
    end
end

if out.nil?
    puts "NO"
else
    puts "YES"
    puts out
end

# http://codeforces.com/contest/1073/problem/A

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

A_ORD = 'a'.ord

def solve(n, s)
  results = []

  s.each_char.each_with_index do |char, i|
    new_result = Array.new(26, 0)
    new_ord = char.ord - A_ORD
    new_result[new_ord] = 1

    results.each_with_index do |(result, total, max), j|
      result[new_ord] += 1
      if result[new_ord] > max
        max = result[new_ord]
      end

      return [i, j] if max <= (total + 1) / 2

      results[j] = [result, total + 1, max]
    end

    results << [new_result, 1, 1]
  end

  nil
end

result = solve(n, s)

if result.nil?
  puts 'NO'
else
  puts 'YES'
  i, j = result
  puts s[j..i]
end

gets;s=gets.chomp.chars.uniq
puts s.size<2 ? :NO : "YES\n%s%s"%s[0,2]

s=gets.chomp.chars.uniq
puts s.size<2 ? :NO : "YES\n%s %s"%[s,2]

gets;s=gets.chomp.chars.uniq
puts s.size<2 ? :NO : "YES\n%s %s"%s[0,2]

# http://codeforces.com/contest/1073/problem/A

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

def solve(n, s)
  last_result = {}
  results = [last_result]

  s.each_char do |char|
    new_result = last_result.dup
    new_result[char] ||= 0
    new_result[char] += 1
    last_result = new_result
    results << new_result
  end

  length = results.length

  length.times do |i|
    (i - 1).times do |j|
      differences = results[i].inject({}) do |result, (char, count)|
        j_count = results[j][char] || 0
        result.merge(char => count - j_count)
      end

      total_count = differences.inject(0) { |sum, (_, count)| sum + count }

      differences.each do |char, count|
        if count <= total_count / 2
          return [i-1, j]
        end
      end
    end
  end

  nil
end

result = solve(n, s)

if result.nil?
  puts 'NO'
else
  puts 'YES'
  i, j = result
  puts s[j..i]
end


$vis = Array.new(100005,0)
def cal
	pre = 2
    sim = 2
    for i in 1...100002
        pre /= i
        n = i
        while true
            cur = i * n * n + 2 * n * n + (n * n / i)
            if cur >= pre
                $vis[i] = cur - pre
                pre = (i+1) * n
                break
            end
        end
        sim = (sim + ($vis[i] * i))
        temp = Math.sqrt(sim).to_i
        if (temp * temp != sim || temp % (i+1) != 0)
            puts temp
        end
        sim = temp
	end
end

cal()

N = gets.to_i
for i in 1..N
	puts $vis[i]
end

n = gets.to_i

puts 2

(2..n).each do |k|
  puts k*(k+1)*(k+1) - (k-1)
end

n = gets.chomp.to_i

ans = [2]
for k in 2..n
  x = (k - 1) * k
  y = k * (k + 1)
  ans << (y**2 - x) / k
end
puts ans.*"\n"

n = gets.to_i
sr = 2
x = 2
ans = [2]
2.upto(n) do |m|
  sr = sr + 2 * m
  ans << (sr * sr - x) / m
  x = sr
end
ans.each{|x| puts x}

level = gets.chomp.to_i

(1..level).each do |l|
    puts 2 if l == 1
    puts l * (l + 1) * (l + 1) - (l - 1) if l != 1
end

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

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

n = gets.to_i

cur = 2
1.upto(n) do |ni|
  nxt = lcm(ni, ni + 1)
  k = (nxt * nxt - cur) / ni
  puts k
  cur = nxt
end

n=gets.to_i()
m=2
(1..n).each{|k|
	b=k*k+k
	puts (b*b-m)/k
	m=b
}

n = gets.chomp.to_i

x = 2
for k in 1..n
  x = k * (k + 1)
  y = k * (k + 1) * (k + 2)
  puts (y**2 - x) / k
end

n = gets.to_i
sr = 2
x = 2
ans = []
2.upto(n) do |m|
  sr = sr + 2 * m
  ans << (sr * sr - x) / m
  x = sr
end
ans.each{|x| puts x}

level = gets.chomp.to_i
level += 1

target = level ** 2
current = 1
number = 2

until current == level
hit = target - number * current

number = target ** 0.5

current += 1
until number % current == 0
	current += 1
end

puts hit
#puts "Number = #{number}"
#puts "Hit = #{hit}"
#puts "Curr = #{current}"
end

level = gets.chomp.to_i
level += 1

target = level ** 2
current = 1
number = 2

until current == level
hit = target - number * current

number = target ** 0.5

current += 1
until number % current == 0
	current += 1
end

puts hit.to_i
#puts "Number = #{number}"
#puts "Hit = #{hit}"
#puts "Curr = #{current}"
end

level = gets.chomp.to_i
level += 1

target = (level ** 2) * 4
current = 1
number = 2

until current == level
hit = (target - number) / current

number = target ** 0.5

current += 1
until number % current == 0
	current += 1
end

puts hit.to_i
#puts "Number = #{number}"
#puts "Hit = #{hit}"
#puts "Curr = #{current}"
end

level = gets.chomp.to_i
level += 1

target = level ** 2
current = 1
number = 2

until current == level
hit = (target - number) / current

number = target ** 0.5

current += 1
until number % current == 0
	current += 1
end

puts hit.to_i
#puts "Number = #{number}"
#puts "Hit = #{hit}"
#puts "Curr = #{current}"
end


n, k = gets.split.map{|x| x.to_i}
h = gets.split.map{|x| x.to_i}
a = [h[0..k-1].inject(0){|s, x| s + x}]
(k..n-1).each{|i| a << a.last + h[i] - h[i - k]}
puts(a.index(a.min) + 1)

line = gets.chomp.split(" ").map {|e| e.to_i}
n = line[0]
k = line[1]

hs = gets.chomp.split(" ").map {|e| e.to_i}

if k == 1
  min = -1
  minInd = -1
  for i in 0...(hs.length)
    if min == -1 || hs[i] < min
      min = hs[i]
      minInd = i + 1
    end
  end
  puts minInd
else
  ps = [0]

  acc = 0
  for i in 0...(hs.length)
    acc += hs[i]
    ps.push acc
  end

  min = -1
  minInd = -1
  for i in k..(hs.length)
    t = ps[i] - ps[i - k]
    if min == -1 || t < min
      min = t
      minInd = i - k
    end
  end

  puts (minInd + 1)
end

INF =  1.5 * 10 * 10 * 10 * 10 * 10  * 1000

tmp = gets.chomp.split(" ")
n, k = tmp[0].to_i, tmp[1].to_i
fence = gets.chomp.split(" ").map!{|v| v.to_i}
for i in 1...fence.size do
  fence[i] += fence[i - 1]
end
fence = [0] + fence
ans, max = 0, INF
for i in 0...(fence.size - k) do
  if (max > fence[i + k] - fence[i])
    ans = i + 1
    max = fence[i + k] - fence[i]
  end
end
puts ans

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

s=0
ans=1
w.times{|i|
	s+=a[i]
}
t=s
1.upto(n-w){|i|
	s=s+a[i+w-1]-a[i-1]
	if t>s then
		t=s
		ans=i+1
	end
}
puts ans

n,k = gets.chomp.split(" ").map{|i| i.to_i}
h = gets.chomp.split(" ").map{|i| i.to_i}

min = h[0...k].inject(0) {|sum, i| sum += i}
min_index = 0
last_sum = min
(k...n).each do |i|
  last_sum = last_sum + h[i] - h[i-k]
  if min > last_sum
    min_index = i - k + 1
    min = last_sum
  end
end

puts min_index + 1

# coding: utf-8

# if __FILE__ == $0
# end

n, k = gets.split.map(&:to_i)
hs = gets.split.map(&:to_i)
hsum = hs[0...k].reduce(:+)
minimum_hsum = hsum
minimum_idx = 1 #zero-based
(0...(n-k)).each { |idx|
    hsum -= hs[idx]
    hsum += hs[idx + k]

    if hsum < minimum_hsum
        minimum_hsum = hsum
        minimum_idx = idx + 1 + 1 # one-based, exact index
    end
}

puts minimum_idx

def solution(fence, take)
  cost = Array.new(fence.size, Float::INFINITY)
  cost[0] = fence[0...take].reduce(:+)

  for i in 1...fence.size-take+1 do
    cost[i] = cost[i-1] - fence[i-1] + fence[i + take - 1]
  end

  remove = 0
  min_cost = Float::INFINITY
  cost.each_with_index do |c, index|
    if min_cost > c
      min_cost = c
      remove = index
    end
  end
  remove + 1
end

tables, take = gets.split.map(&:to_i)
fence = gets.split.map(&:to_i)

puts solution(fence, take)

def solution(fence, take)
  prefix_sum = fence.inject([0]) { |v, i| v << v.last + i }

  min_cost = Float::INFINITY
  for i in 0...prefix_sum.size-take do
    if min_cost > prefix_sum[i+take] - prefix_sum[i]
      min_cost = prefix_sum[i+take] - prefix_sum[i]
      index = i + 1
    end
  end
  index
end

tables, take = gets.split.map(&:to_i)
fence = gets.split.map(&:to_i)

puts solution(fence, take)

n, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
b = []
c = 0
n.times do |i|
  c += a[i]
  if i >= k - 1
    b << c
    c -= a[i - k + 1]
  end
end
puts b.index(b.min) + 1

s = gets.split.map(&:to_i)
n = s[0]
k = s[1]
a = gets.split.map(&:to_i)

sum = Array.new(n + 1, 0)
minimum = 10000000000
best = 0

1.upto(n) do |i|
    sum[i] = sum[i - 1] + a[i - 1]
    if i >= k
        sumk = sum[i] - sum[i - k]
        if sumk < minimum
            minimum = sumk
            best = i - k + 1
        end
    end
end

puts best

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

sum = 0
ans = -1
min = 1_000_000_000
a.each_with_index do |e, i|
  sum += e
  sum -= a[i-k] if i>k

  if i >= k && min > sum
    min = sum
    ans = i - k + 1
  end
end

puts ans

n,k = gets.chomp.split(" ").map{|i| i.to_i}
h = gets.chomp.split(" ").map{|i| i.to_i}

min = h[0...k].inject(0) {|sum, i| sum += i}
last_sum = min
(k...n).each do |i|
  last_sum = last_sum + h[i] - h[i-k]
  min = last_sum if min > last_sum
end

puts min

# coding: utf-8

# if __FILE__ == $0
# end

n, k = gets.split.map(&:to_i)
hs = gets.split.map(&:to_i)
hsum = hs[0...k].reduce(:+)
minimum_hsum = hsum
minimum_idx = 0 #zero-based
(0...(n-k)).each { |idx|
    hsum -= hs[idx]
    hsum += hs[idx + k]

    if hsum < minimum_hsum
        minimum_hsum = hsum
        minimum_idx = idx
    end
}

# p [minimum_idx, minimum_hsum]
puts minimum_idx+1+1 #1-based index, another one for obtaining exact index

def solution(fence, take)
  prefix_sum = fence.inject([0]) { |v, i| v << v.last + i }

  min_cost = Float::INFINITY
  index = 1

  for i in 1...fence.size-take do
    if min_cost > prefix_sum[i+take-1] - prefix_sum[i-1]
      min_cost = prefix_sum[i+take-1] - prefix_sum[i-1]
      index = i
    end
  end
  index
end

tables, take = gets.split.map(&:to_i)
fence = gets.split.map(&:to_i)

puts solution(fence, take)

def solution(fence, take)

  prefix_sum = fence.inject([0]) { |v, i| v << v.last + i }

  min_cost = Float::INFINITY
  index = -1

  for i in 1...fence.size-take do
    if min_cost > prefix_sum[i+take-1] - prefix_sum[i-1]
      min_cost = prefix_sum[i+take-1] - prefix_sum[i-1]
      index = i
    end
  end
  index
end

tables, take = gets.split.map(&:to_i)
fence = gets.split.map(&:to_i)

puts solution(fence, take)

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

sum = 0
ans = -1
min = 1_000_000
a.each_with_index do |e, i|
  sum += e
  sum -= a[i-k] if i>k

  if i >= k && min > sum
    min = sum
    ans = i - k + 1
  end
end

puts ans

line = gets.chomp.split(" ").map {|e| e.to_i}
n = line[0]
k = line[1]

hs = gets.chomp.split(" ").map {|e| e.to_i}

if k == 1
  min = -1
  minInd = -1
  for i in 0...(hs.length)
    if min == -1 || hs[i] < min
      min = hs[i]
      minInd = i + 1
    end
  end
  puts minInd
else
  ps = []

  acc = 0
  for i in 0...(hs.length)
    acc += hs[i]
    ps.push acc
  end

  min = -1
  minInd = -1
  for i in (k - 1)...(hs.length)
    t = ps[i] - ps[i - k + 1]
    if min == -1 || t < min
      min = t
      minInd = i - k + 1
    end
  end

  puts (minInd + 1)

end

line = gets.chomp.split(" ").map {|e| e.to_i}
n = line[0]
k = line[1]

hs = gets.chomp.split(" ").map {|e| e.to_i}

if k == 1
  min = -1
  minInd = -1
  for i in 0...(hs.length)
    if min == -1 || hs[i] < min
      min = hs[i]
      minInd = i + 1
    end
  end
  puts minInd
else
  ps = [0]

  acc = 0
  for i in 0...(hs.length)
    acc += hs[i]
    ps.push acc
  end

  min = -1
  minInd = -1
  for i in k...(hs.length)
    t = ps[i] - ps[i - k]
    if min == -1 || t < min
      min = t
      minInd = i - k
    end
  end

  puts (minInd + 1)
end

line = gets.chomp.split(" ").map {|e| e.to_i}
n = line[0]
k = line[1]

hs = gets.chomp.split(" ").map {|e| e.to_i}
ps = []

acc = 0
for i in 0...(hs.length)
  acc += hs[i]
  ps.push acc
end

min = -1
minInd = -1
for i in (k - 1)...(hs.length)
  t = ps[i] - ps[i - k + 1]
  if min == -1 || t < min
    min = t
    minInd = i - k + 1
  end
end

puts (minInd + 1)


def solve(num)
  start = num[0].to_i.to_s(2)
  target = num[1].to_i.to_s(2)
  i = 0
  while start[i] == 0
    start.shift
  end
  i = 0
  while target[i] == 0
    target.shift
  end
  start_index = start.rindex("1")
  target_index = target.rindex("1")
  return -1 if start_index != target_index
  i = 0
  while i <= start_index
    foo = start[i]
    bar = target[i]
    return -1 if foo != bar
    i += 1
  end

  foo = [start.length, target.length].max
  baz = [start.length, target.length].min
  t = foo - baz
  (t / 3.0).ceil

end

amount = gets.chomp.to_i
amount.times do
  input = gets.chomp.split(" ")
  puts solve(input)
end

t = 0
t = gets.chomp.to_i

while t>0
    a,b = gets.chomp.split(' ').map{|a| a.to_i}
    #puts "Value of a is" ,a
    #puts "Value of b is ",b
    i = 0
    min = 0
    value = 0
    if a < b
        while(a<b)
            a=a*2
            i+= 1
        end

    else
        while(b<a)
            b=b*2
            i+=1
        end
    end

    if a!=b
        puts "-1"
    else
        min = [1,i%3].min
        value = i/3 + min
        puts value
    end
    t = t - 1
end

data_lines = gets.chomp
input_values = []
(1..data_lines.to_i).each do
	input_str = gets.chomp
	val1, val2 = input_str.split(" ")
	input_values.push [val1.to_i, val2.to_i]
end

input_values.each do |values_pair|
	from_value = values_pair[0]
	to_value = values_pair[1]
	if from_value == to_value
		puts 0
		next
	end
	if from_value > to_value
		if from_value % to_value > 0
			puts -1
			next
		end
		if (from_value / to_value) % 2 > 0
			puts -1
			next
		end
	end
	if to_value > from_value
		if to_value % from_value > 0
			puts -1
			next
		end
		if (to_value / from_value) % 2 > 0
			puts -1
			next
		end
	end
	result = nil
	iter = 0
	if from_value > to_value
		tmp = to_value
		to_value = from_value
		from_value = tmp
	end
	# p 'from_value = ' + from_value.to_s
	# p 'to_value = ' + to_value.to_s

	while from_value != to_value
		# p 'from_value = ' + from_value.to_s
		iter += 1

		if to_value >= from_value * 8
			# p 'yes'
			from_value = from_value * 8
		elsif to_value >= from_value * 4
			# p 'yes2'
			from_value = from_value * 4
		elsif to_value >= from_value * 2
			# p 'yes3'
			from_value = from_value * 2
		else
			from_value = to_value
			iter = -1
		end
	end
	puts iter
end

def solve(num)
  start = num[0].to_i.to_s(2)
  target = num[1].to_i.to_s(2)
  start_index = start.index("1")
  target_index = target.index("1")
  start = start[start_index..-1]
  target = target[target_index..-1]
  start_rindex = start.rindex("1")
  target_rindex = target.rindex("1")
  return -1 if start_rindex != target_rindex
  i = 0
  while i <= start_rindex
    return -1 if start[i] != target[i]
    i += 1
  end
  longer = [start.length, target.length].max
  shorter = [start.length, target.length].min
  diff = longer - shorter
  (diff / 3.0).ceil
end

amount = gets.chomp.to_i
amount.times do
  input = gets.chomp.split(" ")
  puts solve(input)
end


s=gets.strip
n=gets.to_i
m=""
n.times{|i| w=gets.strip; m=(m<w && !m.empty?)?m:w if w.start_with? s}
puts (m.empty?)?s:m

s = gets.chomp!
n = gets.to_i
visited = $stdin.readlines.map(&:chomp!).sort!
t = visited.bsearch{|x| x >= s}
if t.nil? or (/#{s}/ =~ t) != 0
  puts s
else
  puts t
end

word = gets.strip
n    = gets.to_i

a = []
o = []

for i in 0..(n-1)
  a << gets.strip
end

a.each {|x| o << x if x.start_with?(word) }

o.length == 0 ? (puts word) : (puts o.min)

str = STDIN.gets.chomp
n   = STDIN.gets.to_i
lines = []
n.times { lines << STDIN.gets.chomp }

lines.sort.each do |line|
  if line.rindex(str) == 0
    puts line
    exit
  end
end
puts str

s, n = gets.chomp, gets.to_i
lines = []
n.times { lines << gets.chomp }

lines.sort.each do |line|
  if line.start_with?(s)
    puts line; exit
  end
end
puts s

=begin 59A - Word
str = gets.chomp
lower = 0
upper = 0
str.each_char { |w| /[[:lower:]]/.match(w) ? lower+= 1 : upper+= 1 }
puts upper > lower ? str.upcase : str.downcase
=end
str = gets.chomp
n = gets.to_i
out = nil
while n > 0
	tmp = gets.chomp
  if /\A#{str}[[:lower:]]*/.match(tmp)
    if out.nil? || tmp < out
      out = tmp
    end
  end
  n-=1
end
puts out.nil? ? str : out

s = gets.chomp!
n = gets.to_i

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

mas.sort!
for i in 0..n-1
  if (mas[i].index(s) == 0)
    puts mas[i]
    exit
  end
end

puts s

str = gets.chomp
num = gets.chomp.to_i

lines = []
num.times {|i|
  lines << gets.chomp
}

regexp = Regexp.new("^" + str)
strs = lines.select {|line| regexp =~ line}
if strs.length == 0
  puts str
else
  puts strs.sort[0]
end

s = gets.strip
a = []

gets.to_i.times {
    n = gets.strip
    a.push n if n.start_with? s
}

puts a.empty? ? s : a.sort.first

str = STDIN.gets.chomp
n   = STDIN.gets.to_i
lines = []
n.times { lines << STDIN.gets.chomp }
lines.sort!

lines.each do |line|
  if line.rindex(str) == 0
    puts line
    exit
  end
end
puts str

str = gets.strip; gets; auto = []
while g = gets; auto.push g.strip; end
s = auto.sort.grep(/^#{str}+/).first
print s ? s : str

=begin 59A - Word
str = gets.chomp
lower = 0
upper = 0
str.each_char { |w| /[[:lower:]]/.match(w) ? lower+= 1 : upper+= 1 }
puts upper > lower ? str.upcase : str.downcase
=end
str = gets.chomp
n = gets.to_i
max = 101
out = str
while n > 0
	tmp = gets.chomp
  if /\A#{str}[[:lower:]]*/.match(tmp)
    if tmp.size < max
      max = tmp.size
      out = tmp
    end
  end
  n-=1
end
puts out

=begin 59A - Word
str = gets.chomp
lower = 0
upper = 0
str.each_char { |w| /[[:lower:]]/.match(w) ? lower+= 1 : upper+= 1 }
puts upper > lower ? str.upcase : str.downcase
=end
str = gets.chomp
n = gets.to_i
max = 101
out = str
while n > 0
	tmp = gets.chomp
  if /\A#{str}[[:lower:]]*/.match(tmp)
    if tmp.size < max
      max = tmp.size
      out = tmp
    elsif tmp.size == max
      out = tmp < out ? tmp : out
    end
  end
  n-=1
end
puts out

s=gets.strip
n=gets.to_i # n can bo omitted in calculations
ok=false
m=""
n.times{|i| w=gets.strip; m,ok=((m<w || !ok)?m:w),true if w.start_with? m}
puts (ok ? m : s)