k=gets.split[1].to_i
p gets.split.count{|x| x.count('47')<=k}

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

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

a.select! do |i|
  i.to_s.scan(/[47]/).length <=k
end

puts a.length

n,k=gets.split.map(&:to_i)
a=gets.split.map(&:to_i)
a.select! {|i| i.to_s.scan(/[47]/).length <=k}
puts a.length

n, k = gets.split.map(&:to_i)
puts gets.split.count{|x| x.count('47') <= k}

n, k = gets.split.map(&:to_i)
a = gets.split.map(&:chars)
puts a.count{|x| x.count('4') + x.count('7') <= k}

a=gets.chomp.split(" ")
b=gets.chomp.split(" ")
ans=0
max=a[1].to_i
b.each do |i|
if i.count("4")+i.count("7")<=max
ans+=1
end
end
puts "#{ans}"

n, k = gets.split.map &:to_i
a = gets.split.map &:to_i
puts a.inject(0) { |s, x| x.to_s.split('').select { |d| d == '4' || d == '7'}.size <= k ? s + 1 : s }

n,k=gets.split.map(&:to_i)
p gets.split.map{|x| x.scan(/4|7/).size<=k ? 1 : 0}.reduce(:+)

n, k = gets.split.map(&:to_i)
p gets.split.map { |x|
  x.count('4') + x.count('7') <= k ? 1 : 0
}.reduce(:+)

def is_lucky?(n, k)
  while n > 0 do
    k-=1 if n%10 == 4 || n%10 == 7
    n/=10
  end
  k < 0 ? false : true
end

n, k = gets.split.map &:to_i
a = gets.split.map &:to_i
counter = 0
a.each {|el| counter += 1 if is_lucky?(el, k) }

puts counter

n, k = gets.chomp.split.map { |x| x.to_i }
a = gets.chomp.split
count = 0
for i in 0...n
  count += 1 if a[i].scan(/4|7/).count <= k
end
puts count

BEGIN{
	def get_line_int()
		return gets.split.map(&:to_i)
	end
	def count(x)
		cc = 0
		x.to_s.each_char do |c|
			if c == "4" or c == "7" then
				cc += 1
			end
		end
		return cc
	end
	def main()
		n, k = get_line_int
		a = get_line_int
		cc = 0
		a.each do |i|
			if count(i) <= k then
				cc += 1
			end
		end
		puts cc
	end
	Test_case = 1
	Test_case.times do
		main()
	end
}

a = gets.split(" ").collect{|x| x.to_i}
n = a[0]
k = a[1]

a = gets.split(" ").collect{|x| x.to_i}
result = 0

a.each{|x|
	c = 0
	while x > 0
		t = x % 10
		x /= 10
		if t == 4 || t == 7
			c += 1
		end
	end
	if c <= k
		result += 1
	end
}

puts result

n,k=gets.split.map{|s|s.to_i}
a=gets.split.map{|s|s.to_i}
r=0
n.times do |i|
  j=0
  while a[i] > 0 do
    j+=1 if [4,7].include?(a[i]%10)
    a[i] /= 10
  end
  r+=1 if j <= k
end
puts r

n, k = gets.split(' ').map(&:to_i)
puts gets.chomp.split(' ',n).map{|x| x.scan(/[47]/).count}.select{|x| x<=k}.count

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

st = gets.split
result = 0
n.times do |i|
    x = st[i].count("4")
    y = st[i].count("7")
    if x + y <= k then
        result += 1
    end
end

puts result

 n,k=gets.split.map(&:to_i)
 a=gets.split.map(&:to_s)
 ans=0
 a.each do |ch|
	g=0
	for i in 0...ch.size do
		g+=1 if  ch[i]=='4' or ch[i]=='7'
	end
	ans+=1 if g<=k
 end
 puts ans

k = gets.split[1].to_i
puts gets.split.count{|a| a.count('47') <= k}

# -*- encoding: utf-8 -*-

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

c = 0

digits.each do |a|
  c+=1 if a.count("4") + a.count("7") <= k
end

puts c

n, k = STDIN.readline.split.map {|s| s.to_i }
ss = STDIN.readline.split
count = 0
ss.each do |s|
	count += 1 if s.count('4') + s.count('7') <= k
end
puts count

n,k=gets.chomp.split(' ').map(&:to_i)
sum=n
#puts sum
a=gets.chomp.split(' ').map(&:to_s)
for i in a do
	count=0
	j=i.split('')
	j.each do |x|
		if x=='4' || x=='7'
			count+=1
		end
	end
	if count>k
		sum-=1
	end
end
puts sum

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

