#!/usr/bin/ruby

def gcd(a, b)
	return (b != 0) ? gcd(b, a % b) : a
end

gets
gets.split.map(&:to_i).each do |n|
	puts (n * 4) / gcd(n * 4, n + 1) + 1
end

t = gets.to_i
array = gets.split.map(&:to_i)
array.each do |n|
  if n % 4 == 3
    puts n+1
  elsif n % 4 == 1
    puts 2*n+1
  else
    puts 4*n+1
  end
end

#!/usr/bin/ruby

t = $stdin.gets.to_i
ns = $stdin.gets.split.map(&:to_i)
ns.each do |n|
  g = (n+1).gcd(4*n)
  puts (4*n/g)+1
end

gets;gets.split.map{ |v| v=v.to_i; if v.even?; 4*v+1; else if (v+1)%4>0; 2*v+2*v/(v+1); else; v+1; end; end; }.map{ |v| p v }

#!/usr/bin/ruby

def gcd(a, b)
	return (b != 0) ? gcd(b, a % b) : a
end

def solve(n)
	puts (n * 4) / gcd(n * 4, n + 1) + 1
end

gets
gets.split.map(&:to_i).map{ |n| solve(n) }

gets
gets.split.map { |x| x.to_i } . map { |x| x*4 / (x*4).gcd(x+1) } . each { |x| puts x+1}

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

for i in input
  if i%2 == 0 then puts i*4+1
  else
    if i%4 == 1
      puts i*2+1
    else
      puts i+1
    end
  end
end

def NOD(x, y)
    if x!=0
        return NOD((y%x),x)
    else
        return y
    end
end

def NOK(x,y)
    return (x*y)/NOD(x,y)
end

total = gets.chomp.to_i
line= gets.chomp
numbers=line.split(" ", total)
numbers.each do |number|
    number=number.chomp.to_i
    number=number+1
    mod=4*number-4
    puts NOK(mod, number)/number+1
end

"""(c) gorlum0 [at] gmail.com"""

def solve(n)
  g = (4*n).gcd(n+1)
  4*n / g + 1
end

t = STDIN.gets.to_i
ns = STDIN.gets.split.map(&:to_i)
ns.each do |n|
  puts solve(n)
end

"""(c) gorlum0 [at] gmail.com"""

def solve(n)
  g = (4*n).gcd(n+1)
  4*n / g + 1
end

def main
t = gets.to_i
ns = gets.split.map(&:to_i)
ns.each do |n|
  puts solve(n)
end
end

main

"""(c) gorlum0 [at] gmail.com"""

def solve(n)
  g = (4*n).gcd(n+1)
  4*n / g + 1
end

def main
  t = gets.to_i
  ns = gets.split.map(&:to_i)
  ns.each do |n|
    puts solve(n)
  end
end

if __FILE__ == $0
  main
end

"""(c) gorlum0 [at] gmail.com"""

def solve(n)
  g = (4*n).gcd(n+1)
  4*n / g + 1
end

t = gets.to_i
ns = gets.split.map(&:to_i)
ns.each do |n|
  puts solve(n)
end

t = gets.to_i
a = gets.split(" ").map(&:to_i)
a.each do |i|
    j = (i+1).gcd(4*i)
    p (4*i/j)+1
end

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

for i in input
  if i%2 == 0 then puts i*2+1
  else
    if i == 1
      puts 2
    elsif i%4 == 1
      puts i*2+1
    else
      puts i+1
    end
  end
end

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

for i in input
  if i%2 == 0 then puts i*4+1
  else
    if i == 1
      puts 2
    elsif i%4 == 1
      puts i*2+1
    else
      puts i+1
    end
  end
end

t = gets.to_i
array = gets.split.map(&:to_i)
array.each do |n|
  a = 4 * n
  b = n + 1
  c = 0
  count = 0
  while c != 0
    c = a - b
    if c < 0
      c = a + c
    end
    count += 1
  end
  puts count
end

t = gets.to_i
array = gets.split.map(&:to_i)
array.each do |n|
  if n == 1
    puts 3
  elsif n == 3
    puts 4
  else
    puts n * 4 + 1
  end
end

t = gets.to_i
array = gets.split.map(&:to_i)
array.each do |n|
  puts n * 4 + 1
end

t = gets.to_i
array = gets.split.map(&:to_i)
array.each do |n|
  if n == 1
    puts 3
  else
    puts n * 4 + 1
  end
end

t = gets.to_i
array = gets.split.map(&:to_i)
array.each do |n|
  if n == 1
    puts 2
  else
    puts n * 4 + 1
  end
end

t = gets.to_i
array = gets.split.map(&:to_i)
a = 0
array.each do |n|
  a += 1
  print n * 4 + 1
  if a != t
    print "\n"
  end
end

gets
gets.split.map { |x| x.to_i } . map { |x| x*4 / x.gcd(x+1) } . each { |x| puts x+1}


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

r_sum = a.reverse.each_with_object([0]) { |i, a| a << a.last + i }.reverse

l_sum = Hash.new { 0 }

sum = 0
result = 0

a.each_with_index do |a, i|
  sum = sum + a
  l_sum[sum] += 1

  next if i.zero? || i == (n - 1)

  result += l_sum[sum/2] - (sum.zero? ? 1 : 0) if r_sum[i+1]*2 == sum && sum.even?
end

puts result

#
# E - Number of Ways
#

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

s = a.reduce(:+)

if (s % 3 != 0)
  puts 0
else

  count = (1..10000000).map { |i| 0 }

  s /= 3
  sub_sum = 0

  (n - 1).downto(0) do |i|
    sub_sum += a[i]
    count[i] = 1 if sub_sum == s
  end

  (n - 2).downto(0) do |i|
    count[i] += count[i + 1]
  end

  answer = 0
  sub_sum = 0
  i = 0

  loop do
    break if i + 2 >= n

    sub_sum += a[i]
    answer += count[i + 2] if sub_sum == s
    i += 1
  end

  puts answer
end

#!/usr/bin/ruby

n = STDIN.readline.to_i
arr = STDIN.readline.split.map {|s| s.to_i }

total = arr.reduce(:+)
if total%3 != 0
	puts 0
	exit
end
target = total / 3

sums = [0]
sum = 0
arr.each {|x| sums.push(sum += x) }

low, result = 0, 0
(1..n-2).each do |i|
	low += 1 if sums[i] == target
	result += low if total - sums[i+1] == target
end
puts result

n = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)
sum = 0
a.each { |x| sum += x }
if sum % 3 != 0
  puts 0
  exit
end
sum /= 3
ans, cnt, psum = 0, 0, 0
for x in 0...n-1 do
  psum += a[x]
  ans += cnt if psum == 2 * sum
  cnt += 1   if psum == sum
end
puts ans

n=gets.to_i
x=gets.split.map{|e| e.to_i}
s1=x.inject(0){|sum1,e|
	sum1+e
}
if s1%3!=0 || n<3 then
	puts 0
else
	s3=s1/3
	sum=0
	arr=[]
	i=0
	x.each{|e|
		sum=sum+e
		if s3==sum then
			arr<<i
		end
		i=i+1
	}
	arr2=[]
	x.reverse!
	i=x.size-1
	sum=0
	x.each{|e|
		sum=sum+e
		if s3==sum then
			arr2<<i
		end
		i=i-1
	}
	arr2.reverse!
	ans=0
	while !arr.empty? && !arr2.empty?
		if arr2[0]<=arr[0]+1 then
			arr2.shift
		else
			ans+=arr2.size
			arr.shift
		end
	end
	puts ans
end

# coding: utf-8

# if __FILE__ == $0
# end

n = gets.to_i
acc = 0
ar = []
gets.split.each { |i|
    i = i.to_i
    acc += i
    ar << acc
}

# p ar

# ar.last 는 반드시 3의 배수이다.
# 각 부분의 합을 p, q, r 이라고 할 때, p + q + r = 3n
# p = 3a, q = 3b, r = 3c 라고 할 때
# p + q + r = 3*(a + b+ c) = 3n 이고, 3으로 양변을 나누면
# a + b + c = n 이때 a, b, c, n 은 모두 정수이다.
# 만약 p q r 중 하나가 3의 배수가 아니라면 합이 정수가 되지 못한다.
# 그리고 균등하게 분할해야하므로 p = q = r, 3a = 3b = 3c, a = b = c이다.

if ar.last % 3 != 0
    puts "0"
else
    partsum = ar.last/3
    dpartsum = partsum * 2
    partsum_counter = 0

    combinations = 0
    ar[0...(n-1)].each { |i|
        if dpartsum == i
            combinations += partsum_counter
        end

        if partsum == i
            partsum_counter += 1
        end
    }

    puts combinations
end

n = gets.to_i
arr = gets.split(" ").map(&:to_i)
# sum = [0]
# arr.each do |a|
# 	sum << a + sum[-1]
# end
# sum.shift
# count = 0
# (0...(n-2)).each do |i|
# 	((i + 1)...(n-1)).each do |j|
# 		if (sum[i] == (sum[j] - sum[i])) && (sum[i] == (sum[-1] - sum[j] ))
# 			# puts "#{i} #{j}"
# 			count += 1
# 		end
# 	end
# end
# # puts "#{sum}"
# puts "#{count}"
sum = arr.inject(0,:+)
if sum % 3 != 0
	puts 0
else
	sum /= 3
	s = 0
	count = 0
	current_ways = 0
	arr[0..(n-2)].each do |a|
		s += a

		count += current_ways if s == 2 * sum
		current_ways += 1 if s == sum
	end
	puts count
end

elements = gets.to_i
arr = gets.split(" ").map(&:to_i)

sum, answer, count, temp_sum = 0, 0, 0, 0

arr.each { |e| sum = sum + e }

if sum % 3 == 0
  sum = sum / 3
  for i in 0...(elements - 1)
    temp_sum = temp_sum + arr[i]
    answer = answer + count if temp_sum == 2 * sum
    count = count + 1 if temp_sum == sum
  end

end

puts answer

n = gets.to_i
a = gets.split.map(&:to_i)
a_sum = [a[0]]
(n - 1).times.each{|i| a_sum[i + 1] = a_sum[i] + a[i + 1]}
goal = a_sum[n - 1] == 0 ? 0 : a_sum[n - 1] / 3
an = [nil, 0, 0]
ind = 1
ans = 0
n.times do |i|
  if ind == 1 && a_sum[i] == goal && a_sum[i] == goal * 2
    an[1] += 1
    an[2] += 1
  elsif ind == 1 && a_sum[i] == goal
    an[1] += 1
  elsif ind == 2 && a_sum[i] == goal
    ans += an[1] * an[2]
    ind = 1
    an[1] = 1
  elsif a_sum[i] == goal * 2
    ind = 2
    an[2] += 1
  end
  if i == n - 1 && ind == 2
    ans += an[1] * an[2]
  end
end
if ans == 0 && (an[1] < 1 || an[2] < 1) || (goal == 0 && an[1] < 3) || goal * 3 != a_sum[n - 1]
  puts 0
elsif goal == 0
  puts (an[1] - 1) * (an[1] - 2) / 2
else
  puts ans
end

#
# E - Number of Ways
#

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

s = a.reduce(:+)

if (s % 3 != 0)
  puts 0
else

  s /= 3
  count = 0
  ans = 0
  sub_sum = 0

  for i in (0..n-1)
    sub_sum += a[i]

    count += 1 if sub_sum == s
    ans += count if sub_sum == 2 * s
  end

  puts ans
end

# coding: utf-8

# if __FILE__ == $0
# end

n = gets.to_i
acc = 0
ar = []
gets.split.each { |i|
    i = i.to_i
    acc += i
    ar << acc
}

# p ar

# ar.last 는 반드시 3의 배수이다.
# 각 부분의 합을 p, q, r 이라고 할 때, p + q + r = 3n
# p = 3a, q = 3b, r = 3c 라고 할 때
# p + q + r = 3*(a + b+ c) = 3n 이고, 3으로 양변을 나누면
# a + b + c = n 이때 a, b, c, n 은 모두 정수이다.
# 만약 p q r 중 하나가 3의 배수가 아니라면 합이 정수가 되지 못한다.
# 그리고 균등하게 분할해야하므로 p = q = r, 3a = 3b = 3c, a = b = c이다.

if ar.last % 3 != 0
    puts "0"
else
    partsum = ar.last/3
    dpartsum = partsum * 2
    partsum_counter = 0

    combinations = 0
    ar[1...(n-1)].each { |i|
        if partsum == i
            partsum_counter += 1
        end

        if dpartsum == i &&
            combinations += partsum_counter
        end
    }

    puts combinations
end

# coding: utf-8

# if __FILE__ == $0
# end

n = gets.to_i
acc = 0
ar = []
gets.split.each { |i|
    i = i.to_i
    acc += i
    ar << acc
}

# p ar

# ar.last 는 반드시 3의 배수이다.
# 각 부분의 합을 p, q, r 이라고 할 때, p + q + r = 3n
# p = 3a, q = 3b, r = 3c 라고 할 때
# p + q + r = 3*(a + b+ c) = 3n 이고, 3으로 양변을 나누면
# a + b + c = n 이때 a, b, c, n 은 모두 정수이다.
# 만약 p q r 중 하나가 3의 배수가 아니라면 합이 정수가 되지 못한다.
# 그리고 균등하게 분할해야하므로 p = q = r, 3a = 3b = 3c, a = b = c이다.

if ar.last % 3 != 0
    puts "0"
else
    partsum = ar.last/3
    dpartsum = partsum * 2
    partsum_counter = 0

    combinations = 0
    ar[1...n].each { |i|
        if dpartsum == i
            combinations += partsum_counter
        end

        if partsum == i
            partsum_counter += 1
        end
    }

    puts combinations
end

# coding: utf-8

# if __FILE__ == $0
# end

n = gets.to_i
acc = 0
ar = []
arr = gets.split.each { |i|
    i = i.to_i
    acc += i
    ar << acc
}

# ar.last 는 반드시 3의 배수이다.
# 각 부분의 합을 p, q, r 이라고 할 때, p + q + r = 3n
# p = 3a, q = 3b, r = 3c 라고 할 때
# p + q + r = 3*(a + b+ c) = 3n 이고, 3으로 양변을 나누면
# a + b + c = n 이때 a, b, c, n 은 모두 정수이다.
# 만약 p q r 중 하나가 3의 배수가 아니라면 합이 정수가 되지 못한다.
# 그리고 균등하게 분할해야하므로 p = q = r, 3a = 3b = 3c, a = b = c이다.

if ar.last % 3 != 0
    puts "0"
else
    partsum = ar.last/3
    dpartsum = partsum * 2
    partsum_counter = 0

    combinations = 0
    ar.each { |i|
        if dpartsum == i
            combinations += partsum_counter
        end

        if partsum == i
            partsum_counter += 1
        end
    }

    puts combinations
end

elements = gets.to_i
arr = gets.split(" ").map(&:to_i)

sum, answer, count, psum = 0, 0, 0, 0

arr.each { |e| sum = sum + e }

unless sum % 3 != 0
  sum = sum / 3

  for i in 0...elements do
    psum = psum + arr[i]
    answer = answer + count if psum == 2 * sum
    count = count + 1 if psum == sum
  end

end

puts answer

