def function
b=gets.chomp
a=gets.chomp
a=a.split(' ').map(&:to_i).sort
sum=0
a.each do |i|
sum+=i
end
if sum%2!=0
a.each do |i|
if i%2!=0
sum-=i
puts sum
break
end
end
else
puts sum
end
end
function

gets
x,y=gets.split.map(&:to_i).sort.reverse.partition{|e|e%2==0}
p x.reduce(0,:+)+y[0,y.size/2*2].reduce(0,:+)

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

min_odd = numbers.find(&:odd?)
sum = numbers.inject(0, :+)
puts sum.even? ? sum : sum - min_odd

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

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

odds_sum = odds.size.even? ? odds.inject(0, :+) : odds.drop(1).inject(0, :+)

puts evens.inject(0, :+) + odds_sum

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

par = []
nep = []
sum = a.reduce(:+)
a.each { |x| x.even? ? par.push(x) : nep.push(x) }

puts sum.even? ? sum : sum - nep[0]

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

par, nep = [], []
a.each do |x|
  x.even? ? par.push(x) : nep.push(x)
end
sum = a.reduce(:+)

puts sum.even? ? sum : sum - nep[0]

def sum_all(arr)
	sum =0
	arr.each do |i|
		sum+=i
	end
	return sum
end

n = gets.chomp
arr = gets.split.map(&:to_i)
odd_count =0
even_count =0
arr.each do|i|
	if i.even?
		even_count +=1
	else
		odd_count +=1
	end
end
sum=0

if odd_count.even?
	puts sum_all(arr)
else
	odd_count -=1
arr.sort!.reverse!

sum =0
arr.each do |i|
	if i.odd? and odd_count>0
		sum+=i
		odd_count -=1
	elsif i.even?
		sum+=i
	end
end
puts sum
end

gets
e1=0
o1=-1
x=gets.split.map{|e| e.to_i}
x.each{|e|
	d=e%2
	if d==0 then
		e1+=e
		if o1!=-1 then
			o1+=e
		end
	else
		o2=e1+e
		if o1!=-1 then
			e1=[e1,o1+e].max
		end
		o1=[o1,o2].max
	end
}
puts e1

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

a.sort!{|x, y| y <=> x }
ans = 0
odd = []
a.each do |v|
  if v % 2 == 0
    ans += v
  else
    if odd.size == 0
      odd.push(v)
    else
      ans += v + odd.shift
    end
  end
end
puts ans

# coding: utf-8

n = gets.to_i
a = []
sum = 0
odds = 0
gets.split.each { |i|
    i = i.to_i

    if i.even?
        sum += i
    else
        odds += 1 if i.odd?
        a << i
    end
}
a.sort!
if odds.odd?
    a.shift
end
a << 0

puts a.reduce(:+) + sum

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

s = xs.inject(&:+)
if s % 2 == 0
  puts s
else
  puts s - xs.select { |x| x % 2 == 1 }.min
end

def solve(a)
  s = a.inject(0, :+)
  return s if s.even?
  x = a.lazy.select(&:odd?).min
  return s - x if x
  0
end

gets
puts solve(gets.split.map(&:to_i))

n = gets.to_i
a = gets.split(' ').map &:to_i
s = a.reduce(&:+)
if s%2 == 0
  puts s
else
  mn = Float::INFINITY
  for i in a
    mn = [mn, i].min if i%2 == 1
  end
  puts s - mn
end

n = gets.to_i
a = gets.split.map(&:to_i)
sum = a.inject(:+)
puts sum.even? ? sum : sum - a.select(&:odd?).min

n = gets.to_i
a = gets.split.map(&:to_i).sort
sum = a.inject(:+)
puts sum.even? ? sum : sum - a.find{|x| x.odd?}

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

aoddmin = a.select{|x| x.odd?}.min

asum = a.inject(:+)
if asum.even? then
  puts asum
else
  puts asum - aoddmin
end

gets
a = gets.split.map{|x| x.to_i}
odds = a.select{|x| x%2 == 1}
puts(a.inject(0){|s, x| s + x} - (odds.size%2 != 0 ? odds.min : 0))

gets
x,y=gets.split.map(&:to_i).sort.reverse.partition{|e|e==0}
p x.reduce(0,:+)+y[0,y.size/2*2].reduce(0,:+)

def function
a=gets.chomp
a=a.split(' ').map(&:to_i).sort
sum=0
a.each do |i|
sum+=i
end
a.each do |i|
if i%2!=0
sum-=i
break
end
end
puts sum
end
function

n = gets.chomp
arr = gets.split.map(&:to_i)
odd_count =0
even_count =0
arr.each do |i|
	if i.odd?
		odd_count+=1
	else
		even_count +=1
	end
end

if odd_count.odd?
	odd_count = odd_count -1
end
sum = 0
arr.each do |i|
	if i.odd? and not odd_count.zero?
		sum +=i
		odd_count= odd_count -1
	elsif i.even?
		sum +=i
	end
end
puts sum

gets
e1=0
o1=-1
x=gets.split.map{|e| e.to_i}
x.each{|e|
	d=e%2
	if d==0 then
		e1+=e
		if o1!=-1 then
			o1+=e
		end
	else
		o2=e1+e
		if o1!=-1 then
			e1=o1+e
		end
		o1=o2
	end
}
puts e1

# coding: utf-8

n = gets.to_i
a = []
sum = 0
odds = 0
gets.split.each { |i|
    i = i.to_i

    if i.even?
        sum += i
    else
        odds += 1 if i.odd?
        a << i
    end
}

if odds.odd?
    a.shift
    a << 0
end

puts a.reduce(:+) + sum

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

aoddmax = a.select{|x| x.odd?}.max

asum = a.inject(:+)
if asum.even? then
  puts asum
else
  puts asum - aoddmax
end


t = gets.to_i

t.times do
  n = gets.to_i
  h1 = h2 = h3 = n / 3
  m = n % 3
  if m == 1
    h1 += 1
  elsif m == 2
    h1 += 1
    h2 += 1
  end

  until h3 < h2 && h2 < h1 && h1+h2+h3 == n
    h1 += 1
    h3 -= 1
  end
  puts [h2, h1, h3].join(" ")
end

#require "prime"
#input of int(split by space)
def get_i()
    return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
    return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
    return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
    return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
    return bool ? y : n
end
#output grid(two dimensional array)
def puts_grid(grid,join_char="")
    grid.each do|line|
        puts line.join(join_char)
    end
end

Dirxy4=[[1,0],[-1,0],[0,1],[0,-1]]
Dirxy8=[[1,0],[1,-1],[1,1],[0,-1],[0,1],[-1,0],[-1,-1],[-1,1]]

INF=Float::INFINITY

#MOD=998_244_353
MOD=10**9+7

T=gets.to_i
T.times do
    n=gets.to_i
    v=n/3
    r=n%3
    case r
    when 0 then
        puts [v,v+1,v-1].join(" ")
    when 1 then
        puts [v,v+2,v-1].join(" ")
    when 2 then
        puts [v+1,v+2,v-1].join(" ")
    end
end

def solution(n)
    fi, se, th = 3, 2, 1
    m = (n - 6) / 3
    r = (n - 6) % 3
    fi += m
    se += m
    th += m
    while r > 0
        if r > 0
            fi += 1
            r -= 1
        end
        if r > 0
            se += 1
            r -= 1
        end
        if r > 0
            th += 1
            r -= 1
        end
    end
    puts se.to_s + " " + fi.to_s + " " + th.to_s
end

n = $stdin.gets.to_i
(0...n).each do |i|
  n = $stdin.gets.to_i
  solution(n)
end

#require "prime"
#input of int(split by space)
def get_i()
    return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
    return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
    return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
    return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
    return bool ? y : n
end
#output grid(two dimensional array)
def puts_grid(grid,join_char="")
    grid.each do|line|
        puts line.join(join_char)
    end
end

Dirxy4=[[1,0],[-1,0],[0,1],[0,-1]]
Dirxy8=[[1,0],[1,-1],[1,1],[0,-1],[0,1],[-1,0],[-1,-1],[-1,1]]

INF=Float::INFINITY

#MOD=998_244_353
MOD=10**9+7

T=gets.to_i
T.times do
    n=gets.to_i
    puts [2,n-3,1].join(" ")
end


s = gets.strip.split ''

brk = Array.new
right = {'>' => '<', '}' => '{', ']' => '[', ')' => '('}

res = 0

s.each do |e|
	if right.include? e
		if brk.size == 0
			res = -1
			break
		end

		if brk[-1]  == right[e]
			brk.pop
		else
			res += 1
			brk.pop
		end
	else
		brk.push e
	end
end

if res == -1 or brk.any?{|e| e != 0}
	puts 'Impossible'
else
	puts res
end

s = gets.chomp

RBS = Array.new		# regular bracket sequance
change = 0

for i in 0...s.length
	case s[i]
		when '(', '[', '{', '<' then
			RBS.push s[i]

		when ')', ']', '}', '>' then
			if RBS.empty?
				puts "Impossible"
				exit true
			end

			ch = RBS.pop
			if not ((ch == '(' and s[i] == ')') or (ch == '[' and s[i] == ']') or (ch == '{' and s[i] == '}') or (ch == '<' and s[i] == '>'))
				change = change + 1
			end
	end

end

if not RBS.empty?
	puts "Impossible"
else
	puts change
end

ans=0
s=[]
def type_of b
	case b
	when ?<,?{,?[,?(
		:opening
	when ?>,?},?],?)
		:closing
	end
end

def is_paired?(o,c)
	case o
	when ?<
		c==?>
	when ?{
		c==?}
	when ?[
		c==?]
	when ?(
		c==?)
	end
end

while c=STDIN.getc
	if type_of(c)==:opening
		s.push c
	elsif type_of(c)==:closing
		o=s.pop
		unless o
			puts "Impossible"
			exit
		end
		ans+=1 unless is_paired?(o,c)
	end
end

puts s.empty? ? ans : "Impossible"

str = gets.chomp

stack = []
res = 0
hash = {
  ')' => '(',
  '>' => '<',
  ']' => '[',
  '}' => '{'
}

str.each_char do |c|
  case c
  when '(', '{', '<', '[' then stack.push c
  when ')'
    res = 'Impossible' and break if (stack.length==0)
    res += 1 if stack[-1]!='('
    stack.pop
  when '}'
    res = 'Impossible' and break if (stack.length==0)
    res += 1 if stack[-1]!='{'
    stack.pop
  when '>'
    res = 'Impossible' and break if (stack.length==0)
    res += 1 if stack[-1]!='<'
    stack.pop
  when ']'
    res = 'Impossible' and break if (stack.length==0)
    res += 1 if stack[-1]!='['
    stack.pop
  end
end

if stack.length==0
  puts res
else
  puts 'Impossible'
end

s = gets.strip.split ''

brk =Array.new(4, 0)
right = {'>' => 0, '}' => 1, ']' => 2, ')' => 3}
left = {'<' => 0, '{' => 1, '[' => 2, '(' => 3}
res = 0

s.each do |e|
	if right.include? e
		if brk.none?{|i| i > 0}
			res = -1
			break
		end

		if brk[right[e]] != 0
			brk[right[e]] -= 1
		else
			res += 1
			brk[brk.find_index{|e| e != 0}] -= 1
		end
	else left.include? e
			brk[left[e]] += 1
	end
end

if res == -1 or brk.any?{|e| e != 0}
	puts 'Impossible'
else
	puts res
end

ans=0
s=[]
def type_of b
	case b
	when ?<,?{,?[,?(
		:opening
	when :>,?},?],?)
		:closing
	end
end

def is_paired?(o,c)
	case o
	when ?<
		c==?>
	when ?{
		c==?}
	when ?[
		c==?]
	when ?(
		c==?)
	end
end

while c=STDIN.getc
	if type_of(c)==:opening
		s.push c
	elsif type_of(c)==:closing
		o=s.pop
		unless o
			puts "Impossible"
			exit
		end
		ans+=1 unless is_paired?(o,c)
	end
end

puts s.empty? ? ans : "Impossible"

ans=0
s=[]
def type_of b
	case b
	when ?<,?{,?[,?(
		:opening
	when ?>,?},?],?)
		:closing
	end
end

def is_paired?(o,c)
	case o
	when ?<
		c==?>
	when ?{
		c==?}
	when ?[
		c==?]
	when ?(
		c==?)
	end
end

while c=STDIN.getc
	p type_of(c)
	if type_of(c)==:opening
		s.push c
	elsif type_of(c)==:closing
		o=s.pop
		unless o
			puts "Impossible"
			exit
		end
		ans+=1 unless is_paired?(o,c)
	end
end

puts s.empty? ? ans : "Impossible"


n,k=gets.chomp.split.collect{|a| a.to_i}
arr=gets.chomp.split.collect{|a| a.to_i}.sort
set={}
arr.each{|a| if a%k!=0 || set[a/k]== nil then set[a]=true end }
puts set.size

#!/usr/bin/ruby1.9

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

a.sort!
index = {}
a.length.times {|i| index[a[i]] = i }

count = 0
a.length.times do |i|
	next if a[i] < 0
	count += 1
	j = index[k*a[i]]
	a[i] *= -1
	if j != nil
		a[j] *= -1
	end
end

puts count

require 'set'
nk = gets.split(' ').collect!{|i| i.to_i}
n = nk[0]
k = nk[1]

a = gets.split(' ').collect!{|i| i.to_i}.sort!

# ak = []
# size = 0
# a.each do |i|
# 	if !ak.include?(i)
# 		ak << i*k
# 		size += 1
# 	end
# end

# puts size
s = Set.new
a.each do |i|
	s << i*k if !s.include?(i)
end

p s.size

# require 'set'
nk = gets.split(' ').collect!{|i| i.to_i}
n = nk[0]
k = nk[1]

a = gets.split(' ').collect!{|i| i.to_i}.sort!

# s = Set.new
s = {}
b = 0
a.each do |i|
	if !s.include?(i)
		s[i*k] = b
		b += 1
	end
end

p b

def binary_search(ary, x)

  n = ary.size
  left  = 0
  right = n - 1

  while left <= right
    mid = (left + right) / 2

    case ary[mid] <=> x
    when 0
      return mid
    when 1
      right = mid - 1
    when -1
      left  = mid + 1
    end
  end

  return -1
end

n, k = gets.split.map &:to_i
ary  = gets.split.map(&:to_i).sort
aryc = Array.new(n, 0)
ans  = 0

for i in 0 .. n - 1 do

  if aryc[i] == 1 then next end
  aryc[i] = 1

  tmp = ary[i]
  cnt = 1

  while tmp <= ary[n - 1]
    if k == 1 then break end
    tmp *= k
    check = binary_search(ary, tmp)
    if check > -1
      aryc[check] = 1
      cnt += 1
    else
      break
    end
  end

  ans += (cnt + 1) / 2
end

puts ans

a,k={},gets.split.map(&:to_i)[1]
gets.split.map(&:to_i).sort.each{|i|a[i]=1 if i%k>0||!a[i/k]}
p a.size