a.each do |x|
   counter = 0
   x.split(//).each do |t|
      counter+=1 if t == "4" || t == "7"
   end
   n-=1 if counter>k
end
puts n

n,k = gets.chomp.split(" ").collect! {|x| x.to_i}
line = gets.chomp.split(" ")
s = 0
line.each {|w|
    n = 0
    w.split("").each {|t|
       if t =="4" or t=="7"
        n+=1
       end
    }
    if n<=k
        s +=1
    end
}

puts s

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

a.each do |x|
   counter = 0
   x.split("").each do |t|
      counter+=1 if t == "4" || t == "7"
   end
   n-=1 if counter>k
end
puts n

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

a.each {|x|
   counter = 0
   x.split("").each {|t|
      counter+=1 if t == "4" || t == "7"
   }
   n-=1 if counter>k
}
puts n

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

a.each do |x|
   counter = 0
   x.split("").each do |t|
      counter+=1 if t == "4" || t == "7"
   end
   n-=1 if counter>k
end
puts n

def run
  lines = ARGF.readlines

  while lines.length > 0
    ret = 0

    n, k = lines.shift.chomp.split(" ").map {|x| x.to_i }
    vals = lines.shift.chomp.split(" ")

    vals.each do |val|
      cnt = 0
      val.split(//).each do |c|
        cnt += 1 if c == '4' || c == '7'
      end

      ret += 1 if cnt <= k
    end

    puts ret
  end
end

run if $0 == __FILE__

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

ans = 0
as.each do |a|
  if a.count('4') + a.count('7') <= k
    ans += 1
  end
end

puts ans

n, k = gets.chomp.split(/ /).map(&:to_i)
list = gets.chomp.split(/ /)
ans = 0
list.each do |num|
    lucky_digits = 0
    num.each_char do |d|
        lucky_digits += 1 if d == '4' || d == '7'
    end
    ans += 1 if lucky_digits <= k
end
puts ans

n,k=gets.split.map{|e| e.to_i}
x=gets.split
ans=0
x.each{|e|
	c1=e.chars.count{|e2|
			e2=="4" || e2=="7"
	}
	ans+=1 if c1<=k
}
puts ans

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

def nice( number, k )
  count = 0
  number.to_s.split(//).each{|c|
    count+=1 if c == "4" || c == "7"
  }
  count <= k
end

n, k = gets.split.map &:to_i
nums = gets.split.map &:to_i

ans = 0
nums.each{|v|
  ans+=1 if nice v, k
}

print ans

n,k = gets.split(" ").map(&:to_i)
arr = gets.split(" ")
count = 0
arr.each { |e|
	count += 1 if e.scan(/[47]/).length <= k
}
puts count

a=gets.split.map &:to_i;b=gets.split.map &:to_i;k=0;a[0].times{|x|b[x].to_s.count('4')+b[x].to_s.count('7')<=a[1] ?(k+=1):(0)};puts k

n,k=gets.split.map(&:to_i)
a=gets.split.select {|i| i.scan(/[47]/).length <=k}
puts a.length

n,k=gets.split.map(&:to_i)
a=gets.split.select {|i| i.to_s.scan(/[47]/).length <=k}
puts a.length

 n,k=gets.split.map(&:to_i)
 a=gets.split.map(&:to_s)
 ans=0
 a.each do |ch|
	g=0
	for i in 0...ch.size do
		g+=1 if  ch[i]==4 or ch[i]==7
	end
	ans+=1 if g<=k
 end
 puts ans

n, k = gets.chomp.split(/ /).map(&:to_i)
list = gets.chomp.split(/ /)
ans = 0
list.each do |num|
    ans += 1 if num.length <= k
end
puts ans


k = gets.strip.to_i
d = gets.strip.split.map(&:to_i)
ans = []
cnt = []
d.each do |i|
    if i == 0
        cnt[0] = 1
        next
    end
    if i == 100
        cnt[1] = 1
        next
    end
    if i % 10 == 0
        cnt[2] = i
        next
    end
    if i < 10
        cnt[3] = i
        next
    end
    cnt[4] = i
end
ans << 0 if !cnt[0].nil?
ans << 100 if !cnt[1].nil?
ans << cnt[2] if !cnt[2].nil?
ans << cnt[3] if !cnt[3].nil?
ans << cnt[4] if !cnt[4].nil? && cnt[3].nil? && cnt[2].nil?
puts ans.length
puts ans.sort.join(" ")

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

a.each do |i|
	if i==0
		c[0]=1
	elsif i==100
		c[1]=1
	elsif i%10==0
		c[2]=i
	elsif i<10
		c[3]=i
	else
		c[4]=i
	end
end
b<<0 if c[0]
b<<100 if c[1]
b<<c[2] if c[2]
b<<c[3] if c[3]
b<<c[4] if !c[2] && !c[3] && c[4]
puts b.length
b.each {|i| print "#{i} "}
puts

n = gets.to_i
arr = gets.split(" ").map(&:to_i)
zero = nil
one = nil
two = nil
three = nil

arr.each do |a|
	if !zero &&  a == 0
		zero = a
	elsif !one && a > 0 && a <= 9
		one = a
	elsif !two && a < 100 && (a % 10) == 0
		two = a
	elsif !three && a == 100
		three = a
	end
end
res = [zero,one,two,three].compact
if res.empty?
	res = [arr.first]
elsif !one && !two
	 val = arr.detect{|a| a.to_s.length == 2}
	 res << val if val
end

puts res.count
puts res.join(' ')

def get_bucket n
  s = 0
  if n%10 != 0
    s += 1
  end
  if (n/10)%10 != 0
    s = s + 2
  end
  if n==100
    s = 4
  end
  return s
end

k = gets.to_i
b = [0]*5
nn = [-1]*5
arr = gets.chomp.split(' ').collect {|x| x.to_i}
arr.each { |v|
   b[get_bucket(v)] = 1
   nn[get_bucket(v)] = v
}

m1 = b[0] + b[1] + b[2] + b[4]
m2 = b[3] + b[4] + b[0]

puts [m1,m2].max

if m1 > m2
  r = nn[0..2] + [nn[4]]
else
  r = nn[3..4] + [nn[0]]
end

puts r.keep_if {|x| x!=-1}.join " "

# 305A
# What a retarded task statement! Nothing can be understood...

gets
a = gets.chomp.split

r = []
q = a.find { |t| t == '0' }
r << q if q
w = a.find { |t| t == '100' }
r << w if w
z = a.find { |t| t.size == 1 && t != '0' }
r << z if z
x = a.find { |t| t.size == 2 && t[1] == '0' }
r << x if x
unless z || x
  y = a.find { |t| t.size == 2 }
  r << y if y
end

puts r.size
puts r * ' ' unless r.empty?

ans=[]
rest=[]
multiple10=false
one_digit=false
k=gets.to_i
d=gets.split.map(&:to_i)
d.each{|num|
  if num==0
  	ans<<num
  elsif num==100
  	ans<<num
  elsif !multiple10 && num%10==0
  	ans<<num
  	multiple10=true
  elsif !one_digit && num<10
  	ans<<num
  	one_digit=true
  else
  	rest<<num
  end
}
unless multiple10
  ans<< rest.first if !rest.empty? && !one_digit
end
puts ans.size
puts ans*" "

#!/usr/bin/ruby1.9

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

zeros, one, ten, double, hundred = [0, 0, 0, 0, 0]
nums.each do |num|
	if num == 0
		zeros += 1
	elsif num == 100
		hundred = 1
	elsif num%10 == 0
		ten = num
	elsif num < 10
		one = num
	else
		double = num
	end
end

result = zeros.times.collect { 0 }
if one+ten+double > 0
	if one > 0
		result.push(one)
		if ten > 0
			result.push(ten)
		end
	elsif ten > 0
		result.push(ten)
	else
		result.push(double)
	end
end
if hundred > 0
	result.push(100)
end

puts result.length
puts result.join(' ')

#!/usr/bin/ruby1.9

zeros = 10.times.collect { false }
n = STDIN.readline.to_i
nums = STDIN.readline.split.collect {|s| s.to_i }

result = [nums.shift]
nums.each do |num|
	a = num
	okay = true
	result.each do |b|
		while a != 0 and b != 0
			if a%10 != 0 and b%10 != 0
				break
			end
			a /= 10
			b /= 10
		end
		if a != 0 and b != 0
			okay = false
			break
		end
	end
	if okay
		result.push(num)
	end
end

puts result.length
puts result.join(' ')

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

a.each do |i|
	if i==0
		c[0]=1
	elsif i==100
		c[1]=1
	elsif i%10==0
		c[2]=i
	elsif i<10
		c[3]=i
	else
		c[4]=i
	end
end
b<<0 if c[0]
b<<100 if c[1]
b<<c[2] if c[2]
b<<c[3] if c[3]
b<<c[4] if !c[2] && !c[3] && !c[4]
puts b.length
b.each {|i| print "#{i} "}
puts

n = gets.to_i
arr = gets.split(" ")
res = arr.select{|a| a =~ /[0]/}
rem = arr - res
r = res.length-1
res << rem[0..r]
puts res.count
puts res.join(' ')

n = gets.to_i
arr = gets.split(" ").map(&:to_i)
zero = nil
one = nil
two = nil
three = nil

arr.each do |a|
	if !zero &&  a == 0
		zero = a
	elsif !one && a > 0 && a <= 9
		one = a
	elsif !two && a < 100 && (a % 10) == 0
		two = a
	elsif !three && a == 100
		three = a
	end
end
res = [zero,one,two,three].compact

puts res.count
puts res.join(' ')

n = gets.to_i
arr = gets.split(" ").map(&:to_i)
zero = nil
one = nil
two = nil
three = nil

arr.each do |a|
	if !zero &&  a == 0
		zero = a
	elsif !one && a > 0 && a <= 9
		one = a
	elsif !two && a < 100 && (a % 10) == 0
		two = a
	elsif !three && a == 100
		three = a
	end
end
res = [zero,one,two,three].compact
if res.empty?
	res = [arr.first]
end

puts res.count
puts res.join(' ')

# 305A

gets
a = gets.chomp.split
if a.size == 1
  puts 1
  puts a * ' '
  exit
end
r = []
z = a.find { |t| t.size == 1 && t != '0' }
r << z if z
n = a.find { |t| t == '0' }
r << n if n
u = a.find { |t| t =~ /^\d0$/ }
r << u if u
n = a.find { |t| t == '100' }
r << n if n
if n && z && !u
  u = a.find { |t| t.size == 2 }
  r << u if u
end

if r.empty?
  r << a[0]
end
puts r.size
puts r * ' ' unless r.empty?

# 305A

gets
a = gets.chomp.split
r = []
n = a.find { |t| t.size == 1 && t != '0' }
r << n if n
n = a.find { |t| t == '0' }
r << n if n
n = a.find { |t| t =~ /^\d0$/ }
r << n if n
n = a.find { |t| t == '100' }
r << n if n

puts r.size
puts r * ' ' unless r.empty?

# 305A

gets
a = gets.chomp.split
if a.size == 1
  puts 1
  puts a * ' '
  exit
end
r = []
n = a.find { |t| t.size == 1 && t != '0' }
r << n if n
n = a.find { |t| t == '0' }
r << n if n
u = a.find { |t| t =~ /^\d0$/ }
r << u if u
n = a.find { |t| t == '100' }
r << n if n
if n && !u
  u = a.find { |t| t.size == 2 }
  r << u if u
end

if r.empty?
  r << a[0]
end
puts r.size
puts r * ' ' unless r.empty?

# 305A

gets
a = gets.chomp.split
if a.size == 1
  puts 1
  puts a * ' '
end
r = []
n = a.find { |t| t.size == 1 && t != '0' }
r << n if n
n = a.find { |t| t == '0' }
r << n if n
n = a.find { |t| t =~ /^\d0$/ }
r << n if n
n = a.find { |t| t == '100' }
r << n if n

puts r.size
puts r * ' ' unless r.empty?

# 305A

gets
a = gets.chomp.split
if a.size == 1
  puts 1
  puts a * ' '
  exit
end
r = []
n = a.find { |t| t.size == 1 && t != '0' }
r << n if n
n = a.find { |t| t == '0' }
r << n if n
n = a.find { |t| t =~ /^\d0$/ }
r << n if n
n = a.find { |t| t == '100' }
r << n if n

if r.empty?
  r << a[0]
end
puts r.size
puts r * ' ' unless r.empty?

# 305A

gets
a = gets.chomp.split
if a.size == 1
  puts 1
  puts a * ' '
  exit
end
r = []
z = a.find { |t| t.size == 1 && t != '0' }
r << z if z
w = a.find { |t| t == '0' }
r << w if w
u = a.find { |t| t =~ /^\d0$/ }
r << u if u
n = a.find { |t| t == '100' }
r << n if n
if (n && w && !u) || r == ['0']
  u = a.find { |t| t.size == 2 }
  r << u if u
end

if r.empty?
  r << a[0]
end
puts r.size
puts r * ' ' unless r.empty?

# 305A

gets
a = gets.chomp.split
if a.size == 1
  puts 1
  puts a * ' '
  exit
end
r = []
z = a.find { |t| t.size == 1 && t != '0' }
r << z if z
w = a.find { |t| t == '0' }
r << w if w
u = a.find { |t| t =~ /^\d0$/ }
r << u if u
n = a.find { |t| t == '100' }
r << n if n
if n && w && !u
  u = a.find { |t| t.size == 2 }
  r << u if u
end

if r.empty?
  r << a[0]
end
puts r.size
puts r * ' ' unless r.empty?

# 305A

gets
a = gets.chomp.split
if a.size == 1
  puts 1
  puts a * ' '
  exit
end
r = []
n = a.find { |t| t.size == 1 && t != '0' }
r << n if n
n = a.find { |t| t == '0' }
r << n if n
n = a.find { |t| t =~ /^\d0$/ }
r << n if n
n = a.find { |t| t == '100' }
r << n if n

puts r.size
puts r * ' ' unless r.empty?

# 305A

gets
a, b = gets.chomp.split.partition { |token| token.include? '0' }
if a.empty?
  puts 0
else
  a << b[0] unless b.empty?
  puts a.size
  puts a * ' '
end

ans=[]
diff=[]
k=gets.to_i
d=gets.split.map(&:to_i)
d.each{|num|
  if num.to_s.count(?0)>0
    ans<<num
  else
    diff<<num
  end
}
unless ans.empty?
  ans<<diff.first unless diff.empty?
end
puts ans.size
puts ans*" "

ans=[]
diff=[]
k=gets.to_i
d=gets.split.map(&:to_i)
d.each{|num|
  if num.to_s.count(?0)>0
    ans<<num
  else
    diff<<num
  end
}
ans<<diff.first unless diff.empty?
puts ans.size
puts ans*" "


a=gets.chomp
b=gets.chomp.to_i
l=a.length
if l%b!=0
puts "NO"
else
tr=0
i=0
b=l/b
if b>1
loop do
if a[i..i+b-1]!=a[i..i+b-1].reverse
tr=1
break
else
i+=b
end
break if i==l
end
end

if tr==1
puts "NO"
else
puts "YES"
end
end

#!ruby

s = gets.chomp
k = gets.chomp.to_i

ul = s.length/k
if ul*k != s.length
  puts "NO"
  exit
end

0.upto(k-1) do |i|
  ss = s[ul*i..ul*(i+1)-1]
  if ss != ss.reverse
    puts "NO"
    exit
  end
end
puts "YES"
exit

#!/usr/bin/env ruby
s=gets.chomp
k=gets.to_i
puts s.size%k==0 && k.times.all?{|i|t=s[s.size/k*i,s.size/k];t==t.reverse} ? :YES : :NO

# http://codeforces.com/contest/548/problem/A
def palindrome?(a)
  a == a.reverse
end

def valid?(chars, k)
  return false if chars.length % k != 0

  messages = chars.each_slice(chars.length / k).to_a
  messages.all? { |m| palindrome?(m) }
end

chars = gets.chomp.chars
k = gets.chomp.to_i

puts valid?(chars, k) ? "YES" : "NO"

s = gets.chomp.chars
k = gets.to_i
if s.size % k == 0
  ans = s.each_slice(s.size / k).all?{|x| x == x.reverse}
else
  ans = false
end
puts ans ? 'YES' : 'NO'

def valid_fax(fax, num_pals)

  word_len = fax.size / num_pals

  ans = false
  if fax.size % num_pals == 0
    ans = fax.each_slice(word_len).all? { |wrd| wrd == wrd.reverse }
  end
  ans
end

words = gets().chomp.chars
len = gets().strip
if valid_fax(words,len.to_i) == true
  puts 'YES'
else
  puts 'NO'
end

str = gets.chomp;
n = gets.to_i;
ans = false;
ans = str.chars.each_slice(str.length / n).all?{|x| x == x.reverse} if (str.length % n == 0);
puts ans ? "YES\n":"NO\n";

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

# a.rb

def is_palindrome(s)
    s.size.times do |i|
        return false if s[i] != s[s.size - i - 1]
    end
    return true
end

def ok(s, k)
    return false if s.size % k != 0
    n = s.size / k
    k.times do |i|
        return false if !is_palindrome(s[n * i, n])
    end
    return true
end

def main()
    s = gets.chomp
    k = gets.to_i

    puts ok(s, k) ? "YES" : "NO"
end

if __FILE__ == $0 then
    main()
end

s = gets.chomp
k = gets.to_i
if s.size%k != 0
    puts "NO"
    exit
end
len = s.size/k
(0...s.size).step(len).each do |i|
    if s[i,len] != s[i,len].reverse
        puts "NO"
        exit
    end
end
puts "YES"

string = gets.chomp
k = gets.chomp.to_i
flag = true

def palindrome?(str)
	str == str.reverse
end

parts = []
nowStart = 0

until parts.length == k - 1
	parts << string.slice(nowStart, string.length / k)
	nowStart += string.length / k

	#puts nowStart
end

parts << string.slice(nowStart, string.length - nowStart)

=begin
parts.each do |partString|
	puts "partString : #{partString}"
end
=end

parts.each do |partString|
	flag = false if !palindrome?(partString)
	flag = false if partString.length != string.length / k
end

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

s = gets.chomp.chars
k = gets.to_i
a = []
valid = false
s.size.times do |i|
  a << s[i]
  if a == a.reverse
    start = a.size
    c = 1
    valid = true
    (k - 1).times do
      t = s[start...start + a.size]
      if start + a.size > s.size || t != t.reverse
        valid = false
        break
      end
      start += a.size
    end
    valid = false if a.size * k != s.size
    break if valid
  end
end
puts valid ? 'YES' : 'NO'

s=gets.chomp
n=gets.to_i

if s.size%n!=0 then
	puts "NO"
else
	m=s.size/n
	ans="YES"
	s.chars.to_a.each_slice(m).each{|e|
		if e!=e.reverse then
			ans="NO"
		end
	}
	puts ans
end

# http://codeforces.com/contest/548/problem/A
def palindrome?(a)
  a == a.reverse
end

chars = gets.chomp.chars
k = gets.chomp.to_i

messages = chars.each_slice(chars.length / k).to_a
puts messages.all? { |m| palindrome?(m) } ? "YES" : "NO"

str = gets.chomp;
n = gets.to_i;
ans = 0;
ans = str.chars.each_slice(str.length / n).all?{|x| x == x.reverse} if (str.length % n == 0);
puts ans ? "YES\n":"NO\n";

str = gets.chomp;
n = gets.to_i;
ans = 0;
ans = str.chars.each_slice(str.length / n).all?{|x| x == x.reverse} if (str.length % n == 0);
puts ans == 1 ? "YES\n":"NO\n";

str = gets.chomp;
n = gets.to_i;
if (str.length / n > 0)
  arr = str.chars.each_slice(str.length / n).map(&:join);
  puts arr.all?{|x| x.length == arr[0].length && x == x.reverse} ? "YES":"NO";
else
  puts "NO\n";
end

str = gets.chomp;
n = gets.to_i;
if (str.length / n > 0)
  arr = str.chars.each_slice(str.length / n).map(&:join);
  puts arr.all?{|x| x.length == arr[0].length && x = x.reverse} ? "YES":"NO";
else
  puts "NO\n";
end

string = gets.chomp
k = gets.chomp.to_i
flag = true

def palindrome?(str)
	str == str.reverse
end

parts = []
nowStart = 0

until parts.length == k - 1
	parts << string.slice(nowStart, string.length / k)
	nowStart += string.length / k

	#puts nowStart
end

parts << string.slice(nowStart, string.length - nowStart)

=begin
parts.each do |partString|
	puts "partString : #{partString}"
end
=end

parts.each do |partString|
	flag = false if !palindrome?(partString)
	flag = false if partString.length != k
end

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

string = gets.chomp
k = gets.chomp.to_i
flag = true

def palindrome?(str)
	str == str.reverse
end

parts = []
nowStart = 0

until parts.length == k
	parts << string.slice(nowStart, string.length / k)
	nowStart += string.length / k

	#puts nowStart
end

parts.each do |partString|
	flag = false if !palindrome?(partString)
end

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

string = gets.chomp
k = gets.chomp.to_i
flag = true

def palindrome?(str)
	str == str.reverse
end

parts = []
nowStart = 0

until parts.length == k
	parts << string.slice(nowStart, string.length / k)
	nowStart += string.length / k

	puts nowStart
end

parts.each do |partString|
	flag = false if !palindrome?(partString)
end

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

string = gets.chomp
k = gets.chomp.to_i
flag = true

def palindrome?(str)
	str == str.reverse
end

parts = []
nowStart = 0

until parts.length == k
	parts << string.slice(nowStart, string.length / k)
end

parts.each do |partString|
	flag = false if !palindrome? partString
end

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

string = gets.chomp
k = gets.chomp.to_i
flag = true

def palindrome?(str)
	str == str.reverse
end

parts = []
nowStart = 0

until parts.length == k
	parts << string.slice(nowStart, string.length / k)
	nowStart += string.length / k

	#puts nowStart
end

parts.each do |partString|
	flag = false if !palindrome? partString
end

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

a=gets.chomp
b=gets.chomp.to_i
l=a.length
if l%b!=0
puts "NO"
else
tr=0
i=0
if b>1
b=l/b
loop do
if a[i..i+b-1]!=a[i..i+b-1].reverse
tr=1
break
else
i+=b
end
break if i==l
end
end

if tr==1
puts "NO"
else
puts "YES"
end
end

def is_pal(word, word2)
  word == word2.reverse
end

def valid_fax(fax, word_len)

  #puts "fax size = #{fax.size-1}, word_len = #{word_len-1} mod #{(fax.size-1 % word_len-1)}"
  if ((fax.size-1) % (word_len-1)) != 0
    #puts "here"
    return false
  end

  i = 0
  puts fax.size
  while i < fax.size-1
    #puts "Testing #{fax[i,word_len]} and #{fax[i+word_len, word_len]}"
    unless is_pal(fax[i, word_len], fax[i+word_len, word_len])
      return false
    end
    i += word_len * 2
  end
  return true
end

words = gets()
len = gets()
if valid_fax(words,len.to_i + 1)
  puts 'YES'
else
  puts 'NO'
end

def is_pal(word)
  word == word.reverse
end

def valid_fax(fax, num_pals)

  #puts "Fax.size #{fax.size}, number of pals #{num_pals}"
  word_len = (fax.size) / num_pals
  #puts "pals are of length #{word_len}, size = #{fax.size}"

  #puts "#{word_len}"
  if word_len == 0
    return false
  end

  if (fax.size)%word_len != 0
    return false
  end

  fax.each_slice(word_len) do |wrd|
    return false unless is_pal(wrd)
  end
  return true
end

words = gets().strip.chars
len = gets().strip
if valid_fax(words,len.to_i)
  puts 'YES'
else
  puts 'NO'
end

def valid_fax(fax, num_pals)

  word_len = (fax.size) / num_pals

  #puts "#{word_len}"
  if word_len == 0
    return false
  end
  ans = false
  if fax.size % word_len == 0
    ans = fax.each_slice(word_len).all? do |wrd|
      wrd == wrd.reverse
    end
  end
  ans
end

words = gets().chomp.chars
len = gets().strip
if valid_fax(words,len.to_i) == true
  puts 'YES'
else
  puts 'NO'
end

def valid_fax(fax, num_pals)

  word_len = (fax.size) / num_pals

  #puts "#{word_len}"
  if word_len == 0
    return false
  end
  if fax.size % word_len != 0
    return false
  end

  return fax.each_slice(word_len).all? do |wrd|
    wrd == wrd.reverse
  end
end

words = gets().strip.chars
len = gets().strip
if valid_fax(words,len.to_i)
  puts 'YES'
else
  puts 'NO'
end

def valid_fax(fax, num_pals)

  word_len = (fax.size) / num_pals

  #puts "#{word_len}"
  if word_len == 0
    return false
  end
  if fax.size % word_len != 0
    return false
  end

  ! fax.each_slice(word_len).any? do |wrd|
    puts wrd
    wrd != wrd.reverse
  end
end

words = gets().strip.chars
len = gets().strip
if valid_fax(words,len.to_i)
  puts 'YES'
else
  puts 'NO'
end

def is_pal(word, word2)
  word == word2.reverse
end

def valid_fax(fax, word_len)

  #puts "fax size = #{fax.size-1}, word_len = #{word_len-1} mod #{(fax.size-1 % word_len-1)}"
  if ((fax.size-1) % (word_len-1)) != 0
    #puts "here"
    return false
  end

  i = 0
  #puts fax.size
  while i < fax.size-1
    #puts "Testing #{fax[i,word_len]} and #{fax[i+word_len, word_len]}"
    unless is_pal(fax[i, word_len], fax[i+word_len, word_len])
      return false
    end
    i += word_len * 2
  end
  return true
end

words = gets()
len = gets()
if valid_fax(words,len.to_i + 1)
  puts 'YES'
else
  puts 'NO'
end

def valid_fax(fax, num_pals)

  word_len = (fax.size) / num_pals

  #puts "#{word_len}"
  if word_len == 0
    return false
  end
  if fax.size % word_len != 0
    return false
  end

  return fax.each_slice(word_len).all? do |wrd|
    wrd == wrd.reverse
  end
end

words = gets().chomp.chars
len = gets().strip
if valid_fax(words,len.to_i)
  puts 'YES'
else
  puts 'NO'
end

def is_pal(word)
  word == word.reverse
end

def valid_fax(fax, num_pals)

  word_len = fax.size / num_pals
  #puts "pals are of length #{word_len}, size = #{fax.size-1}"
  if (fax.size-1)%word_len != 0
    return false
  end

  if word_len == 1
    return true
  end

  i = 0
  #puts fax.size
  while i < fax.size-1
    #puts "Testing #{fax[i,word_len]}"
    unless is_pal(fax[i, word_len])
      return false
    end
    i += word_len * 2
  end
  return true
end

words = gets()
len = gets()
if valid_fax(words,len.to_i)
  puts 'YES'
else
  puts 'NO'
end

def is_pal(word)
  word == word.reverse
end

def valid_fax(fax, num_pals)

  #puts "Fax.size #{fax.size}, number of pals #{num_pals}"
  word_len = (fax.size) / num_pals
  #puts "pals are of length #{word_len}, size = #{fax.size}"

  #puts "#{word_len}"
  if word_len == 0
    return false
  end

  if word_len == 1
    return true
  end
  if (fax.size)%word_len != 0
    return false
  end

  fax.each_slice(word_len) do |wrd|
    return false if !is_pal(wrd)
  end
  return true
end

words = gets().strip.chars
len = gets().strip
if valid_fax(words,len.to_i)
  puts 'YES'
else
  puts 'NO'
end

def is_pal(word, word2)
  word == word2.reverse
end

def valid_fax(fax, word_len)

  if fax%word_len != 0
    return false
  end

  i = 0
  puts fax.size
  while i < fax.size-1
    puts "Testing #{fax[i,word_len]} and #{fax[i+word_len, word_len]}"
    unless is_pal(fax[i, word_len], fax[i+word_len, word_len])
      return false
    end
    i += word_len * 2
  end
  return true
end

words = gets()
len = gets()
if valid_fax(words,len.to_i + 1)
  puts 'YES'
else
  puts 'NO'
end

def is_pal(word)
  word == word.reverse
end

def valid_fax(fax, num_pals)

  word_len = fax.size / num_pals

  if word_len == 1
    return true
  end

  #puts "pals are of length #{word_len}, size = #{fax.size-1}"
  if (fax.size-1)%word_len != 0
    return false
  end

  i = 0
  #puts fax.size
  while i < fax.size-1
    #puts "Testing #{fax[i,word_len]}"
    unless is_pal(fax[i, word_len])
      return false
    end
    i += word_len * 2
  end
  return true
end

words = gets()
len = gets()
if valid_fax(words,len.to_i)
  puts 'YES'
else
  puts 'NO'
end

def is_pal(word)
  word == word.reverse
end

def valid_fax(fax, num_pals)

  word_len = fax.size / num_pals
  #puts "pals are of length #{word_len}, size = #{fax.size-1}"
  if (fax.size-1)%word_len != 0
    return false
  end

  i = 0
  #puts fax.size
  while i < fax.size-1
    #puts "Testing #{fax[i,word_len]}"
    unless is_pal(fax[i, word_len])
      return false
    end
    i += word_len * 2
  end
  return true
end

words = gets()
len = gets()
if valid_fax(words,len.to_i)
  puts 'YES'
else
  puts 'NO'
end

def is_pal(word, word2)
  word == word2.reverse
end

def valid_fax(fax, word_len)

  puts "fax size = #{fax.size-1}, word_len = #{word_len-1} mod #{(fax.size-1 % word_len-1)}"
  if ((fax.size-1) % (word_len-1)) != 0
    puts "here"
    return false
  end

  i = 0
  puts fax.size
  while i < fax.size-1
    #puts "Testing #{fax[i,word_len]} and #{fax[i+word_len, word_len]}"
    unless is_pal(fax[i, word_len], fax[i+word_len, word_len])
      return false
    end
    i += word_len * 2
  end
  return true
end

words = gets()
len = gets()
if valid_fax(words,len.to_i + 1)
  puts 'YES'
else
  puts 'NO'
end

def is_pal(word)
  word == word.reverse
end

def valid_fax(fax, num_pals)

  #puts "Fax.size #{fax.size-1}, number of pals #{num_pals}"
  word_len = (fax.size) / num_pals
  #puts "pals are of length #{word_len}, size = #{fax.size-1}"

  #puts "#{word_len}"
  if word_len == 0
    return false
  end
  if word_len == 1
    return true
  end
  if (fax.size)%word_len != 0
    return false
  end

  fax.each_slice(word_len) do |wrd|
    return false unless is_pal(wrd)
  end
  return true
end

words = gets()
len = gets()
if valid_fax(words,len.to_i)
  puts 'YES'
else
  puts 'NO'
end

def valid_fax(fax, num_pals)

  word_len = (fax.size) / num_pals

  #puts "#{word_len}"
  if word_len == 0
    return false
  end
  if fax.size % word_len != 0
    return false
  end

  return fax.each_slice(word_len).all? do |wrd|
    wrd == wrd.reverse
  end
end

words = gets().chomp.chars
len = gets().strip
if valid_fax(words,len.to_i) == true
  puts 'YES'
else
  puts 'NO'
end

def is_pal(word)
  word == word.reverse
end

def valid_fax(fax, num_pals)

  word_len = fax.size / num_pals
  #puts "pals are of length #{word_len}"

  i = 0
  #puts fax.size
  while i < fax.size-1
    #puts "Testing #{fax[i,word_len]}"
    unless is_pal(fax[i, word_len])
      return false
    end
    i += word_len * 2
  end
  return true
end

words = gets()
len = gets()
if valid_fax(words,len.to_i)
  puts 'YES'
else
  puts 'NO'
end

def valid_fax(fax, num_pals)

  #puts "Fax.size #{fax.size}, number of pals #{num_pals}"
  word_len = (fax.size) / num_pals
  #puts "pals are of length #{word_len}, size = #{fax.size}"

  #puts "#{word_len}"
  if word_len == 0
    return false
  end

  if word_len == 1
    return true
  end
  if fax.size % word_len != 0
    return false
  end

  ! fax.each_slice(word_len).any? do |wrd|
    wrd != wrd.reverse
  end
end

words = gets().strip.chars
len = gets().strip
if valid_fax(words,len.to_i)
  puts 'YES'
else
  puts 'NO'
end

def is_pal(word)
  word == word.reverse
end

def valid_fax(fax, num_pals)

  #puts "Fax.size #{fax.size-1}, number of pals #{num_pals}"
  word_len = (fax.size-1) / num_pals
  #puts "pals are of length #{word_len}, size = #{fax.size-1}"

  #puts "#{word_len}"
  if word_len == 0
    return false
  end
  if word_len == 1
    return true
  end
  if (fax.size-1)%word_len != 0
    return false
  end

  i = 0
  #puts fax.size
  while i < fax.size-1
    #puts "Testing #{fax[i,word_len]}"
    unless is_pal(fax[i, word_len])
      return false
    end
    i += word_len * 2
  end
  return true
end

words = gets()
len = gets()
if valid_fax(words,len.to_i)
  puts 'YES'
else
  puts 'NO'
end

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

# a.rb

def is_palindrome(s)
    return false if s.size == 1
    s.size.times do |i|
        return false if s[i] != s[s.size - i - 1]
    end
    return true
end

def ok(s, k)
    return false if s.size % k != 0
    n = s.size / k
    k.times do |i|
        return false if !is_palindrome(s[n * i, n])
    end
    return true
end

def main()
    s = gets.chomp
    k = gets.to_i

    puts ok(s, k) ? "YES" : "NO"
end

if __FILE__ == $0 then
    main()
end

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

# a.rb

def is_palindrome(s)
    return false if s.size == 1
    s.size.times do |i|
        return false if s[i] != s[s.size - i - 1]
    end
    return true
end

def ok(s, k)
    if s == "" && k == 0 then
        return true
    end
    if (s != "" && k == 0) || (s == "" && k > 0) then
        return false
    end

    ret = false
    2.upto(s.size) do |i|
        ss = s[0, i]
        if is_palindrome(ss) then
            ret = ret | ok(s[i, s.size], k - 1)
        end
    end
    return ret
end

def main()
    s = gets.chomp
    k = gets.to_i

    puts ok(s, k) ? "YES" : "NO"
end

if __FILE__ == $0 then
    main()
end

s = gets.chomp.chars
n = gets.to_i
c = 0
a = []
i = 0
while i < s.size
  if a != [] && s[i...i + a.size] == a.reverse
    c += 1
    i += a.size
    a = []
  else
    a << s[i]
    i += 1
  end
end
puts c == n ? 'YES' : 'NO'

s = gets.chomp.chars
k = gets.to_i
a = []
valid = false
s.size.times do |i|
  a << s[i]
  if a == a.reverse
    start = a.size
    c = 1
    valid = true
    (k - 1).times do
      t = s[start...start + a.size]
      if start + a.size >= s.size || t != t.reverse
        valid = false
        break
      end
      start += a.size
    end
    valid = false if a.size * k != s.size
    break if valid
  end
end
puts valid ? 'YES' : 'NO'

s = gets.chomp.chars
k = gets.to_i
a = []
valid = false
s.size.times do |i|
  a << s[i]
  if s[a.size...2 * a.size] == a.reverse
    start = 2 * a.size
    (k - 1).times do
      valid = true
      if s[start...start + a.size] != s[start + a.size...start + 2 * a.size].reverse
        valid = false
        break
      end
      start += 2 * a.size
    end
    break if valid
  end
end
puts valid ? 'YES' : 'NO'

s = gets.chomp.chars
k = gets.to_i
a = []
valid = false
s.size.times do |i|
  a << s[i]
  if a == s[a.size...2 * a.size].reverse
    start = 2 * a.size
    valid = true
    (k - 1).times do
      if start + 2 * a.size > s.size || s[start...start + a.size] != s[start + a.size...start + 2 * a.size].reverse
        valid = false
        break
      end
      start += 2 * a.size
    end
    break if valid
  end
end
puts valid ? 'YES' : 'NO'

s = gets.chomp.chars
k = gets.to_i
puts s.each_slice(s.size / k).to_a.all?{|x| x == x.reverse} ? 'YES' : 'NO'

#!ruby

s = gets.chomp
k = gets.chomp.to_i

ul = s.length/k
0.upto(k-1) do |i|
  ss = s[ul*i..ul*(i+1)-1]
  if ss != ss.reverse
    puts "NO"
    exit
  end
end
puts "YES"
exit


# https://codeforces.com/contest/1332/problem/B

primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]

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

 answer = []
 colors = {}
 color_count = 1

 numbers.each do |n|
  color = primes.find do |p|
   n % p == 0
  end

  if colors[color].nil?
   colors[color] = color_count
   color_count += 1
  end

  answer << colors[color]
 end

 puts colors.size
 puts answer.join(' ')
end

primes = [2,3,5,7,11,13,17,19,23,29,31]
t = gets.chomp.to_i

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

  colors = {}
  coloring = a.map do |aa|
              color = primes.find do |pr|
                aa % pr == 0
              end

              if colors.key?(color)
                colors[color]
              else
                colors[color] = colors.size + 1
              end
            end
  puts colors.size
  puts coloring.join(' ')
end

PRIME = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
t = gets.to_i
t.times do
  n = gets.to_i
  a = gets.split.map(&:to_i)
  mapping = {}
  used = 0
  c = Array.new(n, nil)
  a.each_with_index do |v, i|
    PRIME.each_with_index do |p, j|
      if v % p == 0
        if !mapping.include?(p)
          used += 1
          mapping[p] = used
        end
        c[i] = mapping[p]
        break
      end
    end
  end
  puts used
  puts c.join(" ")
end

# https://codeforces.com/contest/1332/problem/B

require 'set'

@primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]