n = gets.to_i
a = gets.split.map(&:to_i)
a_sum = [a[0]]
(n - 1).times.each{|i| a_sum[i + 1] = a_sum[i] + a[i + 1]}
goal = a_sum[n - 1] == 0 ? 0 : a_sum[n - 1] / 3
if goal * 3 != a_sum[n - 1]
  puts 0
else
  a1 = a_sum.count(goal)
  a2 = a_sum.count(goal * 2)
  puts a1 == a2 ? (a1 - 1) * (a1 - 2) / 2 : a1 * a2
end

n = gets.to_i
a = gets.split.map(&:to_i)
a_sum = [a[0]]
(n - 1).times.each{|i| a_sum[i + 1] = a_sum[i] + a[i + 1]}
goal = a_sum[n - 1] == 0 ? 0 : a_sum[n - 1] / 3
a1 = a_sum.count(goal)
a2 = a_sum.count(goal * 2)
if (a1 < 1 || a2 < 1) || goal * 3 != a_sum[n - 1]
  puts 0
else
  puts goal == goal * 2 ? (a1 - 1) * (a1 - 2) / 2 : a1 * a2
end

n = gets.to_i
a = gets.split.map(&:to_i)
a_sum = [a[0]]
(n - 1).times.each{|i| a_sum[i + 1] = a_sum[i] + a[i + 1]}
goal = a_sum[n - 1] == 0 ? 0 : a_sum[n - 1] / 3
an = [nil, 0, 0]
ind = 1
n.times do |i|
  if ind == 1 && a_sum[i] == goal && a_sum[i] == goal * 2
    an[1] += 1
    an[2] += 1
  elsif ind == 1 && a_sum[i] == goal
    an[1] += 1
  elsif a_sum[i] == goal * 2
    ind = 2
    an[2] += 1
  end
end
if (an[1] < 1 || an[2] < 1) || (goal == 0 && an[1] < 3) || goal * 3 != a_sum[n - 1]
  puts 0
elsif goal == 0
  puts (an[1] - 1) * (an[1] - 2) / 2
else
  puts an[1] * an[2]
end

n = gets.to_i
a = gets.split.map(&:to_i)
a_sum = [a[0]]
(n - 1).times.each{|i| a_sum[i + 1] = a_sum[i] + a[i + 1]}
goal = a_sum[n - 1] == 0 ? 0 : a_sum[n - 1] / 3
a1 = a_sum.count(goal)
a2 = a_sum.count(goal * 2)
if (a1 < 1 || a2 < 1) || goal * 3 != a_sum[n - 1]
  puts 0
else
  puts a1 == a2 ? (a1 - 1) * (a1 - 2) / 2 : a1 * a2
end

n = gets.to_i
a = gets.split.map(&:to_i)
a_sum = [a[0]]
(n - 1).times.each{|i| a_sum[i + 1] = a_sum[i] + a[i + 1]}
goal = a_sum[n - 1] == 0 ? 0 : a_sum[n - 1] / 3
an = [nil, 0, 0]
ind = 1
ans = 0
n.times do |i|
  if ind == 1 && a_sum[i] == goal && a_sum[i] == goal * 2
    an[1] += 1
    an[2] += 1
  elsif ind == 1 && a_sum[i] == goal
    an[1] += 1
  elsif ind == 2 && a_sum[i] == goal
    ans += an[1] * an[2]
    ind = 1
    an[1] = 1
  elsif a_sum[i] == goal * 2
    ind = 2
    an[2] += 1
  end
  if i == n - 1 && ind == 2
    ans += an[1] * an[2]
  end
end
if ans > 0
  puts ans
elsif (an[1] < 1 || an[2] < 1) || (goal == 0 && an[1] < 3) || goal * 3 != a_sum[n - 1]
  puts 0
elsif goal == 0
  puts (an[1] - 1) * (an[1] - 2) / 2
else
  puts ans
end

n = gets.to_i
a = gets.split.map(&:to_i)
a_sum = [a[0]]
(n - 1).times.each{|i| a_sum[i + 1] = a_sum[i] + a[i + 1]}
goal = a_sum[n - 1] == 0 ? 0 : a_sum[n - 1] / 3
an = [nil, 0, 0]
ind = 1
ans = 0
n.times do |i|
  if ind == 1 && a_sum[i] == goal && a_sum[i] == goal * 2
    an[1] += 1
    an[2] += 1
  elsif ind == 1 && a_sum[i] == goal
    an[1] += 1
  elsif ind == 2 && a_sum[i] == goal
    p an
    ans += an[1] * an[2]
    ind = 1
    an[1] = 1
  elsif a_sum[i] == goal * 2
    ind = 2
    an[2] += 1
  end
  if i == n - 1 && ind == 2
    ans += an[1] * an[2]
  end
end
if ans > 0
  puts ans
elsif (an[1] < 1 || an[2] < 1) || (goal == 0 && an[1] < 3) || goal * 3 != a_sum[n - 1]
  puts 0
elsif goal == 0
  puts (an[1] - 1) * (an[1] - 2) / 2
else
  puts ans
end


n, m = gets.split.map(&:to_i)
a = n.times.map{gets.chomp}

aa = Array.new(3){Array.new(n, 0)}
[/[[:alpha:]]/, /\d/, /\W/].each_with_index do |reg, i|
  n.times do |j|
    t1 = a[j] =~ reg
    t2 = (a[j].reverse =~ reg) + 1 if a[j].reverse =~ reg
    aa[i][j] = [t1, t2].min || 1000
  end
end

mi = 1000
n.times do |i|
  n.times do |j|
    next if j == i
    n.times do |k|
      next if k == i || k == j
      mi = [aa[0][i] + aa[1][j] + aa[2][k], mi].min
    end
  end
end
p mi

TEST_MODE = ARGV[0] == 't'

def evaluate(actual, expected); actual == expected ? "OK" : "**NG**"; end
def tests(); yield if TEST_MODE; end
def to_array(val); val.kind_of?(Array) ? val : [val]; end
def parse_int_array(str); str.split(" ").collect{|s| s.to_i}; end
def p(*arg); puts "DEBUG: " + arg.to_s if TEST_MODE; end

def t(input, expected_output)
  input = to_array(input)
  expected_output = to_array(expected_output)
  output = []
  solve(input, output)
  puts "#{evaluate(output, expected_output)} : input=#{input.to_s}, expected=#{expected_output.to_s}, actual=#{output.to_s}"
end

# actual codes here
BIG_INT = 1000000

def find_in(str)
  return 0 if yield(str[0])
  for i in 1..str.size/2
    return i if yield(str[i]) or yield(str[str.size-i])
  end
  return BIG_INT
end

def analyze(str)
  [
    find_in(str) { |c| 'a' <= c && c <= 'z' },
    find_in(str) { |c| '0' <= c && c <= '9' },
    find_in(str) { |c| '#*&'.index(c) != nil }
  ]
end

def findmin(arr)
  min = BIG_INT
  (0..arr.size-1).each { |i|
    sum = arr[i][0]
    (0..arr.size-1).each { |j|
      next if i==j
      sum = arr[i][0] + arr[j][1]
      next if sum >= min
      (0..arr.size-1).each { |k|
        next if i==k || j==k
        sum = arr[i][0] + arr[j][1] + arr[k][2]
        next if sum >= min
        min = sum if sum < min
      }
    }
  }
  return min
end

def solve(input, output)
  n, m = parse_int_array(input[0])
  arr = input[1..-1].collect {|str|
    analyze(str)
  }
  p(arr)
  output << findmin(arr).to_s
end

tests do
  # test cases
  t(["3 4",
"1**2",
"a3*0",
"c4**"], "1")
  t(["5 5",
"#*&#*",
"*a1c&",
"&q2w*",
"#a3c#",
"*&#*&"], "3")
end

puts solve(STDIN.read.split("\n"), []) unless TEST_MODE


n = Integer(gets.chomp)
original_text = Array.new(n+1)
for i in 0...n
    original_text[i] = "<3" + gets.chomp
end
original_text[n] = "<3"
text_received = gets.chomp
pointer = 0
find_all = true
for i in 0...n+1
    for k in 0...original_text[i].length
        a = original_text[i][k]
        find = false
        for j in pointer...text_received.length
            if text_received[j] == a
                pointer = j + 1
                find = true
                break
            end
        end
    end
    if !find
        find_all = false
        break
    end
end

if find_all
    puts "yes"
else
    puts "no"
end

n=gets.to_i
w=['']
n.times{w<<gets.chomp}
w<<''
m=gets.chomp
w=w.join '<3'
j=0
m.size.times{|i|j+=1 if j<w.size && m[i]==w[j]}
puts j==w.size ? 'yes':'no'

n = gets.to_i
s = "<3"
for i in 0...n
  s << gets.strip + "<3"

end

t = gets.strip

a = s.length
b = t.length

j = 0
for i in 0...a
  until t[j] == s[i]
    j += 1
    if j >= b
      print "no"
      exit
    end
  end
  j += 1
end

print "yes"

cnt = gets.to_i
cstr = "<3"
cnt.times {	cstr <<  gets.chomp << "<3" }
str = gets.chomp
idx = 0
cstr.each_char {|c|
	res = str.index(c, idx)
	if res == nil
		puts "no"
		exit
	end
	idx = res + 1
}
puts "yes"

n = gets.to_i
pattern = "<3"
n.times do |i|
  pattern = pattern << gets.chomp
  pattern = pattern << "<3"
end
ans = gets
len = pattern.size()
index = 0
alen = ans.size()
alen.times do |i|
  next if (pattern[index]!=ans[i])
  break if index == len or alen - i < len - index
  index += 1
end
if index == len then
  puts "yes"
else
  puts "no"
end

w = []
for _ in 1..Integer(gets.chomp)
  w << gets.chomp
end
s = "<3#{w * '<3'}<3"
t = gets.chomp
p = 0
n = s.size
for i in 0...t.size
  break if p == n
  p += 1 if t[i] == s[p]
end
puts(p == n ? 'yes' : 'no')

n = gets.chomp.to_i
msg = ["<3"]

n.times do
  word = gets.chomp
  msg.push(word)
  msg.push("<3")
end

enc = gets.chomp

msg = msg.join("")

curr = 0
enc.each_char do |c|
  if (curr < msg.length && c == msg[curr])
    curr += 1
  end
end

if (curr == msg.length)
  puts "yes"
else
  puts "no"
end

d = ('<3' + (gets.to_i.times.map{gets.split}).join('<3') + '<3').chars.to_a
str = gets.strip.chars.to_a
index = 0; get = 0;
(d.length).times do |i|
    get = i
    while(d[i] != str[index])
        if index == str.length-1
            break
        end
        index+=1
    end

    if index == str.length-1
        break
    end
    if d[i] == str[index]
        index+=1
    end
end
(get == d.length-1)? (puts "yes") : (puts "no")

cnt = gets.to_i
cstr = "<3"
cnt.times {	cstr <<  gets.chomp << "<3" }
str = gets.chomp
idx = 0
cstr.each_char {|c|
	res = str.index(c, idx)
	if res == nil
		puts "no"
		puts "idx=#{idx}, char=#{c}"
		exit
	end
	idx = res + 1
}
puts "yes"

n = gets.to_i
s = []
n.times do
  s << gets.chop
end
ans = gets.chop
pattern = "<3"
n.times do |i|
  pattern = pattern + s[i]
  pattern = pattern + "<3"
end
len = pattern.size()
cnt = 0
index = 0
if ans.size() - len != 1 then
  puts "no"
  exit
end
len.times do |i|
  while pattern[i] != ans[index] do
    index += 1
    cnt += 1
    break if index >= ans.size()
  end
  index += 1
  break if index >= ans.size()
end
if cnt == 1 then
  puts "yes"
else
  puts "no"
end

n = gets.to_i
s = []
n.times do
  s << gets.chop
end
ans = gets.chop
pattern = "<3"
n.times do |i|
  pattern = pattern + s[i]
  pattern = pattern + "<3"
end
len = pattern.size()
insert = false
index = 0
if ans.size() - len != 1 then
  puts "no"
  exit
end
len.times do |i|
  if ans[index] != pattern[i] then
    puts "no" if insert
    insert = true
    index += 1
  end
  index += 1
end
puts "yes"

n = gets.to_i
s = []
n.times do
  s << gets.chop
end
ans = gets.chop
pattern = "<3"
n.times do |i|
  pattern = pattern + s[i]
  pattern = pattern + "<3"
end
len = pattern.size()
cnt = 0
index = 0
len.times do |i|
  while pattern[i] != ans[index] do
    index += 1
    cnt += 1
    break if index >= ans.size()
  end
  index += 1
  break if index >= ans.size()
end
if cnt == 1 then
  puts "yes"
else
  puts "no"
end

n = Integer(gets.chomp)
original_text = ""
for i in 0...n
    original_text += gets.chomp
end
text_received = gets.chomp
pointer = 0
count = ""
for i in 0...original_text.length
    a = original_text[i]
    for j in pointer...text_received.length
        if text_received[j] == a
            pointer = j + 1
            count += a
            break
        end
    end
end

if count == original_text && text_received.length > original_text.length + 2 * n
    puts "yes"
else
    puts "no"
end

n = Integer(gets.chomp)
original_text = ""
for i in 0...n
    original_text += gets.chomp
end
text_received = gets.chomp
pointer = 0
count = ""
for i in 0...original_text.length
    a = original_text[i]
    for j in pointer...text_received.length
        if text_received[j] == a
            pointer = j + 1
            count += a
            break
        end
    end
end

if count == original_text
    puts "yes"
else
    puts "no"
end

d = ('<3' + (gets.to_i.times.map{gets.split}).join('<3') + '<3').chars.to_a
str = gets.strip.chars.to_a
index = 0; get = 0;
(d.length).times do |i|
    gets = i
    while(d[i] != str[index])
        if index == str.length-1
            break
        end
        index+=1
    end

    if index == str.length-1
        break
    end
end
(get == d.length-1)? (puts "yes") : (puts "no")

d = ('<3' + (gets.to_i.times.map{gets.split}).join('<3') + '<3').chars.to_a
str = gets.strip.chars.to_a
index = 0; get = 0;
(d.length).times do |i|
    get = i
    while(d[i] != str[index])
        if index == str.length-1
            break
        end
        index+=1
    end

    if index == str.length-1
        break
    end
end
(get == d.length-1)? (puts "yes") : (puts "no")

d = gets.to_i.times.map{gets.split}
str = gets.strip.chars.to_a
ans = ""
str.each{|x| (ans+=x) if (x>='a' && x<='z')}
(ans == d.join)? (puts "yes") : (puts "no")

d = ('<3' + (gets.to_i.times.map{gets.split}).join('<3') + '<3').chars.to_a
str = gets.strip.chars.to_a
index = 0; get = 0;
(d.length).times do |i|
	while(d[i] != str[index])
		if index == str.length-1
			break
		end
		index+=1
	end

	if index == str.length-1
		get = i
		break
	end
end
(get == d.length-1)? (puts "yes") : (puts "no")

n=gets.to_i
w=[]
n.times{w<<gets.chomp}
m=gets.chomp
w=w.join '<3'
j=0
m.size.times{|i|j+=1 if j<w.size && m[i]==w[j]}
puts j==w.size ? 'yes':'no'

n=gets.to_i
w=[]
n.times{w<<gets.chomp}
m=gets.chomp
w=w.join '<3'
j=0
m.size.times{|i|j+=1 if m[i]==w[j]}
puts j==w.size ? 'yes':'no'