k=gets.split.map(&:to_i)[1]
a,ans={},0
gets.split.map(&:to_i).sort.each{|i|a[i]=1}
a.each do |key,v|
  next if v==0
  ans+=1
  a[key*k]-=1 if a[k*key]
end
p ans

nk = gets.split(' ').collect!{|i| i.to_i}
n = nk[0]
k = nk[1]

a = gets.split(' ').collect!{|i| i.to_i}.sort!

# ak = []
# size = 0
# a.each do |i|
# 	if !ak.include?(i)
# 		ak << i*k
# 		size += 1
# 	end
# end

# puts size
s = []
a.each do |i|
	s << i if !s.include?(i/k)
end

p s.size

def binary_search(ary, x)

  n = ary.size
  left  = 0
  right = n - 1

  while left <= right
    mid = (left + right) / 2

    case ary[mid] <=> x
    when 0
      return mid
    when 1
      right = mid - 1
    when -1
      left  = mid + 1
    end
  end

  return -1
end

n, k = gets.split.map &:to_i
ary  = gets.split.map(&:to_i).sort
aryc = Array.new(n, 0)
ans  = 0

for i in 0 .. n - 1 do

  if k == 1 then break end

  if aryc[i] == 1 then next end
  aryc[i] = 1

  tmp = ary[i]
  cnt = 1

  while tmp <= ary[n - 1]
    tmp *= k
    check = binary_search(ary, tmp)
    if check > -1
      aryc[check] = 1
      cnt += 1
    else
      break
    end
  end

  ans += (cnt + 1) / 2
end

puts ans

def binary_search(ary, x)
n = ary.size
left = 0
right = n - 1
while left < right
mid = (left + right) / 2
case ary[mid] <=> x
when 0
return mid
when 1
right = mid
when -1
left  = mid + 1
end
end
return -1
end

n, k = gets.split.map &:to_i
ary = gets.split.map(&:to_i).sort
aryc = Array.new(n, 0)
ans = 0

for i in 0 .. n - 1 do
if aryc[i] == 1 then next end
aryc[i]= 1
tmp = ary[i]
cnt = 1
while tmp <= ary[n - 1]
tmp *= k
check = binary_search(ary, tmp)
if check > -1
break
else
aryc[check] = 1
cnt += 1
end
end
ans += cnt/2
end

puts ans


gets.to_i.times do
  a = []
  b = []
  m = 9
  gets.chomp!.chars.map!(&:to_i).reverse_each do |c|
    m = c if m > c
    if m == c
      a << c
    else
      b << c
    end
  end
  a += b.map! { |e| e == 9 ? 9 : e + 1 }
  puts a.sort!.join
end

gets.to_i.times do
  s = gets.chomp!.chars.map!(&:to_i).reverse!
  a = []
  b = []
  m = 9
  s.each do |c|
    m = c if m > c
    if m == c
      a << c
    else
      b << c
    end
  end
  a += b.map! { |e| e == 9 ? 9 : e + 1 }
  puts a.sort!.join
end

gets.to_i.times do
  m = 9
  puts (gets.chomp!.chars.map!(&:to_i).reverse_each.map do |c|
    if m >= c
      m = c
      c
    elsif c == 9
      c
    else
      c + 1
    end
  end.sort!.join)
end

gets.to_i.times do
  a = []
  b = []
  m = 9
  puts (gets.chomp!.chars.map!(&:to_i).reverse_each.map do |c|
    if m >= c
      m = c
      c
    elsif c == 9
      c
    else
      c + 1
    end
  end.sort!.join)
end

gets.to_i.times do
  a = []
  b = []
  m = 9
  gets.chomp!.chars.map!(&:to_i).reverse_each do |c|
    if m >= c
      m = c
      a << c
    else
      b << c
    end
  end
  a += b.map! { |e| e == 9 ? 9 : e + 1 }
  puts a.sort!.join
end

gets.to_i.times do
  a = []
  b = []
  m = 9
  gets.chomp!.chars.map!(&:to_i).reverse_each do |c|
    if m >= c
      c = m
      a << c
    else
      b << c
    end
  end
  a += b.map! { |e| e == 9 ? 9 : e + 1 }
  puts a.sort!.join
end

gets.to_i.times do
  s = gets.chomp!.chars.map!(&:to_i)
  a = []
  (0..9).each do |i|
    break if s.empty?
    c = s.count(i)
    if c != 0
      j = s.rindex(i)
      s = s[(j + 1)..-1] + s[0...j].map! do |e|
        if e == i || e == 9
          e
        else
          e + 1
        end
      end.tap { |s| s.delete(i) }.sort!
      a += [i] * c
    end
  end
  puts a.join
end


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

hs = Hash.new(0)

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

i = 0
j = 0
ok = false
while i < a.size
    if i - 1 >= 0
        ok = false if hs[a[i-1]] == m
        hs[a[i-1]] -= 1
    end

    until ok or j == a.size
        ok = true if (hs[a[j]] += 1) == m
        j += 1
    end
    ans += a.size - j + 1 if ok
#p [i,j,ans]
#    p hs
    i += 1
end

puts ans

n,m=gets.split.map &:to_i;a=gets.split.map &:to_i;h=Hash.new 0;j,z=-1,0;n.times{|i|h[a[j+=1]]+=1 until h[a[j]]>=m||j==n;z+=n-j;h[a[i]]-=1;};p z

n,m=gets.split.map &:to_i;a=gets.split.map &:to_i;h=Hash.new 0;j,z=-1,0;n.times{|i|h[i]-=1;h[a[j+=1]]+=1 until h[a[j]]>=m||j==n;z+=n-j};p z


s = gets.chomp.chars.map &:ord
t = gets.chomp
bads = [0]*97 + t.chars.map{ |i| i == ?0 }
k = gets.to_i

ans = 0
pre = []

for x in (0...s.length).map{ |i| s[i..-1] }.sort
    h = pre.zip(x).take_while{ |i, j| i == j }.length
    p = 0
    x.each_with_index do |c, i|
		p += 1 if bads[c]
        next if i < h
		break if p > k
		ans += 1
    end
	pre = x
end

puts ans

s = gets.chomp.chars.map{ |i| i.ord - 97 }
bads = gets.chomp.chars.map{ |i| i == ?0 }
k = gets.to_i

ans = 0
pre = []

for x in (0...s.length).map{ |i| s[i..-1] }.sort
    h = pre.zip(x).take_while{ |i, j| i == j }.length
    p = 0
    x.each_with_index do |c, i|
		break if k < p += 1 if bads[c]
        ans += 1 unless i < h
    end
	pre = x
end

puts ans

require "Set"

string = gets.chomp.chars.map &:ord
bads = [0]*97 + gets.chomp.chars.map{ |i| 1 - i.to_i }
limit = gets.to_i

zo = string.map{ |i| bads[i] }

left = 0
right = -1
n = 0

h = Set.new

loop do
    for i in left+1..right
        h.add string[i..right]
    end
    break if string.length == right += 1
    if limit < n += bads[string[right]]
        n = limit
        left += zo[left..right].index(1) + 1
    end
    h.add string[left..right]
end

puts h.size


n = gets.to_i
ds = gets.split.map(&:to_i)
s, t = gets.split.map(&:to_i).sort
if s == t
  puts 0
  exit
end
sum = ds.inject{|m,i|m+i}
dis = ds[s-1,t-s].inject{|m,i|m+i}
puts [dis, sum - dis].min

n = gets.to_i
ar = [0] + gets.split(' ').map(&:to_i)
s, t = gets.split(' ').map(&:to_i).minmax
v1 = ar.inject(:+)
v2 = ar[s...t].inject(0,:+)
puts [v1-v2, v2].min

n = gets.to_i
d = gets.split.map{|i| i.to_i}
s,t = gets.split.map{|i| i = i.to_i - 1}
res1 = 0
res2 = 0

if s > t then
    k = t
    while k < s do
        res1 += d[k]
        k += 1
    end
    while k < n do
        res2 += d[k]
        k += 1
    end
    k = 0
    while k < t do
        res2 += d[k]
        k += 1
    end
else
    k = s
    res1 = 0
    while k < t do
        res1 += d[k]
        k += 1
    end
    while k < n do
        res2 += d[k]
        k += 1
    end
    k = 0
    while k < s do
        res2 += d[k]
        k += 1
    end
end

puts [res1, res2].min

class Array
  def sum
    self.inject{|sum, x| sum + x}
  end
end
num = gets.chomp.to_i
dis = gets.chomp.split(" ").map {|x| x.to_i}
tmp = gets.chomp.split(" ")
a = tmp[0].to_i
b = tmp[1].to_i
if a > b
  a,b = b,a
end
r1 = 0
for i in a-1..b-2
  r1 += dis[i]
end

if r1 < dis.sum-r1
  puts r1
else
  puts dis.sum-r1
end

n = gets.to_i
d = gets.split(' ').map(&:to_i)
s, t = gets.split(' ').map(&:to_i)
if t < s
  s , t = t, s
end
l1 , l2 = 0, 0

for i in 0..d.size - 1 do
  if (i < s - 1) || (i > t - 2)
    l1 += d[i]
  else
    l2 += d[i]
  end
end

puts (if l1 < l2 then l1 else l2 end)

n = gets.chomp.to_i
d = gets.chomp.split(" ").map{|x| x.to_i}
s,j = gets.chomp.split(" ").map{|x| x.to_i}.sort

sum1 = 0
(s-1..j-2).each do |i|
  sum1 += d[i]
end

sum2 = 0
(0..s-2).each do |i|
  sum2 += d[i]
end

(j-1..n-1).each do |i|
  sum2 += d[i]
end

puts [sum1,sum2 ].min

num_stations = gets.to_i
stations = gets.split.collect {|i| i.to_i}
req_stations = gets.split.collect {|i| i.to_i}
total_distance = stations.inject(:+)
distance = 0
first = req_stations.min
last = req_stations.max
for i in first-1...last-1
	distance = distance + stations[i]
end
puts [distance,total_distance-distance].min

n = gets.to_i
dis = Array.new(n+1, 0)
d = gets.split.map(&:to_i)
for i in 1..n
  dis[i] = dis[i-1]+d[i-1]
end
a = gets.split.map(&:to_i)
A = (a.min) -1
B = (a.max) -1
puts [dis[B] - dis[A], (dis[n]-dis[B]) + dis[A]].min

#!/usr/bin/ruby

n = STDIN.readline.to_i

distances = STDIN.readline.split.collect {|s| s.to_i}
total = distances.inject {|sum, x| sum += x }

limits = STDIN.readline.split.collect {|s| s.to_i}
limits.sort!

sum = 0
((limits[0]-1)..(limits[1]-2)).each do |i|
	sum += distances[i]
end
puts [sum, total-sum].min

l = gets.chomp.to_i
arr = gets.chomp.split(' ').map(&:to_i)
s, t = gets.chomp.split(' ').map(&:to_i).sort

s -= 1
t -= 1

l1 = l2 = 0

s.upto(t-1).each do |ind|
  l1 += arr[ind]
end

(s-1).downto(0).each do |ind|
  l2 += arr[ind]
end

t.upto(l-1).each do |ind|
  l2 += arr[ind]
end

#puts l1, l2, s ,t
puts l1 > l2 ? l2 : l1

def run
  n = ARGF.readline.to_i
  d = ARGF.readline.split.map(&:to_i)
  t, s = ARGF.readline.split.map(&:to_i)

  positive = 0
  cur = t - 1
  while cur != (s - 1)
    positive += d[cur]
    cur = (cur + 1) % n
  end

  negative = 0
  cur = t - 1
  while cur != (s - 1)
    cur = (cur + n - 1) % n
    negative += d[cur]
  end

  puts [positive, negative].min
end

run if $0 == __FILE__

def run
  n = ARGF.readline.to_i
  d = ARGF.readline.split.map(&:to_i)
  t, s = ARGF.readline.split.map(&:to_i)

  sum = 0
  cur = t - 1
  while cur != (s - 1)
    sum += d[cur]
    cur = (cur + 1) % n
  end

  puts [sum, d.reduce(:+) - sum].min
end

run if $0 == __FILE__

a=gets.chomp.to_i
b=gets.chomp.split(" ")
0.upto(a-1) {|i| b[i]=b[i].to_i}
d=gets.chomp.split(" ")
0.upto(1) {|i| d[i]=d[i].to_i}
d.sort!
ans1=0
ans2=0

(d[0]-1).upto(d[1]-2) {|i| ans1+=b[i]}
if d[0]!=1
0.upto(d[0]-2) {|i| ans2+=b[i]}
end
(a-1).downto(d[1]-1 ){|i| ans2+=b[i]}
if ans1<ans2
puts "#{ans1}"
else
puts "#{ans2}"
end

n=gets.to_i
xs=gets.split.map{|e| e.to_i}
a,b=gets.split.map{|e| e.to_i}
c=[a,b].min
d=[a,b].max

sum=0
xs.each{|e| sum+=e}

sum2=0
((c-1)..(d-2)).each{|i|
	sum2+=xs[i]
}
puts [sum2,sum-sum2].min

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

n = gets.to_i
stops = gets.split.map(&:to_i)
a, b = gets.split.map(&:to_i)
from, to = [a, b].min - 1, [a, b].max - 1

total_weight = stops.inject(0, :+)
from_a_to_b = stops[from...to].inject(0, :+)

print [total_weight - from_a_to_b, from_a_to_b].min

n=gets.to_i
a=gets.split.map(&:to_i)
s,t=gets.split.map(&:to_i)
s-=1
t-=1
i,k=s,0
while i!=t do
    k+=a[i]
    i=(i+1)%n
end
res=k
i,k=s,0
while i!=t do
    k+=a[(i-1+n)%n]
    i=(i-1+n)%n
end
puts [res, k].min

n = Integer(gets)
input = gets.chomp
nums = input.split
d = Array.new
for i in 0...n
    d[i] = Integer(nums[i])
end
input2 = gets.chomp
num = input2.split
s = Integer(num[0])
t = Integer(num[1])
sum = 0
for i in 0...n
    sum = sum + d[i]
end
sov = 0
if s <= t
    for i in s-1...t-1
        sov = sov + d[i]
    end
else
    for i in t-1...s-1
        sov = sov + d[i]
    end
end
sov2 = sum - sov
if sov >= sov2
    puts sov2
else
    puts sov
end

n = gets.to_i
d = gets.split(' ').collect!{|i| i.to_i}

s, t = gets.split(' ').collect!{|i| i.to_i - 1}.sort

sum = 0
sum1 = 0
d.each_index do |i|
	sum += d[i]
	sum1 += d[i] if i >= s && i < t
end
sum2 = sum - sum1

p [sum1, sum2].min

gets
ds = gets.split.map(&:to_i)
s, t = gets.split.map(&:to_i)

s, t = [s, t].sort

first = ds[(s-1)..(t-2)].reduce(:+) || 0
second = ds.reduce(:+) - first
p [first, second].min

