n = gets.to_i
op = Hash.new "PLR"
op[0] = "PRL"
gets.split(' ',n).map(&:to_i).each_with_index do |x,id|
  if id == 0
    print "PRL" * x
  else
    print "R"
    print "PLR" * x
  end
end

n = Integer(gets)
input = gets.chomp
nums = input.split
a = Array.new
for i in 0...n
    a[i] = Integer(nums[i])
end
sov = Array.new
if a[0] != 0
    sov[0] = "PRL" * (a[0]-1) + "P"
else
    sov[0] = nil
end
b = Array.new
for i in  1...n
    if a[i] >= 1
        b[i] = "RPL" * (a[i]-1) + "RP"
    else  a[i] == 0
        b[i] = "R"
    end

    sov.push(b[i])
end
print sov.join

n=gets.to_i
d=gets.split.map(&:to_i)
ans=''
n.times do |i|
    if i == 0
        ans+= 'RLP'*d[i]
    else
        ans+= 'LRP'*d[i]
    end
    ans+='R'
end
puts ans[0..-2]

n=gets.to_i
a=gets.split.map(&:to_i)
print 'PRL'*a[0]
(1..n-1).each{|i|print 'R','PLR'*a[i]}

n=gets.to_i
a=gets.split.map(&:to_i)
x=0
s=''
loop do
  (a[x]-=1;s<<'P')if a[x]>0
  if x==0
    x+=1
    s<<'R'
  elsif a[x-1]>0 || a[x]>0
    x-=1
    s<<'L'
  elsif x==n-1
    if a[x]>0
      x-=1
      s<<'L'
    else
      break
    end
  elsif
    x+=1
    s<<'R'
  end
end
puts s

n = gets.to_i
a = gets.split.map(&:to_i)
print 'PRL' * a[0]
c = false
if a[n-1] != 0
a[n-1] -= 1
c = true
end
(1..n-1).each{|i| print 'R', 'PLR' * a[i]}
if c
print 'P'
end

n = gets.to_i
a = gets.split.map(&:to_i)
print 'PRL' * a[0]
(1..n-1).each{|i| print 'R', 'PLR' * a[i]}

=begin
Dear online judge:
I've wasted time reading the problem and trying to figure out the solution
If you insist on the penalty system, please don't include the time of debugging
I hope my code compile and get accepted. KEE O.o
     ____________
    /         __ \
   /   __    |  | \
  /   |__|   |  |  \
 (           |__|   )
  \                /
   \      ___     /
    \____________/
=end

class Solve
  def solve()
    $n = Integer(gets)
    $list = gets().split()
    $count = 0
    $n -= 1
    for $i in 0..$n do
      if $list[$i] != "0"
        $count += Integer($list[$i])
      end
    end
    $res = ""
    $dir = 1
    $i = 0
    $cur = Array.new($n + 1,0)
    while $count > 0 do
      if $cur[$i] < Integer($list[$i])
        $cur[$i] += 1
        $count -= 1
        $res<<'P'
      end
      if $count > 0
        if $i == $n
          $dir = -1
        else
          if $i == 0
            $dir = 1
          end
        end
        if $dir == 1
          $res<<'R'
        end
        if $dir == -1
          $res<<'L'
        end
      end
      $i += $dir
    end
    puts $res
  end
end

Solve.new.solve

RIGHT = 1
LEFT  = 0

wallets_count, *wallets = STDIN.read.split

wallets.map!(&:to_i)
wallets_count = wallets_count.to_i

index         = 0
direction     = RIGHT
coins_to_give = wallets.inject(0) { |sum, value| sum + value }

until coins_to_give.zero?
  if wallets[index] > 0
    print :P
    wallets[index] -= 1
    coins_to_give  -= 1
    break if coins_to_give.zero?
  end

  if (direction == RIGHT && index < wallets_count - 1) || (direction == LEFT && index == 0)
    print :R
    index += 1
    direction = RIGHT
  else
    print :L
    index -= 1
    direction = LEFT
  end
end

print "\n"

inA = gets
inB = gets
count = inA.to_i

counts = inB.split
counts.map! {|x| x.to_i}

result = ""
position = 0
forward = true
lastPuted = 0
while true
	if(counts[position] > 0)
		result << 'P'
		lastPuted = 0
		counts[position] -= 1
	else
		lastPuted += 1
	end

	if(forward && (position == counts.length() -1))
		forward = false
	elsif ( (!forward) && position == 0)
		forward = true
	end

	if(forward)
		position += 1
		result << 'R'
	else
		position -= 1
		result << 'L'
	end

	if(lastPuted > (counts.length*2 + 2))
		puts result.slice(0, result.length - lastPuted - 1)
		break
	end
end

inA = gets
inB = gets
count = inA.to_i

counts = inB.split
counts.map! {|x| x.to_i}

result = ""
position = 0
forward = true
lastPuted = 0
while true
	if(counts[position] > 0)
		result << 'P'
		lastPuted = 0
		counts[position] -= 1
	else
		lastPuted += 1
	end

	if(forward && (position == counts.length() -1))
		forward = false
	elsif ( (!forward) && position == 0)
		forward = true
	end

	if(forward)
		position += 1
		result << 'R'
	else
		position -= 1
		result << 'L'
	end

	if(lastPuted > counts.length)
		puts result.slice(0, result.length - lastPuted - 1)
		break
	end
end

n = Integer(gets)
input = gets.chomp
nums = input.split
a = Array.new
for i in 0...n
    a[i] = Integer(nums[i])
end
sov = Array.new
if a[0] != 0
    sov[0] = "PRL" * (a[0]-1) + "PR"
else
    sov[0] = nil
end
b = Array.new
for i in  1...n
    b[i] = ("R" * i + "P"  + "L" * i) * a[i]
    sov.push(b[i])
end
print sov.join

n = Integer(gets)
input = gets.chomp
nums = input.split
a = Array.new
for i in 0...n
    a[i] = Integer(nums[i])
end
sov = Array.new
if a[0] != 0
    sov[0] = "PRL" * (a[0]-1) + "PR"
else
    sov[0] = nil
end
b = Array.new
for i in  1...n
    if a[i] >= 2
        b[i] = "PL" + "RPL" * (a[i]-2) + "RP"
    else a[i] = 1
        b[i] = "PL"
    end

    sov.push(b[i])
end
print sov.join

n = Integer(gets)
input = gets.chomp
nums = input.split
a = Array.new
for i in 0...n
    a[i] = Integer(nums[i])
end
sov = Array.new
if a[0] != 0
    sov[0] = "PRL" * (a[0]-1) + "PR"
else
    sov[0] = "R"
end
b = Array.new
for i in  1...n
    if a[i] >= 2
        b[i] = "PL" + "RPL" * (a[i]-2) + "RP"
    elsif a[i] == 1
        b[i] = "PL"
    else  a[i] == 0
        b[i] = "R"
    end

    sov.push(b[i])
end
print sov.join

n = Integer(gets)
input = gets.chomp
nums = input.split
a = Array.new
for i in 0...n
    a[i] = Integer(nums[i])
end
sov = Array.new
sov[0] = "PRL" * a[0]
b = Array.new
for i in  1...n
    b[i] = ("R" * i + "P"  + "L" * i) * a[i]
    sov.push(b[i])
end
print sov.join

n = Integer(gets)
input = gets.chomp
nums = input.split
a = Array.new
for i in 0...n
    a[i] = Integer(nums[i])
end
sov = Array.new
if a[0] != 0
    sov[0] = "PRL" * (a[0]-1) + "PR"
else
    sov[0] = "R"
end
b = Array.new
for i in  1...n
    if a[i] >= 2
        b[i] = "PL" + "RPL" * (a[i]-2) + "RP"
    elsif a[i] == 1
        b[i] = "PL"
    else  a[i] == 0
        b[i] = "RR"
    end

    sov.push(b[i])
end
print sov.join

n = Integer(gets)
input = gets.chomp
nums = input.split
a = Array.new
for i in 0...n
    a[i] = Integer(nums[i])
end
sov = Array.new
if a[0] != 0
    sov[0] = "PRL" * (a[0]-1) + "PR"
else
    sov[0] = "R"
end
b = Array.new
for i in  1...n
    if a[i] >= 2
        b[i] = "PL" + "RPL" * (a[i]-2) + "RP"
    else a[i] = 1
        b[i] = "PL"
    end

    sov.push(b[i])
end
print sov.join

n = gets.to_i
a = gets.split.map(&:to_i)
print 'PRL' * a[0]
if a[n-1] != 0
a[n-1] -= 1
end
(1..n-1).each{|i| print 'R', 'PLR' * a[i]}
print 'P'


def solve(x, y)
  m = Math.log2(x).to_i
  n = Math.log2(y).to_i
  if n == m
    return 2 ** n, [y, (1.25*2**n).to_i].min
  elsif n == m + 1
    if x > (2 ** n / 1.25).to_i
      return (2 ** n / 1.25).to_i, 2 ** n
    else
      return 2 ** m, (1.25 * 2 ** m).to_i
    end
  else
    return 2 ** m, (1.25 * 2 ** m).to_i
  end
end

y, x = gets.split.map(&:to_i)
x0, y0 = x, y
swap = false
if x > y
  x, y = y, x
  swap = true
end

p, q = solve(x, y)
if swap
  p, q = q, p
end
if p > q and (p <= y0 and q <= x0)
  p, q = q, p
end
printf("%d %d\n", q, p)

def solve(x, y)
  m = Math.log2(x).to_i
  n = Math.log2(y).to_i
  if n == m
    return 2 ** n, [y, (1.25*2**n).to_i].min
  elsif n == m + 1
    if x > (2 ** n / 1.25).to_i
      return (2 ** n / 1.25).to_i, 2 ** n
    else
      return 2 ** m, (1.25 * 2 ** m).to_i
    end
  else
    return 2 ** m, (1.25 * 2 ** m).to_i
  end
end

y, x = gets.split.map(&:to_i)
swap = false
if x > y
  x, y = y, x
  swap = true
end

p, q = solve(x, y)
if swap
  p, q = q, p
end
printf("%d %d\n", q, p)

def solve(x, y)
  m = Math.log2(x).to_i
  n = Math.log2(y).to_i
  if n == m
    return 2 ** n, [y, (1.25*x).to_i].min
  elsif n == m + 1
    if x > (2 ** n / 1.25).to_i
      return (2 ** n / 1.25).to_i, 2 ** n
    else
      return 2 ** m, (1.25 * 2 ** m).to_i
    end
  else
    return 2 ** m, (1.25 * 2 ** m).to_i
  end
end

y, x = gets.split.map(&:to_i)
swap = false
if x > y
  x, y = y, x
  swap = true
end

p, q = solve(x, y)
if swap
  p, q = q, p
end
printf("%d %d\n", q, p)


n = gets.to_i
x = gets.split.map &:to_i

max = x.max

def sieve_numbers n
  sieve_array = Array.new(n + 1, true)
  sieve_array[0] = false
  sieve_array[1] = false

  for current_prime in 2 .. Math.sqrt(n).to_i
    next unless sieve_array[current_prime]
    i = 2
    while current_prime * i <= n
      sieve_array[current_prime * i] = false
      i += 1
    end
  end

  return sieve_array
end

def t_prime? sieve_array, n
  n_sqrt = Math.sqrt(n).to_i
  return n_sqrt * n_sqrt == n && sieve_array[n_sqrt]
end

primes = sieve_numbers(Math.sqrt(max).ceil)

x.each do |test_case|
  if t_prime? primes, test_case
    puts "YES"
  else
    puts "NO"
  end
end

#!/usr/bin/env ruby
def prime(n)
  all_nums = (0..n).to_a
  all_nums[0] = all_nums[1] = nil
  all_nums.each do |p|
    next unless p
    break if p * p > n
    (p*p).step(n, p){ |m| all_nums[m] = nil }
  end
  all_nums.compact
end

amount = 1000000
primes = prime(amount)

t = {}
primes.map{|p| t[p*p]=true }

col = gets.to_i
arr = gets.split(" ").map{|p| p.to_i }

(0..col-1).each do |i|
	if t[arr[i]] then
		puts "YES"
	else
		puts "NO"
	end
end

# require 'prime'

n = gets.to_i
f = gets.split.map { |x| x.to_i }

# p = Prime.first(700000)
is_prime = Array.new(1000001, true)
is_prime[0] = is_prime[1] = false
2.upto(1000001) do |i|
	if is_prime[i]
		j = i * 2
		while j < 1000001
			is_prime[j] = false
			j += i
		end
	end
end

f.each do |x|
	t = (x ** 0.5).round
	if t ** 2 == x and is_prime[t]
		puts 'YES'
	else
		puts 'NO'
	end
end

require 'prime'

c=(0..10**6).map{0}
c[0]=1
c[1]=1
b=2
while b*b<=(10**6)
	if c[b]==0 then
		b2=b+b
		while b2<=10**6
			c[b2]=1
			b2=b2+b
		end
	end
	b=b+1
end
gets
x=gets.split.map{|e| e.to_i}

x.each{|e|
	m=(e**0.5).to_i
	if m*m==e && c[m]==0 then
		puts "YES"
	else
		puts "NO"
	end
}

a = Array.new(1000001,0)
a[1] = -1
i = 3
while i < 1000
	if a[i] == 0
		j = i+i
		while j < 1000000
			a[j] = -1
			j += i
		end
	end
	i += 2
end
n = gets.to_i
gets.split.map(&:to_i).each do |i|
	x = Math.sqrt(i)
	if x % 1 == 0
		if x % 2 == 0 and x != 2
			puts 'NO'
		else
			if a[x] == -1
				puts 'NO'
			else
				puts 'YES'
			end
		end

	else
		puts 'NO'
	end
end

#!/usr/bin/ruby

N = Integer gets.chomp
numbers = gets.chomp.split
for i in 0...N do
	numbers[i] = Integer numbers[i]
end

X = 1000000
flags = Array.new(X+1)
for i in 0..X do
	flags[i] = true
end
flags[0] = flags[1] = false
for i in 2..X do
	if flags[i]
		j = i * i
		while (j <= X) do
			flags[j] = false
			j += i;
		end
	end
end

for i in numbers do
	j = Integer Math.sqrt(i)
	if flags[j] and j * j == i
		print "YES\n"
	else
		print "NO\n"
	end
end

def generate_prime(n)
	primes = (0..n).to_a
	primes[0] = nil
	primes[1] = nil
	(2..Math.sqrt(n)).each do |i|
		if primes[i]
			(i**2..n).step(i).each do |j|
				primes[j] = nil
			end
		end
	end
	primes.compact
end

n = gets.to_i
arr = gets.split(" ").map(&:to_i)
@primes = generate_prime(10 ** 6).map{|x| x *x}
true_arr = @primes & arr

true_hash = Hash[true_arr.map{|x| [x,true]}]
#d puts "#{true_hash}"
res = []
arr.each do |a|
	res << (true_hash[a] ? "YES" : "NO")
end

res.each do |i|
	puts i
end