n=gets.to_i
w=[]
n.times{w<<gets.chomp}
m=gets.chomp
w=w.join '<3'
j=0
m.size.times{|i|j+=1 if j<w.size && m[i]==w[j]}
puts j>=w.size ? 'yes':'no'

n=gets.to_i
w=[]
n.times{w<<gets.chomp}
w<<''
m=gets.chomp
w=w.join '<3'
j=0
m.size.times{|i|j+=1 if j<w.size && m[i]==w[j]}
puts j==w.size ? 'yes':'no'


# http://codeforces.com/problemset/problem/981/B
a, b = [], []
n = gets.chomp.to_i
n.times do
  a << gets.chomp.split.map(&:to_i)
end
a.sort!

m = gets.chomp.to_i
m.times do
  b << gets.chomp.split.map(&:to_i)
end
b.sort!

sum = 0
for i in 0..(n - 1)
  sum += a[i][1]
end

for i in 0..(m - 1)
  sum += b[i][1]
end

repeated_index = []
i, j = 0, 0
while i < n && j < m
  if a[i][0] == b[j][0]
    repeated_index << [i, j]
    i += 1
    j += 1
  elsif a[i][0] < b[j][0]
    i += 1
  else
    j += 1
  end
end

if repeated_index.empty?
  puts sum
else
  for i in 0..(repeated_index.length - 1)
    a_repeated_index = repeated_index[i][0]
    b_repeated_index = repeated_index[i][1]

    sum -= a[a_repeated_index][1] < b[b_repeated_index][1] ? a[a_repeated_index][1] : b[b_repeated_index][1]
  end

  puts sum
end

l1 = gets.to_i
a = {}
l1.times{
  k,v =  gets.chomp.split(" ").map{|x| x.to_i}
  a[k] = v
}

b = {}
l2 = gets.to_i
l2.times{
  k,v =  gets.chomp.split(" ").map{|x| x.to_i}
  b[k] = v
}

a.each_key{|k|
  if b[k]
    if b[k] > a[k]
      a.delete(k)
    else
      b.delete(k)
    end
  end
}

puts a.values.inject(0){|sum,x| sum+x} + b.values.inject(0){|sum,x| sum+x}


t = gets.to_i
t.times{|x|
	a = gets.split.map &:to_i
	if a.max(2) == a[0..1].sort.reverse || a.max(2) == a[2..3].sort.reverse then
		puts "NO"
	else
		puts "YES"
	end
}

def solution(arr)
	m1, m2 = [arr[0], arr[1]].max, [arr[2], arr[3]].max
	[m1, m2].sort == arr.max(2).sort
end

t = gets.to_i
t.times do
	arr = gets.chomp.split(' ').map(&:to_i)
	puts solution(arr) ? 'Yes' : 'No'
end

t = gets.to_i
t.times{|x|
	a = gets.split.map &:to_i
	if a.max(2) == a[0..1].sort.reverse || a.max(2) == a[2..3].sort.reverse then
		puts "YES"
	else
		puts "NO"
	end
}


require 'set'
#if File.exists?("input")
#  $stdin = File.open("input")
#  $stdout = File.open("output","w")
#end
n = gets.to_i
arr = gets.chomp.split(" ").map(&:to_i)

i=0
ans=0
mySet = Set.new

while(i<n)
	ans+=1;
    loop do
		mySet.add(arr[i])
    	if(mySet.include?(i+1))
    		mySet.delete(i+1)
    	end
    	i+=1
    	break if mySet.empty?
    end
end

puts ans

N = gets.to_i
A = gets.split.map &:to_i
ans = 0
am = nil
(1..N).each{ |i|
  a = A[i-1]
  if !am
    am = a
    ans += 1
  end
  am = a if a > am
  if am <= i
    am = nil
    next
  end
}
p ans


n = gets.chomp.to_i
n.times do
    s, t = gets.chomp.split(" ").map(&:to_i)
    if s  == t
        puts "#{s-1}" + " " + "#{t}"
    elsif s > t
        puts "#{s-1}" + " " + "#{t}"
    elsif s < t
        puts "#{s-1}" + " " + "#{t}"
    end
end

t = gets.to_i
t.times do
 a, b = gets.split.map(&:to_i)
 puts (a-1).to_s + " " + b.to_s
end

n = gets.chomp.to_i
n.times do
    s, t = gets.chomp.split(" ").map(&:to_i)
    if s  == t
        if s == 1
            x = 0
            y = 1
            puts "#{x}" + " " "#{y}"
        else
            puts "#{s}" + " " + "#{t}"
        end
    elsif s > t
        puts "#{s-t}" + " " + "#{t}"
    elsif s < t
        puts "#{s-1}" + " " + "#{t-(s-1)}"
    end
end

n = gets.chomp.to_i
n.times do
    s, t = gets.chomp.split(" ").map(&:to_i)
    if s  == t
        puts "#{s-1}" + " " + "#{t}"
    elsif s > t
        puts "#{s-1}" + " " + "#{t}"
    elsif s < t
        puts "#{s-1}" + " " + "#{t-1}"
    end
end

n = gets.chomp.to_i
n.times do
    s, t = gets.chomp.split(" ").map(&:to_i)
    if s  == t
        puts "#{s-1}" + " " + "#{t}"
    elsif s > t
        puts "#{s-t}" + " " + "#{t}"
    elsif s < t
        puts "#{s-1}" + " " + "#{t-(s-1)}"
    end
end

n = gets.chomp.to_i
n.times do
    s, t = gets.chomp.split(" ").map(&:to_i)
    if s  == t
        if s == 1
            x = 0
            y = 1
            puts "#{x}" + " " "#{y}"
        else
            puts "#{s}" + " " + "#{t}"
        end
    elsif s > t
        puts "#{s-1}" + " " + "#{t}"
    elsif s < t
        puts "#{s}" + " " + "#{t-1}"
    end
end


n, k = gets.split.map(&:to_i)
s = gets.chomp
m = (n + 1..n * 2).find { |i|
	str = "?" * i
	str[...n] = s
	str[-n..] = s
	str[...n] == s
} - n
puts s + s[-m..] * (k - 1)

N, K = gets.split.map(&:to_i)
s = gets.chomp
n = N
(1...N).each do |i|
    if s[i, N-i] == s[0, N-i]
        n = i
        break
    end
end
ans = ''
(K-1).times do
    ans << s[0, n]
end
ans << s
puts ans

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

t=s.dup
k-=1

j = n-1
while j>0
  break if t[(n-j)...n] == s[0...j]
  j-=1
end

k.times do
  t << s[j...n]
end
puts t

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

i = nil
j = 0
loop {
  i = j if t[0..j] == t[-1-j..-1]
  j += 1
  break if j >= t.size-1
}

puts (t.size == 1 || i.nil? ? t * k : t[0..i] + t[i+1..-1] * k)

#i_am_fucking_stupid

v = gets.chomp.split(" ")
a = gets.chomp

s = a.size

m = 0

for i in 1..s-1
	temp = a[0...i]
	if temp == a[-i..-1]
		if m < temp.size
			m = temp.size
		end
	end
end

print a
(v[1].to_i - 1).times do
	print(a[m..-1])
end

n, k = gets.split().map{ |x| x.to_i }
s = gets.chomp
len = n - 1
until len == 0 do
    if s[0, len] == s[n - len, len]
        break
    end
    len -= 1
end
t = s[len, n - len]
(k - 1).times { s = s + t }
puts s

def ascan; gets.split.map(&:to_i); end

n,k = ascan
str = gets.chomp

if k == 1
    puts str; exit
elsif n == 1
    puts str*k; exit
else
    t = nil
    1.upto(n-1) do |i|
        if str[i..-1] == str[0..(-1-i)]
            header = str[0...i]
            footer = str[i..-1]
            puts header*k+footer; exit
        end
    end
    puts str*k; exit
end

nk = gets.chomp.split(" ").map(&:to_i)
str = gets.chomp
k = nk[1]

def splitof(str)
  a = str.length-2
  while a >=0
    break if str[0..a]==str[-1-a..-1]
    a-=1
  end

  if a==-1
    return [str,""]
  else
    return [str[0..-2-a],str[-1-a..-1]]
  end
end

asd = splitof(str)
#p asd
k.times do
  print(asd[0])
end

print(asd[1])
puts

#! /usr/bin/env ruby

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

def c(s, t)
  cnt=0
  (0..(s.size-t.size)).each do |i|
    cnt+=1 if s[i...(i+t.size)]==t
  end
  # print "#{s} #{t} #{cnt}\n"
  return cnt==2
end

n.times do |i|
  t=s+s[-(i+1)..-1]
  # print "#{t} #{s} #{s[-(i+1)..-1]}\n"
  if c(t, s)
    puts s+s[-(i+1)..-1]*(k-1)
    break
  end
end

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

t=s.dup
k-=1

k.times do
  j = 1
  while j<n && t[(n-j)...n] == s[0...j]
    j+=1
  end
  j-=1
  t += s[j...n]
end
puts t

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

i = 0
loop {
  t[0..i] == t[-1-i..-1] ? i += 1 : break
  break if i > t.size-1-i
}
i = -1 if t[0] != t[-1]

puts (t.size == 1 ? t * k : i == -1 ? t * k : t[0..t.size-i-1] * k + t[t.size-i..-1])

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

i = j = 0
loop {
  t[0..j] == t[-1-j..-1] ? i = j : nil
  j += 1
  break if j > t.size-1-j
}
i = -1 if t[0] != t[-1]

puts (t.size == 1 ? t * k : i == -1 ? t * k : t[0..t.size-i-1] + t[t.size-i..-1] * k)

a = gets.chomp.split(" ")
st = gets.chomp

j = 0
i = 1
while i < a[0].to_i
  if(st[i] == st[j])
    j += 1
  else
    if(j > 0)
      i -= 1
     end
    j = 0
  end
  i += 1
end

print(st)

(a[1].to_i-1).times do
  print(st[j...a[0].to_i])
end

a = gets.chomp.split(" ")
st = gets.chomp

j = 0
i = 1
while i < a[0].to_i
  if(st[i] == st[j])
    j += 1
  else
    j = 0
  end
  i += 1
end

print(st)

(a[1].to_i-1).times do
  print(st[j...a[0].to_i])
end

v = gets.chomp.split(" ")
a = gets.chomp

s = (a.size / 2).ceil
m = 0

for i in 1..s
	temp = a[0...i]
	if temp == a[-i..-1]
		if m < temp.size
			m = temp.size
		end
	end
end

print a
(v[1].to_i - 1).times do
	print(a[m..-1])
end


gets.to_i.times{puts gets.count(?N)==1 ? "NO" : "YES"}

gets.to_i.times{puts gets.count(?N)==1 ? "NO":"YES"}


t = gets.chomp.to_i
t.times do
  n = gets.chomp.to_i
  arr = gets.chomp.split(' ').map(&:to_i)
  dp = Hash.new {|_| [-1]}
  arr.each_with_index do |el, ind|
    if dp.has_key?(el)
      dp[el] << ind
    else
      dp[el] = dp[el] + [ind]
    end
    #dp[el] = dp[el] + [ind]
  end
  mn = 10 ** 10
  mn_v = -1
  dp.each do |k, v|
    tmp = 0
    st = v[0]
    (v[1..] + [n]).each do |el|
      if (el - st > 1)
        tmp += 1
      end
      st = el
    end
    mn = [mn, tmp].min
  end
  puts mn
end

t = gets.to_i

1.upto t do
  n = gets.to_i
  a = gets.split.map(&:to_i)
  new = a.chunk(&:itself).map(&:first)
  h = new.tally
  h[new[0]] -= 1
  h[new[-1]] -= 1
  puts h.values.min + 1
end

t = gets.chomp.to_i
t.times do
  n = gets.chomp.to_i
  arr = gets.chomp.split(' ').map(&:to_i)
  dp = Hash.new {|_| [-1]}
  arr.each_with_index do |el, ind|
    if dp.has_key?(el)
        dp[el] << ind
      else
        dp[el] = dp[el]
      end
  end
  mn = 10 ** 10
  mn_v = -1
  dp.each do |k, v|
    tmp = 0
    st = v[0]
    (v[1..] + [n]).each do |el|
      if (el - st > 1)
        tmp += 1
      end
      st = el
    end
    mn = [mn, tmp].min
  end
  puts mn
end


gets
d = []
gets.split.each_with_index { |x, i| d[x.to_i] = i + 1 }
puts gets.split.each.map { |x| d[x.to_i] }

n = gets.to_i
a, b = [0, 1].map { gets.split.map(&:to_i) }
p = []
n.times do |i|
  p[a[i] - 1] = b[i]
end
puts p.join(' ')

n = gets.to_i
a = gets.split.map &:to_i
b = gets.split.map &:to_i
d = Array.new(n + 1)
a.each_with_index { |x, i| d[x] = i + 1 }
c = b.each.map { |x| d[x] }
puts c

n = gets.to_i
a = gets.split.map &:to_i
b = gets.split.map &:to_i
d = []
a.each_with_index { |x, i| d[x] = i + 1 }
c = b.each.map { |x| d[x] }
puts c

n = gets.chomp.to_i
a = gets.chomp.split(/ /).map!{|x| x.to_i}
b = gets.chomp.split(/ /).map!{|x| x.to_i}
ab = []
for i in 0..n-1
    ab << [a[i], b[i]]
end
ab.sort!{|ab1,ab2|
    ab1[0] <=> ab2[0]
}
ret = []
for i in 0..n-1
    ret << ab[i][1]
end
puts ret.join(" ")


(1..gets.to_i).map{
  gets
  puts gets.sub(/\s.*$/,"") }

(1..gets.to_i).map{
  gets
  puts gets.split[0]}

(1..gets.to_i).map{
  gets
  puts gets.split.map(&:to_i)[0] }

gets.to_i.times do
  gets
  puts gets.split.map(&:to_i)[0]
end

gets.to_i.times do
  gets.to_i
  puts gets.split.map(&:to_i)[0]
end

gets.to_i.times do
  n = gets.to_i
  a = gets.split.map(&:to_i)
  n.times do |i|
    x = 0
    n.times do |j|
      x ^= a[j] if j != i
    end
    if (a[i] == x)
      puts a[i]
      break
    end
  end
end

gets.to_i.times do
  n = gets.to_i
  a = gets.split.map(&:to_i)
  for i in 0..(n - 1)
    x = 0
    for j in 0..(n - 1)
      x ^= a[j] if j != i
    end
    if (a[i] == x)
      puts a[i]
      break
    end
  end
end

# gets.to_i
# gets.split.map(&:to_i)

gets.to_i.times do
  n = gets.to_i
  a = gets.split.map(&:to_i)
  n.times do |i|
    now = a[i]
    sum = 0
    n.times do |j|
      next if i == j
      sum ^= a[j]
    end
    if now == sum
      puts now
      break
    end
  end
end


n, m = STDIN.readline.split.map {|s| s.to_i }
lines = STDIN.readlines
count = n.times.map { n.times.map { 0 } }
dr = [-1, -1, -1, 0, 0, 0, 1, 1, 1]
dc = [-1, 0, 1, -1, 0, 1, -1, 0, 1]
lines.each_with_index do |line, i|
	x, y = line.split.map {|s| s.to_i-1 }
	9.times do |j|
		r = x+dr[j]
		next if r == -1 or r == n
		c = y+dc[j]
		next if c == -1 or c == n
		count[r][c] += 1
		if count[r][c] == 9
			puts i+1
			exit
		end
	end