n = gets.chomp.to_i
arr = gets.split(" ").collect! {|x| x.to_i}
s1,t1 = gets.split(" ").collect! {|x| x.to_i}
sum = 0
arr.each {|v|
	sum += v
}

f = 0
s = [s1,t1].min
t = [s1,t1].max
arr[(s-1)...(t-1)].each {|w|
	f += w
}

puts [f,sum-f].min

n = gets.to_i;
a = gets.split.map(&:to_i);
sum = a.inject(:+);
acc = 0;
d = [0].concat(a.map {|x| acc += x})
s, t = gets.split.map(&:to_i);
s, t = t, s if t < s
p ([d[t-1]-d[s-1], sum - d[t-1] + d[s-1]].min)

n = Integer(gets.chomp)
d = gets.chomp.split.map { |x| x.to_i }
s, t = gets.chomp.split.map { |x| x.to_i }.sort
puts(s == t ? 0 : [d[s - 1...t - 1], d[t - 1...n] + d[0...s - 1]].map { |a| a.inject(:+) }.min)

gets
ds = gets.split.map(&:to_i)
ps = gets.split.map(&:to_i).map(&:pred)
p [ds.slice!(ps.min, ps.reduce(&:-).abs), ds].map { |i|
  (i || []).reduce(&:+).to_i
}.min

n = Integer(gets)
input = gets.chomp
nums = input.split
d = Array.new
for i in 0...n
	d[i] = Integer(nums[i])
end
input2 = gets.chomp
num = input2.split
s = Integer(num[0])
t = Integer(num[1])
sum = 0
for i in 0...n
	sum = sum + d[i]
end
sov = 0
for i in s-1...t-1
	sov = sov + d[i]
end
sov2 = sum - sov
if sov >= sov2
	puts sov2
else
	puts sov
end

n = gets.to_i
d = gets.split(' ').collect!{|i| i.to_i}

s, t = gets.split(' ').collect!{|i| i.to_i}.sort

rast1 = 0
(s..(t-1)).each do |x|
	rast1 += d[x-1]
end

rast2 = 0
if s > 1
	(0..(s-1)).each do |x|
		rast2 += d[x-1]
	end
end

(t..n).each do |x|
	rast2 += d[x-1]
end

if rast1 < rast2
	p rast1
else
	p rast2
end

n = gets.to_i
d = gets.split(' ').collect!{|i| i.to_i}

s, t = gets.split(' ').collect!{|i| i.to_i}.sort

if t > s
	rast1 = 0

	(s..(t-1)).each do |x|
		rast1 += d[x-1]
	end

	rast2 = 0
	if s > 1
		(0..(s-1)).each do |x|
			rast2 += d[x-1]
		end
	end

	(t..n).each do |x|
		rast2 += d[x-1]
	end

	if rast1 < rast2
		p rast1
	else
		p rast2
	end
else
	p 0
end

gets
ds = gets.split.map(&:to_i)
s, t = gets.split.map(&:to_i)

first = ds[(s-1)..(t-2)].reduce(:+) || 0
second = ds.reduce(:+) - first
p [first, second].min

gets
ds = gets.split.map(&:to_i)
ps = gets.split.map(&:to_i).map(&:pred)
puts [ds.rotate!(-ds[0]).slice!(0, ps.reduce(&:-).abs), ds].map { |i|
  (i || []).reduce(&:+)
}.min

l = gets.chomp.to_i
arr = gets.chomp.split(' ').map(&:to_i)
s, t = gets.chomp.split(' ').map(&:to_i).sort

s -= 1
t -= 1

l1 = l2 = 0

s.upto(t-1).each do |ind|
  l1 += arr[ind]
end

s.downto(0).each do |ind|
  l2 += arr[ind]
end

t.upto(l-1).each do |ind|
  l2 += arr[ind]
end

puts l1 > l2 ? l2 : l1


def reverse_signs(s)
	case s
	when ">="
		return "<"
	when ">"
		return "<="
	when "<"
		return ">="
	when "<="
		return ">"
	end

end

def calc(s,no,start,finish)
	case s
	when ">="
		start = no if no > start
	when ">"
		start = no + 1 if no + 1 > start
	when "<"
		finish = no - 1 if no - 1 < finish
	when "<="
		finish = no	if no < finish
	end
	return start,finish
end

n = gets.to_i
start = -(10 ** 9) * 2
finish = (10 ** 9) * 2

n.times do
	s,no,ans = gets.split(" ")
	no = no.to_i
	# puts "#{s},#{no},#{ans}"
	if ans == "Y"
		# puts "here"
		start,finish =  calc(s,no,start,finish)
		# puts "#{start},#{finish}"
	else
		start,finish =  calc(reverse_signs(s),no,start,finish)
	end
end
# puts start
# puts finish
if start <= finish
	puts "#{start}"
else
	puts "Impossible"
end

a = 2 * -10 ** 9
b = 2 * 10 ** 9
n = gets.to_i
t = { ">=" => "<", "<=" => ">", ">" => "<=", "<" => ">=" }
n.times do
	s, c, an = gets.split
	s = t[s] if an.chomp == "N"
	c = c.to_i
	case s
		when ">="
			a = c if c > a
		when ">"
			a = c + 1 if c + 1 > a
		when "<="
			b = c if c < b
		when "<"
			b = c - 1 if c - 1 < b
	end
end

puts a if (a..b).size.nonzero?
puts "Impossible" if (a..b).size.zero?

#f = File.open('test1.txt', 'r')
f = STDIN

n = f.gets.chomp.to_i
left, right = -2_000_000_000, 2_000_000_000
op = {
  ">" => "<=",
  "<" => ">=",
  ">=" => "<",
  "<=" => ">"
}
n.times do
  sign, x, answer = f.gets.chomp.split
  sign = op[sign] if answer == 'N'
  case sign
    when '<' #
      right = [right, x.to_i - 1].min
    when '>' #
      left = [left, x.to_i + 1].max
    when '<=' #
      right = [right, x.to_i].min
    when '>=' #
      left = [left, x.to_i].max
  end
end

puts (left <= right ? left : 'Impossible')

#!/usr/bin/ruby
A=['>','<','<=','>=']
min=-10**9-1
max=10**9+1
gets.to_i.times{
line=gets.chomp.split
line[0]=A.index(line[0])
line[0]^=2 if line[2]=='N'
line[1]=line[1].to_i
if line[0]==0
	min=[line[1]+1,min].max
elsif line[0]==1
	max=[line[1]-1,max].min
elsif line[0]==2
	max=[line[1],max].min
else
	min=[line[1],min].max
end
}
puts min<=max ? min : 'Impossible'

mn = -0x3f3f3f3f
mx = -mn
gets.to_i.times do
	op, x, ans = gets.split
	x = x.to_i
	(op = "<") && (x = x + 1) if op == "<="
	(op = ">=") && (x = x + 1) if op == ">"
	if op == ">=" && ans == "Y" || op == "<" && ans == "N"
		mn = [mn, x].max
	else
		mx = [mx, x-1].min
	end
end
puts mn <= mx ? mn : "Impossible"

min = 10 ** 9 * (-2)
max = 10 ** 9 * 2

increase_min = proc { |num| min = (min >= num) ? min : num }
decrease_max = proc { |num| max = (max <= num) ? max : num }

n = gets.chomp.to_i
n.times do
    sign, num, answer = gets.chomp.split
    num = num.to_i

    case sign
    when ">"
        increase_min[num + 1] if answer == "Y"
        decrease_max[num] if answer == "N"
    when ">="
        increase_min[num] if answer == "Y"
        decrease_max[num - 1] if answer == "N"
    when "<"
        decrease_max[num - 1] if answer == "Y"
        increase_min[num] if answer == "N"
    when "<="
        decrease_max[num] if answer == "Y"
        increase_min[num + 1] if answer == "N"
    end
end

if min > max
    print "Impossible"
else
    print min
end

class ProblemA
  INF = 2e9.to_i

  def initialize
    @dats = STDIN.read.split("\n")
    @min, @max = -INF, INF
    @qnum = @dats[0].to_i
  end

  def solve
    possible = true
    (1..@qnum).each do |row|
      question = @dats[row]
      operator, num, ans = question.split(" ").map {|s| s = s.gsub(" ", "")}
      num = num.to_i

      ret = case operator
            when ">="
              ans == "Y" ? update(operator, num) : update("<", num)
            when "<="
              ans == "Y" ? update(operator, num) : update(">", num)
            when ">"
              ans == "Y" ? update(operator, num) : update("<=", num)
            when "<"
              ans == "Y" ? update(operator, num) : update(">=", num)
            end
      (possible = false and break) unless ret
    end
    if possible
      print @min
    else
      print "Impossible"
    end
  end

  def update(operator, num)
    case operator
    when ">="
      @min = num if @min < num
    when "<="
      @max = num if @max > num
    when ">"
      @min = num+1 if @min < num+1
    when "<"
      @max = num-1 if @max > num-1
    end
    @min > @max ? false : true
  end
end

solver = ProblemA.new
solver.solve

n = gets.chomp.to_i
max = (10 ** 9) * 2
min = -max
n.times do
    sign, x, ans = gets.chomp.split(/ /)
    x = x.to_i
    if ans == "N"
        case sign
        when '>'
            sign = '<='
        when '>='
            sign = '<'
        when '<'
            sign = '>='
        when '<='
            sign = '>'
        end
    end
    case sign
    when '>='
        min = [min, x].max
    when '>'
        min = [min, x + 1].max
    when '<'
        max = [max, x - 1].min
    when '<='
        max = [max, x].min
    end
end
if min <= max
    puts min
else
    puts "Impossible"
end

n = gets.chomp.to_i

a = 2*-10e8
b = 2* 10e8
n.times do |e|
	s = gets.chomp
	re = /^([>=<]{1,2})\s([-]?\d*)\s([YN])$/
	md = re.match(s)

	token = md[1]
	if md[3] =~ /^N/
		token = '>=' if md[1] == '<'
		token = '<=' if md[1] == '>'
		token = '<'  if md[1] == '>='
		token = '>'  if md[1] == '<='
	end

	if token[0] == '<'
		if b >= md[2].to_i
			b = md[2].to_i - 1

			b += 1 if token.length > 1
		end
	end

	if token[0] == ('>')
		if a <= md[2].to_i
			a = md[2].to_i + 1

			a -= 1 if token.length > 1
		end
	end
end

if a > b
	puts "Impossible"
else
	puts Random.rand(a..b).to_i
end

#!/usr/bin/ruby
A=['>','<','<=','>=']
min=-10**9
max=10**9
gets.to_i.times{
line=gets.chomp.split
line[0]=A.index(line[0])
line[0]^=2 if line[2]=='N'
line[1]=line[1].to_i
if line[0]==0
	min=line[1]+1
elsif line[0]==1
	max=line[1]-1
elsif line[0]==2
	max=line[1]
else
	min=line[1]
end
}
puts min<=max ? min : 'Impossible'

#!/usr/bin/ruby
A=['>','<','<=','>=']
min=-10**9
max=10**9
gets.to_i.times{
line=gets.chomp.split
line[0]=A.index(line[0])
line[0]^=2 if line[2]=='N'
line[1]=line[1].to_i
if line[0]==0
	min=[line[1]+1,min].max
elsif line[0]==1
	max=[line[1]-1,max].min
elsif line[0]==2
	max=[line[1],max].min
else
	min=[line[1],min].max
end
}
puts min<=max ? min : 'Impossible'

min = 10 ** 9 * (-1)
max = 10 ** 9

n = gets.chomp.to_i
n.times do
    sign, num, answer = gets.chomp.split
    next if answer == "N"

    num = num.to_i
    case sign
    when ">"
        min = (min > num) ? min : num + 1
    when "<"
        max = (max < num) ? max : num - 1
    when ">="
        min = (min >= num) ? min : num
    when "<="
        max = (max <= num) ? max : num
    end
end

if min > max
    print "Impossible"
else
    print min
end

min = 10 ** 9 * (-1)
max = 10 ** 9

increase_min = proc { |num| min = (min >= num) ? min : num }
decrease_max = proc { |num| max = (max <= num) ? max : num }

n = gets.chomp.to_i
n.times do
    sign, num, answer = gets.chomp.split
    num = num.to_i

    case sign
    when ">"
        increase_min[num + 1] if answer == "Y"
        decrease_max[num] if answer == "N"
    when ">="
        increase_min[num] if answer == "Y"
        decrease_max[num - 1] if answer == "N"
    when "<"
        decrease_max[num - 1] if answer == "Y"
        increase_min[num] if answer == "N"
    when "<="
        decrease_max[num] if answer == "Y"
        increase_min[num + 1] if answer == "N"
    end
end

if min > max
    print "Impossible"
else
    print min
end

class ProblemA
  INF = 2e10
  def initialize
    @dats = STDIN.read.split("\n")
    @min, @max = -INF, INF
    @qnum = @dats[0].to_i
  end

  def solve
    possible = true
    (1..@qnum).each do |row|
      question = @dats[row]
      operator, num, ans = question.split(" ").map {|s| s = s.gsub(" ", "")}
      num = num.to_i

      ret = case operator
            when ">="
              ans == "Y" ? update(operator, num) : update("<", num)
            when "<="
              ans == "Y" ? update(operator, num) : update(">", num)
            when ">"
              ans == "Y" ? update(operator, num) : update("<=", num)
            when "<"
              ans == "Y" ? update(operator, num) : update(">=", num)
            end
      (possible = false and break) unless ret
    end
    if possible
      print @min
    else
      print "Impossible"
    end
  end

  def update(operator, num)
    print "#{operator} #{num}\n"
    case operator
    when ">="
      @min = num if @min < num
    when "<="
      @max = num if @max > num
    when ">"
      @min = num+1 if @min < num+1
    when "<"
      @max = num-1 if @max > num-1
    end
    @min > @max ? false : true
  end
end

solver = ProblemA.new
solver.solve

class ProblemA
  INF = 2e10.to_i

  def initialize
    @dats = STDIN.read.split("\n")
    @min, @max = -INF, INF
    @qnum = @dats[0].to_i
  end

  def solve
    possible = true
    (1..@qnum).each do |row|
      question = @dats[row]
      operator, num, ans = question.split(" ").map {|s| s = s.gsub(" ", "")}
      num = num.to_i

      ret = case operator
            when ">="
              ans == "Y" ? update(operator, num) : update("<", num)
            when "<="
              ans == "Y" ? update(operator, num) : update(">", num)
            when ">"
              ans == "Y" ? update(operator, num) : update("<=", num)
            when "<"
              ans == "Y" ? update(operator, num) : update(">=", num)
            end
      (possible = false and break) unless ret
    end
    if possible
      print @min
    else
      print "Impossible"
    end
  end

  def update(operator, num)
    case operator
    when ">="
      @min = num if @min < num
    when "<="
      @max = num if @max > num
    when ">"
      @min = num+1 if @min < num+1
    when "<"
      @max = num-1 if @max > num-1
    end
    @min > @max ? false : true
  end