def lowest_divisor(n)
 @primes.each do |p|
  if n % p == 0
   return p
  end
 end
end

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

 answer = ""
 colors = {}
 color_count = 1

 numbers.each do |n|
  color = lowest_divisor(n)
  if colors[color].nil?
   colors[color] = color_count
   color_count += 1
  end

  answer += "#{colors[color]} "
 end

 answer[-1] = ""

 puts colors.size
 puts answer
end

# https://codeforces.com/contest/1332/problem/B

require 'set'

@primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]

def lowest_divisor(n)
 @primes.each do |p|
  if n % p == 0
   return p
  end
 end
end

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

 answer = ""
 colors = Set.new()

 numbers.each do |n|
  color = lowest_divisor(n)
  colors << color
  answer += "#{@primes.index(color) + 1} "
 end

 answer[-1] = ""

 puts answer
end

# https://codeforces.com/contest/1332/problem/B

require 'set'

@primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]

def lowest_divisor(n)
 @primes.each do |p|
  if n % p == 0
   return p
  end
 end
end

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

 answer = ""
 colors = Set.new()

 numbers.each do |n|
  color = lowest_divisor(n)
  colors << color
  answer += "#{@primes.index(color) + 1} "
 end
end

# https://codeforces.com/contest/1332/problem/B

require 'set'

@primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]

def lowest_divisor(n)
 @primes.each do |p|
  if n % p == 0
   return p
  end
 end
end

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

 answer = ""
 colors = Set.new()

 numbers.each do |n|
  color = lowest_divisor(n)
  colors << color
  answer += "#{@primes.index(color) + 1} "
 end

 answer.rstrip!
end

# https://codeforces.com/contest/1332/problem/B

require 'set'

@primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]

def lowest_divisor(n)
 @primes.each do |p|
  if n % p == 0
   return p
  end
 end
end

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

 answer = ""
 colors = Set.new()

 numbers.each do |n|
  color = lowest_divisor(n)
  colors << color
  answer += "#{@primes.index(color) + 1} "
 end

 answer[-1] = ""

 puts colors.size
 puts answer
end


def solve(line)
  plus = 1
  minu = 0

  line.each_char do |ch|
    if ch == '+'
      plus += 1
    elsif ch == '-'
      minu += 1
    end
  end

  line =~ /([0-9]+)/
  n = Regexp.last_match[0].to_i

  if n > plus * n - minu || n < plus - minu * n
    puts "Impossible"
    return
  end

  curr = plus - minu

  signs = '+' + line.gsub(/[^+-]/, '')

  first = true

  puts "Possible"

  signs.each_char do |sign|
    print " #{sign} " if !first
    first = false
    if sign == '+'
      if curr >= n
        print 1
      else
        x = [n - curr + 1, n].min
        curr += x - 1
        print x
      end
    else
      if curr <= n
        print 1
      else
        x = [curr - n + 1, n].min
        curr -= x - 1
        print x
      end
    end
  end

  puts " = #{n}"
end

while line = gets
  solve(line.chomp)
end

str = ("+ " + gets).split
l = str.length
m = l/2 -1
n = str[l-1].to_i
a = Array.new(m){|e| e = 0}
s = 0
m.times{ |i|
	a[i] = str[i*2]=='+'?1: -1;
	s+=a[i]
}

i = 0

if (s<n)
	while(i<m && s!=n)
		if a[i]>0 && a[i]<n
			s+=1;a[i]+=1;
		else
			i+=1;
		end
	end
elsif s>n
	while(i<m && s!=n)
		if a[i]<0 && a[i]>-n
			s-=1;a[i]-=1;
		else
			i+=1;
		end
	end
end

if s!=n
	print "Impossible\n"
else
	print "Possible\n"
	str = ""
	for i in (0...m)
		str += "#{a[i]}" if i==0
		if i!=0
			if a[i]>0
				str += " + #{a[i]}"
			else
				str += " - #{-a[i]}"
			end
		end
	end
	str += " = #{n}"
	print str
