h=Hash.new(0)
n=gets.to_i
gets.split.each{|e|h[e.to_i]+=1}
r=n*(n-1)/2
h.each{|k,v|r-=v*(v-1)/2}
p r

n, m = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
a = a.sort
b = []
for i in 1..m do
  b[i] = 0
end
a.each do |val|
  b[val] += 1
end

combinations = 0
for i in 1..m do
  combinations += b[i] * (n - b[i])
  n -= b[i]
end
puts combinations

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

n, m = gis
a = vcount(gis,[0]*m.succ)

puts (1..m).inject(0){|r,i| (i+1..m).inject(r){|r,j|r+a[i]*a[j]} }

data1=gets.chomp.split
n=data1[0].to_i
m=data1[1].to_i

data2=gets.chomp.split

books=[]

data2.each do |i|
	books.push(i.to_i)
end

books.sort!

books1=[]
b=books[0]
s=0
books.each do |item|
	if item == b
		s+=1
	else
		books1.push(s)
		b=item
		s=1
	end
end

books1.push(s)

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

for i in(0..books1.length-1)
	sum-=(books1[i]*(books1[i]-1))/2
end

puts sum

#!/usr/bin/env ruby

n, m = gets.split.map(&:to_i)
freqs = Hash.new(0)
a = gets.split.map(&:to_i)
a.each do |_a|
  freqs[_a] += 1
end
ans = n * (n - 1) / 2
freqs.each_pair do |k, v|
  ans -= (v * (v - 1) / 2)
end
puts ans

arr1 = gets.chomp.split(/ /)
t = arr1[0].to_i
n = arr1[1].to_i
arr2 = gets.chomp.split(/ /)
arr2.sort!
#puts arr2
arr3 = Array.new(n, 0)
index=0
loop do
	break if index>=t
	arr3[arr2[index].to_i-1]+=1
	index+=1
end

sum=0
count=0

index=0
loop do
	break if index>=n-1
	count = count + arr3[index]
	sum = sum + arr3[index]*(t-count)
	index+=1
	#puts "Index is #{index} and sum is #{sum} and count is #{count}"
end

puts sum

n,m = gets.split(" ").map {|x| x.to_i }
a = gets.split(" ").map{|x| x.to_i}
b = Array.new(m, 0)

remain = n
a.each do |x|
  b[x-1] += 1
end

result = 0
b.each do |x|
  remain -= x
  result += remain* x
end

puts result

n, m = gets.chomp.split(" ").map(&:to_i)
books = gets.chomp.split(" ").map(&:to_i)
dic = Hash.new(0)
res = 0
books.each do |k|
  dic[k] += 1
end
(1..m).to_a.combination(2) do |i, j|
    res +=  dic[i] * dic[j]
end
puts res

n, m = gets.split(' ')
array = gets.split(' ')
sta = Array.new(m.to_i, 0)
for item in array
    sta[item.to_i - 1] += 1
end
ans = 0
for i in 0..m.to_i-1
    for j in i+1..m.to_i-1
        ans += sta[i] * sta[j]
    end
end
puts ans

n, m = gets.split.map(&:to_i)
books = gets.split.map(&:to_i)
genre = Array.new(m)
for book in books
  if genre[book] == nil
    genre[book] = 1
  else
    genre[book] += 1
  end
end

count = 0
for i in (1..m-1)
  for j in (i+1..m)
    count += genre[i] * genre[j]
  end
end

puts count

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

list = gets.chomp.split.map(&:to_i)
hash = Hash.new { |hash, key| hash[key] = 0 }

for i in 0..(list.length - 1)
  hash[list[i]] += 1
end

new_list = hash.values
result = 0
for i in 0..(new_list.length - 1)
  for j in (i+1)..(new_list.length - 1)
    result += new_list[j] * new_list[i]
  end
end

puts result

n = 0
m = Array.new

args = gets.chomp.split(/ /)
m = args.last.to_i

genre = Array.new
for i in 0..m do genre[i] = 0 end

arr = gets.chomp.split(/ /)
arr.each {|el| genre[el.to_i - 1] = genre[el.to_i - 1] + 1}

s = genre[0]
ans = 0
for i in 1..m do
	ans = ans + s * genre[i]
	s = s + genre[i];
end

print ans


n = gets.to_i
a = gets.chomp.split(" ").map(&:to_i)
if n != 1
  puts "1 #{n}"
  n.times do |i|
    v = ((n-1) - a[i] % (n-1)) * n
    a[i] += v
    print "#{v} "
  end
  puts ""
  puts "1 #{n-1}"
  (n-1).times do |i|
    print "#{-a[i]} "
  end
  puts ""
  puts "#{n} #{n}"
  puts -a[n-1]
else
  puts "1 1"
  puts -a[0]
  puts "1 1"
  puts "0"
  puts "1 1"
  puts "0"
end


# Print cardiogram given 2d array
def print_cardiogram(out)
    for i in 0..(out.length - 1) do
        puts out[i].join("")
    end
end

# Read Input
n = gets.strip.to_i
a = gets.strip.split.map{|s| s.to_i}

# Find output size and starting point
hd = 0; pp = 0; pn = 0; w = 0;
for i in 0..(a.length - 1) do
    if i.even?
        hd = hd + a[i]
        pp = hd if hd > pp
    else
        hd = hd - a[i]
        pn = hd if hd < pn
    end
    w = w + a[i]
end
h = [pp,0].max - [pn,0].min
y = pp - 1; x = 0;

# Create out array
out = Array.new(h) {Array.new(w){" "}}

# Fill out array
for i in 0..(a.length - 1) do
    for j in 1..a[i] do
        if i.even?
            out[y][x] = "/"
            y = y - 1 if j < a[i]
        else
            out[y][x] = "\\"
            y = y + 1 if j < a[i]
        end
        x = x + 1
    end
end

# Print cardiogram
print_cardiogram(out)

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

coords = [[0,0]]

(0..tab.size-1).each do |i|
    if i % 2 == 0
        coords << [coords[i][0] + tab[i], coords[i][1] + tab[i]]
    else
        coords << [coords[i][0] + tab[i], coords[i][1] - tab[i]]
    end
end

x = coords.map{|a| a[0]}
y = coords.map{|a| a[1]}

x_diff = x.max
y_diff = y.max - y.min

zero = y.max

coords.map!{|x| [x[0], zero-x[1]]}

result = []
(y_diff+1).times do
    result << [' '] * x_diff
end

(0..coords.size-2).each do |i|
    if i % 2 == 0
        temp = 0
        while coords[i][0] + temp != coords[i+1][0]
            result[coords[i][1]-temp][coords[i][0]+temp] = "/"
            temp += 1
        end
    else
        temp = 0
        while coords[i][0] + temp != coords[i+1][0]
            result[coords[i][1]+temp+1][coords[i][0]+temp] = "\\"
            temp += 1
        end
    end

end

result[1..-1].each do |row|
    puts row.join("")
end


$stdin = File.open("input.txt", "r")
$stdout = File.open("output.txt", "w")
n = gets.to_i
s = gets
ones = (0...n).select{|pos| s[pos]=="1"}
diff = ones.map.with_index(1){|e,i| ones[i]-e if ones[i]}.compact
puts (diff.all?{|x| x == diff[0]} ? "YES" : "NO")

File.open('input.txt', 'r') do |inp|
	File.open('output.txt', 'w') do |out|
		a = inp.readlines[1].chars.to_a.each_with_index.reduce([]) { |s, (x, i)| s <<= i if x == '1'; s }
		out.write %w[YES NO][Array(1...a.length).reduce([]) { |s, x| s << a[x] - a[x - 1] }.sort.uniq.length == 1 ? 0 : 1]
	end
end

f,g=open("input.txt","r"),open("output.txt","w")
f.gets
g.puts(f.gets[/1.+1/].chop.scan(/10*/).map(&:size).uniq.size<2 ? "YES" : "NO")
f.close
g.close

a, b = [], []
open('input.txt').read.split("\n")[1].each_char.with_index { |c, i| a.push i if c == "1" }
a[0].step(a[-1], a[1] - a[0]) { |e| b.push << e }
open('output.txt','w').print a == b ? :YES : :NO

a, b = [], []
p STDIN.read.split("\n")[1]

File.open('input.txt').each { |line|
    puts line
}

File.open('input.txt').each { |line|
    open('output.txt','w').puts line
}

a, b = [], []; gets
#test
# gets.strip.each_char.with_index { |c, i| a.push i if c == "1" }
#a[0].step(a[-1], a[1] - a[0]) { |e| b.push << e }
#print a == b ? :YES : :NO


t = gets.to_i

t.times do
  n = gets.to_i
  a = gets.split.map &:to_i
  n.times do |i|
    b = gets.chomp
    a[i] = (a[i] + b.count('D') - b.count('U')) % 10
  end
  puts a*' '
end

gets.to_i.times {
	n = gets.to_i
	k = gets.split.map(&:to_i)
	n.times { |x|
		m, ud = gets.split
		u = ud.chars.count {|x| x == 'U'}
		d = m.to_i -  u
		print (k[x] - u + d)%10, ' '
	}
	puts ''
}

def cypher(n, str, a)
  i = 0
  res = a
  while n-1 >= 0
    if str[i] == "D"
      res += 1
    else
      res -= 1
    end
    n -= 1
    i += 1
  end
  res % 10
end
t = gets.chomp.to_i
final = []

(0..t-1).each do |i|
  inputs = []
  x = 0
  n = gets.chomp.to_i
  arr = gets.chomp
  arr = arr.split(" ").map(&:to_i)

  (0..n-1).each do |j|
    combination = gets.chomp
    combination = combination.split(" ")
    combination.push(arr[x])
    inputs.push(combination)
    x+=1
  end
  final.push(inputs)
end

final.each do |input|
  ans = ""
  input.each do |i|
    x = cypher(i[0].to_i, i[1], i[2])
    ans += "#{x} "
  end

  puts ans.strip
end

#!/usr/bin/env ruby

# https://codeforces.com/contest/1703/problem/C

t = gets.chomp.to_i # tests

(1..t).each do |numtest|
  n = gets.chomp.to_i # wheels
  l = gets.chomp # final state
  state = l.split(' ').map(&:to_i)
  #puts "final state=#{state}"
  (0..n-1).each do |numwheel|
    #puts "numwheel=#{numwheel}"
    m = gets.chomp
    pm = m.split(' ')
    #puts "pm=#{pm}"
    (0..pm[0].to_i-1 ).each do |i|
      #puts "i=#{i}"
      if pm[1][i] == 'U'
        state[numwheel] = state[numwheel] == 0 ? 9 : state[numwheel] - 1
      elsif pm[1][i] == 'D'
        state[numwheel] = state[numwheel] == 9 ? 0 : state[numwheel] + 1
      else
        echo "Problem with character #{i} that is #{pm[1][i]}"
        exit 1;
      end
      #puts "state=#{state}"
    end
  end
  puts state.join(' ')

end


gets.to_i.times do
 n, k = gets.split(' ').map(&:to_i)
 word = gets.chomp

 changes_count = 0
 letter_count = {}

 i = 0
 if k > 1
  while i < k/2 do
   j = 0
   while i+k*j < n-1
    letter_count[word[i+k*j]].nil? ?
     letter_count[word[i+k*j]] = 1 :
     letter_count[word[i+k*j]] += 1

    letter_count[word[k-1-i+k*j]].nil? ?
     letter_count[word[k-1-i+k*j]] = 1 :
     letter_count[word[k-1-i+k*j]] += 1

    j += 1
   end
   changes_count += (n/k)*2 - letter_count.values.max

   letter_count = {}
   i += 1
  end
 end

 if k % 2 == 1
  letter_count = {}
  i = k / 2
  j = 0
  while i + k * j < n
   letter_count[word[i+k*j]].nil? ?
    letter_count[word[i+k*j]] = 1 :
    letter_count[word[i+k*j]] += 1

   j+= 1
  end
  changes_count += (n/k) - letter_count.values.max
 end

 puts changes_count
end

gets.to_i.times do
 n, k = gets.split(' ').map(&:to_i)
 word = gets.chomp

 changes_count = 0
 i = 0

 while i < k/2 do
  letter_count = Hash.new(0)
  j = 0

  while j < n/k
   letter_count[word[i+k*j]] += 1
   letter_count[word[k-1-i+k*j]] += 1
   j += 1
  end

  changes_count += (n/k)*2 - letter_count.values.max
  i += 1
 end

 if k % 2 == 1
  letter_count = Hash.new(0)
  i, j = k/2, 0

  while j < n/k
   letter_count[word[i+k*j]] += 1
   j+= 1
  end

  changes_count += (n/k) - letter_count.values.max
 end

 puts changes_count
end

t = gets.to_i
t.times do
  n, k = gets.split.map(&:to_i)
  s = gets.chomp
  count = 0
  for i in 0...(k / 2) do
    hash = Hash.new(0)
    for j in 0...(n / k) do
      hash[s[i + k * j]] += 1
      hash[s[k - 1 - i + k * j]] += 1
    end
    count += (n / k * 2) - hash.values.max
  end
  if k % 2 == 1
    hash = Hash.new(0)
    for j in 0...(n / k) do
      hash[s[k / 2 + k * j]] += 1
    end
    count += (n / k) - hash.values.max
  end
  puts count
end

gets.to_i.times do
 n, k = gets.split(' ').map(&:to_i)
 word = gets.chomp

 changes_count = 0
 letter_count = {}

 i = 0
 if k > 1
  while i < k/2 do
   j = 0
   while i+k*j < n-1
    letter_count[word[i+k*j]].nil? ?
     letter_count[word[i+k*j]] = 1 :
     letter_count[word[i+k*j]] += 1

    letter_count[word[k-1-i+k*j]].nil? ?
     letter_count[word[k-1-i+k*j]] = 1 :
     letter_count[word[k-1-i+k*j]] += 1

    j += 1
   end
   changes_count += (n/k)*2 - letter_count.values.max

   letter_count = {}
   i += 1
  end
 end

 if k % 2 == 1
  letter_count = {}
  i = k / 2
  j = 0
  while i + k * j < n-1
   letter_count[word[i+k*j]].nil? ?
    letter_count[word[i+k*j]] = 1 :
    letter_count[word[i+k*j]] += 1
   j+= 1
  end
  changes_count += (n/k) - letter_count.values.max
 end

 puts changes_count
end


S = gets.chomp.chars
N = S.size

def f(n)
  return [] if n == 0

  left_pos = []
  left_cnt = 0

  0.upto(N - 1) do |i|
    s = S[i]

    if left_cnt < n && s == '('
      left_pos << i + 1
      left_cnt += 1
    end

    break if left_cnt == n
  end

  right_pos = []
  right_cnt = 0

  (N - 1).downto(0) do |i|
    s = S[i]

    if right_cnt < n && s == ')'
      right_pos.unshift(i + 1)
      right_cnt += 1
    end

    break if right_cnt == n
  end

  if left_cnt < n || right_cnt < n
    return false
  elsif left_pos[-1] > right_pos[0]
    return false
  else
    left_pos + right_pos
  end
end

ok = 0
ng = S.size

while (ok - ng).abs > 1
  n = (ok + ng) / 2

  if f(n)
    ok = n
  else
    ng = n
  end
end

if ok == 0
  puts 0
else
  res = f(ok)

  puts 1
  puts res.size
  puts res.join(' ')
end