end

solver = ProblemA.new
solver.solve

class ProblemA
  INF = 2e10
  def initialize
    @dats = STDIN.read.split("\n")
    @min, @max = -INF, INF
    @qnum = @dats[0].to_i
  end

  def solve
    possible = true
    (1..@qnum).each do |row|
      question = @dats[row]
      operator, num, ans = question.split(" ").map {|s| s = s.gsub(" ", "")}
      num = num.to_i

      ret = case operator
            when ">="
              ans == "Y" ? update(operator, num) : update("<", num)
            when "<="
              ans == "Y" ? update(operator, num) : update(">", num)
            when ">"
              ans == "Y" ? update(operator, num) : update("<=", num)
            when "<"
              ans == "Y" ? update(operator, num) : update(">=", num)
            end
      (possible = false and break) unless ret
    end
    if possible
      print @min
    else
      print "Impossible"
    end
  end

  def update(operator, num)
    case operator
    when ">="
      @min = num if @min < num
    when "<="
      @max = num if @max > num
    when ">"
      @min = num+1 if @min < num+1
    when "<"
      @max = num-1 if @max > num-1
    end
    @min > @max ? false : true
  end
end

solver = ProblemA.new
solver.solve

n = gets.chomp.to_i
max = (10 ** 9) * 2
min = -max
n.times do
    sign, x, ans = gets.chomp.split(/ /)
    x = x.to_i
    if ans == "N"
        case sign
        when '>'
            sign = '<='
        when '>='
            sign = '<'
        when '<'
            sign = '>='
        when '<='
            sign = '>'
        end
    end
    case sign
    when '>='
        min = [min, x].max
    when '>'
        min = [min, x + 1].max
    when '<'
        max = [max, x - 1].min
    when '<='
        max = [max, x].min
    end
end
puts "#{min} #{max}"
if min <= max
    puts min
else
    puts "Impossible"
end

n = gets.chomp.to_i
min = -1000000000
max = -min
n.times do
    sign, x, ans = gets.chomp.split(/ /)
    x = x.to_i
    if ans == "N"
        case sign
        when '>'
            sign = '<='
        when '>='
            sign = '<'
        when '<'
            sign = '>='
        when '<='
            sign = '>'
        end
    end
    case sign
    when '>='
        min = [min, x].max
    when '>'
        min = [min, x + 1].max
    when '<'
        max = [max, x - 1].min
    when '<='
        max = [max, x].min
    end
end
if min <= max
    puts min
else
    puts "Impossible"
end

n = gets.chomp.to_i
min = -1000000000
max = -min
n.times do
    sign, x, ans = gets.chomp.split(/ /)
    x = x.to_i
    if ans == "N"
        case sign
        when '>'
            sign = '<='
        when '>='
            sign = '<'
        when '<'
            sign = '>='
        when '<='
            sign = '>'
        end
    end
    case sign
    when '>', '>='
        min = [min, x].max
    when '<', '<='
        max = [max, x].min
    end
end
if min <= max
    puts min
else
    puts "Impossible"
end

n = gets.chomp.to_i

a = -10e8
b = 10e8
n.times do |e|
	s = gets.chomp
	re = /^([>=<]{1,2})\s([-]?\d*)\s([YN])$/
	md = re.match(s)

	token = md[1]
	if md[3] =~ /^N/
		token = '>=' if md[1] == '<'
		token = '<=' if md[1] == '>'
		token = '<'  if md[1] == '>='
		token = '>'  if md[1] == '<='
	end

	if token[0] == '<'
		if b > md[2].to_i
			b = md[2].to_i - 1
		end

		if token.length > 1
			b += 1
		end
	end

	if token[0].eql?('>')
		if a < md[2].to_i
			a = md[2].to_i + 1
		end

		if token.length > 1
			a -= 1
		end
	end
end

if a > b
	puts "Impossible"
else
	puts Random.rand(a..b).to_i
end

n = gets.chomp.to_i

a = 2*-10e8
b = 10e8
n.times do |e|
	s = gets.chomp
	re = /^([>=<]{1,2})\s([-]?\d*)\s([YN])$/
	md = re.match(s)

	token = md[1]
	if md[3] =~ /^N/
		token = '>=' if md[1] == '<'
		token = '<=' if md[1] == '>'
		token = '<'  if md[1] == '>='
		token = '>'  if md[1] == '<='
	end

	if token[0] == '<'
		if b > md[2].to_i
			b = md[2].to_i - 1

			b += 1 if token.length > 1
		end
	end

	if token[0].eql?('>')
		if a < md[2].to_i
			a = md[2].to_i + 1

			a -= 1 if token.length > 1
		end
	end
end

if a > b
	puts "Impossible"
else
	puts Random.rand(a..b).to_i
end

n = gets.chomp.to_i

a = -10e9
b = 10e9
n.times do |e|
	s = gets.chomp
	re = /^([>=<]{1,2})\s([-]?\d*)\s([YN])$/
	md = re.match(s)
	if md[3] =~ /^Y/
		if md[1][0] == '<'
			if b > md[2].to_i
				b = md[2].to_i - 1
			end

			if md[1].length > 1
				b += 1
			end
		end

		if md[1][0].eql?('>')
			if a < md[2].to_i
				a = md[2].to_i + 1
			end

			if md[1].length > 1
				a -= 1
			end
		end
	end
end

# puts a
# puts b
if a > b
	puts "Impossible"
else
	puts Random.rand(a..b).to_i
end

n = gets.chomp.to_i

a = 2*-10e8
b = 2* 10e8
n.times do |e|
	s = gets.chomp
	re = /^([>=<]{1,2})\s([-]?\d*)\s([YN])$/
	md = re.match(s)

	token = md[1]
	if md[3] =~ /^N/
		token = '>=' if md[1] == '<'
		token = '<=' if md[1] == '>'
		token = '<'  if md[1] == '>='
		token = '>'  if md[1] == '<='
	end

	if token[0] == '<'
		if b > md[2].to_i
			b = md[2].to_i - 1

			b += 1 if token.length > 1
		end
	end

	if token[0].eql?('>')
		if a < md[2].to_i
			a = md[2].to_i + 1

			a -= 1 if token.length > 1
		end
	end
end

if a > b
	puts "Impossible"
else
	puts Random.rand(a..b).to_i
end

n = gets.chomp.to_i

a = -10e8
b = 10e8
n.times do |e|
	s = gets.chomp
	re = /^([>=<]{1,2})\s([-]?\d*)\s([YN])$/
	md = re.match(s)

	token = md[1]
	if md[3] =~ /^N/
		token = '>=' if md[1] == '<'
		token = '<=' if md[1] == '>'
		token = '<'  if md[1] == '>='
		token = '>'  if md[1] == '<='
	end

	if token[0] == '<'
		if b > md[2].to_i
			b = md[2].to_i - 1

			b += 1 if token.length > 1
		end
	end

	if token[0].eql?('>')
		if a < md[2].to_i
			a = md[2].to_i + 1

			a -= 1 if token.length > 1
		end
	end
end

if a > b
	puts "Impossible"
else
	puts Random.rand(a..b).to_i
end

n = gets.chomp.to_i

a = 2*-10e8
b = 2* 10e8
n.times do |e|
	s = gets.chomp
	re = /^([>=<]{1,2})\s([-]?\d*)\s([YN])$/
	md = re.match(s)

	token = md[1]
	if md[3] =~ /^N/
		token = '>=' if md[1] == '<'
		token = '<=' if md[1] == '>'
		token = '<'  if md[1] == '>='
		token = '>'  if md[1] == '<='
	end

	if token[0] == '<'
		if b > md[2].to_i
			b = md[2].to_i - 1

			b += 1 if token.length > 1
		end
	end

	if token[0].eql?('>')
		if a < md[2].to_i
			a = md[2].to_i + 1

			a -= 1 if token.length > 1
		end
	end
end

if a >= b
	puts "Impossible"
else
	puts Random.rand(a..b).to_i
end

n = gets.chomp.to_i

a = -10e9
b = 10e9
n.times do |e|
	s = gets.chomp
	re = /^([>=<]{1,2})\s([-]?\d*)\s([YN])$/
	md = re.match(s)
	if md[3] =~ /^Y/
		if md[1][0] == '<'
			if b > md[2].to_i
				b = md[2].to_i - 1
			end

			if md[1].length > 1
				b += 1
			end
		end

		if md[1][0].eql?('>')
			if a < md[2].to_i
				a = md[2].to_i + 1
			end

			if md[1].length > 1
				a -= 1
			end
		end
	end
end

if a > b
	puts "Impossible"
else
	puts Random.rand(a..b).to_i
end

n = gets.chomp.to_i

a = -10e8
b = 10e8
n.times do |e|
	s = gets.chomp
	re = /^([>=<]{1,2})\s([-]?\d*)\s([YN])$/
	md = re.match(s)
	if md[3] =~ /^Y/
		if md[1][0] == '<'
			if b > md[2].to_i
				b = md[2].to_i - 1
			end

			if md[1].length > 1
				b += 1
			end
		end

		if md[1][0].eql?('>')
			if a < md[2].to_i
				a = md[2].to_i + 1
			end

			if md[1].length > 1
				a -= 1
			end
		end
	end
end

if a > b
	puts "Impossible"
else
	puts Random.rand(a..b).to_i
end

def reverse_signs(s)
	case s
	when ">="
		return "<"
	when ">"
		return "<="
	when "<"
		return ">="
	when "<="
		return ">"
	end

end

def calc(s,no,start,finish)
	case s
	when ">="
		start = no if no > start
	when ">"
		start = no + 1 if no + 1 > start
	when "<"
		finish = no - 1 if no - 1 < finish
	when "<="
		finish = no	if no < finish
	end
	return start,finish
end

n = gets.to_i
start = -10 ** 9
finish = 10 ** 9
n.times do
	s,no,ans = gets.split(" ")
	no = no.to_i
	# puts "#{s},#{no},#{ans}"
	if ans == "Y"
		puts "here"
		start,finish =  calc(s,no,start,finish)
		# puts "#{start},#{finish}"
	else
		start,finish =  calc(reverse_signs(s),no,start,finish)
	end
end
if start <= finish
	puts "#{start}"
else
	puts "Impossible"
end

def reverse_signs(s)
	case s
	when ">="
		return "<"
	when ">"
		return "<="
	when "<"
		return ">="
	when "<="
		return ">"
	end

end

def calc(s,no,start,finish)
	case s
	when ">="
		start = no if no > start
	when ">"
		start = no + 1 if no + 1 > start
	when "<"
		finish = no - 1 if no - 1 < finish
	when "<="
		finish = no	if no < finish
	end
	return start,finish
end

n = gets.to_i
start = -10 ** 9
finish = 10 ** 9
n.times do
	s,no,ans = gets.split(" ")
	no = no.to_i
	# puts "#{s},#{no},#{ans}"
	if ans == "Y"
		# puts "here"
		start,finish =  calc(s,no,start,finish)
		# puts "#{start},#{finish}"
	else
		start,finish =  calc(reverse_signs(s),no,start,finish)
	end
end
if start <= finish
	puts "#{start}"
else
	puts "Impossible"
end

a = -10 ** 9
b = 10 ** 9
n = gets.to_i
t = { ">=" => "<", "<=" => ">", ">" => "<=", "<" => ">=" }
n.times do
	s, c, an = gets.split
	s = t[s] if an.chomp == "N"
	c = c.to_i
	case s
		when ">="
			a = c
		when ">"
			a = c + 1
		when "<="
			b = c
		when "<"
			b = c - 1
	end
end

puts a if (a..b).size.nonzero?
puts "Impossible" if (a..b).size.zero?

a = -10 ** 9
b = 10 ** 9
n = gets.to_i
t = { ">=" => "<", "<=" => ">", ">" => "<=", "<" => ">=" }
n.times do
	s, c, an = gets.split
	s = t[s] if an.chomp == "N"
	c = c.to_i
	case s
		when ">="
			a = c if c > a
		when ">"
			a = c + 1 if c + 1 > a
		when "<="
			b = c if c < b
		when "<"
			b = c - 1 if c - 1 < b
	end
end

puts a if (a..b).size.nonzero? and b >= -10 ** 9 and a <= 10 ** 9
puts "Impossible" unless (a..b).size.nonzero? and b >= -10 ** 9 and a <= 10 ** 9

a = -10 ** 9
b = 10 ** 9
n = gets.to_i
t = { ">=" => "<", "<=" => ">", ">" => "<=", "<" => ">=" }
n.times do
	s, c, an = gets.split
	s = t[s] if an.chomp == "N"
	c = c.to_i
	case s
		when ">="
			a = c if c > a
		when ">"
			a = c + 1 if c + 1 > a
		when "<="
			b = c if c < b
		when "<"
			b = c - 1 if c - 1 < b
	end
end

puts a if (a..b).size.nonzero?
puts "Impossible" if (a..b).size.zero?

a = -10 ** 9 - 1
b = 10 ** 9 + 1
n = gets.to_i
t = { ">=" => "<", "<=" => ">", ">" => "<=", "<" => ">=" }
n.times do
	s, c, an = gets.split
	s = t[s] if an.chomp == "N"
	c = c.to_i
	case s
		when ">="
			a = c if c > a
		when ">"
			a = c + 1 if c + 1 > a
		when "<="
			b = c if c < b
		when "<"
			b = c - 1 if c - 1 < b
	end
end

puts a if (a..b).size.nonzero? and a != -10 ** 9 - 1 and b != 10 ** 9 + 1
puts "Impossible" unless (a..b).size.nonzero? and a != -10 ** 9 - 1 and b != 10 ** 9 + 1

#f = File.open('test1.txt', 'r')
f = STDIN

n = f.gets.chomp.to_i
left, right = -2_000_000_000, 2_000_000_000
op = {
  ">" => "<",
  "<" => ">",
  ">=" => "<=",
  "<=" => ">="
}
n.times do
  sign, x, answer = f.gets.chomp.split
  sign = op[sign] if answer == 'N'
  case sign
    when '<' #
      right = [right, x.to_i - 1].min
    when '>' #
      left = [left, x.to_i + 1].max
    when '<=' #
      right = [right, x.to_i].min
    when '>=' #
      left = [left, x.to_i].max
  end
end

puts (left <= right ? left : 'Impossible')


a = gets.chomp.chars
a[-1] = a[0] = ""
p a.join("").split(", ").uniq.size

require 'set'
s=gets.chomp
s=s.slice(1,s.size-2).split(", ")
puts Set.new(s).count

s = gets.chomp
puts s.gsub("{", "").gsub("}", "").split(",").map(&:strip).uniq.count

s=gets.chomp
s.gsub!('{','').gsub!('}','')
arr = s.split(',').map(&:strip)
co = {}
arr.each do |a|
  if co[a].nil?
    co[a] = 1
  else
  co[a] +=1
  end
end

puts co.keys.length

a=gets.chomp
if a.length==2
	puts "0"