end

def isok(arr, n, target)
  pos, neg = arr.count{|x| x == "+"}, arr.count{|x| x == '-'}
  max, min = pos * n - neg, pos - neg * n
  #print "##", max, " ", min, " ", target
  #puts ""
  if target <= max && target >= min
    return 0
  elsif target > max
    return -1
  else
    return 1
  end
end

arr = readline.gsub(/[?=]/, "").split(' ')
n = arr.last.to_i
arr = ["+"] + arr[0..-2]

if isok(arr, n, n) == 0
  puts "Possible"
  target = n
  0.upto(arr.length - 1) do |ind|
    ans = 0
    flag = arr[ind] == "+" ? 1 : -1
    if isok(arr[ind + 1..-1], n, target - flag) == 0
      ans = 1
    elsif isok(arr[ind + 1..-1], n, target - n * flag) == 0
      ans = n
    else
      down, up = 1, n
      downf = isok(arr[ind + 1..-1], n, target - flag)
      upf = isok(arr[ind + 1..-1], n, target - n * flag)
      while down + 1 < up
        mid = (down + up) / 2
        res = isok(arr[ind + 1..-1], n, target - mid * flag)
        if res == 0
          ans = mid
          break
        elsif res == downf
          down = mid
        else
          up = mid
        end
      end
    end
    if ind != 0
      print " " + arr[ind] + " "
    end
    print ans
    target -= ans * flag
  end
  print " = "
  puts n
else
  puts "Impossible"
end

arr=gets.split('?')
arr[0]='+'
sz=arr.size
n=arr[sz-1]
n=n[3,n.size-3].to_i
a=Array.new(111)
s=-n
for i in 0..sz-2
	if arr[i].strip=='+'
		a[i]=n
		s+=n
	else
		a[i]=1
		s-=1
	end
end
for i in 0..sz-2
	if s>0 && arr[i].strip=='+'
		det = [n-1, s].min
		a[i]-=det
		s-=det
	end
	if s>0 && arr[i].strip=='-'
		det = [n-1, s].min
		a[i]+=det
		s-=det
	end
end
if s!=0
	puts "Impossible"
else
	puts "Possible"
	arr[0]=""
	for i in 0..sz-2
		print "#{arr[i]}#{a[i]}"
	end
	puts arr[sz-1]
end

def isok(arr, n, target)
  pos, neg = arr.count{|x| x == "+"}, arr.count{|x| x == '-'}
  max, min = pos * n - neg, pos - neg * n
  #print "##", max, " ", min, " ", target
  #puts ""
  if target <= max && target >= min
    return 0
  elsif target > max
    return -1
  else
    return 1
  end
end

arr = readline.gsub(/[?=]/, "").split(' ')
n = arr.last.to_i
arr = ["+"] + arr[0..-2]

if isok(arr, n, n) == 0
  puts "Possible"
  target = n
  0.upto(arr.length - 1) do |ind|
    ans = 0
    flag = arr[ind] == "+" ? 1 : -1
    if isok(arr[ind + 1..-1], n, target - flag) == 0
      ans = 1
    elsif isok(arr[ind + 1..-1], n, target - n * flag) == 0
      ans = n
    else
      down, up = 1, n
      downf = isok(arr[ind + 1..-1], n, target - flag)
      upf = isok(arr[ind + 1..-1], n, target - n * flag)
      while down + 1 < up
        mid = (down + up) / 2
        res = isok(arr[ind + 1..-1], n, target - mid)
        if res == 0
          ans = mid
          break
        elsif res == downf
          down = mid
        else
          up = mid
        end
      end
    end
    if ind != 0
      print " " + arr[ind] + " "
    end
    print ans
    target -= ans * flag
  end
  print " = "
  puts n
else
  puts "Impossible"
end

def isok(arr, n, target)
  pos, neg = arr.count{|x| x == "+"}, arr.count{|x| x == '-'}
  max, min = pos * n - neg, pos - neg * n
  #print "##", max, " ", min, " ", target
  #puts ""
  if target <= max && target >= min
    return 0
  elsif target > max
    return -1
  else
    return 1
  end
end

arr = readline.gsub(/[?=]/, "").split(' ')
n = arr.last.to_i
arr = ["+"] + arr[0..-2]

if isok(arr, n, n) == 0
  target = n
  0.upto(arr.length - 1) do |ind|
    ans = 0
    flag = arr[ind] == "+" ? 1 : -1
    if isok(arr[ind + 1..-1], n, target - flag) == 0
      ans = 1
    elsif isok(arr[ind + 1..-1], n, target - n * flag) == 0
      ans = n
    else
      down, up = 1, n
      downf = isok(arr[ind + 1..-1], n, target - flag)
      upf = isok(arr[ind + 1..-1], n, target - n * flag)
      while down + 1 < up
        mid = (down + up) / 2
        res = isok(arr[ind + 1..-1], n, target - mid)
        if res == 0
          ans = mid
          break
        elsif res == downf
          down = mid
        else
          up = mid
        end
      end
    end
    if ind != 0
      print " " + arr[ind] + " "
    end
    print ans
    target -= ans * flag
  end
  print " = "
  puts n
else
  puts "Impossible"
end

arr=gets.split('?')
arr[0]='+'
sz=arr.size
n=arr[sz-1]
n=n[3,n.size-3].to_i
a=Array.new(111)
s=-n
for i in 0..sz-2
	if arr[i].strip=='+'
		a[i]=n
		s+=n
	else
		a[i]=1
		s-=1
	end
end
for i in 0..sz-2
	if s>0 && a[i]==n
		det = [n-1, s].min
		a[i]-=det
		s-=det
	end
end
if s!=0
	puts "Impossible"
else
	puts "Possible"
	arr[0]=""
	for i in 0..sz-2
		print "#{arr[i]}#{a[i]}"
	end
	puts arr[sz-1]
end


# frozen_string_literal: true

@data = $stdin.read.split

def next_token
  @data.shift
end

def next_int
  next_token.to_i
end

next_int.times do
  n = next_int
  x = next_int
  y = next_int

  maxp = [x + y - 1, n].min
  b = x + y + 1 - n
  # b -= 1 if y == n
  minp = [[b, n].min, 1].max
  # a = x + y - n + 1
  # b = x + y
  # a = [a, 1].max
  # b = [b, n].min
  # minp = b - a
  # minp += 1 if b < n
  # minp = n - minp
  puts "#{minp} #{maxp}"
end

def best(n, x, y)
  case x+y
  when (2..n) then 1
  when 2*n then n
  else x+y - n + 1
  end
end

def worst(n, x, y)
  x+y > n+1 ? n : x+y -1
end

1.upto(gets.chomp.to_i) do
  n,x,y = gets.chomp.split.map(&:to_i)

  puts [best(n,x,y), worst(n,x,y)].join(' ')
end

#! /usr/bin/env ruby

=begin
1 2 3 4 5 和
1 2 3 4 5 两两配对
希望对子的和大于我的对子的和

注意到 2+5  3+4  .. 5+2 都是7

可以贪心。枚举第一场比赛成绩，可得 要这个人输给我，第二场得多差

n太大，得优化一下
avail_y = [1, ... my_y-1], [my_y+1, ... n]
阶段1：x + y_too_small  ...
阶段2：x + y
=end

def solve_best(n, my_x, my_y)
  goal = my_x + my_y + 1
  nlose = 0

  x = goal - n; y = n
  if x < 1 then x = 1 end
  loop do
	  break if x > n || y < 1
	  if my_y == y
	    y -= 1
	    if x+y < goal then x += 1 end
	  end
	  if my_x == x then x += 1 end
	  break if x > n || y < 1

	  len = n
	  stop_at = (y > my_y ? my_y : 0)
	  if len > y - stop_at then len = y - stop_at end
	  stop_at = (x < my_x ? my_x : n+1)
	  if len > stop_at - x then len = stop_at - x end
	  nlose += len
	  x += len
	  y -= len
  end

  print (n - nlose), ' '
end

def solve_worst(n, my_x, my_y)
  goal = my_x + my_y
  nwin = 1 # myself

  x = 1; y = goal - 1
  if y > n then y = n end
  loop do
    break if x > n || y < 1
    if my_x == x
      x += 1
      if x+y > goal then y -= 1 end
    end
    if my_y == y then y -= 1 end
    break if x > n || y < 1

    len = n
    stop_at = (y > my_y ? my_y : 0)
    if len > y - stop_at then len = y - stop_at end
    stop_at = (x < my_x ? my_x : n+1)
    if len > stop_at - x then len = stop_at - x end
    nwin += len
    x += len
    y -= len
  end

  puts nwin
end

def solve
  n, myx, myy = gets.split.map{|x| x.to_i}
  solve_best(n, myx, myy)
  solve_worst(n, myx, myy)
end

t = gets.to_i
t.times { solve }

T = gets.to_i

def estimate_top(n, x, y)
  rank = 1

  above_a = x - 1
  below_a = [0, n - (x + 1)].max
  above_b = y - 1
  below_b = [0, n - (y + 1)].max

  d1 = [0, [above_a, below_b].min].max
  d2 = [0, [above_b, below_a].min].max

  above_a -= d1
  above_b -= d2

  rank += [0, [above_a, above_b].max].max

  rank
end

def estimate_bottom(n, x, y)
  rank = 1

  above_a = x - 1
  below_a = n - x
  above_b = y - 1
  below_b = n - y

  d1 = [0, [above_a, below_b].min].max
  d2 = [0, [above_b, below_a].min].max

  above_a -= d1
  above_b -= d2

  rank += d1 + d2 + [0, [above_a, above_b].max].max

  rank
end

T.times do
  n, x, y = gets.split.map(&:to_i)
  x, y = [x, y].sort

  top = estimate_top(n, x, y)
  bottom = estimate_bottom(n, x, y)

  puts "#{top} #{bottom}"
end

# frozen_string_literal: true

@data = $stdin.read.split

def next_token
  @data.shift
end

def next_int
  next_token.to_i
end

next_int.times do
  n = next_int
  x = next_int
  y = next_int

  a = x + y - n
  b = x + y - 1
  a = [a, 1].max
  b = [b, n].min
  maxp = (b - a + 1)
  b = [[x + y + 1 - n, n].min, 1].max
  minp = b
  # a = x + y - n + 1
  # b = x + y
  # a = [a, 1].max
  # b = [b, n].min
  # minp = b - a
  # minp += 1 if b < n
  # minp = n - minp
  puts "#{minp} #{maxp}"
end

# frozen_string_literal: true

@data = $stdin.read.split

def next_token
  @data.shift
end

def next_int
  next_token.to_i
end

next_int.times do
  n = next_int
  x = next_int
  y = next_int

  a = x + y - n
  b = x + y - 1
  a = [a, 1].max
  b = [b, n].min
  maxp = (b - a + 1)
  b = x + y + 1 - n
  b -= 1 if y == n
  minp = [[b, n].min, 1].max
  # a = x + y - n + 1
  # b = x + y
  # a = [a, 1].max
  # b = [b, n].min
  # minp = b - a
  # minp += 1 if b < n
  # minp = n - minp
  puts "#{minp} #{maxp}"
end

# frozen_string_literal: true

@data = $stdin.read.split

def next_token
  @data.shift
end

def next_int
  next_token.to_i
end

next_int.times do
  n = next_int
  x = next_int
  y = next_int

  maxp = [x + y - 1, n].min
  b = x + y + 1 - n
  b -= 1 if y == n
  minp = [[b, n].min, 1].max
  # a = x + y - n + 1
  # b = x + y
  # a = [a, 1].max
  # b = [b, n].min
  # minp = b - a
  # minp += 1 if b < n
  # minp = n - minp
  puts "#{minp} #{maxp}"
end

# frozen_string_literal: true

@data = $stdin.read.split

def next_token
  @data.shift
end

def next_int
  next_token.to_i
end

next_int.times do
  n = next_int
  x = next_int
  y = next_int

  a = x + y - n
  b = x + y - 1
  a = [a, 1].max
  b = [b, n].min
  maxp = (b - a + 1)
  a = x + y - n + 1
  b = x + y
  a = [a, 1].max
  b = [b, n].min
  minp = b - a
  minp += 1 if b < n
  puts "#{n - minp} #{maxp}"
end

T = gets.to_i

def estimate_top(n, x, y)
  rank = 1

  above_a = x - 1
  d = n - (y + 1)

  if d < above_a
    rank += above_a - d
  end

  rank
end

def estimate_bottom(n, x, y)
  rank = 1

  above_a = x - 1
  above_b = y - 1

  rank += above_a + above_b

  rank
end

T.times do
  n, x, y = gets.split.map(&:to_i)
  x, y = [x, y].sort

  top = estimate_top(n, x, y)
  bottom = estimate_bottom(n, x, y)

  puts "#{top} #{bottom}"
end

T = gets.to_i

def estimate_top(n, x, y)
  rank = 1

  above_a = x - 1
  d = [0, n - (y + 1)].max

  if d < above_a
    rank += above_a - d
  end

  rank
end

def estimate_bottom(n, x, y)
  rank = 1

  above_a = x - 1
  below_a = n - x
  above_b = y - 1
  below_b = n - y

  d1 = [0, [above_a, below_b].min].max
  d2 = [0, [above_b, below_a].min].max

  above_a -= d1
  above_b -= d2

  rank += d1 + d2 + [above_a, above_b].min

  rank
end

T.times do
  n, x, y = gets.split.map(&:to_i)
  x, y = [x, y].sort

  top = estimate_top(n, x, y)
  bottom = estimate_bottom(n, x, y)

  puts "#{top} #{bottom}"
end

T = gets.to_i

def estimate_top(n, x, y)
  rank = 1

  above_a = x - 1
  d = n - (y + 1)

  if d < above_a
    rank += above_a - d
  end

  rank
end

def estimate_bottom(n, x, y)
  rank = 1

  above_a = x - 1
  below_a = n - x
  above_b = y - 1
  below_b = n - y

  d1 = [0, [above_a, below_b].min].max
  d2 = [0, [above_b, below_a].min].max

  rank += d1 + d2

  rank
end

T.times do
  n, x, y = gets.split.map(&:to_i)
  x, y = [x, y].sort

  top = estimate_top(n, x, y)
  bottom = estimate_bottom(n, x, y)

  puts "#{top} #{bottom}"
end

T = gets.to_i

def estimate_top(n, x, y)
  rank = 1

  above_a = x - 1
  below_a = [0, n - (x + 1)].max
  above_b = y - 1
  below_b = [0, n - (y + 1)].max

  d1 = [0, [above_a, below_b].min].max
  d2 = [0, [above_b, below_a].min].max

  above_a -= d1
  above_b -= d2

  rank += [above_a, above_b].min

  rank
end

def estimate_bottom(n, x, y)
  rank = 1

  above_a = x - 1
  below_a = n - x
  above_b = y - 1
  below_b = n - y

  d1 = [0, [above_a, below_b].min].max
  d2 = [0, [above_b, below_a].min].max

  above_a -= d1
  above_b -= d2

  rank += d1 + d2 + [above_a, above_b].min

  rank
end

T.times do
  n, x, y = gets.split.map(&:to_i)
  x, y = [x, y].sort

  top = estimate_top(n, x, y)
  bottom = estimate_bottom(n, x, y)

  puts "#{top} #{bottom}"
end