def Eratosthenes2(n)
	l = Array 0..n

	l[0] = l[1] = nil

	for i in (2..n ** (1.0 / 2))
		if l[i]
			j = i ** 2
			while j <= n
				l[j] = nil
				j += i
			end
		end
	end

	return l.compact.map { |x| x ** 2 }
end

l = Eratosthenes2(1000000)

class Array
	def bs(x)

		s = 0
		e = size - 1

		while s <= e
			t = at((s + e) / 2)

			if x < t
				e = (s + e) / 2 - 1
			elsif x > t
				s = (s + e) / 2 + 1
			else
				return t
			end
		end

		return nil
	end
end

gets
gets.split.each { |x| puts (l.bs(x.to_i) != nil) ? "YES" : "NO" }

PRIME_LIMIT = Math.sqrt(10**12).to_i + 1
@prime_numbers = Array.new(PRIME_LIMIT, true)

def sieve
  @prime_numbers[1] = false
  i = 2
  while i*i < PRIME_LIMIT do
    if @prime_numbers[i] != false
      j = 2 * i
      while j < PRIME_LIMIT do
        @prime_numbers[j] = false
        j += i
      end
    end
    i+= 1
  end
end

sieve()

gets
gets
values = $_.split.map(&:to_i)
values.each do |value|
  svalue = Math.sqrt(value).to_i
  if (svalue * svalue == value && @prime_numbers[svalue] == true && value != 1)
    puts "YES"
  else
    puts "NO"
  end
end

n = gets.to_i
a = gets.split.map(&:to_i)
c = Array.new(1000000, true)
c[1] = false
2.upto(1000000) do |i|
  if c[i]
    (i + i).step(1000000, i){|j| c[j] = false}
  end
end
a.each do |x|
  m = Math.sqrt(x)
  if m.ceil == m.to_i && c[m]
    puts 'YES'
  else
    puts 'NO'
  end
end

require 'set'

tprimes = Set.new
sieve = Array.new(1000001,true)
sieve[0] = false
sieve[1] = false
(2..1000000).each do |p|
  next if sieve[p] == false
  i = p*p
  tprimes.add(i)
  while(i<=1000000)
    sieve[i] = false
    i += p
  end
end

gets.to_i
gets.split(/\s+/).each do |x|
  puts tprimes.member?(x.to_i) ? "YES" : "NO"
end

n = gets.to_i
a = gets.split.map(&:to_i)
c = Array.new(1000000, true)
c[1] = false
2.upto(1000) do |i|
  if c[i]
    (i * i).step(1000000, i){|j| c[j] = false}
  end
end
a.each do |x|
  m = Math.sqrt(x).round
  if m * m == x && c[m]
    puts 'YES'
  else
    puts 'NO'
  end
end

require 'set'

c = Array.new(1_000_001, false)
c[2] = true
p = [ 2 ]
3.step(1_000_000, 2) do |i|
  next if c[i]

  p << i

  i.step(1_000_000, i) { |x| c[x] = true }
end

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

pp = Set.new p.map { |x| x*x }

a.each do |n|
  puts pp.include?(n) ? 'YES' : 'NO'
end

MAXP = 1e6.to_i
is_prime = Array.new MAXP, true
t_primes = {}
(2...MAXP).each do |i|
  if is_prime[i] then
    t_primes[i * i] = 0
    ((i + i)...MAXP).step(i).each do |j|
      is_prime[j] = false
    end
  end
end
n = gets
x = gets.split.map &:to_i
x.each do |i|
  if t_primes.has_key? i then
    puts 'YES'
  else
    puts 'NO'
  end
end

#!/usr/bin/ruby

limit = 10**6 + 1
is_prime = {}
sieve = Array.new(limit)
pos = 2
while true
	while pos != limit and sieve[pos]
		pos += 1
	end
	break if pos == limit
	seek = pos
	while seek < limit
		sieve[seek] = true
		seek += pos
	end
	is_prime[pos] = true
end

n = STDIN.readline.to_i
arr = STDIN.readline.split.map {|s| s.to_i }
lines = []
arr.each do |x|
	y = (x**0.5).floor
	if y*y == x and is_prime[y]
		lines.push('YES')
	else
		lines.push('NO')
	end
end
puts lines.join("\n")

gets.to_i;
arr = gets.chomp.split(' ').map(&:to_i);
primes = Array.new(1000000, 1);
primes[1] = nil;
(2..1000000).each do |i|
  if primes[i]
    (i**2).step(1000000, i) {|m| primes[m] = nil}
  end
end

arr.each {|x|
  sq = Math.sqrt(x).to_i;
  puts (sq**2 == x && primes[sq] ? "YES" : "NO")
}

n = gets.chomp.to_i
a = gets.chomp.split(" ").map{|i| i.to_f}

L = []

(1..1000000).each do |i|
  L[i] = 1
end
L[1] = 0

(2..1000000).each do |i|
  kq = 2*i
  if L[i] == 1
    while kq <= 1000000 do
      L[kq] = 0
      kq += i
    end
  end
end

(0..n-1).each do |i|
  can = Math.sqrt(a[i])
  if can == can .ceil && L[can] == 1
    puts "YES"
  else
    puts "NO"
  end
end

require 'set'

n = gets.to_i

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

N = 10 ** 6
M = 10 ** 3

sieve = Array.new(N+1,true)

S = Set.new

(2..N).each do |i|
  next if not sieve[i]
  S.add(i ** 2)
  m = 2 * i
  while m <= N
    sieve[m] = false
    m += i
  end
end

x.each{|e| S.member?(e) ? (puts 'YES') : (puts 'NO')}

a=Array.new(1000000,0)
a[0]=1
for i in 2...1000000
	if a[i-1]==0
		j=2
		while i*j<=1000000
			a[i*j-1]=1
			j+=1
		end
	end
end
t=gets.to_i
ar=gets.chomp.split.map(&:to_i)
ar.each do |i|
	j=Math.sqrt(i).to_i
	puts (a[j-1]==0 && j*j==i) ? "YES" : "NO"
end

def eratosthenes(top)
  sieve = []
  for i in 2 .. top
    sieve[i] = i
  end
  for i in 2 .. Math.sqrt(top)
    next unless sieve[i]
    (i*i).step(top, i) do |j|
      sieve[j] = nil
    end
  end
  sieve
end
e = eratosthenes(1_000_000)
gets
gets.split.map(&:to_i).each do |x|
  f = Math.sqrt(x)
  if f == f.round and !e[f].nil?
    puts :YES
  else
    puts :NO
  end
end

n = gets.to_i
a = gets.split(' ').map{|i| i.to_i}
L = Array.new

(1..1000000).each do |i|
  L[i] = 1
end

L[1] = 0

(2..1000000).each do |i|
  kq = 2*i
  if L[i] == 1
    while kq <= 1000000 do
      L[kq] = 0
      kq += i
    end
  end
end

a.each do |i|
    if Math.sqrt(i.to_f) == Math.sqrt(i.to_f).floor
        f = Math.sqrt(i.to_f).to_i
        if L[f] == 1
            puts 'YES'
        else
            puts 'NO'
        end
    else
        puts 'NO'
    end
end

n = gets.to_i
x = gets.split.map &:to_i

max = x.max

def sieve_numbers n
  sieve_array = Array.new(n + 1, true)
  sieve_array[0] = false
  sieve_array[1] = false

  for current_prime in 2 .. Math.sqrt(n).to_i
    next unless sieve_array[current_prime]
    i = 2
    while current_prime * i <= n
      sieve_array[current_prime * i] = false
      i += 1
    end
  end

  prime_numbers = []
  sieve_array.each_index do |index|
    prime_numbers << index if sieve_array[index]
  end
  return prime_numbers
end

primes = sieve_numbers(Math.sqrt(max).ceil)
squared_primes = primes.map{|p| p * p}

x.each do |test_case|
  if squared_primes.bsearch{|element| test_case - element}
    puts "YES"
  else
    puts "NO"
  end
end

gets.to_i;
arr = gets.chomp.split(' ').map(&:to_i);
primes = Array.new(1000000, 1);
(2..1000000).each do |i|
  if primes[i]
    (i**2).step(1000000, i) {|m| primes[m] = nil}
  end
end

arr.each {|x|
  sq = Math.sqrt(x).to_i;
  puts (sq**2 == x && primes[sq] ? "YES" : "NO")
}

require 'prime'

gets.to_i;
arr = gets.chomp.split(' ').map(&:to_i);
primes = Prime.each(100000).map {|x| [x, 1]};
hash = Hash[*primes.flatten];

arr.each { |x|
  sq = Math.sqrt(x).to_i;
  if (sq*sq == x && hash[sq])
    puts "YES";
  else
    puts "NO";
  end
}

require 'mathn'
n = gets.to_i
n.times do
  f = Math.sqrt(gets.to_i)
  puts (f == f.round and f.prime?) ? :YES : :NO
end

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

ind = 0
d = Array.new(100001,false)
ok = Array.new(100001)

for i in 2..1000001 do
    if (d[i] == false)
        ind += 1
        ok[ind] = i*i
        j = i+i
        begin
          d[j] = true
          j += i
          if (j > 100001) then break end
        end while true
    end
end

for i in 0..n-1 do
    l = 0x0
    r = 0x0
    l = 1.to_i
    r = ind.to_i
    ans = false
    begin
        if (l>=r) then break end
        mid = (l+r) / 2
        if (ok[mid] > a[i]) then r = mid end
        if (ok[mid] < a[i]) then l = mid+1 end
        if (ok[mid] == a[i]) then ans = true end
        if (ans == true) then break end
    end while true
    if (ok[l] == a[i]) then ans = true end
    if (ans == true) then  puts "YES"
        else puts "NO"
    end
end

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

ind = 0
d = Array.new(1000001,false)
ok = Array.new(0)

for i in 2..1000001 do
    if (d[i] == false)
        ind += 1
        ok.push(i*i)
        j = i+i
        begin
          d[j] = true
          j += i
          if (j > 1000001) then break end
        end while true
    end
end

for i in 0..n-1 do
    l = 0x0
    r = 0x0
    l = 1.to_i
    r = ind.to_i
    ans = false
    begin
        if (l>=r) then break end
        mid = (l+r) / 2
        if (ok[mid] > a[i]) then r = mid end
        if (ok[mid] < a[i]) then l = mid+1 end
        if (ok[mid] == a[i]) then ans = true end
        if (ans == true) then break end
    end while true
    if (ok[l] == a[i]) then ans = true end
    if (ans == true) then  puts "YES"
        else puts "NO"
    end
end

a = Array.new(1000001,0)
a[1] = -1
i = 3
while i < 1000
	if a[i] == 0
		j = i+i
		while j < 1000000
			a[j] = -1
			j += j
		end
	end
	i += 2
end
n = gets.to_i
gets.split.map(&:to_i).each do |i|
	x = Math.sqrt(i)
	if x % 1 == 0
		if x % 2 == 0 and x != 2
			puts 'NO'
		else
			if a[x] == -1
				puts 'NO'
			else
				puts 'YES'
			end
		end

	else
		puts 'NO'
	end
end

#!/usr/bin/ruby

N = Integer gets.chomp
numbers = gets.chomp.split
for i in 0...N do
	numbers[i] = Integer numbers[i]
end

X = 100000
flags = Array.new(X+1)
for i in 0..X do
	flags[i] = true
end
flags[0] = flags[1] = false
for i in 2..X do
	if flags[i]
		j = i * i
		while (j <= X) do
			flags[j] = false
			j += i;
		end
	end
end

for i in numbers do
	j = Integer Math.sqrt(i)
	if flags[j] and j * j == i
		print "YES\n"
	else
		print "NO\n"
	end
end

#!/usr/bin/ruby

N = Integer gets.chomp
numbers = gets.chomp.split
for i in 0...N do
	numbers[i] = Integer numbers[i]
end

X = 100000
flags = Array.new(X+1)
for i in 0..X do
	flags[i] = true
end
flags[0] = flags[1] = false
primes = Array.new
for i in 2..X do
	if flags[i]
		primes.push i
		j = i * i
		while (j <= X) do
			flags[j] = false
			j += i;
		end
	end
end

for i in numbers do
	is_prime = i != 1
	for j in primes do
		if j * j > i
			break
		end
		if i % j == 0
			is_prime = false
			break
		end
	end
	if is_prime
		print "YES\n"
	else
		print "NO\n"
	end
end

def generate_prime(n)
	primes = Hash.new(true)
	primes[0] = false
	primes[1] = false
	(2..Math.sqrt(n)).each do |i|
		if primes[i]
			primes[i] = true
			(i**2..n).step(i).each do |j|
				primes[j] = false
			end
		end
	end
	primes.select {|k,v| v == true}.keys
end

n = gets.to_i
arr = gets.split(" ").map(&:to_i)
@primes = generate_prime(10**6)
arr.each do |a|
	# puts @primes.include?(Math.sqrt(a)) ? "YES" : "NO"
end

def Eratosthenes2(n)
	l = Array 0..n

	l[0] = l[1] = nil

	for i in (2..n ** (1.0 / 2))
		if l[i]
			j = i ** 2
			while j <= n
				l[j] = nil
				j += i
			end
		end
	end

	return l.compact.map { |x| x ** 2 }
end

l = Eratosthenes2(1000000)

gets
gets.split.each { |x| puts (l[0] == x.to_i or l.bsearch { |y| y == x.to_i } != nil) ? "YES" : "NO" }

n = gets.to_i
a = gets.split.map(&:to_i)
c = Array.new(10, true)
2.upto(10) do |i|
  if c[i]
    i.step(10, i){|j| c[j] = false if j != i}
  end
end
a.each do |x|
  m = Math.sqrt(x)
  if m.ceil == m.to_i && c[m]
    puts 'YES'
  else
    puts 'NO'
  end
end

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

a.each do |x|
  m = x.prime_division
  if m.size == 1 && m[0][0] == m[0][1]
    puts 'YES'
  else
    puts 'NO'
  end
end

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

a.each do |x|
  m = x.prime_division
  if m.size == 1 && m[0][0] != x
    puts 'YES'
  else
    puts 'NO'
  end
end

n = gets.to_i
a = gets.split.map(&:to_i)
c = Array.new(10, true)
c[1] = false
2.upto(10) do |i|
  if c[i]
    i.step(10, i){|j| c[j] = false if j != i}
  end
end
a.each do |x|
  m = Math.sqrt(x)
  if m.ceil == m.to_i && c[m]
    puts 'YES'
  else
    puts 'NO'
  end
end

require 'set'

def t_prime(x)
  result = false
  $p.each do |i|
    break if i > x
    if x.modulo(i).zero? && x.div(i) > 1 && result == false
      result = true
    elsif x.modulo(i).zero?
      return false
    end
  end
  result
end

c = Set.new [ 2 ]
$p = [ 2 ]
i = 1
until i > 1_000_000
  i += 2

  next if c.include? i

  x = i
  until x > 1_000_000
    c << x
    x += i
  end
end

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

a.each do |n|
  puts t_prime(n) ? 'YES' : 'NO'