elsif a.length==3
	puts "1"
else
	puts a[1..(a.length-2)].split(",").map{|s| s.lstrip.rstrip}.uniq.length
end

hash = Hash.new(0)
gets.chomp.slice(1...-1).split(/,\s*/).each {|e| hash[e] +=1}
puts hash.length

#!/usr/bin/ruby
p gets.chomp[1...-1].split(', ').uniq.size

a=gets.chomp.split("")
a.delete("{")
a.delete("}")
a.delete(" ")
a.delete(",")
a.uniq!
puts "#{a.length}"

line = gets.chomp
letters = line[1..(line.length - 2)].split(/, /)
letters.uniq!
puts letters.length

ar = gets.chomp.split(/[^[:lower:]]/).select{|x| x.length>0}
hs = Hash.new 0
ar.each{|x| hs[x]+=1}
puts hs.length

#puts "Enter the string\n"
s = gets.chomp.to_s
l = s.length
#puts l
a = [l]
j = 0
for i in 0...l-1 do
    if s[i].ord >= 97 && s[i].ord <= 122
        a[j] = s[i]
        j += 1
        #puts a[j-1]
    end
end

#puts j (size of array a)
if j == 0
    puts 0
elsif j == 1
    puts 1
else
    a =  a.sort
    c = 0
    for k in 0..j do
        if a[k] != a[k+1]
            c += 1
        end
    end
    puts c
end

set = gets.chomp
puts set.tr('{},','').split(' ').uniq.length

require 'set'
puts gets.chomp.gsub(/[{} ]/,"").split(",").to_set.count

#!/usr/bin/env ruby

require 'set'

s = Set.new STDIN.gets.strip[1...-1].split(',').map(&:strip)

puts s.size

require 'set'

set = Set.new
s = gets.chomp
s.gsub!(/{|}| /, "")

s.split(",").each { |c| set << c }
puts set.length

s = gets.chomp
l = s.length
c={}
for i in 0...l
if s[i]=="{" || s[i]=="}"||s[i]==","||s[i]==" " then next
elsif c["#{s[i]}"]==nil then
    c["#{s[i]}"]=1
end
end
puts c.length

array = gets.delete('{}').chomp.split(", ")
puts array.uniq.count

s = gets.chomp
s =  s.delete!  "{, } "
s =  s.chars.uniq
puts s.size

numbers = gets.strip[1..-2].split(', ')

set = Hash.new(0)
numbers.each do |num|
  set[num] += 1
end

puts set.size

input = gets.chomp
letter = input.gsub(/[^a-zA-Z ]/," ").split(" ")
counter = {}
for i in 0...letter.length
	counter[letter[i]] = 1
end
sum = 0
counter.each do |key, value|
	sum += value
end
puts sum

letters = gets
letters = letters.slice(1, letters.length - 3).split(', ')

puts letters.uniq.length

s = $stdin.readline

b = s.scan(/[a-z]/)

puts b.uniq.count

def run
  h = Hash.new(0)
  $stdin.gets.gsub(/[{}]/, "").split(",").map(&:strip).each do |c|
    h[c] += 1 if c != ""
  end
  puts h.size
end

run if $0 == __FILE__

s = gets.chomp()
c = 0
('a'..'z').each do |char|
    if s.include? char
        c += 1
    end
end
puts(c)

puts gets.chomp.gsub(/{|}/, '').split(', ').uniq.count

require 'set'
s=gets
s=s.slice(1,s.size-2).split(", ")
puts Set.new(s).count


n,m,k,l=gets.split.map &:to_i
x=(k+l+m-1)/m
p m*x>n ? -1 : x

N,M,K,L=gets.split.map &:to_i
if M>N
    puts -1
    exit
end
d=N/M
x=N-K
if d*M-K<L
    puts -1
    exit
end
puts (L+K+M-1)/M

#N different collectible coins,
#Ivan has K of them
#M freinds
#L coins from gifts altogether, must be new in Ivan's collection

N, M, K, L = gets.split(" ").map(&:to_i)

#example 1
# N, M, K, L = "20 15 2 3".split(" ").map(&:to_i)
#assert 1

#example 2
# N, M, K, L = "10 11 2 4".split(" ").map(&:to_i)
#assert -1

def condition_all_coins_different( friends, coins_per_friend, total_collectable_coins )
	return false if friends * coins_per_friend > total_collectable_coins
	true
end

def condition_minimum_amount_of_new_coins( minimum_new_coins, total_coins_gifted, total_collectable_coins, already_present_coins )
	#possible_new_coins = total_collectable_coins - already_present_coins
	total_coins_gifted >= minimum_new_coins + already_present_coins
end

coins_per_friend = ( K + L ) / M
until condition_minimum_amount_of_new_coins( L, M * coins_per_friend, N, K )
 #condition_all_coins_different( M, coins_per_friend, N ) and
	coins_per_friend += 1
end

# puts coins_per_friend

if condition_all_coins_different( M, coins_per_friend, N)
	puts coins_per_friend
else
	puts -1
end

n,m,k,l=gets.split.map &:to_i
x=(k+l)/m
p m*x>n ? x : -1

n,m,k,l=gets.split.map &:to_i
x=(k+l)/m
p m*x>n ? -1 : x

n,m,k,l=gets.split.map &:to_i
x=(k+l+m-1)/m
p m*x>n ? x : -1


n = gets.chomp.to_i
colors = gets.chomp.split('')

if n == 1
	puts 0
	exit
end

def getA colors, init
current = init

bWrong = []
rWrong = []

for i in (0...colors.length)
	if current == colors[i]
		bWrong << i if current == 'b'
		rWrong << i if current == 'r'

		current = 'r' if colors[i] == 'b'
		current = 'b' if colors[i] == 'r'
	else
		current = colors[i]
	end
end

swap = 0
change = 0

bWrongSize = bWrong.length
rWrongSize = rWrong.length

until bWrongSize == 0 || rWrongSize == 0
	bWrongSize -= 1
	rWrongSize -= 1
	swap += 1
end

change = bWrongSize + rWrongSize

return swap + change
end

forward = getA colors, 'r'
backward = getA colors, 'b'

#puts forward
#puts backward

puts [forward, backward].min

def func(s, k)
    r=b=i=0
    s.chars{|c|
        r+=1 if c==?r and i%2==k
        b+=1 if c==?b and i%2!=k
        i+=1
    }
    x, y=[r, b].minmax
    y-x+x
end

gets
s=gets.chomp
puts [func(s, 0), func(s, 1)].min

def func(n, s, k)
    r=b=i=0
    s.chars{|c|
        r+=1 if c==?r and i%2==k
        b+=1 if c==?b and i%2!=k
        i+=1
    }
    x, y=[r, b].minmax
    y-x+x
end

n=gets.to_i
s=gets.chomp
puts [func(n, s, 0), func(n, s, 1)].min

#!/usr/local/rvm/rubies/ruby-2.3.0/bin/ruby

class Task2
  attr_accessor :cockroach, :n, :result

  def initialize()
    @n=0
    @cockroach = []
    @result = 0
  end

  def getData()
    ln=$stdin.readline
    @n=ln.chomp.to_i
    tmp=$stdin.readline
    @cockroach = tmp.chomp
  end

  def getFileData()
    file = File.new("test.txt","r")
    ln=file.readline
    @n=ln.chomp.to_i
    tmp=file.readline
    @cockroach = tmp.chomp
  end

  def getResult()
    @result = getSubResult()
    if @n%2 == 1
      @cockroach=@cockroach.reverse
      result = getSubResult()
      @result=[@result,result].min
    end
  end

  def getSubResult()
    result=0
    cnt={rr:0,rb:0,br:0,bb:0}
    (0..@n/2-1).each {|x| cnt[@cockroach[x*2..x*2+1].to_sym]+=1} if @n>1
    # print cnt
    # puts
    # exit(0)
    result = (cnt[:br]>cnt[:rb]) ? cnt[:rb]: cnt[:br]
    lst = (cnt[:br]>cnt[:rb]) ? 'r': 'b'
    result+=[cnt[:rr],cnt[:bb]].min
    delta = [cnt[:rr],cnt[:bb]].max-[cnt[:rr],cnt[:bb]].min
    result+=delta
    result+= (@n%2==1 && @cockroach[@n-1]==lst)?1:0  if cnt[:br]+cnt[:rb]>0
    return result
  end

  def printResult()
    puts @result
  end

  def run()
    if ARGV[0] == 'DEBUG'
      getFileData
    else
      getData
    end
    # print @n
    # print @cockroach
    # puts
    getResult
    printResult
  end

end
if __FILE__ == $0
  pc = Task2.new
  pc.run
end

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

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

c = gets.chop.to_i
word = gets.chop

fb_b = 0
fb_r = 0
fr_b = 0
fr_r = 0

i = 0;
word.chars.each_with_index do |x, i|
    if i.even?
        if x == 'b'
             fr_b += 1
        elsif x == 'r'
            fb_r += 1
        end
    else
        if x == 'b'
            fb_b += 1
        elsif x == 'r'
            fr_r += 1
        end
    end
end

puts min(max(fb_b, fb_r), max(fr_b, fr_r))

gets; s = gets.chomp
def min1(s,k)
  r = b = i = 0
  s.chars{ |c|
    r +=1 if c==?r and i%2 == k
    b +=1 if c==?b and i%2 != k
    i += 1
  }
  x,y = [r,b].minmax
  y-x+x
end
puts [min1(s,0), min1(s,1)].min

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

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

c = gets.chop.to_i
word = gets.chop

bfb = 0
bfr = 0
rfr = 0
rfb = 0

i = 0;
while i < word.size
    if i.even?
        if word[i] == 'b'
            rfr += 1
        elsif word[i] == 'r'
            bfr += 1
        end
    else
        if word[i] == 'b'
            bfr += 1
        elsif word[i] == 'r'
            rfb += 1
        end
    end
    i += 1
end

puts min(max(bfb, bfr), max(rfr, rfb))

c = gets.chop.to_i
word = gets.chop

cnt = { 'r' => 0, 'b' => 0 }

i = 0;
while i < word.size - 1
    if word[i] == word[i+1]
        #puts i
        if i + 2 < word.size && word[i+1] != word[i]
            word[i+1], word[i+2] = word[i+2], word[i+1]
        elsif i + 2 < word.size
            cnt[word[i]] += 1
        else
            cnt[word[i]] += 1
        end
        i += 2
    else
        i += 1
    end
end

puts (cnt['r'] > cnt['b']) ? cnt['r'] : cnt['b']

c = gets.chop.to_i
word = gets.chop

cnt = { 'r' => 0, 'b' => 0 }

k = 0

i = 0;
while i < word.size - 1
    if word[i] == word[i+1]
        #puts i
        if i + 2 < word.size && word[i+1] != word[i+2]
            word[i+1], word[i+2] = word[i+2], word[i+1]
            k += 1
            i += 2
        elsif i + 2 < word.size && word[i+1] == word[i+2]
            cnt[word[i]] += 1
            i += 3
        else
            cnt[word[i]] += 1
            i += 2
        end
    else
        i += 1
    end
end

puts ((cnt['r'] > cnt['b']) ? cnt['r'] : cnt['b']) + k

c = gets.chop.to_i
word = gets.chop

cnt = { 'r' => 0, 'b' => 0 }

k = 0

i = 0;
while i < word.size - 1
    if word[i] == word[i+1]
        #puts i
        if i + 2 < word.size && word[i+1] != word[i+2]
            word[i+1], word[i+2] = word[i+2], word[i+1]
            k += 1
            i += 2
        elsif i + 2 < word.size && word[i+1] == word[i+2]
            cnt[word[i]] += 1
            i += 2
        else
            cnt[word[i]] += 1
            i += 2
        end
    else
        i += 1
    end
end

puts ((cnt['r'] > cnt['b']) ? cnt['r'] : cnt['b']) + k

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

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

c = gets.chop.to_i
word = gets.chop

bfb = 0
bfr = 0
rfr = 0
rfb = 0

i = 0;
while i < word.size
    if i % 2 == 0
        if word[i] == 'b'
            rfr += 1
        elsif word[i] == 'r'
            bfr += 1
        end
    else
        if word[i] == 'b'
            bfr += 1
        elsif word[i] == 'r'
            rfb += 1
        end
    end
    i += 1
end

puts min(max(bfb, bfr), max(rfr, rfb))

c = gets.chop.to_i
word = gets.chop

cnt = { 'r' => 0, 'b' => 0 }

k = 0

i = 0;
while i < word.size - 1
    if word[i] == word[i+1]
        #puts i
        if i + 2 < word.size && word[i+1] != word[i+2]
            word[i+1], word[i+2] = word[i+2], word[i+1]
            k += 1
        elsif i + 2 < word.size
            cnt[word[i]] += 1
        else
            cnt[word[i]] += 1
        end
        i += 2
    else
        i += 1
    end
end

puts ((cnt['r'] > cnt['b']) ? cnt['r'] : cnt['b']) + k

c = gets.chop.to_i
word = gets.chop

cnt = { 'r' => 0, 'b' => 0 }

k = 0

i = 0;
while i < word.size - 1
    if word[i] == word[i+1]
        #puts i
        if i + 2 < word.size && word[i+1] != word[i+2]
            word[i+1], word[i+2] = word[i+2], word[i+1]
            k += 1
            i += 2
        elsif i + 2 < word.size && word[i+1] == word[i+2]
            cnt[word[i]] += 1
            i += 3
        else
            cnt[word[i]] += 1
            i += 2
        end
    else
        i += 2
    end
end

puts ((cnt['r'] > cnt['b']) ? cnt['r'] : cnt['b']) + k

def func(n, s, a)
    res=0
    i=0
    while i<n
        if s[i]!=a[i]
            i+=1 if i+1<n and s[i]!=s[i+1]
            res+=1
        end
        i+=1
    end
    res
end

n=gets.to_i
s=gets.chomp
brbr="br"*n
puts [func(n, s, brbr), func(n, s, brbr.reverse!)].min

def func(n, s, b)
    f=[]
    s.each_with_index{|c, i| f<<(c==b[i])}

    res=0
    j=n-1
    s.each_with_index{|c, i|
        unless f[i]
            while j>i
                j-=1
                break if c!=s[j] and !f[j]
            end
            f[j]=true if j>i
            res+=1
        end
    }
    res
end

n=gets.to_i
s=gets.chomp.chars
brbr="br"*n
puts [func(n, s, brbr), func(n, s, brbr.reverse)].min

n = gets.chomp.to_i
colors = gets.chomp.split('')

if n == 1
	puts 0
	exit
end

current = colors[0]

bWrong = []
rWrong = []

for i in (1...colors.length)
	if current == colors[i]
		bWrong << i if current == 'b'
		rWrong << i if current == 'r'

		current = 'r' if colors[i] == 'b'
		current = 'b' if colors[i] == 'r'
	else
		current = colors[i]
	end
end

swap = 0
change = 0