end
puts -1

n, m = STDIN.readline.split.map {|s| s.to_i }
count = n.times.map { n.times.map { 0 } }
result = -1
dr = [-1, -1, -1, 0, 0, 0, 1, 1, 1]
dc = [-1, 0, 1, -1, 0, 1, -1, 0, 1]
m.times do |i|
	x, y = STDIN.readline.split.map {|s| s.to_i-1 }
	next if result != -1
	9.times do |j|
		r = x+dr[j]
		next if r == -1 or r == n
		c = y+dc[j]
		next if c == -1 or c == n
		count[r][c] += 1
		if count[r][c] == 9
			result = i+1
		end
	end
end
puts result

n,m = gets.split.map(&:to_i)
array = Array.new(n){ Array.new(n) }

m.times do |z|
    x,y = gets.split.map(&:to_i)
    x -= 1
    y -= 1
    array[x][y] = true
    -1.upto(1) do |i|
        if x+i <0 || x+i >n-1
            next
        end
        -1.upto(1) do |j|
            if y+j <0 || y+j >n-1
                next
            end
            if(!array[x+i][y+j])
                next
            end
            black = 0
            catch(:exit) {
            -1.upto(1) do |k|
                if x+i+k < 0 || x+i+k > n-1
                    next
                end
                -1.upto(1) do |l|
                    if y+j+l < 0 || y+j+l > n-1
                        next
                    end
                    if(array[x+i+k][y+j+l])
                        black += 1
                    else
                    throw :exit
                    end
                end
            end
            if black == 9
                puts z+1
                exit
            end
            }
        end
    end
end
puts -1

n,m = gets.split.map(&:to_i)
bins = Array.new(n){Array.new(n){0}}
p [*1..m].find{ |o|
    x,y = gets.split.map(&:to_i)
    y-=1; x-=1
    !->{
        if y>=2
            return if 9 == bins[y-2][x-2] += 1 if x>=2
            return if 9 == bins[y-2][x-1] += 1 if x>=1
            return if 9 == bins[y-2][x] += 1
        end
        if y>=1
            return if 9 == bins[y-1][x-2] += 1 if x>=2
            return if 9 == bins[y-1][x-1] += 1 if x>=1
            return if 9 == bins[y-1][x] += 1
        end
            return if 9 == bins[y][x-2] += 1 if x>=2
            return if 9 == bins[y][x-1] += 1 if x>=1
            return if 9 == bins[y][x] += 1
        true
    }[]
} || -1

n,m = gets.split.map(&:to_i)
array = Array.new(n){ Array.new(n) }

m.times do |i|
    x,y = gets.split.map(&:to_i)
    x -= 1
    y -= 1
    array[x][y] = true
    -1.upto(1) do |i|
        if x+i <0 || x+i >n-1
            next
        end
        -1.upto(1) do |j|
            if y+j <0 || y+j >n-1
                next
            end
            if(!array[x+i][y+j])
                next
            end
            black = 0
            -1.upto(1) do |k|
                if x+i+k < 0 || x+i+k > n-1
                    next
                end
                -1.upto(1) do |l|
                    if y+j+l < 0 || y+j+l > n-1
                        next
                    end
                    if(array[x+i+k][y+j+l])
                        black += 1
                    else
                        break
                    end
                end
            end
            if black == 9
                puts m-1
                exit
            end
        end
    end
end
puts -1


gets
z = gets.split.map(&:to_i).min - 1
if z==0
    puts -1
else
    puts 1
end

n=gets.to_i
x=gets.split.map{|e| e.to_i}.min
if x==1 then
	puts -1
else
	puts 1
end

gets
nums = gets.chomp.split.map(&:to_i)
puts nums.include?(1) ? -1 : 1

gets
q = gets.split.map { |c| c.to_i }.sort
puts q[0] == 1 ? -1 : 1

n = gets.chomp
A = []
nbs = gets.chomp.split(" ")
exist = false
nbs.each do |x|
    exist ||= x.to_i == 1
end

if exist
    print -1
else
    print 1
end

n = gets.chomp
A = []
nbs = gets.chomp.split(" ")
exist = false
nbs.each do |x|
    exist = true if x.to_i == 1
end

print exist ? -1 : 1

# coding: utf-8

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

if ar.first == 1
    puts "-1" # 1 can express all!
else
    puts 1
end

n = gets.to_i
a = gets.split.map(&:to_i)
puts a.include?(1) ? -1 : 1

arr=gets(gets).split.map(&:to_i).sort(); puts arr[0] == 1 ? "-1" : "1"

num = gets.to_i
numbers=gets.split(' ')
result = numbers.collect{ |x| x.to_i }.sort!
puts -1 if result[0] == 1
puts 1 if result[0] != 1

banknoteNum = gets.chomp.to_i
banknotes = gets.chomp.split(' ').map {|item| item.to_i}

if banknotes.include?(1)
	puts "-1"
	exit
else
	puts "1"
	exit
end

banknotes.sort!

nowIndex = 0

until banknotes.length - 1 == nowIndex
	if banknotes[nowIndex + 1] - banknotes[nowIndex] > 1
		puts banknotes[nowIndex] + 1
		exit
	end

 	nowIndex += 1
 end

#!/usr/bin/ruby
gets
m=gets.split.map(&:to_i).min-1
p m==0 ? -1 : 1

n = gets.to_i
currency = gets.split(' ')
currency.map!{|c| c.to_i}
currency.sort!
if currency.first == 1
    puts -1
else
    puts 1
end

# http://codeforces.com/contest/560/problem/A
# A. Currency System in Geraldion
def unfortunate_value(values)
  return nil if values.include?(1)

  values.sort!
  (1..(10**6)).to_a.find do |n|
    values.all? { |v| n % v != 0 }
  end
end

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

ans = unfortunate_value(values)
puts ans.nil? ? -1 : ans

n = gets.to_i
input = gets.split(' ')
nums = (input.collect { |x| x.to_i }).sort!

if nums[0] == 1
	puts -1
else
	puts 1
end

n = gets.to_i
a = gets.split.map(&:to_i).sort
puts a[0] == 1 ? -1 : 1

#!/usr/bin/ruby
gets
m=gets.split.map(&:to_i).min-1
p m==0 ? -1 : m

# http://codeforces.com/contest/560/problem/A
# A. Currency System in Geraldion
def unfortunate_value(values)
  return nil if values.include?(1)

  values.sort!
  (1..(10**6)).to_a.select do |n|
    return true if values.all? { |v| n % v != 0 }
  end.first
end

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

ans = unfortunate_value(values)
puts ans.nil? ? -1 : ans

# coding: utf-8

n = gets.to_i
ar = gets.split.map(&:to_i).sort
total_sum = ar.reduce(:+)
i = 0
uf_num = -1
for j in ar
    if j - i > 1
        uf_num = i
        break
    else
        i = j
    end
end

if uf_num == -1
    puts "-1"
else
    puts total_sum - 1
end

# coding: utf-8

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

if ar.first == 1
    puts "-1" # 1 can express all!
else
    puts ar.first - 1
end

# coding: utf-8

n = gets.to_i
ar = gets.split.map(&:to_i).sort
total_sum = ar.reduce(:+)
i = ar.first
uf_num = -1
for j in ar[1..-1]
    if j - i > 1
        uf_num = i + 1
        break
    else
        i = j
    end
end

if uf_num == -1
    puts "-1"
else
    puts total_sum - (uf_num - 1) + uf_num
end

arr=gets.split.map(&:to_i).sort(); puts arr[0] == 1 ? "-1" : "1"


H, W = gets.split.map(&:to_i)
pic = []
H.times do |i|
    pic[i] = gets.chomp
end

down = Array.new(H+1){Array.new(W+1, -1)}
up = Array.new(H+1){Array.new(W+1, -1)}
left = Array.new(H+1){Array.new(W+1, -1)}
right = Array.new(H+1){Array.new(W+1, -1)}

H.times do |i|
    W.times do |j|
        up[i][j] = (pic[i][j] == '*' ? up[i-1][j] + 1 : -1)
        left[i][j] = (pic[i][j] == '*' ? left[i][j-1] + 1 : -1)
    end
end
(H-1).downto(0) do |i|
    (W-1).downto(0) do |j|
        down[i][j] = pic[i][j] == '*' ? down[i+1][j] + 1 : -1
        right[i][j] = pic[i][j] == '*' ? right[i][j+1] + 1 : -1
    end
end

ans = []
H.times do |i|
    W.times do |j|
        num = [down[i][j], left[i][j], up[i][j], right[i][j]].min
        if num > 0
            pic[i][j] = '.'
            (1..num).each do |k|
                pic[i-k][j] = '.'
                pic[i+k][j] = '.'
                pic[i][j-k] = '.'
                pic[i][j+k] = '.'
            end
            ans.push([i+1, j+1, num])
        end
    end
end

if pic.all?{|row| row.count('*') == 0}
    puts ans.length
    ans.each do |arr|
        puts arr.join(' ')
    end
else
    puts -1
end

def make_hash(n, m, boardstr)
  {}.tap do |h|
    (0...n).each do |i|
      (0...m).each do |j|
        h[[i,j]] = true if boardstr[i][j] == ?*
      end
    end
  end
end

require 'set'

def move(point, y, x)
  i, j = point
  [i + y, j + x]
end

def get_star(board, i, j)
  p, q = i, j

  points = Set.new

  up = [p, q]
  down = [p, q]
  left = [p, q]
  right = [p, q]

  size = -1

  while board[up] && board[down] && board[left] && board[right]
    points << up
    points << down
    points << left
    points << right

    size += 1

    up = move(up, -1, 0)
    down = move(down, 1, 0)
    left = move(left, 0, -1)
    right = move(right, 0, 1)
  end

  [points, size] if size > 0

end

def solution
  n, m = read_ints

  boardstr = []

  n.times do
    boardstr << read_string
  end

  board = make_hash(n, m, boardstr)
  lit = Set.new(board.keys)

  stars = []

  (1...(n-1)).each do |i|
    (1...(m-1)).each do |j|
      star_points, star_size = get_star(board, i, j)
      next unless star_points

      stars << [i+1, j+1, star_size]
      lit.subtract(star_points)

    end
  end

  if lit.empty?
    puts stars.size
    stars.each do |s|
      puts s.join(' ')
    end
  else
    puts(-1)
  end

end

def read_int
  gets.to_i
end

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

def read_string
  gets.chomp
end

solution unless ENV['TEST__MODE']


n = gets.to_i
a = gets.split(' ').map { |c| c.to_i }

if n == 1
    puts 1
    exit
end

leftright = Array.new(n, 0)
rightleft = Array.new(n, 0)
leftright[0] = rightleft[n - 1] = 1

(n - 1).times do |i|
    pos = i + 1
    leftright[pos] = 1 + (a[pos] > a[pos - 1] ? leftright[pos - 1] : 0)
end
(n - 1).times do |i|
    pos = n - i - 2
    rightleft[pos] = 1 + (a[pos] < a[pos + 1] ? rightleft[pos + 1] : 0)
end

best = 1 + [rightleft[1], leftright[n - 2]].max
(n - 2).times do |i|
    pos = i + 1
    best = [best, leftright[pos - 1] + 1].max
    best = [best, rightleft[pos + 1] + 1].max
    if a[pos - 1] + 2 <= a[pos + 1]
        best = [best, leftright[pos - 1] + 1 + rightleft[pos + 1]].max
    end
end

puts best

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

left, right = Array.new(n), Array.new(n)

best = n <= 2 ? n : 1
left[0] = 1
(1..(n - 1)).each do |i|
  left[i] = a[i] > a[i - 1] ? left[i - 1] + 1 : 1
end

right[n - 1] = 1
(0..(n - 2)).to_a.reverse.each do |i|
  right[i] = a[i] < a[i + 1] ? right[i + 1] + 1 : 1
end

(1..(n - 2)).each do |i|
  best = [best, left[i - 1] + right[i + 1] + 1].max if a[i - 1] + 1 < a[i + 1]
  best = [best, left[i] + 1].max
  best = [best, right[i] + 1].max
end

puts best

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

left, right = Array.new(n), Array.new(n)

best = n <= 2 ? n : 1
left[0] = 1
(1..(n - 1)).each do |i|
  left[i] = a[i] > a[i - 1] ? left[i - 1] + 1 : 1
  # puts best
end

right[n - 1] = 1
(0..(n - 2)).to_a.reverse.each do |i|
  right[i] = a[i] < a[i + 1] ? right[i + 1] + 1 : 1
  # puts best
end

(1..(n - 2)).each do |i|
  best = [best, left[i - 1] + right[i + 1] + 1].max if a[i - 1] + 1 < a[i + 1]
  best = [best, left[i] + 1].max
  best = [best, right[i] + 1].max
  # puts best
end

# puts left.join(" ")
# puts right.join(" ")
puts best

n = gets.chomp.to_i
if n == 1
	puts 1
	exit
end
a = gets.split.map{ |i| i.to_i }
r = [1] * n
l = r.clone

( 1..n-1 ).each do |i|
	l[i] = l[i-1] + 1 if a[i] > a[i-1]
end

(n - 2).downto( 0 ).each do |i|
	r[i] = r[i+1] + 1 if a[i] < a[i+1]
end

ans = r[1] + 1
( 1..n-2 ).each do |i|
	ans = [ans, l[i-1] + r[i+1] + 1].max if a[i+1] - a[i-1] >= 2
	ans = [ans, l[i-1] + 1].max
	ans = [ans, r[i+1] + 1].max
end
ans = [ans, l[-2] + 1].max
puts ans

# Calculates the derivative
def derivative(ar)
    return ar.clone().unshift(0).each_cons(2).map{|x, y| y - x}
    # each_cons returns an iterator over pairs of elements
    # clone to get over the dumb ruby passig by reference
end

# Returns indices of non-increaseing points
def loc(ar)
    # Obtain the derivative of the input
    der = derivative(ar)
    return der.each_index.select{|i| der[i] <= 0}
    # each_index returns an itetrator over indices
    # select returns elements that match condition
end

# Read Input
n = gets.strip.to_i
a = gets.strip.split.map(&:to_i)

# Obtain the locations of non-increasing points
negloc = loc(a).unshift(0).push(n)

# Create an array to store lengths of segments
seqlength = [negloc[1]]

# Loop over locations of non-increasing points
for i in 1..(negloc.length - 1) do
    j = negloc[i]
    if i == negloc.length - 1
        seqlength[i] = negloc[i] - negloc[i-1] + 1
    elsif j + 1 < a.length && a[j-1] + 1 < a[j+1]
        seqlength[i] = negloc[i+1] - negloc[i-1]
    elsif j - 2 > -1 && a[j-2] + 1 < a[j]
        seqlength[i] = negloc[i+1] - negloc[i-1]
    else
        seqlength[i] = negloc[i] - negloc[i-1] + 1
    end
end

puts [seqlength.max,n].min

n = gets.chomp.to_i
a = gets.split.map{ |i| i.to_i }
r = [1] * n
l = r.clone

( 1..n-1 ).each do |i|
	l[i] = l[i-1] + 1 if a[i] > a[i-1]
end

(n - 2).downto( 0 ).each do |i|
	r[i] = r[i+1] + 1 if a[i] < a[i+1]
end