end

require 'set'

def t_prime(x)
  result = false
  $p.each do |i|
    break if i > x
    if x.modulo(i).zero? && x.div(i) > 1 && result == false
      result = true
    elsif x.modulo(i).zero?
      return false
    end
  end
  result
end

c = Set.new [ 2 ]
$p = [ 2 ]
c << 2
i = 1
until i > 1_000_000
  i += 2

  next if c.include? i

  $p << i

  x = i
  until x > 1_000_000
    c << x
    x += i
  end
end

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

a.each do |n|
  puts t_prime(n) ? 'YES' : 'NO'
end

n = gets.to_i
b = gets.split(' ')

a = []

(0..n-1).each do |i|
    a[i] = b[i].to_f
    if Math.sqrt(a[i]) == Math.sqrt(a[i]).ceil
        puts "YES"
    else
        puts "NO"
    end
end

n = gets.chomp.to_i
a = gets.chomp.split(" ").map{|i| i.to_f}

(0..n-1).each do |i|
    dem = 0
    can = Math.sqrt(a[i])
  (2..can.floor).each do |j|
    dem +=1 if a[i]%j == 0
  end
  if can == can.floor
    if 2*dem + 1 == n
        puts "YES"
    else
        puts "NO"
    end
  else
    if 2*dem + 2 == n
        puts "YES"
    else
        puts "NO"
    end
  end
end

n = gets.to_i
b = gets.split(' ')

a = []
kt = 1

(0..n-1).each do |i|
    kt = 1
    a[i] = b[i].to_f
    can = Math.sqrt(a[i])
    if can == can.ceil
        (2..Math.sqrt(can).floor).each do |i|
            kt = 0 if can%i == 0
        end
    else kt = 0
    end
    if kt == 0
        puts "NO"
    else
        puts "YES"
    end
end

n = gets.chomp.to_i
a = gets.chomp.split(" ").map{|i| i.to_f}

(0..n-1).each do |i|
  kt = 1
  if a[i] < 4
    puts "NO"
  else
    if a[i] == 4
      puts "YES"
    else
        can = Math.sqrt(a[i]).to_f
      if (can.ceil == can)
        (2..Math.sqrt(can).floor).each do |j|
          if can%j == 0
            puts "NO"
            kt = 0
          end
        end
        if kt == 1
          puts "YES"
        end
      else
        puts "NO"
      end
    end
  end
end

n = gets.to_i
b = gets.split(' ')

a = []

(0..n-1).each do |i|
    a[i] = b[i].to_f
    dem = 0
    can = Math.sqrt(a[i])
  (2..can.floor).each do |j|
    dem +=1 if a[i]%j == 0
  end
  if can == can.floor
    if 2*dem + 1 == n
        puts "YES"
    else
        puts "NO"
    end
  else
    if 2*dem + 2 == n
        puts "YES"
    else
        puts "NO"
    end
  end
end

n = gets.to_i
b = gets.split(' ')

a = []

(0..n-1).each do |i|
    kt = 0
    a[i] = b[i].to_f
    (2..Math.sqrt(a[i]).floor).each do |j|
        if (a[i]%j == 0)
            kq = a[i]/j
            while kq > 1 do
                if kq %j != 0
                    break
                else
                    kq = kq/j
                end
            end
            kt = 1 if kq == 1
            break
        end
    end
    if kt == 0
        puts "NO"
    else
        puts "YES"
    end
end

require 'set'

n = gets.to_i

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

N = 10 ** 6
M = 10 ** 3

sieve = Array.new(N+1,true)

S = Set.new

(2..N).each do |i|
  next if not sieve[i]
  S.add(i ** 2)
  m = 2 * i
  while m < N
    sieve[m] = false
    m += i
  end
end

x.each{|e| S.member?(e) ? (puts 'YES') : (puts 'NO')}

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

a.each do |i|
    if Math.sqrt(i.to_f) == Math.sqrt(i.to_f).floor && Math.sqrt(i.to_f).floor > 1
        f = Math.sqrt(i.to_f).to_i
        g = Math.sqrt(f).to_i
        puts 'YES'

    else
        puts 'NO'
    end
end

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

a.each do |i|
	if Math.sqrt(i.to_f) == Math.sqrt(i.to_f).floor && Math.sqrt(i.to_f).floor > 1
		f = Math.sqrt(i.to_f).to_i
		if f == 2 || f == 3
			puts 'YES'
		elsif f > 3
			g = Math.sqrt(f)
			m = 0
			(2..g).each do |t|
				if f%t == 0
					puts 'NO'
					break
				end
				m = t
			end
			if m == g
				puts 'YES'
			end
		end
	else
		puts 'NO'
	end
end

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

a.each do |i|
    if Math.sqrt(i.to_f) == Math.sqrt(i.to_f).floor && Math.sqrt(i.to_f).floor > 1
        f = Math.sqrt(i.to_f).to_i
        if f == 2 || f == 3
            puts 'YES'
        elsif f > 3
            g = Math.sqrt(f).floor
            m = 0
            (2..g).each do |t|
                if f%g == 0
                    puts 'NO'
                    break
                end
                m = t
            end
            if m == g
                puts 'YES'
            end
        end
    else
        puts 'NO'
    end
end

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

a.each do |i|
    if Math.sqrt(i.to_f) == Math.sqrt(i.to_f).floor && Math.sqrt(i.to_f).floor > 1
        f = Math.sqrt(i.to_f).to_i
        if f == 2 || f == 3
            puts 'YES'
        elsif f > 3
            g = (f/2).floor
            m = 0
            (2..g).each do |t|
                if f%g == 0
                    puts 'NO'
                    break
                end
                m = t
            end
            if m == g
                puts 'YES'
            end
        end
    else
        puts 'NO'
    end
end

# require 'prime'

n = gets.to_i
f = gets.split.map { |x| x.to_i }

# p = Prime.first(700000)
is_prime = Array.new(1000001, true)
is_prime[0] = false
2.upto(1000001) do |i|
	if is_prime[i]
		j = i * 2
		while j < 1000001
			is_prime[j] = false
			j += i
		end
	end
end

f.each do |x|
	t = (x ** 0.5).round
	if t ** 2 == x and is_prime[t]
		puts 'YES'
	else
		puts 'NO'
	end
end


a=gets.chomp.to_i
ans=a*3
0.upto(a-1) do |i|
print "#{ans+i} "
end

n = gets.to_i
MAX = 1300000
is_prime = Array.new(MAX + 1){true}
is_prime[0] = false
is_prime[1] = false
i = 2
while i * i <= MAX
    if is_prime[i]
        # puts i
        j = i * i
        while j < MAX + 1
            is_prime[j] = false
            j += i
        end
    end
    i += 1
end
res = []
is_prime.each_with_index{|x, i| res << i if x}
puts res[0...n].join(" ")

prime = Array.new(1300000, true)

prime[0] = prime[1] = false
2.upto(1300000) do |i|
	if prime[i]
		t = i * 2
		while t < 1300000
			prime[t] = false
			t += i
		end
	end
end

ans = []
n = gets.to_i
2.upto(1300000) do |i|
	if prime[i]
		if n > 0
			n -= 1
			ans << i
		end
	end
end

puts ans.join ' '

n = Integer(gets)

b = Array.new
b[0] = 2
b[1] = 3
for i in 0...10000
    c = 0
    for j in 0...b.length
        if (i + 2)% b[j] != 0
            c = 1
        else
            c = 0
            break
        end
    end
    if c == 1
        b.push(i + 2)
    end
end
c = Array.new

for i in 0...b.length
    for j in i...b.length
         c.push(b[i]*b[j])

        if c.length >= n
            break
        end
    end
    if c.length >= n
            break
        end
end
c = c.sort
puts c

n = Integer(gets)

b = Array.new
b[0] = 2
b[1] = 3
for i in 0...10000
    c = 0
    for j in 0...b.length
        if (i + 2)% b[j] != 0
            c = 1
        else
            c = 0
            break
        end
    end
    if c == 1
        b.push(i + 2)
    end
end
c = Array.new

for i in 0...b.length
    for j in i...b.length
         c.push(b[i]*b[j])

        if c.length >= n
            break
        end
    end
end
c = c.sort
for i in 0...n
    puts c[i]
end

n = gets.strip.to_i
a = []
n.times do |i|
  a << (10000000 - n + i)
end
puts a.join(" ")

def eratosthenes(n)
  nums = [true, false, true] * ((n + 5) / 6)
  nums[0] = false
  nums[1] = true

  i = 5
  until(m = i * i
  m > n) do
  if nums[i >> 1]
    i_times_2 = i << 1
    i_times_4 = i << 2
    while m <= n
      nums[m >> 1] = false
      m += i_times_2
      nums[m >> 1] = false
      m += i_times_4
    end
  end
  i += 2
  if nums[i >> 1]
    m = i * i
    i_times_2 = i << 1
    i_times_4 = i << 2
    while m <= n
      nums[m >> 1] = false
      m += i_times_4
      nums[m >> 1] = false
      m += i_times_2
    end
  end
  i += 4
  end

  primes = [2]
  nums.each_index {|i| primes << (i * 2 + 1) if nums[i]}
  primes.pop while primes.last > n
  return primes
end

puts eratosthenes(1299722)[0..gets.to_i-1].join(' ')

n = Integer(gets)

b = Array.new
b[0] = 2
b[1] = 3
for i in 0...4*n
    c = 0
    for j in 0...b.length
        if (i + 2)% b[j] != 0
            c = 1
        else
            c = 0
            break
        end
    end
    if c == 1
        b.push(i + 2)
    end
end
for i in 0...n
    print b[i], " "
end

n = Integer(gets)

b = Array.new
b[0] = 2
b[1] = 3
for i in 0...2*n
    c = 0
    for j in 0...b.length
        if (i + 2)% b[j] != 0
            c = 1
        else
            c = 0
            break
        end
    end
    if c == 1
        b.push(i + 2)
    end
end
for i in 0...n
    print b[i], " "
end

n = Integer(gets)

b = Array.new
b[0] = 2
b[1] = 3
for i in 0...n + 1000
    c = 0
    for j in 0...b.length
        if (i + 2)% b[j] != 0
            c = 1
        else
            c = 0
            break
        end
    end
    if c == 1
        b.push(i + 2)
    end
end
for i in 0...n
    print b[i], " "
end

n = Integer(gets)

b = Array.new
b[0] = 2
b[1] = 3
for i in 0...10000
    c = 0
    for j in 0...b.length
        if (i + 2)% b[j] != 0
            c = 1
        else
            c = 0
            break
        end
    end
    if c == 1
        b.push(i + 2)
    end
end
c = Array.new

for i in 0...b.length
    for j in i...b.length
         c.push(b[i]*b[j])

        if c.length >= n
            break
        end
    end
end
for i in 0...n
    puts c[i]
end

n = Integer(gets)

b = Array.new
b[0] = 2
b[1] = 3
for i in 0...n + 100
    c = 0
    for j in 0...b.length
        if (i + 2)% b[j] != 0
            c = 1
        else
            c = 0
            break
        end
    end
    if c == 1
        b.push(i + 2)
    end
end
for i in 0...n
    print b[i], " "
end

n = Integer(gets)

b = Array.new
b[0] = 2
b[1] = 3
for i in 0...6*n
    c = 0
    for j in 0...b.length
        if (i + 2)% b[j] != 0
            c = 1
        else
            c = 0
            break
        end
    end
    if c == 1
        b.push(i + 2)
    end
end
for i in 0...n
    print b[i], " "
end

n = Integer(gets)

b = Array.new
b[0] = 2
b[1] = 3
for i in 0...10000
    c = 0
    for j in 0...b.length
        if (i + 2)% b[j] != 0
            c = 1
        else
            c = 0
            break
        end
    end
    if c == 1
        b.push(i + 2)
    end
end
c = Array.new

for i in 0...b.length
    for j in i...b.length
         c.push(b[i]*b[j])

        if c.length >= n
            break
        end
    end
    if c.length >= n
            break
        end
end

puts c

n = Integer(gets)

b = Array.new
b[0] = 2
b[1] = 3
for i in 0...10000
    c = 0
    for j in 0...b.length
        if (i + 2)% b[j] != 0
            c = 1
        else
            c = 0
            break
        end
    end
    if c == 1
        b.push(i + 2)
    end
end
c = Array.new

for i in 0...b.length
    for j in 0...b.length
         c.push(b[i]*b[j])

        if c.length >= n
            break
        end
    end
end
for i in 0...n
    puts c[i]
end


n = gets.to_i
arr = []
(0..n * 2 - 3).each do |i|
  arr.push([gets.chop, i])
end
brr = arr.sort_by{ |t| t.first.length }
c1 = brr[-1].first + brr[-2].first[-1]
c2 = brr[-2].first + brr[-1].first[-1]

def isPrefix(s, pr)
  s[0 .. pr.length - 1] == pr
end

def isSuffix(s, sf)
  s[-sf.length .. -1] == sf
end

res1 = "_" * (n * 2 - 2)
res2 = res1.dup

brr.each_slice(2) do |f, s|
  s1, n1 = f
  s2, n2 = s
  res1[n1], res1[n2] = "P", "S" if isPrefix(c1, s1) && isSuffix(c1, s2)
  res1[n1], res1[n2] = "S", "P" if isSuffix(c1, s1) && isPrefix(c1, s2)
  res2[n1], res2[n2] = "P", "S" if isPrefix(c2, s1) && isSuffix(c2, s2)
  res2[n1], res2[n2] = "S", "P" if isSuffix(c2, s1) && isPrefix(c2, s2)
end

if !res1.include? "_" then puts res1 else puts res2 end

n = gets.to_i
str = []
(2*n-2).times do |i|
  str << [gets.chomp,i]
end

str.sort_by!{|s| s[0].length}

a,b,c,d = str[0][0],str[1][0],str[-1][0],str[-2][0]
guess = [a+c,a+d,b+c,b+d]

#p guess
str.each do |a|
  s = a[0]
  len = s.length
  guess.each do |t|
    guess.delete(t) if t[0,len] != s && t[n-len,len] != s
  end
  #p guess
end

origin = guess[0]

(n-1).times do |i|
  a,b = str[2*i][0],str[2*i+1][0]
  len = a.length

  #p [a,b,flg]
  if a == origin[0,len]
    str[2*i] << "P"
    str[2*i+1] << "S"
  else
    str[2*i] << "S"
    str[2*i+1] << "P"
  end
end
#p guess

str.sort_by!{|s| s[1]}
str.each do |a|
  print "#{a[2]}"
end