bWrongSize = bWrong.length
rWrongSize = rWrong.length

until bWrongSize == 0 || rWrongSize == 0
	bWrongSize -= 1
	rWrongSize -= 1
	swap += 1
end

change = bWrongSize + rWrongSize

forward = swap + change

current = colors[colors.length - 1]
bWrong = []
rWrong = []

(colors.length - 2).downto(0).each do |i|
	if current == colors[i]
		bWrong << i if current == 'b'
		rWrong << i if current == 'r'

		current = 'r' if colors[i] == 'b'
		current = 'b' if colors[i] == 'r'
	else
		current = colors[i]
	end
end

swap = 0
change = 0

bWrongSize = bWrong.length
rWrongSize = rWrong.length

until bWrongSize == 0 || rWrongSize == 0
	bWrongSize -= 1
	rWrongSize -= 1
	swap += 1
end

change = bWrongSize + rWrongSize
backward = swap + change

puts [forward, backward].min

n = gets.chomp.to_i
colors = gets.chomp.split('')

if n == 1
	puts 0
	exit
end

def getA colors, init
current = init

bWrong = []
rWrong = []

for i in (1...colors.length)
	if current == colors[i]
		bWrong << i if current == 'b'
		rWrong << i if current == 'r'

		current = 'r' if colors[i] == 'b'
		current = 'b' if colors[i] == 'r'
	else
		current = colors[i]
	end
end

swap = 0
change = 0

bWrongSize = bWrong.length
rWrongSize = rWrong.length

until bWrongSize == 0 || rWrongSize == 0
	bWrongSize -= 1
	rWrongSize -= 1
	swap += 1
end

change = bWrongSize + rWrongSize

return swap + change
end

forward = getA colors, 'r'
backward = getA colors, 'b'

puts [forward, backward].min

n = gets.chomp.to_i
colors = gets.chomp.split('')

current = colors[0]

bWrong = []
rWrong = []

for i in (1...colors.length)
	if current == colors[i]
		bWrong << i if current == 'b'
		rWrong << i if current == 'r'

		current = 'r' if colors[i] == 'b'
		current = 'b' if colors[i] == 'r'
	else
		current = colors[i]
	end
end

swap = 0
change = 0

bWrongSize = bWrong.length
rWrongSize = rWrong.length

until bWrongSize == 0 || rWrongSize == 0
	bWrongSize -= 1
	rWrongSize -= 1
	swap += 1
end

change = bWrongSize + rWrongSize

puts swap + change


require 'scanf'
STDIN.read.split("\n").each do |line|
	num = line
	zeros_count = num.count('0')
	num = num.tr("0", '')
	num = num.sub("1", '')
	num = num.sub("6", '')
	num = num.sub("8", '')
	num = num.sub("9", '')
	num = "" if num == "0"
	reminder = 0
	num.split('').each do |digit|
		reminder *= 10
		reminder += digit.to_i
		reminder %= 7
	end
	reminder = reminder * 10000 % 7
	permutation = case reminder
		when 0
			"8169"
		when 1
			"8196"
		when 2
			"9861"
		when 3
			"8691"
		when 4
			"6891"
		when 5
			"1689"
		when 6
			"6189"
		end
	puts num + permutation + "0" * zeros_count
end

require 'scanf'
STDIN.read.split("\n").each do |line|
	num = line
	zeros_count = num.count('0')
	num = num.tr("0", '')
	num = num.sub("1", '')
	num = num.sub("6", '')
	num = num.sub("8", '')
	num = num.sub("9", '')
	num = "" if num == "0"
	num = num + "0000"
	reminder = 0
	num.split('').each do |digit|
		reminder *= 10
		reminder += digit.to_i
		reminder %= 7
	end
	permutation = case reminder
		when 0
			"8169"
		when 1
			"8196"
		when 2
			"9861"
		when 3
			"8691"
		when 4
			"6891"
		when 5
			"1689"
		when 6
			"6189"
		end
	puts num + permutation + "0" * zeros_count
end


t = gets.to_i
ans = []
t.times do |i|
  n = gets.to_i
  a = gets.chomp.split(" ").map(&:to_i)
  hash = Hash.new(0)
  a.each do |x|
    hash[x] += 1
  end
  max = hash.each_value.max
  num = hash.each_value.count(max)
  if num == 1
    ans << ((n-max) / (max-1))
  elsif max == 2
    ans << n - num - 1
  else
    dis = n - num - 1
    rest = (dis - (max - 2))
    ans << rest / (max-1)
  end
end
ans.each do |x|
  puts x
end

tc=gets.to_i

ans=[]

tc.times do|i|
    n=gets.to_i
    a=gets.chomp.split(" ").map(&:to_i)

    h=Hash.new(0)

    a.each do |x|
        h[x]+=1
    end

    mx=h.each_value.max
    cnt=h.each_value.count(mx)

    if cnt==1
        ans<< ((n-mx)/(mx-1))
    elsif mx==2
        ans<< n-cnt-1

    else
        dis=n-cnt-1
        rest=dis-(mx-2)
        ans<< rest/(mx-1)
    end
end

ans.each do|x|
    puts x
end


Integer(gets.chomp).times{
    n = Integer(gets.chomp)
    if(n%2 == 1)
        puts "NO"
        next
    else
        sq4 = Float(1)
        isq4 = 0
        if(n%4 == 0)
            sq4 = Math.sqrt(n/4)
            isq4 = Integer(sq4)
        end
        sq2 = Math.sqrt(n/2)
        isq2 = Integer(sq2)

        puts (sq2 == isq2 || sq4 == isq4) ? "YES" : "NO"
    end
}

def solve(n)
  while true
    return true if n == 2
    return false if n % 2 == 1
    n >>= 1
    sqrtn = Integer.sqrt(n)
    return true if sqrtn * sqrtn == n
  end
end

t = gets.to_s.to_i
1.upto(t) do |casenum|
  n = gets.to_s.to_i
  printf("%s\n", solve(n) ? "YES" : "NO")
end

def solve(n)
  return true if n == 2
  while true
    return false if n % 2 == 1
    sqrtn = Integer.sqrt(n)
    return true if sqrtn * sqrtn == n
    n >>= 1
  end
end

t = gets.to_s.to_i
1.upto(t) do |casenum|
  n = gets.to_s.to_i
  printf("%s\n", solve(n) ? "YES" : "NO")
end

def solve(n)
  while true
    return true if n == 2
    return false if n % 2 == 1
    sqrtn = Integer.sqrt(n)
    return true if sqrtn * sqrtn == n
    n >>= 1
  end
end

t = gets.to_s.to_i
1.upto(t) do |casenum|
  n = gets.to_s.to_i
  printf("%s\n", solve(n) ? "YES" : "NO")
end


def bnot(a)
  a == '0' ? '1' : '0'
end

n, p = gets.split.map(&:to_i)
s = gets.chomp
fuck = false
n.times do |i|
  if i < n - p
    if s[i] == '.' and s[i+p] == '.'
      s[i] = '0'
      s[i+p] = '1'
      fuck = true
    elsif s[i] == '.'
      s[i] = bnot s[i+p]
      fuck = true
    elsif s[i+p] == '.'
      s[i+p] = bnot s[i]
      fuck = true
    elsif s[i] != s[i+p]
      fuck = true
    end
  elsif s[i] == '.'
    s[i] = '0'
  end
end

if fuck
  puts s
else
  puts :No
end

# https://codeforces.com/problemset/problem/989/B
def check_possible(records, p)
  len = records.size
  return 'No' if len == 1

  0.upto(len - p - 1) do |i|
    end_idx = i + p

    if records[i] == '.' || records[end_idx] == '.'
      s_v, e_v = get_solution(records, i, end_idx)
      ret = records.dup
      ret[i] = s_v
      ret[end_idx] = e_v
      replace(ret)
      return ret
    end

    if records[i] != records[end_idx]
      replace(records)
      return records
    end
  end

  'No'
end

def replace(records)
  0.upto(records.size - 1) do |i|
    records[i] = '0' if records[i] == '.'
  end
end

def get_solution(records, start_idx, end_idx)
  if records[start_idx] == '.' && records[end_idx] == '.'
    return ['0', '1']
  end

  if records[start_idx] == '.'
    start = records[end_idx] == '0' ? '1' : '0'
    return [start, records[end_idx]]
  end

  [records[start_idx], records[start_idx] == '0' ? '1' : '0']
end

n, p = gets.split.map(&:to_i)
records = gets.chomp

puts check_possible(records, p)


testcases = Integer(gets.chomp)
resultados = []

for i in 0..testcases-1
    n = Integer(gets.chomp)
    arreglo = gets.chomp
    bigram = arreglo.split(" ")
    longitudTotal = bigram.length * 2
    if longitudTotal >= n
        letrasAQuitar = longitudTotal - n
        for j in 0..bigram.length-2
            if letrasAQuitar == 0
                break
            end
            bigram1 = bigram[j]
            bigram2 = bigram[j+1]
            if bigram1.length == 1
                if bigram1[0] == bigram2[0]
                    bigram[j+1] = bigram2[1]
                    letrasAQuitar -= 1
                end
            else
                if bigram1[1] == bigram2[0]
                    bigram[j+1] = bigram2[1]
                    letrasAQuitar -= 1
                end
            end
        end
    else
        letrasAAgregar = n-longitudTotal
        for j in 1..letrasAAgregar
            bigram[bigram.length-1] += "a"
        end
    end
    string = ""
    for j in 0..bigram.length-1
        string += bigram[j]
    end
    resultados.push(string)
end
puts resultados

gets.to_i.times do
  n = gets.to_i
  s = ''

  gets.strip.split.each do |big|
    a, b = big.chars

    if s.empty?
      s = big
      next
    end

    if s[-1] == a
      s += b
      next
    end

    s += big
  end

  if s.size < n
    s += 'b'
  end

  puts s
end

t = gets.to_i
ans = []
t.times do
  n = gets.to_i
  s = gets.split(" ")
  str = [s[0][0],s[0][1]]
  s[1..].each do |v|
    if str[-1] == v[0]
      str << v[1]
    else
      str << v[0]
      str << v[1]
    end
  end
  if str.size != n
    str << "a"
  end
  ans << str
end
ans.each do |v|
  puts v.join
end


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

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

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

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

putsend(0) if s.count('W')==n||s.count('B')==n

ans=[]
# Wにする
(n-1).times do |i|
  if s[i]!='W'
    s[i]='W'
    ans<<i+1
    #反転
    if s[i+1]=='W'
      s[i+1]='B'
    else
      s[i+1]='W'
    end
  end
end
if s[n-1]==s[n-2]
  puts ans.size
  putsend(ans.join(" "))
end

# Bにする
(n-1).times do |i|
  if s[i]!='B'
    s[i]='B'
    ans<<i+1
    #反転
    if s[i+1]=='W'
      s[i+1]='B'
    else
      s[i+1]='W'
    end
  end
end
if s[n-1]==s[n-2]
  puts ans.size
  putsend(ans.join(" "))
end
puts -1

# coding: utf-8

# if __FILE__ == $0
# end