s = gets.strip
mirrored = ["A", "b", "d", "H", "I", "M", "O", "o", "p", "q", "T", "U", "V", "v", "W", "w", "X", "x", "Y"]
mirror_of = ["A", "d", "b", "H", "I", "M", "O", "o", "q", "p", "T", "U", "V", "v", "W", "w", "X", "x", "Y"]
i = 0
j = s.length - 1
palindrom = true
while i <= j
    l = mirrored.index s[i]
    r = mirror_of.index( s[j] )
    palindrom = false if l.nil? || r.nil? || l != r
    i += 1
    j -= 1
end
if palindrom
    puts "TAK"
else
    puts "NIE"
end

word  = gets.to_s
char_array = word.chars.to_a
len = char_array.length-1
array_div = len/2
array_mod = len%2
char_valid = "AbdHIMOopqTUVvWwXxY".chars.to_a
#puts len
#puts array_div
#puts array_mod
ctr = 0
if (1 <= len) && (len <= 1000)
	if array_mod == 0
			for i in 0..array_div-1
				if char_valid.include?(char_array[i])
					if ((char_array[i] == 'q' && char_array[len-1-i] == 'p') || (char_array[i] == 'p' && char_array[len-1-i] == 'q'))
          ctr += 1
            #puts 'a'
            #puts  ctr
          elsif ((char_array[i] == 'd' && char_array[len-1-i] == 'b') || (char_array[i] == 'b' && char_array[len-1-i] == 'd'))
            ctr += 1
            #puts 'b'
            #puts ctr
          elsif (char_array[i] == char_array[len-1-i] && (char_array[i] != 'b' && char_array[i] != 'd' && char_array[i] != 'p' && char_array[i] != 'q'))
						ctr += 1
           # puts 'c'
            #puts ctr

					end
				end
      end
else
			for i in 0..array_div
				if char_valid.include?(char_array[i])
					if ((char_array[i] == 'q' && char_array[len-1-i] == 'p') || (char_array[i] == 'p' && char_array[len-1-i] == 'q'))
						ctr += 1
					#	puts 'a'
					#	puts ctr
          elsif ((char_array[i] == 'd' && char_array[len-1-i] == 'b') || (char_array[i] == 'b' && char_array[len-1-i] == 'd'))
						ctr += 1
					#	puts 'b'
					#	puts ctr
          elsif (char_array[i] == char_array[len-1-i] && i != len-1-i && (char_array[i] != 'b' && char_array[i] != 'd' && char_array[i] != 'p' && char_array[i] != 'q'))
						ctr += 1
					#	puts 'c'
					#	puts ctr
          elsif(i == len-1-i && (char_array[i] != 'b' && char_array[i] != 'd' && char_array[i] != 'p' && char_array[i] != 'q'))
						ctr += 1
					#	puts 'd'
					#	puts ctr
					end
				end
      end
  end
#puts ctr
  if array_mod == 0
    if ctr == array_div
			puts 'TAK'
    else
      puts 'NIE'
    end
  else
    if ctr == array_div+1
			puts 'TAK'
    else
      puts 'NIE'
    end
  end

end

s = gets.strip
puts s == s.tr('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ','#d#b##########oqp####vwx##A######HI###M#O####TUVWXY#').reverse ? "TAK" :"NIE"

s = gets.chomp
puts s == s.tr('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ','!d!b!!!!!!!!!!oqp!!!!vwx!!A!!!!!!HI!!!M!O!!!!TUVWXY!').reverse ? "TAK" :"NIE"

s=gets.chomp;puts s==s.tr('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ','#d#b##########oqp####vwx##A######HI###M#O####TUVWXY#').reverse ? :TAK : :NIE

s = gets.strip
mirrored = ["A", "b", "d", "H", "I", "i", "l", "M", "m", "n", "O", "o", "p", "T", "U", "u", "V", "v", "W", "w", "X", "x", "Y"]
mirror_of = ["A", "d", "b", "H", "I", "i", "l", "M", "m", "n", "O", "o", "q", "T", "U", "u", "V", "v", "W", "w", "X", "x", "Y"]
i = 0
j = s.length - 1
palindrom = true
while i <= j
    l = mirrored.index s[i]
    r = mirror_of.index( s[j] )
    palindrom = false if l.nil? || r.nil? || l != r
    i += 1
    j -= 1
end
if palindrom
    puts "TAK"
else
    puts "NIE"
end

s = gets.strip
mirrored = ["A", "b", "d", "H", "I", "M", "O", "o", "p", "T", "U", "V", "v", "W", "w", "X", "x", "Y"]
mirror_of = ["A", "d", "b", "H", "I", "M", "O", "o", "q", "T", "U", "V", "v", "W", "w", "X", "x", "Y"]
i = 0
j = s.length - 1
palindrom = true
while i < j
    l = mirrored.index s[i]
    r = mirror_of.index( s[j] )
    palindrom = false if l.nil? || r.nil? || l != r
    i += 1
    j -= 1
end
if palindrom
    puts "TAK"
else
    puts "NIE"
end

s = gets.strip
mirrored = ["A", "b", "d", "H", "I", "i", "M", "m", "n", "O", "o", "p", "T", "U", "u", "V", "v", "W", "w", "X", "x", "Y"]
mirror_of = ["A", "d", "b", "H", "I", "i", "M", "m", "n", "O", "o", "q", "T", "U", "u", "V", "v", "W", "w", "X", "x", "Y"]
i = 0
j = s.length - 1
palindrom = true
while i <= j
    l = mirrored.index s[i]
    r = mirror_of.index( s[j] )
    palindrom = false if l.nil? || r.nil? || l != r
    i += 1
    j -= 1
end
if palindrom
    puts "TAK"
else
    puts "NIE"
end

s = gets.strip
mirrored = ["A", "b", "d", "H", "I", "M", "O", "o", "p", "T", "U", "V", "v", "W", "w", "X", "x", "Y"]
mirror_of = ["A", "d", "b", "H", "I", "M", "O", "o", "q", "T", "U", "V", "v", "W", "w", "X", "x", "Y"]
i = 0
j = s.length - 1
palindrom = true
while i <= j
    l = mirrored.index s[i]
    r = mirror_of.index( s[j] )
    palindrom = false if l.nil? || r.nil? || l != r
    i += 1
    j -= 1
end
if palindrom
    puts "TAK"
else
    puts "NIE"
end

word  = gets.to_s
char_array = word.chars.to_a
len = char_array.length-1
array_div = len/2
array_mod = len%2
char_valid = "AbdHIMOopqTUVvWwXxYy".chars.to_a
#puts len
#puts array_div
#puts array_mod
ctr = 0
if (1 <= len) && (len <= 1000)
	if array_mod == 0
			for i in 0..array_div-1
				if char_valid.include?(char_array[i])
					if ((char_array[i] == 'q' && char_array[len-1-i] == 'p') || (char_array[i] == 'p' && char_array[len-1-i] == 'q'))
          ctr += 1
            #puts 'a'
            #puts  ctr
          elsif ((char_array[i] == 'd' && char_array[len-1-i] == 'b') || (char_array[i] == 'b' && char_array[len-1-i] == 'd'))
            ctr += 1
            #puts 'b'
            #puts ctr
          elsif (char_array[i] == char_array[len-1-i] && (char_array[i] != 'b' && char_array[i] != 'd' && char_array[i] != 'p' && char_array[i] != 'q'))
						ctr += 1
           # puts 'c'
            #puts ctr

					end
				end
      end
else
			for i in 0..array_div
				if char_valid.include?(char_array[i])
					if ((char_array[i] == 'q' && char_array[len-1-i] == 'p') || (char_array[i] == 'p' && char_array[len-1-i] == 'q'))
						ctr += 1
					#	puts 'a'
					#	puts ctr
          elsif ((char_array[i] == 'd' && char_array[len-1-i] == 'b') || (char_array[i] == 'b' && char_array[len-1-i] == 'd'))
						ctr += 1
					#	puts 'b'
					#	puts ctr
          elsif (char_array[i] == char_array[len-1-i] && i != len-1-i && (char_array[i] != 'b' && char_array[i] != 'd' && char_array[i] != 'p' && char_array[i] != 'q'))
						ctr += 1
					#	puts 'c'
					#	puts ctr
          elsif(i == len-1-i && (char_array[i] != 'b' && char_array[i] != 'd' && char_array[i] != 'p' && char_array[i] != 'q'))
						ctr += 1
					#	puts 'd'
					#	puts ctr
					end
				end
      end
  end
#puts ctr
  if array_mod == 0
    if ctr == array_div
			puts 'TAK'
    else
      puts 'NIE'
    end
  else
    if ctr == array_div+1
			puts 'TAK'
    else
      puts 'NIE'
    end
  end

end

word  = gets.to_s
char_array = word.chars.to_a
len = char_array.length-1
array_div = len/2
array_mod = len%2
char_valid = "AbdHIMOopqTUVvWwXxYy".chars.to_a
#puts len
#puts array_div
#puts array_mod
ctr = 0
if (1 <= len) && (len <= 1000)
	if array_mod == 0
			for i in 0..array_div-1
				if char_valid.include?(char_array[i])
					if ((char_array[i] == 'q' && char_array[len-1-i] == 'p') || (char_array[i] == 'p' && char_array[len-1-i] == 'q'))
          ctr += 1
            #puts 'a'
            #puts  ctr
          elsif ((char_array[i] == 'd' && char_array[len-1-i] == 'b') || (char_array[i] == 'b' && char_array[len-1-i] == 'd'))
            ctr += 1
            #puts 'b'
            #puts ctr
          elsif (char_array[i] == char_array[len-1-i] && (char_array[i] != 'b' && char_array[i] != 'd' && char_array[i] != 'p' && char_array[i] != 'q'))
						ctr += 1
           # puts 'c'
            #puts ctr

					end
				end
      end
else
			for i in 0..array_div
				if char_valid.include?(char_array[i])
					if ((char_array[i] == 'q' && char_array[len-1-i] == 'p') || (char_array[i] == 'p' && char_array[len-1-i] == 'q'))
						ctr += 1
					#	puts 'a'
					#	puts ctr
          elsif ((char_array[i] == 'd' && char_array[len-1-i] == 'b') || (char_array[i] == 'b' && char_array[len-1-i] == 'd'))
						ctr += 1
					#	puts 'b'
					#	puts ctr
          elsif (char_array[i] == char_array[len-1-i] && i != len-1-i && (char_array[i] != 'b' && char_array[i] != 'd' && char_array[i] != 'p' && char_array[i] != 'q'))
						ctr += 1
					#	puts 'c'
					#	puts ctr
          elsif(i == len-1-i && (char_array[i] != 'b' && char_array[i] != 'd' && char_array[i] != 'p' && char_array[i] != 'q'))
						ctr += 1
					#	puts 'd'
					#	puts ctr
					end
				end
      end
  end
#puts ctr
  if array_mod == 0
    if ctr == array_div
			puts 'TAK'
    else
      puts 'NEI'
    end
  else
    if ctr == array_div+1
			puts 'TAK'
    else
      puts 'NEI'
    end
  end

end


n,k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
t = a.sort.reverse
n.times do |i|
  len = 0
  flg = true
  t.each do |j|
    len += j if flg
    flg = !flg
  end
  if len > k
    t.delete_at(t.find_index(a[-i-1]))
  else
    p n-i
    break
  end
end

f="gets.split.map &:to_i"
n,k=eval f
a=eval f
n-=1 while k<(a[0...n].sort.values_at(*(-n|1...0).step(2)).reduce &:+)
p n

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

def f(k)
  list = A.take(k).sort
  height = 0

  until list.empty?
    a, b = list.pop(2)
    h = [a, b || 0].max

    height += h
  end

  height <= H
end

puts [*1..N].reverse.bsearch { |k| f(k) }

n,h = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
min = 0
max = n+1
while max-min > 1
    mid = (min+max)/2
    b = a[0,mid].sort.reverse
    x = 0
    for i in 0..(mid-1)/2
        x += b[i*2]
    end
    if x > h
        max = mid
    else
        min = mid
    end
end
puts min


#puts "Enter the number of magnets\n"
n = gets.to_i
m = [n]
for i in 0...n do
    m[i] = gets.to_s
end
c = 0
for j in 0...n do
    if m[j] != m[j+1]
        c += 1
    end
end
puts c

n = gets.to_i

c = 0
d = ""

n.times {
  f = gets.chomp
  if f != d
    c += 1
  end
  d = f
}

puts c

n = gets.to_i - 1
c = 1
l = gets.chomp
n.times do
	t = gets.chomp
	c += 1 if l[1] == t[0]
	l = t
end
puts c

n = gets.to_i

result = 1
prev = nil

1.upto n do
  curr = gets.to_i

  result += 1 if prev && prev != curr

  prev = curr
end

puts result

#!ruby

n = gets.to_i

prev_line = gets

count = 1

while line = gets
  count += 1 if line != prev_line
  prev_line = line
end

puts count

loopNum = gets.chomp.to_i
groupNum = 1
currentPole = 0

loopNum.times do
    pole = gets.chomp
    if pole == '01' # -1
        if currentPole == 1
            groupNum += 1
            currentPole = -1
        else
            currentPole = -1
        end
    elsif pole == '10' # 1
        if currentPole == -1
            groupNum += 1
            currentPole = 1
        else
            currentPole = 1
        end
    end
end

puts groupNum

n = gets.to_i
ar = []
n.times{ar << gets.chomp}
puts ar.chunk{|x| (x =~ /01/).nil?}.count

n = gets.strip.to_i

tmp = 1
cnt = 1
i = 0
lst  = gets.strip

while i < n-1
	fst = gets.strip

	if (fst[0] != lst[1])
		tmp += 1
	else
		cnt += 1
		tmp = 1
	end
	lst = fst
	i += 1
end

puts cnt

n = gets.to_i
black = 1
hoare = Array.new(n)

for i in 0...n
  hoare[i] = gets.to_i
end

for i in 1...n
  if hoare[i]!=hoare[i-1]
    black += 1
    # puts "Increm here " + i.to_s
  end
end

puts black

n = gets.to_i
result = 1
last = gets.to_i
(n-1).times do
   current = gets.to_i
   result += 1 if current != last
   last = current
end

puts result

n = gets.to_i

last = "00"
ans = 0

(0...n).each do |i|
    cur = gets.to_s
    if (last != cur)
        ans += 1
    end
    last = cur
end

if (ans == 0)
    puts 1
else
    puts ans
end

n = gets.to_i
if n==0
    print 0
    exit
end
input = $stdin.read.gsub("\n", "")
print input.scan(/00|11/).size+1

n = gets.to_i
if n==0
    print 0
    exit
end
result = 1
input = $stdin.read.split("\n")
exit if input.size < n
last = input[0][0]
input[1...n].each { |x|
	if x[0] != last
		last = x[0]
		result += 1
	end
}
print result

in_line = gets
n = in_line.to_i
exit if n < 0
if n==0
    print 0
    exit
end
result = 1
last = gets
last = last[0]
(n-1).times {
    x = gets
    if x[0] != last
        last = x[0]
        result += 1
    end
}
print result

n = gets.chomp.to_i
str = ""
n.times { str << gets.chomp }
puts str.scan(/(00)|(11)/).length+1

n = gets.to_i
a = Array.new(n)

for i in 0..n-1
  a[i] = gets.to_s.chomp
end

counter = 0
n.times do |i|
 if a[i] != a[i+1]
     counter+=1
 end
end

puts counter

n = $stdin.readline.to_i
a = $stdin.readline.scan(/./).map(&:to_i)
k = 1

(n-1).times do
    b = $stdin.readline.scan(/./).map(&:to_i)
    k+=1 if a.last == b.first
    a = b
end

puts k