# Utility
class StringBuilder
  def initialize(chunks)
    chunks_sorted = chunks.map.with_index { |chunk, i| {i: i, str: chunk} }
                          .sort { |a, b| a[:str].length <=> b[:str].length }
    @pairs = Array.new(chunks_sorted.length / 2) { |i| [chunks_sorted[2 * i], chunks_sorted[2 * i + 1]] }

    @string = build

    @solution = "S" * chunks.length
    @pairs.each do |p|
      if @string.start_with? p[0][:str]
        @solution[p[0][:i]] = "P"
      else
        @solution[p[1][:i]] = "P"
      end
    end
  end

  attr_reader :string
  attr_reader :solution

  private
  def build
    str_1 = @pairs[-1][0][:str] + @pairs[-1][1][:str][-1]
    str_2 = @pairs[-1][1][:str] + @pairs[-1][0][:str][-1]
    return str_1 if correct? str_1
    return str_2 if correct? str_2
  end

  def correct?(str)
    (str.length - 1).times do |i|
      a = (str.start_with? @pairs[i][0][:str]) && (str.end_with? @pairs[i][1][:str])
      b = (str.start_with? @pairs[i][1][:str]) && (str.end_with? @pairs[i][0][:str])
      break false unless a || b
    end
  end
end

# Input
n = gets.to_i # 2 <= n <= 100
chunks = Array.new(2 * n - 2) { |i| gets.chop }

# Result
result = StringBuilder.new(chunks)
#puts result.string
puts result.solution

n = gets.to_i
str = []
(2*n-2).times do |i|
  str << [gets.chomp,i]
end

str.sort_by!{|s| s[0].length}
guess = " "*n

((n-1)/2).times do |i|
  a,b,c,d = str[2*i][0],str[2*i+1][0],str[-2*i-1][0],str[-2*i-2][0]
  (i+1).times do |j|
    if a[j] == b[j]
      guess[j] = a[j]
      guess[n-i-1+j] = a[j]
    end
  end
  (n-i-1).times do |j|
    if c[j] == d[j]
      guess[j] = c[j]
      guess[i+j+1] = c[j]
    end
  end
  #p guess
end

(n-1).times do |i|
  a,b = str[2*i][0],str[2*i+1][0]
  flg1,flg2 = true,true
  (i+1).times do |j|
    flg1 = false if guess[j] != " " && guess[j] != a[j]
    flg2 = false if guess[j] != " " && guess[j] != b[j]
  end
  if flg1 && !flg2
    guess[0,i+1] = a
    guess[n-i-1,i+1] = b
  elsif !flg1 && flg2
    guess[0,i+1] = b
    guess[n-i-1,i+1] = a
  end
end
#p guess

(n-1).times do |i|
  a,b = str[2*i][0],str[2*i+1][0]
  flg = true
  (i+1).times do |j|
    flg = false if guess[j] != " " && guess[j] != a[j]
  end
  #p [a,b,flg]
  if flg
    str[2*i] << "P"
    str[2*i+1] << "S"
  else
    str[2*i] << "S"
    str[2*i+1] << "P"
  end
end
#p guess

str.sort_by!{|s| s[1]}
str.each do |a|
  print "#{a[2]}"
end

# Utility
class StringBuilder
  def initialize(chunks)
    chunks_sorted = chunks.map.with_index { |chunk, i| {i: i, str: chunk} }
                          .sort { |a, b| a[:str].length <=> b[:str].length }
    @pairs = Array.new(chunks_sorted.length / 2) { |i| [chunks_sorted[2 * i], chunks_sorted[2 * i + 1]] }

    @string = build

    @solution = "S" * chunks.length
    @pairs.each do |p|
      if @string.start_with? p[0][:str]
        @solution[p[0][:i]] = "P"
      else
        @solution[p[1][:i]] = "P"
      end
    end
  end

  attr_reader :string
  attr_reader :solution

  private
  def build
    str_1 = @pairs[-1][0][:str] + @pairs[-1][1][:str][-1]
    str_2 = @pairs[-1][1][:str] + @pairs[-1][0][:str][-1]
    return str_1 if correct? str_1
    return str_2 if correct? str_2
  end

  def correct?(str)
    (str.length - 1).times do |i|
      break false unless @pairs[i].find { |e| str.start_with? e[:str] }
    end
  end
end

# Input
n = gets.to_i # 2 <= n <= 100
chunks = Array.new(2 * n - 2) { |i| gets.chop }

# Result
result = StringBuilder.new(chunks)
#puts result.string
puts result.solution

# Utility
class StringBuilder
  def initialize(chunks)
    chunks_sorted = chunks.map.with_index { |chunk, i| {i: i, str: chunk} }
                          .sort { |a, b| a[:str].length <=> b[:str].length }
    pairs = Array.new(chunks_sorted.length / 2) { |i| [chunks_sorted[2 * i], chunks_sorted[2 * i + 1]].sort! { |a, b| a[:str] <=> b[:str] } }
    # Beacuse of sorting inside pairs
    #p pairs

    str_1 = pairs[-1][0][:str]
    str_2 = pairs[-1][1][:str]
    if str_1 + str_2[-1] == str_1[0] + str_2
      # str_1 is prefix
      @string = str_1 + str_2[-1]
    else
      # str_2 is prefix
      @string = str_2 + str_1[-1]
    end

    @solution = "S" * chunks.length
    pairs.each do |p|
      if @string.start_with? p[0][:str]
        @solution[p[0][:i]] = "P"
      else
        @solution[p[1][:i]] = "P"
      end
    end
  end

  attr_reader :string
  attr_reader :solution
end

# Input
n = gets.to_i # 2 <= n <= 100
chunks = Array.new(2 * n - 2) { |i| gets.chop }

# Result
result = StringBuilder.new(chunks)
puts result.string
puts result.solution

# Utility
class StringBuilder
  def initialize(chunks)
    @n = 1 + chunks.length / 2
    chunks_sorted = chunks.sort { |a, b| a[:str].length <=> b[:str].length }
    pairs = Array.new(chunks_sorted.length / 2) { |i| [chunks_sorted[2 * i], chunks_sorted[2 * i + 1]] }

    builder(pairs)
  end

  attr_reader :string
  attr_reader :solution

  private
  def builder(pairs, str = nil, prefix_indexes = [], last_char = nil)
    # Building from prefixes
    unless str
      # First call
      str = ""
    end

    if pairs.length == 0
      # Last call
      @string = str + last_char
      @solution = "S" * (2 * @n - 2)
      prefix_indexes.each { |i| @solution[i] = "P" }
      return @string
    end

    pair = pairs.shift
    str_ext = nil # Next string
    2.times do |i|
      next unless pair[i][:str].start_with?(str)
      #puts "#{str} => #{pair[i][:str]}"
      str_ext = builder(pairs, pair[i][:str], prefix_indexes + [pair[i][:i]], last_char || pair[1 - i][:str])
      break if str_ext # Built successfully
      #puts "X"
    end

    return str_ext
  end
end

# Input
n = gets.to_i # 2 <= n <= 100
chunks = Array.new(2 * n - 2) { |i| {i: i, str: gets.chop} }

# Result
result = StringBuilder.new(chunks)
#puts result.string
puts result.solution

# Utility
class StringBuilder
  def initialize(chunks)
    chunks_sorted = chunks.map.with_index { |chunk, i| {i: i, str: chunk} }
                          .sort { |a, b| a[:str].length <=> b[:str].length }
    pairs = Array.new(chunks_sorted.length / 2) { |i| [chunks_sorted[2 * i], chunks_sorted[2 * i + 1]].sort! { |a, b| a[:str] <=> b[:str] } }
    # Beacuse of sorting inside pairs
    #p pairs

    str_1 = pairs[-1][0][:str]
    str_2 = pairs[-1][1][:str]
    if str_1 + str_2[-1] == str_1[0] + str_2
      # str_1 is prefix
      @string = str_1 + str_2[-1]
    else
      # str_2 is prefix
      @string = str_2 + str_1[-1]
    end

    @solution = "S" * chunks.length
    pairs.each do |p|
      if @string.start_with? p[0][:str]
        @solution[p[0][:i]] = "P"
      else
        @solution[p[1][:i]] = "P"
      end
    end
  end

  attr_reader :string
  attr_reader :solution
end

# Input
n = gets.to_i # 2 <= n <= 100
chunks = Array.new(2 * n - 2) { |i| gets.chop }

# Result
result = StringBuilder.new(chunks)
#puts result.string
puts result.solution


#!/usr/bin/env ruby

events_no = gets
events_seq = gets

output = Array.new(10, 0)

events_seq.delete!("\n").split('').each {  |c|

	if c == 'L'
		output[output.find_index(0)]=1
        elsif c == 'R'
		output[output.rindex(0)]=1

	else
		output[c.to_i] = 0
	end

}

puts output.join('')

def test
 ind_l = 0
 ind_r = 0

input = $stdin.read
input = input.split("\n")
 length = input[0].to_i
 str = input[1].chars

 out = [0,0,0,0,0,0,0,0,0,0]
 for i in str
    if i == 'L'

      ind_l = out.index(0)
      out[ind_l] = 1
      ind_l  = ind_l +1 ;
    elsif i == 'R'

        out_rev=out.reverse
        ind_r=out_rev.index(0)
        out[9-ind_r] = 1
        ind_r = ind_r +1 ;
    else

        out[i.to_i] = 0
    end

 end
 puts out.join()
end
test

def find_zero_index_from_left(array)
  found_index = nil
  array.each_with_index do |element, index|
    if element.eql?(0)
      found_index = index
      break
    end
  end
  found_index
end

def find_zero_index_from_right(array)
  found_index = nil
  (array.size - 1).downto(0).each do |index|
    if array[index].eql?(0)
      found_index = index
      break
    end
  end
  found_index
end

_ = gets.strip.to_i
arrives_code = gets.strip.split('')

codes = Array.new(10, 0)

arrives_code.each do |code|
  if code.eql?('L')
    index = find_zero_index_from_left(codes)
    codes[index] = 1
  elsif code.eql?('R')
    index = find_zero_index_from_right(codes)
    codes[index] = 1
  else
    index = code.to_i
    codes[index] = 0
  end
end

puts codes.join('')

def change_room_status_for(event_char, rooms_status)

  if event_char == "L"
    empty_room = rooms_status.index("0")
    rooms_status[empty_room] = "1"
  elsif event_char == "R"
    empty_room = rooms_status.rindex("0")
    rooms_status[empty_room] = "1"
  else
    checked_out_room = event_char.to_i
    rooms_status[checked_out_room] = "0"
  end

end

num_of_events_in_amugae_memory = gets.chomp.to_i

events = gets.chomp
rooms_status = '0' * 10

events.each_char { |event| change_room_status_for(event, rooms_status) }

puts rooms_status

def change_room_status_for(event_char, rooms_status)
  if event_char == "L"
    room_idx = closest_empty_room_from_left(rooms_status)
    rooms_status[room_idx] = "1"
  elsif event_char == "R"
    room_idx = closest_empty_room_from_right(rooms_status)
    rooms_status[room_idx] = "1"
  else
    leaving_customer_idx = event_char.to_i
    rooms_status[leaving_customer_idx] = "0"
  end
end

def closest_empty_room_from_left(rooms_status)
  rooms_status.index("0")
end

def closest_empty_room_from_right(rooms_status)
  idx = rooms_status.length - 1

  while idx >= 0
    if rooms_status[idx] == "0"
      return idx
    end

    idx -= 1
  end
end

num_of_events_in_amugae_memory = gets.chomp.to_i

events = gets.chomp
rooms_status = '0' * 10

events.each_char { |event| change_room_status_for(event, rooms_status) }

puts rooms_status

a=Array.new(10,0)
n=gets().to_i
s=gets()
for i in 0...n do
    if s[i]=="L" then
        a[a.index(0)]=1
    elsif s[i]=="R" then
        a[a.rindex(0)]=1
    else
        a[(s[i]).to_i]=0
    end
end
for i in 0..9 do
    print a[i]
end

n = gets.to_i
str = gets.chomp
ans = '0'*10
str.each_char do |x|
	if x == 'L'
		ans[ans.index('0')] = '1'
	elsif x == 'R'
		ans[ans.rindex('0')] = '1'
	else
		ans[x.to_i] = '0'
	end
end
puts ans

def find_zero_index_from_left(array)
  found_index = nil
  array.each_with_index do |element, index|
    if element.eql?(0)
      found_index = index
      break
    end
  end
  found_index
end

def find_zero_index_from_right(array)
  found_index = nil
  (array.size - 1).downto(0).each do |index|
    if array[index].eql?(0)
      found_index = index
      break
    end
  end
  found_index
end

_ = gets.strip.to_i
arrives_code = gets.strip.split('')

codes = Array.new(10, 0)

arrives_code.each do |code|
  if code.eql?('L')
    index = find_zero_index_from_left(codes)
    codes[index] = 1
  elsif code.eql?('R')
    index = find_zero_index_from_right(codes)
    codes[index] = 1
  else
    index = code.to_i
    codes[index] = 0
  end
end

p codes

def test
 ind_l = 0
 ind_r = 0
 $/ = "1"
input = STDIN.gets
input = input.split("\n")
 length = input[0].to_i
 str = input[1].to_s.chars

 out = [0,0,0,0,0,0,0,0,0,0]
 for i in str
    if i == 'L'

      ind_l = out.index(0)
      out[ind_l] = 1
      ind_l  = ind_l +1 ;
    elsif i == 'R'

        out_rev=out.reverse
        ind_r=out_rev.index(0)
        out[9-ind_r] = 1
        ind_r = ind_r +1 ;
    else

        out[i.to_i] = 0
    end

 end
 return out
end
test

def test
 ind_l = 0
 ind_r = 0
 $/ = "1"
input = STDIN.gets
input = input.split("\n")
 length = input[0].to_i
 str = input[1].to_s.chars

 out = [0,0,0,0,0,0,0,0,0,0]
 for i in str
    if i == 'L'

      ind_l = out.index(0)
      out[ind_l] = 1
      ind_l  = ind_l +1 ;
    elsif i == 'R'

        out_rev=out.reverse
        ind_r=out_rev.index(0)
        out[9-ind_r] = 1
        ind_r = ind_r +1 ;
    else

        out[i.to_i] = 0
    end

 end
 puts out.to_s
end
test

def test
 ind_l = 0
 ind_r = 0
 $/ = "1"
input = STDIN.gets
input = input.split("\n")
 length = input[0].to_i
 str = input[1].to_s.chars

 out = [0,0,0,0,0,0,0,0,0,0]
 for i in str
    if i == 'L'

      ind_l = out.index(0)
      out[ind_l] = 1
      ind_l  = ind_l +1 ;
    elsif i == 'R'

        out_rev=out.reverse
        ind_r=out_rev.index(0)
        out[9-ind_r] = 1
        ind_r = ind_r +1 ;
    else

        out[i.to_i] = 0
    end

 end
 puts "#{out}"
end
test

def test
 ind_l = 0
 ind_r = 0
 $/ = "1"
input = STDIN.gets
input = input.split("\n")
 length = input[0].to_i
 str = input[1].to_s.chars

 out = [0,0,0,0,0,0,0,0,0,0]
 for i in str
    if i == 'L'

      ind_l = out.index(0)
      out[ind_l] = 1
      ind_l  = ind_l +1 ;
    elsif i == 'R'

        out_rev=out.reverse
        ind_r=out_rev.index(0)
        out[9-ind_r] = 1
        ind_r = ind_r +1 ;
    else

        out[i.to_i] = 0
    end

 end
 puts out.join()