ans = r[0]
( 1..n-2 ).each do |i|
	ans = [ans, l[i-1] + r[i+1] + 1].max if a[i+1] - a[i-1] >= 2
end
ans = [ans, l[-1]].max
puts ans

n = gets.chomp.to_i
a = gets.split.map{ |i| i.to_i }
r = [1] * n
l = r.clone

( 1..n-1 ).each do |i|
	l[i] = l[i-1] + 1 if a[i] > a[i-1]
end

(n - 2).downto( 0 ).each do |i|
	r[i] = r[i+1] + 1 if a[i] < a[i+1]
end

ans = r[0]
( 1..n-2 ).each do |i|
	ans = [ans, l[i-1] + r[i+1] + 1].max if a[i+1] - a[i-1] >= 2
	ans = [ans, l[i-1] + 1].max
	ans = [ans, r[i+1] + 1].max
end
ans = [ans, l[-1]].max
puts ans

n = gets.chomp.to_i
a = gets.split.map{ |i| i.to_i }
l = 0
r = 1
ans = 1
changes = -1
while l < n && r < n do
	if a[r] <= a[r - 1]
		if changes < 0
			if l == r - 1
				a[r-1] = a[r] - 1
				changes = l
			else
				a[r] = a[r-1] + 1
				changes = r
			end
		else
			l = changes + 1
			changes = -1
		end
	end
	ans = [ans, r - l + 1].max
	r += 1
end
puts ans

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

longest_so_far = 0
length = 1
hicat = 0
i = 0

while i < n - 1
    if a[i] >= a[i+1]
        lognest_so_far = length if length > longest_so_far
        length = length - hicat
        hicat = length
    end
    length = length + 1
    i = i + 1
end

lognest_so_far = length if length > longest_so_far

puts lognest_so_far

def derivative(ar)
    # Each cons returns an iterator over pairs of elements
    return ar.clone().unshift(0).each_cons(2).map{|x, y| y - x}
end

def loc(ar, v)
    return ar.each_index.select{|i| ar[i] <= v}
end

# Read Input
n = gets.strip.to_i
a = gets.strip.split.map(&:to_i)

if (n <= 2)
    puts n
    exit
end

# Obtain the derivative of the input
der = derivative(a)

# Obtain the locations of negatives
negloc = loc(der,0).unshift(0).push(n)

seqlength = []

for i in 0..(negloc.length - 1) do
   j = negloc[i]

   if i == 0
        seqlength[i] = negloc[1]
   elsif i == negloc.length - 1
        seqlength[i] = negloc[i] - negloc[i-1] + 1
   elsif j+1 < a.length && a[j-1] + 1 < a[j+1]
        seqlength[i] = negloc[i+1] - negloc[i-1]
   else
        seqlength[i] = negloc[i] - negloc[i-1] + 1
   end

end

puts [seqlength.max,n].min

def derivative(ar)
    # Each cons returns an iterator over pairs of elements
    return ar.clone().unshift(0).each_cons(2).map{|x, y| y - x}
end

def loc(ar, v)
    return ar.each_index.select{|i| ar[i] <= v}
end

# Read Input
n = gets.strip.to_i
a = gets.strip.split.map(&:to_i)

if (n <= 2)
    puts n
    exit
end

# Obtain the derivative of the input
der = derivative(a)

# Obtain the locations of negatives
negloc = loc(der,0).unshift(0).push(n)

seqlength = []

for i in 0..(negloc.length - 1) do
   j = negloc[i]

   if i == 0
        seqlength[i] = negloc[1]
   elsif i == negloc.length - 1
        seqlength[i] = negloc[i] - negloc[i-1] + 1
   elsif j+1 < a.length && a[j-1] + 1 < a[j+1]
        seqlength[i] = negloc[i+1] - negloc[i-1]
   else
        seqlength[i] = negloc[i] - negloc[i-1] + 1
   end

end

puts seqlength.max

def derivative(ar)
    # Each cons returns an iterator over pairs of elements
    return ar.clone().unshift(0).each_cons(2).map{|x, y| y - x}
end

def loc(ar, v)
    return ar.each_index.select{|i| ar[i] <= v}
end

# Read Input
n = gets.strip.to_i
a = gets.strip.split.map(&:to_i)

# Obtain the derivative of the input
der = derivative(a)

# Obtain the locations of negatives
negloc = loc(der,0).unshift(0).push(n)

seqlength = []

for i in 0..(negloc.length - 1) do
   j = negloc[i]

   if i == 0
        seqlength[i] = negloc[1]
   elsif i == negloc.length - 1
        seqlength[i] = negloc[i] - negloc[i-1] + 1
   elsif j+1 < a.length && a[j-1] + 1 < a[j+1]
        seqlength[i] = negloc[i+1] - negloc[i-1]
   else
        seqlength[i] = negloc[i] - negloc[i-1] + 1
   end

end
puts seqlength.max

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

longest_so_far = 0
length = 1
hicat = 0
i = 0

while i < n - 1
    if a[i] >= a[i+1]
        longest_so_far = length if length > longest_so_far
        length = length - hicat
        hicat = length
    end
    length = length + 1
    i = i + 1
end

longest_so_far = length if length > longest_so_far

puts longest_so_far

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

puts n
puts a

longest_so_far = 0
length = 1
hicat = 0
i = 0

while i < n - 1
    if a[i] >= a[i+1]
        lognest_so_far = length if length > longest_so_far
        length = length - hicat
        hicat = length
    end
    length = length + 1
    i = i + 1
end

lognest_so_far = length if length > longest_so_far

puts lognest_so_far

def derivative(ar)
    # Each cons returns an iterator over pairs of elements
    return ar.clone().unshift(0).each_cons(2).map{|x, y| y - x}
end

def loc(ar, v)
    return ar.each_index.select{|i| ar[i] <= v}
end

# Read Input
n = gets.strip.to_i
a = gets.strip.split.map(&:to_i)

# Obtain the derivative of the input
der = derivative(a)

# Obtain the locations of negatives
negloc = loc(der,0).unshift(0).push(n)

seqlength = []

for i in 0..(negloc.length - 1) do
   j = negloc[i]

   if i == 0
        seqlength[i] = negloc[1]
   elsif i == negloc.length - 1
        seqlength[i] = negloc[i] - negloc[i-1]
   elsif j+1 < a.length && a[j-1] + 1 < a[j+1]
        seqlength[i] = negloc[i+1] - negloc[i-1]
   else
        seqlength[i] = negloc[i] - negloc[i-1] + 1
   end

end

puts seqlength.max

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

longest_so_far = 0
length = 1
hicat = 0
i = 0

while i < n - 1
    if a[i] >= a[i+1]
        longest_so_far = length if length > longest_so_far
        length = length - hicat
        hicat = length
    end
    length = length + 1
    i = i + 1
end

lognest_so_far = length if length > longest_so_far

puts longest_so_far

def derivative(ar)
    # Each cons returns an iterator over pairs of elements
    return ar.clone().unshift(0).each_cons(2).map{|x, y| y - x}
end

def loc(ar, v)
    return ar.each_index.select{|i| ar[i] <= v}
end

# Read Input
n = gets.strip.to_i
a = gets.strip.split.map(&:to_i)

if (n <= 2)
    return n
    exit
end

# Obtain the derivative of the input
der = derivative(a)

# Obtain the locations of negatives
negloc = loc(der,0).unshift(0).push(n)

seqlength = []

for i in 0..(negloc.length - 1) do
   print "Now at: "
   puts negloc[i]

   j = negloc[i]

   if i == 0
        seqlength[i] = negloc[1]
   elsif i == negloc.length - 1
        seqlength[i] = negloc[i] - negloc[i-1] + 1
   elsif j+1 < a.length && a[j-1] + 1 < a[j+1]
        seqlength[i] = negloc[i+1] - negloc[i-1]
   else
        seqlength[i] = negloc[i] - negloc[i-1] + 1
   end

end

puts seqlength.max

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

left, right = Array.new(n), Array.new(n)

left[0] = 1
(1..(n - 1)).each do |i|
  left[i] = a[i] > a[i - 1] ? left[i - 1] + 1 : 1
end

right[n - 1] = 1
(0..(n - 2)).to_a.reverse.each do |i|
  right[i] = a[i] < a[i + 1] ? right[i + 1] + 1 : 1
end

best = 1
(1..(n - 2)).each do |i|
  best = [best, left[i] + right[i] + 1].max if a[i - 1] + 1 < a[i + 1]
end

puts best

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

left, right = Array.new(n), Array.new(n)

left[0] = 1
(1..(n - 1)).each do |i|
  left[i] = a[i] > a[i - 1] ? left[i - 1] + 1 : 1
end

right[n - 1] = 1
(0..(n - 2)).to_a.reverse.each do |i|
  right[i] = a[i] < a[i + 1] ? right[i + 1] + 1 : 1
end

best = 1
(1..(n - 2)).each do |i|
  best = [best, left[i - 1] + right[i + 1] + 1].max if a[i - 1] + 1 < a[i + 1]
  best = [best, left[i] + 1, right[i] + 1].max
  # puts best
end

# puts left.join(" ")
# puts right.join(" ")
puts best

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

left, right = Array.new(n), Array.new(n)

best = 1
left[0] = 1
(1..(n - 1)).each do |i|
  left[i] = a[i] > a[i - 1] ? left[i - 1] + 1 : 1
  best = [best, left[i] + 1].max
end

right[n - 1] = 1
(0..(n - 2)).to_a.reverse.each do |i|
  right[i] = a[i] < a[i + 1] ? right[i + 1] + 1 : 1
  best = [best, right[i] + 1].max
end

(1..(n - 2)).each do |i|
  best = [best, left[i - 1] + right[i + 1] + 1].max if a[i - 1] + 1 < a[i + 1]
end

puts best

n = gets.to_i
a = gets.split(' ').map { |c| c.to_i }
leftright = Array.new(n, 0)
rightleft = Array.new(n, 0)
leftright[0] = rightleft[n - 1] = 1

(n-1).times do |i|
  pos = i + 1
  leftright[pos] = 1
  if a[pos] > a[pos - 1]
    leftright[pos] += 1
  end
end

(n-1).times do |i|
  pos = n - 2 - i
  rightleft[pos] = 1
  if a[pos] < a[pos + 1]
    rightleft[pos] += 1
  end
end

best = [1 + rightleft[1], 1 + leftright[n - 2]].max
a.each_with_index do |val, i|
  next if i == 0 || i == n - 1 || a[i - 1] + 2 > a[i + 1]
  best = [best, leftright[i - 1] + 1 + rightleft[i + 1]].max
end

puts best


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
  n = gi
  a = gli
  b = gli
  a_s = a.sum
  b_s = 0
  mn = [a_s, b.sum].max
  for i in (0..n-1)
    a_s -= a[i]
    tmp = [a_s, b_s].max
    mn = tmp if tmp < mn
    b_s += b[i]
  end
  puts mn
end

def main
  gi.times { solve }
end

main

#!/usr/bin/env ruby

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

def pfr(ar)
  res = [0]
  ar.each do |x| res.append(res[-1] + x) end
  res
end

class Grid
  def initialize(ar)
    @pfr = ar.map{|x| pfr(x)}
    @n = ar[0].length
  end
  def score(x)
    [@pfr[1][x-1], @pfr[0][@n] - @pfr[0][x]].max
  end
end

gets.chomp.to_i.times do
  n = gets.chomp.to_i
  a = (1..2).map{arline}
  g = Grid.new(a)
  puts (1..n).map{|x| g.score(x) }.min
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
  n = gi
  a = gli
  b = gli
  a_s = a.sum
  b_s = b.sum
  mn = [a_s, b_s].max
  b_s = 0
  for i in (0..n-1)
    a_s -= a[i]
    b_s += b[i]
    tmp = [a_s, b_s].max
    mn = tmp if mn > tmp
  end
  puts mn - b[-1]
end

def main
  gi.times { solve }
end

main


dist = ->zs, z1 { zs.map { |z2| (z2 - z1).abs }.sum }

gets.to_i.times do
  n = gets.to_i
  xys = n.times.map { gets.split.map(&:to_i) }
  p ([0, 1].map do |i|
      zs = xys.map { |xy| xy[i] }
      min = zs.min_by { |a| dist[zs, a] }
      mind = dist[zs, min]
      a = (0..min).bsearch { |i| dist[zs, i] == mind }
      b = (min..(10 ** 10)).bsearch { |i| dist[zs, i] > mind }
      (b - a).abs
    end).reduce(:*)
end

def solve(range, n)
  range.sort!

  return 1 if n % 2 == 1

  range[n/2] - range[n/2 - 1] + 1
end

cases = gets.chomp.to_i

cases.times do
  n = gets.chomp.to_i
  xs = []
  ys = []
  n.times do
    x, y = gets.chomp.split(" ").map(&:to_i)
    xs << x
    ys << y
  end
  puts solve(xs, n) * solve(ys, n)
end

def solve(range, n)
  range.sort!

  range[n/2] - range[(n - 1)/2] + 1
end

cases = gets.chomp.to_i

cases.times do
  n = gets.chomp.to_i
  xs = []
  ys = []
  n.times do
    x, y = gets.chomp.split(" ").map(&:to_i)
    xs << x
    ys << y
  end
  puts solve(xs, n) * solve(ys, n)
end

def solve(a)
    n = a.size
    a.sort!
    a[n / 2] - a[(n - 1) / 2] + 1
end
gets.to_i.times do
    n = gets.to_i
    x, y = [], []
    n.times do |i|
        cx, cy = gets.split.map &:to_i
        x << cx
        y << cy
    end
    puts solve(x) * solve(y)
end


gets.to_i.times do
  gets
  s=Array.new(8) {gets.chomp}
  puts s.include?('R'*8) ? 'R' : 'B'
end

t=gets.to_i
t.times do
    _=gets
    arr=Array.new(8){gets.chomp}
    puts ((arr.include? "R"*8)?"R":"B")
end

t=gets.to_i
t.times do
    _=gets
    arr=[]
    isHorizonal=false
    8.times do
        arr=gets.chomp
        if arr.count('R')==8
            isHorizonal=true
        end
    end
    if isHorizonal
        puts "R"
    else
        puts "B"
    end
end


n = gets.to_i
ary = gets.strip.split.map(&:to_i)
# tmp = ary.dup

sum = 0
ops = []
mod = 2100 # 500000

(n-1).downto(0).each do |i|
  v = ary[i]+sum
  v %= mod
  target = mod - (n-i)
  # puts "target:#{target}, v:#{v}"
  next if v == target
  xs = 0
  if target > v
    xs = target-v
  elsif target < v
    xs = mod+target-v
  end
  ops << "1 #{i+1} #{xs}"
  sum += xs
end
ops << "2 #{n} #{mod}"
puts ops.size
puts ops.join("\n")

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

puts n+1

def getdiff(elem,n,modn)
  k = elem/n
  req = k*n + modn
  if req<elem
    req += n
  end

  return req-elem
end

i = n-1
while(i>=0)
  toadd = getdiff(arr[i],n,i)
  j = 0
  while(j<=i)
    arr[j]+= toadd
    j = j+1
  end
  puts "1 #{i+1} #{toadd}"
  i = i-1
end

puts "2 #{n} #{n}"

=begin
(0..n-1).each do |i|
   arr[i] = arr[i]%n
end
p arr
=end

