n=gets.to_i
a=gets(p).split.map(&:squeeze)
puts a.all?{|s|s.size<2}&&(a*"").squeeze.size==n ?:YES :"NO"

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

t = Array.new(m) {|i| i = []}
result = "YES"

n.times do
    s = gets.chomp
    k = s[0]
    if s.delete(s[0]).size != 0 then
        result = "NO"
    end
    m.times do |i|
        if t[i][-1] == s[i] then
            result = "NO"
        end
        t[i] << s[i]
    end
end

puts result

ns,ms = gets.chomp.split(/ /)
n = ns.to_i
m = ms.to_i
ar = Array.new(n)
for i in 0..n-1
	s = gets.chomp
	ar[i] = s.split(//)
end

ret = "YES"
for i in 0..n-1
	for j in 1..m-1
		if ar[i][j] != ar[i][0]
			ret = "NO"
			break;
		end
	end
	if i > 0
		if ar[i][0] == ar[i-1][0]
			ret = "NO"
			break;
		end
	end
end

puts ret

n, m = gets.strip.split.map { |e| e.to_i }
color = ''
bool = true
n.times do
	str = gets.strip.squeeze
	if str.size != 1
		bool = false
	else
		if str != color
			color = str
		else
			bool = false
		end
	end
end
if bool
	puts 'YES'
else
	puts 'NO'
end

n=gets.to_i
back=-1
(1..n).each{
        data=gets.split[0]
        if(back==data[0].to_i) then
                puts "NO"
                exit
        end
        back=data[0].to_i
        for i in 1..data.length-1
                if(data[i].to_i!=data[0].to_i) then
                        puts "NO"
                        exit
                end
        end
}
puts "YES"

#!/usr/bin/ruby

n, m = gets.chomp.split.map{|e| e.to_i}
color = -1
n.times do
  this_line = gets.chomp.split('').map{|e| e.to_i}
  if this_line[0] == color
    puts "NO"
    exit
  end
  color = this_line[0]
  this_line.each{|e|
    if e != color
      puts "NO"
      exit
    end
  }
end
puts "YES"

rez = gets.split(" ").map { |e| e.to_i }
flag = true
k = 0
ch = 'a'
rez[0].times {
    s = gets
    k += 1
    if k != 1
        if s[0] == ch then
            flag = false
            break
        end
    end
    mas = s.chomp.split("").map { |e| e.to_i }
    mas = mas | mas
    if mas.size != 1
        flag = false
    end
    ch = s[0]

}
puts "YES" if flag
puts "NO" if !flag

n, m = gets.split.map(&:to_i)
grid = []
compare = [""]
iso = false
n.times do
	row = gets.chomp.split('')
	unique = row.uniq
	if unique.length > 1 || unique == compare
		puts "NO"
		iso = false
	else
		compare = unique
		iso = true
	end
	break unless iso
end
puts "YES" if iso

def main()
	nm=gets.chomp.to_s.split(" ");
	n=nm[0].to_i;
	m=nm[1].to_i;
	fr=gets.chomp;
	prevn=fr[0].chr;
	nofn=fr.count(prevn);
	if nofn==m
		f=true;
		for i in 1...n
			r=gets.chomp;
			if prevn==r[0].chr
				f=false;
			else
				prevn=r[0].chr;
				nofn=r.count(prevn);
				if nofn!=m
					f=false;
				end
			end
		end
		if f
			puts "YES"
		else
			puts "NO"
		end
	else
		puts "NO";
	end
end
main()

input = gets.chomp.split(' ').map { |e| e.to_i }
flag = Array.new(input[1])
f_bool = true
(0...input[0]).each do |i|
  flag[i] =  gets.chomp.to_s
end
(0...input[0]).each do |i|
   if flag[i].count(flag[i][0]) != flag[i].length
     puts "NO"
     f_bool = false
     break
  else
      if flag.length == 1
       puts "YES"
       f_bool = false
       break
     else
       if i == 0
         if flag[0] == flag[1]
           puts "NO"
           f_bool = false
           break
         end
       else
         if flag[i] == flag[i+1] || flag[i] == flag[i-1]
           puts "NO"
           f_bool = false
           break
         end
       end
     end
  end
end
puts "YES" if f_bool

n=gets.to_i
rows=gets(p).split.map(&:squeeze)
puts rows.all?{|str| str.size==1}&&(rows*"").squeeze.size==n ?:YES :"NO"

n, m = gets.split.collect{|i| i.to_i}
flag = Array.new(m,-1)
(1..n).each do
    tmp = gets.chomp.split("").collect{|i| i.to_i}
    if flag[0] == tmp[0] or tmp.count(tmp[0]) != m
        puts "NO"
        exit
    end
    flag = tmp
end
puts "YES"

n, m = gets.split.collect{|i| i.to_i}
flag = -1
(1..n).each do
    tmp = gets.chomp.split("").collect{|i| i.to_i}
    if flag == tmp[0] or tmp.count(tmp[0]) != m
        puts "NO"
        exit
    end
    flag = tmp[0]
end
puts "YES"

n_and_m = gets.split(" ")
n = n_and_m[0].to_i
m = n_and_m[1]
bandeira = []
resposta = "YES"
n.times do
	linha = gets.strip
	linha_horizontal = linha.split("")
	cor_da_linha = linha_horizontal.uniq
		if cor_da_linha.size != 1
			resposta = "NO"
		end
	bandeira << cor_da_linha
end
for cor in 1..bandeira.size - 1 do
	break if resposta == "NO" || bandeira.size == 1
	if bandeira[cor - 1] == bandeira[cor] || bandeira[cor + 1] == bandeira[cor]
		resposta = "NO"
		break
	else
		resposta = "YES"
	end
end
puts resposta

class String
  def uniq?
    self.split('').uniq.size < 2
  end
end

def print_no
  puts 'NO'
  exit
end

n, _ = gets.split.map { |x| x.to_i }
p = gets.chomp
print_no unless p.uniq?
for __ in 2..n
  s = gets.chomp
  print_no unless s != p && s.uniq?
  p = s
end
puts 'YES'

s1 = gets.chomp.split

n = s1[0].to_i
m = s1[1].to_i
k = 0
all = []
ok = true;

for i in 1..n do
	s = gets.chomp
	t = s[0];
	ok = true;
	for j in 1..s.length-1 do
		if t != s[j]
			ok = false;
		end
	end
	if not ok
		print "NO"
		break
	end
	all[k] = t
	k+=1
end

if ok
	tr = true
	for i in 0..k-2 do
		if all[i] == all[i + 1]
			print "NO"
			tr = false
			break
		end
	end

	if tr
		print "YES"
	end
end

n,m=gets.split.map(&:to_i)
prev="z"; result=true
n.times do
	line=gets.split(//)
	if line[0]==prev
		result=false
	end
	prev=line[0]
	if line.count(line[0])!=m
		result=false
	end
end

if result
	puts "YES\n"
else
	puts "NO\n"
end

gets; flag = STDIN.read.split "\n"

flag.each.with_index do |f, i|
	if f.length == f.count(f[0])
		f.length.times do |j|
			if i > 0
				(print :NO; exit) if flag[i][j] == flag[i - 1][j]
			end
		end
	else
		print :NO
		exit
	end
end

print :YES

t = gets.split.collect{|x| x.to_i}
n,m = t[0], t[1]

ok = 'YES'
last = ''

n.times do |i|
	s = gets.strip
	if last != ''
		if s == last
			ok = 'NO'
		end
	end
	if s != s[0]*m
		ok = 'NO'
	end
	last = s
end

puts ok

puts %w[YES NO][STDIN.readlines.drop(1).map { |x| x.chomp }.reduce(['*', 0]) { |s, x| [x[0], s.last | (x.chars.to_a.uniq.length == 1 && x[0] != s.first ? 0 : 1)] }.last]

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

t = {}
result = "YES"

n.times do
    s = gets.chomp
    k = s[0]
    if s.delete(s[0]).size != 0 then
        result = "NO"
    end
    m.times do |i|
        if t[i] then
            if t[i].include? s[i] then
                result = "NO"
            else
                t[i] << s[i]
            end
        else
            t[i] = [s[i]]
        end
    end
end

puts result

n_m = gets.chomp.split(' ').map { |i| i.to_i }
flag = Array.new(n_m[1])
(0...n_m[0]).each do |i|
  flag[i] = gets.chomp.to_s
end
bol = true
(0...n_m[1]).each do |i|
  if n_m[0] > 1
    if i == 0
      if flag[i] == flag[i+1]
        bol = false
        puts "NO"
        break
      end
      (0...flag[i].length).each do |j|
        if flag[i][0] != flag[i][j]
          bol = false
          puts "NO"
          break
        end
      end
      if bol == false
        break
      end
    else
      if flag[i] == flag[i+1] || flag[i] == flag[i-1]
        bol = false
        puts "NO"
        break
      end
      if bol == false
        break
      end
      (0...flag[i].length).each do |j|
        if flag[i][0] != flag[i][j]
          bol = false
          puts "NO"
          break
        end
      end
      if bol == false
        break
      end
    end
  else
    (0...n_m[1]).each do |j|
      if flag[0][0] != flag[0][j]
        bol = false
        puts "NO"
        break
      end
    end
    break if bol == false
  end
end
puts "YES" if bol == true

n_m = gets.chomp.split(' ').map { |i| i.to_i }
flag = Array.new(n_m[1])
(0...n_m[0]).each do |i|
  flag[i] = gets.chomp.to_s
end
bol = true
(0...n_m[1]).each do |i|
  if i== 0
    if flag[i] == flag[i+1]
      bol = false
      puts "NO"
      break
    end
    (0...flag[i].length).each do |j|
      if flag[i][0] != flag[i][j]
        bol = false
        puts "NO"
        break
      end
    end
  else
    if flag[i] == flag[i+1] || flag[i] == flag[i-1]
      bol = false
      puts "NO"
      break
    end
    (0...flag[i].length).each do |j|
      if flag[i][0] != flag[i][j]
        bol = false
        puts "NO"
        break
      end
    end
  end
end
puts "YES" if bol == true

input = gets.chomp.split(' ').map { |e| e.to_i }
flag = Array.new(input[1])
f_bool = true
(0...input[0]).each do |i|
  flag[i] =  gets.chomp.to_s
end
(0...input[0]).each do |i|
   if flag[i].count(flag[i][0]) != flag[i].length
     puts "NO"
     f_bool = false
  else
      if flag.length == 1
       puts "YES"
       f_bool = false
       break
     else
       if i == 0
         if flag[0] == flag[1]
           puts "NO"
           f_bool = false
           break
         end
       else
         if flag[i] == flag[i+1] || flag[i] == flag[i-1]
           puts "NO"
           f_bool = false
           break
         end
       end
     end
  end
end
puts "YES" if f_bool

n_m = gets.chomp.split(' ').map { |i| i.to_i }
flag = Array.new(n_m[1])
(0...n_m[0]).each do |i|
  flag[i] = gets.chomp.to_s
end
bol = true
(0...n_m[1]).each do |i|
  if i== 0
    if flag[i] == flag[i+1]
      bol = false
      puts "NO"
      break
    end
    (0...flag[i].length).each do |j|
      if flag[i][0] != flag[i][j]
        bol = false
        puts "NO"
        break
      end
    end
    if bol == false
      break
    end
  else
    if flag[i] == flag[i+1] || flag[i] == flag[i-1]
      bol = false
      puts "NO"
      break
    end
    if bol == false
      break
    end
    (0...flag[i].length).each do |j|
      if flag[i][0] != flag[i][j]
        bol = false
        puts "NO"
        break
      end
    end
    if bol == false
      break
    end
  end
end
puts "YES" if bol == true

n_m = gets.chomp.split(' ').map { |i| i.to_i }
flag = Array.new(n_m[1])
(0...n_m[0]).each do |i|
  flag[i] = gets.chomp.to_s
end
bol = true
(0...n_m[1]).each do |i|
  if n_m[0] == 1
    break
  end
  if i== 0
    if flag[i] == flag[i+1]
      bol = false
      puts "NO"
      break
    end
    (0...flag[i].length).each do |j|
      if flag[i][0] != flag[i][j]
        bol = false
        puts "NO"
        break
      end
    end
    if bol == false
      break
    end
  else
    if flag[i] == flag[i+1] || flag[i] == flag[i-1]
      bol = false
      puts "NO"
      break
    end
    if bol == false
      break
    end
    (0...flag[i].length).each do |j|
      if flag[i][0] != flag[i][j]
        bol = false
        puts "NO"
        break
      end
    end
    if bol == false
      break
    end
  end
end
puts "YES" if bol == true

n_and_m = gets.split(" ")
n = n_and_m[0].to_i
m = n_and_m[1]
bandeira = []
resposta = ""
n.times do
	linha = gets.strip
	linha_horizontal = linha.split("")
	cor_da_linha = linha_horizontal.uniq
		if cor_da_linha.size != 1
			resposta = "NO"
		end
	bandeira << cor_da_linha
end
for cor in 1..bandeira.size - 1 do
	break if resposta == "NO"
	if bandeira[cor - 1] == bandeira[cor] || bandeira[cor + 1] == bandeira[cor]
		resposta = "NO"
		break
	else
		resposta = "YES"
	end
end
puts resposta

t = gets.split.collect{|x| x.to_i}
n,m = t[0], t[1]

ok = 'YES'
last = ''

n.times do |i|
	s = gets.strip
	if last != ''
		if s == last or s != s[0]*m
			ok = 'NO'
		end
	else
		last = s
	end
end

puts ok

t = gets.split.collect{|x| x.to_i}
n,m = t[0], t[1]

ok = 'YES'
last = ''

n.times do |i|
	s = gets.strip
	if last != ''
		if s == last or s != s[0]*m
			ok = 'NO'
		end
	end
	last = s
end

puts ok


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

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

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end

def puts_yesno(can) puts(can ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def debug(k,v) puts "#{k}:#{v}" end
########### ( ˘ω˘ )ｽﾔｧ… ###########
n=gi
a=gsmi
ans=[]

i=0
cnt=0
prev=-1
while i<n do
  if prev < a[i]
    cnt+=1
  else
    # ng
    ans<<[i-cnt,i-1,cnt] if cnt>0
    cnt=1
  end
  prev=a[i]
  i+=1
end
ans<<[n-cnt,n-1,cnt] if cnt>0
#puts ans.to_s

prev_en=-2
prev_cnt=0
max=0
ans.each do |st,en,cnt|
  if (st-prev_en)==2 && a[prev_en]<a[st]
    c=cnt+prev_cnt
    max=c if max<c
  elsif (st-prev_en)==1 &&((cnt>1&&a[prev_en]<a[st+1]) || (prev_cnt>1&&a[prev_en-1]<a[st]))
    c=cnt+prev_cnt-1
    max=c if max<c
  end
  prev_en=en
  prev_cnt=cnt
  #puts max
end

max_unit = ans.map{|i|i[2]}.max

puts max(max,max_unit)

def solve
    n = gets.strip.to_i
    a = gets.strip.split(' ').map(&:to_i)
    dp = Array.new(n + 1){ Array.new(3) }
    a.each_with_index { |e, i| dp[i][0] = dp[i][1] = dp[i][2] = 1 }
    an = -1
    a.each_with_index { |e, i|
        next if i == 0
        if i > 1
            dp[i][0] = dp[i - 2][1] + 1 if a[i] - a[i - 2] > 0
        end
        if a[i] - a[i - 1] > 0
            dp[i][1] = dp[i - 1][1] + 1
            dp[i][2] = [dp[i - 1][2], dp[i - 1][0]].max + 1
        end
        an = [an, dp[i][0], dp[i][2]].max
    }
    puts an
end

solve


#! ruby -Ku
# -*- coding: UTF-8 -*-

def check_movability(start, goal)
  if start == nil || goal == nil
    return false
  end
  a = start[0]
  b = start[1]
  c = goal[0]
  d = goal[1]
  if (c < a && a < d) || (c < b && b < d)
    return true
  else
    return false
  end
end

def answer(intervals, query)
  intervals.each do |elem|
    if elem != nil
      elem[2] = false
    end
  end

  current = intervals[query.shift-1]
  goal = intervals[query.shift-1]
  if current == nil || goal == nil
    return false
  end
  stack = Array::new
  stack.push(current)

  while stack.size != 0
    current = stack.pop
    if check_movability(current, goal)
      return true
    else
      current[2] = true
      intervals.each do |elem|
        if check_movability(current, elem) && !elem[2]
          stack.push(elem)
        end
      end
    end
  end

  return false
end

# file = open("input.txt")
# total_line = file.gets.to_i
total_line = gets.to_i

intervals = Array::new
queries = Array::new

total_line.times do |i|
  # input = file.gets.split.map(&:to_i)
  input = gets.split.map(&:to_i)
  if input.shift == 1
    input << false
    intervals << input
  else
    check = answer(intervals, input)
    if check == true
      puts "YES"
    else
      puts "NO"
    end
  end
end

def dfs (a, f, i)
  x, y = a[i]
  f[i] = true
  a.each_index do |j|
    nx, ny = a[j]
    next if f[j]
    dfs(a, f, j) if ((nx < x and x < ny) or (nx < y and y < ny))
  end
end

a = []
n = gets.strip.to_i
n.times do
  t, x, y = gets.strip.split(" ").collect{|v| v.to_i}
  if t == 1 then
    a << [x, y]
    next
  end

  f = Hash.new{|h,k| h[k] = false}
  dfs(a, f, x-1)
  f[y-1] ? (puts "YES") : (puts "NO")
end

# Define a func to update reachability matrix
def update_reach(reachabilty, intervals)
    reachabilty.push([])
    j = intervals.length - 1; c = intervals[j][1]; d = intervals[j][2];
    for i in 0..(j - 1) do
        a = intervals[i][1]; b = intervals[i][2];
        if (((c < a) && (a < d)) || ((c < b) && (b < d)))
            reachabilty[i].push(j)
        end
        if (((a < c) && (c < b)) || ((a < d) && (d < b)))
            reachabilty[j].push(i)
        end
    end
end

# Define a func to run dfs
def dfs(root, traversal, reachabilty)
    traversal[traversal.length] = root
    for child in reachabilty[root] do
        unless traversal.include?(child)
            dfs(child, traversal, reachabilty)
        end
    end
end

# Initialize variables
n = 0; queries = []; traversal = []; reachabilty = []; intervals = [];

# Read input
n = gets.strip.to_i
n.times {queries.push(gets.strip.split.map{|s| s.to_i})}

# Loop over queries
for i in 0..(n - 1) do
    if queries[i][0] == 1
        intervals.push(queries[i])
        update_reach(reachabilty, intervals)
    else
        traversal = []; root, target = queries[i][1,2].map{|k| k - 1};
        dfs(root,traversal,reachabilty)
        puts traversal.include?(target) ? "YES" : "NO"
    end
end

def compute_reachability arr, index
  (1..index).each do |k|
    (1..index).each do |i|
      (1..index).each do |j|
        if (arr[i][j] == nil) && arr[i][k] !=nil && arr[k][j] != nil
          arr[i][j] = 1
        end
      end
    end
  end
end

n = gets.to_i
arr = Array.new(n + 1) {Array.new(n + 1)}
intervals = []
(1..n).each { |i| arr[i][i] = nil}
(1..n).each do |index|
  command, x, y = gets.split(' ').map(&:to_i)
  if command == 1
    current = intervals.length + 1
    intervals.each_with_index do |interval, i|
      a,b = interval[0], interval[1]
      if ( a < x && x < b) ||  ( a < y && y < b)
        arr[current][i +1] = 1
      end
      if (x < a && a < y) ||  ( x < b && b < y)
        arr[i +1][current] = 1
      end
    end
    compute_reachability(arr, current)
    intervals << [x,y]
  else
    puts  arr[x][y]!=nil ? "YES" : "NO"
  end

end

#!/usr/bin/ruby

$arr = []

def forward_edge(a, b, c, d)
	(c < a and a < d) or (c < b and b < d)
end

def dfs(vis, a)
	if vis[a]
		return
	end
	vis[a] = true

	(0...$arr.size).each do |u|
		if forward_edge(*$arr[a], *$arr[u])
			dfs(vis, u)
		end
	end
end

# a, b are 0-indexed
def query(a, b)
	vis = [false]*($arr.size)
	dfs(vis, a)

	puts vis[b] ? "YES" : "NO"
end

gets
readlines.each do |line|
	cmd, x, y = line.strip.split.map(&:to_i)
	if cmd == 1
		$arr << [x, y]
	else
		query(x - 1, y - 1)
	end
end

#!/usr/bin/env ruby
def can_go?(x, y, path, vis)
  vis[x] = true
  return true if x == y
  path[x].each do |to|
    next if vis[to]
    return true if can_go?(to, y, path, vis)
  end
  return false
end
n = gets.to_i
can_go = Array.new(105){Array.new}
interval = [[0, 0]]
n.times do
  p, a, b = gets.split(' ').map(&:to_i)
  if p == 1
    for i in 1...interval.size
      c, d = interval[i]
      can_go[interval.size] << i if((c < a && a < d) || (c < b && b < d))
      can_go[i] << interval.size if((a < c && c < b) || (a < d && d < b))
    end
    interval << [a, b]
  else
    vis = Array.new(105, false)
    puts can_go?(a, b, can_go, vis) ? "YES" : "NO"
  end
end

def dfs(i)
	@visited[i] =  true
	@arr.each_with_index do |a,k|
		if @visited[k]
			next
			#@arr[i][0]-a,@arr[i][1]- b, a[0] - c,a[1] - d
		elsif a[0] < @arr[i][0] && @arr[i][0] < a[1]
			dfs(k)
		elsif a[0] < @arr[i][1] && @arr[i][1] < a[1]
			dfs(k)
		end
	end
end

n = gets.to_i
@arr = []
n.times do
	m,a,b = gets.split(" ").map(&:to_i)
	if m == 1
		@arr << [a,b]
	else
		@visited = Hash.new(false)
		dfs(a-1)
		if @visited[b-1]
			puts "YES"
		else
			puts "NO"
		end
	end
end

def dfs(i)
	@visited[i] =  true
	@arr.each_with_index do |a,k|
		if @visited[k]
			next
			#@arr[i][0]-a,@arr[i][1]- b, a[0] - c,a[1] - d
		elsif a[0] < @arr[i][0] && @arr[i][0] < a[1]
			dfs(k)
		elsif a[0] < @arr[i][1] && @arr[i][1] < a[1]
			dfs(k)
		end
	end
end

n = gets.to_i
@arr = []
n.times do
	m,a,b = gets.split(" ").map(&:to_i)
	if m == 1
		@arr << [a,b]
	else
		@visited = Hash.new(false)
		dfs(a)
		if @visited[b]
			puts "YES"
		else
			puts "NO"
		end
	end
end

def dfs (a, f, i)
  x, y = a[i]
  f[i] = true
  a.each_index do |j|
    nx, ny = a[j]
    next if f[j]
    dfs(a, f, j) if ((nx < x and x < ny) or (nx < y and y < ny))
  end
end

a = []
f = Hash.new{|h,k| h[k] = false}
n = gets.strip.to_i
n.times do
  t, x, y = gets.strip.split(" ").collect{|v| v.to_i}
  if t == 1 then
    a << [x, y]
    next
  end

  dfs(a, f, x-1)
  f[y-1] ? (puts "YES") : (puts "NO")
end

#! ruby -Ku
# -*- coding: UTF-8 -*-

def check_movability(start, goal)
  if start == nil || goal == nil
    return false
  end
  a = start[0]
  b = start[1]
  c = goal[0]
  d = goal[1]
  if (c < a && a < d) || (c < b && b < d)
    return true
  else
    return false
  end
end

def answer(intervals, query)
  intervals.each do |elem|
    if elem != nil
      elem[2] = false
    end
  end

  current = intervals[query.shift-1]
  goal = intervals[query.shift-1]
  if current == nil || goal == nil
    return false
  end
  stack = Array::new
  stack.push(current)

  while stack.size != 0
    current = stack.pop
    if check_movability(current, goal)
      return true
    else
      current[2] = true
      intervals.each do |elem|
        if check_movability(current, elem) && !elem[2]
          stack.push(elem)
        end
      end
    end
  end

  return false
end

# file = open("input.txt")
# total_line = file.gets.to_i
total_line = gets.to_i

intervals = Array::new
queries = Array::new

total_line.times do |i|
  # input = file.gets.split.map(&:to_i)
  input = gets.split.map(&:to_i)
  if input.shift == 1
    input << false
    intervals[i] = input
  else
    check = answer(intervals, input)
    if check == true
      puts "YES"
    else
      puts "NO"
    end
  end
end

def compute_reachability arr, index
  (1..index).each do |i|
    (1..index).each do |j|
      if (arr[i][j] == nil) && arr[i][index] == 1 && arr[index][j] == 1
        arr[i][j] = 1
      end
    end
  end
end

n = gets.to_i
arr = Array.new(n + 1) {Array.new(n + 1)}
intervals = []
(1..n).each { |i| arr[i][i] = 0}
(1..n).each do |index|
  command, x, y = gets.split(' ').map(&:to_i)
  if command == 1
    intervals.each_with_index do |interval, i|
      if (x < interval[1] && x > interval[0]) ||  (y < interval[1] && y > interval[0])
        arr[index][i +1] = 1
      end
      if (interval[0] < y && interval[0] > x) ||  ( interval[1] < y && interval[1] > x)
        arr[i +1][index] = 1
      end
    end
    compute_reachability(arr, index)
    intervals << [x,y]
  else
    puts  arr[x][y]== 1 ? "YES" : "NO"
  end

end


t = gets.to_i
ans = []
t.times do
  n = gets.to_i
  s = gets.chomp.split("").map(&:to_i)
  one_fin = 0
  zero_fin = 0
  index = 0
  arr = Array.new(n)
  max = 0
  n.times do |i|
    if s[i] == 1
      if zero_fin > 0
        one_fin += 1
        zero_fin -= 1
        index += 1
        arr[i] =  index
      else
        one_fin += 1
        arr[i] = one_fin
        index += 1
        max = one_fin if max < one_fin
      end
    elsif s[i] == 0
      if one_fin > 0
        zero_fin += 1
        one_fin -= 1
        arr[i] = index
        index -= 1
      else
        zero_fin += 1
        arr[i] = zero_fin
        max = zero_fin if max < zero_fin
      end
    end
  end
  ans << [arr,max]
end
ans.each do |ar|
  puts ar[1]
  ar[0].each do |x|
    print "#{x} "
  end
  puts ""
end

t = gets.to_i
ans = []
t.times do
  n = gets.to_i
  s = gets.chomp.split("")
  one_fin = 0
  zero_fin = 0
  index = 0
  arr = Array.new(n)
  max = 0
  n.times do |i|
    if s[i] == "1"
      if zero_fin > 0
        one_fin += 1
        zero_fin -= 1
        index += 1
        arr[i] =  index
      else
        one_fin += 1
        arr[i] = one_fin
        index += 1
        max = one_fin if max < one_fin
      end
    elsif s[i] == "0"
      if one_fin > 0
        zero_fin += 1
        one_fin -= 1
        arr[i] = index
        index -= 1
      else
        zero_fin += 1
        arr[i] = zero_fin
        max = zero_fin if max < zero_fin
      end
    end
  end
  ans << [arr,max]
end
ans.each do |ar|
  puts ar[1]
  ar[0].each do |x|
    print "#{x} "
  end
  puts ""
end

t = gets.to_i
ans = []
t.times do
  n = gets.to_i
  s = gets.chomp
  one_fin = 0
  zero_fin = 0
  index = 0
  arr = []
  n.times do |i|
    if s[i] == "0" && one_fin > 0
      zero_fin += 1
      one_fin -= 1
      arr << index
      index -= 1
    elsif s[i] == "0" && one_fin > 0
      zero_fin += 1
      arr << zero_fin
    elsif s[i] == "0" && zero_fin > 0
      one_fin += 1
      zero_fin -= 1
      index += 1
      arr << index
    else
      one_fin += 1
      arr << one_fin
      index += 1
    end
  end
  ans << arr
end
ans.each do |ar|
  puts ar.max
  ar.each do |x|
    print "#{x} "
  end
  puts ""
end

t = gets.to_i
ans = []
t.times do
  n = gets.to_i
  s = gets.chomp
  one_i = 1
  zero_i = 1
  arr = []
  n.times do |i|
    if s[i] == "0"
      if zero_i < one_i
        one_i -= 1
        arr << one_i
      else
        arr << zero_i
        zero_i += 1
      end
    elsif s[i] == "1"
      if zero_i > one_i
        zero_i -= 1
        arr << zero_i
      else
        arr << one_i
        one_i += 1
      end
    end
  end
  ans << arr
end
ans.each do |ar|
  puts ar.max
  ar.each do |x|
    print "#{x} "
  end
  puts ""
end

t = gets.to_i
ans = []
t.times do
  n = gets.to_i
  s = gets.chomp
  one_i = 1
  zero_i = 1
  arr = []
  n.times do |i|
    if s[i] == "0"
      if zero_i < one_i
        one_i -= 1
        arr << one_i
      else
        arr << zero_i
        zero_i += 1
      end
    elsif s[i] == "1"
      if zero_i > one_i
        zero_i -= 1
        arr << zero_i
      else
        arr << one_i
        one_i += 1
      end
    end
  end
  ans << arr
end
ans.each do |ar|
  ar.each do |x|
    print "#{x} "
  end
  puts ""
end

t = gets.to_i
ans = []
t.times do
  n = gets.to_i
  s = gets.chomp
  one_fin = 0
  zero_fin = 0
  arr = []
  n.times do |i|
    if s[i] == "0"
      if one_fin > 0
        zero_fin += 1
        arr << zero_fin
        one_fin -= 1
      else
        zero_fin += 1
        arr << zero_fin
      end
    elsif s[i] == "1"
      if zero_fin > 0
        one_fin += 1
        arr << one_fin
        zero_fin -= 1
      else
        one_fin += 1
        arr << one_fin
      end
    end
  end
  ans << arr
end
ans.each do |ar|
  puts ar.max
  ar.each do |x|
    print "#{x} "
  end
  puts ""
end


a = gets.split(',').map(&:to_i).sort
b = []
s = t = a[0]
a.each do |i|
	if i <= t + 1 then
		t = i
	else
		b << [s, t]
		s = t = i
	end
end
b << [s, t]
puts b.map{|a, b| a == b ? a : "#{a}-#{b}"} * ','

__END__

s = gets.split(",")
s = s.collect {|i| i = i.to_i}
s = s.sort
s = s.uniq
i = s.size-1
while i>0 do
    k = s[i].to_i
    if k == s[i-1] + 1 then
        if t = s[i].to_s.index("-") then s[i] = s[i][t+1...s[i].size].to_i
        end
        s[i-1] = s[i-1].to_s + "-" + s[i].to_s
        s.delete_at(i)
    end
    i -= 1
end
str = s.join(",")
print "#{str}\n"

sa = gets.chomp.split(/,/)
sa.map!{|x| x.to_i}
sa.uniq!
sa.sort!

ret = ""
st = 0
prev = 0
for i in 0..sa.length-1
	if st == 0
		ret += sa[i].to_s
		st = sa[i]
		prev = st
	else
		if sa[i] == prev+1
			prev = sa[i]
		else
			if st == prev
				ret +=  "," + sa[i].to_s
			else
				ret +=  "-" + prev.to_s + "," + sa[i].to_s
			end
			st = sa[i]
			prev = st
		end
	end
end

if st != prev
	ret +=  "-" + prev.to_s
end

puts ret

pages = gets.strip.split(",").map{|s| s.to_i}
inc = [false] * 2000
pages.each {|n| inc[n] = true}

i = 1
was = false
while i <= 1000
  unless inc[i]
    i += 1
    next
  end
  print "," if was
  j = i+1
  j += 1 while inc[j]
  print i
  print "-",j-1 if j > i+1
  was = true
  i = j
end

pages = gets.strip.split(",").map{|s| s.to_i}
inc = [false] * 2000
pages.each {|n| inc[n] = true}

i = 1
res = []
while i <= 1000
  unless inc[i]
    i += 1
    next
  end
  j = i+1
  j += 1 while inc[j]
  if j == i+1
    res << i
  else
    res << [i, "-", j-1].join("")
  end
  i = j
end

puts res.join(",")

#!usr/bin/env ruby
x=gets()
array=x.split(',')
#puts(array)
array2=Array.new()
array.each do
    |a|
    a=a.to_i
    #puts(a)
    array2 << a
end
array2.sort!
array2 = array2 & array2
#puts(array2)
prev = -1
res = ""
last=0
for x in array2 do
        if x-prev != 1 then
            if prev !=-1 && last != prev then
                res << "-" << prev.to_s
                last = prev
            end
            if res == "" then
                res << x.to_s
                last = x
            else
                res << ","
                res << x.to_s
                last = x
            end
        end
        prev = x
    end
    if last != prev then
        res << "-" << prev.to_s
    end
puts (res)

#!usr/bin/env ruby
x=gets()
array=x.split(',')
#puts(array)
array2=Array.new()
array.each do
    |a|
    a=a.to_i
    #puts(a)
    array2 << a
end
array2.sort!
array2 = array2 & array2
#puts(array2)
prev = -1
res = ""
last=0
for x in array2 do
        if x-prev != 1 then
            if prev !=-1 then
                res << "-" << prev.to_s
                last = prev
            end
            if res == "" then
                res << x.to_s
                last = x
            else
                res << ","
                res << x.to_s
                last = x
            end
        end
        prev = x
    end
    if last != prev then
        res << "-" << prev.to_s
    end
puts (res)


n = STDIN.readline.to_i
cups = []
n.times {|ix| cups.push([STDIN.readline.to_i, ix]) }
count = Hash.new(0)
cups.each {|volume, ix| count[volume] += 1 }
if count.keys.count == 1
  puts 'Exemplary pages.'
  exit
end

def fail
  puts 'Unrecoverable configuration.'
  exit
end

cups.sort!
delta = cups[-1][0] - cups[0][0]
fail if delta % 2 == 1
pour, source, target = delta/2, cups[0][1]+1, cups[-1][1]+1

cups[0][0] += pour
cups[-1][0] -= pour
count = Hash.new(0)
cups.each {|volume, ix| count[volume] += 1 }
fail if count.keys.count != 1

puts '%d ml. from cup #%d to cup #%d.' % [pour, source, target]

n = gets.to_i
a = n.times.map{gets.to_i}
s = a.inject &:+
k = a.find_all{|_| _ != s / n}.map{|_| a.index _}
if s % n != 0 || (!k.empty? && k.size != 2)
	puts 'Unrecoverable configuration.'
elsif k.empty?
	puts 'Exemplary pages.'
else
	i, j = *k
	i, j = j, i if a[i] < a[j]
	puts "#{(a[i] - a[j]) / 2} ml. from cup ##{j + 1} to cup ##{i + 1}."
end

n=gets.to_i
a=[]
n.times{
    a.push(gets.to_i)
}
ok=1
(n-1).times{|i|
    if a[i]!=a[i+1] then
        ok=0
        break
    end
}
if ok==1 then
    puts "Exemplary pages."
    exit
end
cnt={}
cnt.default=0
a.each{|i|
    cnt[i]+=1
}
if cnt.length<5 then
    n.times{|i|
        if cnt[a[i]]==1 then
            n.times{|j|
                if cnt[a[j]]==1 then
                    if a[i]>a[j] then
                        v=a[i]-a[j]
                        v/=2
                        a[i]-=v
                        a[j]+=v
                        ok=1
                        (n-1).times{|i|
                            if a[i]!=a[i+1] then
                            ok=0
                            break
                            end
                        }
                        if ok==1 then
                            printf "%d ml. from cup #%d to cup #%d.\n",v,j+1,i+1
                            exit
                        end
                        a[i]+=v
                        a[j]-=v;
                    end
                end
            }
        end
    }
end
puts "Unrecoverable configuration."

def check(a, b, n)
	diff = b[0]-a[0]
	if diff.odd? || (a[0]+b[0])/2 != n
		puts "Unrecoverable configuration."
		exit
	end
	puts "#{(diff)/2} ml. from cup ##{a[1]} to cup ##{b[1]}."
	exit
end

n = gets.to_i
arr = Array.new(n) { |idx| [gets.to_i, idx+1] }.sort.freeze

if arr[0][0] == arr[-1][0]
	puts "Exemplary pages."
	exit
end

if arr.size == 2
	diff = arr[1][0]-arr[0][0]
	if diff.odd?
		puts "Unrecoverable configuration."
		exit
	end
	check(arr[0], arr[1], (arr[0][0]+arr[1][0])/2)
end

if arr[1][0] != arr[-2][0]
	puts "Unrecoverable configuration."
	exit
end

check(arr[0], arr[-1], arr[1][0])

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

ls = $stdin.readlines.map(&:chomp)
n = ls[0].to_i
vs = ls.drop(1).map(&:to_i)

s = vs.inject(0, &:+)
if s % n != 0
  puts 'Unrecoverable configuration.'
  exit 0
end
ave = s / n

a = []
vs.each_with_index do |v, i|
  if v != ave
    a << [v, i]
  end
end
if a.empty?
  puts 'Exemplary pages.'
elsif a.size == 2 and a[0][0] + a[1][0] == ave * 2
  x, y = a.sort
  puts "#{ave - x[0]} ml. from cup ##{x[1]+1} to cup ##{y[1]+1}."
else
  puts 'Unrecoverable configuration.'
end

n = gets.to_i
arr = []
n.times do
	arr << gets.to_i
end
# arr.sort!
sorted = arr.sort
normal = sorted[1]
chunk = sorted.chunk{|x| x}
# puts "#{chunk.count}"
ans = false
if chunk.count == 1
	puts "Exemplary pages."
	ans = true
elsif chunk.count == 2 || chunk.count == 3
	min,min_ind,max,max_ind = arr.each_with_index.minmax.flatten
	# puts "min #{min} ind #{min_ind} #{max} #{max_ind}" if n == 198
	# puts "#{arr.count(min) == 1  && arr.count(max) == 1}"

	el = (min + max) / 2
	ml = max - el

	if (arr.count(min) == 1)  && (arr.count(max) == 1) && (el-min == ml)
		if !(chunk.count == 3 && el != normal)
			ans = true
			puts "#{ml} ml. from cup ##{min_ind+1} to cup ##{max_ind+1}."
		end
	end
end

puts "Unrecoverable configuration." unless ans

n = STDIN.readline.to_i
cups = []
n.times {|ix| cups.push([STDIN.readline.to_i, ix]) }
count = Hash.new(0)
cups.each {|volume, ix| count[volume] += 1 }
key_num = count.keys.count
if key_num == 1
  puts 'Exemplary pages.'
  exit
end
def fail
  puts 'Unrecoverable configuration.'
  exit
end
fail if key_num != 2 + (n > 2 ? 1 : 0)
cups.sort!
fail if n > 3 and cups[1][0] != cups[-2][0]
delta = cups[-1][0] - cups[0][0]
fail if delta % 2 == 1
pour, source, target = delta/2, cups[0][1]+1, cups[-1][1]+1
puts '%d ml. from cup #%d to cup #%d.' % [pour, source, target]

n = STDIN.readline.to_i
cups = []
n.times {|ix| cups.push([STDIN.readline.to_i, ix]) }
count = Hash.new(0)
cups.each {|volume, ix| count[volume] += 1 }
key_num = count.keys.count
if key_num == 1
  puts 'Exemplary pages.'
  exit
end
def fail
  puts 'Unrecoverable configuration.'
  exit
end
fail if key_num != 2 + (n > 2 ? 1 : 0)
fail if n > 3 and cups[1] != cups[-2]
cups.sort!
delta = cups[-1][0] - cups[0][0]
fail if delta % 2 == 1
pour, source, target = delta/2, cups[0][1]+1, cups[-1][1]+1
puts '%d ml. from cup #%d to cup #%d.' % [pour, source, target]

n = STDIN.readline.to_i
cups = []
n.times {|ix| cups.push([STDIN.readline.to_i, ix]) }
count = Hash.new(0)
cups.each {|volume, ix| count[volume] += 1 }
key_num = count.keys.count
if key_num == 1
  puts 'Exemplary pages.'
  exit
end
def fail
  puts 'Unrecoverable configuration.'
  exit
end
fail if key_num > 3 or n > 2 and key_num == 2
cups.sort!
delta = cups[-1][0] - cups[0][0]
fail if delta % 2 == 1
pour, source, target = delta/2, cups[0][1]+1, cups[-1][1]+1
puts '%d ml. from cup #%d to cup #%d.' % [pour, source, target]

n = STDIN.readline.to_i
cups = []
n.times {|ix| cups.push([STDIN.readline.to_i, ix]) }
count = Hash.new(0)
cups.each {|volume, ix| count[volume] += 1 }
key_num = count.keys.count
if key_num == 1
  puts 'Exemplary pages.'
  exit
end
def fail
  puts 'Unrecoverable configuration.'
  exit
end
fail if key_num > 3
cups.sort!
delta = cups[-1][0] - cups[0][0]
fail if delta % 2 == 1
pour, source, target = delta/2, cups[0][1]+1, cups[-1][1]+1
puts '%d ml. from cup #%d to cup #%d.' % [pour, source, target]

n = STDIN.readline.to_i
cups = []
n.times {|ix| cups.push([STDIN.readline.to_i, ix]) }
count = Hash.new(0)
cups.each {|volume, ix| count[volume] += 1 }
key_num = count.keys.count
if key_num == 1
  puts 'Exemplary pages.'
  exit
end
def fail
  puts 'Unrecoverable configuration.'
  exit
end
fail if key_num > 3
cups.sort!
delta = cups[-1][0] - cups[0][0]
fail if delta % 2 == 1
pour, source, target = delta/2, cups[-1][1]+1, cups[0][1]+1
puts '%d ml. from cup #%d to cup #%d.' % [pour, source, target]

n = STDIN.readline.to_i
cups = []
n.times {|ix| cups.push([STDIN.readline.to_i, ix]) }
count = Hash.new(0)
cups.each {|volume, ix| count[volume] += 1 }
key_num = count.keys.count
if key_num == 1
  puts 'Exemplary pages.'
  exit
end
def fail
  puts 'Unrecoverable configuration.'
  exit
end
fail if key_num > 3 or (n > 2 and key_num == 2)
cups.sort!
delta = cups[-1][0] - cups[0][0]
fail if delta % 2 == 1
pour, source, target = delta/2, cups[0][1]+1, cups[-1][1]+1
puts '%d ml. from cup #%d to cup #%d.' % [pour, source, target]

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

ls = $stdin.readlines.map(&:chomp)
n = ls[0].to_i
vs = ls.drop(1).map(&:to_i)

s = vs.inject(0, &:+)
if s % n != 0
  puts 'Unrecoverable configuration.'
  exit 0
end

a = []
vs.each_with_index do |v, i|
  if v != s / n
    a << [v, i]
  end
end
if a.empty?
  puts 'Exemplary pages.'
elsif a.size == 2 and a[0][0] + a[1][0] == s / n * 2
  x, y = a.sort
  puts "#{s/n - x[0]} ml. from cup ##{x[1]+1} to cup ##{y[1]+1}."
else
  puts 'Unrecoverable configuration'
end

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

ls = $stdin.readlines.map(&:chomp)
n = ls[0].to_i
vs = ls.drop(1).map(&:to_i)

s = vs.inject(0, &:+)
if s % n != 0
  puts 'Unrecoverable configuration.'
  exit 0
end

a = []
vs.each_with_index do |v, i|
  if v != s / n
    a << [v, i]
  end
end
if a.empty?
  puts 'Exemplay pages.'
elsif a.size == 2 and a[0][0] + a[1][0] == s / n * 2
  x, y = a.sort
  puts "#{s/n - x[0]} ml. from cup ##{x[1]+1} to cup ##{y[1]+1}."
else
  puts 'Unrecoverable configuration'
end

n = gets.to_i
arr = []
n.times do
	arr << gets.to_i
end
# arr.sort!
chunk = arr.sort.chunk{|x| x}
# puts "#{chunk.count}"
if chunk.count == 1
	puts "Exemplary pages."
elsif chunk.count == 2 || chunk.count == 3
	min,min_ind,max,max_ind = arr.each_with_index.minmax.flatten
	# puts "min #{min} ind #{min_ind} #{max} #{max_ind}" if n == 198
	# puts "#{arr.count(min) == 1  && arr.count(max) == 1}"

	el = (min + max) / 2
	ml = max - el

	if (arr.count(min) == 1)  && (arr.count(max) == 1) && el == arr.sort[1] && (el-min == ml)

		puts "#{ml} ml. from cup ##{min_ind+1} to cup ##{max_ind+1}."
	else
		puts "Unrecoverable configuration."
	end
else
	puts "Unrecoverable configuration."
end

n = gets.to_i
arr = []
n.times do
	arr << gets.to_i
end
# arr.sort!
chunk = arr.sort.chunk{|x| x}
# puts "#{chunk.count}"
if chunk.count == 1
	puts "Exemplary pages."
elsif chunk.count == 3
	min,min_ind,max,max_ind = arr.each_with_index.minmax.flatten
	# puts "min #{min} ind #{min_ind} #{max} #{max_ind}"
	# puts "#{arr.count(min) == 1  && arr.count(max) == 1}"
	if (arr.count(min) == 1)  && (arr.count(max) == 1)

		el = (min + max) / 2
		ml = max - el

		puts "#{ml} ml. from cup ##{min_ind+1} to cup ##{max_ind+1}."
	else
		puts "Unrecoverable configuration."
	end
else
	puts "Unrecoverable configuration."
end

n = gets.to_i
arr = []
n.times do
	arr << gets.to_i
end
# arr.sort!
chunk = arr.sort.chunk{|x| x}
# puts "#{chunk.count}"
if chunk.count == 1
	puts "Exemplary pages."
elsif chunk.count == 2 || chunk.count == 3
	min,min_ind,max,max_ind = arr.each_with_index.minmax.flatten
	# puts "min #{min} ind #{min_ind} #{max} #{max_ind}"
	# puts "#{arr.count(min) == 1  && arr.count(max) == 1}"

	el = (min + max) / 2
	ml = max - el
	if (arr.count(min) == 1)  && (arr.count(max) == 1) && (el-min == ml)

		puts "#{ml} ml. from cup ##{min_ind+1} to cup ##{max_ind+1}."
	else
		puts "Unrecoverable configuration."
	end
else
	puts "Unrecoverable configuration."
end

n = gets.to_i
arr = []
n.times do
	arr << gets.to_i
end
# arr.sort!
chunk = arr.sort.chunk{|x| x}
# puts "#{chunk.count}"
if chunk.count == 1
	puts "Exemplary pages."
elsif chunk.count == 2 || chunk.count == 3
	min,min_ind,max,max_ind = arr.each_with_index.minmax.flatten
	puts "min #{min} ind #{min_ind} #{max} #{max_ind}" if n == 198
	# puts "#{arr.count(min) == 1  && arr.count(max) == 1}"

	el = (min + max) / 2
	ml = max - el

	if (arr.count(min) == 1)  && (arr.count(max) == 1) && (el-min == ml)

		puts "#{ml} ml. from cup ##{min_ind+1} to cup ##{max_ind+1}."
	else
		puts "Unrecoverable configuration."
	end
else
	puts "Unrecoverable configuration."
end


size = gets.to_i
done = true
i=1
tableau_de_somme = []
tableau_final = []
tableau_final[0] = "!"

while done do
	puts "?"+ " " + i.to_s + " " + (i+=1).to_s
	$stdout.flush
	tableau_de_somme << gets.to_i
	done = false if i == size
end

resultat = []
resultat[0] = 0
a = 0

while a < (size-2) do
	resultat[0] += tableau_de_somme[a]
	resultat[0] -= tableau_de_somme[a += 1]
	a += 1
end

if size.modulo(2) == 0
	puts "?"+ " " + 1.to_s + " " + (size-1).to_s
	$stdout.flush
	tableau_de_somme << gets.to_i
else
	puts "?"+ " " + 1.to_s + " " + (size).to_s
	$stdout.flush
	tableau_de_somme << gets.to_i
end

resultat[0] += tableau_de_somme[size-1]
resultat[0] /= 2
tableau_final << resultat[0]

tableau_de_somme.each do |val|
	tableau_final << val - tableau_final.last
end

tableau_final.pop

tableau_final.each do |val|
	print val.to_s + " "
	$stdout.flush
end

#!/usr/bin/ruby

size = gets.to_i
resolu = true
i=1
tableau_de_somme = []
tableau_final = []
tableau_final[0] = "!"

while resolu do
	puts "?"+ " " + i.to_s + " " + (i+=1).to_s
	$stdout.flush
	tableau_de_somme << gets.to_i
	resolu = false if i == size
end
resultat = []
resultat[0] =0
iterator=0
while iterator < (size-2) do
	resultat[0] += tableau_de_somme[iterator]
	resultat[0] -= tableau_de_somme[iterator+=1]
	iterator+=1
end
if size.modulo(2) == 0
	puts "?"+ " " + 1.to_s + " " + (size-1).to_s
	$stdout.flush
	tableau_de_somme << gets.to_i
else
	puts "?"+ " " + 1.to_s + " " + (size).to_s
	$stdout.flush
	tableau_de_somme << gets.to_i
end
resultat[0] += tableau_de_somme[size-1]
resultat[0] /= 2
tableau_final << resultat[0]

tableau_de_somme.each do |val|
	tableau_final << val - tableau_final.last
end
tableau_final.pop
tableau_final.each do |val|
	print val.to_s + " "
	$stdout.flush
end

size = gets.to_i
resolu = true
indice=0
i=1
puts indice
tableau_de_somme = []
tableau_final = []
tableau_final[0] = "!"

while resolu do
    $stdout.print "?"+ " " + i.to_s + " " + (i+=1).to_s
    $stdout.flush
    tableau_de_somme << gets.to_i
    resolu = false if i == size
end
resultat = []
resultat[0] =0
iterator=0
while iterator < (size-2) do
    resultat[0] += tableau_de_somme[iterator]
    resultat[0] -= tableau_de_somme[iterator+=1]
    iterator+=1
end
if size.modulo(2) == 0
    $stdout.print "?"+ " " + 1.to_s + " " + (size-1).to_s
    $stdout.flush
    tableau_de_somme << gets.to_i
else
    $stdout.print "?"+ " " + 1.to_s + " " + (size).to_s
    $stdout.flush
    tableau_de_somme << gets.to_i
end
resultat[0] += tableau_de_somme[size-1]
resultat[0] /= 2
tableau_final << resultat[0]

tableau_de_somme.each do |val|
    tableau_final << val - tableau_final.last
end
tableau_final.pop
tableau_final.each do |val|
    print val.to_s + " "
end


n, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
MIN, MAX = a.minmax
if MIN <= k+1
  puts MIN
  exit
end

b = Array.new(MAX+1, 0)
a.each { |e| b[e] += 1 }
b.each_index do |i|
  b[i] += b[i-1] if i != 0
end

ans = MIN
loop do
  l = ans + k
  r = 2*ans - 1
  flag = true

  loop do
    if r > MAX
      if l >= MAX
        break flag = true
      else
        if b[l] < b[MAX]
          break flag = false
        else
          break flag = true
        end
      end
    elsif b[l] < b[r]
      break flag = false
    end
    l += ans
    r += ans
  end

  break if flag
  ans -= 1
end
puts ans

gets.scan(/(\d+) (\d+)/)
n=$1.to_i
k=$2.to_i
a=gets.scan(/\d+/).map {|s| s.to_i}.uniq.sort
l=Array.new(a.max+1, -1)
i=0
0.upto(a.max) {|j|
  if i<n && a[i]==j
    l[j+1]=a[i]
    i+=1
  else
    l[j+1]=l[j]
  end
}

a.first.downto(2){|divisor|
  existAns=true
  j=a.last
  while j>=a.first
    if j%divisor>k || j==a.first && j<divisor
      existAns=false
      break
    end
    j=l[j-j%divisor]
  end
  if existAns
    p divisor
    exit
  end
}
p 1

gets.scan(/(\d+) (\d+)/)
n=$1.to_i
k=$2.to_i
a=gets.scan(/\d+/).map {|s| s.to_i}.uniq.sort
l=Array.new(a.max+1, -1)
(0..a.size-2).each{|i|
  l.fill(a[i], a[i]+1..a[i+1])
}

a.first.downto(2){|divisor|
  existAns=true
  j=a.last
  while j>=a.first
    if j%divisor>k
      existAns=false
      break
    end
    j=l[j-j%divisor]
  end
  if existAns
    p divisor
    exit
  end
}
p 1

n, k = gets.split(' ').map {|x| x.to_i}
a = gets.split(' ').map {|x| x.to_i}.sort
minv, maxv = a.minmax

cnt = (Array.new maxv + 5).fill(0)
a.each {|x| cnt[x] += 1}
cnt.each_index {|i| cnt[i] += cnt[i - 1] if (i > 0)}
cnt[-1] = 0 # guard

(puts minv; exit) if (minv <= k + 1)

ans = minv
loop do
	l, r = k, ans - 1
	flag = 1
	while (l <= maxv) do
		r = maxv if (r > maxv)
		(flag = 0; break) if (cnt[r] > cnt[l])
		l += ans
		r += ans
	end
	break if (flag == 1)
	ans -= 1
end
puts ans

n, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
MIN, MAX = a.minmax
if MIN <= k+1
  puts MIN
  exit
end

b = Array.new(MAX+1, 0)
a.each { |e| b[e] += 1 }
b.each_index do |i|
  b[i] += b[i-1] if i != 0
end

ans = MIN
loop do
  l = ans + k
  r = 2*ans - 1
  flag = true

  while r < MAX
    if b[l] < b[r]
      break flag = false
    end
    l += ans
    r += ans
  end

  break if flag && l >= MAX
  ans -= 1
end

puts ans

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

loop do
  flag = true
  a.each do |e|
    while e % ans > k
      ans -= 1
      flag = false
    end
  end
  break if flag
end
puts ans

gets.scan(/(\d+) (\d+)/)
n=$1.to_i
k=$2.to_i
a=gets.scan(/\d+/).map {|s| s.to_i}.uniq.sort

p (1..a.first).to_a.delete_if {|divisor| a.reject!{|x|x%divisor>k || x==a.first && x<divisor}!=nil}.last

gets.scan(/(\d+) (\d+)/)
n=$1.to_i
k=$2.to_i
a=gets.scan(/\d+/).map {|s| s.to_i}.sort
l=Array.new(a.max+1, -1)
i=0
0.upto(a.max) {|j|
  if i<n && a[i]==j
    l[j+1]=a[i]
    i+=1
  else
    l[j+1]=l[j]
  end
}

a.first.downto(2){|divisor|
  existAns=true
  j=a.last
  while j>=a.first
    if j%divisor>k || j==a.first && j<divisor
      existAns=false
      break
    end
    j=l[j-j%divisor]
  end
  if existAns
    p divisor
    exit
  end
}
p 1


a=gets.chomp.split(" ")
n=a[0].to_i
k=a[1].to_i
k.times do
printf "#{n} "
n-=1
end

1.upto(n) do |i|
printf "#{i} "
end

#!/usr/bin/env ruby

n, k = STDIN.readline.split.map{ |x| Integer(x)}

k.times do |i|
    print "#{n - i} "
end

(1..n-k).each do |i|
    print "#{i} "
end

puts

def run
  n, k = $stdin.gets.split.map(&:to_i)
  $stdout.puts ((k + 1).downto(1).to_a + (k + 2).upto(n).to_a).join(" ")
end

run if $0 == __FILE__

# cook your code here
n, k =gets.split(' ').map(&:to_i)

arr = Array(1..n)
arr.unshift(arr.pop(k).reverse)
puts arr.join(' ')

# cook your code here
n, k =gets.split(' ').map(&:to_i)

k_copy =k
arr = Array(1..n)
last_index = arr.size-1
ans_arr = []
n.times do
    while k>0 do
        ans_arr << arr[last_index]
        last_index-=1
        k-=1
    end
end

(n-k_copy).times do  |i|
    ans_arr << arr[i]
end

puts ans_arr.join(" ")

class A
  def initialize
    n, k = $stdin.gets.split(' ').map(&:to_i)

    list = (1..n).to_a

    flag = true

    ans = Array.new(n,nil)

    if k > 0
      index = -1
      k.times do
        ans[index] = list.shift
        index -= 1
      end

      index = 0
      (n-k).times do
        ans[index] = list.shift
        index += 1
      end
    else
      ans = list
    end

    puts ans.join(' ')
  end
end

a = A.new

require 'set'
require 'rational'
require 'mathn'
include Math
$stdin = File.open("./input.txt", "r") if ENV["USER"] == "new"
# ====================================

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

((k+1)..n).each do |index|
  print index," "
end
k.downto(1) do |index|
  print index," "
end

n,k = gets.split.map &:to_i
to = n-k
for i in (1..to-1)
    print "#{i} "
end
for i in (to+1..n)
    print "#{n-i+to+1} "
end
print to

require 'scanf'
(n, k) = scanf("%d%d")
# (n, k) = gets.chomp.split(' ').map(&:to_i)
a = Array.new(n)
(1..n).each do |i|
  a[i-1] = (i<=k) ? (n-i+1) : (i-k)
end
puts a.join(' ')

n,k=gets.split.map(&:to_i)
a=[]
n.downto(1){|x|a<<x}
a[0,k+1]=a[0,k+1].reverse
puts a.reverse*' '

n,k = gets.split.map &:to_i
    for i in (1..n-k-1)
      print i.to_s+" "
    end
    i=n
    while i>=n-k
        print i.to_s+" "
        i-=1
    end
    puts ""

n, k = gets.split.map(&:to_i)
puts ((1...(n - k)).to_a + n.downto(n - k).to_a).join(' ')

n, k = gets.split.map(&:to_i)
(1..k).each{|i| print n-i+1, ' '}
(1..(n-k)).each{|i| print i, ' '}

#!/usr/bin/env ruby

n, k = gets.split.collect{ |i| i.to_i }

k.downto(0) { |i| print "#{i+1} " }
(k+2).upto(n) { |i| print "#{i} " }

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

(1..n)
result = (k+1).downto(1).to_a + (k+2..n).to_a

puts result.join(' ')

n, k = gets.split(' ').map(&:to_i)
ans = (0...k).map{|x| n-x} + (1..n-k).map{|x| x}
puts ans.map(&:to_s).join(" ")

# -*- encoding: utf-8 -*-
n, k = gets.chomp.split( " " ).map{ |e| e.to_i }
array = (1 .. n).to_a

ans = array[0 .. k].reverse() + array[k + 1 .. n]
puts ans.join " "

st = gets.split
n=st[0].to_i
k=st[1].to_i

el=n
(k).times do
  print(el," ")
  el-=1
end

el=1
(n-k).times do
  print(el," ")
  el+=1
end

n, k = gets.split.map { |i| i.to_i }
a = (1..n).to_a
a = a[0..-(k + 2)] + a[-(k + 1)..-1].reverse

a.each do |i|
  print i, ' '
end
puts

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

a = Array.new

for i in 0...k
  a << n-i
end

for i in 1..n-k
  a << i
end

for i in a
  print i, " "
end

#!/usr/bin/ruby1.9

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

prefix = (1..k+1).collect {|x| x }.reverse
suffix = (k+2..n).collect {|x| x }

puts (prefix+suffix).join(' ')

# cook your code here
n, k =gets.split(' ').map(&:to_i)

arr = Array(1..n)
arr.unshift(arr.pop(k))
puts arr.join(' ')

class A
  def initialize
    n, k = $stdin.gets.split(' ').map(&:to_i)

    list = (1..n).to_a

    flag = true

    ans = Array.new(n,nil)

    if k > 0
      index = -1
      k.times do
        ans[index] = list.shift
        index -= 1
      end

      index = 0
      (n-k).times do
        ans[index] = list.shift
      end
    else
      ans = list
    end

    puts ans.join(' ')
  end
end

a = A.new

a=gets.chomp.split(" ")
c=a[0].to_i
b=a[1].to_i
trig=0
ans=[]
loop do
if ans.count(c%b)==0
ans << c%b
else
break
end

c=c+c%b
if c % b == 0
trig=1
break
end

end

if trig==1
puts "Yes"
else
puts "No"
end


$stdout.sync = true

def query(x)
  puts "? #{x}"
  gets.chomp.to_i
end

def solution(n)
  value = yield(1)
  l, r = 1, value + 1
  while r - l > 1 do
    mid = (l + r) / 2
    a, b = yield(mid - 1), yield(mid)
    delta = mid - l
    if a < b
      r = mid
    elsif b <= value - delta
      l, value = mid, b
    else
      r = mid
    end
  end
  return l
end

def stress
  array = (20).times.map { |x| x + 1 }.shuffle
  index = solution(array.length) { |x| array[x - 1] } - 1
  puts(array.inspect)
  puts(index)
  if not ((index == 0 or array[index - 1] > array[index]) and (index == array.length - 1 or array[index + 1] > array[index]))
    puts("Fail!")
  end
end

def main
  n = gets.chomp.to_i
  puts("! #{solution(n) { |x| query(x) }}")
end

main

n=gets.to_i
arr=[nil]*(n+2)
l=0
r=n+1
while r-l>3
  m0=l+(r-l)/3
  m1=r-(r-l)/3
  if !arr[m0]
    puts "? #{m0}"
    $stdout.flush
    v0=gets.to_i
    arr[m0]=v0
  else
    v0=arr[m0]
  end
  if !arr[m1]
    puts "? #{m1}"
    $stdout.flush
    v1=gets.to_i
    arr[m1]=v1
  else
    v1=arr[m1]
  end
  if v0>v1
    l=m0
  else
    r=m1
  end
end
m0=l+1
m1=r-1
if !arr[m0]
  puts "? #{m0}"
  $stdout.flush
  v0=gets.to_i
  arr[m0]=v0
else
  v0=arr[m0]
end
if !arr[m1]
  puts "? #{m1}"
  $stdout.flush
  v1=gets.to_i
  arr[m1]=v1
else
  v1=arr[m1]
end
if v0>v1
  puts "! #{m1}"
else
  puts "! #{m0}"
end

$stdout.sync = true

def query(x)
  puts "? #{x}"
  gets.chomp.to_i
end

n = gets.chomp.to_i
value = query(1)
l, r = 1, value + 1
while r - l > 1 do
  mid = (l + r) / 2
  mid_value = query(mid)
  delta = mid - l
  if mid_value <= value - delta
    l, value = mid, mid_value
  else
    r = mid
  end
end
puts "! #{l}"

$stdout.sync = true

def query(x)
  puts "? #{x}"
  gets.chomp.to_i
end

n = gets.chomp.to_i
value = query(1)
l, r = 1, value + 1
while r - l > 1 do
  mid = (l + r) / 2
  mid_value = query(mid)
  delta = mid - l
  if mid_value <= value - delta
    l = mid
    value = mid_value
  else
    r = mid
  end
end
puts "! #{l}"

n=gets.to_i
l=1
r=n
ll=l
rr=r
puts "? #{l}"
$stdout.flush
lm=gets.to_i
puts "? #{r}"
$stdout.flush
rm=gets.to_i
while true
  m=(l+r)/2
  f=0
  if lm<=rm
    r=m
    f=0
  else
    l=m
    f=1
  end
  while r-l>1
    puts "? #{m}"
    $stdout.flush
    m=(l+r)/2
    if f==0
      rm=gets.to_i
    else
      lm=gets.to_i
    end
    if lm<=rm
      rr=r
      r=m
      f=0
    else
      ll=l
      l=m
      f=1
    end
  end
  puts "? #{m}"
  $stdout.flush
  mm=gets.to_i
  if lm>mm&&mm<rm
    puts "! #{m}"
    exit
  else
    l=ll
    r=rr
    puts "? #{l}"
    $stdout.flush
    lm=gets.to_i
    puts "? #{r}"
    $stdout.flush
    rm=gets.to_i
  end
end


fst=gets.split
n=fst[0].to_i
p1=fst[1].to_i
p2=fst[2].to_i
p3=fst[3].to_i
t1=fst[4].to_i
t2=fst[5].to_i
line=gets.split
l=[line[0].to_i]
r=[line[1].to_i]
d=r[0]-l[0]
res=d*p1
(n-1).times do |i|
  line=gets.split
  l[i+1]=line[0].to_i
  r[i+1]=line[1].to_i
  d0=r[i+1]-l[i+1]
  res += d0*p1
  d1=l[i+1]-r[i]
  if d1<=t1
    res += d1*p1
  else
    res += t1*p1
    d2=d1-t1
    if d2<=t2
      res += d2*p2
    else
      res += t2*p2
      res += (d2-t2)*p3
    end
  end
end
puts res

s,e,c=[],[],0
n,p0,p1,p2,t0,t1=gets.chomp!.split(" ").map{|elem|elem.to_i}
n.times {|i|
  s[i%2],e[i%2]=gets.chomp!.split(" ").map{|elem|elem.to_i}
  c+=(e[i%2]-s[i%2])*p0
  if i>0 then w=s[i%2]-e[(i+1)%2]
  if w<=t0 then c+=w*p0 elsif w<=t0+t1 then c+=p0*t0+p1*(w-t0) else c+=p0*t0+p1*t1+p2*(w-t1-t0) end end
}
puts c

n, p1, p2, p3, t1, t2 = gets.chomp.split.map(&:to_i)
l, r = [], []
power = 0
n.times do |index|
	l[index % 2], r[index % 2] = gets.chomp.split.map(&:to_i)
	power += (r[index % 2] - l[index % 2]) * p1
	if index > 0
		no_activity = l[index % 2] - r[(index + 1) % 2]
		if no_activity <= t1
			power += no_activity * p1
		elsif no_activity <= t1 + t2
			power += t1 * p1 + (no_activity - t1) * p2
		else
			power += t1 * p1 + t2 * p2 + (no_activity - t1 - t2) * p3
		end
	end
end

puts power

n, p1, p2, p3, t1, t2 = gets.split.map(&:to_i)
s, t = 0, 0
n.times do |i|
	l, r = gets.split.map(&:to_i)
	if i > 0
		[[p1, t1], [p2, t2], [p3, 1e9]].each do |pi, ti|
			d = [ti, l - t].min
			s += d * pi
			t += d
		end
	end
	s += (r - l) * p1
	t = r
end
p s

input=gets.split.map(&:to_i)
n=input[0]
p1=input[1]
p2=input[2]
p3=input[3]
t1=input[4]
t2=input[5]

back=-1
ans=0
n.times{|i|
    input=gets.split.map(&:to_i)
    if back==-1 then
        back=input[0]
    end
    ans+=(input[1]-input[0])*p1
    t=input[0]-back
    t1.times{
        if t==0 then
            break
        end
        t-=1
        ans+=p1
    }
    t2.times{
        if t==0 then
            break
        end
        t-=1
        ans+=p2
    }
    ans+=t*p3
    back=input[1]
}
puts ans

s,e,c=[],[],0
n,p0,p1,p2,t0,t1=gets.chomp!.split(" ").map{|elem|elem.to_i}
n.times {|i|s[i%2],e[i%2]=gets.chomp!.split(" ").map{|elem|elem.to_i}
  c+=(e[i%2]-s[i%2])*p0
  if i>0 then w=s[i%2]-e[(i+1)%2]
  if w<=t0 then c+=w*p0 elsif w<=t1 then c+=p0*t0+p1*(w-t0) else c+=p0*t0+p1*t1+p2*(w-t1-t0) end end}
puts c


gets.to_i.times do
  n, x = gets.split.map(&:to_i)
  as = gets.split.map(&:to_i).sort
  sums = as.reduce([]) { |acc, x| acc << (acc.last || 0) + x }
  answer = sums.map.with_index do |sum, i|
    [0, (1 + (x - sum) / (i + 1))].max
  end.sum
  p answer
end

gets.to_i.times do
  n, x= gets.chomp.split.map(&:to_i)
  a = gets.chomp.split.map(&:to_i).sort
  cum = 0
  ans = 0
  0.upto(n-1) do |i|
    cum += a[i]
    ans += (x >= cum)?((x-cum)/(i+1)+1) : 0
  end
  puts ans
end


s = gets.chomp

mod = 10**9 + 7
str = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_'
ans = 1

s.split('').each do |c|
  (str.index(c) + 64).to_s(2).split('').each do |d|
    ans = ans * 3 % mod if d == '0'
  end
end

puts ans

 def gao(ch)
  case ch
  when '0'..'9'
    return ch.ord - '0'.ord
  when 'A'..'Z'
    return ch.ord - 'A'.ord + 10
  when 'a'..'z'
    return ch.ord - 'a'.ord + 36
  when '-'
    return 62
  when '_'
    return 63
  end
end

def cal(num)
#  puts num
  ret = 0
  6.times do
    ret += 1 if (num % 2) == 0
    num >>= 1
  end
#  puts ret
  ret
end

str = readline.strip
sum = str.each_char.map{|num| gao(num)}.map{|num| cal(num)}.inject(0, :+)
mod = 1000000007
res = 1
sum.times {res = (res * 3) % mod}
puts res

s = gets.chomp
ans = 1
patterns = ("0".."9").to_a + ("A".."Z").to_a + ("a".."z").to_a + ["-","_"]
symbols = {}
patterns.each_with_index do |s,i|
    symbols[s] = i
end

for c in s.split("") do
    val = symbols[c]
    6.times do |i|
        if val&1 == 0 then
            ans = (ans*3)%1000000007
        end
        val >>= 1
    end
end

print ans


a=gets.chomp.to_i
if a==1
puts "1"
puts "1"
elsif a==2
puts "1"
puts "1"
elsif a==3
puts "2"
puts "1 3"
else
puts "#{a}"
if a%2==1
printf "#{a/2 + 1} "
0.upto(a/2 - 1) do |i|
printf "#{i+1} #{a-i} "
end
else
printf "#{a/2 + 1} "
0.upto(a/2 - 2) do |i|
printf "#{i+1} #{a-i} "
end
printf "#{a/2}"
end
end

n=gets.to_i
arr=[]
if n<5 then
	arr=[[],[1],[1],[1,3],[2,4,1,3]][n]
	puts arr.size
	puts arr*" "

else
	1.step(n,2){|e|
			arr<<e
	}
	2.step(n,2){|e|
		arr<<e
	}
	puts arr.size
	puts arr*" "
end

n = gets.to_i

if n == 1 || n == 2
  puts '1'
  puts '1'
elsif n == 3
  puts '2'
  puts '1 3'
else
  puts n

  print 3
  (5..n).step(2).each_with_index { |v,i|
    print ' '
    print v
  }
  print ' '
  print 1
  (2..n).step(2).each_with_index.reverse_each { |v, i|
    print ' '
    print v
  }
  print "\n"
end

def sol(arr,i,n)
	# p arr
	if i>n
		return arr
	end

	ch = 0
	if !arr.include?(i)
		if arr == []
			ch = 1
			p = sol(arr+[i],1,n)
		elsif (i>=arr[-1]+2 || i<=arr[-1]-2)
			ch = 1
			p = sol(arr+[i],1,n)
		end
	end
	np = sol(arr,i+1,n)

	if ch == 1
		return p.length > np.length ? p : np
	end
	return np
end

n = gets.chomp.to_i
f = (1..n/2).to_a.reverse
bf = ((n/2)+1..n).to_a.reverse
order = f.length>bf.length ? 1 : 2

if n < 6
	a = sol([],1,n)
	puts "#{a.length}"
	puts a.join(" ")
else

	ans = []
	while true
		if f == [] && bf == []
			break
		end
		if order == 1
			if f!=[]
				ans << f.pop
			end
			if bf!=[]
				ans << bf.pop
			end
		else
			if bf!=[]
				ans << bf.pop
			end
			if f!=[]
				ans << f.pop
			end
		end
	end

	puts "#{ans.length}"

	puts ans.join(" ")
end

n = gets.strip.to_i
if n <= 2
  puts "1"
  puts "1"
  exit
end

if n == 3
  puts n - 1
  puts (1..n).to_a.select { |e| e.odd? }.sort.reverse.join(' ')
  exit
end

odd = (1..n).to_a.select { |e| e.odd? }.sort.reverse
even = (1..n).to_a.select { |e| e.even? }.sort.reverse

puts n
print odd.join(' ')
print " "
print even.join(' ')

a= gets().chomp().to_i
if a==1||a==2
  print 1,"\n",1
elsif a==3
  print 2,"\n",1,' ',3
else
 print a,"\n" ;(1..a).each{|num| print num,' ' if num%2==0} ;(1..a).each{|num| print num,' ' if num%2==1}
end

n = gets.to_i

if n <= 2
  puts "1\n1\n"
elsif n == 3
  puts "2\n1 3\n"
else
  e = 1.upto(n).select { |x| x % 2 == 0 }
  o = 1.upto(n).select { |x| x % 2 == 1 }
  puts n
  puts e.join(" ") + " " + o.join(" ")
end

n = gets.to_i
if n==1 or n==2
    print "1\n1\n"
    exit
elsif n==3
    print "2\n1 3\n"
    exit
elsif n==4
    print "4\n3 1 4 2\n"
    exit
end
left = Array.new
right = Array.new
for i in (1...n).step(2)
    left.push(i)
    right.push(i+1)
end
if n.odd?
    left.push(n)
end
puts n
puts (left+right).join(' ')

#!/usr/bin/env ruby
n=gets.to_i
if n<3
	puts "1\n1\n"
elsif n<4
	puts "2\n1 3\n"
else
	p n
	puts (2.step(n,2).to_a+1.step(n,2).to_a)*' '
end

# http://codeforces.com/contest/534/problem/A
n = gets.to_i
arr = case n
      when 1, 2
        [1]
      when 3
        [1, 3]
      else
        2.step(n, 2).to_a + 1.step(n, 2).to_a
      end

puts arr.length
puts arr.join(' ')

n = gets.to_i
if n==1 or n==2
    print "1\n1\n"
    exit
elsif n==3
    print "2\n1 3\n"
    exit
elsif n==4
    print "4\n3 1 4 2\n"
    exit
end
puts n
puts ((1..n).step(2).to_a+(2..n).step(2).to_a).join(' ')

n = gets.to_i
ans = case n
when 1, 2
  [1]
when 3
  [1, 3]
when 4
  [3, 1, 4, 2]
else
  a = []
  b = []
  1.upto(n) do |i|
    (i.odd? ? a : b) << i
  end
  a + b
end
puts ans.size
puts ans.join(" ")

n = gets.to_i
a = case n
when 1, 2
  [1]
when 3
  [1, 3]
when 4
  [3, 1, 4, 2]
else
  a = []
  b = []
  n.times do |i|
    i += 1
    (i % 2 == 0 ? b : a) << i
  end
  a + b
end
puts a.size
puts a.join(" ")

n = gets.to_i
ans = case n
when 1, 2
  [1]
when 3
  [1, 3]
when 4
  [3, 1, 4, 2]
else
  (1..n).partition{|x| x.odd?}.flatten
end
puts ans.size, ans.join(" ")

#!/usr/bin/env ruby
n=gets.to_i
if n<3
	puts "1\n1\n"
elsif n<5
	puts "2\n1 3\n"
else
	p n
	puts (1.step(n,2).to_a+2.step(n,2).to_a)*' '
end

# http://codeforces.com/contest/534/problem/A
n = gets.to_i
arr = case n
      when 1, 2
        [1]
      when 3
        [1, 3]
      else
        1.step(n, 2).to_a + 2.step(n, 2).to_a
      end

puts arr.length
puts arr.join(' ')

a=gets.chomp.to_i
if a==1
puts "1"
puts "1"
elsif a==2
puts "0"
elsif a==3
puts "2"
puts "1 3"
else
puts "#{a}"
if a%2==1
printf "#{a/2 + 1} "
0.upto(a/2 - 1) do |i|
printf "#{i+1} #{a-i} "
end
else
printf "#{a/2 + 1} "
0.upto(a/2 - 2) do |i|
printf "#{i+1} #{a-i} "
end
printf "#{a/2}"
end
end

n = gets.to_i

if n == 2
  pust '1'
  puts '1'
elsif n == 3
  puts '2'
  puts '1 3'
else
  puts n

  print 3
  (5..n).step(2).each_with_index { |v,i|
    print ' '
    print v
  }
  print ' '
  print 1
  (2..n).step(2).each_with_index.reverse_each { |v, i|
    print ' '
    print v
  }
  print "\n"
end

def sol(arr,i,n)
	# p arr
	if i>n
		return arr
	end

	ch = 0
	if !arr.include?(i)
		if arr == []
			ch = 1
			p = sol(arr+[i],1,n)
		elsif (i>=arr[-1]+2 || i<=arr[-1]-2)
			ch = 1
			p = sol(arr+[i],1,n)
		end
	end
	np = sol(arr,i+1,n)

	if ch == 1
		return p.length > np.length ? p : np
	end
	return np
end

n = gets.chomp.to_i
f = (1..n/2).to_a.reverse
bf = ((n/2)+1..n).to_a.reverse

if n < 6
	a = sol([],1,n)
	puts "#{a.length}"
	puts a.join(" ")
else

	ans = []
	while true
		if f == [] && bf == []
			break
		end
		if f!=[]
			ans << f.pop
		end
		if bf!=[]
			ans << bf.pop
		end
	end

	puts "#{ans.length}"

	puts ans.join(" ")
end

# def sol(arr,i,n)
# 	# p arr
# 	if i>n
# 		return arr
# 	end

# 	ch = 0
# 	if !arr.include?(i)
# 		if arr == []
# 			ch = 1
# 			p = sol(arr+[i],1,n)
# 		elsif (i>=arr[-1]+2 || i<=arr[-1]-2)
# 			ch = 1
# 			p = sol(arr+[i],1,n)
# 		end
# 	end
# 	np = sol(arr,i+1,n)

# 	if ch == 1
# 		return p.length > np.length ? p : np
# 	end
# 	return np
# end

n = gets.chomp.to_i
an = [1]
set = (2..n).to_a
i = 0
while true
	if n == 4
		break
	end
	ch = 0
	if i == n
		break
	end
	set.length.times{|x|
		if set[x]>=an[i]+2 || set[x] <= an[i]-2
			# p set
			an<< set[x]
			set.delete(set[x])
			i+=1
			ch = 1
			break
		end
	}
	if ch == 0
		break
	end
end

if n == 4
	puts 4.to_s
	puts [3,1,4,2].join(" ")
else
	# a = sol([],1,n)
	puts "#{i}"
	# puts "#{a.length}"
	# puts a.join(" ")
	puts an.join(" ")
end

n = gets.chomp.to_i
an = [1]
set = (2..n).to_a
i = 0
while true
	ch = 0
	if i == n
		break
	end
	set.length.times{|x|
		if set[x]>=an[i]+2 || set[x] <= an[i]-2
			# p set
			an<< set[x]
			set.delete(set[x])
			i+=1
			ch = 1
			break
		end
	}
	if ch == 0
		break
	end
end

puts "#{i+1}"
puts an.join(" ")

# def sol(arr,i,n)
# 	# p arr
# 	if i>n
# 		return arr
# 	end

# 	ch = 0
# 	if !arr.include?(i)
# 		if arr == []
# 			ch = 1
# 			p = sol(arr+[i],1,n)
# 		elsif (i>=arr[-1]+2 || i<=arr[-1]-2)
# 			ch = 1
# 			p = sol(arr+[i],1,n)
# 		end
# 	end
# 	np = sol(arr,i+1,n)

# 	if ch == 1
# 		return p.length > np.length ? p : np
# 	end
# 	return np
# end

n = gets.chomp.to_i
an = [1]
set = (2..n).to_a
i = 0
while true
	if n == 4
		break
	end
	ch = 0
	if i == n
		break
	end
	set.length.times{|x|
		if set[x]>=an[i]+2 || set[x] <= an[i]-2
			# p set
			an<< set[x]
			set.delete(set[x])
			i+=1
			ch = 1
			break
		end
	}
	if ch == 0
		break
	end
end

if n == 4
	puts 4.to_s
	puts [3,1,4,2].join(" ")
else
	# a = sol([],1,n)
	puts "#{i+1}"
	# puts "#{a.length}"
	# puts a.join(" ")
	puts an.join(" ")
end

n = gets.strip.to_i
if n <= 2
  puts "0"
  exit
end

if n == 3
  puts n - 1
  puts (1..n).to_a.select { |e| e.odd? }.sort.join(' ')
  exit
end
odd = (1..n).to_a.select { |e| e.odd? }.sort
even = (1..n).to_a.select { |e| e.even? }.sort

puts n
print odd.join(' ')
print " "
print even.join(' ')

n = gets.strip.to_i
if n <= 2
  puts "1"
  puts "1"
  exit
end

if n == 3
  puts n - 1
  puts (1..n).to_a.select { |e| e.odd? }.sort.join(' ')
  exit
end
odd = (1..n).to_a.select { |e| e.odd? }.sort
even = (1..n).to_a.select { |e| e.even? }.sort

puts n
print odd.join(' ')
print " "
print even.join(' ')

n = gets.strip.to_i
if n <= 2
  puts "0"
  exit
end

if n == 3
  puts (1..n).to_a.select { |e| e.odd? }.sort.join(' ')
  exit
end
odd = (1..n).to_a.select { |e| e.odd? }.sort
even = (1..n).to_a.select { |e| e.even? }.sort

print odd.join(' ')
print " "
print even.join(' ')

n = gets.to_i
if n==1
    print "1\n1\n"
    exit
end
left = Array.new
right = Array.new
k = n/2
for i in 1..k
    if i.odd?
        left.push(i)
        right.push(n+1-i)
    else
        left.push(n+1-i)
        right.push(i)
    end
end
puts k*2
puts (left+right).join(' ')

n = gets.to_i
left = Array.new
right = Array.new
k = n/2
for i in 1..k
    if i.odd?
        left.push(i)
        right.push(n+1-i)
    else
        left.push(n+1-i)
        right.push(i)
    end
end
puts k*2
puts (left+right).join(' ')

n = gets.to_i
if n==1 or n==2
    print "1\n1\n"
    exit
elsif n==3
    print "2\n1 3\n"
    exit
elsif n==4
    print "4\n1 4 2 3\n"
    exit
end
left = Array.new
right = Array.new
for i in (1...n).step(2)
    left.push(i)
    right.push(i+1)
end
if n.odd?
    left.push(n)
end
puts n
puts (left+right).join(' ')

n = gets.to_i
if n==1 or n==2
    print "1\n1\n"
    exit
elsif n==4
    print "4\n3 1 4 2\n"
end
left = Array.new
right = Array.new
k = n/2
for i in 1..k
    if i.odd?
        left.push(i)
        right.push(n+1-i)
    else
        left.push(n+1-i)
        right.push(i)
    end
end
puts k*2
puts (left+right).join(' ')

n = gets.to_i
if n==1 or n==2
    print "1\n1\n"
    exit
end
left = Array.new
right = Array.new
k = n/2
for i in 1..k
    if i.odd?
        left.push(i)
        right.push(n+1-i)
    else
        left.push(n+1-i)
        right.push(i)
    end
end
puts k*2
puts (left+right).join(' ')

n = gets.to_i
if n==1 or n==2
    print "1\n1\n"
    exit
elsif n==4
    print "4\n3 1 4 2\n"
    exit
end
left = Array.new
right = Array.new
k = n/2
for i in 1..k
    if i.odd?
        left.push(i)
        right.push(n+1-i)
    else
        left.push(n+1-i)
        right.push(i)
    end
end
puts k*2
puts (left+right).join(' ')


n = gets.to_i
a = gets.split.map{ |i| i.to_f }
a.sort!
p = 1
s = 0
ans = 0
out = 0
while s < 1.0 && a.length > 0 do
	el = a.pop
	if s + el * (1 - el) > 1.0
		out = [out, ans + p * el * ( 1 - s )].max
		next
	end
	ans += p * el * ( 1 - s )
	p *= (1 - el)
	s += el / (1 - el)
	out = [ans, out].max
end
puts out

n=readline.to_i
p=readline.split(' ').map &:to_f
p=p.sort{|a,b| b<=>a}
ap,bs,ans=1,0,0
p.each do |x|
  nap=ap*(1.0-x)
  nbs=bs+x/(1.0-x)
  if nap*nbs > ans
    ans=nap*nbs
    ap,bs=nap,nbs
  end
end
puts [p[0],ans].max

_ = gets.to_i
p = gets.split.map { |x| x.to_f }
ans = 0.0
res = 1.0
while p.size > 0
  max = ans
  sel = -1
  p.each_with_index do |x, i|
    if ans * (1.0 - x) + res * x > max
      max = ans * (1.0 - x) + res * x
      sel = i
    end
  end
  break if sel == -1
  ans = max
  res *= 1 - p[sel]
  p.delete_at(sel)
end
puts ans

n=readline.to_i
p=readline.split(' ').map &:to_f
p=p.sort{|a,b| b<=>a}
ans=p.shift
p.each {|x| ans=[ans, x*(1.0-ans)+ans*(1.0-x)].max }
puts ans

n=readline.to_i
p=readline.split(' ').map &:to_f
p=p.sort{|a,b| b<=>a}
ap,bs,ans=1,0,p[0]
p.each do |x|
  nap=ap*(1.0-x)
  nbs=bs+x/(1.0-x)
  if nap*nbs > ans
    ans=nap*nbs
    ap,bs=nap,nbs
  end
end
puts ans

n=readline.to_i
p=readline.split(' ').map &:to_f
p=p.sort{|a,b| b<=>a}
ap,bs,ans=1,0,0
p.each do |x|
  nap=ap*(1.0-x)
  nbs=bs+x/(1.0-x)
  if nap*nbs > ans
    ans=nap*nbs
    ap,bs=nap,nbs
  end
end
puts ans


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

def gi(); gets.to_i; end
def gis(); gets.chomp.split.map(&:to_i); end

m = gis
w = gis
h = gis

score = (1..5).map{|x| x*500}.zip(m,w).map{|xi,mi,wi|
    [300 * xi,  (1000 - 4 * mi) * xi - 50000 * wi].max
}.inject(:+) + 100000 * h[0] - 50000 * h[1]

puts score.div(1000)

xx = [500, 1000, 1500, 2000, 2500]
mm = gets.chomp.split(" ").map(&:to_f)
ww = gets.chomp.split(" ").map(&:to_f)
hs, hu = gets.chomp.split(" ").map(&:to_i)
calc_score = ->(x, m, w) {
  (250 - m) * x / 250 - 50 * w
}
scores = Array.new
(0...5).each do |i|
  scores << [0.3*xx[i], calc_score.call(xx[i], mm[i], ww[i])].max
end
puts (scores.inject(:+) + hs * 100 - hu * 50).to_i

maxpoint=[]
0.upto(4) do |i|
	maxpoint[i]=(i+1)*500
end
time=gets.chomp.split(" ")
0.upto(4) do |i|
	time[i]=time[i].to_i
end
wrong=gets.chomp.split(" ")
0.upto(4) do |i|
	wrong[i]=wrong[i].to_i
end
hack=gets.chomp.split(" ")
0.upto(1) do |i|
	hack[i]=hack[i].to_i
end
point=[]
0.upto(4) do |i|
	point[i]=((1.0-time[i]/250.0)*maxpoint[i])-(50*wrong[i])
	if point[i]< (0.3*maxpoint[i])
		point[i]=0.3*maxpoint[i]
	end
end
point=point.inject{|memo,n| memo+n }
point=point+(100*hack[0])-(50*hack[1])
puts point.to_i

max_marks = [500, 1000, 1500, 2000, 2500]
solution_times = $stdin.readline.split.map(&:to_i)
nums_wrong_attempts = $stdin.readline.split.map(&:to_i)
good_cracks, bad_cracks = $stdin.readline.split.map(&:to_i)

score = max_marks.zip(solution_times, nums_wrong_attempts).map{|max_mark, solution_time, num_wrong_attempts|
  [3.quo(10)*max_mark, (1 - solution_time.quo(250) ) * max_mark - 50 * num_wrong_attempts].max
}.inject(0, &:+)

puts (score + good_cracks * 100 - bad_cracks * 50).to_i

class Solver
	def main
		max_score = [500, 1000, 1500, 2000, 2500]
		last_submission_time = gets.split.map { |x| x.to_i }
		wrong_submissions = gets.split.map { |x| x.to_i }
		successful_hacks, unsuccessful_hacks = gets.split.map { |x| x.to_i }

		problem_score = Array.new(5, 0)
		0.upto(5 - 1) do |i|
			lhs = max_score[i] * 3 / 10
			rhs = max_score[i] - max_score[i] / 250 * last_submission_time[i] \
				- wrong_submissions[i] * 50
			problem_score[i] = [lhs, rhs].max
		end

		total_score = problem_score.reduce(:+)
		total_score += successful_hacks * 100
		total_score -= unsuccessful_hacks * 50
		puts total_score
	end
end

Solver.new.main

minutes = gets.chomp.split.map(&:to_f)
wrongs = gets.chomp.split.map(&:to_f)
s, f = gets.chomp.split.map(&:to_i)
points = [500, 1000, 1500, 2000, 2500]

score = 0
(0..4).each do |idx|
  score += [
    0.3 * points[idx],
    (1 - minutes[idx] / 250.0) * points[idx] - 50 * wrongs[idx]
  ].max
end
score += s * 100 - f * 50
puts score.to_i

minutes=[]
mins=gets.chomp.split
mins.each do |i|
	minutes.push(i.to_i)
end

hacked=[]
haks=gets.chomp.split
haks.each do |i|
	hacked.push(i.to_i)
end

success=[]
sucs=gets.chomp.split
sucs.each do |i|
	success.push(i.to_i)
end

sum=0

a1=(250-minutes[0])*2-hacked[0]*50
b1=3*50
if a1>b1
	sum+=a1
else
	sum+=b1
end

a2=(250-minutes[1])*4-hacked[1]*50
b2=3*100
if a2>b2
	sum+=a2
else
	sum+=b2
end

a3=(250-minutes[2])*6-hacked[2]*50
b3=3*150
if a3>b3
	sum+=a3
else
	sum+=b3
end

a4=(250-minutes[3])*8-hacked[3]*50
b4=3*200
if a4>b4
	sum+=a4
else
	sum+=b4
end

a5=(250-minutes[4])*10-hacked[4]*50
b5=3*250
if a5>b5
	sum+=a5
else
	sum+=b5
end

sum=sum-success[1]*50+success[0]*100

puts sum

m = []
w = []
h = []
m = gets.split.map(&:to_i)
w = gets.split.map(&:to_i)
h = gets.split.map(&:to_i)

tmp = 0
5.times do |v|
    ms = 500*(v+1)
    ma = 0.3*ms
    mt = (1-m[v]/250.0)*ms - 50*w[v]
    if ma < mt
        tmp += mt
    else
        tmp += ma
    end
end
tmp += (100*h[0] - 50*h[1])
puts tmp.to_i

m = gets.split.to_a.map(&:to_f)
w = gets.split.to_a.map(&:to_f)
hs, hu = gets.split.map(&:to_f)
x=[500,1000,1500,2000,2500]
result = 0
for i in 0..4
	if(0.3*x[i]>(1-m[i]/250)*x[i]-50*w[i])
		result+= 0.3*x[i]
	else
			result+= (1-m[i]/250)*x[i]-50*w[i]
	end
end
 result+=hs*100-hu*50
 p result.to_i

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

def gi(); gets.to_i; end
def gis(); gets.chomp.split.map(&:to_i); end

m = gis
w = gis
h = gis

score = (1..5).map{|x| x*500}.zip(m,w).map{|xi,mi,wi| [0.3 * xi,  (1.0 - mi / 250.0) * xi - 50.0 * wi].max}.inject(:+) + 100 * h[0] + 50 * h[1]

puts score.floor

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

def gi(); gets.to_i; end
def gis(); gets.chomp.split.map(&:to_i); end

m = gis
w = gis
h = gis

score = (1..5).map{|x| x*500}.zip(m,w).map{|xi,mi,wi|
    [300 * xi,  (1000 - 4 * mi) * xi - 500 * wi].max
}.inject(:+) + 100000 * h[0] + 50000 * h[1]

puts score.div(1000)

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

def gi(); gets.to_i; end
def gis(); gets.chomp.split.map(&:to_i); end

m = gis
w = gis
h = gis

score = (1..5).map{|x| x*500}.zip(m,w).map{|xi,mi,wi|
    [300 * xi,  (1000 - 4 * mi) * xi - 50000 * wi].max
}.inject(:+) + 100000 * h[0] + 50000 * h[1]

puts score.div(1000)

maxpoint=[]
0.upto(4) do |i|
	maxpoint[i]=(i+1)*500
end
time=gets.chomp.split(" ")
0.upto(4) do |i|
	time[i]=time[i].to_i
end
wrong=gets.chomp.split(" ")
0.upto(4) do |i|
	wrong[i]=wrong[i].to_i
end
hack=gets.chomp.split(" ")
0.upto(1) do |i|
	hack[i]=hack[i].to_i
end
point=[]
0.upto(4) do |i|
	point[i]=((1.0-time[i]/250.0)*maxpoint[i])-(50*wrong[i])
	if point[i]< (0.3*maxpoint[i])
		point[i]=0.3*maxpoint[i]
	end
end
point1=point.inject{|memo,n| memo+n }
point1=point1+(100*hack[0])-(50*hack[1])

minutes=[]
mins=gets.chomp.split
mins.each do |i|
	minutes.push(i.to_i)
end

hacked=[]
haks=gets.chomp.split
haks.each do |i|
	hacked.push(i.to_i)
end

success=[]
sucs=gets.chomp.split
sucs.each do |i|
	success.push(i.to_i)
end

sum=(((250-minutes[0]).to_f/250)*500+((250-minutes[1]).to_f/250)*1000+((250-minutes[2]).to_f/250)*1500+(1-(minutes[3]).to_f/250)*2000+(1-(minutes[4]).to_f/250)*2500-(hacked[4]+hacked[3]+hacked[2]+hacked[1]+hacked[0])*50+success[0]*100-success[1]*50).to_i
puts sum

xx = [500, 1000, 1500, 2000, 2500]
mm = gets.chomp.split(" ").map(&:to_i)
ww = gets.chomp.split(" ").map(&:to_i)
hs, hu = gets.chomp.split(" ").map(&:to_i)
calc_score = ->(x, m, w) {
  (250 - m) * x / 250 - 50 * w
}
scores = Array.new
(0...5).each do |i|
  scores << [0.3*xx[i], calc_score.call(xx[i], mm[i], ww[i])].max
end
puts scores.inject(:+) + hs * 100 - hu * 50


n, m, k = gets.split.map {|x| Integer x}
a = Array.new(n)
for i in 0...n
  a[i] = Array.new
  s = gets.split.map {|x| (Integer x) - 1}
  for j in 0...m
    a[i][j] = s[j]
  end
end
bad_cell = [false] * k
bad_core = [false] * n
prev = [nil] * k
time = [0] * n
for t in 0...m
  used = [false] * k
  for c in 0...n
    if bad_core[c] or a[c][t] == -1
      next
    end
    if bad_cell[a[c][t]] or used[a[c][t]]
      bad_cell[a[c][t]] = true
      bad_core[c] = true
      if time[c] == 0
        time[c] = t + 1
      end
      bad_core[prev[a[c][t]]] = true
      if time[prev[a[c][t]]] == 0
        time[prev[a[c][t]]] = t + 1
      end
    end
    used[a[c][t]] = true
    prev[a[c][t]] = c
  end
end
puts time

#!/usr/bin/env ruby

# n - cores
# m - ticks
# k - shared cache memory

input = STDIN.read.split("\n")
n, m, k = *input[0].split(' ').map(&:to_i)
commands = input[1..-1].map{|s| s.split(' ').map(&:to_i) }

cores = Array.new n, 0
blocked_cells = []

define_method(:working_cores) do
  cores.map.with_index{|c,i| c == 0 ? i : nil }.compact
end

1.upto(m).each do |tick|
  working_cores.
    map { |core| commands[core][tick - 1] }.
    compact.
    group_by(&:to_i).
    select{|_,xs| xs.count > 1 }.
    keys.
    reject{|c| c == 0 }.
    reject{|c| blocked_cells.include?(c) }.
    each { |cell| blocked_cells += [cell] }

    cores.map.with_index do |s,i|
      next if s > 0
      cores[i] = tick if blocked_cells.include?(commands[i][tick - 1])
    end
end

cores.each do |core|
  puts core
end

input = STDIN.read.split("\n")
n, m, k = *input[0].split(' ').map(&:to_i)
commands = input[1..-1].map{|s| s.split(' ').map(&:to_i) }

cores = Array.new n, 0
blocked_cells = []

define_method(:working_cores) do
  cores.map.with_index{|c,i| c == 0 ? i : nil }.compact
end

1.upto(m).each do |tick|
  working_cores.
    map { |core| commands[core][tick - 1] }.
    compact.
    group_by(&:to_i).
    select{|_,xs| xs.count > 1 }.
    keys.
    reject{|c| c == 0 }.
    reject{|c| blocked_cells.include?(c) }.
    each { |cell| blocked_cells += [cell] }

    cores.map.with_index do |s,i|
      next if s > 0
      cores[i] = tick if blocked_cells.include?(commands[i][tick - 1])
    end
end

puts cores

n, m, k = gets.split.map &:to_i
a = Array.new
n.times do |i|
	a[i] = gets.split.map { |x| x.to_i - 1 }
end
lock = Array.new(n) { 0 }
lockcell = Array.new(k) { false }
0.upto(m - 1) do |i|
	turn = Array.new(k) { -1 }
	0.upto(n - 1) do |j|
		if lock[j] == 0 && a[j][i] != -1
			if lockcell[a[j][i]]
				lock[j] = i + 1
			elsif turn[a[j][i]] != -1
				lock[turn[a[j][i]]] = lock[j] = i + 1
				lockcell[a[j][i]] = true
			end
			turn[a[j][i]] = j
		end
	end
end
puts lock

#!/usr/bin/env ruby

# n - cores
# m - ticks
# k - shared cache memory

input = STDIN.read.split("\n")
n, m, k = *input[0].split(' ').map(&:to_i)
commands = input[1..-1].map{|s| s.split(' ').map(&:to_i) }

cores = Array.new n, 0
blocked_cells = []

define_method(:working_cores) do
  cores.map.with_index{|c,i| c == 0 ? i : nil }.compact
end

1.upto(m).each do |tick|
  working_cores.
    map { |core| commands[core][tick - 1] }.
    compact.
    group_by(&:to_i).
    select{|_,xs| xs.count > 1 }.
    keys.
    reject{|c| blocked_cells.include?(c) }.
    each { |cell| blocked_cells += [cell] }

    cores.map.with_index do |s,i|
      next if s > 0
      cores[i] = tick if blocked_cells.include?(commands[i][tick - 1])
    end
end

cores.each do |core|
  puts core
end


gets.to_i.times {
  a, b = gets.split.map { |v| v.to_i }
  s = a * b
  puts s / 2 + s % 2
}

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

  puts n.div(2)*m + n.modulo(2)*m.div(2) + n.modulo(2)*m.modulo(2)
end

t = gets.chomp.to_i
t.times do |testcase|
  (n,m) = gets.split.map(&:to_i)
  puts (n*m+1)/2
end

t = gets.to_i

1.upto t do |i|
  n, m = gets.split.map(&:to_i)
  puts ((n * m) / 2 + (n * m) % 2)
end


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

line=gets.strip
hs=Hash.new(0)

line.each_char{|c|
	hs[c.ord]+=1
}

ans=0
hs.values.each{|v|
	ans+=v**2
}

puts ans

counter = Hash.new(0)
STDIN.read.gsub("\n", "").split("").each { |symbol| counter[symbol] += 1 }
puts counter.values.inject(0) { |res, count| res + count ** 2}

s = gets.chomp!

mas = Hash.new()
s.chars { |c|
  mas[c] == nil ? mas[c] = 1 : mas[c] += 1
}

sum = 0
mas.each_value {|d|
  sum += d**2
}

puts sum


def to_num(s)
    a = s.split(/\./)

    n = a.length
    if n == 1
        return s.to_i * 100
    end

    if a[n-1].length == 2
        return a[0..n-2].join('').to_i * 100 + a[n-1].to_i
    end

    a.join('').to_i * 100
end

def to_str(x)
    rem = x % 100
    ret = rem == 0 ? '' : ".%02d" % (x % 100)

    s = (x / 100).to_s
    i = s.length - 1

    while i >= 0 do
        j = i - 2
        if j < 0
            j = 0
        end
        ret = '.' + s[j..i] + ret
        i = j - 1
    end

    ret[1..-1]
end

a = STDIN.gets.gsub(/[a-z]/,' ').split.map { |s| to_num(s) }
sum = a.inject(&:+)
puts to_str(sum)

def parse(s)
  bias = 1
  if s.length <= 3 || s[-4] == '.'
    bias = 100
  end
  s.gsub!(/\./, "")
  bias * s.to_i
end

def enchant(n)
  s = ""
  if n % 100 != 0
    s = format(".%02d", n % 100)
  end
  n /= 100
  n = n.to_s
  nz = n.length
  for i in 0 .. nz - 1
    s = n[nz - 1 - i] + s
    if i < nz - 1 && i % 3 == 2
      s = "." + s
    end
  end
  s
end

s = gets.chomp
s = s.split(/[a-z]+/).select{|v| v != ""}
tot = 0
for v in s
  tot += parse(v)
end

puts enchant(tot)

def to_num(s)
    a = s.split(/\./)

    n = a.length
    if n == 1
        return s.to_f
    end

    if a[n-1].length == 2
        x = a[0..n-2].join('') + '.' + a[n-1]
        return x.to_f
    end

    a.join('').to_f
end

def to_str(x)
    x = x.round(2)
    if x.to_s == x.to_i.to_s
        return x.to_i.to_s
    end
    a = x.to_s.split(/\./)
    s = a[0]
    ret = ".#{a[1]}"

    i = s.length - 1
    while i >= 0 do
        j = i - 2
        if j < 0
            j = 0
        end
        ret = '.' + s[j..i] + ret
        i = j - 1
    end

    ret[1..-1]
end

a = STDIN.gets.gsub(/[a-z]/,' ').split.map { |s| to_num(s) }
sum = a.inject(&:+)
puts to_str(sum)

def to_num(s)
    a = s.split(/\./)

    n = a.length
    if n == 1
        return s.to_i * 100
    end

    if a[n-1].length == 2
        return a[0..n-2].join('').to_i * 100 + a[n-1].to_i
    end

    a.join('').to_i * 100
end

def to_str(x)
    if x % 100 == 0
        return (x / 100).to_s
    end

    s = (x / 100).to_s
    ret = ".%02d" % (x % 100)

    i = s.length - 1
    while i >= 0 do
        j = i - 2
        if j < 0
            j = 0
        end
        ret = '.' + s[j..i] + ret
        i = j - 1
    end

    ret[1..-1]
end

a = STDIN.gets.gsub(/[a-z]/,' ').split.map { |s| to_num(s) }
sum = a.inject(&:+)
puts to_str(sum)

def parse(s)
  bias = 1
  if s.length <= 3 || s[-4] == '.'
    bias = 100
  end
  s.gsub!(/\./, "")
  bias * s.to_i
end

def enchant(n)
  s = ""
  if n % 100 != 0
    s = format(".%02d", n % 100)
  end
  n /= 100
  n = n.to_s
  nz = n.length
  for i in 0 .. nz - 1
    s = n[nz - 1 - i] + s
    if i < nz - 1 && i % 3 == 2
      s = "." + s
    end
  end
  s
end

s = gets.chomp
s = s.split(/[a-z]+/).select{|v| v != ""}
p s
tot = 0
for v in s
  tot += parse(v)
end

puts enchant(tot)


def debug(*arg)
  puts "[DEBUG] #{arg.join " "}"
end

t = gets.to_i

t.times do
  a, b, c = gets.split.map(&:to_i)

  if a == (b-c).abs + c
    puts 3
  elsif a < (b-c).abs + c
    puts 1
  else
    puts 2
  end
end

n = { 1 => 1, 2 => 3, 3 => 2 }
$stdin.each_line.with_index do |x, i|
    next if i == 0
    a, b, c = x.split(" ").map(&:to_i)
    t1 = a - 1
    t2 = (b - c).abs + (c - 1)
    puts n[(t1 <=> t2) + 2]
end

t=gets.to_i
for t0 in (0...t)
  m=gets.split(' ').to_a
  a=m[0].to_i
  b=m[1].to_i
  c=m[2].to_i
  r=(b-c).abs+c
  puts 1 if a<r
  puts 2 if a>r
  puts 3 if a==r
end

$stdin.readline

map = { -1 => 1, 0 => 3, 1 => 2}

$stdin.each_line do |line|
    a, b, c = line.chomp.split.map(&:to_i)
    puts map[(a - c <=> (c - b).abs)]
end

def solve(a, b, c)
  first_dis = (a - 1).abs
  second_dis = (b - c).abs + (c - 1).abs
  if first_dis == second_dis
    p 3
  elsif first_dis < second_dis
    p 1
  else
    p 2
  end
end

t = gets.chomp.to_i

for i in 1..t
  a, b, c = gets.chomp.split(' ').map(&:to_i)
  solve(a,b,c)
end

def check_elevator(a,b,c)
  comp=((c-b).abs+c)-a
  if comp>0
    1
  elsif comp==0
    3
  else
    2
  end
end

n_rounds=gets.to_i

n_rounds.times do
  puts check_elevator(*(gets.split(' ').map(&:to_i)))
end

t = gets.chomp.to_i
tab = []
for i in 1..t

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

    if ( (a-1).abs ) < ((b-c).abs + (c-1).abs)
        tab.push(1)
    elsif ( (a-1).abs ) > ((b-c).abs + (c-1).abs)
        tab.push(2)
    else
        tab.push(3)
    end
end

for i in tab
    puts "#{i}"
end

c = Hash.new(nil)
$stdin.each_line.with_index do |l, i| next if i == 0 || i % 2 == 1
    puts c[l] if c[l] != nil
    nt = 0
    o = ""
    l.chomp.each_char.with_index do |x, i|
        if nt != 0
            nt -= 1
            next
        end
        if (i < (l.chomp.length - 2)) && (l[i + 2] == "0") && (i > l.chomp.length - 4 || l[i + 3] != "0")
            nt = 2
            o += ("a".."z").to_a[(x + l[i + 1]).to_i - 1]
            next
        end
        o += ("a".."z").to_a[x.to_i - 1]
    end
    c[l]=o
    puts o
end

def debug(*arg)
  puts "[DEBUG] #{arg.join " "}"
end

t = gets.to_i

t.times do
  a, b, c = gets.split.map(&:to_i)

  # debug(a, b + c -b)
  if a == b + c - b + 1
    puts 3
  elsif a < b + c - b + 1
    puts 1
  else
    puts 2
  end
end