def main
  s = gets.chomp.chars
  n = s.size
  # scan '(' from left and ')' from right
  left = 0
  right = n-1
  cnt = 0
  l_a = []
  r_a = []
  while (right > left)
    while left < n && s[left] != '('
      left += 1
    end
    # Here, s[left] == '(' or left == n
    while right >= 0 && s[right] != ')'
      right -= 1
    end
    # Here, s[right] == ')' or right == -1

    if (right <= left) # Meet
      break
    end

    cnt += 1
    l_a << left + 1 # 1-indexed
    r_a << right + 1 # 1-indexed
    left += 1
    right -= 1
  end
  # Here, right <= left. cnt contains the result
  if cnt > 0
    p 1
    p cnt * 2
    a = l_a + r_a
    a.sort!
    print a.join(" ") + "\n"
  else
    p 0
  end
end

main

s = gets.chomp
out = []
i = 0;
j = s.size - 1;
while j > i do
  if s[i] == '(' && s[j] == ')'
    out << [i, j]
    i += 1
    j -= 1
  elsif s[i] == '('
    j -= 1
  elsif s[j] == ')'
    i += 1
  else
    i += 1
    j -= 1
  end
end
if out.size.zero?
  puts 0
else
  puts 1
  out.flatten!.sort!
  puts out.size
  puts out.map{|x| x + 1}.join(' ')
end

def main
  s = gets.chomp.chars
  n = s.size
  # scan '(' from left and ')' from right
  left = 0
  right = n-1
  cnt = 0
  l_a = []
  r_a = []
  while (right > left)
    while left < n && s[left] != '('
      left += 1
    end
    # Here, s[left] == '(' or left == n
    while right >= 0 && s[right] != ')'
      right -= 1
    end
    # Here, s[right] == ')' or right == -1

    if (right <= left) # Meet
      break
    end

    cnt += 1
    l_a << left + 1 # 1-indexed
    r_a << right + 1 # 1-indexed
    left += 1
    right -= 1
  end
  # Here, right <= left. cnt contains the result
  if cnt > 0
    p 1
    p cnt * 2
    print (l_a + r_a).join(" ") + "\n"
  else
    p 0
  end
end

main


p = gets.chomp
ia = Array.new()
prev = 0
p.each_byte{|a|
  b = sprintf("%08b", a).reverse.to_i(2)
  c = (prev - b) % 256
  ia.push(c)
  prev = b
}
ia.each{|i|
  puts i
}

#!/usr/bin/ruby

def readNextValues
  gets.split.map {|x| x.to_i}
end

line = gets.chomp
prev_byte = 0

line.each_byte do |b|
  bin = sprintf("%08b", b)
  val = bin.reverse.to_i(2)

  bin2 = sprintf("%08b", prev_byte)
  step2 = bin2.reverse.to_i(2)

  n = (step2 - val) % 256
  puts n

  prev_byte = b
end

s = STDIN.gets.strip
s = s.bytes.to_a
s.collect!{|char| char.to_s(2)}
s.collect! do |str|
    str = Array.new(8-str.size, "0").join + str
end
result = 0
s.each do |str|
   temp = str.reverse.to_i(2)
   p (result - temp) % 256
   result = temp
end

s = gets.strip
a = 0
s.each_char do |c|
  b = c.bytes.to_a[0].to_s(2)
  b = "0" * (8-b.size) + b if b.size < 8
  n = 0
  p = 1
  b.each_char do |cc|
    n += p if cc == "1"
    p *= 2
  end
  p ((a - n) % 256)
  a = n
end

s=gets.chomp
pre=0
s.bytes.each{|b|post=("%08b"%b).reverse.to_i(2);puts (pre-post)%256;pre=post}

def to_bin n
	str=""

	while n!=0
		str+=(n%2).to_s
		n/=2
	end

	str+"0"*(8-str.length)
end

def to_ten bin
	pos=bin.length-1
	pow=0

	ans=0
	while pos>-1
		ans+=(bin[pos].to_i)*2**pow

		pow+=1
		pos-=1
	end

	ans
end

line=gets.strip

start=0
data=[]
line.split(//).each{|c|
	code=to_ten(to_bin(c.ord))

	data << (start-code)%256
	start=code
}

puts data

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

def revbin(c)
  c.ord.to_s(2).rjust(8, '0').reverse.to_i(2)
end
M = 256

s = $stdin.gets.chomp
s.chars.inject(0) do |acc, c|
  n = revbin c
  puts ((acc - n) % M)
  n
end

p = gets.chomp
prev = 0
p.each_byte{|l|
  cur = l.ord.to_s(2)
  cur = "0"*(8 - cur.length)+cur
  cur = cur.reverse.to_i(2)
  res = (prev - cur) % 256
  prev = cur
  puts res
}

a = []
n = gets.to_s.chomp
a = n.split("").map(&:to_s)
n = 0
j = 0
for i in a do
  n = i.ord.to_s(2).rjust(8,"0").reverse.to_i(2)
  puts (j-n) % 256
  j = n
end

def gao(_)
    ('%08b' % _).reverse.to_i(2)
end

s = gets.chomp
x = 0
s.each_byte do |b|
    y = (gao(x) - gao(b)) % 256
    p y
    x = gao((gao(x) - y) % 256)
end

s=gets.chomp
x=0
s.each_byte{|c|
	y=("%08b"%c).reverse.to_i(2);
	p x-y&255
	x=y
}

s = gets.bytes

def d(x)
  xs = x.to_s(2)
  xs.insert(0,'0') while xs.size < 8
  4.times { |i| xs[7-i], xs[i] = xs[i], xs[7-i] }
  xs.to_i(2)
end

s.size.pred.times do |i|
  x = i.zero? ? 0 : s[i-1]
  y = s[i]
  puts (d(x) - d(y)) % 256
end

s = gets.chomp
v = 0
s.each_byte do |c|
  x1 = ("%08b"%v).reverse.to_i(2)
  r = ("%08b"%c).reverse.to_i(2)
  x2 = (x1 - r + 256)%256

  p x2
  v = c
end

str=gets.chomp;
v=0;
str.each_byte do |c|
	p (v-("%08b"%c).reverse.to_i(2)+256)%256;
	v=("%08b"%c).reverse.to_i(2);
end

#!/usr/bin/ruby
while l = STDIN.gets
  prev = 0
  l.chomp.each_byte do |c|
    str = c.to_s(2)
    while str.size < 8
      str = "0" + str
    end
    str.reverse!
    v = (prev - str.to_i(2)) % 256
    prev = str.to_i(2)
    p v
  end
end

# def gray_code(n)
	# a = ['0', '1']
	# until a[0].length == n do
		# a = a.map{|i| '0' + i} + a.reverse.map{|i| i + '1'}
	# end
	# return a
# end

# puts gray_code(3)

# require 'set'
# visited = Set.new
# Dir.chdir ".."
# stack = Array.new
# stack.push("mine")
# until stack.length == 0 do
	# dir = false
	# Dir.chdir stack.pop

	# puts Dir.pwd
	# Dir["*"].each do |f|
		# print "File: ", f, "\n" if File.file?(f)
		# if (File.directory?(f) && visited.include?(Dir.pwd + "/" + f) == false) then
			# print "Directory: ", f, "\n"
			# stack.push(f) if File.directory?(f)
			# dir = true
			# break
		# end
	# end
	# if dir == false then
		# visited.add(Dir.pwd)
		# Dir.chdir ".."
	# end
	# puts Dir.pwd
# end
# puts "\nCompleted"

inp = STDIN.gets.chomp
start = 0
inp.each_byte do |ch|
	bin = ch.to_s(2).rjust(8, '0').reverse.to_i(2).to_s(10).to_i
	puts (start - bin) % 256
	start = bin
end

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

STR=gets.chomp
last=0
siz=STR.bytes.to_a.size
please=(siz+3)/4-2
STR.each_byte.with_index{|e,i|
	c = e
	c = (c & 0x55) << 1 | (c & 0xaa) >> 1
	c = (c & 0x33) << 2 | (c & 0xcc) >> 2
	c = (c & 0x0f) << 4 | (c & 0xf0) >> 4
	last2 = c
	c = (last-c)&0xff
	last = last2
	p c&0xff
}

__END__
[cesspool.c]
unsigned int lastout = 0;
c = lastout - a[i];
lastout = c;
c = (c & 0x0f) << 4 | (c & 0xf0) >> 4;
c = (c & 0x33) << 2 | (c & 0xcc) >> 2;
c = (c & 0x55) << 1 | (c & 0xaa) >> 1;
putchar(c);

#!/usr/bin/ruby
while l = STDIN.gets
  prev = 0
  l.each_byte do |c|
    str = c.to_s(2)
    while str.size < 8
      str = "0" + str
    end
    str.reverse!
    v = (prev - str.to_i(2)) % 256
    prev = str.to_i(2)
    p v
  end
end

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

STR=STDIN.read
last=0
siz=STR.bytes.to_a.size
please=(siz+3)/4-2
STR.each_byte.with_index{|e,i|
	c = e
	c = (c & 0x55) << 1 | (c & 0xaa) >> 1
	c = (c & 0x33) << 2 | (c & 0xcc) >> 2
	c = (c & 0x0f) << 4 | (c & 0xf0) >> 4
	last2 = c
	c = (last-c)&0xff
	last = last2
	p c&0xff
}

__END__
[cesspool.c]
unsigned int lastout = 0;
c = lastout - a[i];
lastout = c;
c = (c & 0x0f) << 4 | (c & 0xf0) >> 4;
c = (c & 0x33) << 2 | (c & 0xcc) >> 2;
c = (c & 0x55) << 1 | (c & 0xaa) >> 1;
putchar(c);

s = STDIN.gets
s = s.bytes.to_a
s.collect!{|char| char.to_s(2)}
s.collect! do |str|
    str = Array.new(8-str.size, "0").join + str
end
result = 0
s.each do |str|
   temp = str.reverse.to_i(2)
   p (result - temp) % 256
   result = temp
end

s = STDIN.gets
s = s.bytes.to_a
s.collect!{|char| char.to_s(2)}
s.collect! do |str|
    str = Array.new(8-str.size, "0").join + str
end
result = 0
s.push
s.each do |str|
   temp = str.reverse.to_i(2)
   p (result - temp) % 256
   result = temp
end


n = gets.to_i

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

c = Hash.new(0)

d = Rational(5,6)
#puts 4

h = 0
k = 0

for i in 0...n
  if a[i]==0
    if b[i]==0
      k=k+1
    end
    next
  end
  d = Rational((-b[i]), a[i])
  #puts d
  c[d] = c[d] + 1
  #puts c[d]
end

f = c.values

f.each{ |a| h = (h>a)?h:a}

puts h+k

if File.exists?("input")
  $stdin = File.open("input")
  $stdout = File.open("output","w")
end

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