n = gets.to_i
ary = gets.strip.split.map(&:to_i)
# tmp = ary.dup

sum = 0
ops = []
mod = 2100 # 500000

(n-1).downto(0).each do |i|
  v = ary[i]+sum
  v %= mod
  target = mod - (n-i)
  # puts "target:#{target}, v:#{v}"
  next if v == target
  xs = 0
  if target > v
    xs = target-v
  elsif target < v
    xs = mod+target-v
  end
  ops << "1 #{i+1} #{xs}"
  sum += xs
end
ops << "2 #{n} #{mod}"
puts ops.join("\n")

n = gets.to_i
ary = gets.strip.split.map(&:to_i)
# tmp = ary.dup

sum = 0
ops = []
mod = 500000

(n-1).downto(0).each do |i|
  v = ary[i]+sum
  v %= mod
  target = mod - (n-i)
  # puts "target:#{target}, v:#{v}"
  next if v == target
  xs = 0
  if target > v
    xs = target-v
  elsif target < v
    xs = mod+target-v
  end
  ops << "1 #{i+1} #{xs}"
  sum += xs
end
ops << "2 #{n} #{mod}"
puts ops.join("\n")


# Codeforces My Practice
# author: Leonardone @ NEETSDKASU

def gs() gets.strip end
def gss() gs.split end
def gis() gss.map &:to_i end

H, W = gis
F = H.times.map do gs end
C = gs

x, y = 0, 0
H.times do |i|
    W.times do |j|
        if F[i][j] == 'S'
            x, y = j, i
        end
    end
end
SX, SY = x, y

MV = [:L, :U, :D, :R]

ans = MV.permutation.reduce(0) do |a, mv|
    x, y = SX, SY
    C.each_char do |ch|
        case mv[ch.to_i]
        when :L
            x -= 1
        when :U
            y -= 1
        when :D
            y += 1
        when :R
            x += 1
        end
        if !(0...W).include? x
            break
        end
        if !(0...H).include? y
            break
        end
        if F[y][x] == '#'
            break
        end
        if F[y][x] == 'E'
            a += 1
            break
        end
    end
    a
end

puts ans

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

maze = Array.new(n)
n.times do |i|
  maze[i] = gets.chomp
  S = [i, maze[i].index(?S)] if maze[i].include?(?S)
  G = [i, maze[i].index(?E)] if maze[i].include?(?E)
end

s = gets.chomp

ans = 0
%w(U D R L).permutation(4) do |a, b, c, d|

  R = S.dup
  i = [a, b, c, d]

  s.each_char do |c|

    d = i[c.to_i]

    if d == ?U
      R[0] += 1
    elsif d == ?D
      R[0] -= 1
    elsif d == ?R
      R[1] += 1
    else
      R[1] -= 1
    end

    break if R[0] < 0 ||  n <= R[0] || R[1] < 0 || m <= R[1] || maze[R[0]][R[1]] == ?#

    if R == G
      ans += 1
      break
    end
  end
end

puts ans

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

maze = Array.new(n)
n.times do |i|
  maze[i] = gets.chomp
  if maze[i].include?(?S)
    S = [i, maze[i].index(?S)]
  end
  if maze[i].include?(?E)
    G = [i, maze[i].index(?E)]
  end
end

# p [n,m]
# p [S, G]

s = gets.chomp

maze

ans = 0
%w(U D R L).permutation(4) do |a, b, c, d|

  R = S.dup
  # is_next = false

  i = [a, b, c, d]

  s.each_char do |c|

    d = i[c.to_i]

    if d == ?U
      R[0] += 1
    elsif d == ?D
      R[0] -= 1
    elsif d == ?R
      R[1] += 1
    else
      R[1] -= 1
    end

    if R[0] < 0 ||  n <= R[0] || R[1] < 0 || m <= R[1] || maze[R[0]][R[1]] == ?#
      # is_next = true
      break
    end

    if R == G
      ans += 1
      break
    end
  end

  # next if is_next
  # p R
  # if G == R
  #   ans += 1
  # end
end

puts ans

def valid_perm(n,m,arr,start_i,start_j,ends_i,ends_j,perm,str)

cur_i = start_i
cur_j = start_j

str.each do |c|

		ind =  perm.index(c)
		if ind==0 #up
			if cur_i - 1 <0 or arr[cur_i - 1][cur_j] == '#'
				return false
			elsif cur_i - 1 == ends_i and cur_j == ends_j
				return true
			end
			cur_i-=1
		elsif ind == 1 #down
			if cur_i + 1 >=n or arr[cur_i + 1][cur_j] == '#'
				return false
			elsif cur_i + 1 == ends_i and cur_j == ends_j

				return true
			end
			cur_i+=1

		elsif ind== 2 #left
			if cur_j - 1 <0 or arr[cur_i][cur_j-1] == '#'
				return false
			elsif cur_i  == ends_i and cur_j-1 == ends_j

				return true
			end
			cur_j-=1

		elsif ind==3 #right
			if c == "0" and perm.index(c)==3
	 		end
			if cur_j + 1 >=m or arr[cur_i ][cur_j+1] == '#'
				return false
			elsif cur_i  == ends_i and cur_j+1 == ends_j
				return true
			end
			cur_j+=1
		end
	end
return false
end

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

arr = []
start_i=0
start_j=0
ends_i=0
ends_j=0
(0...n).each do |i|
	s = gets.chomp.split('')
	if s.include?("S")
		start_i = i
		start_j = s.index("S")
	end
	if s.include?("E")
		ends_i = i
		ends_j = s.index("E")
	end
	arr<<s
end

str=gets.chomp.split('')
all_perm=["0","1","2","3"].permutation
count=0
all_perm.each do |perm|
	if valid_perm(n,m,arr,start_i,start_j,ends_i,ends_j,perm,str)

		count+=1
	end

end
puts count

#0:up,1:down,2:left,3:right

$dr = [0, 0, -1, 1]
$dc = [-1, 1, 0, 0]
p = [0, 1, 2, 3].permutation.to_a
$s = []
def check
  r = $sr
  c = $sc
  for i in (0...$x.length)
    if r == $er && c == $ec
      return true
    end
    r += $dr[$f[$x[i].to_i]]
    c += $dc[$f[$x[i].to_i]]
    if r < 0 || c < 0 || r >= $n || c >= $m || $s[r][c] == '#'
      return false
    end
  end
  return r == $er && c == $ec
end

g = gets.chomp.split(' ')
$n = g[0].to_i
$m = g[1].to_i
for i in (0...$n)
  g = gets.chomp
  $s.push(g)
  for j in (0...$m)
    if g[j] == 'S'
      $sr = i
      $sc = j
    end
    if g[j] == 'E'
      $er = i
      $ec = j
    end
  end
end
$x = gets.chomp
ans = 0
for i in (0...p.length)
  $f = p[i]
  ans += check ? 1 : 0
end
puts ans


a = [ gets.count("aeiou"), gets.count("aeiou"), gets.count("aeiou") ]
puts a==[5,7,5] ?"YES":"NO"

phrases = Array.new
phrases.push(gets.split(""))
phrases.push(gets.split(""))
phrases.push(gets.split(""))
if phrases[0].count("a") + phrases[0].count("e") + phrases[0].count("i") + phrases[0].count("o") + phrases[0].count("u") == 5 and\
   phrases[1].count("a") + phrases[1].count("e") + phrases[1].count("i") + phrases[1].count("o") + phrases[1].count("u") == 7 and\
   phrases[2].count("a") + phrases[2].count("e") + phrases[2].count("i") + phrases[2].count("o") + phrases[2].count("u") == 5
    puts "YES"
else
    puts "NO"
end

str = gets.split

first = 0
second = 0
third = 0

str.each{|s|
  loop{
    if s =~ /[aiueo]/
      s.sub!($&, "")
      first += 1
    else
      break
    end
  }
}

str = gets.split

str.each{|s|
  loop{
    if s =~ /[aiueo]/
      s.sub!($&, "")
      second += 1
    else
      break
    end
  }
}

str = gets.split

str.each{|s|
  loop{
    if s =~ /[aiueo]/
      s.sub!($&, "")
      third += 1
    else
      break
    end
  }
}

if first == 5
  if second == 7
    if third == 5
      puts "YES"
      exit
    end
  end
end

puts "NO"

a = gets().chomp
b = gets().chomp
c = gets().chomp

def check( c )
    if( c == "a" || c == "i" || c == "u" || c == "e" || c == "o" )
        return true
    else
        return false
    end
end