n = gets.to_i
ret, prev = 0, nil
n.times do
  mag = gets
  ret += 1 if mag != prev || prev == nil
  prev = mag
end
puts ret

def run
  n = $stdin.gets.to_i
  s = $stdin.readlines.map(&:to_i)
  c = 1

  (s.length - 1).times do |i|
    c += 1 if s[i] == 10 and s[i + 1] == 1
    c += 1 if s[i] == 1 and s[i + 1] == 10
  end

  puts c
end

run if $0 == __FILE__

n = gets.to_i
ret = 0
prev = nil
n.times {
    mag = gets
    ret +=1 if mag != prev || prev == nil
    prev =mag
}
puts ret

str = ""
gets.to_i.times do
  str << gets.chomp
end
if str.length == 2
  puts 1
else
  str.gsub!(/10/,'x').gsub!(/01/,'y')
  counter =  0
  str.scan(/x+/) { counter += 1 }
  str.scan(/y+/) { counter += 1 }
  puts counter
end

class A
  def initialize
    n = gets.chomp.to_i

    state = 2
    count = 0

    n.times do
      magnet = gets.chomp

      if magnet == "10"
        if state == 1 || state == 2
          state = 0
          count += 1
        end
      else
        if state == 0 || state == 2
          state = 1
          count += 1
        end
      end
    end

    puts count
  end
end

a = A.new

a=gets.chomp.to_i
b=gets.chomp
if b=="01"
t=-1
else
t=1
end
temp=1
max=1
(a-1).times do
te=gets.chomp
if (te=="01" && t==1 )|| (te=="10" && t==-1)
t*=-1
max+=1
end
end

puts  "#{max}"

n = gets.to_i
g = gets.chomp
ans = 1
(n-1).times do
  m = gets.chomp
  if g != m
    ans += 1
    g = m
  end
end
puts ans

a=gets.chomp.to_i #কয়টা ইনপুট সেটা
b=gets.chomp #প্রথম ইনপুট টা
if b=="01"
t=-1 #মনে রাখে এখন ০১ না ১০ এর সিকোয়েন্স চলে
else
t=1
end
counter=1 # ভাগ সংখ্যা কাউন্ট করে

(a-1).times do #একটা ফর লুপ যা বাকি a-1 ইনপুট নেয়
te=gets.chomp # ইনপুট
if (te=="01" && t==1 )|| (te=="10" && t==-1) #t=1 মানে "10" এর সিকোয়েন্স চলে তখন "01" আসলে বা t=-1 মানে "01" তখন "10" আসলে
t*=-1                                        # ব্রেক হইসে। তখন কাউন্টার এক বাড়াব আর t এর মান চেঞ্জ করব কারণ নতুন সিকোয়েন্স শুরু হইসে
counter+=1
end
end

puts  "#{counter}" # কাউন্টার প্রিন্ট করে।

n=gets.to_i
o=gets.chomp
ans=1
(n-1).times{|i|
	a=gets.chomp
	if o!=a then
		ans=ans+1
		o=a
	end
}
puts ans

data = $stdin.read.split("\n")[1..-1].join
puts data.scan(/100/).size + data.scan(/110/).size + 1

n = gets.chomp.to_i
curr_inp = gets.chomp
co = 1
(n-1).times.each do
  prev_inp = curr_inp
  curr_inp = gets.chomp
  co +=1 if prev_inp != curr_inp
end

puts co

n = gets.to_i
k = 0

cur = gets.to_i
k += 1
for i in 2..n
  new = gets.to_i
  if cur != new
    k += 1
  end
  cur = new
end

puts k

magnets = gets.chomp.to_i
pairs = []
for i in (0..magnets-1)
	pairs[i] = gets.chomp
end

count = 0
for i in (0..magnets-1)
	if i < magnets-1
		if pairs[i] != pairs[i+1]
			count += 1
		end
	end
end

print count + 1

t = gets.to_i
last = gets.strip
ans = 1
(t - 1).times do
    g = gets.strip
    if g[0] == last[1]
        ans += 1
    end
    last = g
end
puts (t == 1 ? 1 : ans)

a=gets.chomp.to_i
b=gets.chomp
if b=="01"
t=-1
else
t=1
end
temp=1
max=1
(a-1).times do
te=gets.chomp
if (te=="01" && t==1 )|| (te=="10" && t==-1)
temp+=1
t*=-1
elsif (te=="01" && t==-1) || (te=="10" && t==1)
if temp > max
max=temp
end
temp=1
end
end
if temp > max
max=temp
end
puts  "#{max}"

a=gets.chomp.to_i
b=gets.chomp
if b=="01"
t=-1
else
t=1
end
temp=1
max=1
(a-1).times do
te=gets.chomp
if (te=="01" && t==1 )|| (te=="10" && t==-1)
temp+=1
elsif (te=="01" && t==-1) || (te=="10" && t==1)
t=t*-1
if temp > max
max=temp
end
temp=1
end
end
if temp > max
max=temp
end
puts  "#{max}"

a=gets.chomp.to_i
b=gets.chomp
if b=="01"
t=-1
else
t=1
end
temp=1
max=1
(a-1).times do
te=gets.chomp
if (te=="01" && t==-1 )|| (te=="10" && t==1)
temp+=1
elsif (te=="01" && t==1) || (te=="10" && t==-1)
t=t*-1
if temp > max
max=temp
end
temp=1
end
end

puts  "#{max}"

t = gets.to_i
last = '-'
ans = 0
t.times do
    g = gets.strip
    if g[1] == last
        ans += 1
    else
        last = g[1]
    end
end
puts (t == 1 ? 0 : ans)

t = gets.to_i
last = '-'
ans = 0
t.times do
    g = gets.strip
    if g[1] == last
        ans += 1
    else
        last = g[1]
    end
end
puts ans

t = gets.to_i
last = '-'
ans = 0
t.times do
    g = gets.strip
    if g[1] == last
        ans += 1
    else
        last = g[1]
    end
end
puts (t == 1 ? 1 : ans)

num = gets.chomp.to_i
input = []
ans = 0

(0...num).each do |iterNum|
	input << gets.chomp
end

(0...(num - 1)).each do |iterNum|
	ans += 1 if input[iterNum] == input[iterNum + 1]
end

if num == 1
	puts 1
	exit
end

puts ans

num = gets.chomp.to_i
input = []
ans = 0

(0...num).each do |iterNum|
	input << gets.chomp
end

(0...(num - 1)).each do |iterNum|
	ans += 1 if input[iterNum] == input[iterNum + 1]
end

puts ans

n = gets.strip.to_i

tmp = 1
cnt = 0
i = 0
lst  = gets.strip

while i < n-1
	fst = gets.strip

	if (fst[0] != lst[1])
		tmp += 1
	else
		cnt = (cnt > tmp ? cnt : tmp)
		tmp = 1
	end
	lst = fst
	i += 1
end

puts cnt

n = gets.to_i

last = "00"
ans = 0

(0...n).each do |i|
    cur = gets.to_s
    if (last == cur)
        ans += 1
    end
    last = cur
end

puts ans

n = gets.to_i

last = "00"
ans = 0

(0...n).each do |i|
    cur = gets.to_s
    if (last == cur)
        ans += 1
    end
    last = cur
end

if (ans == 0)
    puts 1
else
    puts ans
end

n = $stdin.readline.to_i
a = $stdin.readline.scan(/./).map(&:to_i)
k = 0

(n-1).times do
    b = $stdin.readline.scan(/./).map(&:to_i)
    k+=1 if a.last != b.first
    a = b
end

k = 1 if k==0
puts k

n = $stdin.readline.to_i
a = $stdin.readline.scan(/./).map(&:to_i)
k = 0

(n-1).times do
    b = $stdin.readline.scan(/./).map(&:to_i)
    k+=1 if a.last != b.first
    a = b
end

puts k

n = gets.to_i
ret, temp, prev = 0, 0, nil
n.times do
  mag = gets
  temp += 1
  if mag != prev || prev == nil
  	ret = [ret, temp].max
  	temp = 0
  end
  prev = mag
end
puts ret

n = gets.to_i
a = []
n.times do
    a << gets
end
is_one = a[0] == "10"
cnt = 0
a.each do |mag|
    next if mag == a[0]
    if (is_one && mag[0] == '0') || (!is_one && mag[0]=='1')
        cnt+=1
    end
end
puts(cnt+1)


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

bin = Hash.new(0)
a.each{|x| bin[x] += 1}

num = 0
1.upto(10){|x| num += bin[x]*bin[-x]}
num += bin[0]*(bin[0]-1)/2

p num

n = gets.to_i
a = gets.split.map(&:to_i)
mp = Hash.new
mp.default = 0
a.each { |i|
  mp[i] += 1
}
ans = mp[0] * (mp[0]-1)/2
10.times { |i|
  ans += mp[i+1] * mp[-i-1]
}
p ans

n=gets
t=gets.split.map(&:to_i)
cnt=Hash.new
cnt.default=0
t.each{|i|
        cnt[i]+=1
}
ans=cnt[0]*(cnt[0]-1)/2
for i in 1..10
        ans+=cnt[i]*cnt[-i]
end
p ans

#!/usr/bin/env ruby

n = gets.to_i
arr = gets.split.map(&:to_i)
dict = Hash.new(0)
arr.each do |i|
    dict[i] += 1
end

ans = 0
ans += dict[0]*(dict[0]-1)/2 if dict[0] >= 2
(1..10).each do |i|
    ans += dict[i]*dict[-i]
end

p ans

gets
a = {}
gets.chomp.split(' ').each do |e|
  if not a.has_key?(e)
    a[e] = 0
  end
  a[e] += 1
end

ret = 0

if a.has_key?("0")
  n = a["0"] - 1
  ret += n * (n + 1) / 2
end

(1..10).map{|e| e.to_s}.each do |i|
  if a.has_key?(i) and a.has_key?('-' + i)
    ret += a[i] * a['-' + i]
  end
end

p ret

m = gets.chomp.to_i

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

h = Hash.new(0)
a.each { | v | h.store(v, h[v]+1) }

k = 2
n = h[0]
if k > n
  t = 0
else
  t = n*(n-1)/2
end

h.keys.keep_if{|x| x>0}.each do |key|
  t+=h[-key]*h[key]
end

puts t

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

hs=Hash.new(0)
data.each do |val|
	hs[val]+=1
end

ans=hs[0]*(hs[0]-1)/2
(-10..-1).each do |i|
	a,b=hs[i], hs[i*(-1)]
	ans+=a*b
end

puts ans

n = gets.to_i
a = gets.split.map(&:to_i)
s = 0
(1..10).each{|i|
  s = s + a.find_all{|e| e == i}.size * a.find_all{|e| e == -i}.size
  a = a - [i, -i]
}
b = a.find_all{|e| e == 0}.size
s = s + b * (b - 1)/2
p s

n = gets.to_i
a = gets.split.map(&:to_i)
s = 0
(1..10).each{|i|
  s = s + a.find_all{|e| e == i}.size * a.find_all{|e| e == -i}.size
  a = a - [i, -i]
}
b = a.size
s = s + b * (b - 1)/2
p s

n = gets.to_i
a = gets.split.map(&:to_i)
s = 0
(1..10).each{|i|
  s = s + a.find_all{|e| e == i}.size * a.find_all{|e| e == -i}.size
}
b = a.find_all{|e| e == 0}.size
s = s + b * (b - 1)/2
p s

number = gets.strip.to_i
count = {}
gets.strip.split(' ').map(&:to_i).each do |num|
  count["#{num}"] ||= 0
  count["#{num}"] += 1
end

result = 0
1.upto(10).each do |val|
  count["#{val}"] ||= 0
  count["#{-val}"] ||= 0
  result += count["#{val}"] * count["#{-val}"]
end

if !count["0"].nil? && count["0"] >= 2
  result += (count["0"] - 1) * count["0"] / 2
end

puts result

gets # Skip the first line
hm = gets.split.map { |x| x.to_i }.inject(Hash.new(0)) { |h, e| h[e] += 1; h }
c = 0
for i in -10...0
  if hm.has_key?(i) && hm.has_key?(-i)
    c += hm[i] * hm[-i]
  end
end
if hm.has_key?(0)
  n = hm[0] - 1
  c += n * (n + 1) / 2
end
puts c

m = gets.chomp.to_i

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

h = Hash.new(0)
a.each { | v | h.store(v, h[v]+1) }

k = 2
n = h[0]
if k > n
  t = 0
else
  t = (1..n).inject(:*)/2/((1..(n-2)).inject(:+) || 1)
end

h.keys.keep_if{|x| x>0}.each do |key|
  t+=h[-key]*h[key]
end

puts t

n = gets.to_i
a = gets.split.map(&:to_i)
s = 0
n.times{|i|
    (i..(n-1)).each{ |j|
    if a[i] + a[j] == 0 then
      s = s + 1
    end
    }
}
p s


t = gets.chomp.to_i

for i in (1..t)
    n = gets.chomp.to_i
    a = (gets.chomp.split.map {|e| e.to_i}).reverse
    x = 0
    for j in (1..n-1)
        if a[j] != a[0]
            break
        end
        x += 1
    end
    ans = 0
    until x >= n-1
        # Aplique a operacao em que os valores (0, x) são copiados para (x+1, 2x+1)
        x = [n-1, 2*x+1].min
        ans += 1
        for j in (x+1..n-1)
            if a[j] != a[0]
                break
            end
            x += 1
        end
    end
    puts ans
end

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

  ans = 0
  g = n - 1

  while g > 0
    if xs[g - 1] == xs[n - 1]
      g -= 1
    else
      g = 2 * g - n
      ans += 1
    end
  end

  p ans
end


def max(a,b)
    return a>b ? a : b
end

s=gets
n=s.length
res=eval(s)
for i in -1..n-1 do
    if i==-1 || s[i]=='*'
        for j in i+1..n do
            if j==n || s[j]=='*'
                res=max(res,eval(s[0...i+1]+'('+s[i+1...j]+')'+s[j...n]))
            end
        end
    end
end
puts res

s = gets.chomp.to_s
s = "1*" + s + "*1"
#p s
a = (0...s.length).find_all{ |i| s[i] == '*' }
ans = -1
for i in a
 for j in a
   if( i != j )
     if( i < j )
     k = i
     else k = j
     end
     l = i + j - k
     x = s[0..k] + "(" + s[k+1..l-1] + ")" + s[l..s.length]
 #        p "#{x}  #{i}  #{j} #{k} #{l} "
     if( eval(x) > ans )
      ans = eval(x)
     end
   end
 end
end
puts ans

c = gets.strip
max = eval(c)

lpos = [0]
rpos = [c.length]
c.chars.each_with_index do |ci, idx|
  if ci == '*'
    lpos.push idx + 1
    rpos.push idx
  end
end

lpos.each do |l|
  rpos.each do |r|
    next if l > r
    exp = c[0...l] + '(' + c[l...r] + ')' + c[r...c.length]
    max = [max, eval(exp)].max
  end
end
p max

def max(a,b)
    return a>b ? a : b
end

s=gets
n=s.length
res=eval(s)
for i in -1..n-1 do
    if i==-1 || s[i]=='*'
        for j in i+1..n do
            if j==n || s[j]=='*'
                res=max(res,eval(s[0,i+1]+'('+s[i+1,j]+')'+s[j,n-1]))
            end
        end
    end
end
puts res


factor = 1.000000011
n, t = gets.split(" ").map { |x| x.to_i }

ans = n * factor ** t
puts ans.round(16)