=begin
int gcd(int a, int b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
=end

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

#c = d*a+b
#c needs to have 0s i.e. c = 0
# d*a = c-b = 0-b
# d = -b/a

hash=Hash.new(0)

zerocount=0
totcount=0

(0..n-1).each do |i|
	mya = a[i]
	myb = b[i]

	if(myb==0)
		if(mya==0)
			totcount+=1
		end
		zerocount+=1
		next
	end

	if(mya==0)
		next
	end

	mygcd = gcd(mya,myb)

	mya/=mygcd
	myb/=mygcd

	hash[[mya,myb]]+=1
end

if hash.empty?
	puts zerocount
else
	puts [hash.values.max+totcount,zerocount].max
end

n = gets.to_i

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

c = Hash.new(0)

d = Rational(5,6)
#puts 4

for i in 0...n
  if a[i]==0
    next
  end
  d = Rational((-b[i]), a[i])
  #puts d
  c[d] = c[d] + 1
  #puts c[d]
end

f = c.values

h = 0

f.each{ |a| h = (h>a)?h:a}

puts h

if File.exists?("input")
  $stdin = File.open("input")
  $stdout = File.open("output","w")
end

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

=begin
int gcd(int a, int b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
=end

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

#c = d*a+b
#c needs to have 0s i.e. c = 0
# d*a = c-b = 0-b
# d = -b/a

hash=Hash.new(0)

totcount=0

(0..n-1).each do |i|
	mya = a[i]
	myb = b[i]

	if(myb==0)
		totcount+=1
		next
	end

	if(mya==0)
		next
	end

	mygcd = gcd(mya,myb)

	mya/=mygcd
	myb/=mygcd

	hash[[mya,myb]]+=1
end

if hash.empty?
	puts totcount
else
	puts hash.values.max+totcount
end


N = gets.to_i
s = gets.chomp
t = gets.chomp
ans = []
N.times do |i|
    next if s[i] == t[i]
    j = ((i+1)...N).find{|k| s[k] == t[i]}
    if j
        (j-1).downto(i) do |k|
            ans.push(k+1)
            s[k, 2] = s[k, 2].reverse
        end
    else
        puts -1; exit
    end
end
puts ans.length
puts ans.join(' ') if ans.length > 0

def solution
  n = read_int
  s = read_string
  t = read_string

  if s.chars.sort != t.chars.sort
    puts "-1"
    return
  end

  tpos = Hash.new { |h, k| h[k] = [] }
  t.chars.each.with_index{ |c,i| tpos[c] << i }

  ss = {}
  s.chars.each.with_index{ |c, i| ss[i] = c }

  moves = []

  n.times do |i|
    next if ss[i] == t[i]

    j = (i+1...s.size).find{|k| ss[k] == t[i]}

    [*(i+1)..j].reverse.each do |k|
      moves << k
      ss[k], ss[k-1] = ss[k-1], ss[k]
    end
  end

  puts moves.size
  puts moves.join(' ')

end

def read_int
  gets.to_i
end

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

def read_string
  gets.chomp
end

solution unless ENV['TEST__MODE']

n = gets.to_i
s = gets.strip
t = gets.strip

def swp(str, i)
  c=str[i]
  str[i]=str[i+1]
  str[i+1]=c
end

ans = []
(n-1).downto(0).each do |ti|
  next if s[ti]==t[ti]
  si=ti-1
  si-=1 while si>=0 && s[si]!=t[ti]
  if si==-1
    puts "-1"
    exit 0
  end
  si.upto(ti-1).each do |i|
    swp(s, i)
    ans << (i+1)
  end
end

puts ans.size
puts ans.join(" ")

gets
s = gets.chomp.split('')
t = gets.chomp.split('')

container = {}
s.each do |item|
  if container.key?(item)
    container[item] += 1
  else
    container[item] = 1
  end
end

t.each do |item|
  container[item] -= 1 if container.key?(item)
end

if container.values.any? { |e| e != 0 }
  puts '-1'
else
  swaps = []
  t.each.with_index do |item, i|
    if item != s[i]
      j = s.rindex(item)
      k = j - 1
      while k != i - 1
        s[k], s[k + 1] = s[k + 1], s[k]
        swaps.push(k + 1)
        k -= 1
      end
    end
  end
  puts swaps.length
  puts swaps.join(' ') unless swaps.empty?
end

gets
s = gets.chomp.split('')
t = gets.chomp.split('')

container = {}
s.each do |item|
  if container.key?(item)
    container[item] += 1
  else
    container[item] = 1
  end
end

t.each do |item|
  container[item] -= 1 if container.key?(item)
end

if container.values.any? { |e| e != 0 }
  puts '-1'
else
  swaps = []
  s.each.with_index do |item, i|
    if item != t[i]
      j = t.rindex(item)
      k = j - 1
      while k != i - 1
        t[k], t[k + 1] = t[k + 1], t[k]
        swaps.push(k)
        k -= 1
      end
    end
  end
  puts swaps.length
  puts swaps.join(' ') unless swaps.empty?
end

gets
s = gets.chomp.split('')
t = gets.chomp.split('')

container = {}
s.each do |item|
  if container.key?(item)
    container[item] += 1
  else
    container[item] = 1
  end
end

t.each do |item|
  container[item] -= 1 if container.key?(item)
end

if container.values.any? { |e| e != 0 }
  puts '-1'
else
  swaps = []
  s.each.with_index do |item, i|
    if item != t[i]
      j = t.rindex(item)
      k = j - 1
      while k != i - 1
        t[k], t[k + 1] = t[k + 1], t[k]
        swaps.push(k + 1)
        k -= 1
      end
    end
  end
  puts swaps.length
  puts swaps.join(' ') unless swaps.empty?
end

n = gets.to_i
s = gets.strip
t = gets.strip

def swp(str, i)
  c=str[i]
  str[i]=str[i+1]
  str[i+1]=c
end

ans = []
(n-1).downto(0).each do |ti|
  next if s[ti]==t[ti]
  si=ti-1
  si-=1 while si>=0 && s[si]!=t[ti]
  if si==-1
    puts "-1"
    exit 0
  end
  si.upto(ti-1).each do |i|
    swp(s, i)
    ans << i
  end
end

puts ans.size
puts ans.join(" ")


n = gets.chomp.to_i
arStr = Array.new(n).map do |str|
    str = gets.chomp
end
i = 0
while i != n
    if arStr[i][0..4] != 'miao.' && arStr[i][-5..-1] == 'lala.'
        puts "Freda's"
    elsif arStr[i][0..4] == 'miao.' && arStr[i][-5..-1] != 'lala.'
        puts "Rainbow's"
    else
        puts "OMG>.< I don't know!"
    end
    i += 1
end

reF = Regexp.new( /lala\.$/ )
reR = Regexp.new( /^miao\./ )

gets.to_i.times do
	line = gets.chomp
	if ( reF =~ line && reR !~ line )
		puts "Freda's"
	elsif ( reR =~ line && reF !~ line )
		puts "Rainbow's"
	else
		puts "OMG>.< I don't know!"
	end
end

ans = []
gets.to_i.times do
  s = gets.to_s.chomp
  if s[0..4] == 'miao.' && s[-5..-1] != 'lala.' then
    ans << 'Rainbow\'s'
  elsif s[0..4] != 'miao.' && s[-5..-1] == 'lala.' then
    ans << 'Freda\'s'
    else
      ans << 'OMG>.< I don\'t know!'
  end
end
puts ans

n = gets.to_i
n.times do
    s = gets.gsub /\r\n|\r|\n/, ''
    is_f, is_r = false, false
    if s.length >= 5
        is_f = s[-5..-1] == 'lala.'
        is_r = s[0...5] == 'miao.'
    end
    if is_f and not is_r then
        puts "Freda's"
    elsif not is_f and is_r then
        puts "Rainbow's"
    else
        puts "OMG>.< I don't know!"
    end
end

gets.to_i.times do
  s = gets
  lala = /.*lala\.$/.match s
  miao = /^miao\..*/.match s
  if( (lala && miao) || (!lala && !miao) )
    puts "OMG>.< I don't know!"
  elsif lala
    puts "Freda's"
  else
    puts "Rainbow's"
  end
end

omg = "OMG>.< I don't know!"
freda = "Freda's"
rainbow = "Rainbow's"
rainbow_begin = /^miao\./
freda_end = /lala\.$/

for _ in 1..gets.to_i
  s = gets.chomp
  if s[rainbow_begin]
    puts(s[freda_end] ? omg : rainbow)
  elsif s[freda_end]
    puts freda
  else
    puts omg
  end
end

n = gets.to_i
n.times do
	s = gets.chomp
	if s.length < 5
		puts "OMG>.< I don't know!"
	else
		R = s[0..4] == "miao."
		F = s[-5..-1] == "lala."
		if R == F
			puts "OMG>.< I don't know!"
		elsif R
			puts "Rainbow's"
		else
			puts "Freda's"
		end
	end
end

#!/usr/bin/ruby

n = gets.to_i

n.times do |i|
  line = gets.chomp
  a = line.match(/^miao\./)
  b = line.match(/lala\.$/)

  if (a and b) or (not a and not b)
    puts "OMG>.< I don't know!"
  elsif line.start_with?("miao.")
    puts "Rainbow's"
  elsif line.end_with?("lala.")
    puts "Freda's"
  end
end

def myfun
n = gets.chomp.to_i
str = Array.new
for i in 1..n
  str[i] = gets.chomp
end

for i in 1..n
  if str[i].index('miao.') == 0 && str[i].rindex('lala.') != str[i].length - 5
    puts "Rainbow's"
  elsif str[i].index('miao.') != 0 && str[i].rindex('lala.') == str[i].length - 5
    puts "Freda's"
   else
     puts "OMG>.< I don't know!"
  end
end
return nil
end

puts myfun

lines = STDIN.read.split("\n")
n = lines[0].to_i

for i in 1..n
  line = lines[i]
  testA = line.rindex('lala.') == line.size - 5
  testB = line.index('miao.') == 0
  if testA && !testB
    puts "Freda's"
    next
  end
  if !testA && testB
    puts "Rainbow's"
    next
  end
  puts "OMG>.< I don't know!"
end

#!/usr/bin/ruby1.9

n = STDIN.readline.to_i
n.times do
	sentence = STDIN.readline[0..-2]
	miao = (sentence[0..4] == 'miao.')
	lala = (sentence[-5..-1] == 'lala.')
	if miao and not lala
		puts "Rainbow's"
	elsif lala and not miao
		puts "Freda's"
	else
		puts "OMG>.< I don't know!"
	end
end

input = STDIN.read.split("\n")
input.shift
input.each do |line|
  r = line[0, 5] == 'miao.'
  f = line[-5..-1] == 'lala.'
  if not r ^ f
    puts 'OMG>.< I don\'t know!'
  elsif r
      puts 'Rainbow\'s'
  else
    puts 'Freda\'s'
  end
end

n = gets.chomp.to_i
(1..n).each do
    str = gets.chomp
    r = (str[(0..4)] == "miao.")
    f = (str[(-5..-1)] == "lala.")
    puts "OMG>.< I don't know!" if ((f && r) || (!f && !r))
    puts "Freda's" if f && !r
    puts "Rainbow's" if r && !f
end

class A
  def initialize
    n = gets.chomp.to_i

    freda = 0
    rain = 0

    answer = []

    n.times do
      text = gets.chomp

      if text =~ /lala\.$/ && (text =~ /^miao\./).nil?
        answer << "Freda's"
      elsif text =~ /^miao\./ && (text =~ /lala\.$/).nil?
        answer << "Rainbow's"
      else
        answer << "OMG>.< I don't know!"
      end
    end

    puts answer
  end
end

a = A.new

a=gets.chomp.to_i
a.times do
temp=gets.chomp
l=temp.length
if temp[0..4]=="miao." && temp[l-5..l-1]=="lala."
 puts "OMG>.< I don't know!"
elsif temp[0..4]=="miao."
 puts "Rainbow's"
elsif temp[l-5..l-1]=="lala."
 puts "Freda's"
else
puts  "OMG>.< I don't know!"
end
end

n  = gets.to_i
(1..n).each {
  s = gets.chomp
  f = s.end_with?("lala.")
  r = (s[0..4] == "miao.")
  if f ^ r
    if f
      puts "Freda's"
    else
      puts "Rainbow's"
    end
  else
    puts "OMG>.< I don't know!"
  end
}

gets.to_i.times do
	input = gets.chomp

	t = ( ( input =~(/.*lala\.$/)) )
	o = ( ( input =~(/^miao\..*/)) )

	if (o and t) or (!o and !t)
		puts "OMG>.< I don't know!"
	elsif o
		puts "Rainbow's"
	elsif t
		puts "Freda's"
	end
end

n = gets.to_i
(0...n).each do
    s = gets.chomp
    if s.size < 5
        puts "OMG>.< I don't know!"
    elsif s[0,5] == "miao." and s[s.size-5,5] != "lala."
        puts "Rainbow's"
    elsif s[0,5] != "miao." and s[s.size-5,5] == "lala."
        puts "Freda's"
    else
        puts "OMG>.< I don't know!"
    end
end

n = gets.chomp.to_i
arStr = Array.new(n).map do |str|
    str = gets.chomp
end
i = 0
while i != n
    if arStr[i][0..5] != 'miao.' && arStr[i][-5..-1] == 'lala.'
        puts "Freda's"
    elsif arStr[i][0..5] == 'miao.' && arStr[i][-5..-1] != 'lala.'
        puts "Rainbow's"
    else
        puts "OMG>.< I don't know!"
    end
    i += 1
end

n = gets.chomp.to_i
arStr = Array.new(n).map do |str|
    str = gets.chomp
end
i = 0
while i != n
    if arStr[i][0..5] == 'miao.' && arStr[i][-6...-1] != 'lala.'
        puts "Rainbow's"
    elsif arStr[i][0..5] != 'miao.' && arStr[i][-6...-1] == 'lala.'
        puts "Freda's"
    else
        puts "OMG>.< I don't know!"
    end
    i += 1
end

n = gets.chomp.to_i
arStr = Array.new(n).map do |str|
    str = gets.chomp
end
i = 0
while i != n
    if arStr[i][0..5] == 'miao.' && arStr[i][-6...-1] != 'lala.'
        puts "Freda's"
    elsif arStr[i][0..5] != 'miao.' && arStr[i][-5...-1] == 'lala.'
        puts "Rainbow's"
    else
        puts "OMG>.< I don't know!"
    end
    i += 1
end

n = gets.chomp.to_i
arStr = Array.new(n).map do |str|
    str = gets.chomp
end
i = 0
while i != n
    if arStr[i][0..5] != 'miao.' && arStr[i][-6...-1] == 'lala.'
        puts "Freda's"
    elsif arStr[i][0..5] == 'miao.' && arStr[i][-6...-1] != 'lala.'
        puts "Rainbow's"
    else
        puts "OMG>.< I don't know!"
    end
    i += 1
end

n = gets.chomp.to_i
arStr = Array.new(n).map do |str|
    str = gets.chomp
end
i = 0
while i != n
    if arStr[i][0..5] != 'miao.' && arStr[i][-6..-1] == 'lala.'
        puts "Freda's"
    elsif arStr[i][0..5] == 'miao.' && arStr[i][-6..-1] != 'lala.'
        puts "Rainbow's"
    else
        puts "OMG>.< I don't know!"
    end
    i += 1
end

n = gets.chomp.to_i
arStr = Array.new(n).map do |str|
    str = gets.chomp
end
i = 0
while i != n
    if arStr[i][0..5] == 'miao.' && arStr[i][-5...-1] != 'lala.'
        puts "Freda's"
    elsif arStr[i][0..5] != 'miao.' && arStr[i][-5...-1] == 'lala.'
        puts "Rainbow's"
    else
        puts "OMG>.< I don't know!"
    end
    i += 1
end

def myfun
n = gets.chomp.to_i
str = Array.new
for i in 1..n
  str[i] = gets.chomp
  puts i
end

for i in 1..n
  if str[i].index('miao.') == 0 && str[i].rindex('lala.') != str[i].length - 5
    puts "Rainbow's"
  elsif str[i].index('miao.') != 0 && str[i].rindex('lala.') == str[i].length - 5
    puts "Freda's"
   else
     puts "OMG>.< I don't know!"
  end
end
return nil
end

puts myfun

#!/usr/bin/ruby1.9

n = STDIN.readline.to_i
n.times do
	sentence = STDIN.readline.strip
	miao = (sentence[0..4] == 'miao.')
	lala = (sentence[-5..-1] == 'lala.')
	if miao and not lala
		puts "Rainbow's"
	elsif lala and not miao
		puts "Freda's"
	else
		puts "OMG>.<I don't know!"
	end
end

#!/usr/bin/ruby1.9

n = STDIN.readline.to_i
n.times do
	sentence = STDIN.readline.strip
	miao = (sentence[0..4] == 'miao.')
	lala = (sentence[-5..-1] == 'lala.')
	if miao and not lala
		puts "Rainbow's"
	elsif lala and not miao
		puts "Freda's"
	else
		puts "OMG>.< I don't know!"
	end
end

n = gets.chomp.to_i
(1..n).each do
    str = gets.chomp
    r = (str[(0..4)] == "miao.")
    f = (str[(-5..-1)] == "lala.")
    puts "OMG>.< I don't know!" if ((f && r) || (!f && !r))
    puts "Freda's" if f
    puts "Rainbow's" if r
end

n = gets.chomp.to_i
(1..n).each do
    str = gets.chomp
    r = (str[(0..5)] == "miao.")
    f = (str[(-5..-1)] == "lala.")
    puts "OMG>.< I don't know!" if ((f && r) || (!f && !r))
    puts "Freda's" if f
    puts "Rainbow's" if r
end

n = gets.chomp.to_i
(1..n).each do
    str = gets.chomp
    r = (str[(-5..-1)] == "miao.")
    f = (str[(-5..-1)] == "lala.")
    puts "OMG>.< I don't know!" if ((f && r) || (!f && !r))
    puts "Freda's" if f
    puts "Rainbow's" if r
end

class A
  def initialize
    n = gets.chomp.to_i

    freda = 0
    rain = 0

    answer = []

    n.times do
      text = gets.chomp

      if text =~ /lala\.$/ && (text =~ /miao\./).nil?
        answer << "Freda's"
      elsif text =~ /^miao\./ && (text =~ /lala\./).nil?
        answer << "Rainbow's"
      else
        answer << "OMG>.< I don't know!"
      end
    end

    puts answer
  end
end

a = A.new

class A
  def initialize
    n = gets.chomp.to_i

    freda = 0
    rain = 0

    answer = []

    n.times do
      text = gets.chomp

      if text =~ /lala\./ && (text =~ /miao\./).nil?
        answer << "Freda's"
      elsif text =~ /miao\./ && (text =~ /lala\./).nil?
        answer << "Rainbow's"
      else
        answer << "OMG>.< I don't know!"
      end
    end

    puts answer
  end
end

a = A.new

class A
  def initialize
    n = gets.chomp.to_i

    freda = 0
    rain = 0

    answer = []

    n.times do
      text = gets.chomp

      if text =~ /lala\./
        answer << "Freda's"
      elsif text =~ /mial\./
        answer << "Rainbow's"
      else
        answer << "OMG>.< I don't know!"
      end
    end

    puts answer
  end
end

a = A.new


x1, y1 = STDIN.readline.split.map {|s| s.to_i }
x2, y2 = STDIN.readline.split.map {|s| s.to_i }

n = STDIN.readline.to_i
count = 0

n.times do
  a, b, c = STDIN.readline.split.map {|s| s.to_i }
  if ((a*x1 + b*y1 + c) * (a*x2 + b*y2 + c) < 0)
      count += 1
  end
end

puts count

x1, y1 = gets.split.collect{|i| i.to_i}
x2, y2 = gets.split.collect{|i| i.to_i}
n = gets.to_i
ans = 0
for i in 0...n
    a, b, c = gets.split.collect{|i| i.to_i}
    ans += 1 if (a*x1+b*y1+c)*(a*x2+b*y2+c) < 0
end
puts ans

x1, y1 = STDIN.readline.split.map {|s| s.to_i }
x2, y2 = STDIN.readline.split.map {|s| s.to_i }
if x2 < x1
  x1, x2 = x2, x1
  y1, y2 = y2, y1
end
n = STDIN.readline.to_i
count = 0

n.times do
  a, b, c = STDIN.readline.split.map {|s| s.to_i }
  if b == 0
    if (a*x1 < -c and -c < a*x2) or (a*x2 < -c and -c < a*x1)
      count += 1
    end
  else
    y3 = -a*x1 - c
    y4 = -a*x2 - c
    if (y3 < b*y1 and b*y2 < y4) or (b*y1 < y3 and y4 < b*y2)
      count += 1
    end
  end
end

puts count

x1, y1 = gets.split.map(&:to_i)
x2, y2 = gets.split.map(&:to_i)
n = gets.to_i
r = 0
n.times do
  a, b, c = gets.split.map(&:to_i)
  r += 1 if (a * x1 + b * y1 + c) * (a * x2 + b * y2 + c) < 0
end
puts r

def getints
  gets.split.map &:to_i
end
x1,y1 = getints
x2,y2 = getints
n, = getints
s = 0
n.times do
  a,b,c = getints
  s += 1 if (a*x1+b*y1+c) * (a*x2+b*y2+c) < 0
end
puts s

def getints
  gets.split.map &:to_i
end
x1,y1 = getints
x2,y2 = getints
n, = getints
s = 0
n.times do
  a,b,c = getints
  s += 1 if (a*x1+b*y1-c) * (a*x2+b*y2-c) < 0
end
puts s

x1, y1 = STDIN.readline.split.map {|s| s.to_i }
x2, y2 = STDIN.readline.split.map {|s| s.to_i }
if x2 < x1
  x1, x2 = x2, x1
  y1, y2 = y2, y1
end
n = STDIN.readline.to_i
count = 0

n.times do
  a, b, c = STDIN.readline.split.map {|s| s.to_i }
  if b == 0
    if a*x1 < -c and -c < a*x2
      count += 1
    end
  else
    y3 = -a*x1 - c
    y4 = -a*x2 - c
    if (y3 < b*y1 and b*y2 < y4) or (b*y1 < y3 and y4 < b*y2)
      count += 1
    end
  end
end

puts count


EPS = 1e-8

def find_zero(t0, t1, depth=0, &block)
  y0 = yield(t0)
  y1 = yield(t1)

  return nil if y1 > EPS
  return t0 if y0 == 0
  return t1 if y1 == 0

  100.times do
    t2 = (t0+t1)/2
    y2 = yield(t2)
    return t2 if y2 == 0

    if y2 > 0
      t0 = t2
      y0 = y2
    else
      t1 = t2
      y1 = y2
    end
  end

  (t0+t1)/2
end

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

n = gets.to_i
a = []
(n+1).times{ a << gets.split.map(&:to_f)}
vp, vs = gets.split.map(&:to_f)
xp, yp, zp = pos = gets.split.map(&:to_f)

t = 0.0
n.times do |i|
  x0, y0, z0 = a[i]
  x1, y1, z1 = a[i+1]

  du = distance(a[i], a[i+1])/vs
  vx = (x1-x0)/du
  vy = (y1-y0)/du
  vz = (z1-z0)/du

  tm = find_zero(0, du) do |dt|
    distance([x0+dt*vx, y0+dt*vy, z0+dt*vz], [xp, yp, zp]) - vp*(t + dt)
  end

  if tm
    puts "YES"
    puts t+tm
    puts [x0+tm*vx, y0+tm*vy, z0+tm*vz]*" "
    exit
  end

  t += du
end
puts "NO"

def solve(t0, t1)
  y0 = yield(t0)
  y1 = yield(t1)

  return nil if y1 > 1e-8
  return t0 if y0 == 0
  return t1 if y1 == 0

  99.times do
    t2 = (t0 + t1) / 2
    y2 = yield(t2)

    if y2 > 0
      t0 = t2
      y0 = y2
    elsif y2 < 0
      t1 = t2
      y1 = y2
    else
      return t2
    end
  end

  (t0 + t1) / 2
end

def dist(a, b)
  (0..2).inject(0){|s, i| s + (a[i] - b[i]) ** 2} ** 0.5
end

n = gets.to_i
a = (0..n).map{ gets.split.map(&:to_f) }
vp, vs = gets.split.map(&:to_f)
xp, yp, zp = pos = gets.split.map(&:to_f)

t = 0.0
n.times do |i|
  x0, y0, z0 = a[i]
  x1, y1, z1 = a[i+1]

  du = dist(a[i], a[i+1]) / vs
  vx = (x1 - x0) / du
  vy = (y1 - y0) / du
  vz = (z1 - z0) / du

  r = solve(0, du) { |dt|
    dist([x0 + dt * vx, y0 + dt * vy, z0 + dt * vz], [xp, yp, zp]) - vp * (t + dt)
  }

  if r
    puts "YES"
    puts t + r
    puts [x0 + r * vx, y0 + r * vy, z0 + r * vz] * " "
    exit
  end

  t += du
end
puts "NO"

def distance_lp(alpha, beta, pos)
  return distance(alpha, pos) if alpha == beta

  s1 = alpha.zip(beta,pos).inject(0.0){|r,(a,b,po)| r+(a+b-po)*(b-a)}
  s2 = alpha.zip(beta,pos).inject(0.0){|r,(a,b,po)| r+(b-a)*(b-a)}

  s = s1/s2
  if s < 0
    s = 0
  elsif s > 1
    s = 1
  end

  alpha.zip(beta,pos).inject(0.0){|r,(a,b,po)| r + (s*a + (1-s)*b - po)**2} **0.5
end

def find_zero(t0, t1)
  y0 = yield(t0)
  return t0 if y0 == 0
  y1 = yield(t1)
  return t1 if y1 == 0

  t2 = (t0+t1)/2
  y2 = yield(t2)
  return t2 if y2 == 0
  return nil if y2 > 0 && y1 > 0 && y0 > 0
  return nil if y2 > y1 && y2 > y0

  while t1-t0 > 1e6
    t3 = (t0+t2)/2
    y3 = yield(t3)
    return t3 if y3 == 0
  end
end

def find_zero_s(t0, t1, depth=0, &block)
  y0 = yield(t0)
  y1 = yield(t1)

  20.times do
    t2 = (t0+t1)/2
    y2 = yield(t2)

    if y2 > 0
      t0 = t2
      y0 = y2
    else
      t1 = t2
      y1 = y2
    end

    #break if (y0 - y1).abs < 1e7
  end

  (t0+t1)/2
end

EPS = 1e-8
DZ = 128
def find_zero(t0, t1, depth=0, &block)
  return t0 if yield(t0) <= EPS
  return t1 if yield(t1) <= EPS

  return (t0+t1)/2 if depth == 2
  return find_zero_s(t0, t1, &block) if depth >= 1

  yz = nil
  0.upto(DZ) do |d|
    dt = (t1-t0)/DZ.to_f
    y = yield(t0 + d*dt)
    return (t0 + d*dt) if y == 0
    if y < 0
      return find_zero_s(t0+(d-1)*dt, t0+d*dt, &block)
    elsif y <= EPS
      return find_zero(t0+(d-1)*dt, t0+d*dt, depth+1, &block)
    end
  end
  return nil
end

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

n = gets.to_i
a = []
(n+1).times{ a << gets.split.map(&:to_f)}
vp, vs = gets.split.map(&:to_f)
xp, yp, zp = pos = gets.split.map(&:to_f)

t = 0.0
n.times do |i|
  x0, y0, z0 = a[i]
  x1, y1, z1 = a[i+1]

  du = distance(a[i], a[i+1])/vs
  vx = (x1-x0)/du
  vy = (y1-y0)/du
  vz = (z1-z0)/du

  if distance_lp(a[i], a[i+1], pos) - (t+du)*vp < 1e5

    tm = find_zero(0, du) do |dt|
      distance([x0+dt*vx, y0+dt*vy, z0+dt*vz], [xp, yp, zp]) - vp*(t + dt)
    end

    if tm
      puts "YES"
      puts t+tm
      puts [x0+tm*vx, y0+tm*vy, z0+tm*vz]*" "
      exit
    end
  end

  t += du
end
puts "NO"

def find_zero(t0, t1)
  y0 = yield(t0)
  return t0 if y0 == 0
  y1 = yield(t1)
  return t1 if y1 == 0

  t2 = (t0+t1)/2
  y2 = yield(t2)
  return t2 if y2 == 0
  return nil if y2 > 0 && y1 > 0 && y0 > 0
  return nil if y2 > y1 && y2 > y0

  while t1-t0 > 1e6
    t3 = (t0+t2)/2
    y3 = yield(t3)
    return t3 if y3 == 0
  end
end

def find_zero_s(t0, t1, depth=0, &block)
  y0 = yield(t0)
  y1 = yield(t1)

  20.times do
    t2 = (t0+t1)/2
    y2 = yield(t2)

    if y2 > 0
      t0 = t2
      y0 = y2
    else
      t1 = t2
      y1 = y2
    end
  end

  (t0+t1)/2
end

DZ = 100
def find_zero(t0, t1, depth=0, &block)
  return (t0+t1)/2 if depth == 2

  yz = nil
  0.upto(DZ) do |d|
    dt = (t1-t0)/DZ.to_f
    y = yield(t0 + d*dt)
    return (t0 + d*dt) if y == 0
    if y < 0
      return find_zero_s(t0+(d-1)*dt, t0+d*dt, &block)
    elsif y <= 1e-8
      return find_zero(t0+(d-1)*dt, t0+d*dt, depth+1, &block)
    end
  end
  return nil
end

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

n = gets.to_i
a = []
(n+1).times{ a << gets.split.map(&:to_f)}
vp, vs = gets.split.map(&:to_f)
xp, yp, zp = gets.split.map(&:to_f)

t = 0.0
n.times do |i|
  x0, y0, z0 = a[i]
  x1, y1, z1 = a[i+1]

  du = distance(a[i], a[i+1])/vs
  vx = (x1-x0)/du
  vy = (y1-y0)/du
  vz = (z1-z0)/du

  tm = find_zero(0, du) do |dt|
    distance([x0+dt*vx, y0+dt*vy, z0+dt*vz], [xp, yp, zp]) - vp*(t + dt)
  end

  if tm
    puts "YES"
    puts t+tm
    puts [x0+tm*vx, y0+tm*vy, z0+tm*vz]*" "
    exit
  end

  t += du
end
puts "NO"


gets.to_i.times do
    ans = 0
    n,k = gets.split.map(&:to_i)
    while n != 0
        if n%k == 0
            ans += 1
            n /= k
        else
            ans += n%k
            n -= n%k
        end
    end
    puts ans
end

test_cases = gets.chomp.to_i

test_cases.times do |tc|
  n, k = gets.chomp.split(" ").map(&:to_i)

  counter = 0

  while n != 0
    if n % k == 0
      n = n / k
      counter += 1
    else
      rem = n % k
      counter += rem
      n -= rem
    end
  end

  puts(counter)
end

n = gets.chomp.to_i

tests = []

n.times do
  tests.push(gets.split(' ').map {|e| e.to_i})
end

tests.each do |test|
  remainder = 0
  current_num = test[0]
  operations = 0
  while current_num >= test[1] do
    remainder += current_num % test[1]
    current_num = current_num / test[1]
    operations += 1
  end

  operations += remainder + current_num

  puts operations
end


n = gets.chomp.to_i
n.times do
    t = gets.chomp.to_i
    # kakudo = 360  * 10000000000000000000/ t
    # # puts kakudo
    # ama = 360  * 10000000000000000000 % t
    # # puts "YY"
    # # puts ama
    # if ama != 0
    #     puts "NO"
    #     next
    # end
    # hantei = 90  * 10000000000000000000 / kakudo
    # amari = 90  * 10000000000000000000 % kakudo
    # if amari != 0
    #     puts "NO"
    #     next
    # end
    # saigo = (hantei * kakudo) % 10000000000000000000
    hantei = t % 4

    if hantei == 0
        puts "YES"
    else
        puts "NO"
    end
end

require 'set'; require 'prime'; require 'pp'
INF=Float::INFINITY; MOD=10**9+7
t = gets.chomp.to_i
t.times do
  n = gets.chomp.to_i
  if n % 4 == 0
    puts 'YES'
  else
    puts 'NO'
  end
end

t = gets.chomp.to_i
t.times do
	n = gets.chomp.to_i
	puts n % 4 == 0 ? "YES" : "NO"
end

gets.to_i.times { puts gets.to_i.modulo(4).zero? ? "YES" : "NO" }

n = gets.chomp.to_i
n.times {
  arrNum = gets.chomp.to_i
  if arrNum%4 != 0
    puts 'NO'
  else
    puts 'YES'
  end
}

n = gets.chomp.to_i
n.times do
    t = gets.chomp.to_i
    kakudo = 360  * 10000000000000000000/ t.to_f
    # puts kakudo
    ama = 360  * 10000000000000000000 % t
    # puts "YY"
    # puts ama
    if ama != 0
        puts "NO"
        next
    end
    hantei = 90  * 10000000000000000000 / kakudo
    amari = 90  * 10000000000000000000 % kakudo
    if amari != 0
        puts "NO"
        next
    end
    if hantei * kakudo / 10000000000000000000 == 90
        puts "YES"
    else
        puts "NO"
    end
end

n = gets.chomp.to_i
n.times do
    t = gets.chomp.to_i
    # kakudo = 360  * 10000000000000000000/ t
    # # puts kakudo
    # ama = 360  * 10000000000000000000 % t
    # # puts "YY"
    # # puts ama
    # if ama != 0
    #     puts "NO"
    #     next
    # end
    # hantei = 90  * 10000000000000000000 / kakudo
    # amari = 90  * 10000000000000000000 % kakudo
    # if amari != 0
    #     puts "NO"
    #     next
    # end
    # saigo = (hantei * kakudo) % 10000000000000000000
    hantei = n % 4

    if hantei == 0
        puts "YES"
    else
        puts "NO"
    end
end

n = gets.chomp.to_i
n.times do
    t = gets.chomp.to_i
    kakudo = 360  * 10000000000000000000/ t
    # puts kakudo
    ama = 360  * 10000000000000000000 % t
    # puts "YY"
    # puts ama
    if ama != 0
        puts "NO"
        next
    end
    hantei = 90  * 10000000000000000000 / kakudo
    amari = 90  * 10000000000000000000 % kakudo
    if amari != 0
        puts "NO"
        next
    end
    if hantei * kakudo / 10000000000000000000 == 90
        puts "YES"
    else
        puts "NO"
    end
end

n = gets.chomp.to_i
n.times do |i|
    t = gets.chomp.to_i
    kakudo = 360  * 10000000000000000000/ t.to_f
    # puts kakudo
    ama = 360  * 10000000000000000000 % t
    # puts "YY"
    # puts ama
    if ama != 0
        puts "NO"
        next
    end
    hantei = 90  * 10000000000000000000 / kakudo
    amari = 90  * 10000000000000000000 % kakudo
    if amari != 0
        puts "NO"
        next
    end
    if hantei * kakudo / 10000000000000000000 == 90
        puts "YES"
    else
        puts "NO"
    end
end

n = gets.chomp.to_i
n.times do |i|
    t = gets.chomp.to_i
    kakudo = 360  * 1000000000/ t
    hantei = 90  * 1000000000 / kakudo
    if hantei * kakudo / 1000000000 == 90
        puts "YES"
    else
        puts "NO"
    end
end

n = gets.chomp.to_i
n.times do
    t = gets.chomp.to_i
    kakudo = 360  * 10000000000000000000/ t
    # puts kakudo
    ama = 360  * 10000000000000000000 % t
    # puts "YY"
    # puts ama
    if ama != 0
        puts "NO"
        next
    end
    hantei = 90  * 10000000000000000000 / kakudo
    amari = 90  * 10000000000000000000 % kakudo
    if amari != 0
        puts "NO"
        next
    end
    saigo = (hantei * kakudo) % 10000000000000000000
    if hantei * kakudo / 10000000000000000000 == 90 && saigo == 0
        puts "YES"
    else
        puts "NO"
    end
end

n = gets.chomp.to_i
n.times {
  arrNum = gets.chomp.to_i
  if arrNum%2 != 0
    puts 'NO'
  else
    puts 'YES'
  end
}


n= gets.to_i
a = gets.split(" ").map(&:to_i)
count = 0
for i in 1..n-2
	if (a[i]>a[i-1] && a[i]>a[i+1]) || (a[i]<a[i-1] && a[i]<a[i+1])
    	count  +=  1
    end
end
print(count)

n,*a=$<.read.split.map &:to_i
p a.each_cons(3).count{|x,y,z|(x>y&&z>y)||(x<y&&z<y)}

n = gets.to_i
a = gets.split ' '
a = a.collect {|i| i.to_i}
total = 0
for i in 1...n-1
	if a[i] < a[i - 1] && a[i] < a[i + 1]
		total += 1
	elsif a[i] > a[i + 1] && a[i] > a[i - 1]
		total += 1
	end
end
puts total

gets
x1=gets.split.map{|e| e.to_i}
x2=x1.clone
x2.shift
x3=x2.clone
x3.shift
x1=x1.zip(x2,x3)
x1.pop
x1.pop
puts x1.count{|e|
	(e[0]<e[1] && e[1]>e[2]) || (e[0]>e[1] && e[1]<e[2])
}

def extremum(a, b, c)
  a = a.to_i
  b = b.to_i
  c = c.to_i
  if a < b && b > c
    return true
  elsif a > b && b < c
    return true
  else
    return false
  end
end

ans = 0
n = gets.to_i
a = gets.split
for i in (1...n-1) do
  if extremum(a[i - 1], a[i], a[i + 1])
    ans = ans + 1
  end
end
p ans

n = Integer(gets.chomp)

a = gets.chomp
        .split
        .map{ |i| Integer(i) }

print (1...n-1).inject(0){ |res, i|
  ((a[i] > a[i-1] and a[i] > a[i+1]) or (a[i-1] > a[i] and a[i+1] > a[i])) ? res + 1 : res}

n=gets.to_i
a=gets.split ' '
a=a.collect{|i| i.to_i}
sum=0
for i in 1..n-2
if a[i]<a[i-1] && a[i]<a[i+1] || a[i]>a[i-1] && a[i]>a[i+1]
    sum+=1
end
end
print sum

n,*a=gets.split.map &:to_i
p a.each_cons(3).count{|x,y,z|!( (x>y&&z>y)||(x<y&&z<y) )}

n,*a=gets.split.map &:to_i
p a.each_cons(3).count{|x,y,z|(x>y&&z>y)||(x<y&&z<y)}

gets
x1=gets.split.map{|e| e.to_i}
x2=x1.clone
x2.shift
x3=x2.clone
x3.shift
x1=x1.zip(x2,x3)
x1.pop
x1.pop
ans=x1.index{|e|
	e[0]<e[1] && e[1]>e[2]
}
if ans
	puts ans+2
else
	puts 0
end

n=gets.to_i
a=gets.split ' '
a=a.collect{|i| i.to_i}
sum=0
for i in 1..n-2
if a[i]<a[i-1] and a[i]<a[i+1] or a[i]>a[i-1] and a[i]>a[i+1]
    sum+=1
end
end
print sum

n=gets.to_i
a=gets.split ' '
a=a.collect{|i| i.to_i}
sum=0
for i in 2..n-2
if a[i]<a[i-1] and a[i]<a[i+1] or a[i]>a[i-1] and a[i]>a[i+1]
    sum+=1
end
end
print sum


n,m,k=gets.split.map &:to_i;z=[1]*k+[n]+[n+1]*(k-1);if m>n-(k>1?1:2) then z<<2*n-1 end;p z.size;puts z.join' '


n, k = gets.split.map(&:to_i)
s = gets.chomp.chars
c = s.uniq.map{|x| s.count(x)}.sort.reverse
ans = 0
c.each do |x|
  t = [x, k].min
  ans += t * t
  k -= t
end
p ans

n,k=gets.split.map(&:to_i)
str=gets.to_s.chomp
arr=str.split(//)
# hsh=arr.inject(Hash.new(0)) { |h,e| h[e] += 1; h }.select {
#     |k,v| v > 1 }.inject({}) { |r, e| r[e.first] = e.last; r }

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

sum=0
kol=0
while (kol<k) do
    maxval=hsh.values.max
    kol+=maxval
    if (kol<=k)
        sum+=maxval**2
    else
        sum+=(maxval-(kol-k))**2
    end
    key=hsh.select{|k,v| v==maxval}.keys
    hsh.delete key[0]
end

puts sum

line = gets
i, ka = line.split.map(&:to_i)
line = gets
char_count = {}
line.each_char do |char|
	next if char == "\n"
	char_count[char] ||= 0
	char_count[char] += 1
end
char_ar = []
char_count.each do |k, v|
	char_ar << [k, v]
end
char_ar.sort! do |a, b|
	a[1] <=> b[1]
end.reverse!
output = 0

char_ar.each do |a|
	b = if ka >= a[1]
		a[1]
	else
	    ka
	end
	ka -= b
	output += (b ** 2)
	break if ka < 1
end
puts output
# a => 1, b => 5

n, k = gets.split.map(&:to_i)
tab = gets.strip.split(//)
amount = {}
#p tab
tab.each do |i|
    if amount[i] == nil
        amount[i] = 1
    else
        amount[i] += 1
    end
end
#amount = tab.inject(0){|x, y| p y}
#amount = tab.inject({}){|x, y| if x[y] == nil; x[y] = 1 else x[y] += 1 end}

amount = amount.to_a.map(&:reverse).sort.reverse
result = 0
i = 0

while i < amount.size && k > 0
    result += [amount[i][0], k].min**2
    k -= [amount[i][0], k].min
    i += 1
end

puts result

require 'pp'

n,k = STDIN.gets.chomp.split(/ /).map(&:to_i)
h = {}
ans = 0

STDIN.gets.chomp.split(//).each do |c|
  h[c] ||= 0
  h[c] += 1
end

vs = h.values.sort.reverse
vs.each do |v|
  if v <= k
    ans += v*v
    k -= v
  else
    ans += k*k
    k = 0
  end
end

puts ans

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

cards = Hash.new(0)

gets.split(//).each { |card| cards[card] += 1 }

cards = cards.to_a.sort { |c1, c2| c2[1] <=> c1[1] }

ans = 0
i = 0

while k > 0
    x = cards[i][1]

    if x > k
        ans += k ** 2
        k = 0
    elsif x <= k
        ans += x ** 2
        k -= x
    end

    i += 1
end

puts ans

n,k=gets.split(/ /).map(&:to_i)
h=Hash.new
gets.split(//).each do |i|
  h[i]?h[i]+=1:h[i]=1
end
ans=0
h.values.sort.reverse.each do |i|
  if i<=k
    ans+=i**2
    k-=i
  else
    ans+=k*k
    k=0
  end
end
puts ans

nAndk = gets.chomp.split(' ').map { |x| x.to_i }
n = nAndk[0]
k = nAndk[1]
bins = {}
cards = gets.chomp.split('')

for card in cards
  if bins[card].nil?
    bins[card] = 0
  end
  bins[card] += 1
end
work = bins.sort_by {|_key, value| value}
score = 0
while k > 0
  count = work.last[1]
  if count < k
    k -= count
    score += bins[work.last[0]] ** 2
    work.pop
  else
    score += k*k
    k = 0
  end
end
p score

n,k = gets.split(/\s+/).map(&:to_i)
h = Hash.new { |h, k| h[k] = 0 }
gets.strip.split(//).inject(h) {|h,s| h[s] += 1; h}

result = 0

h.values.sort.reverse.each do |v|
  if v < k
    k -= v
    result += v**2
  else
    result += k**2
    break
  end
end

p result

n, k = gets.split.map(&:to_i)
s = gets.chomp.chars
c = s.uniq.map{|x| s.count(x)}.sort.reverse
ans = 0
t = 0
c.each do |i|
  t = [i, k].min
  ans += t * t
  break if t == k
  k -= t
end
p ans

n, k = gets.split.map(&:to_i)
s = gets.chomp.chars
c = s.uniq.map{|x| s.count(x)}.sort.reverse
ans = 0
t = 0
accum = 0
c.each do |i|
  t = [i, k].min
  accum += t
  ans += t * t
  break if accum == k
  k -= t
end
p ans

line = gets
i, ka = line.split.map(&:to_i)
line = gets
char_count = {}
line.each_char do |char|
	char_count[char] ||= 0
	char_count[char] += 1
end
char_ar = []
char_count.each do |k, v|
	char_ar << [k, v]
end
char_ar.sort! do |a, b|
	a[1] <=> b[1]
end

output = 0

char_ar.each do |a|
	break if ka < 1
	b = if a[1] > ka
		ka
	else
		ka - a[1]
	end
	puts b
	ka -= b
	output += b ** 2
end
puts output
# a => 1, b => 5

line = gets
i, ka = line.split.map(&:to_i)
line = gets
char_count = {}
line.each_char do |char|
	char_count[char] ||= 0
	char_count[char] += 1
end
char_ar = []
char_count.each do |k, v|
	char_ar << [k, v]
end
char_ar.sort! do |a, b|
	a[1] <=> b[1]
end

output = 0

char_ar.each do |a|
	break if ka < 1
	b = if a[1] > ka
		ka
	else
		ka - a[1]
	end
	ka -= b
	output += b ** 2
end
puts output
# a => 1, b => 5

n, k = gets.split.map(&:to_i)
tab = gets.strip.split(//)
amount = {}
#p tab
tab.each do |i|
    if amount[i] == nil
        amount[i] = 1
    else
        amount[i] += 1
    end
end
#amount = tab.inject(0){|x, y| p y}
#amount = tab.inject({}){|x, y| if x[y] == nil; x[y] = 1 else x[y] += 1 end}

amount = amount.to_a.map(&:reverse).sort.reverse
result = 0
i = 0

while i < amount.size && k > 0
    result += [amount[i][0], k].min**2
    k -= [amount[i][0], k].min
end

puts result


def gao(a, b, dump = nil)
    a, b = b, a if a.size < b.size
    if dump
        c = []
        a.size.times do |i|
            c << a[i][1]
            break if i == b.size
            c << b[i][1]
        end
        c
    else
        a[[a.size, b.size + 1].min - 1][0] + b[-1][0]
    end
end

n = gets.to_i
h = Hash.new{[]}
n.times do |i|
    c, s = gets.split.map(&:to_i)
    h[c] <<= [s, i + 1]
end
h.each do |c, s|
    s.sort!
    s.reverse!
    1.upto(s.size - 1) do |i|
        s[i][0] += s[i - 1][0]
    end
end

a = []
h.sort{|x, y| [x[1].size, x[1][-1]] <=> [y[1].size, y[1][-1]]}.each {|c, s|
    a << s if a.size < 2 || a[-2].size < s.size
}

ans = [-1]
a.each do |x|
    a.each do |y|
        break if x.equal?(y)
        tmp = gao(x, y)
        ans = [tmp, x, y] if tmp > ans[0]
    end
end
p ans[0]
ans = gao(ans[1], ans[2], true)
p ans.size
puts ans * ' '


t = gets.to_i
ans = []
t.times do
  h,w = gets.chomp.split(" ").map(&:to_i)
  a = h.times.map{gets.chomp}
  cnt = 0
  (h-1).times do |i|
    cnt += 1 if a[i][-1] == "R"
  end
  (w-1).times do |i|
    cnt += 1 if a[-1][i] == "D"
  end
  ans << cnt
end
ans.each do |x|
  puts x
end

# t = gets.chomp.to_i
# t.times do
# n, m = gets.chomp.split(" ").map(&:to_i)
#     yy = []
#     xx = []
#     arr = []
#     count = 0
#     n.times do |i|
#     r = gets.chomp.split("")
#         arr << r
#         if n == 1
#             puts "YY"
#             yy << "C"
#             xx << r
#             break
#         elsif m == 1 && i != n-1
#             yy << r
#         elsif m == 1 && i == n-1
#             yy << "C"
#             break
#         end
#         if i != n-1 && n != 1 && m != 1
#             yy << r[-1]
#         elsif i == n-1 && n != 1 && m != 1
#             xx << r
#             yy << r[-1]
#         end
#     end
#     p xx
#     p yy
#     me_x = 0
#     me_y = 0
#     if xx[0].include?("R")
#         ar =  xx[0].count("D")
#         count += ar
#     else
#         me_x += 1
#     end
#     if yy.include?("D")
#         ar = yy.count("R")
#         count += ar
#     else
#         me_y += 1
#     end
#     if me_x >= 1
#         count += m-1
#     elsif me_y >= 1
#         count += n-1
#     end
#     puts count
    # x = 0
    # y = 0
    # ans = 0
    # if  n != 1 && m != 1
    #     until arr[y][x] == "C"
    #         if arr[y][x] == "R"
    #             x += 1
    #         elsif arr[y][x] == "D"
    #             y += 1
    #         end
    #         if x == m - 1
    #             ans = n - y - 1
    #             (y..n-1).each do |k|
    #                 if yy[0][k] == "D"
    #                     ans -= 1
    #                 end
    #             end
    #             break
    #         end
    #         if y == n - 1
    #             ans = m - x - 1
    #             (x..m-1).each do |k|
    #                 if xx[0][k] == "R"
    #                     ans -= 1
    #                 end
    #             end
    #             break
    #         end
    #     end
    # elsif n == 1 || m == 1
    #     if n == 1
    #         if xx.include?("R")
    #             ans = m - 1 - xx.count("R")
    #         else
    #             ans = m - 1
    #         end
    #     elsif m == 1
    #         if yy.include?("D")
    #             ans = n - 1 - yy.count("D")
    #         else
    #             ans = n -1
    #         end
    #     end
    # end
t = gets.chomp.to_i
t.times do |i|
    n, m = gets.chomp.split(" ").map(&:to_i)
    count = 0
    if n == 1
        ar = gets.chomp.split("")
        arr = ar
        yy = ["C"]
        xx = ar
        count = xx.count("D")
    elsif n >= 2
        arr = []
        yy = []
        xx = []
        if m >= 2
            n.times do |i|
            ar = gets.chomp.split("")
            arr << ar
            yy << ar[-1]
                if i == n - 1
                    xx = ar
                end
            end
        elsif m == 1
            xx = ["C"]
            n.times do |i|
                ar = gets.chomp
                arr << ar
                yy << ar
            end
        end
        count += xx.count("D")
        count += yy.count("R")

    end
    puts count
end


n=gets.to_i
x=gets.split.map{|e| e.to_i}
c=0
ans=1
x.inject(0){|l,e|
	if l<e then
		c+=1

		ans=[ans,c].max
	else
		c=1
	end
	e
}
puts ans

n = gets.chomp.to_i
a = gets.split.map(&:to_i)
ans=1
z = 1
(n-1).times do |i|
    if a[i]<a[i+1]
        z+=1
    else
        ans = [ans, z].max
        z=1
    end
end
ans = [ans, z].max
p ans

#!/usr/bin/ruby
gets
r=c=1
a=gets.split.map(&:to_i).each_cons(2){|x,y|
	if x<y
		c+=1
		r=[r,c].max
	else
		c=1
	end
}
p r

n = gets.to_i

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

ans = 1
temp = 1

for i in 1...n do
  if mas[i] > mas[i-1] then
    temp+=1
  else
    ans = temp if temp > ans
    temp = 1
  end
end

ans = temp if temp > ans

puts ans

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

max = 1
arr = [a.first]
(1...n).each do |idx|
  if arr.last < a[idx]
    arr << a[idx]
  else
    arr = [a[idx]]
  end
  max = [max, arr.length].max
end
puts max

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

ans = 1
cnt = 1
now = as[0]

(1..n-1).each do |i|
  if now < as[i]
    cnt += 1
  else
    cnt = 1
  end
  now = as[i]
  ans = [ans, cnt].max
end

puts ans

n = gets.strip.to_i
a = gets.strip.split.map(&:to_i)
prev = a[0]
count = ans = i = 1
while i < n
    if prev < a[i]
        count += 1
    else
        count = 1
    end
    ans = [ans, count].max
    prev = a[i]
    i += 1
end
puts ans

n=gets.to_i
a=gets.split.map &:to_i
dp=[1]*n
for i in 1...n
    dp[i]=dp[i-1]+1 if a[i]>a[i-1]
end
puts dp.max

gets
dp=[1]
a=gets.split.map(&:to_i)
(1..a.size-1).each {|i| dp << ((a[i]>a[i-1])? dp.last+1: 1)}
puts dp.max

# coding: utf-8

# if __FILE__ == $0
# end

n = gets.to_i
l = 0
consecutive = 0
longest_consecutive = 0
gets.split.each { |i|
    i = i.to_i
    if l < i
        consecutive += 1
    else
        consecutive = 1 # new first one
    end

    if longest_consecutive < consecutive
        longest_consecutive = consecutive
    end

    l = i
}

puts longest_consecutive

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

count = 1
array = []
array << count
for i in (1..n-1)
	if a[i] > a[i-1]
		count += 1
		array << count
	else
		count = 1
	end
end

print array.max

def solution(arr)
  counter = 1
  max = 0
  for i in 1...arr.size do
    if arr[i] > arr[i-1]
      counter += 1
    else
      max = [max, counter].max
      counter = 1
    end
  end
  max = [max, counter].max
end

_ = gets
puts solution(gets.split.map(&:to_i))

n = gets.chomp.to_i
#a = Array.new
#n.times { puts gets }
longest = 0
current = 0
before = -1
a = STDIN.gets.split(" ").to_a
a.each do |b|
  b = b.to_i
  if b > before
    current += 1
    longest = current if current > longest
  else
    current = 1
  end
  before = b
end
puts longest

def read_line
  gets.chomp.split.map &:to_i
end

n = read_line
a = read_line
k = 0
x = 0
m = 0
a.each do |y|
  if x<y
    k += 1
  else
    k = 1
  end
  m = k if k>m
  x = y
end

puts m

gets
a = gets.split.map{|x| x.to_i}
t, l = 1, 1
(1..a.size-1).each do |i|
    l = 0 if a[i] <= a[i - 1]
    l += 1
    t = [t, l].max
end
puts t

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

result = a.each_with_object({ prev: a.first, max: 1, s: 1 }) do |elm, obj|
  if elm > obj[:prev]
    obj.merge!({ max: [obj[:s]+1, obj[:max]].max, s: obj[:s]+1 })
  else
    obj.merge!({ max: obj[:max], s: 1 })
  end
  obj[:prev] = elm
end

puts result[:max]

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

max = 0
arr = [a.first]
(1...n).each do |idx|
  if arr.last < a[idx]
    arr << a[idx]
  else
    arr = [a[idx]]
  end
  max = [max, arr.length].max
end
puts max

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

count = 1
array = []
for i in (1..n-1)
	if a[i] > a[i-1]
		count += 1
		array << count
	else
		count = 1
	end
end

print array.max

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

count = 1
array = []
for i in (1..n-1)
	if a[i] > a[i-1]
		count += 1
		array << count
	else
		count = 1
		array << count
	end
end

print array.max


gets.to_i.times do
n=gets.to_i
a=gets.split(' ').map(&:to_i)
sum=a.reduce(:+)
answer = ! a.select{|v| v % (n - 1) == sum % (n-1) && v == (sum - v) / (n - 1)}.empty?
puts answer ? 'YES' : 'NO'
end

t = gets.to_i
t.times do
  n = gets.to_i
  a = gets.chomp!.split.map! &:to_i
  s = a.sum
  if s % a.size == 0 && a.include?(s / a.size)
    puts 'YES'
  else
    puts 'NO'
  end
end

gets.to_i.times do
  n = gets.to_i
  a = gets.split.map(&:to_i)
  s = a.reduce(:+)
  ans = "NO"
  0.upto(n-1) do |i|
    if (s == n*a[i]) then
      ans = "YES"
    end
  end
  puts ans
end

gets.to_i.times do
n=gets.to_i
a=gets.split(' ').map(&:to_i)
sum=a.reduce(:+)
answer = ! a.select{|v| v % n == sum % n && v == (sum - v) / (n - 1)}.empty?
puts answer ? 'YES' : 'NO'
end

gets.to_i.times do
n=gets.to_i
a=gets.split(' ').map(&:to_i)
sum=a.reduce(:+)
answer = ! a.select{|v| v % n == sum % n && v == (sum - v) / n}.empty?
puts answer ? 'YES' : 'NO'
end


lines = STDIN.readlines
result = []

lines.each_with_index do |line, i|
  if line.strip[0] == '#'
    if result.length != 0 and result[-1][-1] != "\n"
      result.push("\n")
    end
    result.push(line)
  else
    result.push(line.gsub(/\s/, ''))
  end
end

if result[-1][-1] != "\n"
  result.push("\n")
end
puts result.join

lines = STDIN.readlines
result = []
is_amplifying = []

lines.each do |line|
  if line.strip[0] == '#'
    result.push(line)
    is_amplifying.push(true)
  else
    result.push(line.gsub(/\s/, ''))
    is_amplifying.push(false)
  end
end

(1..lines.length-1).each do |i|
  if is_amplifying[i] and !is_amplifying[i-1]
    result[i-1] += "\n"
  end
end

if result[-1][-1] != "\n"
  result.push("\n")
end
puts(result.join)

lines = STDIN.readlines
result = []
is_amplifying = []

lines.each do |line|
  if line.strip[0] == '#'
    result.push(line)
    is_amplifying.push(true)
  else
    result.push(line.gsub(/\s/, ''))
    is_amplifying.push(false)
  end
end

(1..lines.length-1).each do |i|
  if is_amplifying[i] and !is_amplifying[i-1]
    result[i-1] += "\n"
  end
end

if result[-1][-1] != "\n"
  result.push("\n")
end
print(result.join)

#!/usr/bin/ruby

buf = []
$stdin.readlines.each do |line|
  line.chomp!
  if line =~ /^ *#/
    if not buf.empty?
      puts buf.join('')
      buf = []
    end
    puts line
  else
    buf << line.gsub(/ /, '')
  end
end
if not buf.empty?
  puts buf.join('')
end

tmp = []

readlines.each do |line|
  if line =~ /^ *#/
    if not tmp.empty?
      puts tmp.join
      tmp = []
    end
    puts line
  else
    tmp << line.delete(' ').chomp
  end
end

puts tmp.join if not tmp.empty?

tmp = []

while line = gets
  if line.lstrip[0] == '#'
    if not tmp.empty?
      puts tmp.join
      tmp = []
    end
    puts line
  else
    tmp << line.delete(' ').chomp
  end
end

puts tmp.join if not tmp.empty?

tmp = []

readlines.each do |line|
  if line.lstrip[0] == '#'
    if not tmp.empty?
      puts tmp.join
      tmp = []
    end
    puts line
  else
    tmp << line.delete(' ').chomp
  end
end

puts tmp.join if not tmp.empty?

last = nil
f = true

while s = gets
	t = s.strip.gsub(' ','')
	if t[0] == '#'
		if last != nil
			puts last
			last = nil
		end
		puts s
	else
		last ||= ""
		last << t
	end
	f = false
end
if last != nil
	puts last
end

lines = STDIN.readlines
result = []
is_amplifying = []

lines.each do |line|
  if line.strip[0] == '#'
    result.push(line)
    is_amplifying.push(true)
  else
    result.push(line.gsub(/\s/, ''))
    is_amplifying.push(false)
  end
end

(1..lines.length-1).each do |i|
  if is_amplifying[i] and !is_amplifying[i-1]
    result[i-1] += "\n"
  end
end

print(result.join)

lines = STDIN.readlines
result = []

lines.each_with_index do |line, i|
  if line.strip[0] == '#'
    if result.length != 0 and result[-1][-1] != "\n"
      result.push("\n")
    end
    result.push(line)
  else
    result.push(line.gsub(/\s/, ''))
  end
end

puts result.join

lines = STDIN.readlines
result = []

lines.each_with_index do |line, i|
  if line.strip[0] == '#'
    if result.length > 0
      if result[-1].length == 0 or result[-1][-1] != "\n"
        result.push("\n")
      end
    end
    result.push(line)
  else
    result.push(line.gsub(/\s/, ''))
  end
end

puts result.join

lines = STDIN.readlines
result = []
is_amplifying = []

lines.each do |line|
  if line.strip[0] == '#'
    result.push(line)
    is_amplifying.push(true)
  else
    result.push(line.gsub(/\s/, ''))
    is_amplifying.push(false)
  end
end

(1..lines.length-1).each do |i|
  if is_amplifying[i] and !is_amplifying[i-1]
    result[i-1] += "\n"
  end
end

puts result.join

tmp = ''
last_line_was_text = false

while line = gets
  if line.lstrip[0] == '#'
    tmp += "\n" if last_line_was_text
    tmp += line
  else
    tmp += line.delete(' ').chomp
    last_line_was_text = true
  end
end

puts tmp.chomp

tmp = ''
last_line_was_text = false

while line = gets
  if line.lstrip[0] == '#'
    tmp += "\n" if last_line_was_text
    tmp += line
    last_line_was_text = false
  else
    tmp += line.delete(' ').chomp
    last_line_was_text = true
  end
end

puts tmp.chomp

#$/ = nil
tmp = ''
last_line_was_text = false

while line = gets
  if line.lstrip[0] == '#'
    tmp += "\n" if last_line_was_text
    tmp += line
    last_line_was_text = false
  else
    tmp += line.delete(' ').chomp
    last_line_was_text = true
  end
end

print tmp.chomp

last = ""
f = true

while s = gets
	t = s.strip.gsub(' ','')
	if t[0] == '#'
		if not f
			puts last
			last = ""
		end
		puts s
	else
		last << t
	end
	f = false
end
puts last

imp = false
f = true
while s = gets
	t = s.strip
	if t[0] == '#'
		if not imp and not f
			puts
		end
		print s
		imp = true
	else
		t = t.gsub(' ','')
		print t
		imp = false
	end
	f = false
end

imp = false
f = true
while s = gets
	t = s.strip
	if t[0] == '#'
		if not imp and not f
			puts
		end
		puts s
		imp = true
	else
		t = t.gsub(' ','')
		print t
		imp = false
	end
	f = false
end
puts


# END { load __FILE__ unless $stdin.eof? }

t = gets.to_i
t.times do

n = gets.to_i
a = gets.split.map!(&:to_i)
z = Array.new(n, &:itself)

if a[-1] == 0
  z.push(n)
elsif a[0] != 0
  z.unshift(n)
else
  k = a.each_cons(2).find_index { |ai, aj| ai == 0 && aj != 0 }
  raise unless k
  z.insert(k + 1, n)
end

puts z.map!(&:succ) * " "

rescue

puts -1

end

gets.to_i.times do
  n=gets.to_i
  a=gets.split.map(&:to_i)
  i=a.reverse.index(0)
  if i==nil
    puts ([n+1]+[*1..n]).join(" ")
  elsif i==0
    i=n-1-i
    puts ([*1..n]+[n+1]).join(" ")
  else
    i=n-1-i
    puts ([*1..i+1]+[n+1]+[*i+2..n]).join(" ")
  end
end


def min(a, b)
  a < b ? a : b
end

class Array
  def sum
    self.inject { |r, v| r + v }
  end
end

n, volume = gets.split.map { |v| v.to_f }
a = gets.split.map { |v| v.to_f }
b = gets.split.map { |v| v.to_f }

multiplier = min(volume / a.sum, b.zip(a).map { |f, s| f / s }.min)

puts multiplier * a.sum

sum , i= 0,0
arr = gets.split(' ').map { |x| x.to_i }
n,v = arr[0],arr[1]
res = v
a = gets.split(' ').map { |x| x.to_i }
for c in a
  sum += c
end
b = gets.split(' ').map { |x| x.to_i }
for s in b
  if res > 1.00*s*sum/a[i] then
    res = 1.00*s*sum/a[i]
  end
  i += 1
end
puts res


n, a=gets.split.map &:to_i
x=180.0*(n-2)/n
minD=(x-a).abs
minX=2
(3...n).each do |i|
    b=(180.0*(i-2)-x*(i-2))/2
    d=(b-a).abs
    if d<minD
        minD=d
        minX=n+2-i
    end
end
puts "1 #{minX} #{minX+1}"

n,k=gets.split(" ").map(&:to_i)
ans=0
mn=180.1
(3..n).each{|i|
	tmp=(180.0/n*(i-2)-k).abs
	if tmp<mn
		mn=tmp
		ans=i
	end
}
puts "2 1 #{ans}"


t = gets.chomp.to_i

ans = 0
for i in 1..t
  s = gets.chomp
  if s[0] == "+" or s[-1] == "+"
    ans+=1
  else
    ans-=1
  end
end
puts ans

s = gets.split(" ")
n = s[0].to_i
rez = 0
for i in 1..n
  s = gets
  if(s[1] == "-")
    rez -= 1
  end
    if(s[1] == "+")
    rez += 1
  end
end
puts(rez)

total = 0
n = gets.to_i.times {
	gets[1] == '+' ? (total += 1):(total -=1)
}
puts total

x = gets.to_i
i = 0

for j in 1..x do
	y = gets.chomp
	if y[1] == "+"
		i = i+1
	else
		i = i-1
	end
end
puts i

x = 0
gets.chomp.to_i.times do
	s = gets.chomp
	if s =~ /(\+\+(x|X)|(x|X)\+\+)/
		x += 1
	else
		x -= 1
	end
end
puts x

n = gets.chomp.to_i

x = 0
1.upto(n) do |i|
    instruction = gets.chomp
    instruction.each_char do |char|
        if char == "+"
            x += 1
            break
        elsif char == "-"
            x -= 1
            break
        end
    end
end
puts x

n = gets.chomp
n = n.to_i

res = 0

n.times do
  cmd = gets.chomp
  res += 1 if cmd == "++X" or cmd == "X++"
  res -= 1 if cmd == "--X" or cmd == "X--"
end

puts res

n = gets.to_i

x = 0
n.times do
  if gets.count('+') != 0
    x += 1
  else
    x -= 1
  end
end

puts x

value = gets.chomp

operation = []
value.to_i.times do |i|
	value = gets.chomp
	operation << value
end
 x = 0
operation.each do |line|
	if line.include?('++')
		x += 1
	elsif line.include?('--')
			x -= 1
	end

end

puts x

n = gets.to_i
x = 0

1.upto(n) do
  line = gets

  case
    when line =~ /\+\+/
      x += 1
    when line =~ /--/
      x -= 1
  end
end

puts x

def answers ()
  n = gets.to_i
  count = 0
  for i in 0...n
    ope = gets.chomp
    if ope.include? "+"
      count +=1
    else
      count -=1
    end
  end
  puts count
end

answers

input = ARGV ? $< : File(ARGV[0])

n = gets.to_i

count = 0
for i in input.each_line.take n
	if i[0] == '+' || i[-2] == '+'
		count += 1
	else
		count -= 1
	end
end

puts count

n = gets.to_i
sum = 0

(1..n).each do |i|
  s = gets.chomp
  if s[1] == '+'
    sum += 1
  else
    sum -= 1
  end
end

puts sum

n = gets.chomp.to_i
c = 0
n.times do
    str = gets
    if str.include? "+"
        c += 1
    else
        c -= 1
    end
end
puts c

number = gets.strip.to_i

x = 0
number.times do
  input = gets.strip
  if input.downcase == '++x' || input.downcase == 'x++'
    x += 1
  else
    x -= 1
  end
end

puts x

x=gets.to_i
z=0
v=0
while z<x
c=gets.chomp
if c=="++X" || c=="X++"
    v+=1
else v-=1
end
z+=1
end
puts v

n = gets.to_i
nilai = 0
for i in 1..n
	kata = gets.chomp
	myarray =kata.split("")
	if (myarray[0] == "+" && myarray[1] == "+") || (myarray[1] == "+" && myarray[2] == "+")
		nilai += 1
	else
		nilai -= 1
	end
end

puts nilai

n, x = gets.to_i, 0
n.times {
  a = gets
  if ((a.count '+') > 0)
    x += 1
  else
    x -= 1
  end
}
puts x

n = gets.chomp.to_i

ans = 0
n.times {

  s = gets.chomp

  if s[1] == '+'
    ans += 1
  else
    ans -= 1
  end
}

puts ans

a = gets.chomp.to_i
x = 0
while a>0
    a-=1
    if gets.chomp[1]=='+'
        x+=1
    else
        x-=1
    end
end
print x

x=0
gets.to_i.times{
	if gets.include?("++")
		x+=1
	else
		x-=1
	end
}
puts x

stateNum = gets.chomp.to_i
value = 0

for i in 0...stateNum
	statement = gets.chomp

	value += 1 if statement.include?('+')
	value -= 1 if statement.include?('-')
end

puts value

x = 0
i = gets.to_i

while i > 0 do
    if gets.index('--') != nil
        x = x - 1
    else
        x = x + 1
    end
    i = i - 1
end

print x

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

counters,xounterz = 0,0
for i in 0..n-1
 s[i] = gets.to_s
  if s[i].include? "+"
       counters+=1
   else
       xounterz+=1
   end
end
puts counters-xounterz

n = gets.strip.to_i
x = 0
var = "X"
n.times do
  str = gets.strip
  if str == "++#{var}" || str == "#{var}++" then
    x += 1
  elsif str == "--#{var}" || str == "#{var}--" then
    x -= 1
  end
end
puts x

n = gets.to_i
rt = n
n.times do
  rt-=2 if gets=~/-/
end
puts rt

n =  gets.strip.to_i
arr = []
last = ""

n.times do |i|
 x = gets.strip.to_s
 x.include?("+") ? arr << 1 : arr << -1
 last = x if (n - i == 1)
end

puts  arr.reduce(0){|init,ele| init + ele}

n=Integer(gets.chomp)
x=0
until n==0
    if gets.chomp.index('+')!=nil
        x = 1 + x
    else
        x = x - 1
    end
    n -= 1
end
puts x

ret = 0
gets.to_i.times do
    if (gets =~ /-/) then ret -= 1 else ret += 1 end
end
puts ret

a=gets.chomp.to_i
x=0
a.times do
b=gets.chomp
if b[0]=="+" || b[2] == "+"
x+=1
else
x-=1
end
end

puts "#{x}"

x=0
gets.to_i.times{
	s=gets.chomp
	x=x+(" ++X++".index(s)?1:-1)
}
puts x

require 'scanf'

n = $stdin.readline.to_i
x = 0

n.times do |i|
  line = $stdin.readline
  line = line.chomp('').downcase
  line = line[0, 3]
  if line == "++x" || line == "x++"
    x += 1
  elsif line == "--x" || line == "x--"
    x -= 1
  end
end

puts x

$stdin = File.open("./input.txt", "r") if ENV["USER"] == "new"
# ====================================

x=0
n = gets.to_i

n.times{
  cmd = gets.strip

  x+=1 if cmd.include? "+"
  x-=1 if cmd.include? "-"
}

puts x

x = 0
n = gets.chomp.to_i
n.times do
	value = gets.chomp
	x = x + 1 if value.scan("+").count == 2 unless value.scan("X").count == 0
	x = x - 1 if value.scan("-").count == 2 unless value.scan("X").count == 0
end
puts(x)

x = 0

gets.strip.to_i.times do
  statement = gets.strip
  x += 1 if statement.include?('++')
  x -= 1 if statement.include?('--')
end

puts x

n = gets.chomp.to_i
ans = 0
n.times{
  line = gets.chomp
  ans += 1 if line.include? "+"
  ans -= 1 if line.include? "-"
}
puts ans

n = gets.to_i
o=0

for i in 1..n
  gets.chomp[1] == '+' ? o+=1 : o-=1
end

p o

r = 0

gets.to_i.times do
  if gets[1] == '+'
    r += 1
  else
    r -= 1
  end
end

puts r

n=gets.chomp.to_i
x=0
n.times{
    s=gets.chomp.to_s
    if s.scan(/\+\+/) { |match|
        x+=1
    }
    end
    if s.scan(/--/) { |match|
        x-=1
    }
    end
}
puts (x)

p gets.to_i.times.map{gets=~/\+/?1: -1}.inject &:+

n = Integer(gets)
operation = Array.new
for i in 0...n
    operation[i] = Array.new
    input = gets.chomp
    operation[i] = input
end
x = 0
for i in 0...n
    if operation[i] == "++X" || operation[i] =="X++"
        x += 1
    else
        x -= 1
    end
end
puts x

x = 0
n = gets.chomp.to_i
i = 0
if n >= 1 && n <= 150
	while i < n
		statement = gets.chomp
		if statement == "++X" || statement == "++x" || statement == "x++" || statement == "X++"
			x += 1
		elsif statement == "--X" || statement == "--x" || statement == "x--" || statement == "X--"
			x -= 1
		end
		i += 1
	end
end

puts x

n = gets.to_i
value = 0
n.times do |_|
    statement = gets
    statement.include?('++') ? value += 1 : value -= 1
end
puts value

n = gets.to_i
x = 0
for i in 0...n
  operation = gets.chomp.to_s
  case operation
    when "++X","X++"
      x+=1
    when "--X","X--"
      x-=1
  end
end
puts x

x = 0
gets.to_i.times {
  x += gets.include?("+") ? 1 : -1
}
puts x

ans = 0
gets.to_i.times do |i|
     if gets.include?("++")
         ans += 1
     else
         ans -= 1
     end
end
puts ans

n = gets.to_i
X = 0

n.times do

pokemon = gets.to_s

pokemon.delete! ("X")

b = pokemon.scan(/[+]/).length

if b >= 1
X += 1

else
X -= 1

end

end

p X

x = 0

#input
counter = gets.chomp.to_i
listing = []

while counter != 0
	s = gets.chomp
	if s.include?("++")
		x += 1
	elsif s.include?("--")
		x -= 1
	end

	counter -= 1
end

puts x

n = gets.chomp.to_i
x = 0
n.times do
	s = gets.chomp
	if s.include?("+")
		x += 1
	else
		x -= 1
	end
end
puts x

n = gets.to_i
puts n.times.map{gets['++'] ? +1 : -1}.inject(:+)

n = gets.to_i
ans = 0
n.times.map{gets}.map{|x| x.include?('++') ? ans += 1 : ans -= 1}
puts ans

n=gets.chomp.to_i
y=0
while n>0
b=gets.chomp

if(b=="++X" or b=="X++")
y+=1
end
if(b=="--X" or b=="X--")
y=y-1
end
n=n-1
end
print y

result = 0
gets.chomp.to_i.times do
  case gets.chomp.gsub(/X/, '')
    when '++' then result += 1
    when '--' then result -= 1
  end
end
puts result

operations = []
gets.to_i.times { operations << gets }
puts operations.inject(0) { |x, operation| operation.include?("++") ? x + 1 : x - 1}

result = 0
gets.chomp.to_i.times do
  case gets.chomp
    when 'X++' then result += 1
    when '--X' then result -= 1
  end
end
puts result

k=gets.to_i
l=[]
k.times{l << gets.chomp}
print l.count("++X")-l.count("--X")

x = 0
gets.chomp.to_i.times do
	s = gets.chomp
	if s =~ /(\+\+x|x\+\+)/
		x += 1
	else
		x -= 1
	end
end
puts x

n = gets.to_i
x = 0
n.times do
  if gets.chomp == "x++"
    x += 1
  else
    x -= 1
  end
end

puts x

sum = 0
gets.to_i.times{
  if gets[1]=="+"
    sum+=1
  else
    sum-=1
  end
}
sum

n =  gets.strip.to_i
arr = []
last = ""

n.times do |i|
 x = gets.strip.to_s
 x.include?("+") ? arr << 1 : arr << -1
 last = x if (n - i == 1)
end

if last[0] != "+" and  last[0] != "-"
  arr[arr.length  - 1]  =  0
end

puts  arr.reduce(0){|init,ele| init + ele}

i = gets.to_i
counter = 0
(1..i).each do |x|
  counter += gets.chomp === 'X++' ? 1 : -1
end
print counter

input_line_num = gets.chomp.to_i
n = 0
res = 0
while input_line_num > n
  input_peration = gets.chomp
  case input_peration.include?("+")
  when true
      res +=1
  when false
      if res < 0
        res = 0
      end
        res -=1
  end
  n +=1
end
p res

num = gets.chomp.to_i
lines = []
i = 0
x = 0
while (i < num)
	lines[i] = gets.chomp
	i = i + 1
end
j = 0
while (j < lines.length)
	if(lines[j] == "++x" || lines[j] == "x++")
		x = x +1
	else
	x = x -1
	end
	j = j +1
end
puts x.to_s

number = gets.strip.to_i

x = 0
number.times do
  input = gets.strip
  if input == '++x'
    x += 1
  else
    x -= 1
  end
end

puts x


# https://codeforces.com/problemset/problem/234/C

n = 0
arr = []

File.open("input.txt", "r") do |f|
 n = f.gets.to_i - 2
 arr = f.gets.split(' ').map(&:to_i)
end

s = (arr[0] >= 0 ? 1 : 0) + (arr[-1] <= 0 ? 1 : 0)

File.open("output.txt", "w") do |f|
 if n > 0
  arr = arr[1...-1]

  temp = Array.new(n, 0)

  correct_count = 0
  n.times do |i|
   correct_count += 1 if arr[i] < 0
   temp[i] += correct_count
  end

  correct_count = 0
  (n-1).downto(0) do |i|
   correct_count += 1 if arr[i] > 0
   temp[i] += correct_count
  end

  f.write("#{s + n - temp.max}\n")
 else
  f.write("#{s}\n")
 end
end

n = 0
arr = []
open("input.txt") {|f|
  n = f.gets.to_i
  arr = f.gets.to_s.chomp.split.map(&:to_i)
}
File.open("output.txt", "w"){|f|
  t1 = 0
  t2 = 0
  ar1 = []
  ar2 = []
  n.times do |i|
    t1 += 1 if arr[i] >= 0
    ar1.push(t1)
    t2 += 1 if arr[n-1-i] <= 0
    ar2.push(t2)
  end
  ar2.reverse!
  ar3 = []
  #ar3.push(ar1[n-1])
  #ar3.push(ar2[0])
  (n-1).times do |i|
    ar3.push(ar1[i]+ar2[i+1])
  end
  #p ar1
  #p ar2
  #p ar3
  f.write "#{ar3.min}\n"
}

n = 0
arr = []
open("input.txt") {|f|
  n = f.gets.to_i
  arr = f.gets.to_s.chomp.split.map(&:to_i)
}
File.open("output.txt", "w"){|f|
  t1 = 0
  t2 = 0
  ar1 = []
  ar2 = []
  n.times do |i|
    t1 += 1 if arr[i] >= 0
    ar1.push(t1)
    t2 += 1 if arr[n-1-i] <= 0
    ar2.unshift(t2)
  end
  ar3 = []
  ar3.push(ar1[n-1])
  ar3.push(ar2[0])
  (n-1).times do |i|
    ar3.push(ar1[i]+ar2[i+1])
  end
  #p ar1
  #p ar2
  #p ar3
  f.write "#{ar3.min}\n"
}


gets.to_i.times do
  l1, r1, l2, r2 = gets.split.map(&:to_i)
  if l1 <= r2 && r1 >= l2
    p [l1, l2].max
  else
    p l1 + l2
  end
end

gets.to_i.times do
  l1,r1,l2,r2 = gets.chomp.split.map(&:to_i)
  if (l2 > r1) or (r2<l1) then
    puts l1 + l2
  else
    puts [l1,l2].max
  end
end


t, a = nil
File.open("input.txt") do |f|
  t = f.gets.to_i
  a = []
  t.times{ a << f.gets.to_i}
end

File.open("output.txt", "w") do |f|
  a.each{|x| f.puts 1-x%2}
end

$stdin=File.open('input.txt')
$stdout=File.open('output.txt','w')
N=gets.to_i
for i in 0...N
    j=gets.to_i
    if j%2==0
        puts "1"
    else
        puts "0"
    end
end


def solve
	min = 10 ** 10
	for i in 0..$s.size - 2
		if $s[i] == 'R' and $s[i + 1] == 'L'
			t = ($a[i + 1] - $a[i]) / 2
			min = t if t < min
		end
	end
	return min == 10 ** 10 ? -1 : min;
end

$n = gets.to_i
$s = gets
$a = gets.split.map &:to_i
puts solve

n=gets.to_i
s=gets.chomp
x=gets.split.map{|e| e.to_i}

ans=-1
(n-1).times{|i|
	if s[i]=="R" && s[i+1]=="L" then
		t1=(x[i+1]-x[i])/2
		if ans==-1 || ans>t1 then
			ans=t1
		end
	end
}
puts ans

n = gets.to_i
directions = gets
numbers = gets

numbers = numbers.split(' ')
pr = -1
min = 20000000000
flag = 0
pl = -1
numbers.each_with_index do |r,i|
    if (directions[i] == 'R')
        pr = i
    else
        if (pr != -1)
            pl = i
            #calc magic
            delta = numbers[pl].to_i - numbers[pr].to_i
            min = delta if delta < min
            flag = 1;
        end
    end
end

puts flag == 0 ? -1 : min/2

n = gets.chomp.to_i
ss = gets.chomp.split('')
xs = gets.chomp.split.map(&:to_i)

ls = []
rs = []
(0...n).to_a.each do |i|
  if ss[i] == 'L'
    ls << xs[i]
  else
    rs << xs[i]
  end
end

ls.sort!
ans = -1

rs.each do |r|
  l = ls.bsearch { |l| r < l }
  if !l.nil?
    t = (l - r) / 2
    if ans < 0 || t < ans
      ans = t
    end
  end
end

puts ans

n = gets.to_i
d = gets.chomp.chars
t = gets.split.map(&:to_i)
ans = 1e9
(n - 1).times do |i|
  if d[i] == 'R' && d[i + 1] == 'L'
    ans = [( t[i + 1] - t[i] ) / 2, ans].min
  end
end
puts ans == 1e9 ? -1 : ans

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

ans = nil
last = nil
n.times do |i|
  if d[i] == 'L'
    ans = x[i] - last if last && (ans.nil? || x[i] - last < ans)
  else
    last = x[i]
  end
end

puts ans ? ans / 2 : -1

particleNum = gets.chomp.to_i
directions = gets.chomp.split('')
particles  = gets.chomp.split(' ').map(&:to_i)

foundRight = false
posRight = 0

ans = -1
candAns = []

for i in 0...particleNum
	foundRight = true if directions[i] == 'R'
	posRight = i if directions[i] == 'R'

	if foundRight && directions[i] == 'L'
		candAns << particles[i] - ((particles[posRight] + particles[i]) / 2)
		foundRight = false
	end
end

if candAns.length > 0
	puts candAns.min
else
	puts -1
end

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

ans = 1234567890

(n-1).times do |i|
    if s[i]=='R' && s[i+1]=='L'
        ans = [ans, (a[i+1]-a[i])/2].min
    end
end

if ans==1234567890
    p -1
else
    p ans
end

gets
str = gets.chomp
mas = gets.split.map(&:to_i)

n = str.length

ans = 10000000000000
l = false
for i in 0..n-1 do
  if str[i]=='R' and str[i+1]=='L' then
      l = true
      out = (mas[i+1] - mas[i])/2
      ans = out if ans > out
  end
end

puts (l==true ? "#{ans}": "-1")

n = gets.chomp.to_i
syms = gets.chomp.chars
points = gets.chomp.split.map(&:to_i)

arr = syms.each_cons(2).with_index.select { |s, _| s.join == "RL" }.map do |_, idx|
  (points[idx + 1] - points[idx]) / 2
end

puts arr.empty? ? -1 : arr.min

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

n = gi
s = gs
x = gis

l = nil
r = nil

ans = nil

n.times do |i|
    if s[i] == 'L'
        l = x[i]
    else
        r = x[i]
    end
    next if l.nil?
    next if r.nil?
    next if r > l
    k = (l - r) / 2
    if ans.nil?
        ans = k
    else
        ans = [ans, k].min
    end
end

if ans.nil?
    puts -1
else
    puts ans
end

particleNum = gets.chomp.to_i
directions = gets.chomp.split('')
particles  = gets.chomp.split(' ').map(&:to_i)

foundRight = false
posRight = 0

ans = -1

for i in 0...particleNum
	foundRight = true if directions[i] == 'R'
	posRight = i if directions[i] == 'R'

	if foundRight && directions[i] == 'L'
		ans = particles[i] - ((particles[posRight] + particles[i]) / 2)
		break
	end
end

puts ans


n=gets.to_i
a=gets.split(" ")
s=Array.new(1111111,0)
ans=id=0
a.each do |v|
	x=v.to_i
	y = (s[x]+=1)
	if ans<y
		ans=y
		id=x
	end
end
puts id

#!/usr/bin/ruby
gets;a=gets.split.map(&:to_i)
b=a.group_by{|e|e}.map{|k,v|[-v.size,k]}.sort
c=b.take_while{|s,k|s==b[0][0]}.map(&:last)
h={}
a.reverse.each_with_index{|e,i|h[e]||=i if c.include?(e)}
p h.max_by{|k,v|v}[0]

n = gets.to_i
a = gets.split.map{|x| x.to_i}
h = Hash.new(0)
x = 0
y = -1
for i in 0...n

	h[a[i]] += 1
	if h[a[i]] > x then
		x = h[a[i]]
		y = a[i]
	end

end

puts y


gets.chomp
a = gets.chomp.split(" ").map(&:to_i)
even = a.select(&:even?).sort
odd = a.select(&:odd?).sort

elements_sum = 0
even_size_diff = even.size - odd.size - 1
odd_size_diff = odd.size - even.size - 1

elements_sum = even[0..even_size_diff-1].reduce(0, :+) if even_size_diff > 0
elements_sum = odd[0..odd_size_diff-1].reduce(0,:+) if odd_size_diff > 0

puts elements_sum

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

odds = a.select(&:odd?)
evens = a.select(&:even?)

res = 0
diff_size = (odds.size - evens.size).abs
if diff_size <= 1
  res = 0
else
  arr = (odds.size > evens.size) ? odds : evens
  res = arr.sort[0..(diff_size-2)].reduce(&:+)
end

puts res

n = gets.to_i
a = gets.split.map(&:to_i).sort
x = [[],[]]
n.times do |i|
    x[a[i]%2] << a[i]
end
if (x[0].size-x[1].size).abs <= 1
    puts 0
else
    x[0],x[1] = x[1],x[0] if x[0].size > x[1].size
    m = x[0].size
    puts x[1][0..-m-2].inject(:+)
end


# coding: utf-8

t = gets.to_i

def required(h)
    2 * (h*(h+1)/2) + ((h-1)*h/2)
end

def near_max(ar, v)
    b, e = 0, ar.length
    while b < e
        mid = (b + e)/2
        if v < ar[mid]
            if e - b == 1
                return ar[b]
            else
                e = mid
            end
        elsif v > ar[mid]
            if e - b == 1
                return ar[b]
            else
                b = mid
            end
        else
            return ar[mid]
        end
    end
end
precalc = [0]
for i in 1..25900
    precalc << required(i)
end
# p precalc
# puts near_max(precalc, 10**9)
t.times {
    n = gets.to_i # the number of cards (1<=n<=10**9)
    # if h, required_cards = 2*(from 1 to h, sum) + (from 0 to h-1, sum)
    # h*h + h + h*h/2 - h/2
    pyramids = 0
    while n >= 2
        subtractor = near_max(precalc, n)

        if subtractor == 0
            break
        else
            pyramids += 1
            n -= subtractor
        end
    end
    puts pyramids

}

t = gets.to_i

0.upto t-1 do
  card = gets.to_i
  count = 0
  h = 1    # height
  while card > 1 do
    h = 1
    while card > 1 do
      if card >= (2*h + (h-1))
        card -= (2*h + (h-1))
        h += 1
        if card == 0 or card == 1
          count += 1
        end
      else
        count += 1
        break
      end
    end
  end
  puts count
end


n = gets.to_i
a = gets.split(' ')
s = gets
ori = 0
for i in 0..n-1
	a[i] = a[i].to_i
	if s[i]=='B'
		ori+=a[i]
		a[i]=-a[i]
	end
end
tot = ans = ori
a.each do |v|
	tot+=v
	ans = [ans, tot].max
end
tot = ori
a.reverse_each do |v|
	tot+=v
	ans = [ans, tot].max
end
puts ans

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

init = 0

n.times do |i|
  init += pieces[i] if teams[i] == "B"
end

ret = init

# left
curr = init
n.times do |i|
  if teams[i] == "A" then
    curr += pieces[i]
  else
    curr -= pieces[i]
  end
  if curr > ret then
    ret = curr
  end
end

# right
curr = init
(n - 1).downto(0) do |i|
  if teams[i] == "A" then
    curr += pieces[i]
  else
    curr -= pieces[i]
  end
  if curr > ret then
    ret = curr
  end
end

puts ret

n = gets.to_i
a = gets.split(' ')
s = gets
ori = 0
for i in 0..n-1
	a[i] = a[i].to_i
	if s[i]=='B'
		ori+=a[i]
		a[i]=-a[i]
	end
end
tot = ans = ori
for i in 0..n-1
	tot+=a[i]
	ans = [ans, tot].max
end
tot = ori
i=n-1
while i>=0
	tot+=a[i]
	ans = [ans, tot].max
	i-=1
end
puts ans

#!/usr/bin/ruby
n=gets.to_i
a=gets.split.map(&:to_i)
s=gets.chomp.bytes
r=0
n.times{|i|r+=a[i] if s[i]==66}
r0=r1=r
n.times{|i|
	if s[i]==65
		r0+=a[i]
	else
		r0-=a[i]
	end
	r=[r,r0].max
}
(n-1).downto(0){|i|
	if s[i]==65
		r1+=a[i]
	else
		r1-=a[i]
	end
	r=[r,r1].max
}
p r

n = gets.to_i
a = gets.split(' ')
s = gets
exit if n>400000
ori = 0
for i in 0..n-1
	ori+=a[i].to_i if s[i]=='B'
end
tot = ans = ori
for i in 0..n-1
	tot+=a[i].to_i if s[i]=='A'
	tot-=a[i].to_i if s[i]=='B'
	ans = [ans, tot].max
end
tot = ori
i=n-1;
while i>=0
	tot+=a[i].to_i if s[i]=='A'
	tot-=a[i].to_i if s[i]=='B'
	ans = [ans, tot].max
	i-=1
end
puts ans

n = gets.to_i
a = gets.split(' ')
s = gets
ori = 0
for i in 0..n-1
	a[i] = a[i].to_i
	ori+=a[i] if s[i]=='B'
end
exit if n>400000
tot = ans = ori
for i in 0..n-1
	tot+=a[i] if s[i]=='A'
	tot-=a[i] if s[i]=='B'
	ans = [ans, tot].max
end
tot = ori
i=n-1
while i>=0
	tot+=a[i] if s[i]=='A'
	tot-=a[i] if s[i]=='B'
	ans = [ans, tot].max
	i-=1
end
puts ans

n = gets.to_i
a = gets.split(' ')
s = gets
ori = 0
for i in 0..n-1
	a[i] = a[i].to_i
	ori+=a[i] if s[i]=='B'
end
tot = ans = ori
for i in 0..n-1
	tot+=a[i] if s[i]=='A'
	tot-=a[i] if s[i]=='B'
	ans = [ans, tot].max
end
exit if n>400000
tot = ori
i=n-1
while i>=0
	tot+=a[i] if s[i]=='A'
	tot-=a[i] if s[i]=='B'
	ans = [ans, tot].max
	i-=1
end
puts ans

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

init = 0

n.times do |i|
  init += pieces[i] if teams[i] == "B"
end
ret = init

# left
curr = init
n.times do |i|
  break if teams[i] == "B"
  curr += pieces[i]
end
ret = [ret, curr].max

# right
curr = init
(n - 1).downto(0) do |i|
  break if teams[i] == "B"
  curr += pieces[i]
end
ret = [ret, curr].max

puts ret


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

$results = Array.new($m, 0)
# $results = []

def spiders_indersection(line, position, direction)
  index = nil
  case direction
  when 'L'
    index = position - line
  when 'R'
    index = position + line
  when 'U'
    index = position unless line.odd?
  end
  # if index
  #   $results[index] = ($results[index] || 0) + 1
  # end
  if (index && index >= 0 && index < $m)
    # puts [index, position, line].join(' ')
    $results[index] += 1
  end
end

$n.times do |i|
  gets.chars.first($m).each_with_index do |char, j|
    spiders_indersection(i, j, char)
  end
end

puts $results.first($m).join(' ')

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

init_field = n.times.map {
  readline.strip
}
res = Array.new(m, 0)

init_field.each_with_index{|line, row_idx|
  line.each_char.with_index{|cell, col_idx|
    if cell == 'L'
      col_corr = col_idx - row_idx
      res[col_corr] += 1  if col_corr >= 0
    elsif cell == 'R'
      col_corr = col_idx + row_idx
      res[col_corr] += 1  if col_corr < m
    elsif cell == 'U' && row_idx % 2 == 0
      res[col_idx] += 1
    end
  }
}

puts res.join(' ')

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

$results = Array.new(2*$m, 0)

def spiders_indersection(line, position, direction)
  # $m.times do |omnom_start_position|
  #   met = case direction
  #   when 'L'
  #     position - line == omnom_start_position
  #   when 'R'
  #     omnom_start_position == line + position
  #   when 'U'
  #     omnom_start_position == position
  #   else
  #     false
  #   end
  #   $results[omnom_start_position] += 1 if met
  # end

  case direction
  when 'L'
    $results[position - line] += 1
  when 'R'
    $results[position + line] += 1
  when 'U'
    $results[position] += 1
  end
end

$n.times do |i|
  gets.chars.first($m).each_with_index do |char, j|
    spiders_indersection(i, j, char)
  end
end

puts $results.first($m).join(' ')

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

$results = Array.new($m, 0)

def spiders_indersection(line, position, direction)
  index = -1
  case direction
  when 'L'
    index = position - line
  when 'R'
    index = position + line
  when 'U'
    index = position if line > 1
  end
  $results[index] += 1 if (index >= 0 && index < $m)
end

$n.times do |i|
  gets.chars.first($m).each_with_index do |char, j|
    spiders_indersection(i, j, char)
  end
end

puts $results.first($m).join(' ')

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

$results = Array.new($m, 0)
# $results = []

def spiders_indersection(line, position, direction)
  index = nil
  case direction
  when 'L'
    index = position - line
  when 'R'
    index = position + line
  when 'U'
    index = position if line > 1
  end
  # if index
  #   $results[index] = ($results[index] || 0) + 1
  # end
  if (index && index >= 0)
    # puts [index, position, line].join(' ')
    # $results[index] += 1
    $results[index] = ($results[index] || 0) + 1
  end
end

$n.times do |i|
  gets.chars.first($m).each_with_index do |char, j|
    spiders_indersection(i, j, char)
  end
end

puts $results.first($m).join(' ')


d,h,v,e=gets.split.map(&:to_f)
v/=Math::PI*d*d/4
puts v<e ? "NO" : "YES\n"+(h/(v-e)).to_s

def calc(d, h, v, e)
  speed = v / (d * d * 0.25 * Math::PI)
  return "NO" if speed <= e

  diff = speed - e
  time = h / diff
  time <= 10000.0 ? "YES\n#{time}" : "NO"
end

d, h, v, e = gets.chomp.split.map(&:to_f)
puts calc(d, h, v, e)

d, h, v, e = readline.split(' ').collect(&:to_i)
pi = Math.acos(-1.0)
inc = e * pi * d * d / 4.0
if inc >= v
  puts "NO"
else
  puts "YES"
  puts (pi * d * d / 4.0 * h) / (v - inc)
end

a=gets.chomp.split(" ").map{|i| i.to_i}
pi=3.141592653589793
x=(4*a[2])/((a[0]**2)*pi)
if x>a[3]
k=x-a[3]
time=a[1]/k

if time<=10000
puts"YES"
puts"#{time}"
else
puts"NO"
end

else
puts "NO"
end

d, h, v, e = gets.split.map { |x| x.to_i }
s = (d / 2.0) ** 2 * Math::PI

if v / s > e
	puts "YES"
	ans = h / (v / s - e)
	puts "%.12f" % ans
else
	puts "NO"
end

input = gets.chomp.split(' ').map {|i| i.to_i}
d, h, v, e = input[0], input[1], input[2], input[3]

decreaseSpeed = (4 * v) / ((d ** 2) * Math::PI)
ans = h / (decreaseSpeed - e)

if ans < 0
	puts 'NO'
else
	puts 'YES'
	puts ans
end

input = gets.chomp.split(' ').map {|i| i.to_i}
d, h, v, e = input[0], input[1], input[2], input[3]

decreaseSpeed = (4 * v) / ((d ** 2) * Math::PI)
ans = h / (decreaseSpeed - e)

if ans < 0
	puts 'NO'
else
	puts ans
end