end
test

def test
 ind_l = 0
 ind_r = 0

input = $stdin.read
input = input.split("\n")
 length = input[0].to_i
 str = input[1].chars
 puts length
 puts str
 out = [0,0,0,0,0,0,0,0,0,0]
 for i in str
    if i == 'L'

      ind_l = out.index(0)
      out[ind_l] = 1
      ind_l  = ind_l +1 ;
    elsif i == 'R'

        out_rev=out.reverse
        ind_r=out_rev.index(0)
        out[9-ind_r] = 1
        ind_r = ind_r +1 ;
    else

        out[i.to_i] = 0
    end

 end
 puts out.join()
end
test

def test
 ind_l = 0
 ind_r = 0
input = $stdin.read
input = input.split("\n")
 length = input[0].to_i
 str = input[1].to_s.chars

 out = [0,0,0,0,0,0,0,0,0,0]
 for i in str
    if i == 'L'

      ind_l = out.index(0)
      out[ind_l] = 1
      ind_l  = ind_l +1 ;
    elsif i == 'R'

        out_rev=out.reverse
        ind_r=out_rev.index(0)
        out[9-ind_r] = 1
        ind_r = ind_r +1 ;
    else

        out[i.to_i] = 0
    end

 end
 return out
end
test

def test
 ind_l = 0
 ind_r = 0
input = $stdin.read
input = input.split("\n")
 length = input[0].to_i
 str = input[1].to_s.chars

 out = [0,0,0,0,0,0,0,0,0,0]
 for i in str
    if i == 'L'
      puts 'L'
      ind_l = out.index(0)
      out[ind_l] = 1
      ind_l  = ind_l +1 ;
    elsif i == 'R'
        puts 'R'
        out_rev=out.reverse
        ind_r=out_rev.index(0)
        out[9-ind_r] = 1
        ind_r = ind_r +1 ;
    else
        puts 'ji'
        out[i.to_i] = 0
    end
    puts "#{out}"
 end
 return out
end

def test
 ind_l = 0
 ind_r = 0
 $/ = "1"
input = STDIN.gets
input = input.split("\n")
 length = input[0].to_i
 str = input[1].to_s.chars

 out = [0,0,0,0,0,0,0,0,0,0]
 for i in str
    if i == 'L'

      ind_l = out.index(0)
      out[ind_l] = 1
      ind_l  = ind_l +1 ;
    elsif i == 'R'

        out_rev=out.reverse
        ind_r=out_rev.index(0)
        out[9-ind_r] = 1
        ind_r = ind_r +1 ;
    else

        out[i.to_i] = 0
    end

 end
 puts out
end
test


gets.to_i.times do
  aa,bb,k=gets.split.map(&:to_i)
  a=gets.split.map(&:to_i).sort
  b=gets.split.map(&:to_i).sort
  c=0
  q=0
  cc=0
  a.each do |ai|
    if ai==q
      cc+=1
    else
      c+=cc*(cc-1)/2
      cc=1
      q=ai
    end
  end
  c+=cc*(cc-1)/2
  q=0
  cc=0
  b.each do |ai|
    if ai==q
      cc+=1
    else
      c+=cc*(cc-1)/2
      cc=1
      q=ai
    end
  end
  c+=cc*(cc-1)/2
  puts k*(k-1)/2-c
end

tcases = gets.chomp.to_i
def solve()
  a, b, k = *(gets.chomp.split.map(&:to_i))
  boys = gets.chomp.split.map(&:to_i)
  girls = gets.chomp.split.map(&:to_i)
  boy_out = Array.new(a + 1, 0)
  girls_in =  Array.new(b + 1, 0)
  boys.each do |i|
    boy_out[i] += 1
  end
  girls.each do |i|
    girls_in[i] += 1
  end
  # puts "boy_out = #{boy_out.join(" ")}"
  # puts "girls_out = #{girls_in.join(" ")}"
  ans = 0
  0.upto k-1 do |i|
    b, g = boys[i], girls[i]
    bout, gin = boy_out[b], girls_in[g]
    ans += k - (bout + gin - 1)
  end
  # puts "ans = "
  puts ans / 2
end
tcases.times do solve() end


def solution

  _, m, k = read_ints
  objects = read_ints.reverse

  used_boxes = 1
  crt_size = k
  packed = 0

  for o in objects
    if o <= crt_size
      packed += 1
      crt_size -= o
    else
      if used_boxes < m
        used_boxes += 1
        packed += 1
        crt_size = k - o
      else
        break
      end
    end
  end

  puts packed

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,m,k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
ans = 0

cap = k
m -= 1
(n-1).downto(0) do |i|
  if a[i] <= cap
    cap -= a[i]
    ans += 1
  elsif m != 0 && a[i] <= k
    m -= 1
    cap = k-a[i]
    ans += 1
  else
    break
  end
end

puts ans


n = gets.to_i
p = [0,1] + gets.split.map(&:to_i)
dist = [0,0]
gp = Array.new(n+1,0)
gp[0] = 1
2.upto(n) do |i|
  dist[i] = dist[p[i]] + 1
  gp[dist[i]] += 1
end
ans = 0
gp.each do |e|
  ans += 1 if e % 2 == 1
end
p ans

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

class Node
	attr_accessor :value, :children, :degree

	def initialize value
		@value = value
		@children = []
	end
end
an = Array.new(arr.length+1) { |i| Node.new(i+1)}
i = 0

while i < arr.length
	k = i+1
	an[arr[i]-1].children.push(an[k])
	i+=1
end
an.first.degree = 0
degree = [1]
queue = [an.first]
while queue.length > 0
	el = queue.shift
	el.children.each do |c|
		c.degree = el.degree+1
		degree[c.degree] ||= 0
		degree[c.degree]+=1
		queue.push(c)
	end
end
sum = 0
degree.each do |e|
	if e % 2 != 0
		sum+=1
	end
end
puts sum


def solve(arr, s)
  len = arr.size

  len.times do |i|
    arr[i] += arr[i - 1] if i > 0
  end

  max_result = -1

  if arr[-1] < s
    return -1
  end

  len.times do |left|
    result = binsearch(arr, left, s)
    # p [left, result, (result - left + 1)]

    if (result - left + 1) > max_result
      max_result = result - left + 1
    end
  end

  len - max_result
end

def binsearch(arr, left, a)
  l = left - 1
  r = arr.size

  while l < r - 1
    m = (l + r) / 2
    if (arr[m] - (left > 0 ? arr[left - 1] : 0)) <= a
      l = m
    else
      r = m
    end
  end

  l
end

n = gets.to_i

n.times do
  size, s = gets.split.map(&:to_i)
  array = Array.new(size)
  array = gets.split.map(&:to_i)

  p solve(array, s)
end

def solve
    q = gets.split.map(&:to_i)
    a = gets.split.map(&:to_i)
    n = q[0]
    s = q[1]
    sum = 0
    a.each do |x|
        sum = sum + x
    end
    if s > sum
        puts "-1"
        return
    end
    l = 1
    r = a.length
    while l < r
        mid = (l + r + 1) / 2
        ok = false
        pref = Array.new(n + 1)
        pref[0] = 0
        i = 1
        a.each do |x|
            pref[i] = pref[i - 1]
            pref[i] = pref[i] + x
            if (i - mid) >= 0
                curr = pref[i] - pref[i - mid]
                if curr <= s
                    ok = true
                end
            end
            i = i + 1
        end
        if ok == true
            l = mid
        else
            r = mid - 1
        end
    end
    puts n - l
end

gets.to_i.times do
    solve
end

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

  cnt = 0
  l = 0
  inf = 10101010101010
  ans = inf
  n.times do |r|
    cnt += a[r]
    while l < r && cnt > s
      cnt -= a[l]
      l += 1
    end

    ans = [ans, n-(r-l+1)].min if cnt == s
  end

  puts ans == inf ? -1 : ans
end