arg = STDIN.gets
args = arg.split
n = args[0].to_i
t = args[1].to_i

printf("%.6f", (n * (1.000000011 ** t)))
puts

inp = gets.chomp.split(' ');
n = inp[0].to_i
t = inp[1].to_i

ans = n * (1.000000011 ** t)

p ans

n , t = gets.chomp.split.map(&:to_i)
ans = n
ref = 1.000000011
help = ref ** t
ans = ans * help
puts ans


def delp(s)
    k = -1
    while (k = s.index(" ", k+1)) do
        k += 1

        while s[k] == " " do
            s = s[0...k] + s[k+1..-1]
        end
    end
    return s
end

def cpz (s,z)
    str = ""
    while s.size > 0 do
        if (k = s.index(z)) then
            if s[k+1] != " " then
                s = s[0..k] + " " + s[k+1..-1]
            end
            if s[k-1] == " " then
                s = s[0...k-1] + s[k..-1]
            end
            str += s[0..k]
            s = s[k+1..-1]
        else
            str += s
            s = ""
        end
    end
    return str
end

s = gets.chomp
s = delp(s)
s = cpz(s,".")
s = cpz(s,",")
s = cpz(s,"!")
s = cpz(s,"?")
puts s

str=gets
s=str.chars.to_a
res=''
i=0
def isPunc(str)
  a=("a".."z").to_a+("A".."X").to_a
  a.each{|c|
    if str==c then
      return false
    end
    }
    return true
end
while i<str.length do
  if s[i]==" " then
    for j in i+1..s.length-1 do
      if s[j]!=" " then
        if !isPunc(s[j]) then
          res+=" "
        end
        i=j
        break
      end
    end
  elsif isPunc(s[i]) then
    j=0
    for j in i+1..s.length do
      if s[j]!=" " then
        break
      end
    end
    res+=s[i]+" "
    i=j
  else
    res+=s[i]
    i+=1
  end
end
puts res

words = gets.chomp.scan(/[.,!?]|\w+/)
finalString = String.new

words.each { |word|
  if word.match(/[,.?!]/)
    finalString += word
  else
    finalString += ' ' + word
  end
}

puts finalString[1..finalString.length]

words = gets.chomp.scan(/[.,!?]|\w+/)
ans = String.new

words.each do |word|
  if word.match(/[,.?!]/)
    ans += word
  else
    ans += ' ' + word
  end
end

puts ans[1..ans.length]

def punctuation
  str = gets.split(' ').map{|s| s.strip}.join(' ')

  i = 0
  while i < str.length
    if str[i] == '.' or str[i] == ',' or str[i] == '!' or str[i] == '?'
      if str[i-1] == ' '
        str[i-1] = ''
        i -= 1
      end

      unless str[i+1] == ' '
        str = "#{str[0..i]} #{str[i+1..-1]}"
        i += 1
      end
    end
    i += 1
  end

  puts str
  #galileo galilei was an italian physicist, mathematician, astronomer
  #galileo galilei was an italian physicist, mathematician, astronomer
end

punctuation

result = gets
result.strip!
result.gsub!(/\s+/, ' ')
result.gsub!(/([,.!?]+)(\w)/, '\1 \2')
result.gsub!(/(\w)\s+([,.!?]+)/, '\1\2')
print result

#s = "galileo galilei was an   italian physicist  ,mathematician,astronomer"
s = gets
print s.gsub(/ +/,' ').gsub(/ *([,\.!\?]) */, '\1 ')

input = STDIN.read.gsub(/ +/, ' ')

chars = ".,?!:;"