n = gets.to_i
seq = gets.split(//)[0...-1].map { |c| c == 'B' ? 0 : 1 }
stand = seq[0]

i = 0
flipIdx = []
maximumTries = seq.length * 3
maximumIdx = seq.length - 1 - 1
while flipIdx.length <= maximumTries
    if seq[i] != stand
        seq[i] ^= 1
        seq[i+1] ^= 1
        flipIdx << i+1 # 1-based index
    end

    if i == maximumIdx
        if seq.count(stand) != seq.length
            stand ^= 1
            i = 0
        else
            break
        end
    else
        i += 1
    end
end

if flipIdx.length > maximumTries || seq.count(stand) != seq.length
    # puts flipIdx.length
    # puts flipIdx.join ' '
    # p seq
    puts -1
else
    puts flipIdx.length

    if flipIdx.length > 0
        puts flipIdx.join ' '
    end
end

# coding: utf-8

# if __FILE__ == $0
# end

n = gets.to_i
seq = gets.split(//)[0...-1].map { |c| c == 'B' ? 0 : 1 }

if seq.count(0) == seq.length || seq.count(1) == seq.length
    puts 0
else
    i = 0
    flipIdx = []
    stand = seq[0] ^ 1 # first flipping always occurs
    maximumTries = seq.length * 3
    while i < seq.length-1 && flipIdx.length <= maximumTries
        if seq[i] != stand
            seq[i] ^= 1
            seq[i+1] ^= 1
            flipIdx << i+1 # 1-based index
        end

        if seq[i] == seq[i+1]
            i += 2
        else
            i += 1
        end
    end

    if flipIdx.length > maximumTries || seq.count(stand) != seq.length
        puts -1
    else
        puts flipIdx.length
        puts flipIdx.join ' '
    end
end


x = gets.chomp.split(' ')
n = x[0].to_i
r = x[1].to_i
arr = gets.chomp.split(' ')
ans = []
for i in (0...n)
  ans.push(r)
  arr[i] = arr[i].to_i
  for j in (0...i)
    if (arr[i] - arr[j]).abs <= 2 * r
      x = ans[j] + (4 * r * r - (arr[i] - arr[j]) ** 2) ** 0.5
      if(x > ans[i])
        ans[i] = x
      end
    end
  end
  printf("%.12f ", ans[i])
end

def puta ary

  n = ary.size
  # p n
  n.times do |i|
    print ary[i]
    print i == n - 1 ? "\n" : " "
  end
end

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

y = Array.new(n, r)

n.times do |i|

  tmp = r
  (0...i).each do |j|

    dx = ( x[i] - x[j] ).abs
    next if dx > 2 * r
    tmp = y[j] +  ( (2*r)**2 - dx**2 ) ** 0.5

    y[i] = tmp if y[i] < tmp
    # p [j, tmp] if i == 25
  end
end

puta y

def puta ary

  n = ary.size
  n.times do |i|
    print ary[i]
    print i == n - 1 ? "\n" : " "
  end
end

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

y = Array.new(n, r)

n.times do |i|

  tmp = r
  (0...i).each do |j|

    dx = ( x[i] - x[j] ).abs
    next if dx > 2 * r
    tmp = y[j] +  ( (2*r)**2 - dx**2 ) ** 0.5

  end

  y[i] = [ y[i], tmp ].max

end

puta y


n=gets.to_i
s=gets.chomp
h=Hash.new 0
g=Hash.new n/4
s.each_char{|c|h[c]+=1 if c!='?'}
if n%4>0||h.any?{|k,v|g[k]-=v;v>n/4}
puts '==='
exit
end
s.each_char{|c|
if c!='?'
print c
else
x='ATGC'.chars.find{|x|g[x]>0}
g[x]-=1
print x
end
}
puts

n = gets.to_i
s = gets.chomp.split('')
if n % 4 != 0
  puts '==='
  exit
end
h = {}
['A', 'G', 'C', 'T'].each { |x| h[x] = 0 }
s.each do |x|
  h[x] += 1 if x != '?'
end
if h.values.any? { |m| m > n / 4 }
  puts '==='
  exit
end
ss = s.map do |x|
  if x != '?'
    x
  else
    y = h.keys.find { |z| h[z] < n / 4 }
    h[y] += 1
    y
  end
end
puts ss.join('')

n = gets
s = gets

if n.to_i() % 4 > 0
  puts("===")
else
  a = s.count("A")
  t = s.count("T")
  c = s.count("C")
  g = s.count("G")

  if a.to_i() > n.to_i() / 4 || t.to_i() > n.to_i() / 4 || c.to_i() > n.to_i() / 4 || g.to_i() > n.to_i() / 4
    puts("===")
  else
    while a < n.to_i() / 4
      s[s.index('?')] = 'A'
      a += 1
    end

    while t < n.to_i() / 4
      s[s.index('?')] = 'T'
      t += 1
    end

    while c < n.to_i() / 4
      s[s.index('?')] = 'C'
      c += 1
    end

    while g < n.to_i() / 4
      s[s.index('?')] = 'G'
      g += 1
    end

    puts(s)
  end
end

CODES = ['A', 'G', 'C', 'T']

def count(code)
  result = {'A'=> 0, 'G'=> 0, 'C'=> 0, 'T'=> 0, '?'=> 0}
  code.each_char{|c| result[c]+=1}
  return result
end

def eval(code)
  max = code.length/4
  count(code).all? { |ch, cnt|
    ch == '?' || cnt <= max
  }
end

def find(code)
  return nil if !eval(code)
  i = code.index('?')
  if i.nil?
    return code
  else
    for ch in CODES
      copy = code.dup
      copy[i] = ch
      result = find(copy)
      return result if result
    end
    return nil
  end
end

def solve(n, code)
  return "===" if n < 4 || n%4 != 0
  find(code) || "==="
end

puts solve(STDIN.readline.to_i, STDIN.readline.chomp)

a2 = gets.to_i
str = gets.to_s
count_a = count_g = count_c = count_t = 0
for i in 0..a2-1
  e = str[i]
  a = e.ord
  if (a==65)
    count_a = count_a + 1
  end
  if (a==67)
    count_c = count_c + 1
  end
  if (a==71)
    count_g = count_g + 1
  end
  if (a==84)
    count_t = count_t + 1
  end
end
count_q = a2 - (count_a + count_c + count_g + count_t)
no = a2 / 4

if (a2%4 !=0)||(count_a > no) || (count_c > no) || (count_g > no) || (count_t > no) || ((count_a + count_c + count_g + count_t) > a2)
  print("===")
  flag = 1
elsif count_q == 0
  print str
  flag = 1
end

if (flag != 1)
  count_a = -count_a + no
  count_g = -count_g + no
  count_c = -count_c + no
  count_t = -count_t + no

  stack = Array.new
  for i in 1..count_a
    stack.push("A")
  end
  for i in 1..count_g
    stack.push("G")
  end
  for i in 1..count_c
    stack.push("C")
  end
  for i in 1..count_t
    stack.push("T")
  end
  k =0
  for i in 0..a2-1
    a= str[i].ord
    if (a==63)
      str[i]=stack[k]
      k = k+1
    end
  end
  puts str
end

n=gets.to_i
s=gets.chomp

c=[0]*128
s.bytes{|e|c[e]+=1}

for i in 0..n-1
    if s[i]==??
        "AGCT".bytes{|e|
            if c[e]<n/4
                s[i]=e.chr
                c[e]+=1
                break
            end
        }
    end
end

c=[0]*128
s.bytes{|e|c[e]+=1}
puts ((n%4>0 or c.uniq!=[0,n/4]) ? "===" : s)

class Genome
  attr_reader(:gen)
  def initialize(gen)
    @gen = gen.split("")
    @memo = Hash[
      "A" => 0,
      "C" => 0,
      "G" => 0,
      "T" => 0
    ]
  end

  def length
    @length ||= gen.length
  end

  def gcount
    length / 4
  end

  def _gen_count
    gen.each do |i|
      if(i != "?")
        @memo[i] += 1
      end
    end
    @memo
  end

  def gen_count
    @gen_count ||= _gen_count
  end

  def max_gen_count
    @max_gen_count ||= gen_count.map{|k, v| v}.max
  end

  def possible?
    return false if gen.length % 4 != 0
    @possible ||= max_gen_count <= gcount
  end

  def _solver
    @_solver = []
    gen_count.each do |k, v|
      if(v < gcount)
        (1..(gcount - v)).each{ @_solver << (k) }
      end
    end
    return @_solver
  end

  def solver
    @solver ||= _solver
  end

  def solutions
    return "===" unless possible?
    @solutions = []
    i = 0
    gen.each do |g|
      if(g == "?")
        @solutions << solver[i];
        i += 1
      else
        @solutions << g
      end
    end
    @solutions.join("")
  end

end

gets
puts Genome.new(gets.strip).solutions

def miss
  puts "==="
  exit 0
end

n=gets.to_i
s=gets.chomp
if n % 4 != 0
  miss
end
inv_t={'A'=>0,'G'=>1,'C'=>2,'T'=>3,'?'=>4}
t='AGCT?'.split('')
freq=Array.new(5, 0)
s.split('').each {|c|
  freq[inv_t[c]] += 1
}
(0 .. 3).each {|i|
  if freq[i] > n / 4
    miss
  end
}
(0 ... n).each {|i|
  if s[i] == '?'
    for j in 0 .. 3
      if freq[j] < n / 4
        s[i] = t[j]
        freq[j] += 1
        break
      end
    end
  end
}
puts s

CODES = ['A', 'G', 'C', 'T']

def count(code)
  result = {'A'=> 0, 'G'=> 0, 'C'=> 0, 'T'=> 0, '?'=> 0}
  code.each_char{|c| result[c]+=1}
  return result
end

def eval(code)
  max = code.length/4
  count(code).all? { |ch, cnt|
    ch == '?' || cnt <= max
  }
end

def find(code)
  return nil if !eval(code)
  i = code.index('?')
  if i.nil?
    return code
  else
    for ch in CODES
      copy = code.dup
      copy[i] = ch
      result = find(copy)
      return result if result
    end
    return nil
  end
end

def solve(n, code)
  return "===" if n < 4 || n%4 != 0
  find(code)
end

puts solve(STDIN.readline.to_i, STDIN.readline.chomp)

n=gets.to_i
s=gets.chomp

c=[0]*128
s.bytes{|e|c[e]+=1}

for i in 0..n-1
    if s[i]==??
        "AGCT".bytes{|e|
            if c[e]<n/4
                s[i]=e.chr
                c[e]+=1
                break
            end
        }
    end
end

c=[0]*128
s.bytes{|e|c[e]+=1}
puts (n%4>0 or c.uniq!=[0,n/4] ? "===" : s)

n=gets.to_i
s=gets.chomp

c=[0]*128
s.bytes{|e|c[e]+=1}

for i in 0..n-1
    if s[i]==??
        "AGCT".bytes{|e|
            if c[e]<n/4
                s[i]=e.chr
                c[e]+=1
                break
            end
        }
    end
end

c=[0]*128
s.bytes{|e|c[e]+=1}
puts (c.uniq.size>2 ? "===" : s)

n=gets.to_i
c=[0]*128
s=gets.chomp
s.bytes{|e|c[e]+=1}
m=0
"AGCT".bytes{|e|m=c[e] if m<c[e]}
d=0
"AGCT".bytes{|e|d+=m-c[e]}

if c[??.ord]!=d
    puts "==="
else
    for i in 0..n-1
        if s[i]==??
            "AGCT".bytes{|e|
                if c[e]<m
                    s[i]=e.chr
                    c[e]+=1
                    break
                end
            }
        end
    end
    puts s
end

n=gets.to_i
c=[0]*128
s=gets.chomp
s.bytes{|e|c[e]+=1}
m=0
"AGCT".bytes{|e|m=c[e] if m<c[e]}
d=0
"AGCT".bytes{|e|d+=m-c[e]}

if n%4>0 or (m>0 and c[??.ord]!=d)
    puts "==="
else
    m=n/4 if m==0
    for i in 0..n-1
        if s[i]==??
            "AGCT".bytes{|e|
                if c[e]<m
                    s[i]=e.chr
                    c[e]+=1
                    break
                end
            }
        end
    end
    puts s
end

n=gets.to_i
s=gets.chomp

c=[0]*128
s.bytes{|e|c[e]+=1}

for i in 0..n-1
    if s[i]==??
        "AGCT".bytes{|e|
            if c[e]<n/4
                s[i]=e.chr
                c[e]+=1
                break
            end
        }
    end
end

c=[0]*128
s.bytes{|e|c[e]+=1}
puts (c.uniq!=[0,n/4] ? "===" : s)

class Genome
  attr_reader(:gen)
  def initialize(gen)
    @gen = gen.split("")
    @memo = Hash[
      "A" => 0,
      "C" => 0,
      "G" => 0,
      "T" => 0
    ]
  end

  def length
    @length ||= gen.length
  end

  def gcount
    length / 4
  end

  def _gen_count
    gen.each do |i|
      if(i != "?")
        @memo[i] += 1
      end
    end
    @memo
  end

  def gen_count
    @gen_count ||= _gen_count
  end

  def max_gen_count
    @max_gen_count ||= gen_count.map{|k, v| v}.max
  end

  def possible?
    @possible ||= max_gen_count <= gcount
  end

  def _solver
    @_solver = []
    gen_count.each do |k, v|
      if(v < gcount)
        (1..(gcount - v)).each{ @_solver << (k) }
      end
    end
    return @_solver
  end

  def solver
    @solver ||= _solver
  end

  def solutions
    return "===" unless possible?
    @solutions = []
    i = 0
    gen.each do |g|
      if(g == "?")
        @solutions << solver[i];
        i += 1
      else
        @solutions << g
      end
    end
    @solutions.join("")
  end

end

gets
puts Genome.new(gets.strip).solutions


MOD = 10 ** 9 + 7
def gs; gets.chomp; end
def gi; gets.to_i; end
def gli; gets.split.map(&:to_i); end
def cyesno(x); puts x ? :Yes : :No; end
def uyesno(x); puts x ? :YES : :NO; end
def array_to_hash_by_count(c); Hash.new(0).tap { |x| c.each { |z| x[z] += 1 } }; end

gets.to_i.times do
  a, b, c = gli
  n = 2 * (a - b).abs
  if n < [a, b, c].max
    puts "-1"
  else
    if c > n / 2
      puts c - n / 2
    else
      puts n / 2+c
    end
  end
end

def solve(a, b, c)
  n = (a - b).abs
  return -1 if [a, b, c].max > 2 * n
  a -= 1
  b -= 1
  c -= 1
  (c+n) % (2*n) + 1
end

t = gets.chomp.to_i

t.times do
  a, b, c = gets.chomp.split(' ').map(&:to_i)
  puts "#{solve(a, b, c)}\n"
end


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

puts (as.inject(:+)/x).abs.ceil

class ProblemA
  def initialize
    @dats = STDIN.read.split("\n")
    @cards_num, @max_abs = @dats[0].split(" ").map{|x| x.to_i}
    @cards = @dats[1].split(" ").map{|x| x.to_i}
  end

  def solve
    sum = @cards.inject(:+).abs
    return 1 if sum != 0 && sum <= @max_abs-1
    return 0 if @max_abs == 0

    count_ret = 0
    (@max_abs).downto(1) do |elem|
      if sum >= elem
        d = sum / elem
        sum -= elem * d
        count_ret += d
      elsif sum == 0
        return count_ret
      end
    end
    return count_ret
  end
end

solver = ProblemA.new
p solver.solve

a = readline.split().map {|x| x.to_i}
s = 0
readline.split().map {|i| s += i.to_i}
puts (s.abs + a[1] - 1) / a[1]

n, x = readline.split().map {|i| i.to_i}
s = 0
readline.split().map {|i| s += i.to_i}
puts (s.abs + x - 1) / x

a=gets.chomp.split(" ")
ans=0.0
b=gets.chomp.split(" ").each {|i|  ans+=i.to_i  }
ans=ans.abs
ans=(ans/a[1].to_i).ceil
puts "#{ans}"

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

sum = gets.split.collect{|x| x.to_i}.inject{|y, x| y += x}

sum = sum.abs

k = (sum + x -1)/x

p k

n,x = gets.chomp!.split.map { |e|  e.to_i}
sum = gets.split.collect{|x| x.to_i}.inject{|y, x| y += x}
p (sum.abs + x -1)/x

input = gets.chomp
num = input.split
n = Integer(num[0])
x = Integer(num[1])
input2 = gets.chomp
nums= input2.split
card = Array.new
for i in 0...n
    card[i] = Integer(nums[i])
end

sum = 0
for i in 0...n
    sum += card[i]
end
if sum == 0
    puts 0
else
    if sum.abs <= x
        puts 1
    else
        if sum.abs % x == 0
            puts sum.abs / x
        else
            puts sum.abs / x + 1
        end
    end
end

card = gets.split(" ").map { |e| e.to_i }
mas = gets.split(" ").map { |e| e.to_i }
sum = 0
mas.map { |e| sum += e }
sum = sum.abs
puts (sum.abs + card[1] - 1) / card[1]

n, m = $stdin.gets.split(' ').map{|e| e.to_i}
cards = $stdin.gets.split(' ').map{|e| e.to_i}

result = (cards.inject(:+).abs.to_f / m).ceil
puts result

first_line = (gets()).split()
second_line = (gets()).split()

found_num = (first_line.shift).to_i
max_abs = (first_line.shift).to_i
num_ary = 0

second_line.each do |c|
	num_ary += c.to_i
end
result = (num_ary).abs / max_abs
if ((num_ary % max_abs) != 0)
	result += 1
end
p result

n, x = gets.split(' ').map(&:to_i)
s = gets.split(' ').map(&:to_i).inject(:+).abs
puts s/x + ( s%x == 0 ? 0 : 1 )

n,x = gets.chomp.split

g = gets.chomp.split

n = n.to_i
x = x.to_i
s = 0

for i in 0...n
  s += g[i].to_i
end

s = s.abs

s = s/x.to_f

s = s.ceil

puts s.to_i

n, x = gets.split.map &:to_i
a = gets.split.map &:to_i
s = a.inject(0){|s, x| s + x}
p (s.abs + x - 1)/x

#!/usr/bin/ruby
n,x=gets.split.map(&:to_i)
s=gets.split.map(&:to_i).reduce(:+).abs
p (s+x-1)/x

n, x = gets.chomp.split(" ").map{ |e| e.to_i }
cards = gets.chomp.split(" ").map{ |e| e.to_i }

sum = cards.inject{ |s, i| s += i }.abs
puts (sum.to_f / x.to_f).ceil

def run
  n, x = $stdin.gets.split.map(&:to_i)
  c = $stdin.gets.split.map(&:to_i)
  s = c.reduce(&:+)
  puts (s.abs.to_f / x).ceil
end

run if $0 == __FILE__

def solve(max, cards)
  sum = cards.inject(:+).abs
  div = sum / max
  rem = sum % max
  div += 1 if rem > 0
  div
end

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

if __FILE__ == $0
  puts solve(read_next_line[1], read_next_line)
end

n, x = gets.split.map(&:to_i)
given = gets.split.map(&:to_i)
sum = 0

given.each do |i|
    sum += i
end
ans = sum.abs / Float(x)
ans = ans.ceil
p Integer(ans)

n, x = gets.split.map &:to_i
sum = gets.split.map { |x| x.to_i }.inject(:+)
puts (sum.abs/x.to_f).ceil

class A
  def initialize
    n, x = gets.chomp.split(' ').map(&:to_i)

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

    sum = num_list.inject(:+)

    puts (sum.abs/x.to_f).ceil
  end
end

A.new

#f = File.open('test1.txt', 'r')
f = STDIN
n, x = f.gets.chomp.split.map &:to_i
sum = f.gets.chomp.split.map(&:to_i).reduce(&:+).abs
puts (sum / x + (sum % x != 0 ? 1 : 0))

ri=->{gets.split.map(&:to_i)}
n,x=ri[]
p (ri[].inject(:+).abs+x-1)/x

n, x = gets.split.map { |x| x.to_i }
sum = gets.split.map { |x| x.to_i }.reduce(:+).abs
puts (sum + x - 1) / x

(n , x) = gets.split.map(&:to_i)
arr = gets.split.map(&:to_i)
(sum , res) = 0,0
n.times do |i|
  sum += arr[i]
end

sum = sum.abs
if sum != 0
  res += (sum/x) + (sum%x==0?0:1)
end
puts res

n, x = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
sum = a.reduce(:+).abs
p (sum + x - 1) / x

input = gets.chomp
num = input.split
n = Integer(num[0])
x = Integer(num[1])
input2 = gets.chomp
nums= input2.split
card = Array.new
for i in 0...n
    card[i] = Integer(nums[i])
end

sum = 0
for i in 0...n
    sum += card[i]
end
if sum.abs <= x
    puts 1
else
    if sum.abs % x == 0
        puts sum.abs / x
    else
        puts sum.abs / x + 1
    end
end

card = gets.split(" ").map { |e| e.to_i }
mas = gets.split(" ").map { |e| e.to_i }
sum = 0
mas.map { |e| sum += e }
if sum % 2 != 0 then
    sum = sum / 2 + 1
else
    sum = sum / 2
end
puts sum.abs

card = gets.split(" ").map { |e| e.to_i }
mas = gets.split(" ").map { |e| e.to_i }
sum = 0
mas.map { |e| sum += e }
if sum % card[1] != 0 then
    sum = sum / card[1] + 1
else
    sum = sum / card[1]
end
puts sum.abs

def check_pair (pos_ary,neg_ary,surplus_cards)
	if (pos_ary.first and neg_ary.first)
		num = pos_ary.first
		overlap = neg_ary.index(num)
		if overlap
			pos_ary.shift
			neg_ary.delete_at(overlap)
			return check_pair(pos_ary,neg_ary,surplus_cards)
		else
			pos_ary.shift
			surplus_cards += 1
			return check_pair(pos_ary,neg_ary,surplus_cards)
		end
	else
		surplus_cards = pos_ary.length + neg_ary.length
		return surplus_cards
	end
end

first_line = (gets()).split()
second_line = (gets()).split()
pos_cards = []
neg_cards = []

found_num = (first_line.shift).to_i
mux_abs = (first_line.shift).to_i

second_line.each do |c|
	num = c.to_i
	if num > 0
		pos_cards << num
	elsif num < 0
		neg_cards << num
	end
end

p check_pair(pos_cards,neg_cards,0)

n, x = gets.split.map(&:to_i)
given = gets.split.map(&:to_i)
sum = 0

given.each do |i|
    sum += i
end
sum += x - 1
p sum / x

n, x = gets.split.map(&:to_i)
given = gets.split.map(&:to_i)
sum = 0

given.each do |i|
    sum += i
end
p (sum / x).abs.ceil

#f = File.open('test1.txt', 'r')
f = STDIN
n, x = f.gets.chomp.split.map &:to_i
sum = f.gets.chomp.split.map(&:to_i).reduce(&:+).abs
puts (sum / x + sum % x)

#!/usr/bin/ruby
n,x=gets.split.map(&:to_i)
s=gets.split.map(&:to_i).reduce(:+).abs
p (x+s-1)/s

n, x = gets.split.map &:to_i
sum = gets.split.map { |x| x.to_i }.inject(:+)
puts (sum/x).ceil.abs

n, x = gets.split.map &:to_i
sum = gets.split.map { |x| x.to_i }.inject(:+)
puts (sum/x.to_f).ceil.abs

(n , x) = gets.split.map(&:to_i)
arr = gets.split.map(&:to_i)
print arr
sum = 0
res = 0
n.times do |i|
  sum += arr[i]
end

sum = sum.abs
if sum != 0
  res += (sum/x)+1
end
puts res

(n , x) = gets.split.map(&:to_i)
arr = gets.split.map(&:to_i)
(sum , res) = 0,0
n.times do |i|
  sum += arr[i]
end

sum = sum.abs
if sum != 0
  res += (sum/x)+1
end
puts res

(n , x) = gets.split.map(&:to_i)
arr = gets.split.map(&:to_i)
sum = 0
res = 0
n.times do |i|
  sum += arr[i]
end

sum = sum.abs
if sum != 0
  res += (sum%x)+1
end
puts res

class ProblemA
  def initialize
    @dats = STDIN.read.split("\n")
    @cards_num, @max_abs = @dats[0].split(" ").map{|x| x.to_i}
    @cards = @dats[1].split(" ").map{|x| x.to_i}
  end

  def solve
    sum = @cards.inject(:+).abs
    return 1 if sum <= @max_abs-1
    return 0 if @max_abs == 0

    count_ret = 0
    (@max_abs).downto(1) do |elem|
      if sum >= elem
        d = sum / elem
        sum -= elem * d
        count_ret += d
      elsif sum == 0
        return count_ret
      end
    end
    return count_ret
  end
end

solver = ProblemA.new
p solver.solve

class ProblemA
  def initialize
    @dats = STDIN.read.split("\n")
    @cards_num, @max_abs = @dats[0].split(" ").map{|x| x.to_i}
    @cards = @dats[1].split(" ").map{|x| x.to_i}
  end

  def solve
    sum = @cards.inject(:+).abs
    return 1 if sum <= @max_abs
    return 0 if @max_abs == 0

    count_ret = 0
    (@max_abs-1).downto(1) do |elem|
      if sum > elem
        count_ret += 1
        sum -= elem
      elsif sum == 1
        return count_ret+1
      end
    end
    return count_ret
  end
end

solver = ProblemA.new
p solver.solve

class ProblemA
  def initialize
    @dats = STDIN.read.split("\n")
    @cards_num, @max_abs = @dats[0].split(" ").map{|x| x.to_i}
    @cards = @dats[1].split(" ").map{|x| x.to_i}
  end

  def solve
    sum = @cards.inject(:+).abs
    return 1 if sum <= @max_abs
    return 0 if @max_abs == 0

    count_ret = 0
    (@max_abs-1).downto(1) do |elem|
      if sum >= elem
        count_ret += 1
        sum -= elem
      elsif sum == 1
        return count_ret+1
      elsif sum == 0
        return count_ret
      end
    end
    return count_ret
  end
end

solver = ProblemA.new
p solver.solve

class ProblemA
  def initialize
    @dats = STDIN.read.split("\n")
    @cards_num, @max_abs = @dats[0].split(" ").map{|x| x.to_i}
    @cards = @dats[1].split(" ").map{|x| x.to_i}
  end

  def solve
    sum = @cards.inject(:+).abs
    return 1 if sum <= @max_abs
    return 0 if @max_abs == 0

    count_ret = 0
    (@max_abs-1).downto(1) do |elem|
      if sum >= elem
        count_ret += 1
        sum -= elem
      elsif sum == 0
        return count_ret
      end
    end
    return count_ret
  end
end

solver = ProblemA.new
p solver.solve

class ProblemA
  def initialize
    @dats = STDIN.read.split("\n")
    @cards_num, @max_abs = @dats[0].split(" ").map{|x| x.to_i}
    @cards = @dats[1].split(" ").map{|x| x.to_i}
  end

  def solve
    sum = @cards.inject(:+).abs
    return 1 if sum <= @max_abs-1
    return 0 if @max_abs == 0

    count_ret = 0
    (@max_abs-1).downto(1) do |elem|
      if sum >= elem
        d = sum / elem
        sum -= elem * d
        count_ret += d
      elsif sum == 0
        return count_ret
      end
    end
    return count_ret
  end
end

solver = ProblemA.new
p solver.solve

class ProblemA
  def initialize
    @dats = STDIN.read.split("\n")
    @cards_num, @max_abs = @dats[0].split(" ").map{|x| x.to_i}
    @cards = @dats[1].split(" ").map{|x| x.to_i}
  end

  def solve
    sum = @cards.inject(:+).abs
    return 1 if sum <= @max_abs
    return 0 if @max_abs == 0

    count_ret = 0
    @max_abs.downto(1) do |elem|
      if sum > elem
        count_ret += 1
        sum -= elem
      elsif sum == 1
        return count_ret+1
      end
    end
    return count_ret
  end
end

solver = ProblemA.new
p solver.solve

class ProblemA
  def initialize
    @dats = STDIN.read.split("\n")
    @cards_num, @max_abs = @dats[0].split(" ").map{|x| x.to_i}
    @cards = @dats[1].split(" ").map{|x| x.to_i}
  end

  def solve
    sum = @cards.inject(:+).abs
    return 1 if sum <= @max_abs-1
    return 0 if @max_abs == 0

    count_ret = 0
    (@max_abs-1).downto(1) do |elem|
      if sum >= elem
        count_ret += 1
        sum -= elem
      elsif sum == 0
        return count_ret
      end
    end
    return count_ret
  end
end

solver = ProblemA.new
p solver.solve


n, k = gets.strip.split.map(&:to_i)
ary = gets.strip.split.map(&:to_i)
hsh = {}
ary.each {|x| hsh[x] = (hsh[x] || 0) + 1 }
ary.sort!
ary.uniq!
remaining_ary = []
un = ary.size
0.upto(un-2).each do |j|
  i =  j + 1
  next if ary[j] < ary[i] && ary[i] <= (ary[j]+k)
  remaining_ary << ary[j]
end
remaining_ary << ary.last
puts remaining_ary.map{|x| hsh[x] }.inject(:+)

def read_line
  gets.split.map{|e| e.to_i }
end

n, k = read_line
a = read_line.sort

count = 0

nearest_bigger = []
nearest_bigger[a.count - 1] = a[a.count -1]

(0...n-1).reverse_each do |index|
  cur = a[index]
  next_val = a[index+1]
  if cur == next_val
    nearest_bigger[index] = nearest_bigger[index+1]
  else
    nearest_bigger[index] = next_val
  end
end

a[0...-1].to_enum.with_index.each do |val, index|
  next_val = nearest_bigger[index]
  if val < next_val && (val + k) >= next_val
    count += 1
  end
end

puts n-count

# http://codeforces.com/problemset/problem/990/B

def count
  n, k = gets.split.map(&:to_i)
  a = gets.split.map(&:to_i)
  a.sort!
  # puts a.inspect

  return n if a.first == a.last || n == 1

  s = 0
  c = 0
  1.upto(n - 1) do |i|
    next if a[i] - a[i-1] <= k

    c += skip_count(a, i-1, s)
    s = i
  end

  c += skip_count(a, n-1, s)

  return n - c
end

def skip_count(a, startIdx, endIdx)
  c = 0
  startIdx.downto(endIdx) do |i|
    if a[i] == a[startIdx]
      next
    end

    c = (i - endIdx + 1)
    break
  end

  c
end

puts count

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

b.sort!

n = 0
prev = b.first
prev_cnt = 0
b.each do |i|
  if i > prev
    if i > prev + k
      n += prev_cnt
    end
    prev = i
    prev_cnt = 1
  else
    prev_cnt +=1
  end
end
n += prev_cnt
puts n

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

c = 1
s = 1
unique = true
1.upto(n - 1) do |i|
  unique = false if (a[i] != a[i - 1]) && unique
  next if a[i] - a[i-1] <= k

  (i - 1).downto(s) do |j|
    if a[j] == a[i - 1]
      c += 1
      next
    end

    c += 1
    break
  end

  s = i
end

if unique
  puts n
else
  puts c
end


gets.to_i.times do
  gets
  puts gets.split(' ').map(&:to_i).uniq.join(' ')
end

gets.to_i.times do
	n = gets.to_i
	a = gets.split.map(&:to_i)
	flag = [false] * (n + 1)
	puts a.reduce([]) { |acc, i|
			if !flag[i]
				acc << i
				flag[i] = true
			end
			acc
	     }.join(' ')
end

# frozen_string_literal: true

lines = gets.to_i
lines.times do
  numbers = gets.to_i
  number_permutation = gets.split(' ').map(&:to_i)
  find_map = {}
  number_permutation.each do |i|
    next if find_map[i]

    find_map[i] = true
  end
  print find_map.keys.join(' '), "\n"
end

n = gets.chomp.to_i
n.times do
    b = gets.chomp.to_i
    atr = gets.chomp.split(" ")
    retsu = []
    until atr == []
        a = atr.shift
       # p retsu
        if !retsu.include?(a)
            retsu << a
        end
    end
    #p retsu
    retsu.delete(" ")
    puts retsu.join(" ")
end

tc = gets.to_i

tc.times do
    n = gets.to_i
    arr = gets.split().map{|i| i.to_i}
    dic = Hash.new(0)
    ans = []
    arr.each do |x|
        if(dic[x] == 0)
            ans << x
        end
        dic[x] += 1
    end
    puts ans.join(" ")
end

gets.to_i.times do
    n = gets.to_i
    a = gets.split.map(&:to_i)
    used = [false] * n
    res = []
    (0...2 * n).each do |i|
        if !used[a[i] - 1]
            used[a[i] - 1] = true
            res << a[i]
        end
    end
    puts res.join ' '
end

def solve
  n = gets.strip.to_i
  a = gets.strip.split(' ').map(&:to_i)
  v = []
  (1..n).each { |e| v[e] = true }
  a.each { |e|
    break if n.zero?
    if v[e] == true
      print "#{e} "
      v[e] = false
    end
  }
  puts
end

gets.strip.to_i.times { solve }

gets.to_i.times do
  gets
  puts gets.split.map(&:to_i).uniq.join(' ')
end

n = gets.chomp.to_i
n.times do
    b = gets.chomp.to_i
    atr = gets.chomp.split("")
    retsu = []
    until atr == []
        a = atr.shift
        if !retsu.include?(a)
            retsu << a
        end
    end
    retsu.delete(" ")
    puts retsu.join(" ")
end