main = -> {
    t = int
    t.times do
        n, s = ints
        a = ints
        a_sum = [0]
        a.each do |x|
            a_sum << a_sum[-1] + x
        end

        sum = a_sum[-1]

        if s > sum
            puts -1
            next
        end

        has_to_remove = sum - s

        ans = INF
        (0 ... n).each do |i|
            removed = a_sum[i]
            break if removed > has_to_remove
            j = (0 .. n).bsearch { |m| sum - a_sum[n - m] >= has_to_remove - removed } || 0
            ans = i + j if i + j < ans
        end

        puts ans
    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[]

bsearch_last = ->range, map, target {
  l, r = range.begin, range.end + 1
  while l < r
    m = (l + r) / 2
    if map[m] > target
      r = m
    else
      l = m + 1
    end
  end
  map[r - 1] == target ? r - 1 : nil
}

gets.to_i.times do
  n, s = gets.split.map(&:to_i)
  xs = gets.split.map(&:to_i)
  ps = [0]
  xs.each { |x| ps << x + ps.last }
  sum_inclusive = ->(from, to) { ps[to + 1] - ps[from] }
  answer = (0..n - 1).filter_map do |from|
    to = bsearch_last[from..n - 1, ->to { sum_inclusive[from, to] }, s]
    to ? n - (to - from + 1) : nil
  end.min || -1
  p answer
end

gets.to_i.times do
  n, s = gets.split.map(&:to_i)
  xs = gets.split.map(&:to_i)
  map = {}
  sum, max = 0, -1
  xs.each.with_index do |x, i|
    sum += x
    max = i + 1 if sum == s
    map[sum] ||= i
    if j = map[sum - s]
      max = [max, i - j].max
    end
  end
  p max == -1 ? -1 : n - max
end

bsearch_last = ->range, block {
  i = (0..range.end - range.begin).bsearch { |i| block[range.end - i] }
  i ? range.end - i : i
}

gets.to_i.times do
  n, s = gets.split.map(&:to_i)
  xs = gets.split.map(&:to_i)
  ps = [0]
  xs.each { |x| ps << x + ps.last }
  sum_inclusive = ->(from, to) { ps[to + 1] - ps[from] }
  answer = (0..n - 1).filter_map do |from|
    to = bsearch_last[from..n - 1, ->to { sum_inclusive[from, to] == s }]
    to ? n - (to - from + 1) : nil
  end.min || -1
  p answer
end


s = gets.chomp
manin = 0
manout = 0
s.size.times do |i|
    if s[i] == "+" then
        manin += 1
        if manout != 0 then
            manout -= 1
        end
    else
        manout += 1
        if manin != 0 then
            manin -= 1
        end
    end
end
result = manin + manout
puts "#{result}"

tmp,mn,mx=0,0,0
gets.to_s.chomp.each_char do |c|
	c=="-"?(tmp-=1):(tmp+=1)
	mn=tmp if tmp<mn
	mx=tmp if mx<tmp
end
puts (mn.abs+mx.abs)

dict = {
    'UCA' => 'S',    # Serine
    'UCC' => 'S',    # Serine
    'UCG' => 'S',    # Serine
    'UCU' => 'S',    # Serine
    'UUC' => 'F',    # Phenylalanine
    'UUU' => 'F',    # Phenylalanine
    'UUA' => 'L',    # Leucine
    'UUG' => 'L',    # Leucine
    'UAC' => 'Y',    # Uyrosine
    'UAU' => 'Y',    # Uyrosine
    'UAA' => '_',    # Stop
    'UAG' => '_',    # Stop
    'UGC' => 'C',    # Cysteine
    'UGU' => 'C',    # Cysteine
    'UGA' => '_',    # Stop
    'UGG' => 'W',    # Uryptophan
    'CUA' => 'L',    # Leucine
    'CUC' => 'L',    # Leucine
    'CUG' => 'L',    # Leucine
    'CUU' => 'L',    # Leucine
    'CCA' => 'P',    # Proline
    'CCC' => 'P',    # Proline
    'CCG' => 'P',    # Proline
    'CCU' => 'P',    # Proline
    'CAC' => 'H',    # Histidine
    'CAU' => 'H',    # Histidine
    'CAA' => 'Q',    # Glutamine
    'CAG' => 'Q',    # Glutamine
    'CGA' => 'R',    # Arginine
    'CGC' => 'R',    # Arginine
    'CGG' => 'R',    # Arginine
    'CGU' => 'R',    # Arginine
    'AUA' => 'I',    # Isoleucine
    'AUC' => 'I',    # Isoleucine
    'AUU' => 'I',    # Isoleucine
    'AUG' => 'M',    # Methionine
    'ACA' => 'T',    # Uhreonine
    'ACC' => 'T',    # Uhreonine
    'ACG' => 'T',    # Uhreonine
    'ACU' => 'T',    # Uhreonine
    'AAC' => 'N',    # Asparagine
    'AAU' => 'N',    # Asparagine
    'AAA' => 'K',    # Lysine
    'AAG' => 'K',    # Lysine
    'AGC' => 'S',    # Serine
    'AGU' => 'S',    # Serine
    'AGA' => 'R',    # Arginine
    'AGG' => 'R',    # Arginine
    'GUA' => 'V',    # Valine
    'GUC' => 'V',    # Valine
    'GUG' => 'V',    # Valine
    'GUU' => 'V',    # Valine
    'GCA' => 'A',    # Alanine
    'GCC' => 'A',    # Alanine
    'GCG' => 'A',    # Alanine
    'GCU' => 'A',    # Alanine
    'GAC' => 'D',    # Aspartic Acid
    'GAU' => 'D',    # Aspartic Acid
    'GAA' => 'E',    # Glutamic Acid
    'GAG' => 'E',    # Glutamic Acid
    'GGA' => 'G',    # Glycine
    'GGC' => 'G',    # Glycine
    'GGG' => 'G',    # Glycine
    'GGU' => 'G'    # Glycine
}

s = gets.chomp!

f = g = c =0; res = 0; s.each_char{|si|
	c = 1 if si == '+'; c = -1 if si == '-'
	f += c; g += c; f = 0 if f < 0; g = 0 if g > 0
	res = f if f > res; res = -g if -g > res
}

p res

dict = {
    'UCA' => 'S',    # Serine
    'UCC' => 'S',    # Serine
    'UCG' => 'S',    # Serine
    'UCU' => 'S',    # Serine
    'UUC' => 'F',    # Phenylalanine
    'UUU' => 'F',    # Phenylalanine
    'UUA' => 'L',    # Leucine
    'UUG' => 'L',    # Leucine
    'UAC' => 'Y',    # Uyrosine
    'UAU' => 'Y',    # Uyrosine
    'UAA' => '_',    # Stop
    'UAG' => '_',    # Stop
    'UGC' => 'C',    # Cysteine
    'UGU' => 'C',    # Cysteine
    'UGA' => '_',    # Stop
    'UGG' => 'W',    # Uryptophan
    'CUA' => 'L',    # Leucine
    'CUC' => 'L',    # Leucine
    'CUG' => 'L',    # Leucine
    'CUU' => 'L',    # Leucine
    'CCA' => 'P',    # Proline
    'CCC' => 'P',    # Proline
    'CCG' => 'P',    # Proline
    'CCU' => 'P',    # Proline
    'CAC' => 'H',    # Histidine
    'CAU' => 'H',    # Histidine
    'CAA' => 'Q',    # Glutamine
    'CAG' => 'Q',    # Glutamine
    'CGA' => 'R',    # Arginine
    'CGC' => 'R',    # Arginine
    'CGG' => 'R',    # Arginine
    'CGU' => 'R',    # Arginine
    'AUA' => 'I',    # Isoleucine
    'AUC' => 'I',    # Isoleucine
    'AUU' => 'I',    # Isoleucine
    'AUG' => 'M',    # Methionine
    'ACA' => 'T',    # Uhreonine
    'ACC' => 'T',    # Uhreonine
    'ACG' => 'T',    # Uhreonine
    'ACU' => 'T',    # Uhreonine
    'AAC' => 'N',    # Asparagine
    'AAU' => 'N',    # Asparagine
    'AAA' => 'K',    # Lysine

    'GGC' => 'G',    # Glycine
    'GGG' => 'G',    # Glycine
    'GGU' => 'G'    # Glycine
}

s = gets.chomp!

f = g = c =0; res = 0; s.each_char{|si|
    c = 1 if si == '+'; c = -1 if si == '-'
    f += c; g += c; f = 0 if f < 0; g = 0 if g > 0
    res = f if f > res; res = -g if -g > res
}

p res

s=gets.chomp
prev=s[0]
res=[]
k=1
res<<k
s[1..-1].each_char do |c|
    x=c==s[0] ? 1 : -1
    k+=x if prev==c
    res<<k
    prev=c
end
puts res.max-res.min+1

def main()
	s=gets.chomp.to_s
	nops=0
	inclub=0
	outclub=0
	for i in 0...(s.length)
		if s[i].chr=="+"
			inclub+=1
			if outclub ==0
				nops+=1
			else
				outclub-=1
			end
		else
			outclub+=1
			if inclub==0
				nops+=1
			else
				inclub-=1
			end
		end
	end
	puts nops
end
main()

pos=0
neg=0
count=0

gets.chomp.each_char {|c|
  if c==?+
    count+=1
  else
    count-=1
  end

  pos=count if count>pos
  neg=count if count<neg
}

puts pos.abs+neg.abs

def abs(x)
    if x > 0 then return x
    else return -x
    end
end

s = gets.chomp
plus = 0
minus = 0
k = false
t = false
s.size.times do |i|
    if s[i] == "+" then
        plus += 1
        k = true
    else
        minus += 1
        t = true
    end
end
man = abs(plus-minus)
if k && t then
    man += 1
end
puts "#{man}"

def dif(s,i)
    k = i
    while i < s.size && s[i] != s[i-1] do
        i += 1
    end
    return i-k
end

def find(x, s)
    x.each_index do |i|
        if x[i] == s then
            return i
        end
    end
    return false
end

s = gets.chomp
i = 1
man = [s[0]]
while i < s.size do
    if s[i] != s[i-1] then
        t = find(man, s[i])
        k = dif(s,i)
        i += k
        if t then
            man[t] = s[i-1]
        end
    else
        while s[i] == s[i-1] do
            if s[i] == "+" then
                t = find(man, "-")
            else
                t = find(man, "+")
            end
            if t then
                man[t] = s[i]
            else
                man += [s[i]]
            end
            i += 1
        end
    end
end
puts "#{man.size}"

def abs(x)
    if x > 0 then return x
    else return -x
    end
end

s = gets.chomp
plus = 0
minus = 0
s.size.times do |i|
    if s[i] == "+" then
        plus += 1
    else
        minus += 1
    end
end
if abs(plus-minus) != 0 then
    man = abs(plus-minus)
else
    man = 1
end
puts "#{man}"

def same(s, i)
    k = i
    while (i < s.size && s[i] == s[i-1]) do
        i += 1
    end
    return i-k
end

def dif(s, i)
    k = i
    while (i < s.size && s[i] != s[i-1]) do
        i += 1
    end
    return i-k
end

def alsame(s, i)
    if same(s,i) == s.size-1 then
        s = ""
    end
    return s
end

s = gets.chomp
plus = 0
minus = 0
man = 0
i = 1
while s.size != 0 do
    k = s.size
    s = alsame(s,i)
    if s == "" then
        man += k
    else
        t = dif(s,i)
        s = s[t..-1]
        if t != 0 then
            man += 1
            s = s[1..-1]
        end
        k = s.size
        s = alsame(s,i)
        if s == "" then
            man += k
        else
            k = same(s,i)
            s = s[k..-1]
            man += k
        end
    end
end
puts "#{man}"

s = gets
plus = 0
minus = 0
s.size.times do |i|
    if s[i] == "+" then plus += 1
    else
        minus += 1
    end
end
man = 1
man += (plus-minus).abs
puts "#{man}"

a = gets.to_s.chomp.split(//)
puts (a.find_all{|el|el=="+"}.size-a.find_all{|el|el=="-"}.size).abs

s= gets.to_s.chomp
a=s.split(//)
n= (a.find_all{|el|el=="+"}.size-a.find_all{|el|el=="-"}.size).abs
t1="+"*(s.size-1)
t2="-"*(s.size-1)
while s.index(t1)==nil&&s.index(t2)==nil&&t1!="+" do
t1.chop!
t2.chop!
end
puts [t1.size,n].max

s= gets.to_s.chomp
a=s.split(//)
n= (a.find_all{|el|el=="+"}.size-a.find_all{|el|el=="-"}.size).abs
t1="+"*(s.size-1)
t2="-"*(s.size-1)
while s.index(t1)==nil&&s.index(t2)==nil&&t1!="+" do
t1.chop!
p t1
t2.chop!
end
puts [t1.size,n].max

dict = {
    'UUG' => 'L',    # Leucine
    'UAC' => 'Y',    # Uyrosine
    'UAU' => 'Y',    # Uyrosine
    'UAA' => '_',    # Stop
    'UAG' => '_',    # Stop
    'UGC' => 'C',    # Cysteine
    'UGU' => 'C',    # Cysteine
    'CCU' => 'P',    # Proline
    'CAC' => 'H',    # Histidine
    'CAU' => 'H',    # Histidine
    'CAA' => 'Q',    # Glutamine
    'CAG' => 'Q',    # Glutamine
    'CGA' => 'R',    # Arginine
    'CGC' => 'R',    # Arginine
    'CGG' => 'R',    # Arginine
    'CGU' => 'R',    # Arginine
    'AUA' => 'I',    # Isoleucine
    'AUC' => 'I',    # Isoleucine
    'AUU' => 'I',    # Isoleucine
    'AUG' => 'M',    # Methionine
    'ACA' => 'T',    # Uhreonine

    'GUG' => 'V',    # Valine
    'GUU' => 'V',    # Valine
    'GCA' => 'A',    # Alanine
    'GCC' => 'A',    # Alanine
    'GCG' => 'A',    # Alanine
    'GCU' => 'A',    # Alanine
    'GAC' => 'D',    # Aspartic Acid
    'GAU' => 'D',    # Aspartic Acid
    'GAA' => 'E',    # Glutamic Acid
    'GAG' => 'E',    # Glutamic Acid
    'GGA' => 'G',    # Glycine
    'GGC' => 'G',    # Glycine
    'GGG' => 'G',    # Glycine
    'GGU' => 'G'    # Glycine
}

s = gets.chomp!

f = g = c =0; res = 0; s.each_char{|si|
    c = 1 if si == '+'; c = -1 if si == '-'
    f += c; g += c; f = 0 if f < 0; g = 0 if g > 0
    res = f if f > res; res = -g if -g > res
}

res=k=0
gets.chomp.each_char do |c|
    k+=1 if c=='+'
    k-=1 if c=='-'
    res=[res, k.abs].max
end
puts res

s=gets.gsub("-+", "- +").gsub("+-", "+ -").split
s.push("o") if s.size%2==1
n=s.size/2
res=0
for i in 0..n-1 do
    res=[res, [s[2*i].size, s[2*i+1].size].max].max
end
puts res

s=gets.chomp
res=p=m=0
s.each_char do |c|
    p+=1 if c=='+'
    m+=1 if c=='-'
    res=[res, (p-m).abs].max
end
puts res

s=gets.chomp
res=0
for i in 1..s.size()
    res=i if s.include?('+'*i) or s.include?('-'*i)
end
puts res

def main()
	s=gets.chomp.to_s
	totin=0
	totout=0
	nops=1
	for i in 0...(s.length)
		if s[i].chr=="+"
			totin+=1
			if totin-1 > totout
				nops+=1
			end
		else
			totout+=1
			if totout-1 > totin
				nops+=1
			end
		end
	end
	puts nops
end
main()

def main()
	s=gets.chomp.to_s
	totin=0
	totout=0
	nops=0
	for i in 0...(s.length)
		if s[i].chr=="+"
			totin+=1
			if totin-totout>1 || totout==0
				nops+=1
			end
		else
			totout+=1
			if totout-totin>1 || totin==0
				nops+=1
			end
		end
	end
	puts nops
end
main()

def main()
	s=gets.chomp.to_s
	nops=0
	for i in 0...(s.length)
		if s[i].chr=="+"
			lns=0
			indoln=-7
			j=i-1
			while(j>=0)
				if s[j].chr=="-"
					indoln=j
					break
				end
				j-=1
			end
			if indoln!=-7
				j=indoln
				while(j>=0)
					if s[j].chr=="-"
						lns+=1
						j-=1
					else
						break
					end
				end
				if lns<=i-indoln-1
					nops+=1
				end
			else
				nops+=1
			end
		else
			lps=0
			indolp=-7
			j=i-1
			while(j>=0)
				if s[j].chr=="+"
					indolp=j
					break
				end
				j-=1
			end
			if indolp!=-7
				j=indolp
				while(j>=0)
					if s[j].chr=="+"
						lps+=1
						j-=1
					else
						break
					end
				end
				if lps<=i-indolp-1
					nops+=1
				end
			else
				nops+=1
			end
		end
	end
	puts nops
end
main()

def main()
	s=gets.chomp.to_s
	maxp=0
	maxn=0
	ps="+"
	ns="-"
	j=300
	while(true)
		ind=s.index(ps*j)
		if ind!=nil
			maxp=j
			break
		end
		j-=1
	end
	j=300
	while(true)
		ind=s.index(ns*j)
		if ind!=nil
			maxn=j
			break
		end
		j-=1
	end
	puts [maxp,maxn].max
end
main()

max=0
count=0

gets.chomp.each_char {|c|
  if c==?+
    count=0 if count<0
    count+=1
  else
    count-=1
  end

  max=count.abs if count.abs>max
}

puts max

max=0
count=0

gets.chomp.each_char {|c|
  if c==?+
    count+=1
  else
    count-=1
  end

  max=count.abs if count.abs>max
}

puts max

pos=0
neg=0
count=0

gets.chomp.each_char {|c|
  if c==?+
    count+=1
  else
    count-=1
  end

  pos=count if count>pos
  neg=count if count<neg
}

puts [pos.abs,neg.abs].max

puts gets.chomp.chars.to_a.reduce([0, 0]) { |s, x| s[0] += (x == '+' ? 1 : -1); [s.first, [s.first.abs, s.last].max] }.last


def solve
  _, x = gets.strip.split(' ').map(&:to_i)
  a = gets.strip.split(' ').map(&:to_i)

  h = Hash.new(0)
  a.each_with_index { |e, i|
    if i.zero?
      h[i] = e
      next
    end
    h[i] = h[i - 1] + e
  }

  sum = a.reduce(:+)
  an = a.size
  if sum % x != 0
    puts an
    return nil
  end

  i = 0
  while i < a.size
    if sum % x == 0 && (sum - h[i]) % x != 0
      an = an - i - 1;
      break;
    elsif sum % x == 0 && (sum - h[a.size - i - 2]) % x != 0
      an = an - i - 1
      break;
    end
    i += 1
  end
  if an == a.size
    puts "-1"
  else
    puts an
  end
end

gets.strip.to_i.times { solve }

def solve
  _, x = gets.strip.split(' ').map(&:to_i)
  a = gets.strip.split(' ').map(&:to_i)

  h = Hash.new(0)
  a.each_with_index { |e, i|
    if i.zero?
      h[i] = e
      next
    end
    h[i] = h[i - 1] + e
  }

  sum = a.reduce(:+)
  an = a.size
  if sum % x != 0
    puts an
    return nil
  end

  i = 0
  while i < a.size
    if sum % x == 0 && (sum - h[i]) % x != 0 || sum % x == 0 && (sum - h[a.size - i - 2]) % x != 0
      an = an - i - 1;
      break;
    end
    i += 1
  end
  if an == a.size
    puts "-1"
  else
    puts an
  end
end

gets.strip.to_i.times { solve }

def ans(r, x)
    r.count {|e| e % x !=0 } == 0 and return -1
    r.sum % x != 0 and return r.length
    # find first e % x != 0
    lidx = r.index {|e| e % x != 0}
    ridx = r.rindex {|e| e % x != 0}
    return [r.length - lidx -1, ridx].max
end

gets.to_i.times {
    (_x, x) = gets.chomp.split(' ').map &:to_i
    r = gets.chomp.split(' ').map &:to_i
    puts ans(r,x)
}

def solve
  _, x = gets.strip.split(' ').map(&:to_i)
  a = gets.strip.split(' ').map(&:to_i)

  h = Hash.new(0)
  a.each_with_index { |e, i|
    if i.zero?
      h[i] = e
      next
    end
    h[i] = h[i - 1] + e
  }

  sum = a.reduce(:+)
  an = a.size
  if sum % x != 0
    puts an
    return nil
  end

  i = 0
  while i < a.size
    if sum % 3 == 0 && (sum - h[i]) % 3 != 0
      an = an - i - 1;
      break;
    elsif sum % 3 == 0 && (sum - h[a.size - i - 1]) % 3 != 0
      sum -= h[a.size - i - 1]
      an = an - i - 1
      break;
    end
    i += 1
  end
  if an == a.size
    puts "-1"
  else
    puts an
  end
end

gets.strip.to_i.times { solve }

def solve
  _, x = gets.strip.split(' ').map(&:to_i)
  a = gets.strip.split(' ').map(&:to_i)

  h = Hash.new(0)
  a.each_with_index { |e, i|
    if i.zero?
      h[i] = e
      next
    end
    h[i] = h[i - 1] + e
  }

  sum = a.reduce(:+)
  an = a.size
  if sum % x != 0
    puts an
    return nil
  end

  i = 0
  while i < a.size
    if sum % x == 0 && (sum - h[i]) % x != 0
      an = an - i - 1;
      break;
    elsif sum % x == 0 && (sum - h[a.size - i - 2]) % x != 0
      puts i
      an = an - i - 1
      break;
    end
    i += 1
  end
  if an == a.size
    puts "-1"
  else
    puts an
  end
end

gets.strip.to_i.times { solve }

def solve
  _, x = gets.strip.split(' ').map(&:to_i)
  a = gets.strip.split(' ').map(&:to_i)
  a.each_with_index { |e, i| a[i] = a[i] % x; }
  sum = a.reduce(:+)
  if (sum).zero?
    puts "-1"
    return nil
  end
  if sum % x != 0
    puts a.size
    return nil
  end
  l = 0; r = a.size - 1; an = a.size
  while a[l].zero?
    l += 1
    an -= 1
  end
  while a[r].zero?
    r -= 1
    an -= 1
  end
  puts an + 1
end

gets.strip.to_i.times { solve }

def solve
  _, x = gets.strip.split(' ').map(&:to_i)
  a = gets.strip.split(' ').map(&:to_i)

  h = Hash.new(0)
  a.each_with_index { |e, i|
    if i.zero?
      h[i] = e
      next
    end
    h[i] = h[i - 1] + e
  }

  sum = a.reduce(:+)
  an = a.size
  if sum % x != 0
    puts an
    return nil
  end

  i = 0
  while i < a.size
    if sum % 3 == 0 && (sum - h[i]) % 3 != 0
      an = an - i - 1;
      break;
    elsif sum % 3 == 0 && (sum - h[a.size - i - 1]) % 3 != 0
      sum -= h[a.size - i - 1]
      an = an - i - 1
      break;
    end
    i += 1
  end
  puts "-1" if an.zero? || an == a.size
  puts an if !an.zero?
end

gets.strip.to_i.times { solve }


# http://codeforces.com/problemset/problem/950/B
n, m = gets.split.map(&:to_i)
m1 = gets.split.map(&:to_i)
m2 = gets.split.map(&:to_i)

c = 0
if m == 1 || n == 1
  puts 1
else
  file1_size = 0
  file2_size = 0
  p1 = 0
  p2 = 0

  while p1 < n && p2 < m
    if file1_size + m1[p1] == file2_size + m2[p2]
      file1_size = 0
      file2_size = 0
      p1 += 1
      p2 += 1
      c += 1
      next
    end

    if file1_size + m1[p1] > file2_size + m2[p2]
      file2_size += m2[p2]
      p2 += 1
    else
      file1_size += m1[p1]
      p1 += 1
    end
  end
  puts c
end

la,lb=gets.split.collect{|t|t.to_i}
sbl,res=0,0
a=gets.split.collect{|t|t.to_i}
b=gets.split.collect{|t|t.to_i}
while a.size>0
  if sbl==0
    res+=1
    sbl+=a.shift
  end
  if sbl>0
    sbl-=b.shift
  else
    sbl+=a.shift
  end
end
puts res

n, m = gets.split.map(&:to_i)
a = gets.chomp.split.map(&:to_i)
b = gets.chomp.split.map(&:to_i)
ans, sa, sb, la, lb = 0, 0, 0, 0, 0
while la < n || lb < m
  if sa == 0
    sa += a[la]
    la += 1
  end
  if sb == 0
    sb += b[lb]
    lb += 1
  end
  if sa == sb
    ans += 1
    sa = 0
    sb = 0
  else
    if sa < sb
      sa += a[la]
      la += 1
    else
      sb += b[lb]
      lb += 1
    end
  end
end
ans += 1 if sa != 0
puts ans

# http://codeforces.com/problemset/problem/950/B
n, m = gets.split.map(&:to_i)
m1 = gets.split.map(&:to_i)
m2 = gets.split.map(&:to_i)

c = 0
if m == 1 || n == 1
  puts 1
else
  file1_size = 0
  file2_size = 0
  p1 = 0
  p2 = 0

  while p1 < n && p2 < m
    if file1_size + m1[p1] == file2_size + m2[p2]
      file1_size = 0
      file2_size = 0
      p1 += 1
      p2 += 1
      c += 1
      next
    end

    if file1_size + m1[p1] > file2_size + m2[p2]
      file2_size += m2[p2]
      p2 += 1
    else
      file1_size += m1[p1]
      p1 += 1
    end
  end
end

puts c


gets
a = gets.split.map { |x| x.to_i }.sort
gets
b = gets.split.map { |x| x.to_i }.sort.join(" ")

a.each do |x|
  b.sub!(/\b(#{x-1}|#{x}|#{x+1})\b/, "200")
end
puts b.scan(/200/).length

n = STDIN.readline.to_i
boys = STDIN.readline.split.map {|s| s.to_i }
m = STDIN.readline.to_i
girls = STDIN.readline.split.map {|s| s.to_i }

def search(n, m, kosher, u, seen, match)
	n.times do |v|
		if kosher[u][v] and not seen[v]
			seen[v] = true
			if match[v] < 0 or search(n, m, kosher, match[v], seen, match)
				match[v] = u
				return true
			end
		end
	end
	false
end

kosher = m.times.map {|j| n.times.map {|i| (boys[i]-girls[j]).abs <= 1 } }
match = n.times.map { -1 }
count = 0
m.times do |u|
	seen = n.times.map { false }
	count += 1 if search(n, m, kosher, u, seen, match)
end
puts count

n = STDIN.readline.to_i
boys = STDIN.readline.split.map {|s| s.to_i }.sort
m = STDIN.readline.to_i
girls = STDIN.readline.split.map {|s| s.to_i }.sort

b = 0
count = 0
girls.each do |girl|
	b += 1 while b < n and girl-boys[b] > 1
	if b < n and (girl-boys[b]).abs <= 1
		count += 1
		b += 1
	end
end

puts count

n = gets.to_i
a = gets.split.map { |x| x.to_i }.sort
m = gets.to_i
b = gets.split.map { |x| x.to_i }.sort

i, j = 0, 0
cnt = 0
while i < n and j < m
  if (a[i] - b[j]).abs <= 1
    i += 1
    j += 1
    cnt += 1
  elsif a[i] + 1 < b[j]
    i += 1
  else
    j += 1
  end
end

puts cnt

gets
x=gets.split.map{|e| e.to_i}.sort
gets
y=gets.split.map{|e| e.to_i}.sort

ans=0
while (!x.empty?) && (!y.empty?)
	if (x[0]-y[0]).abs<=1 then
		ans+=1
		x.shift
		y.shift
	else
		if x[0]<y[0] then
			x.shift
		else
			y.shift
		end
	end
end

puts ans

#$stdin = File.open "input.txt"

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

m = gets.to_i
b = gets.split.map(&:to_i).sort

i, j, pairs = 0, 0, 0

while (i < n) && (j < m)
	if (a[i] - b[j]).abs <= 1
		pairs += 1
		i += 1
		j += 1
	else
		if a[i] < b[j]; i += 1 else j += 1 end
	end
end

p pairs

n = Integer(gets)
nums = gets.chomp.split
boy = Array.new
for i in 0...n
    boy[i] = Integer(nums[i])
end
m = Integer(gets)
nums2 = gets.chomp.split
girl = Array.new
for i in 0...m
    girl[i] = Integer(nums2[i])
end

boy.sort!
girl.sort!
def pairs(x,y)
    count = 0
    for i in 0...x.length
        for j in 0...y.length
            if (x[i] - y[j]).abs <= 1
                count += 1
                y.delete_at(j)
                break
            end
        end
    end
    return count
end

if  n >= m
    puts pairs(girl, boy)
else
    puts pairs(boy, girl)
end

boys = gets.chomp.to_i
boys_skills = gets.chomp
boys_skills = boys_skills.split
girls = gets.chomp.to_i
girls_skills = gets.chomp
girls_skills = girls_skills.split

count = 0
for i in (0..girls-1)
	for x in (i..girls-1)
		if girls_skills[i].to_i > girls_skills[x].to_i && i != x
			temp = girls_skills[i].to_i
			girls_skills[i] = girls_skills[x].to_i
			girls_skills[x] = temp
		end
	end
end
for i in (0..boys-1)
	for x in (i..boys-1)
		if boys_skills[i].to_i > boys_skills[x].to_i && i != x
			temp = boys_skills[i].to_i
			boys_skills[i] = boys_skills[x].to_i
			boys_skills[x] = temp
		end
	end
end
if boys <= girls
	for i in (0..boys-1)
		for x in (0..girls_skills.size-1)
			if boys_skills[i].to_i == girls_skills[x].to_i || boys_skills[i].to_i - 1 == girls_skills[x].to_i || boys_skills[i].to_i + 1 == girls_skills[x].to_i
				girls_skills.delete_at(x)
				count += 1
				break
			end
		end
	end
else
	for i in (0..girls-1)
		for x in (0..boys_skills.size-1)
			if girls_skills[i].to_i == boys_skills[x].to_i || girls_skills[i].to_i - 1 == boys_skills[x].to_i || girls_skills[i].to_i + 1 == boys_skills[x].to_i
				boys_skills.delete_at(x)
				count += 1
				break
			end
		end
	end
end
print count

#!/usr/bin/env ruby

n = $stdin.gets.to_i
boys = $stdin.gets.split.map { |b| b.to_i }
m = $stdin.gets.to_i
girls = $stdin.gets.split.map { |b| b.to_i }

raise "weird" unless boys.size == n
raise "weird" unless girls.size == m

boys.sort!
girls.sort!

i = 0
j = 0
res = 0
while i < n and j < m
  if (boys[i] - girls[j]).abs <= 1
    res += 1
    i += 1
    j += 1
  elsif boys[i] < girls[j]
    i += 1
  elsif boys[i] > girls[j]
    j += 1
  end
end

puts res

def solution(boys, boys_skill, girls, girls_skill)
  @boys = boys
  @girls = girls
  @boys_skill = boys_skill.sort!
  @girls_skill = girls_skill.sort!

  @couples = 0
  solve(0, 0)
  @couples
end

def solve(a_i, b_i)
  return nil if a_i == @boys || b_i == @girls
  if (@boys_skill[a_i] - @girls_skill[b_i]).abs <= 1
    @couples += 1
    solve(a_i + 1, b_i + 1)
  elsif @boys_skill[a_i] > @girls_skill[b_i]
    solve(a_i, b_i + 1)
  else
    solve(a_i + 1, b_i)
  end
end

boys = gets.to_i
boys_skill = gets.split.map(&:to_i)
girls = gets.to_i
girls_skill = gets.split.map(&:to_i)
puts solution(boys, boys_skill, girls, girls_skill)

def solution(boys, boys_skill, girls, girls_skill)
  boys_skill.sort!
  girls_skill.sort!
  i, j = 0, 0

  couples = 0
  while i < boys && j < girls do
    if (boys_skill[i] - girls_skill[j]).abs <= 1
      couples += 1
      i += 1
      j += 1
    else
      if boys_skill[i] > girls_skill[j]
        j += 1
      else
        i += 1
      end
    end
  end
  couples
end

boys = gets.to_i
boys_skill = gets.split.map(&:to_i)
girls = gets.to_i
girls_skill = gets.split.map(&:to_i)

puts solution(boys, boys_skill, girls, girls_skill)

n = gets.chomp.to_i
a = gets.split().map(&:to_i)
m = gets.chomp.to_i
b = gets.split().map(&:to_i)
a.sort!
b.sort!
s = 0
i = 0
j = 0
while i < n and j < m
	if a[i] < b[j]
		if b[j] - a[i] <= 1
			s+=1
			j+=1
		end
		i+=1
	else
		if a[i] - b[j] <= 1
			i+=1
			s+=1
		end
		j+=1
	end
end
puts s

n = gets.to_i
ns = gets.chomp.split.map(&:to_i).sort
m = gets.to_i
ms = gets.chomp.split.map(&:to_i).sort
ans = 0
i = 0
j = 0
while i < n && j < m
  if ns[i] == ms[j] || ns[i] + 1 == ms[j] || ns[i] - 1 == ms[j]
    i += 1
    j += 1
    ans += 1
  elsif ns[i] > ms[j] + 1
    j += 1
  elsif ns[i] + 1 < ms[j]
    i += 1
  end
end
p ans

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

gets
b = gets.split(' ').map(&:to_i).sort

result = 0
while !a.empty? && !b.empty?
  if (a.first - b.first).abs < 2
    result += 1
    a.shift
    b.shift
  else
    a.first < b.first ? a.shift : b.shift
  end
end

puts result

#File.open("4.txt","r") do |file|
	a=Array.new
	b=Array.new
	c=Array.new
	d=Array.new
	n=gets.to_i
	str=gets.to_s
	c=str.split
	i=0
	while i<n
		a[i]=c[i].to_i
		i+=1
	end
	m=gets.to_i
	str=gets.to_s
	d=str.split
	i=0
	while i<m
		b[i]=d[i].to_i
		i+=1
	end
	a.sort!
	b.sort!
	# print a
	# puts
	# print b
	# puts
	i=j=s=0
	while i<n and j<m
		if (a[i]-b[j]).abs<=1
			i+=1
			j+=1
			s+=1
		elsif a[i]>b[j]
			j+=1
		else
			i+=1
		end
	end
	puts s
#end

$dp = Array.new(101)
(0..101).each do |i|
  $dp[i]=Array.new(101,-1)
end
$n= gets.to_i
$a= gets.split(' ').map(&:to_i).sort
$m= gets.to_i
$b= gets.split(' ').map(&:to_i).sort
def calc(i,j)
  ret = 0
  if i == $n
    ret
  elsif j==$m
    ret
  elsif $dp[i][j]!=-1
    $dp[i][j]
  else
    ret=calc(i+1,j)
    ret=[calc(i+1,j+1)+(($a[i]-$b[j]).abs<2?1:0),ret].max
    ret=[calc(i,j+1),ret].max
    $dp[i][j]=ret
    ret
  end
end

puts calc(0,0)

# cook your code here
b=gets.to_i
skb = gets.split(/ /).map! { |e| e=e.to_i }
g=gets.to_i
skg = gets.split(/ /).map! { |e| e=e.to_i }
skg=skg.sort
skb=skb.sort
i=0
j=0
pe=0

while j < g and i < b
    if (skb[i]-skg[j]).abs<=1
        pe=pe+1
        i=i+1
        j=j+1
    elsif skb[i]>skg[j]
        j=j+1
    elsif skb[i]<skg[j]
        i=i+1
    end
end
puts pe

n = gets.to_i
a = gets.split.map { |x| x.to_i }
n = gets.to_i
b = gets.split.map { |x| x.to_i }

a.sort!
b.sort!

x = nil
y = nil
count = 0

while (!a.empty? or !x.nil?) and (!b.empty? || !y.nil?)
  x = a.shift if x.nil?
  y = b.shift if y.nil?
  if x < y - 1
    x = nil
  elsif y < x - 1
    y = nil
  else
    x = nil
    y = nil
    count = count + 1
  end
end

puts count

n = gets.to_i

a = gets.split.map { |x| x.to_i }

n = gets.to_i

b = gets.split.map { |x| x.to_i }

a.sort!
b.sort!

x = nil
y = nil
count = 0

while !a.empty? and !b.empty?
	x = a.shift if x.nil?
	y = b.shift if y.nil?
	if x < y - 1
		x = nil
	elsif y < x - 1
		y = nil
	else
		x = nil
		y = nil
		count = count + 1
	end
end

puts count

gets
a = gets.split.map { |x| x.to_i }.sort
gets
b = gets.chomp

a.each do |x|
  b.sub!(/\b(#{x}|#{x+1}|#{x-1})\b/, "200")
end
puts b.scan(/200/).length

gets
a = gets.split.map { |x| x.to_i }.sort
n = gets.to_i
b = gets.split.map { |x| x.to_i }.sort
index = 0
ans = 0

a.each do |x|
  break if (index >= n)

  if ((x - b[index]).abs <= 1)
      index += 1
      ans += 1
  end
end

puts ans

gets
a = gets.split.map { |x| x.to_i }.sort
gets
b = gets.split.map { |x| x.to_i }.sort
ans = 0

a.each do |x|
  b.each do |y|
    if ((x - y).abs <= 1)
      ans += 1
      b.shift
      break
    elsif ( x > y + 1)
      b.shift
    end
  end
end

puts ans

gets
a = gets.split.map { |x| x.to_i }.sort
gets
b = gets.chomp

a.each do |x|
  b.sub!(/\b(#{x-1}|#{x}|#{x+1})\b/, "200")
end
puts b.scan(/200/).length

n = gets.to_i
a = gets.split.map { |x| x.to_i }.sort
m = gets.to_i
b = gets.split.map { |x| x.to_i }.sort

i, j = 0, 0
cnt = 0
while i < n and j < m
  if (a[i] - b[j]).abs <= 1
    i += 1
    j += 1
    cnt += 1
  elsif a[i] + 1 < a[j]
    i += 1
  else
    j += 1
  end
end

puts cnt

#$stdin = File.open "input.txt"

n = gets.to_i
a = gets.split.sort.map &:to_i

m = gets.to_i
b = gets.split.sort.map &:to_i

i, j, pairs = 0, 0, 0

while (i < n) && (j < m)
	if (a[i] - b[j]).abs <= 1
		pairs += 1
		i += 1
		j += 1
	else
		if a[i] < b[j]; i += 1 else j += 1 end
	end
end

p pairs

n = Integer(gets)
nums = gets.chomp.split
boy = Array.new
for i in 0...n
    boy[i] = Integer(nums[i])
end
m = Integer(gets)
nums2 = gets.chomp.split
girl = Array.new
for i in 0...m
    girl[i] = Integer(nums2[i])
end

boy.sort!
girl.sort!
def pairs(x,y)
    count = 0
    for i in 0...x.length
        for j in 0...y.length
            if (x[i] - y[j]).abs <= 1
                print (x[i] - y[j]).abs
                count += 1
                y.delete_at(j)
                break
            end
        end
    end
    return count
end

if  n >= m
    puts pairs(girl, boy)
else
    puts pairs(boy, girl)
end

boys = gets.chomp.to_i
boys_skills = gets.chomp
boys_skills = boys_skills.split
girls = gets.chomp.to_i
girls_skills = gets.chomp
girls_skills = girls_skills.split

count = 0
for i in (0..girls-1)
	for x in (i..girls-1)
		if girls_skills[i].to_i > girls_skills[x].to_i && i += x
			temp = girls_skills[i].to_i
			girls_skills[i] = girls_skills[x].to_i
			girls_skills[x] = temp
		end
	end
end
for i in (0..boys-1)
	for x in (i..boys-1)
		if boys_skills[i].to_i > boys_skills[x].to_i && i != x
			temp = boys_skills[i].to_i
			boys_skills[i] = boys_skills[x].to_i
			boys_skills[x] = temp
		end
	end
end
if boys <= girls
	for i in (0..boys-1)
		for x in (0..girls_skills.size-1)
			if boys_skills[i].to_i == girls_skills[x].to_i || boys_skills[i].to_i - 1 == girls_skills[x].to_i || boys_skills[i].to_i + 1 == girls_skills[x].to_i
				girls_skills.delete_at(x)
				count += 1
				break
			end
		end
	end
else
	for i in (0..girls-1)
		for x in (0..boys_skills.size-1)
			if girls_skills[i].to_i == boys_skills[x].to_i || girls_skills[i].to_i - 1 == boys_skills[x].to_i || girls_skills[i].to_i + 1 == boys_skills[x].to_i
				boys_skills.delete_at(x)
				count += 1
				break
			end
		end
	end
end
print count

boys = gets.chomp.to_i
boys_skills = gets.chomp
boys_skills = boys_skills.split
girls = gets.chomp.to_i
girls_skills = gets.chomp
girls_skills = girls_skills.split

count = 0
if boys <= girls
	for i in (0..boys-1)
		for x in (0..girls_skills.size-1)
			if boys_skills[i].to_i == girls_skills[x].to_i || boys_skills[i].to_i - 1 == girls_skills[x].to_i || boys_skills[i].to_i + 1 == girls_skills[x].to_i
				girls_skills.delete_at(x)
				count += 1
				break
			end
		end
	end
else
	for i in (0..girls-1)
		for x in (0..boys_skills.size-1)
			if girls_skills[i].to_i == boys_skills[x].to_i || girls_skills[i].to_i - 1 == boys_skills[x].to_i || girls_skills[i].to_i + 1 == boys_skills[x].to_i
				boys_skills.delete_at(x)
				count += 1
				break
			end
		end
	end
end
print count
# for i in (0..girls-1)
# 	for x in (1..girls-1)
# 		if girls_skills[i].to_i > girls_skills[x]
# 			temp = girls_skills[i].to_i
# 			girls_skills[i] = girls_skills[x].to_i
# 			girls_skills[x] = temp
# 		end
# 	end
# end

boys = gets.chomp.to_i
boys_skills = gets.chomp
boys_skills = boys_skills.split
girls = gets.chomp.to_i
girls_skills = gets.chomp
girls_skills = girls_skills.split

count = 0
for i in (0..girls-2)
	for x in (1..girls-1)
		if girls_skills[i].to_i > girls_skills[x].to_i
			temp = girls_skills[i].to_i
			girls_skills[i] = girls_skills[x].to_i
			girls_skills[x] = temp
		end
	end
end
for i in (0..boys-2)
	for x in (1..boys-1)
		if boys_skills[i].to_i > boys_skills[x].to_i
			temp = boys_skills[i].to_i
			boys_skills[i] = boys_skills[x].to_i
			boys_skills[x] = temp
		end
	end
end
if boys <= girls
	for i in (0..boys-1)
		for x in (0..girls_skills.size-1)
			if boys_skills[i].to_i == girls_skills[x].to_i || boys_skills[i].to_i - 1 == girls_skills[x].to_i || boys_skills[i].to_i + 1 == girls_skills[x].to_i
				girls_skills.delete_at(x)
				count += 1
				break
			end
		end
	end
else
	for i in (0..girls-1)
		for x in (0..boys_skills.size-1)
			if girls_skills[i].to_i == boys_skills[x].to_i || girls_skills[i].to_i - 1 == boys_skills[x].to_i || girls_skills[i].to_i + 1 == boys_skills[x].to_i
				boys_skills.delete_at(x)
				count += 1
				break
			end
		end
	end
end
print count

boys = gets.chomp.to_i
boys_skills = gets.chomp
boys_skills = boys_skills.split
girls = gets.chomp.to_i
girls_skills = gets.chomp
girls_skills = girls_skills.split

count = 0
for i in (0..girls-1)
	for x in (1..girls-1)
		if girls_skills[i].to_i > girls_skills[x].to_i
			temp = girls_skills[i].to_i
			girls_skills[i] = girls_skills[x].to_i
			girls_skills[x] = temp
		end
	end
end
for i in (0..boys-1)
	for x in (1..boys-1)
		if boys_skills[i].to_i > boys_skills[x].to_i
			temp = boys_skills[i].to_i
			boys_skills[i] = boys_skills[x].to_i
			boys_skills[x] = temp
		end
	end
end
if boys <= girls
	for i in (0..boys-1)
		for x in (0..girls_skills.size-1)
			if boys_skills[i].to_i == girls_skills[x].to_i || boys_skills[i].to_i - 1 == girls_skills[x].to_i || boys_skills[i].to_i + 1 == girls_skills[x].to_i
				girls_skills.delete_at(x)
				count += 1
				break
			end
		end
	end
else
	for i in (0..girls-1)
		for x in (0..boys_skills.size-1)
			if girls_skills[i].to_i == boys_skills[x].to_i || girls_skills[i].to_i - 1 == boys_skills[x].to_i || girls_skills[i].to_i + 1 == boys_skills[x].to_i
				boys_skills.delete_at(x)
				count += 1
				break
			end
		end
	end
end
print count

boys = gets.chomp.to_i
boys_skills = gets.chomp
boys_skills = boys_skills.split
girls = gets.chomp.to_i
girls_skills = gets.chomp
girls_skills = girls_skills.split

count = 0
for i in (0..girls-1)
	for x in (i..girls-1)
		if girls_skills[i].to_i > girls_skills[x].to_i && i != x
			temp = girls_skills[i].to_i
			girls_skills[i] = girls_skills[x].to_i
			girls_skills[x] = temp
		end
	end
end
for i in (0..boys-1)
	for x in (i..boys-1)
		if boys_skills[i].to_i > boys_skills[x].to_i && i != x
			temp = boys_skills[i].to_i
			boys_skills[i] = boys_skills[x].to_i
			boys_skills[x] = temp
		end
	end
end
print boys_skills
print girls_skills
if boys <= girls
	for i in (0..boys-1)
		for x in (0..girls_skills.size-1)
			if boys_skills[i].to_i == girls_skills[x].to_i || boys_skills[i].to_i - 1 == girls_skills[x].to_i || boys_skills[i].to_i + 1 == girls_skills[x].to_i
				girls_skills.delete_at(x)
				count += 1
				break
			end
		end
	end
else
	for i in (0..girls-1)
		for x in (0..boys_skills.size-1)
			if girls_skills[i].to_i == boys_skills[x].to_i || girls_skills[i].to_i - 1 == boys_skills[x].to_i || girls_skills[i].to_i + 1 == boys_skills[x].to_i
				boys_skills.delete_at(x)
				count += 1
				break
			end
		end
	end
end
print count

$dp = Array.new(101)
(0..101).each do |i|
  $dp[i]=Array.new(101,-1)
end
$n= gets.to_i
$a= gets.split(' ').map(&:to_i).sort
$m= gets.to_i
$b= gets.split(' ').map(&:to_i).sort
def calc(i,j)
  ret = 0
  if i == $n
    ret
  elsif j==$m
    ret
  elsif $dp[i][j]!=-1
    $dp[i][j]
  else
    ret=calc(i+1,j)
    ret=[calc(i+1,j+1)+(($a[i]-$b[j]).abs<2?1:0),ret].max
    ret=[calc(i+1,j),ret].max
    $dp[i][j]=ret
    ret
  end
end

puts calc(0,0)


E=1e-10
def rectangle?(a,b,c,d)
	return [a,b,c,d] if rect?(a,b,c,d)
	return [a,c,b,d] if rect?(a,c,b,d)
	return [b,a,c,d] if rect?(b,a,c,d)
	nil
end

def rect?(a,b,c,d)
	m_ac=mid_pts(a,c)
	return nil if same_pos?(a,m_ac)
	m_bd=mid_pts(b,d)
	return nil if same_pos?(b,m_bd)
	return nil unless same_pos?(m_ac,m_bd)
	return nil unless rect_angle?(a,b,c)
	return nil unless rect_angle?(b,c,d)
	true
end

def mid_pts(a,b)
	[(a[0]+b[0])/2,(a[1]+b[1])/2]
end

def dist(a,b)
	(a[0]-b[0])**2+(a[1]-b[1])**2
end

def rect_angle?(a,b,c)
	p,q=b[0]-a[0],b[1]-a[1]
	r,s=b[0]-c[0],b[1]-c[1]
	same_val?(p*r+q*s,0.0)
end

def same_val?(x,y)
	(x-y).abs<E
end

def same_pos?(a,b)
	same_val?(a[0],b[0])&&same_val?(a[1],b[1])
end

def square?(a,b,c,d)
	r=rectangle?(a,b,c,d)
	return nil unless r
	a,b,c,d=r
	same_val?(dist(a,b),dist(b,c))
end

pts=8.times.map{gets.split.map(&:to_f)}
pts.combination(4).each{|x|
	if square?(*x)
		y=pts-x
		if rectangle?(*y)
			puts "YES"
			puts [x,y].map{|vs|vs.map{|v|pts.index(v)+1}*" "}
			exit
		end
	end
}
puts "NO"

points=[]
8.times{|i|
        points.push(gets.split.map(&:to_i).push(i+1))
}
points.permutation.each(){|i|
        dx=i[1][0]-i[0][0]
        dy=i[1][1]-i[0][1]
        if i[2][0]-i[1][0]!=dy then next end
        if i[3][0]-i[2][0]!=-dx then next end
        if i[0][0]-i[3][0]!=-dy then next end
        if i[2][1]-i[1][1]!=-dx then next end
        if i[3][1]-i[2][1]!=-dy then next end
        if i[0][1]-i[3][1]!=dx then next end
        dx=i[5][0]-i[4][0]
        dy=i[5][1]-i[4][1]
        if i[7][0]-i[6][0]!=-dx then next end
        if i[7][1]-i[6][1]!=-dy then next end
        dx2=i[6][0]-i[5][0]
        dy2=i[6][1]-i[5][1]
        if i[4][0]-i[7][0]!=-dx2 then next end
        if i[4][1]-i[7][1]!=-dy2 then next end
        if dx*dx2+dy*dy2!=0 then next end

        puts "YES"
        4.times{|j|
                print "#{i[j][2]} "
        }
        puts
        4.times{|j|
                print "#{i[j+4][2]} "
        }
        puts
        exit

}
puts "NO"

points=[]
8.times{|i|
        points.push(gets.split.map(&:to_i).push(i+1))
}
points.permutation.each(){|i|
        dx=i[1][0]-i[0][0]
        dy=i[1][1]-i[0][1]
        if i[2][0]-i[1][0]!=dy then next end
        if i[3][0]-i[2][0]!=-dx then next end
        if i[0][0]-i[3][0]!=-dy then next end
        if i[2][1]-i[1][1]!=dx then next end
        if i[3][1]-i[2][1]!=-dy then next end
        if i[0][1]-i[3][1]!=-dx then next end
        dx=i[5][0]-i[4][0]
        dy=i[5][1]-i[4][1]
        if i[7][0]-i[6][0]!=-dx then next end
        if i[7][1]-i[6][1]!=-dy then next end
        dx2=i[6][0]-i[5][0]
        dy2=i[6][1]-i[5][1]
        if i[4][0]-i[7][0]!=-dx2 then next end
        if i[4][1]-i[7][1]!=-dy2 then next end
        if dx*dx2+dy*dy2!=0 then next end

        puts "YES"
        4.times{|j|
                print "#{i[j][2]} "
        }
        puts
        4.times{|j|
                print "#{i[j+4][2]} "
        }
        puts
        exit
}
puts "NO"