aa = 0
a.split(//).each{|chr| aa += 1 if(check(chr)) }

bb = 0
b.split(//).each{|chr| bb += 1 if(check(chr)) }

cc = 0
c.split(//).each{|chr| cc += 1 if(check(chr)) }

if( aa == 5 && bb == 7 && cc == 5 )
    puts "YES"
elsif
    puts "NO"
end

c = Array.new
3.times do |i|
	s = STDIN.gets
	c[i] = s.count('aiueo')
end
if c[0] == 5 && c[1] == 7 && c[2] == 5 then
	print "YES"
else
	print "NO"
end

v = 'aeiou'
if gets.count(v) == 5 && gets.count(v) == 7 && gets.count(v) == 5
  puts 'YES'
else
  puts 'NO'
end

[5, 7, 5].each { |c|
  unless gets.chomp.scan(/[aeiou]/).size == c
    puts 'NO'
    exit
  end
}
puts 'YES'

i=j=k=0
gets.chomp.gsub(/[aeiou]/){i+=1}
gets.chomp.gsub(/[aeiou]/){j+=1}
gets.chomp.gsub(/[aeiou]/){k+=1}
puts (i==5 and j==7 and k==5)?"YES":"NO"

input, heiku = STDIN.read.split("\n"), [5, 7, 5]
input.each_with_index { |v, k| (print :NO; exit) if v.count("aeiou") != heiku[k] }
print :YES

a = 3.times.map{gets.count('aeiou')}
puts a == [5, 7, 5] ? :YES : :NO

n = []
3.times do
n.push gets.tr('^aeiou', '').size
end
print n == [5, 7, 5] ? "YES" : "NO"

a=[gets,gets,gets]
l=[]
a.each{ |s|
        l.push(s.length)
}
for i in 0..2
        a[i]=a[i].gsub("a","")
        a[i]=a[i].gsub("o","")
        a[i]=a[i].gsub("u","")
        a[i]=a[i].gsub("i","")
        a[i]=a[i].gsub("e","")
end
if l[0]-a[0].length==5 && l[1]-a[1].length==7 && l[2]-a[2].length==5 then
        puts "YES"
else
        puts "NO"
end

def function
strings=Array.new(3)
counters=Array.new(3)
3.times do |i|
strings[i]=gets.chomp
end
t=/[aeiou]/
if strings[0].scan(t).length==5 && strings[1].scan(t).length==7 && strings[2].scan(t).length==5
print "YES"
else
print "NO"
end
end
function

a = gets.chomp
b = gets.chomp
c = gets.chomp
Vowels = ['a', 'e', 'i', 'o', 'u']
a_s = 0
for char in a.split('')
	a_s += 1 if Vowels.include?char
end
b_s = 0
for char in b.split('')
	b_s += 1 if Vowels.include?char
end
c_s = 0
for char in c.split('')
	c_s += 1 if Vowels.include?char
end
if a_s == 5 && b_s == 7 && c_s == 5
	puts "YES"
else
	puts "NO"
end

a=gets.chomp.split('')
b=gets.chomp.split('')
c=gets.chomp.split('')
x=0
y=0
z=0
a.each do |i|
	if i=='a' || i=='e' || i=='i' || i=='o' || i=='u'
		x+=1
	end
end
b.each do |i|
	if i=='a' || i=='e' || i=='i' || i=='o' || i=='u'
		y+=1
	end
end
c.each do |i|
	if i=='a' || i=='e' || i=='i' || i=='o' || i=='u'
		z+=1
	end
end
if x==5 && y==7 && z==5
	puts "YES"
else
	puts "NO"
end

a = readlines.map(&:strip)
if a[0].gsub(/[aeiou]/).to_a.size == 5 and a[1].gsub(/[aeiou]/).to_a.size == 7 and a[2].gsub(/[aeiou]/).to_a.size == 5
  puts :YES
else
  puts :NO
end

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

a = 3.times.map{ gets.count('aeiou') }
puts a == [5,7,5] ? "YES" : "NO"

v = 'aeiou'
if gets.count(v) == 5 || gets.count(v) == 7 || gets.count(v) == 5
  puts 'YES'
else
  puts 'NO'
end


n = gets.chomp.to_i
m = gets.chomp.to_i
a = []
for i in 1..n do
  a.push(gets.chomp.to_i)
end

a = a.sort.reverse
count = 0
while m > 0 do
  m -= a[count]
  count += 1
end

puts count

a=(1..gets.to_i)
b=gets.to_i
a=a.map{gets.to_i}.sort
c=0
while b > 0
  c += 1
  b -= a.pop
end
p c

#! ruby
# Try Codeforces
# author: Leonardone @ NEETSDKASU
############################################################
def gs() gets.chomp end
def gi() gets.to_i end
def gss() gs.split end
def gis() gss.map(&:to_i) end
def nmapf(n,f) n.times.map{ __send__ f } end
def arr2d(h,w,v=0) h.times.map{[v] * w} end
def ngs(n) nmapf n,:gs end
def ngi(n) nmapf n,:gi end
def ngss(n) nmapf n,:gss end
def ngis(n) nmapf n,:gis end
def for2p(hr,wr,&pr) hr.each{|i|wr.each{|j| yield(i,j)}} end
def nsum(n) n * (n + 1) / 2 end
############################################################

n, m = ngi 2
a = ngi(n).sort.reverse
c = 0
s = 0
a.each do |v|
    s += v
    c += 1
    break if s >= m
end
puts c

n = gets.chomp.to_i
m = gets.chomp.to_i
arr = Array.new(n)
n.times do |i|
  arr[i] = gets.chomp.to_i
end
arr = arr.sort ; arr = arr.reverse
sum = 0 ; res = 0
while sum < m
  sum+=arr[0] ; arr.shift ; res+=1
end
puts res

n=gets.chomp.to_i
size=gets.chomp.to_i
file_arry=[]
0.upto(n-1) do |i|
	file_arry[i]=gets.chomp.to_i
end
file_arry=file_arry.sort.reverse
k=0
output=0
loop do
	k=k+file_arry[output]
	output+=1
	break if k>=size
end
puts output

n = gets.to_i
m = gets.to_i
as = []
n.times do
  as << gets.to_i
end
as.sort!.reverse!
p = 0
while m > 0 do
  m -= as[p]
  p += 1
end
puts p

n=gets.chomp.to_i
size=gets.chomp.to_i

data=[]

a=0
while a<n
	b=gets.chomp.to_i
	data.push(b)
	a+=1
end

data.sort!

k=data.length-1
sum=0
x=0
for i in(0..data.length-1)
	sum+=data[k-i]
	x+=1
	if sum>=size
		break
	end
end

puts x

n=gets.to_i
m=gets.to_i
xs=[]
n.times{
	xs<<(gets.to_i)
}
ans=0
xs.sort.reverse.each{|e|
	m-=e
	ans+=1
	break if m<=0
}
puts ans

#!usr/bin/env ruby

a = []
n = gets.to_i
m = gets.to_i
n.times {
  a << gets.to_i
}

a.sort!
a.reverse!

b = 0
c = 0
while b < m
  c += 1
  b += a.shift
end

puts c

t = gets.to_i
m = gets.to_i
arr1 = Array.new(t)
index=0
t.times do
	arr1[index] = gets.to_i
	index+=1
end

arr1.sort!
sum=m
index=t-1
count=0
while m>0
	count+=1
	m = m - arr1[index]
	index-=1
end
puts count

# coding: utf-8

n = gets.to_i
m = gets.to_i
ar = []
n.times {
    ar << gets.to_i
}
ar.sort!
sticks = 0
while m > 0
    cap = ar.pop
    sticks += 1
    m -= cap
end
puts sticks

carts = gets.to_i
file_mb = gets.to_i

cart = Array.new(carts)

for i in 0..carts-1
	cart[i]= gets.chomp.to_i
end

cart = cart.sort.reverse

sum = 0
num = 0
for i in 0..carts-1
	sum += cart[i]
	num +=1
	if sum >= file_mb
		puts num
		exit
	end
end

n = gets.to_i
m = gets.to_i
a = []
(1..n).each do
  a.push gets.to_i
end

a.sort!
t = 0
tmp = 0
(0...n).each do |i|
  tmp +=a[n-i-1]
  t +=1
  break if tmp >= m
end

puts t

n = gets.chomp.to_i
m = gets.chomp.to_i
a = []
n.times do
  a << gets.chomp.to_i
end
res = 0
a.sort.reverse.each do |i|
  break if m <= 0
  m -= i
  res += 1
end
puts res

n = gets.to_i
m = gets.to_i
a = Array.new(n)
for i in 0..n-1
    a[i] = gets.to_i
end
a = a.sort {|x,y| y <=> x}
k = 0
for item in a
    if m <= 0
        break
    end
    k += 1
    m -= item
end
puts k

n = gets.to_i
m = gets.to_i
arr = []
for i in 0..n-1
    arr[i] = gets.to_i
end

arr = arr.sort
count = 0
idx = n-1
while m > 0
    m -= arr[idx]
    idx -= 1
    count += 1
end

puts count

n = gets.to_i
m = gets.to_i
a = []
n.times { a << gets.to_i }
a.sort!.reverse!
s = 0
(0...a.size).each do |i|
  s += a[i]
  if s >= m
    puts i + 1
    exit
  end
end

n = gets.chomp.to_i
m = gets.chomp.to_i

flash_drives = Array.new
n.times {|i| flash_drives << gets.chomp.to_i}

flash_drives.sort!

k = 0
while m > 0 do
	m = m - flash_drives[n - k - 1]
	k = k + 1
end

print k

t = gets.chomp
t = t.to_i
n = gets.chomp
n = n.to_i
v = []
for i in 1 ..t do
 v << gets.chomp
end
v = v.map(&:to_i)
c=0
s=0
v.sort.reverse.each do |num|
s = s+num
if s >= n
c=c+1
break
else
c=c+1
end
end
puts c

class Solver
	def main
		n = gets.to_i
		m = gets.to_i
		a = []
		n.times do
			a << gets.to_i
		end
		a = a.sort.reverse
		ans = 0
		a.each do |x|
			if m > 0
				m -= x
				ans += 1
			end
		end
		puts ans
	end
end
Solver.new.main

a=(1..gets.to_i).map{gets.to_i}.sort.reverse
b=gets.to_i
c=0
while b > 0
  c += 1
  b -= a.shift
end
p c

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


gets.to_i.times do
  gets
  puts (gets =~ /8\d{10}/ ? :YES : :NO)
end

for x in 1..gets.to_i
    len = gets.to_i
    str = gets
    idx = str.index('8')
    if idx.nil? || len - idx < 11
        puts "NO"
    else
        puts "YES"
    end
end

t = gets.to_i
t.times do
	s = gets.to_i
	n = gets
	flag = true
	for e in 0...s
		if(n[e] == '8')
			if(s-e >= 11)
				puts("YES")
				flag = false
				break
			end
		end
	end
	if(flag)
		puts("NO")
	end
end

gets.to_i.times do
  d = gets.to_i
  num = gets.chomp.index('8')
  puts num && d - num >= 11 ? 'YES' : 'NO'
end

T = gets.to_i
T.times do
	n = gets.to_i
	str = gets.chomp
	if str.index('8')
		if str.size - str.index('8') >= 11
			puts "YES"
			next
		end
	end
	puts "NO"
end

t = gets.to_i
for i in 0...t do
  n = gets.to_i
  s = gets.chomp
  flag = false
  for j in 0..(n-11) do
    if s[j] == '8'
      flag = true
      break
    end
  end
  puts flag ? "YES" : "NO"
end

t = gets.to_i
t.times do
	s = gets.to_i
	n = gets
	for e in 0...s
		flag = true
		if(n[e] == '8')
			if(s-e-1 >= 11)
				puts("YES")
				flag = false
				break
			end
		end
	end
	if(!flag)
		puts("NO")
	end
end

t = gets.to_i
t.times do
	s = gets.to_i
	n = gets
	flag = true
	for e in 0...s
		if(n[e] == '8')
			if(s-e-1 >= 11)
				puts("YES")
				flag = false
				break
			end
		end
	end
	if(flag)
		puts("NO")
	end
end

for x in 1..gets.to_i
    len = gets.to_i
    str = gets
    if str.index('8').nil? || len - str.index('8') < 10
        puts "NO"
    else
        puts "YES"
    end
end

cases = gets
for x in 1..cases.to_i
    len = gets.to_i
    str = gets
    if str.index('8').nil? || len - str.index('8') < 10
        puts "NO"
    else
        puts "YES"
    end
end


# ProblemC
require 'bigdecimal'
require 'bigdecimal/math'
include BigMath
include Math
n, a, d = gets.split().map {|s| s.to_i}

prev = 0.0
tm = sqrt((2 * d) / a.to_f)

n.times do
  t, v = gets.split().map {|s| s.to_i}
  ti = v / a.to_f
  tt = t.to_f
  if tm <= ti
    tt += tm
  else
    dm = (a * ti * ti) / 2.0
    tr = (d - dm) / v.to_f
    tt += tr + ti
  end
  if prev > tt
    puts prev
  else
    puts tt
    prev = tt
  end
end

#!/usr/bin/ruby

n, a, d = $stdin.gets.chomp.split.map(&:to_i)
prev = 0.0
n.times do
  t, v = $stdin.gets.chomp.split.map(&:to_f)
  l = v*v/(2.0*a)
  x =
    if l < d
      u = v/a.to_f
      u + (d-l)/v.to_f
    else
      Math.sqrt(2.0*d/a.to_f)
    end
  ans = [x+t, prev].max
  printf "%.5f\n", ans
  prev = ans
end

# ProblemC
include Math
n, a, d = gets.split().map {|s| s.to_i}

prev = 0.0
tm = sqrt((2 * d) / a.to_f)

n.times do
  t, v = gets.split().map {|s| s.to_i}
  ti = v / a.to_f
  tt = t.to_f
  if tm <= ti
    tt += tm
  else
    dm = (a * ti * ti) / 2.0
    tr = (d - dm) / v.to_f
    tt += tr + ti
  end
  if prev > tt
    puts prev
  else
    puts tt
  end
  prev = tt
end


def danger(x, y, xx, yy, xxx, yyy)
  dx, dy, ddx, ddy = xx - x, yy - y, xxx - xx, yyy - yy
  return ddx * dy - ddy * dx < 0
end

n = readline.to_i
x, y = readline.split(' ').collect(&:to_i)
xx, yy = readline.split(' ').collect(&:to_i)
ret = 0
(n - 1).times do
  xxx, yyy = readline.split(' ').collect(&:to_i)
  ret += 1 if danger(x, y, xx, yy, xxx, yyy)
  x, y, xx, yy = xx, yy, xxx, yyy
end

puts ret

def get_dir(dx, dy)
	return 0 if dy>0
	return 2 if dy<0
	return 1 if dx>0
	return 3 if dx<0
end

def calc(dir, last_dir)
	return 1 if last_dir == (dir+1)%4
	return 0
end

n=gets.to_i
p=Array.new
ans=dir=last_dir=0
for i in 0..n
	buf=gets.split(' ')
	p[i] = [buf[0].to_i, buf[1].to_i]
	dir = get_dir(p[i][0]-p[i-1][0], p[i][1] - p[i-1][1]) if i>0
	ans += calc(dir, last_dir) if i>1
	last_dir = dir
end
puts ans


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

  x = 0
  1000.times do |i|
    if a.include? i
      a[a.index(i)] = -999
    else
      x = i
      break
    end
  end

  y = 0
  1000.times do |i|
    if a.include? i
      a[a.index(i)] = -999
    else
      y = i
      break
    end
  end

  p x+y
end

gets.to_i.times{gets
t=gets.split.map &:to_i
p [1,2].map{|x|(0..t.max+1).map{|x|t.count x}.find_index{|y|y<x}}.sum}

gets;$<.map{t=gets.split.map &:to_i
p [1,2].map{|x|(0..200).map{|x|t.count x}.find_index{|y|y<x}}.sum}

T = gets.to_i

T.times do
  n = gets.to_i
  a = gets.split.map(&:to_i).sort
  counter = a.tally
  counter.default = 0

  if n <= 1
    if a.first == 0
      puts 1
    else
      puts 0
    end

    next
  end

  vals = [-1, -1]

  0.upto(101) do |x|
    next if counter[x] >= 2

    if counter[x] == 1
      vals[0] = x + 1
      vals[1] = x if vals[1] == -1
    else
      vals[0] = x
      vals[1] = x if vals[1] == -1

      break
    end
  end

  puts vals.sum
end


def min_rpst(x)
	if x.length.even?
		m = x.length / 2
		p = x[0...m]
		q = x[m..-1]
		p = min_rpst p
		q = min_rpst q
		x = p < q ? p + q : q + p
	end
	x
end

s1 = gets.strip
s2 = gets.strip
puts (min_rpst(s1) == min_rpst(s2)) ? "YES" : "NO"

$MOD = 1000000000000000003

def pow2?(n)
    return true if n == 0 || n == 1
    return false if n < 0 || n % 2 == 1
    return pow2?(n / 2)
end

def get_hash(s)
    #p s
    return s[0].ord if s.size == 1
    m = s.size / 2
    h1 = get_hash(s[0..m-1])
    h2 = get_hash(s[m..2 * m])
    return ((h1 + h2) * h1 * h2) % $MOD
end

def eq(s1,s2)
    return true if (s1 == s2)
    return false if (s1.size != s2.size) || (s1.size % 2 == 1)
    if pow2?(s1.size)
        return get_hash(s1) == get_hash(s2)
    end

    m = s1.size / 2
    s11 = s1[0..m - 1]
    s12 = s1[m, 2 * m]
    s21 = s2[0..m - 1]
    s22 = s2[m, 2 * m]
    return true if eq(s11,s21) && eq(s12,s22) || eq(s12,s21) && eq(s11,s22)
    return false
end

s1 = gets.strip
s2 = gets.strip
puts (eq(s1,s2) ? 'YES' : 'NO')

def eq_hash(s1,s2)
    base = 7
    mod = 1000000000000000003
    return true if s1 == s2
    return false if (s1.size % 2 == 1) || (s2.size % 2 == 1) ||
            (s1.size != s2.size)
    hash1 = 0
    hash2 = 0
    s1.size.times do |i|
            hash1 += base ** s1[i].ord
            hash2 += base ** s2[i].ord
            hash1 %= mod
            hash2 %= mod
    end

    return hash1 == hash2
end

#p prime? gets.to_i
#100.times {|i| p i if prime? i }
#n = 10 ** 18 + 1
#while !prime? n do
#    n += 2
#end
#p n
s1 = gets.strip
s2 = gets.strip
p (eq_hash(s1,s2) ? "YES" : "NO")

# def prime?(n)
#     return true if n == 2
#     return false if n < 2 || (n % 2 == 0)
#     i = 3
#     while i * i <= n do
# 	return false if n % i == 0
# 	i += 2
#     end
#     return true
# end

def eq_hash(s1,s2)
    base = 7
    mod = 1000000000000000003
    return true if s1 == s2
    return false if (s1.size % 2 == 1) || (s2.size % 2 == 1) ||
	    (s1.size != s2.size)
    hash1 = 0
    hash2 = 0
    s1.size.times do |i|
	    hash1 += base ** s1[i].ord
	    hash2 += base ** s2[i].ord
	    hash1 %= mod
	    hash2 %= mod
    end

    return hash1 == hash2
end

#p prime? gets.to_i
#100.times {|i| p i if prime? i }
#n = 10 ** 18 + 1
#while !prime? n do
#    n += 2
#end
#p n
s1 = gets.strip
s2 = gets.strip
puts (eq_hash(s1,s2) ? 'YES' : 'NO')


n, t = gets.split.map(&:to_i)
mn = 2147483647
idx = -1

n.times do |i|
  s, d = gets.split.map(&:to_i)
  x = ((t-s).to_f/d).ceil

  if x < 0
    x = 0
  end

  if mn > s+d*x
    mn = s+d*x
    idx = i+1
  end
end

p idx

n,t = gets.split.map(&:to_i)
min = 10 ** 6
ans = 0
n.times do |i|
  s,d = gets.split.map(&:to_i)
  if s > t
    tmp = s
  else
    tmp = ((t-s)/d.to_f).ceil * d + s
  end
  if tmp < min
    min = tmp
    ans = i+1
  end
  #p tmp
end
p ans

N, T = gets.split.map(&:to_i)

buses = N.times.map { gets.split.map(&:to_i) }

ans = -1
time = Float::INFINITY

buses.each.with_index(1) do |(s, d), i|
  t = if s >= T
        s
      else
        s + d * ((T - s) / d.to_f).ceil
      end

  if time > t
    time = t
    ans = i
  end
end

puts ans

n, t = gets.chomp.split(" ").map(&:to_i)
ret = 10**5
ans = -1
n.times do |i|
  s, d = gets.chomp.split(" ").map(&:to_i)
  while true
    if s >= t
      st = s - t
      if ret > st
        ret = st
        ans = i + 1
      end
      break
    end
    s += d
  end
end
puts ans


t = gets.to_s.to_i
1.upto(t) do |casenum|
  n, k = gets.to_s.split.map {|x| x.to_i }
  a = gets.to_s.split.map {|x| x.to_i }
  i = 0
  k.times do
    while a[i] == 0 && i < a.size - 1
      i += 1
    end
    if a[i] > 0 && i < a.size - 1
      a[i] -= 1
      a[-1] += 1
    end
  end
  printf("%s\n", a.join(" "))
end

def solution(arr, n, k)
  i = 0

  while i < n - 1 && k > 0
    if arr[i] == 0
      i += 1
      next
    end

    arr[i] -= 1
    arr[n - 1] += 1
    k -= 1
  end

  arr
end

test_cases = gets.to_i

test_cases.times do |test_case|
  n, k = gets.split(' ').map(&:to_i)
  arr = gets.split(' ').map(&:to_i)
  res = solution(arr, n, k)

  puts res.join(' ')
end

t = Integer(gets.chomp)
t.times{
    n, k = gets.chomp.split().map!{|c| Integer(c)}
    a = gets.chomp.split().map!{|c| Integer(c)}

    l = 0
    until k == 0 || l == n-1 do
        if(a[l] > k)
            a[l] -= k
            a[n - 1] += k
            k = 0
        else
            k -= a[l]
            a[n-1] += a[l]
            a[l] = 0
            l += 1
        end
    end

    a.each do |e| print "#{e} " end
    puts ""
}

test_cases = gets.chomp.to_i
for i in 1..test_cases do
    line = gets.chomp.split(" ")
    n = line[0].to_i
    k = line[1].to_i
    a = gets.chomp.split(" ")
    b = Array.new(n)
    for j in 0..n - 1 do
        b[j] = a[j].to_i
    end
    for j in 0..n - 1 do
        d = [k, b[j]].min
        b[j] -= d
        b[n - 1] += d
        k -= d
        if k == 0
            break
        end
    end
    for j in 0..n - 1 do
        print "#{b[j]} "
    end
    puts ""
end

def solution(arr, n, k)
  i = 0

  while i < n - 1 && k > 0
    i += 1 if arr[i] == 0
    arr[i] -= 1
    arr[n - 1] += 1
    k -= 1
  end

  arr
end

test_cases = gets.to_i

test_cases.times do |test_case|
  n, k = gets.split(' ').map(&:to_i)
  arr = gets.split(' ').map(&:to_i)
  res = solution(arr, n, k)

  puts res.join(' ')
end

def solution(arr, n, k)
  i = 0

  while arr[i] >= 0 && k > 0 && i < n - 1
    break if arr[i] == 0
    arr[i] -= 1
    arr[n - i - 1] += 1
    k -= 1
    i += 1 if arr[i] < 1
  end

  arr
end

test_cases = gets.to_i

test_cases.times do |test_case|
  n, k = gets.split(' ').map(&:to_i)
  arr = gets.split(' ').map(&:to_i)
  res = solution(arr, n, k)

  puts res.join(' ')
end

def solution(arr, n, k)
  i = 0

  while arr[i] >= 0 && k > 0 && i < n - 1
    arr[i] -= 1
    arr[n - i - 1] += 1
    k -= 1
    i += 1 if arr[i] == 0
    # puts arr.join(' ')
  end

  arr
end

test_cases = gets.to_i

test_cases.times do |test_case|
  n, k = gets.split(' ').map(&:to_i)
  arr = gets.split(' ').map(&:to_i)
  res = solution(arr, n, k)

  puts res.join(' ')
end

def solution(arr, n, k)
  i = 0

  while i < n && arr[i] > 0 && k > 0
    arr[i] -= 1
    arr[n - i - 1] += 1
    k -= 1
    i += 1 if arr[i] == 1
  end

  arr
end

test_cases = gets.to_i

test_cases.times do |test_case|
  n, k = gets.split(' ').map(&:to_i)
  arr = gets.split(' ').map(&:to_i)
  res = solution(arr, n, k)

  puts res.join(' ')
end


n=gets.to_i
a=gets.split(" ").map(&:to_i)
h=Hash.new
zeroIndex=-1
for i in 0...n
	if a[i]==0
		zeroIndex=i
		h[i]=0
	else
		if zeroIndex>=0
			h[i]=i-zeroIndex
		else
			h[i]=n
		end
	end
end
zeroIndex=-1
for i in (n-1).downto(0)
	if a[i]==0
		zeroIndex=i
	else
		if zeroIndex>=0
			h[i]=[h[i],zeroIndex-i].min
		end
	end
end
puts h.values.join(" ")

n=gets.chomp
a=gets.chomp.split.map!{|x| x.to_i}
last=-a.size
a.each_index do |i|
    last = i if a[i]==0
    a[i]=i-last
end
a.reverse!

last=-a.size
a.each_index do |i|
    last = i if a[i]==0
    a[i]=i-last if a[i]>i-last
end
a.reverse!
puts a * ' '

#!/usr/bin/ruby
n,*a=$<.read.split.map &:to_i
z=[-Float::INFINITY]+(0...n).select{|i|a[i]==0}+[Float::INFINITY]
puts (0...n).map{|i|
	idx=((0...z.size).bsearch{|j|z[j]>=i}||z.size)-1
	[i-z[idx],z[idx+1]-i].min
}*' '

size = gets.chomp.to_i
values = gets.chomp.split(' ').map!(&:to_i)

indexes = values.each_with_object([]).with_index do |(value, obj), index|
  obj << index if value.zero?
end

result = []
left = nil
right = indexes.shift

size.times do |index|
  #puts "left: #{left} right: #{right} tested: #{index}"
  distance_to_left = (index - (left || right)).abs
  distance_to_right = (index - (right || left)).abs

  result << [distance_to_left, distance_to_right].min # pohybujeme se v mantinelu
  # mantinel posuneme jakmile prejdeme pres index
  if index == right
    left = right
    right = indexes.shift
  end
end

puts result.join(' ')

n=gets.chomp
a=gets.chomp.split.map!{|x| x.to_i}
last=-a.size
a.each_index do |i|
    last = i if a[i]=='0'
    a[i]=i-last
end
a.reverse!

last=-a.size
a.each_index do |i|
    last = i if a[i]==0
    a[i]=i-last if a[i]>i-last
end
a.reverse!
puts a

size = gets.chomp.to_i
values = gets.chomp.split(' ').map!(&:to_i)

indexes = values.each_with_object([]).with_index do |(value, obj), index|
  obj << index if value.zero?
end

result = []
left = nil
right = indexes.shift

size.times do |index|
  puts "left: #{left} right: #{right} tested: #{index}"
  distance_to_left = (index - (left || right)).abs
  distance_to_right = (index - (right || left)).abs

  result << [distance_to_left, distance_to_right].min # pohybujeme se v mantinelu
  # mantinel posuneme jakmile prejdeme pres index
  if index == right
    left = right
    right = indexes.shift
  end
end

puts result.join(' ')


gets.to_i.times do
  n = gets.to_i
  a = gets.split.map{|e| e.to_i % 10}
  at = a.tally
  new_a = []
  at.each do |k,v|
    [v,3].min.times do
      new_a << k
    end
  end

  ans = false
  m = new_a.size
  m.times do |i|
    m.times do |j|
    next if i == j
      m.times do |k|
        next if i == k || k == j

        if (new_a[i]+new_a[j]+new_a[k])%10 == 3
          ans = true
          break
        end
      end
      break if ans
    end
    break if ans
  end

  puts ans ? "YES" : "NO"
end

def solve
    n = gets.to_i
    a = gets.split.map(&:to_i)
    cnt = Array.new(10)
    cnt2 = Array.new(10)
    i = 0
    while i < n
        a[i] = a[i] % 10
        i = i + 1
    end
    i = 0
    while i < 10
        cnt[i] = 0
        cnt2[i] = 0
        i = i + 1
    end
    a.each do |i|
        cnt[i] = cnt[i] + 1
    end
    ok = false
    i = 0
    while i < 10
        j = 0
        cnt2[i] = cnt2[i] + 1
        while j < 10
            cnt2[j] = cnt2[j] + 1
            k = 0
            while k < 10
                cnt2[k] = cnt2[k] + 1
                x = (i + j + k) % 10
                if cnt[i] >= cnt2[i] and cnt[j] >= cnt2[j] and cnt[k] >= cnt2[k] and x == 3
                    ok = true
                end
                cnt2[k] = cnt2[k] - 1
                k = k + 1
            end
            cnt2[j] = cnt2[j] - 1
            j = j + 1
        end
        cnt2[i] = cnt2[i] - 1
        i = i + 1
    end
    if ok == true
        puts "YES"
    else
        puts "NO"
    end
end

gets.to_i.times do
    solve
end

# 和が 3 になる組み合わせを列挙
combinations = []
(0 .. 9).each do |x|
    (x .. 9).each do |y|
        (y .. 9).each do |z|
            if (x + y + z) % 10 == 3
                counts = [0] * 10
                counts[x] += 1
                counts[y] += 1
                counts[z] += 1
                combinations << counts
            end
        end
    end
end

t = gets.to_i
t.times do
    n = gets.to_i
    a = gets.split.map(&:to_i)

    counts = [0] * 10
    a.each do |x|
        counts[x % 10] += 1
    end

    ans = combinations.any? { |counts2| (0 .. 9).all? { |x| counts[x] >= counts2[x] } }
    puts ans ? "YES" : "NO"
end

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

        count = [0] * 10
        a.each do |x|
            count[x % 10] += 1
        end

        yesno ((0 ... 10).any? do |x|
            next false if count[x] == 0
            count[x] -= 1
            b = (x ... 10).any? do |y|
                next false if count[y] == 0
                count[y] -= 1
                c = (y ... 10).any? do |z|
                    next false if count[z] == 0
                    (x + y + z) % 10 == 3
                end
                count[y] += 1
                c
            end
            count[x] += 1
            b
        end)
    end
}

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

require "set"
require "prime"

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

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

class TrueClass
  include Boolean
  def to_i; 1 end
end

class FalseClass
  include Boolean
  def to_i; 0 end
end

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

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

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

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

main[]

def solve(a)
  arr = gets.split.map(&:to_i).map { |number| number.modulo(10) }

  hash = Hash.new(0)

  arr.each do |n|
    hash[n] = hash[n] > 3 ? 3 : hash[n].succ
  end

  numbers = []
  hash.each_key do |key|
    while hash[key] > 0
      numbers.push(key)
      hash[key] -= 1
    end
  end

  (0...numbers.size).each do |i|
    ((i + 1)...numbers.size).each do |j|
      ((j + 1)...numbers.size).each do |k|
        if (numbers[i] + numbers[j] + numbers[k]) % 10 == 3
          puts "YES"
          return
        end
      end
    end
  end

  puts "NO"
end

n = gets.to_i

n.times do
  a = gets.to_i
  solve(a)
end

array = []
0.upto(9) do |a|
  0.upto(9) do |b|
    0.upto(9) do |c|
      array << [a, b, c] if (a + b + c) % 10 == 3
    end
  end
end

gets.to_i.times do
  gets
  xs = gets.split.map(&:to_i)
  map = Hash.new(0)
  xs.each do |x|
    map[x % 10] += 1
  end
  ok = array.any? { |array| 0.upto(9).all? { |d| array.count(d) <= map[d] } }
  puts ok ? "YES" : "NO"
end

def solve
    n = gets.to_i
    a = gets.split.map(&:to_i)
    cnt = Array.new(10)
    cnt2 = Array.new(10)
    pairs = Array.new(n) {Array.new(10)}
    i = 0
    while i < n
        j = 0
        while j < 10
            pairs[i][j] = 0
            j = j + 1
        end
        i = i + 1
    end
    i = 0
    while i < 10
        cnt[i] = 0
        cnt2[i] = 0
        i = i + 1
    end
    a.each do |x|
        i = x % 10
        cnt[i] = cnt[i] + 1
    end
    id = 0
    a.each do |x|
        i = x % 10
        j = 0
        cnt[i] = cnt[i] - 1
        while j < 10
            k = (i + j) % 10
            cnt2[k] = cnt2[k] + cnt[j]
            pairs[id][k] = pairs[id][k] + cnt[j]
            j = j + 1
        end
        cnt[i] = cnt[i] + 1
        id = id + 1
    end
    id = 0
    ok = false
    a.each do |x|
        i = x % 10
        j = 0
        while j < 10
            cnt2[j] = cnt2[j] - pairs[id][j]
            j = j + 1
        end
        j = 0
        while j < 10
            k = (i + j) % 10
            if k == 3 and cnt2[j] > 0
                ok = true
            end
            j = j + 1
        end
        j = 0
        while j < 10
            cnt2[j] = cnt2[j] + pairs[id][j]
            j = j + 1
        end
        id = id + 1
    end
    if ok == true
        puts "YES"
    else
        puts "NO"
    end
end

gets.to_i.times do
    solve
end

def solve
    n = gets.to_i
    a = gets.split.map(&:to_i)
    cnt = Array.new(10)
    cnt2 = Array.new(10)
    pairs = Array.new(n) {Array.new(10)}
    i = 0
    while i < n
        j = 0
        while j < 10
            pairs[i][j] = 0
            j = j + 1
        end
        i = i + 1
    end
    i = 0
    while i < 10
        cnt[i] = 0
        cnt2[i] = 0
        i = i + 1
    end
    a.each do |x|
        i = x % 10
        cnt[i] = cnt[i] + 1
    end
    id = 0
    a.each do |x|
        i = x % 10
        j = 0
        cnt[i] = cnt[i] - 1
        while j < 10
            k = (i + j) % 10
            cnt2[k] = cnt2[k] + cnt[j]
            pairs[id][k] = pairs[id][k] + cnt[j]
            j = j + 1
        end
        cnt[i] = cnt[i] + 1
        id = id + 1
    end
    id = 0
    ok = false
    a.each do |x|
        i = x % 10
        j = 0
        while j < 10
            cnt2[j] = cnt2[j] - pairs[id][j]
            j = j + 1
        end
        j = 0
        while j < 10
            k = (i + j) % 10
            if k == 3 and cnt2[j] > 0
                ok = true
            end
            j = j + 1
        end
        j = 0
        while j < 10
            cnt2[j] = cnt2[j] + pairs[id][j]
            j = j + 1
        end
    end
    if ok == true
        puts "YES"
    else
        puts "NO"
    end
end

gets.to_i.times do
    solve
end

def solve
    n = gets.to_i
    a = gets.split.map(&:to_i)
    cnt = Array.new(10)
    cnt2 = Array.new(10)
    pairs = Array.new(n) {Array.new(10)}
    i = 0
    while i < n
        j = 0
        while j < 10
            pairs[i][j] = 0
            j = j + 1
        end
        i = i + 1
    end
    i = 0
    while i < 10
        cnt[i] = 0
        cnt2[i] = 0
        i = i + 1
    end
    a.each do |x|
        i = x % 10
        cnt[i] = cnt[i] + 1
    end
    id = 0
    a.each do |x|
        i = x % 10
        j = 0
        cnt[i] = cnt[i] - 1
        while j < 10
            k = (i + j) % 10
            cnt2[k] = cnt2[k] + cnt[j]
            pairs[id][k] = pairs[id][k] + cnt[j]
            j = j + 1
        end
        cnt[i] = cnt[i] + 1
        id = id + 1
    end
    id = 0
    ok = false
    a.each do |x|
        i = x % 10
        j = 0
        while j < 10
            k = (i + j) % 10
            cnt2[k] = cnt2[k] - pairs[id][k]
            if k == 3 and cnt2[k] > 0
                ok = true
            end
            j = j + 1
        end
        j = 0
        while j < 10
            k = (i + j) % 10
            cnt2[k] = cnt2[k] + pairs[id][k]
            j = j + 1
        end
    end
    if ok == true
        puts "YES"
    else
        puts "NO"
    end
end

gets.to_i.times do
    solve
end

gets.to_i.times do
  n = gets.to_i
  a = gets.split.map{|e| e.to_i % 10}
  at = a.tally
  new_a = []
  at.each do |k,v|
    [v,2].min.times do
      new_a << k
    end
  end

  ans = false
  m = new_a.size
  m.times do |i|
    m.times do |j|
      next if i == j
      k = new_a[i]+new_a[j]
      if k <= 3
        ans = true if !at[(3-k)].nil?
      elsif k <= 13
        ans = true if !at[(13-k)].nil?
      elsif k <= 23
        ans = true if !at[(23-k)].nil?
      end
      break if ans
    end
    break if ans
  end

  puts ans ? "YES" : "NO"
end