input = input.split(//)

input.each.with_index do |v, k|
	if chars.include? v
		if input[k - 1] == " "
			input[k - 1] = v
			input[k + 1] != " " ? input[k] = " " : input[k] = ""
		elsif input[k + 1] != " "
			input[k] = v + " "
		end
	end
end

STDOUT.puts input.join('')

input=gets
while true
        back=input.length
        input.gsub!("  "," ");
        break if back==input.length
end
input.gsub!(" !","!");
input.gsub!(" ?","?");
input.gsub!(" .",".");
input.gsub!(" ,",",");

for i in 0..25
        t="abcdefghijklmnopqrstuvwxyz"[i]
        input.gsub!("!"+t,"! "+t);
        input.gsub!("?"+t,"? "+t);
        input.gsub!("."+t,". "+t);
        input.gsub!(","+t,", "+t);
end
print input

str=gets
s=str.chars.to_a
res=''
i=0
while i<str.length do
  if s[i]==" " then
    for j in i+1..s.length-1 do
      if s[j]!=" " then
        if s[j]!="," then
          res+=" "
        end
        i=j
        break
      end
    end
  elsif s[i]=="," then
    for j in i+1..s.length do
      if s[j]!=" " then
        i=j
        break
      end
    end
    res+=", "
  else
    res+=s[i]
    i+=1
  end
end
puts res

words = gets.chomp.scan(/[.,?!]?[[:word:]]+/)
finalString = String.new
p words
words.each_index { |index|
  if index+1 != words.length
    if words[index+1][0..0].match(/[.,?!]/)
      puts words[index+1][0..0]
      finalString += ' ' + words[index] + words[index+1][0..0]
      words[index+1] = words[index+1][1..words[index+1].length]
    else
      finalString += ' ' + words[index]
    end

  else
    finalString += ' ' + words[index]
  end
}

puts finalString[1..finalString.length]

words = gets.chomp.scan(/[.,?!]?[[:word:]]+/)
finalString = String.new
words.each_index { |index|
  if index+1 != words.length
    if words[index+1][0..0].match(/[.,?!]/)
      finalString += ' ' + words[index] + words[index+1][0..0]
      words[index+1] = words[index+1][1..words[index+1].length]
    else
      finalString += ' ' + words[index]
    end

  else
    finalString += ' ' + words[index]
  end
}

puts finalString[1..finalString.length]

def punctuation
  str = gets.strip

  str = str.split(' ').map{|s| s.strip}.join(' ')
  fin = ''

  (0...str.length).each do |i|
    if str[i] == '.' or str[i] == ',' or str[i] == '!' or str[i] == '?'
      j = i
      if str[i-1] == ' '
        str[i-1] = ''
        j -= 1
      end
      str = "#{str[0..j]} #{str[j+1..-1]}" unless str[j+1] == ' '
    end
  end

  print str
end

punctuation

def punctuation
  str = gets.strip

  str = str.split(' ').map{|s| s.strip}
  fin = ''
  str.each_with_index do |s, ind|
    fin += " " if ind > 0

    (0...s.size).each do |i|
      if s[i] == '.' or s[i] == ',' or s[i] == '!' or s[i] == '?'
        if i == 0
          fin = "#{fin[0...fin.length-1]}#{s[i]} "
        else
          fin += "#{s[i]} "
        end
      else
        fin += s[i]
      end
    end
  end

  puts fin
end

def punctuation
  str = "galileo galilei was an   italian physicist  ,mathematician,astronomer"#gets.strip

  str = str.split(' ').map{|s| s.strip}
  fin = ''
  str.each_with_index do |s, ind|
    fin += " " if ind > 0

    (0...s.size).each do |i|
      if s[i] == '.' or s[i] == ',' or s[i] == '!' or s[i] == '?'
        fin = "#{fin[0...fin.length-1]}#{s[i]} "
      else
        fin += s[i]
      end
    end
  end

  p fin
end

punctuation

def punctuation
  str = gets.strip

  str = str.split(' ').map{|s| s.strip}
  fin = ''
  str.each_with_index do |s, ind|
    fin += " " if ind > 0

    (0...s.size).each do |i|
      if s[i] == '.' or s[i] == ',' or s[i] == '!' or s[i] == '?'
        if i == 0
          fin = "#{fin[0...fin.length-1]}#{s[i]} "
        else
          fin += "#{s[i]} "
        end
      else
        fin += s[i]
      end
    end
  end

  puts fin# == 'galileo galilei was an italian physicist, mathematician, astronomer'
end

def punctuation
  str = gets.strip

  str = str.split(' ').map{|s| s.strip}
  fin = ''
  str.each_with_index do |s, ind|
    fin += " " if ind > 0

    (0...s.size).each do |i|
      if s[i] == '.' or s[i] == ',' or s[i] == '!' or s[i] == '?'
        fin = "#{fin[0...fin.length-1]}#{s[i]} "
      else
        fin += s[i]
      end
    end
  end

  puts fin
end

punctuation

def punctuation
  str = gets.strip

  str = str.split(' ').map{|s| s.strip}.join(' ')
  fin = ''

  i = 0
  while i < str.length
    if str[i] == '.' or str[i] == ',' or str[i] == '!' or str[i] == '?'
      if str[i-1] == ' '
        str[i-1] = ''
        i -= 1
      end

      unless str[i+1] == ' '
        str = "#{str[0..i]} #{str[i+1..-1]}"
        i += 1
      end
    end
    i += 1
  end

  print str
end

def punctuation
  str = gets.strip

  str = str.split(' ').map{|s| s.strip}
  fin = ''
  str.each_with_index do |s, ind|
    fin += " " if ind > 0

    (0...s.size).each do |i|
      if s[i] == '.' or s[i] == ',' or s[i] == '!' or s[i] == '?'
        if i == 0
          fin = "#{fin[0...fin.length-1]}#{s[i]} "
        else
          fin += "#{s[i]} "
        end
      else
        fin += s[i]
      end
    end
  end

  print fin
end

punctuation

def punctuation
  str = gets.strip

  str = str.split(' ').map{|s| s.strip}
  fin = ''
  str.each_with_index do |s, ind|
    fin += " " if ind > 0

    (0...s.size).each do |i|
      if s[i] == '.' or s[i] == ',' or s[i] == '!' or s[i] == '?'
        fin = "#{fin[0...fin.length-1]}#{s[i]} "
      else
        fin += s[i]
      end
    end
  end

  p fin
end

punctuation

input = STDIN.read

input.gsub!(/ +/, ' ')

input.each_char.with_index do |v, k|
	if v == ","
		if input[k - 1] == " "
			input[k] = " "
			input[k - 1] = ","
		elsif input[k + 1] != " "
			input[k] = ", "
		end
	end
end

STDOUT.puts input

input = STDIN.read.gsub(/ +/, ' ')

chars = ".,?!:;"

input.each_char.with_index do |v, k|
	if chars.include? v
		if input[k - 1] == " "
			input[k - 1] = v
			input[k + 1] != " " ? input[k] = " " : input[k] = ""
		elsif input[k + 1] != " "
			input[k] = v + " "
		end
	end
end

STDOUT.puts input


gets.strip.to_i.times do
  h, m = gets.strip.split(' ').map(&:to_i)
  puts 24 * 60 - (h * 60 + m)
end

readline.to_i.times do
  h, m = readline.split.map(&:to_i)
  p((24-h)*60-m)
end

gets.to_i.times do
	a, b = gets.split.map(&:to_i)
	puts 24 * 60 - (a * 60 + b)
end

gets.to_i.times do
  h, m = gets.split.map(&:to_i)
  puts (23*60+60)-(h*60+m)
end

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

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

def big(a,b) return (a>b)? a:b end

def small(a,b) return (a<b)? a:b end

n = inp[0]

n.times do |i|
  h,m = inp
  p (23-h)*60+(60-m)
end

# coding: utf-8

# if __FILE__ == $0
# end

gets.to_i.times {
    hh, mm = gets.split.map(&:to_i)
    puts (23 - hh) * 60 + (60 - mm)
}

t=gets.to_i
t.times do
    h,m=gets.split.map(&:to_i)
    puts (23-h)*60 + 60-m
end

1.upto(gets.to_i) do
  h, m = gets.split(' ').map(&:to_i)

  puts (23-h)*60 + (60-m)
end


def solve(piles)
  return "Mike" if piles.length % 2 != 0
  ans = [Float::INFINITY, -1]
  piles.each_with_index do |pile, i|
    ans = [pile, i] if pile < ans[0]
  end
  ans[1] % 2 == 0 ? "Joe" : "Mike"
end
cases = gets.to_i
cases.times do
  gets
  piles = gets.chomp.split(' ').map(&:to_i)
  puts solve(piles)
end

t = gets.to_i
t.times {
  n = gets.to_i
  a = gets.split.map &:to_i
  if n % 2 == 1
    puts "Mike"
  else
    m = a.min
    i = a.index(m)
    if i % 2 == 0
      puts "Joe"
    else
      puts "Mike"
    end
  end
}

def solve(piles)
  p piles
  return "Mike" if piles.length % 2 != 0
  ans = [Float::INFINITY, -1]
  piles.each_with_index do |pile, i|
    ans = [pile, i] if pile < ans[0]
  end
  ans[1] % 2 == 0 ? "Joe" : "Mike"
end
cases = gets.to_i
cases.times do
  gets
  piles = gets.chomp.split(' ').map(&:to_i)
  puts solve(piles)
end


n, m = gets.split.map(&:to_i)
b = [true] * 4
n.times do
    a = Array.new(4){gets[/([aeiou][^aeiou]*){#{m}}$/]}
    1.upto(3) do |i|
        if b[i]
            b[i] &= a[0] && a[0] == a[i]
            j = i != 1 ? 1 : 2
            k = i != 3 ? 3 : 2
            b[i] &= a[j] && a[j] == a[k]
        end
    end
end

if b.all?
    puts :aaaa
elsif b[1]
    puts :aabb
elsif b[2]
    puts :abab
elsif b[3]
    puts :abba
else
    puts :NO
end

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

old_scheme = "aaaa"
(1..n).each{
  scheme = nil
  lines = Array.new(4) { gets.chomp }

  lines.each_index{|i|
    pos = []
    lines[i].scan(/[aeiou]/){pos << $~.begin(0)}
    if pos[-k].nil?
      puts "NO"
      exit
    end
    lines[i] = lines[i][pos[-k]..-1]
  }

  scheme = "aabb" if lines[0] == lines[1] and lines[2] == lines[3]
  scheme = "abab" if lines[0] == lines[2] and lines[1] == lines[3]
  scheme = "abba" if lines[0] == lines[3] and lines[1] == lines[2]
  scheme = "aaaa" if lines[0] == lines[1] and lines[1] == lines[2] and lines[2] == lines[3]
  if scheme.nil? or (old_scheme != scheme and old_scheme != "aaaa" and scheme != "aaaa")
    puts "NO"
    exit
  end

  old_scheme = scheme if scheme != "aaaa"
}

puts old_scheme

n,k=gets.split.map(&:to_i)
ans=7
re=/.*(([aeiou].*){#{k}})$/

n.times{
	s=4.times.map{gets.chomp}
	if s[0]=~re
		if s[1].end_with?($1)
			if s[2].end_with?($1)
				if s[3].end_with?($1)
					ans&=7
				else
					ans=0
				end
			else
				if s[2]=~re #1
					if s[3].end_with?($1)
						ans&=1
					else
						ans=0
					end
				else
					ans=0
				end
			end
		else
			if s[2].end_with?($1) #2
				if s[1]=~re
					if s[3].end_with?($1)
						ans&=2
					else
						ans=0
					end
				else
					ans=0
				end
			elsif s[3].end_with?($1) #4
				if s[1]=~re
					if s[2].end_with?($1)
						ans&=4
					else
						ans=0
					end
				else
					ans=0
				end
			else
				ans=0
			end
		end
	else
		ans=0
	end
	break if ans==0
}

puts({0=>"NO",1=>"aabb",2=>"abab",4=>"abba",7=>"aaaa"}[ans])

def check_quatrain(k)

	reg = Regexp.new("([aiueo][^aiueo]*){#{k}}$")

	suffixes = []
	4.times do
		if s = gets.slice(reg)
			suffixes << s
		else
			suffixes = []
			break
		end
	end

	case suffixes.uniq.size
	when 1 then
		"aaaa"
	when 2 then
		if suffixes[0] == suffixes[1] && suffixes[2] == suffixes[3]
			"aabb"
		elsif suffixes[0] == suffixes[2] && suffixes[1] == suffixes[3]
			"abab"
		elsif suffixes[0] == suffixes[3] && suffixes[1] == suffixes[2]
			"abba"
		else
			"NO"
		end
	else
		"NO"
	end
end

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

current = "aaaa"
n.times do |i|
	result = check_quatrain(k)
	if result == "aaaa" || result == current
		next
	elsif current == "aaaa"
		current = result
		next
	end
	current = "NO"
	break
end

puts current

n, m = gets.split.map(&:to_i)
b = [true] * 4
n.times do
    a = Array.new(4){gets.gsub(/[^aeiou]/, '').reverse[0, m]}
    1.upto(3) do |i|
        if b[i]
            b[i] &= a[0].size == m && a[0] == a[i]
            j = i != 1 ? 1 : 2
            k = i != 3 ? 3 : 2
            b[i] &= a[j].size == m && a[j] == a[k]
        end
    end
end

if b.all?
    puts :aaaa
elsif b[1]
    puts :aabb
elsif b[2]
    puts :abab
elsif b[3]
    puts :abba
else
    puts :NO
end

n, m = gets.split.map(&:to_i)
b = [true] * 4
n.times do
    a = Array.new(4){gets[/([aeiou].*?){#{m}}$/]}
    1.upto(3) do |i|
        if b[i]
            b[i] &= a[0] && a[0] == a[i]
            j = i != 1 ? 1 : 2
            k = i != 3 ? 3 : 2
            b[i] &= a[j] && a[j] == a[k]
        end
    end
end

if b.all?
    puts :aaaa
elsif b[1]
    puts :aabb
elsif b[2]
    puts :abab
elsif b[3]
    puts :abba
else
    puts :NO
end

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

old_scheme = "aaaa"
(1..n).each{
  scheme = nil
  lines = Array.new(4) { gets.chomp }

  lines.each_index{|i|
    pos = []
    lines[i].scan(/[aeiou]/){pos << $~.begin(0)}
    if pos[-k].nil?
      puts "NO"
      exit
    end
    lines[i] = lines[i][pos[-k]..-1]
  }

  scheme = "aabb" if lines[0] == lines[1] and lines[2] == lines[3]
  scheme = "abab" if lines[0] == lines[2] and lines[1] == lines[3]
  scheme = "abba" if lines[0] == lines[3] and lines[1] == lines[2]
  scheme = "aaaa" if lines[0] == lines[1] and lines[1] == lines[2] and lines[2] == lines[3]
  if scheme.nil? or (old_scheme != scheme and old_scheme != "aaaa")
    puts "NO"
    exit
  end

  old_scheme = scheme
}

puts old_scheme


#!/usr/bin/ruby
n=gets.to_i
a=n.times.map{gets.split}
perm=gets.split.map{|e|e.to_i-1}
a=perm.map{|e|a[e]}
cur=a[0].min
puts (1...n).all?{|i|
	cur=a[i].select{|e|e>=cur}.min
} ? :YES : :NO

n=gets.to_i
a=Array.new(n)
for i in 0...n
	a[i]=gets.chomp.split.sort
end
cur,ans='','YES'
for i in gets.chomp.split.map(&:to_i)
	if a[i-1][0] > cur
		cur = a[i-1][0]
	elsif a[i-1][1] > cur
		cur = a[i-1][1]
	else
		ans = 'NO'
	end
end
puts ans

def can_p(p, names, use_n)
  can
end

n = gets.to_i
names = (1..n).map{gets.split(" ")}
p = gets.split(" ").map(&:to_i)

can_n = true
can_sn = true

(1..n-1).each do |i|
  prev_n, prev_sn = names[p[i-1] - 1]
  cur_n, cur_sn = names[p[i] - 1]
  can_n_next = can_n && cur_n > prev_n || can_sn && cur_n > prev_sn
  can_sn_next = can_n && cur_sn > prev_n || can_sn && cur_sn > prev_sn
  can_n, can_sn = can_n_next, can_sn_next
  break if ! can_n && ! can_sn
end

ans = can_n || can_sn ? "YES" : "NO"
puts ans

n = gets.to_i
a = n.times.map{gets.split.sort}.unshift(nil)
p = gets.split.map(&:to_i)
s = ''
ans = p.each do |i|
  if a[i][0] > s
    s = a[i][0]
  elsif a[i][1] > s
    s = a[i][1]
  else
    break
  end
end
puts ans ? 'YES' : 'NO'

n = gets.to_i
a = [[]] + n.times.map{gets.split.sort}
p = gets.split.map(&:to_i)
s = []
ans = true
p.each do |i|
  if i == p[0] || a[i][0] > s.last[0]
    s << a[i]
  elsif a[i].reverse[0] > s.last[0]
    s << a[i].reverse
  else
    ans = false
    break
  end
end
puts ans ? "YES" : "NO"

a = []
(n = gets.to_i).times {
  a << gets.chomp.split
}
order = gets.chomp.split.map { |c| c.to_i - 1 }
last = a[order[0]]
(1...n).each { |k|
  cur = []
  a[order[k]].each { |x|
    cur << x if last.any? { |v| x > v }
  }
  if cur.empty?
    puts 'NO'
    exit
  end
  last = cur
}
puts 'YES'

n=gets.to_i
h=[0]
n.times{h<<gets.split}
p=gets.split.map &:to_i
b=""
r="YES"
p.each do |i|
  if h[i].min > b
    b=h[i].min
  elsif h[i].max > b
    b=h[i].max
  else
    r="NO"
    break
  end
end
puts r

def can_p(p, names, use_n)
  can
end

n = gets.to_i
names = (1..n).map{gets.split(" ")}
p = gets.split(" ").map(&:to_i)

puts "NAMES: #{names}"
puts "P: #{p}"

can_n = true
can_sn = true

(1..n-1).each do |i|
  prev_n, prev_sn = names[p[i-1] - 1]
  cur_n, cur_sn = names[p[i] - 1]
  can_n_next = can_n && cur_n > prev_n || can_sn && cur_n > prev_sn
  can_sn_next = can_n && cur_sn > prev_n || can_sn && cur_sn > prev_sn
  can_n, can_sn = can_n_next, can_sn_next
  break if ! can_n && ! can_sn
end

ans = can_n || can_sn ? "YES" : "NO"
puts ans

n = gets.to_i
a = n.times.map{gets.chomp}
p = gets.split.map(&:to_i)
def change a
	name1, name2 = a.split
	tmp = name1
	return [name2, tmp].join(" ")
end
def compare i, j, a
	3.times do |k|
		if a[i-1] > a[j-1]
			if k == 0
				a[j-1] = change a[j-1]
			elsif k == 1
				a[i-1] = change a[i-1]
			elsif k == 2
				a[j-1] = change a[j-1]
			end
		elsif a[i-1] < a[j-1]
			return true
			break
		end
	end
end
n.times do |i|
	if compare(p[i], p[i+1], a) == false
		puts "NO"
		break
	elsif i == p.size - 2
		puts "YES"
		break
	end
end

a = []
(n = gets.to_i).times {
  a << gets.chomp.split
}
order = gets.chomp.split.map { |c| c.to_i - 1 }
(0...n - 1).each { |k|
  i, j = order[k, k + 2]
  unless a[i][0] < a[j][0] || a[i][0] < a[j][1] || a[i][1] < a[j][0] || a[i][1] < a[j][1]
    puts 'NO'
    exit
  end
}
puts 'YES'


t=gets.chomp.to_i
t.times do
    r = gets.chomp.to_i
    if(r>=1900)
        puts "Division 1"
    end
    if(r>=1600 && r<=1899)
        puts "Division 2"
    end
    if(r>=1400 && r<=1599)
        puts "Division 3"
    end
    if(r<=1399)
        puts "Division 4"
    end
end

def division?(n)
  if n <= 1399
    puts "Division 4"
  elsif n >= 1400 && n <= 1599
    puts "Division 3"
  elsif n >= 1600 && n <= 1899
    puts "Division 2"
  else
    puts "Division 1"
  end
end

t = gets.chomp.to_i

input = []
(0..t-1).each do |i|
  input.push(gets.chomp.to_i)
end

input.each do |i|
  division?(i)
end

input1 = gets.to_i
input1.times do
  output = ["Division"]
  case (input = gets.to_i)
  when (..1399) then output << "4"
  when (1400..1599) then output << "3"
  when (1600..1899) then output << "2"
  when (1900..) then output << "1"
  end
  puts output.join(" ")
end

gets.to_i.times do
  n = gets.to_i
  x = if n <= 1399
      4
    elsif n <= 1599
      3
    elsif n <= 1899
      2
    else
      1
    end
  puts "Division #{x}"
end

t = gets.chomp().to_i

for i in 1 .. t
    rating = gets.chomp().to_i
    if 1900 <= rating
        puts "Division 1"
    elsif 1600 <= rating and rating <= 1899
        puts "Division 2"
    elsif 1400 <= rating and rating <= 1599
        puts "Division 3"
    elsif rating <= 1399
        puts "Division 4"
    end
end

gets.to_i.times do
  a = gets.to_i
  if a>= 1900
    puts "Division 1"
  elsif a >= 1600
    puts "Division 2"
  elsif a >= 1400
    puts "Division 3"
  else
    puts "Division 4"
  end
end

tests = gets.to_i

tests.times do

    i = gets.to_i

    if i >= 1900
        puts "Division 1"
    elsif 1600 <= i and i <= 1899
        puts "Division 2"
    elsif 1400 <= i and i <= 1599
        puts "Division 3"
    else
        puts "Division 4"
    end
end


#! ruby
# try Codeforces Round 325 div2
# author: Leonardone @ NEETSDKASU

n = gets.to_i
*a, b = readlines.map{|x| x.chomp.split.map(&:to_i)}

f1 = [[:H2S, n - 1, 1, 0, 0]]

sp = 100 * 100
ans = 100 * 100
while !f1.empty?
	f2 = []
	f1.each do |f, x, y, c, r|
		case f
		when :H2S
			if x > 0
				nc = c + a[y][x - 1]
				if x - 1 == 0 && y == 0
					if nc < sp
						sp = nc
						f2 << [:S2H, 0, 0, nc, r]
					end
				else
					f2 << [f, x - 1, y, nc, r]
				end
			end
			if y == 1
				nc = c + b[x]
				if x == 0
					if nc < sp
						sp = nc
						f2 << [:S2H, 0, 0, nc, x]
					end
				else
					f2 << [f, x, 0, nc, x]
				end
			end
		when :S2H
			if x < n - 1
				nc = c + a[y][x]
				if x + 1 == n - 1 && y == 1
					ans = [ans, nc].min
				else
					f2 << [f, x + 1, y, nc, r]
				end
			end
			if y == 0 && r != x
				nc = c + b[x]
				if x == n - 1
					ans = [ans, nc].min
				else
					f2 << [f, x, 1, nc, r]
				end
			end
		end
	end
	f1 = f2
end
puts ans

n=gets.to_i
cross2=gets.split(" ").map(&:to_i)
cross1=gets.split(" ").map(&:to_i)
crossav=gets.split(" ").map(&:to_i)

t=999999999999999
for i in 0...n
	for j in 0...n
		next if i == j

		cost = 0
		cost += (cross1[i..-1].reduce(:+)||0) + crossav[i] + (cross2[0...i].reduce(:+)||0)
		cost += (cross1[j..-1].reduce(:+)||0) + crossav[j] + (cross2[0...j].reduce(:+)||0)

		t = [t, cost].min
	end
end

p t

n, first_row_traffic, second_row_traffic, avenue_traffic, sums =
	gets.chomp.to_i,
	gets.chomp.split(" ").map(&:to_i).unshift(0),
	gets.chomp.split(" ").map(&:to_i).push(0),
	gets.chomp.split(" ").map(&:to_i),
	[]

(n-1).downto 0 do |i|
	sum = 0

	sum += avenue_traffic[i]

	i.downto 0 do |j|
		sum += first_row_traffic[j]
	end

	i.upto (n-1) do |j|
		sum += second_row_traffic[j]
	end

	sums << sum
end
sums.sort!
puts (sums[0] + sums[1])

n = gets.chomp.to_i
top = gets.split.map{ |x| x.to_i }
bot = gets.split.map{ |x| x.to_i }
over = gets.split.map{ |x| x.to_i }
cost = []
n.times do |i|
  sum = over[i]
  (0...i).each { |j| sum += top[j] }
  (i...(n-1)).each { |j| sum += bot[j] }
  cost << sum
end

max= top.inject(:+) + bot.inject(:+) + over.inject(:+)
r1 = max
b1 = 0
n.times do |i|
  if cost[i] < r1
    r1 = cost[i]
    b1 = i
  end
end
r2 = max
n.times do |i|
  if cost[i] < r2 and i != b1
    r2 = cost[i]
  end
end

puts r1+r2

n = gets.chomp.to_i
as = []
2.times do
  as << gets.chomp.split(' ').map(&:to_i)
end
bs = gets.chomp.split(' ').map(&:to_i)

cs = []
for i in 0..1
  c = [0]
  for j in 1..n - 1
    c << c[j-1] + as[i][j-1]
  end
  cs << c
end

ds = []
for i in 0..n-1
  ds << cs[0][i] + bs[i] + cs[1][n-1] - cs[1][i]
end

ds.sort!
puts ds[0] + ds[1]

# coding; utf-8

h = gets.strip.to_i
fr = gets.strip.split(' ').map(&:to_i)
sr = gets.strip.split(' ').map(&:to_i)
av = gets.strip.split(' ').map(&:to_i)

times = [ ]
h.times do |i|
  t = av[i]
  0.upto(i - 1) { |j| t += fr[j] }
  i.upto(sr.length - 1) { |j| t += sr[j] }

  times.push(t)
end

times.sort!
puts (times[0] + times[1]).to_s


def run
  n, x = gets.chomp.split(" ").map(&:to_i)
  a = gets.chomp.split(" ").map(&:to_i)
  rich = a.select{|el| el >= x}
  poor = a.select{|el| el < x}.sort_by{|c| -c}
  count = rich.count
  surplus = rich.reduce(0) {|acc, el| acc + (el > x ? el - x : 0)}
  poor.each do |p|
    if surplus >= x - p
      surplus -= (x - p)
      count += 1
    else
      break
    end
  end
  puts count
end

def main
  t = gets.chomp.to_i

  t.times do
    run
  end
end

main

t = gets.to_i
t.times do
  n, x = gets.split.map(&:to_i)
  a = gets.split.map(&:to_i).sort.reverse
  count = 0
  savings_sum = 0
  a.each_with_index do |v, i|
    savings_sum += v
    if savings_sum >= x * (i + 1)
      count += 1
    else
      break
    end
  end
  puts count
end

1.upto(gets.to_i) do
  n, x = gets.split(' ').map(&:to_i)
  a = gets.split(' ').map(&:to_f).sort.reverse

  s = 0
  n = a.count { |c| c >= x }
  max = n

  a.each_with_index do |e, i|
    s += e

    n -= 1 if e >= x

    break if s/(i+1) < x

    max = [max, n + i + 1].max
  end

  puts max
end