def say_no
  puts 'NO'
  exit
end

g1, g2 = [gets.chomp, gets.chomp]
n = g1.size
say_no if n != g2.size
d = []
for i in 0...n
  say_no if g1[i] != g2[i] && ((t = (d << i).size) > 2 || (t == 2 && (g1[d[0]] != g2[d[1]] || g1[d[1]] != g2[d[0]])))
end
puts [0, 2].any? { |p| p == d.size } ? 'YES' : 'NO'

a, b, c, diff  = gets.strip, gets.strip, 0, []

if a.length == b.length
	a.length.times do |i|
		unless a[i] == b[i]
			c += 1
			c < 3 ? diff.push([a[i], b[i]]) : break
		end
	end
	print c == 2 && diff[0] == diff[1].reverse ? :YES : :NO
else
	print :NO
	exit
end

a = gets.chomp
b = gets.chomp

def work(a, b)
  #puts a.size,b.size
  return false if a.size != b.size
  d = []
  (0...a.size).each {|x| d << x if a[x] != b[x]}
 # p d.size
  return false if d.size != 0 and d.size != 2

  if d.size == 2
    return true if a[d[0]] == b[d[1]] and a[d[1]] == b[d[0]]
    return false
  end

  hs = Hash.new(0)
  a.each_byte{|x| hs[x] = hs[x] + 1}
  return true if hs.values.any?{|x| x > 1}

  return false
end

if work(a,b)
  puts 'YES'
else
  puts 'NO'
end

s1 = gets.chomp.split("")
s2 = gets.chomp.split("")

if s1.sort == s2.sort then
    i = 0
    d = 0
    while i < s1.size do
        if s1[i] != s2[i] then
            d += 1
        end
        i += 1
    end
    if d <= 2 then
        puts "YES"
    else
        puts "NO"
    end
else
    puts "NO"
end

s1 = gets.chomp
s2 = gets.chomp
ret = "NO"
r1 = nil
r2 = nil
if s1.length == s2.length
    for i in 0..s1.length-1
        next if s1[i] == s2[i]
        if r1 == nil
            r1 = s1[i]
            r2 = s2[i]
        else
            if ret == "NO"
                if r1 == s2[i] && r2 == s1[i]
                    ret = "YES"
                else
                    break
                end
            else
                ret = "NO"
                break
            end
        end
    end
end
puts ret

require 'set'

def compare_str(a, b)
  return "NO" if a.length != b.length
  a_set = []
  b_set = []
  (0..a.length).each do |i|
    if a[i] != b[i]
      a_set << a[i]
      b_set << b[i]
    end
  end
  return "NO" if a_set.length > 2
  return "YES" if a_set.sort == b_set.sort
  return "NO"
end

a = gets.chomp
b = gets.chomp

puts compare_str(a, b)

def diff(a, b)
  c = 0
  for i in 0..(a.length - 1)
    if a[i] != b[i]
      c += 1
    end
  end
  c
end

a = gets.chomp.split ""
b = gets.chomp.split ""

puts ((a.sort == b.sort) and diff(a, b) == 2) ? "YES" : "NO"

s = STDIN.readline.strip
t = STDIN.readline.strip
if s.length != t.length
	puts 'NO'
	exit
end
differences = []
s.length.times do |i|
	differences.push(i) if s[i] != t[i]
end
if differences.length != 2
	puts 'NO'
	exit
end
a, b = differences
s[a], s[b] = s[b], s[a]
if s == t
	puts 'YES'
else
	puts 'NO'
end

a=gets.chomp.strip
b=gets.chomp.strip
x=[]
if a.length!=b.length
	puts "NO"
	exit
end
for i in 0...a.length
	if a[i]!=b[i]
		x.push(i)
	end
end
if x.length!=2
	puts "NO"
	exit
end
puts (a[x[0]]==b[x[1]] and b[x[0]]==a[x[1]])? "YES" : "NO"

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

if a.length !=b.length
	puts "NO"
elsif a.sort != b.sort
	puts "NO"
elsif a==b
	puts "YES"
elsif a.reverse==b && a.length==2
	puts "YES"
else

k=[]

	0.upto(a.length-1) do|i|
		k[i]=[a[i],b[i]]
	end

k.each{|i| i.uniq!}
k.sort! {|x,y| y.length <=> x.length}
d=0

	0.upto(2) do |i|
		if k[i].length==2
			d+=1
		end
	end
	if d<=1
		puts "YES"
	elsif d>2
		puts "NO"
	else
		if k[0].reverse==k[1]
			puts "YES"
		else
			puts "NO"
		end
	end

end

a = gets.to_s
b = gets.to_s

if a.size != b.size then
	puts "NO"
	exit
end

count = 0
x = 0
y = 0

0.upto (a.size-1) do |i|
	if a[i] != b[i] then
		count += 1
		if count == 1 then
			x = a[i]
			y = b[i]
		elsif count == 2 then
			if (x != b[i]) or (y != a[i]) then
				puts "NO"
				exit
			end
		else
			puts "NO"
			exit
		end
	end
end

if count == 0 then
	d = {}
	0.upto (a.size -1) do |i|
		if d[i] == 1 then
			puts "YES"
			exit
		else
			d[i] = 1
		end
	end
	puts "NO"
	exit
elsif count == 1 then
	puts "NO"
	exit
else
	puts "YES"
	exit
end

first = gets.chomp
second = gets.chomp
ans = "NO"
if first.length == second.length
    diff = []
    act = []
    (0...first.length).each do |i|
        a = first[i]
        b = second[i]
        if a != b
            diff << a
            act << b
        end
    end
    if diff.length == 2
        ans = "YES" if act[0] == diff[1] && act[1] == diff[0]
    end
end
puts ans

a = gets.chomp
b = gets.chomp

def work(a, b)
  return false if a.size != b.size
  d = []
  (0...a.size).each {|x| d << x if a[x] != b[x]}
 # p d.size
  return false if d.size != 0 and d.size != 2

  if d.size == 2
    return true if a[d[0]] == b[d[1]] and a[d[1]] == b[d[0]]
    return false
  end

  hs = Hash.new(0)
  a.each_byte{|x| hs[x] = hs[x] + 1}
  return true if hs.values.any?{|x| x > 1}

  return false
end

if work(a,b)
  puts 'YES'
else
  puts 'NO'
end

a=gets
b=gets
if a.size != b.size
  puts "NO"
else
  s0=[]
  s1=[]
  (a.size-1).times do |i|
    if a[i] != b[i]
      s0 << a[i]
      s1 << b[i]
    end
  end
  if s0.size!=2 || s0[1] != s1[0] || s0[0] != s1[1]
    puts "NO"
  else
    puts "YES"
  end
end

first_count = Hash.new(0)
second_count = Hash.new(0)

a = gets.chomp
b = gets.chomp
ans = false
mismatch_ind = []
if a.length == b.length
	(0..a.length - 1).each do |i|

		a_char = a[i]
		b_char = b[i]

		first_count[a_char] += 1
		second_count[b_char] += 1
		mismatch_ind << i if a_char != b_char
	end

	ans = true if first_count == second_count && ( mismatch_ind.length == 0 || (mismatch_ind.length == 2 && a[mismatch_ind[0]] == b[mismatch_ind[1]] && a[mismatch_ind[1]] == b[mismatch_ind[0]]))

end
puts ans ? "YES" : "NO"

l = []
a = gets
b = gets
if a.size == b.size
	a.split(//).each_with_index do |x, i|
		l << a[i].ord - b[i].ord if a[i].ord - b[i].ord != 0
		if l.size > 2
			break
		end
	end
else
	l << 0
end

if l.size == 0 or (l.size == 2 and l[0] == -l[1])
	puts "YES"
else
	puts "NO"
end

as, bs = gets.chomp.chars.to_a, gets.chomp.chars.to_a
first = true
first_a, first_b = nil, nil
output = false
answer = "NO"
if as.length == bs.length
  as.each_with_index do |a, i|
    b = bs[i]
    if a != b
      if output
        answer = "NO"
        break
      end
      if first
        first_a = a
        first_b = b
        first = false
      else
        answer = "YES" if a == first_b && b == first_a
        output = true
      end
    end
  end

  puts answer
else
  puts "NO"
end

as, bs = gets.chomp.chars.to_a, gets.chomp.chars.to_a

if as.length != bs.length
  puts "NO"
else
  diff = []

  as.zip(bs).each_with_index do |(a, b), i|
    diff << i if a != b
  end

  puts diff.length == 2 && as[diff[0]] == bs[diff[1]] && as[diff[1]] == bs[diff[0]] ? "YES" : "NO"
end

def main
  a = STDIN.gets
  b = STDIN.gets

  return 'NO' if a.length != b.length

  diffs = []
  (0 ... a.length).each do |i|
    diffs.push(i) if a[i] != b[i]
  end

  return 'NO' if diffs.length != 2

  return a[diffs[0]] == b[diffs[1]] && b[diffs[0]] == a[diffs[1]] ? 'YES' : 'NO'
end

puts main

a = gets
b = gets
ans = false
if a.length == b.length
	s = []
	a.length.times do |i|
		if a[i] != b[i]
			s << i
		end
	end
	ans = s.empty? || ((s.length == 2 and a[s[0]] == b[s[1]] and a[s[1]] == b[s[0]]))
end
puts ans ? "YES" : "NO"

s1 = gets.chomp
s2 = gets.chomp

i = 0
while i < s2.size do
    if s1[i] == s2[i] then
        s1 = s1[0...i] + s1[i+1..-1]
        s2 = s2[0...i] + s2[i+1..-1]
    end
    i += 1
end

s1 = s1.delete(s2)

if s1 == "" then
    puts "YES"
else
    puts "NO"
end

s1 = gets.chomp.split("")
s2 = gets.chomp.split("")

s1 = s1.sort
s2 = s2.sort

if s1 == s2 then
    i = 0
    d = 0
    while i < s1.size do
        if s1[i] != s2[i] then
            d += 1
        end
        i += 1
    end
    if d <= 2 then
        puts "YES"
    else
        puts "NO"
    end
else
    puts "NO"
end

s1 = gets.chomp
s2 = gets.chomp

if s1.size == s2.size then
    i = 0
    while i < s2.size do
        if s1[i] == s2[i] then
            s1 = s1.sub(s1[i], "")
            s2 = s2.sub(s2[i], "")
        end
        i += 1
    end
    if s1.size == 2 then
        s1 = s1.delete(s2)
        if s1 == "" then
            puts "YES"
        else
            puts "NO"
        end
    else
        puts "NO"
    end
else
    puts "NO"
end

s1 = gets.chomp
s2 = gets.chomp

if s1.size == s2.size then
    i = 0
    str = ""
    while i < s2.size do
        if s1[i] == s2[i] then
            str += s1[i]
        end
        i += 1
    end
    s1 = s1.sub(str, "")
    s2 = s2.sub(str, "")
    if s1.size == 2 then
        s1 = s1.delete(s2)
        if s1 == "" then
            puts "YES"
        else
            puts "NO"
        end
    else
        puts "NO"
    end
else
    puts "NO"
end

def diff(a, b)
  c = 0
  for i in 0..(a.length - 1)
    if a[i] == b[i]
      c += 1
    end
  end
  c
end

a = gets.chomp.split ""
b = gets.chomp.split ""

puts ((a.sort == b.sort) and diff(a, b) == 2) ? "YES" : "NO"

def diff(a, b)
  c = 0
  for i in 0..(a.length - 1)
    if a[i] == b[i]
      c += 1
    end
  end
  c
end

a = gets.chomp.split ""
b = gets.chomp.split ""

a.sort!
b.sort!

puts ((a == b) and diff(a, b) == 2) ? "YES" : "NO"

a = gets.chomp.split ""
b = gets.chomp.split ""

a.sort!
b.sort!

puts (a == b) ? "YES" : "NO"

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

if a.length !=b.length
	puts "NO"
elsif a.sort != b.sort
	puts "NO"
elsif a==b
	puts "YES"
elsif a.reverse==b
	puts "YES"
else

k=[]

	0.upto(a.length-1) do|i|
		k[i]=[a[i],b[i]]
	end

k.each{|i| i.uniq!}
k.sort! {|x,y| y.length <=> x.length}
d=0

	0.upto(2) do |i|
		if k[i].length==2
			d+=1
		end
	end

	if d<=1
		puts "YES"
	elsif d>2
		puts "NO"
	else
		if k[0].reverse==k[1]
			puts "YES"
		else
			puts "NO"
		end
	end

end

a=gets
b=gets
if a.size != b.size
  puts "NO"
else
  s0=[]
  s1=[]
  (a.size-1).times do |i|
    puts i
    if a[i] != b[i]
      s0 << a[i]
      s1 << b[i]
    end
  end
  if s0.size!=2 || s0[1] != s1[0] || s0[0] != s1[1]
    puts "NO"
  else
    puts "YES"
  end
end

first_count = Hash.new(0)
second_count = Hash.new(0)

a = gets.chomp
b = gets.chomp

a.each_char do |i|
	first_count[i] += 1
end

b.each_char do |i|
	second_count[i] += 1
end

puts first_count == second_count ? "YES" : "NO"

as, bs = gets.chomp.chars.to_a, gets.chomp.chars.to_a
first = true
first_a, first_b = nil, nil
output = false
as.each_with_index do |a, i|
  b = bs[i]
  if a != b
    if first
      first_a = a
      first_b = b
      first = false
    else
      puts a == first_b && b == first_a ? "YES" : "NO"
      output = true
      break
    end
  end
end

puts "NO" unless output

as, bs = gets.chomp.chars.to_a, gets.chomp.chars.to_a
first = true
first_a, first_b = nil, nil
output = false
answer = "NO"
as.each_with_index do |a, i|
  b = bs[i]
  if a != b
    if output
      answer = "NO"
      break
    end
    if first
      first_a = a
      first_b = b
      first = false
    else
      answer = "YES" if a == first_b && b == first_a
      output = true
    end
  end
end

puts answer

def main
  a = STDIN.gets
  b = STDIN.gets

  return 'NO' if a.length != b.length

  i = 0
  i += 1 while a[i] == b[i]

  return 'YES' if i == a.length

  j = a.length - 1
  j -= 1 while a[j] == b[j]

  return 'YES' if j == i + 1 && a[i] == b[j] && a[j] == b[i]

  return 'NO'
end

print main

def say_no
  puts 'NO'
  exit
end

g1, g2 = [gets.chomp, gets.chomp]
n = g1.size
say_no if n != g2.size
d = []
for i in 0...n
  say_no if g1[i] != g2[i] && ((t = (d << i).size) > 2 || (t == 2 && (g1[d[0]] != g2[d[1]] || g1[d[1]] != g2[d[0]])))
end
puts 'YES'

a , b  = gets.strip, gets.strip
ac, bc = Hash.new(0), Hash.new(0)

a.each_char { |c| ac[c.to_sym] += 1 }
b.each_char { |c| bc[c.to_sym] += 1 }

print ac == bc ? :YES : :NO

a, b, c  = gets.strip, gets.strip, 0
(print :NO; exit) unless a.length == b.length
a.length.times { |i| c += 1 unless a[i] == b[i] }
print c == 2 ? :YES : :NO

a, b = STDIN.read.split("\n")
a1, a2 = a.split('').uniq
b1, b2 = b.split('').uniq

ac1 = a.count(a1)
bc1 = b.count(b1)

ac2 = a2 ? a.count(a2) : 0
bc2 = b2 ? b.count(b2) : 0

print ac1 == bc1 && ac2 == bc2 ? :YES : :NO


def make_fail(str)
    kmp = Array.new(str.length)
    i, j = [1, 0]
    kmp[0] = 0
    while (i < str.length) do
        kmp[i] = j
        while (j > 0 and str[i] != str[j]) do
            j = kmp[j]
        end
        i, j = i + 1, j + 1
    end
    return kmp
end

def get_cycle(str, kmp)
    last = kmp.length - 1
    if kmp[last] == 0 or str[last] != str[kmp[last]]
        return str.length - 1
    else
        if last % (last - kmp[last]) == 0
            return last - kmp[last]
        end
        return last
    end
end

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

def num_of_divisors(num)
    if num < 2
        return 1
    end
    i, cnt = 1, 0
    while i <= num do
        cnt = cnt + 1 if num % i == 0
        i = i + 1
    end
    return cnt
end

s1 = " " + gets.split.first
s2 = " " + gets.split.first

c1 = get_cycle(s1, make_fail(s1))
c2 = get_cycle(s2, make_fail(s2))
n1 = (s1.length - 1) / c1
n2 = (s2.length - 1) / c2

# puts n1.to_s + " " + n2.to_s

if c1 != c2 or s1[1, c1] != s2[1, c2]
    # puts c1.to_s + " " + c2.to_s
    puts 0
else
    g = gcd(n1, n2)
    puts num_of_divisors(g)
end

# ProblemD

def divisors(n)
  ret = []

  i = 1
  while i * i <= n
    if n % i == 0
      ret << i
      if (ret.index(n / i) == nil)
        ret << (n / i)
      end
    end
    i += 1
  end

  return ret
end

s1 = gets.chomp
s2 = gets.chomp

base = ""
target = ""
if s1.size <= s2.size
  base = s1
  target = s2
else
  base = s2
  target = s1
end

base_size = base.size
target_size = target.size

res = 0

base_divisors = divisors(base_size)
base_divisors.each do |base_divisor|
  tmp_str = base[0..base_divisor-1]
  if (tmp_str * (base_size / base_divisor)) == base
    if target_size % base_divisor == 0
      if (tmp_str * (target_size / base_divisor)) == target
        res += 1
      end
    end
  end
end

puts res

def make_fail(str)
    kmp = Array.new(str.length)
    i, j = [1, 0]
    kmp[0] = 0
    while (i < str.length) do
        kmp[i] = j
        while (j > 0 and str[i] != str[j]) do
            j = kmp[j]
        end
        i, j = i + 1, j + 1
    end
    return kmp
end

def get_cycle(str, kmp)
    last = kmp.length - 1
    if kmp[last] == 0 or str[last] != str[kmp[last]]
        return str.length - 1
    else
        return last - kmp[last]
    end
end

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

def num_of_divisors(num)
    if num < 2
        return 1
    end
    i, cnt = 1, 0
    while i <= num do
        cnt = cnt + 1 if num % i == 0
        i = i + 1
    end
    return cnt
end

s1 = " " + gets.split.first
s2 = " " + gets.split.first

c1 = get_cycle(s1, make_fail(s1))
c2 = get_cycle(s2, make_fail(s2))
n1 = (s1.length - 1) / c1
n2 = (s2.length - 1) / c2

# puts n1.to_s + " " + n2.to_s

if c1 != c2 or s1[1, c1] != s2[1, c2]
    puts 0
else
    g = gcd(n1, n2)
    puts num_of_divisors(g) # if s1.length < 100
    # puts s1.length.to_s + " " + s2.length.to_s if s1.length > 100
end

def make_fail(str)
    kmp = Array.new(str.length)
    i, j = [1, 0]
    kmp[0] = 0
    while (i < str.length) do
        kmp[i] = j
        while (j > 0 and str[i] != str[j]) do
            j = kmp[j]
        end
        i, j = i + 1, j + 1
    end
    return kmp
end

def get_cycle(str, kmp)
    last = kmp.length - 1
    if kmp[last] == 0 or str[last] != str[kmp[last]]
        return str.length - 1
    else
        return last - kmp[last]
    end
end

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

s1 = " " + gets.split.first
s2 = " " + gets.split.first

n1 = (s1.length - 1) / get_cycle(s1, make_fail(s1))
n2 = (s2.length - 1) / get_cycle(s2, make_fail(s2))

# puts n1.to_s + " " + n2.to_s

if !(s1.include? s2) and !(s2.include? s2)
    puts 0
else
    g = gcd(n1, n2)
    i = 1
    cnt = 0
    while i * i <= g do
        if g % i == 0
            cnt = cnt + 1
        end
        i = i + 1
    end

    cnt = cnt + 1 if g != 1

    puts cnt
end

def make_fail(str)
    kmp = Array.new(str.length)
    i, j = [1, 0]
    kmp[0] = 0
    while (i < str.length) do
        kmp[i] = j
        while (j > 0 and str[i] != str[j]) do
            j = kmp[j]
        end
        i, j = i + 1, j + 1
    end
    return kmp
end

def get_cycle(str, kmp)
    last = kmp.length - 1
    if kmp[last] == 0 or str[last] != str[kmp[last]]
        return str.length - 1
    else
        return last - kmp[last]
    end
end

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

def num_of_divisors(num)
    if num < 2
        return 1
    end
    i, cnt = 2, 2
    while i * i <= num do
        cnt = cnt + 1 if num % i == 0
        i = i + 1
    end
    return cnt
end

s1 = " " + gets.split.first
s2 = " " + gets.split.first

n1 = (s1.length - 1) / get_cycle(s1, make_fail(s1))
n2 = (s2.length - 1) / get_cycle(s2, make_fail(s2))

# puts n1.to_s + " " + n2.to_s

if !(s1.include? s2) and !(s2.include? s2)
    puts 0
else
    g = gcd(n1, n2)
    puts num_of_divisors(g) if s1.length < 100
    puts s1.length.to_s + " " + s2.length.to_s if s1.length > 100
end

def make_fail(str)
    kmp = Array.new(str.length)
    i, j = [1, 0]
    kmp[0] = 0
    while (i < str.length) do
        kmp[i] = j
        while (j > 0 and str[i] != str[j]) do
            j = kmp[j]
        end
        i, j = i + 1, j + 1
    end
    return kmp
end

def get_cycle(str, kmp)
    last = kmp.length - 1
    if kmp[last] == 0 or str[last] != str[kmp[last]]
        return str.length - 1
    else
        return last - kmp[last]
    end
end

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

def num_of_divisors(num)
    if num < 2
        return 1
    end
    i, cnt = 1, 0
    while i <= num do
        cnt = cnt + 1 if num % i == 0
        i = i + 1
    end
    return cnt
end

s1 = " " + gets.split.first
s2 = " " + gets.split.first

n1 = (s1.length - 1) / get_cycle(s1, make_fail(s1))
n2 = (s2.length - 1) / get_cycle(s2, make_fail(s2))

# puts n1.to_s + " " + n2.to_s

if !(s1.include? s2) and !(s2.include? s1)
    puts 0
else
    g = gcd(n1, n2)
    puts num_of_divisors(g) # if s1.length < 100
    # puts s1.length.to_s + " " + s2.length.to_s if s1.length > 100
end

def make_fail(str)
    kmp = Array.new(str.length)
    i, j = [1, 0]
    kmp[0] = 0
    while (i < str.length) do
        kmp[i] = j
        while (j > 0 and str[i] != str[j]) do
            j = kmp[j]
        end
        i, j = i + 1, j + 1
    end
    return kmp
end

def get_cycle(str, kmp)
    last = kmp.length - 1
    if kmp[last] == 0 or str[last] != str[kmp[last]]
        return str.length - 1
    else
        return last - kmp[last]
    end
end

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

def num_of_divisors(num)
    if num < 2
        return 1
    end
    i, cnt = 1, 0
    while i <= num do
        cnt = cnt + 1 if num % i == 0
        i = i + 1
    end
    return cnt
end

s1 = " " + gets.split.first
s2 = " " + gets.split.first

n1 = (s1.length - 1) / get_cycle(s1, make_fail(s1))
n2 = (s2.length - 1) / get_cycle(s2, make_fail(s2))

# puts n1.to_s + " " + n2.to_s

if !(s1.include? s2) and !(s2.include? s2)
    puts 0
else
    g = gcd(n1, n2)
    puts num_of_divisors(g) # if s1.length < 100
    # puts s1.length.to_s + " " + s2.length.to_s if s1.length > 100
end

# ProblemD

s1 = gets.chomp
s2 = gets.chomp

base = ""
target = ""
if s1.size <= s2.size
  base = s1
  target = s2
else
  base = s2
  target = s1
end

base_size = base.size
target_size = target.size

res = 0
base.size.times do |i|
  tmp_str = base[0..i]
  if target.start_with?(tmp_str)
    n = i + 1
    if (base_size % n == 0) && (target_size % n == 0)
      if tmp_str * (base_size / n) == base && tmp_str * (target_size / n) == target
        puts tmp_str
        res += 1
      end
    end
  end
end

puts res


s = gets.chomp
h = Hash.new(0)
count = 0
stk = [-1]
(0...s.length).each { |i|
	a = s[i]
	if a == "("
		stk.push(i)
	else
		stk.pop
		if stk.empty?
			stk.push(i)
		else
			h[i - stk.last] += 1
		end
	end
}
v, c = h.sort_by { |k, v| k }.last
c = 1 if !v || v == 0
puts "#{v.to_i} #{c.to_i}"

s = gets.chomp

diff = 0
match = []
stack = []

(0...(s.size)).each do |i|
	if s[i] == '('
		diff += 1
		stack << i
	elsif s[i] == ')' and diff > 0
		diff -= 1
		index = stack.pop
		match[index] = i
	end
end

time = 0
max = 0
record = Array.new(s.size)
(0...s.size).each do |i|
	total = 0
	if (not match[i].nil?) and record[i].nil?
		record[i] = true
		total += (match[i] - i + 1)
		j = match[i] + 1
		while match[j] != nil
			total += (match[j] - j + 1)
			record[j] = true
			j = match[j] + 1
		end

		if max < total
			max = total
			time = 1
		elsif max == total
			time += 1
		end
	end
end

time = 1 if max == 0

puts "#{max} #{time}"

line = gets
line.strip!
longest = []  # )对应的最长的sequence长度
opn = []
i = 0
line.each_char do |ch|
	if ch == '('
		opn << i
	else
		if opn.empty?
			longest[i] = -1
		else
			relative = opn.pop
			longest[i] = i - relative + 1 # 不是最优，需要向前搜索
			if relative > 0 && line[relative - 1] == ")" && longest[relative - 1] != -1
				longest[i] += longest[relative - 1]
			end
		end
	end
	i += 1
end
max = 0
cnt = 1
# 不能使用.max方法，因为数组中有nil，不能将nil与整数相比较
longest.each do |item|
	if item && (item > max)
		max = item
		cnt = 1
	elsif item == max
		cnt += 1
	end
end
puts "#{max} #{cnt}"

str = gets
c = Array.new
stack = Array.new
i = 0
str.strip!
str.each_char do |s|
  if s=="("
    stack << i
  else
    if stack.empty?
      c[i]=-1
    else
      corr=stack.pop
      c[i]=i-corr+1
      if corr>0 and c[corr-1] and c[corr-1]!=-1
        c[i]+=c[corr-1]
      end
    end
  end
  i+=1
end
max=0
cnt=1
c.each do |cc|
  if cc and cc>max
    max=cc
    cnt=1
  elsif cc==max
    cnt+=1
  end
end
puts "#{max} #{cnt}"

s = gets.chomp
h = Hash.new(0)
count = 0
stk = []
(0...s.length).each { |i|
	a = s[i]
	if a == "("
		stk.push(a)
	else
		if stk.last == "("
			stk.pop
			count += 2
		else
			count = 0
		end
		h[count] += 1
	end
}
v, c = h.sort_by { |k, v| k }.last
c = 1 if !v
puts "#{v.to_i} #{c.to_i}"

s = gets.chomp
h = Hash.new(0)
count = 0
stk = []
(0...s.length).each { |i|
	a = s[i]
	if a == "("
		stk.push(a)
	else
		if stk.last == "("
			stk.pop
			count += 2
		else
			count = 0
		end
		h[count] += 1
	end
}
v, c = h.sort_by { |k, v| k }.last
c = 1 if !v || v == 0
puts "#{v.to_i} #{c.to_i}"

s = gets.chomp
h = Hash.new(0)
count = 0
stk = []
(0...s.length).each { |i|
	a = s[i]
	if a == "("
		stk.push(a)
	else
		if stk.last == "("
			stk.pop
			count += 2
			h[count] += 1
		else
			count = 0
		end
	end
}
v, c = h.sort_by { |k, v| v }.last
c = 1 if !v
puts "#{v.to_i} #{c.to_i}"

s = gets.chomp

diff = 0
match = []
stack = []

(0...(s.size)).each do |i|
	if s[i] == '('
		diff += 1
		stack << i
	elsif s[i] == ')' and diff > 0
		diff -= 1
		index = stack.pop
		match[index] = i
		match[i] = index
	end
end

max = -1
time = 0
(0...s.size).each do |i|
	next if match[i].nil?

	if max < (i - match[i]).abs
		max = (i - match[i]).abs
		time += 1
	elsif max == (i - match[i]).abs
		time += 1
	end

end

time = 2 if max == -1

puts "#{max + 1} #{time / 2}"


t = gets.to_i
ans = []
t.times do
  r,g,b,w = gets.chomp.split(" ").map(&:to_i)
  sum = r+g+b+w
  if sum % 2 == 0
    if r%2==0 && g%2==0 && b%2==0 && w%2==0
      ans << "YES"
      next
    end
  else
    judge = 0
    judge += 1 if r%2==1
    judge += 1 if g%2==1
    judge += 1 if b%2==1
    judge += 1 if w%2==1
    if judge == 1
      ans << "YES"
      next
    end
  end
  if r > 0 && g > 0 && b > 0
    r -= 1
    g -= 1
    b -= 1
    w += 3
    if sum % 2 == 0
      if r%2==0 && g%2==0 && b%2==0 && w%2==0
        ans << "YES"
        next
      end
    else
      judge = 0
      judge += 1 if r%2==1
      judge += 1 if g%2==1
      judge += 1 if b%2==1
      judge += 1 if w%2==1
      if judge == 1
        ans << "YES"
        next
      end
    end
  end
  ans << "NO"
end
ans.each do |s|
  puts s
end

gets.to_i.times do
  arr = gets.split(' ').map(&:to_i)
  even_number = arr.count { |num| num.even? }

  if even_number >= 3
    puts 'Yes'
  elsif even_number == 2
    puts 'No'
  elsif arr.take(3).include?(0)
    puts 'No'
  else
    puts 'Yes'
  end
end

t = gets.to_i
t.times do
	r, g, b, w = gets.split.map &:to_i
	is_ok = [r, g, b, w].count(&:odd?) < 2
	is_ok ||= [r, g, b].min > 0 && [r-1, g-1, b-1, w+3].count(&:odd?) < 2
	puts (is_ok ? "Yes" : "No")
end

gets.to_i.times do
  arr = gets.split(' ').map(&:to_i)
  even_number = arr.count { |num| num.even? }

  if even_number >= 3
    puts 'Yes'
  elsif even_number == 2
    puts 'No'
  elsif arr.include?(0)
    puts 'No'
  else
    puts 'Yes'
  end
end

t = gets.to_i
t.times do
	r, g, b, w = gets.split.map &:to_i
	is_ok = [r, g, b, w].count(&:odd?) < 2
	is_ok ||= [r, g, b].min > 0 && [r-1, g-1, b-1, w].count(&:odd?) < 2
	puts (is_ok ? "Yes" : "No")
end

t = gets.to_i
t.times do
	r, g, b, w = gets.split.map &:to_i
	is_ok = [r, g, b, w].count(&:odd?) < 2
	is_ok ||= [r, g, b].min > 0 && [r-1, g-1, b-1, w].count(&:odd?)
	puts (is_ok ? "Yes" : "No")
end


N = gets.chomp.to_i
a = Array.new(N+1)
if N.modulo(4) <= 1
  (1..N/2).step(2) do |i|
    a[i], a[i+1], a[N-i+1], a[N-i] = i+1, N-i+1, N-i, i
  end
  a[N / 2 + 1] = N / 2 + 1 if N % 2 == 1
  puts a[1..N].join(' ')
elsif
  puts "-1"
end

n = gets.to_i

if n % 4 == 2 || n % 4 == 3 then
    puts "-1"
    exit
end

ret = Array.new(n, 0)
ret[n / 2] = n / 2 if n % 2
i = 0
while i < n / 2 do
    ret[i], ret[i + 1], ret[n - 2 - i], ret[n - 1 - i] = i + 1, n - 1 - i, i, n - 2 - i
    i += 2
end

ret.map!{ |i| i + 1 }
puts ret.join(' ')


n = gets.chomp.to_i
hs = Hash.new(0)
for c0 in 'a'..'y'
  for c1 in 'a'..'z'
    hs[c0 + c1] = 0 if c0 < c1
  end
end

n.times do
  line = gets.chomp
  cs = line.split('').sort.uniq
  if cs.size == 1
    hs[cs[0]] += line.size
  elsif cs.size == 2
    hs[cs[0] + cs[1]] += line.size
  end
end

rtn = 0

hs.each do |k, v|
  if k.size == 2
    hs[k] += hs[k[0]] + hs[k[1]]
  end
end

hs.each do |k, v|
  rtn = [rtn, v].max
end

puts rtn

require 'set'

file = File.exist?('in.in') ? File.new('in.in', 'r') : STDIN

def init_both(char1,char2)
  total = 0
  [char1,char2].each do |char|
    if @global_count[char]
      total += @global_count[char]
    end
  end
  total
end

n = file.gets.to_i
@global_count = {}
global_words = {}

while n > 0 do
  n -= 1
  word = file.gets.chomp

  valid_word = true
  char1 = word.chars.first
  char2 = nil
  current_count = {}
  word.chars.each do |char|
    char2 ||= char if char != char1
    if char != char1 && char != char2
      valid_word = false
      break
    end
    current_count[char] ||= 0
    current_count[char] += 1
  end
  if valid_word
    if char2
      both_key = "#{char1}#{char2}".chars.sort.join
      @global_count[both_key] ||= init_both(char1,char2)
      @global_count[both_key] += word.length
      global_words[char1] ||= Set.new [char1]
      global_words[char1].add both_key
      global_words[char2] ||= Set.new [char2]
      global_words[char2].add both_key
    else
      @global_count[char1] ||= 0
      global_words[char1] ||= Set.new [char1]
      global_words[char1].add char1

      global_words[char1].each do |char|
        @global_count[char] += word.length
      end
    end
  end
end
# Generate all possible combinations for every single word with word.length == 1
global_words.each do |k,v|
	if k.length == 1
		global_words.each do |q,b|
			both_key = "#{q}#{k}".chars.sort.join
			if q != k && q.length == 1
				global_words[k].add both_key
				@global_count[both_key] ||= init_both(k,q)
			end
		end
	end
end

@global_count = @global_count.sort {|a1,a2| a2[1] <=> a1[1] }
@global_count = Hash[*@global_count.flatten]
puts @global_count.values.first || 0

ws = []
gets.to_i.times do
    ws << gets.strip
end

m = 0
('a'..'z').each do |c1|
    ('a'..'z').each do |c2|
        s = ws.select {|w| w.chars.all?{|c| c == c1 || c == c2 } }.join.size
        m = [m, s].max
    end
end
p m

def get_arr(arr)
  a = arr[0]
  b = arr.delete(a)[0]
  return [a,b]
end

def exist?(arr, arr1)
  arr.each do |x|
    if x == arr1
      return true
      break
    end
  end
  false
end
n = gets.chomp.to_i
x, arr, array, len, arr1, l1, sum = [], [], [], [0], [], [], 0
(1..n).each do |i|
  a = gets.chomp
  t = String.new(a)
  num = 0
  a.each_char do |x|
    if a.delete(x) != a
      a.delete!(x)
      num += 1
    end
    if num == 3
      break
    end
  end
  if num < 3
    arr << t
  end
end
arr.each_with_index do |arr1, index1|
  len[index1] = arr1.length
  if !exist?(array, arr1)
    arr.each_with_index do |arr2, index2|
      if index1 == index2
        next
      else
        if get_arr(arr1) == get_arr(arr2) || get_arr(arr1).reverse == get_arr(arr2) || arr1.squeeze.include?(arr2.squeeze)
          len[index1] += arr2.length
        end
      end
    end
    array << get_arr(arr1)
  end
end
l = len.sort.last
arr.each do |a|
  if a.squeeze.length == 1
    arr1 << a.squeeze
  end
end
if arr1.length > 0
  arr1.uniq.each do |a1|
    sum = 0
    arr.each do |a|
      if a1 == a.squeeze
        sum += a.length
      end
    end
    l1 << sum
  end
  l1.sort!
  p l1.last + l1[l1.length-2] > l && l1.length > 1 ? l1.last + l1[l1.length-2] : l
else
  p l
end

# Problem: http://codeforces.com/contest/593/problem/A
a = []
rs = [0]
gets.to_i.times {a << gets.chomp }
for i in ('a'..'z')
  for j in (i..'z')
    sum = 0
    a.each do |s|
      continue = true
      s.split("").each do |c|
        if c != i and c != j
          continue = false
        end
      end
      if continue == true
        sum += s.size
      end
    end
    if sum > 0
      rs << sum
    end
  end
end
puts rs.max

# Problem: http://codeforces.com/contest/593/problem/A
a = []
rs = [0]
gets.to_i.times {a << gets.chomp }
for i in ('a'..'z')
  for j in (i..'z')
    sum = 0
    a.each do |s|
      continue = true
      s.size.times do |k|
        if s[k] != i and s[k] != j
          continue = false
        end
      end
      if continue == true
        sum += s.size
      end
    end
    if sum > 0
      rs << sum
    end
  end
end
puts rs.max

# Problem: http://codeforces.com/contest/593/problem/A
a = []
d = Hash.new 0
gets.to_i.times {a << gets.chomp }
a.each do |s|
  s_asize = s.size
  s_uniq = s.split("").uniq
  s_size = s_uniq.size
  if s_size > 2
    next
  end
  if s_size == 1
    c = s_uniq.pop
    d[c] += s_asize
    d.keys.each do |k|
      if k.size == 2 and k.include? c
        d[k] += s_asize
      elsif k.size == 1 and k != c
        new_k = [k, c].sort.join
        if d[new_k] == 0
          d[new_k] = d[k] + d[c]
        end
      end
    end
  end
  if s_size == 2
    k = s_uniq.sort.join
    if d[k] == 0
      s_uniq.each { |t| d[k] += d[t] }
    end
    d[k] += s_asize
  end
end
if d.empty?
  puts 0
else
  puts d.values.max
end

def max(a, b)
    return a > b ? a : b
end
n = gets.chomp.to_i
v = []
for i in(1..n)
    v[i-1] = gets.chomp
end
c = 0
for i in('a'..'z')
    for j in(i..'z')
        c1 = 0
        for x in(1..n)
            sw = 0
            for y in(0..(v[x-1].size-1))
                if v[x-1][y] == i || v[x-1][y] == j
                else
                    sw = 1
                end
            end
            if sw==0
                c1+=v[x-1].size
            end
        end
        c = max(c,c1)
    end
end
puts c

n = gets.chomp.to_i
d = Hash.new(0)
n.times do
  word = gets.chomp
  k = word.split("").uniq.sort
  v = word.length
  d[k] += v if k.length <= 2
end
res = 0
(?a..?z).to_a.combination(2) do |kk|
  res = [res, d[[kk[0]]] + d[[kk[1]]] + d[kk]].max
end
puts res

a=("a" .. "z" ).to_a
hash={}
0.upto(25) {|i| hash[a[i]]=i   }
grid = Array.new(26) { Array.new(26,0) }
a=gets.chomp.to_i
a.times do
temp=gets.chomp.split("")
t1=temp.length
temp.uniq!
t2=temp.length
if t2<3
if t2==1
r=hash[temp[0]]
c=hash[temp[0]]
grid[r][c]+=t1
else
r=hash[temp[0]]
c=hash[temp[1]]
grid[r][c]+=t1
grid[c][r]+=t1
end
end
end
ans=0

0.upto(25) do |i|
0.upto(25) do |j|
if i!=j
temp=grid[i][i]+grid[i][j]+grid[j][j]
if temp>ans
ans=temp
end
end
end
end
puts "#{ans}"

def get_array(arr)
  a = arr[0]
  b = arr.delete(a)[0]
  return [a,b]
end
n = gets.chomp.to_i
x, arr, len, arr1, l1, sum = [], [], [0], [], [], 0  #len初始化为0，防止所有输入都不符合，返回0
(1..n).each do |i|
  a = gets.chomp
  t = String.new(a)
  num = 0
  a.each_char do |x|
    if a.delete(x) != a
      a.delete!(x)
      num += 1
    end
    break if num == 3
  end
  arr << t if num < 3
end
arr.each_with_index do |arr1, index1|
  len[index1] = arr1.length
  arr.each_with_index do |arr2, index2|
    next if index1 == index2
    len[index1] += arr2.length if get_array(arr1) == get_array(arr2) || get_array(arr1).reverse == get_array(arr2) || arr1.squeeze.include?(arr2.squeeze)
  end
end
l = len.sort.last
arr.each do |a|
  arr1 << a.squeeze if a.squeeze.length == 1
end
if arr1.length > 0     #排除超过一种字符的行,这里操作每行都是一种字符的情况
  arr1.uniq.each do |a1|
    sum = 0
    arr.each do |a|
      sum += a.length if a1 == a.squeeze
    end
    l1 << sum
  end
  l1.sort!
  p l1.last + l1[l1.length-2] > l && l1.length > 1 ? l1.last + l1[l1.length-2] : l
else
  p l
end

def get_arr(arr)
  a = arr[0]
  b = arr.delete(a)[0]
  return [a,b]
end
# def exist?(arr, arr1)
#   arr.each do |x|
#     if x == arr1
#       true
#       break
#     end
#   end
#   false
# end
n = gets.chomp.to_i
x, arr, array, len, arr1, l1, sum = [], [], [], [0], [], [], 0
(1..n).each do |i|
  a = gets.chomp
  t = String.new(a)
  num = 0
  a.each_char do |x|
    if a.delete(x) != a
      a.delete!(x)
      num += 1
    end
    if num == 3
      break
    end
  end
  if num < 3
    arr << t
  end
end
arr.each_with_index do |arr1, index1|
  len[index1] = arr1.length
  # if !exist?(array, arr1)
    arr.each_with_index do |arr2, index2|
      if index1 == index2
        next
      else
        if get_arr(arr1) == get_arr(arr2) || get_arr(arr1).reverse == get_arr(arr2) || arr1.squeeze.include?(arr2.squeeze)
          len[index1] += arr2.length
        end
      end
    end
    array << get_arr(arr1)
  # end
end
l = len.sort.last
arr.each do |a|
  if a.squeeze.length == 1
    arr1 << a.squeeze
  end
end
if arr1.length > 0
  arr1.uniq.each do |a1|
    sum = 0
    arr.each do |a|
      if a1 == a.squeeze
        sum += a.length
      end
    end
    l1 << sum
  end
  l1.sort!
  p l1.last + l1[l1.length-2] > l && l1.length > 1 ? l1.last + l1[l1.length-2] : l
else
  p l
end

require 'set'

file = File.exist?('in.in') ? File.new('in.in', 'r') : STDIN

def init_both(char1,char2)
  total = 0
  words = []
  [char1,char2].each do |char|
    if @global_count[char]
      total += @global_count[char].total
      words << @global_count[char].words
    end
  end
  Pair.new(total, words.flatten)
end

n = file.gets.to_i
Pair = Struct.new(:total, :words)
@global_count = {}
global_words = {}

while n > 0 do
  n -= 1
  word = file.gets.chomp

  valid_word = true
  char1 = word.chars.first
  char2 = nil
  current_count = {}
  word.chars.each do |char|
    char2 ||= char if char != char1
    if char != char1 && char != char2
      valid_word = false
      break
    end
    current_count[char] ||= 0
    current_count[char] += 1
  end
  if valid_word
    if char2
      both_key = "#{char1}#{char2}".chars.sort.join
      @global_count[both_key] ||= init_both(char1,char2)
      @global_count[both_key].total += word.length
      @global_count[both_key].words << word
      global_words[char1] ||= Set.new [char1]
      global_words[char1].add both_key
      global_words[char2] ||= Set.new [char2]
      global_words[char2].add both_key
    else
      @global_count[char1] ||= Pair.new(0, [])
      global_words[char1] ||= Set.new [char1]
      global_words[char1].add char1

      global_words[char1].each do |char|
        @global_count[char].total += word.length
        @global_count[char].words << word
      end
    end
  end
end
global_words.each do |k,v|
	if k.length == 1
		global_words.each do |q,b|
			both_key = "#{q}#{k}".chars.sort.join
			if q != k && q.length == 1
				global_words[k].add both_key
				@global_count[both_key] ||= init_both(k,q)
			end
		end
	end
end
@global_count = @global_count.sort {|a1,a2| a2[1].total <=> a1[1].total }
@global_count = Hash[*@global_count.flatten]
# puts @global_count
# puts global_words
if @global_count.values.first
  answer = @global_count.values.first.total
  puts answer || 0
else
  puts 0
end

# Problem: http://codeforces.com/contest/593/problem/A
a = []
d = Hash.new 0
gets.to_i.times {a << gets.chomp }
a.each do |s|
  s_asize = s.size
  s_uniq = s.split("").uniq
  s_size = s_uniq.size
  if s_size > 2
    next
  end
  if s_size == 1
    c = s_uniq.pop
    d[c] += s_asize
    d.keys.each do |k|
      if k.size == 2 and k.include? c
        d[k] += s_asize
      end
    end
  end
  if s_size == 2
    k = s_uniq.sort.join
    d[k] += s_asize
  end
end
puts d.values.max

# Problem: http://codeforces.com/contest/593/problem/A
a = []
d = Hash.new 0
gets.to_i.times {a << gets.chomp }
a.each do |s|
  s_asize = s.size
  s_uniq = s.split("").uniq
  s_size = s_uniq.size
  if s_size > 2
    next
  end
  if s_size == 1
    c = s_uniq.pop
    d[c] += s_asize
    d.keys.each do |k|
      if k.size == 2 and k.include? c
        d[k] += s_asize
      elsif k.size == 1 and k != c
        new_k = [k, c].sort.join
        if d[new_k] == 0
          d[new_k] = d[k] + d[c]
        end
      end
    end
  end
  if s_size == 2
    k = s_uniq.sort.join
    d[k] += s_asize
  end
end
if d.empty?
  puts 0
else
  puts d.values.max
end

# Problem: http://codeforces.com/contest/593/problem/A
a = []
d = Hash.new 0
gets.to_i.times {a << gets.chomp }
a.each do |s|
  s_asize = s.size
  s_uniq = s.split("").uniq
  s_size = s_uniq.size
  if s_size > 2
    next
  end
  if s_size == 1
    c = s_uniq.pop
    d[c] += s_asize
    d.keys.each do |k|
      if k.size == 2 and k.include? c
        d[k] += s_asize
      elsif k.size == 1 and k != c
        new_k = [k, c].sort.join
        if d[new_k] == 0
          d[new_k] = d[k] + d[c]
        end
      end
    end
  end
  if s_size == 2
    k = s_uniq.sort.join
    d[k] += s_asize
    d.keys.each do |t|
      if t.size == 1 and k.include? t
        d[k] += d[t]
      end
    end
  end
end
if d.empty?
  puts 0
else
  puts d.values.max
end

# Problem: http://codeforces.com/contest/593/problem/A
a = []
d = Hash.new 0
gets.to_i.times {a << gets.chomp }
a.each do |s|
  s_asize = s.size
  s_uniq = s.split("").uniq
  s_size = s_uniq.size
  if s_size > 2
    next
  end
  if s_size == 1
    c = s_uniq.pop
    d[c] += s_asize
    d.keys.each do |k|
      if k.size == 2 and k.include? c
        d[k] += s_asize
      elsif k.size == 1 and k != c
        new_k = [k, c].sort.join
        d[new_k] = d[k] + d[c]
      end
    end
  end
  if s_size == 2
    k = s_uniq.sort.join
    d[k] += s_asize
  end
end
if d.empty?
  puts 0
else
  puts d.values.max
end

# Problem: http://codeforces.com/contest/593/problem/A
a = []
d = Hash.new 0
gets.to_i.times {a << gets.chomp }
a.each do |s|
  s_asize = s.size
  s_uniq = s.split("").uniq
  s_size = s_uniq.size
  if s_size > 2
    next
  end
  if s_size == 1
    c = s_uniq.pop
    d[c] += s_asize
    d.keys.each do |k|
      if k.size == 2 and k.include? c
        d[k] += s_asize
      end
    end
  end
  if s_size == 2
    k = s_uniq.sort.join
    d[k] += s_asize
  end
end
if d.empty?
  puts 0
else
  puts d.values.max
end

require 'set'

class Pair
  attr_accessor :total, :words

  def initialize(total, words)
    @total = total
    @words = words
  end
end

n = gets.to_i
# Pair = Struct.new(:total, :words)
@global_count = {}
global_words = {}

# def init_both(char1,char2)
# 	total = 0
# 	words = []
# 	[char1,char2].each do |char|
# 		if @global_count[char]
# 			total += @global_count[char].total
# 			words = @global_count[char].words
# 		end
# 	end
# 	Pair.new(total, words)
# end

# while n > 0 do
# 	n -= 1
# 	word = gets.chomp

# 	valid_word = true
# 	char1 = word.chars.first
# 	char2 = nil
# 	current_count = {}
# 	word.chars.each do |char|
# 		char2 ||= char if char != char1
# 		if char != char1 && char != char2
# 			valid_word = false
# 			break
# 		end
# 		current_count[char] ||= 0
# 		current_count[char] += 1
# 	end

# 	if valid_word
# 		if char2
# 			both_key = "#{char1}#{char2}".chars.sort.join
# 			@global_count[both_key] ||= init_both(char1,char2)
# 			@global_count[both_key].total += word.length
# 			@global_count[both_key].words << word
# 			global_words[char1] ||= Set.new [char1]
# 			global_words[char1].add both_key
# 			global_words[char2] ||= Set.new [char2]
# 			global_words[char2].add both_key
# 		else
# 			@global_count[char1] ||= Pair.new(0, [])
# 			global_words[char1] ||= Set.new [char1]
# 			global_words[char1].add char1

# 			global_words[char1].each do |char|
# 				@global_count[char].total += word.length
# 				@global_count[char].words << word
# 			end
# 		end
# 	end
# end

# @global_count = @global_count.sort {|a1,a2| a2[1].total <=> a1[1].total }.to_h
# if @global_count.values.first
# 	answer = @global_count.values.first.total
# 	if @global_count.keys.first.length == 1
# 		size = 0
# 		answer = 0
# 		@global_count.keys.each do |key|
# 			if key.length == 1
# 				size +=1
# 				answer += @global_count[key].total
# 			end
# 			break if size == 2
# 		end
# 	end
# 	puts answer || 0

# else
# 	puts 0
# end

require 'set'
n = gets.to_i
global_count = {}
global_words = {}

while n > 0 do
	n -= 1
	word = gets.chomp

	valid_word = true
	char1 = word.chars.first
	char2 = nil
	current_count = {}
	word.chars.each do |char|
		char2 ||= char if char != char1
		if char != char1 && char != char2
			valid_word = false
			break
		end
		current_count[char] ||= 0
		current_count[char] += 1
	end

	if valid_word
		both_key = "#{char1}#{char2}".chars.sort.join

		global_count[char1] ||= 0
		global_words[char1] ||= Set.new [char1]
		global_count[both_key] ||= 0
		global_words[char1].add both_key

		if char2

			global_count[char2] ||= 0
			global_words[char2] ||= Set.new [char2]
			global_words[char2].add both_key

			global_count[both_key] += current_count[char1]
			global_count[char1] += current_count[char1]
			global_count[both_key] += current_count[char2]
			global_count[char2] += current_count[char2]
		else
			global_words[char1].each do |word|
				global_count[word] += current_count[char1]
			end
		end
	end
end

puts global_count.values.max || 0

require 'set'

file = File.exist?('in.in') ? File.new('in.in', 'r') : STDIN

def init_both(char1,char2)
  total = 0
  words = []
  [char1,char2].each do |char|
    if @global_count[char]
      total += @global_count[char].total
      words = @global_count[char].words.dup
    end
  end
  Pair.new(total, words)
end

n = file.gets.to_i
Pair = Struct.new(:total, :words)
@global_count = {}
global_words = {}

while n > 0 do
  n -= 1
  word = file.gets.chomp

  valid_word = true
  char1 = word.chars.first
  char2 = nil
  current_count = {}
  word.chars.each do |char|
    char2 ||= char if char != char1
    if char != char1 && char != char2
      valid_word = false
      break
    end
    current_count[char] ||= 0
    current_count[char] += 1
  end
  if valid_word
    if char2
      both_key = "#{char1}#{char2}".chars.sort.join
      @global_count[both_key] ||= init_both(char1,char2)
      @global_count[both_key].total += word.length
      @global_count[both_key].words << word
      global_words[char1] ||= Set.new [char1]
      global_words[char1].add both_key
      global_words[char2] ||= Set.new [char2]
      global_words[char2].add both_key
    else
      @global_count[char1] ||= Pair.new(0, [])
      global_words[char1] ||= Set.new [char1]
      global_words[char1].add char1

      global_words[char1].each do |char|
        @global_count[char].total += word.length
        @global_count[char].words << word
      end

			global_words.each do |k,v|
				both_key = "#{char1}#{k}".chars.sort.join
				if char1 != k && k.length == 1
					global_words[char1].add both_key
					@global_count[both_key] ||= init_both(char1,k)
				end
			end

    end
  end
end
@global_count = @global_count.sort {|a1,a2| a2[1].total <=> a1[1].total }
@global_count = Hash[*@global_count.flatten]
# puts @global_count
# puts global_words
if @global_count.values.first
  answer = @global_count.values.first.total
  if @global_count.keys.first.length == 1
    size = 0
    answer = 0
    @global_count.keys.each do |key|
      if key.length == 1
        size +=1
        answer += @global_count[key].total
      end
      break if size == 2
    end
  end
  puts answer || 0

else
  puts 0
end

require 'set'

def init_both(char1,char2)
  total = 0
  words = []
  [char1,char2].each do |char|
    if @global_count[char]
      total += @global_count[char].total
      words = @global_count[char].words
    end
  end
  Pair.new(total, words)
end

n = gets.to_i
Pair = Struct.new(:total, :words)
@global_count = {}
global_words = {}

while n > 0 do
  n -= 1
  word = gets.chomp

  valid_word = true
  char1 = word.chars.first
  char2 = nil
  current_count = {}
  word.chars.each do |char|
    char2 ||= char if char != char1
    if char != char1 && char != char2
      valid_word = false
      break
    end
    current_count[char] ||= 0
    current_count[char] += 1
  end
  if valid_word
    if char2
      both_key = "#{char1}#{char2}".chars.sort.join
      @global_count[both_key] ||= init_both(char1,char2)
      @global_count[both_key].total += word.length
      @global_count[both_key].words << word
      global_words[char1] ||= Set.new [char1]
      global_words[char1].add both_key
      global_words[char2] ||= Set.new [char2]
      global_words[char2].add both_key
    else
      @global_count[char1] ||= Pair.new(0, [])
      global_words[char1] ||= Set.new [char1]
      global_words[char1].add char1

      global_words.each do |k,v|
        if k != char1 && k.length == 1
          both_key = "#{char1}#{k}".chars.sort.join
          unless @global_count[both_key]
            @global_count[both_key] ||= init_both(char1,k)
            global_words[char1].add both_key
          end
        end
      end

      global_words[char1].each do |char|
        @global_count[char].total += word.length
        @global_count[char].words << word
      end
    end
  end
end
@global_count = @global_count.sort {|a1,a2| a2[1].total <=> a1[1].total }
@global_count = Hash[*@global_count.flatten]

# puts @global_count
# puts global_words

if @global_count.values.first
  answer = @global_count.values.first.total
  if @global_count.keys.first.length == 1
    size = 0
    answer = 0
    @global_count.keys.each do |key|
      if key.length == 1
        size +=1
        answer += @global_count[key].total
      end
      break if size == 2
    end
  end
  puts answer || 0

else
  puts 0
end

require 'set'

def init_both(char1,char2)
  total = 0
  words = []
  [char1,char2].each do |char|
    if @global_count[char]
      total += @global_count[char].total
      words = @global_count[char].words
    end
  end
  Pair.new(total, words)
end

n = gets.to_i
Pair = Struct.new(:total, :words)
@global_count = {}
global_words = {}

while n > 0 do
  n -= 1
  word = gets.chomp

  valid_word = true
  char1 = word.chars.first
  char2 = nil
  current_count = {}
  word.chars.each do |char|
    char2 ||= char if char != char1
    if char != char1 && char != char2
      valid_word = false
      break
    end
    current_count[char] ||= 0
    current_count[char] += 1
  end
  if valid_word
    if char2
      both_key = "#{char1}#{char2}".chars.sort.join
      @global_count[both_key] ||= init_both(char1,char2)
      @global_count[both_key].total += word.length
      @global_count[both_key].words << word
      global_words[char1] ||= Set.new [char1]
      global_words[char1].add both_key
      global_words[char2] ||= Set.new [char2]
      global_words[char2].add both_key
    else
      @global_count[char1] ||= Pair.new(0, [])
      global_words[char1] ||= Set.new [char1]
      global_words[char1].add char1

      global_words.each do |k,v|
        if k != char1 && k.length == 1
          both_key = "#{char1}#{k}".chars.sort.join
          @global_count[both_key] ||= init_both(char1,char2)
          global_words[char1].add both_key
        end
      end

      global_words[char1].each do |char|
        @global_count[char].total += word.length
        @global_count[char].words << word
      end
    end
  end
end
@global_count = @global_count.sort {|a1,a2| a2[1].total <=> a1[1].total }
@global_count = Hash[*@global_count.flatten]

# puts @global_count
# puts global_words

if @global_count.values.first
  answer = @global_count.values.first.total
  if @global_count.keys.first.length == 1
    size = 0
    answer = 0
    @global_count.keys.each do |key|
      if key.length == 1
        size +=1
        answer += @global_count[key].total
      end
      break if size == 2
    end
  end
  puts answer || 0

else
  puts 0
end

require 'set'
n = gets.to_i
global_count = {}
global_words = {}

while n > 0 do
	n -= 1
	word = gets.chomp

	valid_word = true
	char1 = word.chars.first
	char2 = nil
	current_count = {}
	word.chars.each do |char|
		char2 ||= char if char != char1
		if char != char1 && char != char2
			valid_word = false
			break
		end
		current_count[char] ||= 0
		current_count[char] += 1
	end

	if valid_word

		both_key = "#{char1}#{char2}".chars.sort.join

		global_count[char1] ||= 0
		global_words[char1] ||= Set.new [char1]
		global_words[char1].add both_key

		if char2
			global_count[char2] ||= 0
			global_words[char2] ||= Set.new [char2]
			global_words[char2].add both_key
			global_count[char2] += current_count[char2]
			global_count[char1] += current_count[char1]

			global_count[both_key] ||= 0
			global_count[both_key] = global_count[char1] + global_count[char2]

		else
			global_words[char1].each do |word|
				global_count[word] += current_count[char1]
			end
		end
	end
end
puts global_count.values.max || 0

require 'set'

def init_both(char1,char2)
  total = 0
  words = []
  [char1,char2].each do |char|
    if @global_count[char]
      total += @global_count[char].total
      words = @global_count[char].words
    end
  end
  Pair.new(total, words)
end

n = gets.to_i
Pair = Struct.new(:total, :words)
@global_count = {}
global_words = {}

while n > 0 do
  n -= 1
  word = gets.chomp

  valid_word = true
  char1 = word.chars.first
  char2 = nil
  current_count = {}
  word.chars.each do |char|
    char2 ||= char if char != char1
    if char != char1 && char != char2
      valid_word = false
      break
    end
    current_count[char] ||= 0
    current_count[char] += 1
  end
  if valid_word
    if char2
      both_key = "#{char1}#{char2}".chars.sort.join
      @global_count[both_key] ||= init_both(char1,char2)
      @global_count[both_key].total += word.length
      @global_count[both_key].words << word
      global_words[char1] ||= Set.new [char1]
      global_words[char1].add both_key
      global_words[char2] ||= Set.new [char2]
      global_words[char2].add both_key
    else
      @global_count[char1] ||= Pair.new(0, [])
      global_words[char1] ||= Set.new [char1]
      global_words[char1].add char1

      global_words[char1].each do |char|
        @global_count[char].total += word.length
        @global_count[char].words << word
      end
    end
  end
end
@global_count = @global_count.sort {|a1,a2| a2[1].total <=> a1[1].total }
@global_count = Hash[*@global_count.flatten]
if @global_count.values.first
  answer = @global_count.values.first.total
  if @global_count.keys.first.length == 1
    size = 0
    answer = 0
    @global_count.keys.each do |key|
      if key.length == 1
        size +=1
        answer += @global_count[key].total
      end
      break if size == 2
    end
  end
  puts answer || 0

else
  puts 0
end

require 'set'

def init_both(char1,char2)
  total = 0
  words = []
  [char1,char2].each do |char|
    if @global_count[char]
      total += @global_count[char].total
      words = @global_count[char].words
    end
  end
  Pair.new(total, words)
end

n = gets.to_i
Pair = Struct.new(:total, :words)
@global_count = {}
global_words = {}

while n > 0 do
  n -= 1
  word = gets.chomp

  valid_word = true
  char1 = word.chars.first
  char2 = nil
  current_count = {}
  word.chars.each do |char|
    char2 ||= char if char != char1
    if char != char1 && char != char2
      valid_word = false
      break
    end
    current_count[char] ||= 0
    current_count[char] += 1
  end
  if valid_word
    if char2
      both_key = "#{char1}#{char2}".chars.sort.join
      @global_count[both_key] ||= init_both(char1,char2)
      @global_count[both_key].total += word.length
      @global_count[both_key].words << word
      global_words[char1] ||= Set.new [char1]
      global_words[char1].add both_key
      global_words[char2] ||= Set.new [char2]
      global_words[char2].add both_key
    else
      @global_count[char1] ||= Pair.new(0, [])
      global_words[char1] ||= Set.new [char1]
      global_words[char1].add char1

      global_words[char1].each do |char|
        @global_count[char].total += word.length
        @global_count[char].words << word
      end
    end
  end
end
puts 0
puts @global_count
@global_count = @global_count.sort {|a1,a2| puts 'ww'; puts a2[1].total; a2[1].total <=> a1[1].total }
puts 0.3
@global_count = Hash[*@global_count.flatten]
puts @global_count
if @global_count.values.first
  puts 3
  answer = @global_count.values.first.total
  if @global_count.keys.first.length == 1
    puts 4
    size = 0
    answer = 0
    @global_count.keys.each do |key|
      if key.length == 1
        size +=1
        answer += @global_count[key].total
      end
      break if size == 2
    end
  end
  puts answer || 0

else
  puts 0
end

n = gets.chomp.to_i
hs = Hash.new(0)
n.times do
  line = gets.chomp
  cs = line.split('').sort.uniq
  if cs.size == 1
    hs[cs[0]] += line.size
  elsif cs.size == 2
    hs[cs[0] + cs[1]] += line.size
  end
end

rtn = 0

hs.each do |k, v|
  if k.size == 2
    hs[k] += hs[k[0]] + hs[k[1]]
  end
end

hs.each do |k, v|
  rtn = [rtn, v].max
end

puts rtn

n = gets.chomp.to_i
hs = Hash.new(0)
n.times do
  cs = gets.chomp.split('').sort
  if cs.uniq.size == 1
    hs[cs[0]] += cs.size
  elsif cs.uniq.size == 2
    hs[cs[0] + cs[1]] += cs.size
  end
end

rtn = 0

hs.each do |k, v|
  if k.size == 2
    hs[k] += hs[k[0]] + hs[k[1]]
  end
end

hs.each do |k, v|
  rtn = [rtn, v].max
end

puts rtn

n = gets.chomp.to_i
d = Hash.new(0)
n.times do
  word = gets.chomp
  k = word.split("").uniq
  v = word.length
  d[k] += v if k.length <= 2
end

if d.empty? then
  res = 0
else
  res = d.values.max
  d.keys.combination(2) do |kk|
    if kk.flatten.uniq.length > 2 then
      next
    else
      res = [res, d[kk[0]] + d[kk[1]]].max
    end
  end

  d.keys.combination(3) do |kk|
    if kk.flatten.uniq.length > 2 then
      next
    else
      res = [res, d[kk[0]] + d[kk[1]]+d[kk[2]]].max
    end
  end
end

puts res

n = gets.chomp.to_i
d = Hash.new(0)
n.times do
  word = gets.chomp
  k = word.split("").uniq
  v = word.length
  d[k] += v if k.length <= 2
end
res = 0
(?a..?z).to_a.combination(2) do |kk|
  res = [res, d[[kk[0]]] + d[[kk[1]]] + d[kk]].max
end

puts res

n = gets.chomp.to_i
d = Hash.new(0)
n.times do
  word = gets.chomp
  k = word.split("").uniq
  v = word.length
  d[k] += v if k.length <= 2
end
res = d.values.max
d.keys.combination(2) do |kk|
  if kk.flatten.uniq.length > 2 then
    next
  else
    res = [res, d[kk[0]] + d[kk[1]]].max
  end
end
d.keys.combination(3) do |kk|
  if kk.flatten.uniq.length > 2 then
    next
  else
    res = [res, d[kk[0]] + d[kk[1]]+d[kk[2]]].max
  end
end
puts res

def get_arr(arr)
  a = arr[0]
  b = arr.split(a)[0]
  return [a,b]
end

def exist?(arr, arr1)
  arr.each do |x|
    if x == arr1
      return true
      break
    end
  end
  false
end
n = gets.chomp.to_i
arr, array, len = [], [], []
(1..n).each do |i|
  a = gets.chomp
  t = String.new(a)
  num = 0
  a.each_char do |x|
    if a.delete(x) != a
      a.delete!(x)
      num += 1
    end
    if num == 3
      break
    end
  end
  if num < 3
    arr << t
  end
end
arr.each_with_index do |arr1, index1|
  len[index1] = arr1.length
  if !exist?(array, arr1)
    arr.each_with_index do |arr2, index2|
      if index1 == index2
        next
      else
        if get_arr(arr1) == get_arr(arr2) || arr1.squeeze.include?(arr2.squeeze)
          len[index1] += arr2.length
        end
      end
    end
    array << get_arr(arr1)
  end
end
p len.sort.last

def get_arr(arr)
  a = arr[0]
  b = arr.delete(a)[0]
  return [a,b]
end

def exist?(arr, arr1)
  arr.each do |x|
    if x == arr1
      return true
      break
    end
  end
  false
end
n = gets.chomp.to_i
x, arr, array, len = [], [], [], [0]
(1..n).each do |i|
  a = gets.chomp
  t = String.new(a)
  num = 0
  a.each_char do |x|
    if a.delete(x) != a
      a.delete!(x)
      num += 1
    end
    if num == 3
      break
    end
  end
  if num < 3
    arr << t
  end
end
arr.each_with_index do |arr1, index1|
  len[index1] = arr1.length
  if !exist?(array, arr1)
    arr.each_with_index do |arr2, index2|
      if index1 == index2
        next
      else
        if get_arr(arr1) == get_arr(arr2) || get_arr(arr1).reverse == get_arr(arr2) || arr1.squeeze.include?(arr2.squeeze)
          len[index1] += arr2.length
        end
      end
    end
    array << get_arr(arr1)
  end
end
l = len.sort.last
arr1 = ""
l1 = 0
arr.each do |a|
  if a.length == l
    arr1 = a
    break
  end
end
if arr1.squeeze.length == 1
  arr.each do |a|
    if a.squeeze.length == 1 && a != arr1 && a.length > l1
      l1 = a.length
    end
  end
  p l+l1
else
  p l
end

def get_arr(arr)
  a = arr[0]
  b = arr.delete(a)[0]
  return [a,b]
end

def exist?(arr, arr1)
  arr.each do |x|
    if x == arr1
      return true
      break
    end
  end
  false
end
n = gets.chomp.to_i
x, arr, array, len = [], [], [], [0]
(1..n).each do |i|
  a = gets.chomp
  t = String.new(a)
  num = 0
  a.each_char do |x|
    if a.delete(x) != a
      a.delete!(x)
      num += 1
    end
    if num == 3
      break
    end
  end
  if num < 3
    arr << t
  end
end
arr.each_with_index do |arr1, index1|
  len[index1] = arr1.length
  if !exist?(array, arr1)
    arr.each_with_index do |arr2, index2|
      if index1 == index2
        next
      else
        if get_arr(arr1) == get_arr(arr2) || arr1.squeeze.include?(arr2.squeeze)
          len[index1] += arr2.length
        end
      end
    end
    array << get_arr(arr1)
  end
end
l = len.sort.last
if arr.length > 1
  arr.each do |k|
    if k.squeeze.length == 1
      x << k.length
    end
  end
  x.sort!
  l1 = x.last + x[x.length-2]
end
p l1 && l1 > l ? l1 : l

def get_arr(arr)
  a = arr[0]
  b = arr.delete(a)[0]
  return [a,b]
end

def exist?(arr, arr1)
  arr.each do |x|
    if x == arr1
      return true
      break
    end
  end
  false
end
n = gets.chomp.to_i
x, arr, array, len = [], [], [], [0]
(1..n).each do |i|
  a = gets.chomp
  t = String.new(a)
  num = 0
  a.each_char do |x|
    if a.delete(x) != a
      a.delete!(x)
      num += 1
    end
    if num == 3
      break
    end
  end
  if num < 3
    arr << t
  end
end
arr.each_with_index do |arr1, index1|
  len[index1] = arr1.length
  if !exist?(array, arr1)
    arr.each_with_index do |arr2, index2|
      if index1 == index2
        next
      else
        if get_arr(arr1) == get_arr(arr2) || arr1.squeeze.include?(arr2.squeeze)
          len[index1] += arr2.length
        end
      end
    end
    array << get_arr(arr1)
  end
end
l = len.sort.last
arr.each do |k|
  if k.squeeze.length == 1
    x << k.length
  end
end
x.sort!
l1 = x.last + x[x.length-2]
p l1 > l ? l1 : l

def get_arr(arr)
  a = arr[0]
  b = arr.delete(a)[0]
  return [a,b]
end

def exist?(arr, arr1)
  arr.each do |x|
    if x == arr1
      return true
      break
    end
  end
  false
end
n = gets.chomp.to_i
x, arr, array, len = [], [], [], [0]
(1..n).each do |i|
  a = gets.chomp
  t = String.new(a)
  num = 0
  a.each_char do |x|
    if a.delete(x) != a
      a.delete!(x)
      num += 1
    end
    if num == 3
      break
    end
  end
  if num < 3
    arr << t
  end
end
arr.each_with_index do |arr1, index1|
  len[index1] = arr1.length
  if !exist?(array, arr1)
    arr.each_with_index do |arr2, index2|
      if index1 == index2
        next
      else
        if get_arr(arr1) == get_arr(arr2) || get_arr(arr1).reverse == get_arr(arr2) || arr1.squeeze.include?(arr2.squeeze)
          len[index1] += arr2.length
        end
      end
    end
    array << get_arr(arr1)
  end
end
l = len.sort.last
index = len.index(l)
if arr[index].squeeze.length == 1
  l1 = 0
  arr.each do |arr1|
    if arr1.length > l1 && arr1 != arr[index]
      l1 = arr1.length
    end
  end
  p l+l1
else
  p l
end


readin=->(){gets.split.map(&:to_i)}
n,k,mn=gets.to_i,readin[],0x3f3f3f3f
n.times{|i|mn=[mn,readin[].inject(:+)*5+k[i]*15].min}
puts mn

n = STDIN.readline.to_i
f = STDIN.readline.split.map { |x| x.to_i }
ans = Array.new(n,0)
n.times do |i|
	t = STDIN.readline.split.map { |x| x.to_i }
	t.each { |x| ans[i] += 5*x+15 }
end
print ans.min

n = gets.to_i
k = gets.split(' ').map{|i| i.to_i}
best = 1023456789
for i in 0..n-1
	best = [best, gets.split(' ').map{|i| i.to_i}.reduce{|a, b| a+b} * 5 + k[i] * 15].min
end
puts best

N=gets().to_i
def Solve(line)
  res=0
  for i in line
     res+=(i*5)
  end
  res+=15*line.size
  res
end
people_num_arr=gets().split(" ").map{|i| i.to_i}
lis=[]
for i in 0...N
   line=gets().split(" ").map{|i| i.to_i}
   lis<<Solve(line)
end
lis.sort!
puts lis[0]

n = gets.to_i
ppl_count = gets.split(" ").map(&:to_i)
arr = []
n.times do
	arr << gets.split(" ").map(&:to_i)
end

sum_arr = arr.map do |a|
	sum = a.inject(0){ |s,e| s += e * 5 }
	sum +=  a.length * 15
	sum
end
# puts "#{sum_arr}"
puts sum_arr.min

=begin
$stdin = File.open("./in.txt", "r")
$stdout = File.open("./out.txt", "w")
=end

n = gets.to_i
k = gets.split.map { |number| number.to_i }
m = []
n.times do |i|
  m << gets.split.map { |number| number.to_i }
end

answer = m.map { |queue|
  time = queue.size * 15
  queue.each { |items| time += items * 5 }
  time
}.min

print answer

n=gets.to_i;a=Array.new(n,0)
k=gets.chomp.split.map(&:to_i)
a=[]
n.times do
	x=gets.chomp.split.map(&:to_i)
	sum=0
	x.each do |i|
		sum+=(5*i)+15
	end
	a<<sum
end
puts a.min

n = Integer gets
k = gets.split.map {|x| Integer x}
ans = Array.new(n, 0)
for i in 0..n - 1
  sum = 0
  arr = gets.split.map {|x|
    sum += Integer x
    Integer x
  }
  ans[i] += sum * 5 + 15 * arr.length
end
puts ans.min

n = gets.chomp.to_i
cashiers = gets.chomp.split(/ /).map(&:to_i)
items = []
n.times do
    items << gets.chomp.split(/ /).map(&:to_i)
end
ans = 100000
cashiers.each_index do |cashier|
    people = cashiers[cashier]
    time = 0
    people.times do |p|
        item = items[cashier][p]
        time += item * 5
    end
    time += people * 15
    ans = [time, ans].min
end
puts ans

a=gets.chomp.to_i
b=gets.chomp.split(" ")
0.upto(a-1) {|i| b[i]=b[i].to_i}
ar=[]
0.upto(a-1) do |i|
temp=gets.chomp.split(" ")
temp2=0
temp.each {|j| temp2+=j.to_i   }
temp2=temp2*5+ b[i]*15
ar << temp2
end
ans=ar.min
puts ans.to_s


n, l = gets.to_i + 1, gets.split.map(&:to_i)
c, b = Array.new(n, 0), 1
l.each {|a| c[a] += 1}
l.each_with_index do |a, i|
  if c[a] > 1
    b += 1 while c[b] > 0
    if a < b && c[a] < n
      c[a] = 999999
    else
      c[a] -= 1
      l[i] = b
      b += 1
    end
  end
end
p c.count(0) - 1
puts l.map(&:to_s).join(' ')

n = gets.to_i

cnt = [1]
arr = gets.split.map{|x| cnt << 0; x.to_i}

arr.each{|x| cnt[x] += 1}

miss = []
cnt.each_with_index{|x, i| miss << i if x == 0}

p miss.size

exist = []
j = 0

puts arr.map{|x|
	if exist[x] || (cnt[x] > 1 && miss[j] < x)
		cnt[x] -= 1
		j += 1
		miss[j - 1]
	else
		exist[x] = 1
		x
	end
}.join(" ")

n, l = gets.to_i + 1, gets.split.map(&:to_i)
cnt, b, c = Array.new(n, 0), 1, 0
l.each {|a| cnt[a] += 1}
l.each_with_index do |a, i|
  if cnt[a] > 1
    b += 1 while cnt[b] > 0
    if a < b && cnt[a] < n
      cnt[a] = 999999
    else
      cnt[a] -= 1
      l[i] = b
      b += 1
      c += 1
    end
  end
end
p c
puts l.map(&:to_s).join(' ')

n, l = gets.to_i + 1, gets.split.map(&:to_i)
cnt, b = Array.new(n, 0), 1
l.each {|a| cnt[a] += 1}
l.each_with_index do |a, i|
  if cnt[a] > 1
    b += 1 while cnt[b] > 0
    if a < b && cnt[a] < n
      cnt[a] = 999999
    else
      cnt[a] -= 1
      l[i] = b
      b += 1
    end
  end
end
puts l.map(&:to_s).join(" ")

n, aa = gets.to_i+1, gets.split.map(&:to_i)
cnt, b = Array.new(n, 0), 1
aa.each {|a| cnt[a] += 1}
aa.each_with_index do |a, i|
  if cnt[a] > 1
    b += 1 while cnt[b] > 0
    if a < b && cnt[a] < n
      cnt[a] = 999999
    else
      cnt[a] -= 1
      aa[i] = b
      b += 1
    end
  end
end
p aa


T = gets.to_i

T.times do
  a, b = gets.split.map{|e| e.to_i}

  if (a == 0 && b == 0)
    puts 1.0
  elsif (a == 0)
    puts 0.5
  elsif (b == 0)
    puts 1.0
  else
    if (b > a / 4.0)
      puts 0.5 + (0.5 * a * a / 4.0) / (2 * a * b)
    else
      puts 1.0 - (0.5 * b * b * 4) / (2 * a * b)
    end
  end

end

#!/usr/bin/ruby

$stdin = File.open('test_69_4') if $DEBUG

t = gets.to_i
t.times do
  a, b = gets.split.map(&:to_i)
  total = b*2*a
  square = a.to_f/4 >= b ? b*b*2 : a*(b - a.to_f/8)
  puts b == 0 ? 1.0 : a == 0 ? 0.5 : (total - square).to_f / total
end

#Infinity
#geti,getia
#Object # dcopy
#
#String # to_a
#   "abc".to_a #=> ["a","b","c"]
#String # to_ia
#   "1 2 3".to_ia #=> [1,2,3]
#
#Array # rsort,rsort!
#   [1,3,2,4].rsort #=> [4,3,2,1]
#
#Integer # divisor
#   24.divisor #=> [1,2,3,4,6,8,12,24]
#
include Math
require "prime"
require "bigdecimal"
require "bigdecimal/math"
require "matrix"
require "pp"
require "benchmark"

Infinity = 1/0.0
class Matrix;def inspect;empty? ? "Matrix.empty(#{row_size}, #{column_size})":"Matrix[\n#{@rows.map(&:inspect).join("\n")}\n]";end;end
def pbin(obj);case obj;when Integer;puts obj.to_s(2);end;end
class String;def to_a;split("");end;end
class String;def to_ia;split.map(&:to_i);end;end
def getia;gets.to_ia;end
def geti;gets.to_i;end
class Object;def dcopy;Marshal.load(Marshal.dump(self));end;end
class Array;def rsort;sort.reverse;end;def rsort!;sort!.reverse!;end;end

t = geti
t.times do
    a,b = gets.split.map(&:to_f)
    y = a * b
    if 4 * b > a
        y += a * a / 8.0
    else
        y += y - b * b * 2.0
    end
    if a == 0 && b == 0
        puts 1
    elsif a == 0
        puts 0.5
    elsif b == 0
        puts 1
    else
        puts y / (a * b * 2.0)
    end
end

n = gets.to_i
n.times do
  a, b = gets.split.map(&:to_i)
  if b == 0
    o = 1.0
  elsif a == 0
    o = 0.5
  elsif a < 4*b
    o = (a*b + a*a*Rational(1,8))/(2*a*b)
  else
    o = (2*a*b - b*b*Rational(2,1))/(2*a*b)
  end
  p o.to_f
end

#Infinity
#geti,getia
#Object # dcopy
#
#String # to_a
#   "abc".to_a #=> ["a","b","c"]
#String # to_ia
#   "1 2 3".to_ia #=> [1,2,3]
#
#Array # rsort,rsort!
#   [1,3,2,4].rsort #=> [4,3,2,1]
#
#Integer # divisor
#   24.divisor #=> [1,2,3,4,6,8,12,24]
#
include Math
require "prime"
require "bigdecimal"
require "bigdecimal/math"
require "matrix"
require "pp"
require "benchmark"

Infinity = 1/0.0
class Matrix;def inspect;empty? ? "Matrix.empty(#{row_size}, #{column_size})":"Matrix[\n#{@rows.map(&:inspect).join("\n")}\n]";end;end
def pbin(obj);case obj;when Integer;puts obj.to_s(2);end;end
class String;def to_a;split("");end;end
class String;def to_ia;split.map(&:to_i);end;end
def getia;gets.to_ia;end
def geti;gets.to_i;end
class Object;def dcopy;Marshal.load(Marshal.dump(self));end;end
class Array;def rsort;sort.reverse;end;def rsort!;sort!.reverse!;end;end

t = geti
t.times do
    a,b = getia
    y = a * b
    if 4 * b > a
        y += a * a / 8.0
    else
        y += y - b * b * 2.0
    end
    puts y / (a * b * 2.0)
end

n = gets.to_i
n.times do
  a, b = gets.split.map(&:to_i)
  if a == 0 || b == 0
    o = 1.0
  elsif a < 4*b
    o = (a*b + a*a*Rational(1,8))/(2*a*b)
  else
    o = (2*a*b - b*b*Rational(1,8))/(2*a*b)
  end
  p o.to_f
end

n = gets.to_i
n.times do
  a, b = gets.split.map(&:to_i)
  if b == 0
    o = 1.0
  elsif a == 0
    o = 0.5
  elsif a < 4*b
    o = (a*b + a*a*Rational(1,8))/(2*a*b)
  else
    o = (2*a*b - b*b*Rational(1,8))/(2*a*b)
  end
  p o.to_f
end

#!/usr/bin/ruby

$stdin = File.open('test_69_4') if $DEBUG

t = gets.to_i
t.times do
  a, b = gets.split.map(&:to_i)
  total = b*2*a
  square = a.to_f/4 >= b ? b*b*2 : a*(b - a.to_f/8)
  puts b == 0 ? 1 : a == 0 ? 0.5 : (total - square) / total
end

T = gets.to_i

T.times do
  a, b = gets.split.map{|e| e.to_i}

  if (b > a / 4.0)
    puts 0.5 + (0.5 * a * a / 4.0) / (2 * a * b)
  else
    puts 1.0 - (0.5 * b * b * 4) / (2 * a * b)
  end

end


# coding: utf-8
require "set"

n, x0, y0 = gets.split.map(&:to_i)
incline_hash = Set.new
n.times {
    x, y = gets.split.map(&:to_i)
    dx, dy = x0 - x, y0 - y
    if dx == 0
        incline_hash.add -1
    else
        incline_hash.add dy*1.0/dx
    end
}

puts incline_hash.length

n,x,y=gets.split.map(&:to_i)
a=[]
n.times do
  x1,y1 =gets.split.map(&:to_f)
  a << (x1==x ? 'w':(y1-y)/(x1-x))
end
p a.uniq.count

require 'set'

n, x0, y0 = gets.split.map(&:to_f)

set = Set.new
n.to_i.times do
  x, y = gets.split.map(&:to_f)

  if x == x0
    set << true
  else
    set << (y - y0) / (x - x0)
  end
end

puts set.length

n,x,y=gets.split.map(&:to_i)
s={}
n.times do
    x1,y1=gets.split.map(&:to_f)
    s[(y1-y)/(x1-x)]=1
end
p s[1.0/0]&&s[-1.0/0]?(s.size-1):s.size

n,x0,y0=gets.chomp.split.map(&:to_i)
vx,vy,ans,i,j=[],[],n,0,0
n.times do |i|
	x,y=gets.chomp.split.map(&:to_i)
	vx<<(x-x0);vy<<(y-y0)
	for j in 0...i
		if vx[i] * vy[j] == vx[j] * vy[i]
			ans-=1
			break
		end
	end
end
puts ans

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

n, x0, y0 = gets.split.map &:to_i
data = Array.new(n) { Array.new(2, 0) }
l = []
flag = 0
m = 0
n.times{|_|
  data[_] = gets.split.map &:to_i
  if x0 == data[_][0]
    flag = 1
  else
    l << (1.0 * y0 - data[_][1]) / (1.0 * x0 - data[_][0])
  end
}
puts (l.uniq.size + flag)

require 'set'
def read_ints; STDIN.gets.split.map(&:to_i); end

n, x0, y0 = read_ints

inp = n.times.map do
  p = read_ints
  p[0] -= x0
  p[1] -= y0
  p
end

dot_set = inp.to_set

ans = 0
loop do
  break if dot_set.empty?
  ans += 1
  p = dot_set.first
  dot_set.delete_if do |dot|
    dot[0] * p[1] == dot[1] * p[0]
  end
end

puts ans

n,x,y=gets.split.map{|e| e.to_i}
ps=Hash.new(0)
add=0
n.times{
	xi,yi=gets.split.map{|e| e.to_i}
	xi=(xi-x)
	yi=(yi-y)
	if xi==0 then
		add=1
	else
		m1=1
		m1=-1 if xi<0
		d1=yi.abs.gcd(xi.abs)
		ps[[yi/d1*m1,xi/d1*m1]]+=1

	end
}
puts ps.size+add

#!/usr/bin/ruby

SMALL_NUMBER = 0.000000000001
input_line = gets
par = input_line.split(' ').map(&:to_f)
n = par[0]
x0 = par[1]
y0 = par[2]
i = 0;
coords = []
while(i < n) do
    input_line = gets
    par = input_line.split(' ').map(&:to_f)
    coords << [par[0],par[1]]
    i = i+1
end
counter = 0
while (coords.size() > 0) do
    counter  = counter + 1
    x1 = coords[0][0]
    y1 = coords[0][1]

    if ((x0-x1).abs > SMALL_NUMBER && (y0-y1).abs > SMALL_NUMBER)
        coords.delete_if do |coord|
            true if ( ( (coord[0]-x0)/(x1-x0) - (coord[1]-y0)/(y1-y0) ).abs < SMALL_NUMBER)
        end
    elsif ((x0-x1).abs < SMALL_NUMBER)
        coords.delete_if do |coord|
            true if ( (coord[0]-x0).abs < SMALL_NUMBER)
        end
    elsif ((y0-y1).abs < SMALL_NUMBER)
        coords.delete_if do |coord|
            true if ( (coord[1]-y0).abs < SMALL_NUMBER)
        end
    end
end

puts counter

n,x1,y1 = gets.split(" ").map(&:to_i)
arr = []
n.times do
	arr << gets.split(" ").map(&:to_i)
end
eq = arr.map do |a|
	x2,y2 = a
	(x2-x1) == 0 ? 10**9 : (y2-y1)/(x2-x1).to_f
end
puts eq.uniq.count

require 'set'

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

a = Set.new
n,x,y = gets.split.map(&:to_i)
1.upto(n).map do |_|
  ex,ey = gets.split.map(&:to_i)
  dx = ex - x
  dy = ey - y
  if dx < 0
    dx *= -1
    dy *= -1
  end
  if dx == 0
    a << [0,1]
  elsif dy == 0
    a << [1,0]
  else
    g = gcd(dx,dy).abs
    a << [dx/g, dy/g]
  end
end

puts a.size

n, x0, y0 = gets.split.map(&:to_i)
a = n.times.map do
  x1, y1 = gets.split.map(&:to_f)
  x1 == x0 ? 'w' : (y1 - y0) / (x1 - x0)
end
puts a.uniq.size

n, x, y = gets.split.map(&:to_i)
a = []
n.times do
  x1, y1 = gets.split.map(&:to_f)
  a << (x1 == x ? 'w' : (y1 - y) / (x1 - x))
end
puts a.uniq.count

n, x, y = gets.split.map(&:to_i)
a = []
n.times do
  x1, y1 = gets.split.map(&:to_f)
  c = (y1 - y) / (x1 - x)
  a << (c.infinite? ? c.abs : c.to_r)
end
puts a.uniq.count

Point = Struct.new(:x, :y)

def points_on_line(arr, zero, p)
  left = p.x - zero.x
  right = p.y - zero.y

  arr = arr.map { |elem|
    if (left * (elem.y - zero.y)) == (right * (elem.x - zero.x))
      nil
    else
      elem
    end
  }

  arr.compact
end

n, x0, y0 = gets.split(' ').map(&:to_i)

zero = Point.new(x0, y0)

arr = []
n.times do |_|
  x, y = gets.split(' ').map(&:to_i)
  arr << Point.new(x, y)
end

counter = 0
until arr.empty?
  p = arr.pop
  arr = points_on_line(arr, zero, p)

  counter += 1
end

p counter

require 'set'

n, x0, y0 = gets.split.map(&:to_f)

set = Set.new
n.to_i.times do
  x, y = gets.split.map(&:to_f)
  set << (y - y0) / (x - x0)
end

puts set.length

# http://codeforces.com/contest/514/problem/A

digits = gets.chomp.chars.map(&:to_i)
inverted = digits.map.with_index do |n, idx|
  case idx
  when 0
    (9 - n) < n && n != 9 ? 9 - n : n
  else
    (9 - n) < n ? 9 - n : n
  end
end

puts inverted.join.to_i

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

n, x0, y0 = gets.split.map &:to_i
data = Array.new(n) { Array.new(2, 0) }
l = []
flag = 0
m = 0
n.times{|_|
  data[_] = gets.split.map &:to_i
  if x0 == data[0]
    flag = 1
  else
    l << (1.0 * y0 - data[_][1]) / (1.0 * x0 - data[_][0])
  end
}
puts (l.uniq.size + flag)

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

n, x0, y0 = gets.split.map &:to_i
data = Array.new(n) { Array.new(2, 0) }
l = []
flag = 0
m = 0
n.times{|_|
  data[_] = gets.split.map &:to_i
  if x0 = data[0]
    flag = 1
  else
    l << (1.0 * y0 - data[_][1]) / (1.0 * x0 - data[_][0])
  end
}
puts (l.uniq.size + flag)

n,x,y=gets.split.map{|e| e.to_i}
ps=Hash.new(0)
add=0
n.times{
	xi,yi=gets.split.map{|e| e.to_i}
	xi=(xi-x)
	yi=(yi-y)
	if xi==0 then
		add=1
	else
		m=1
		m=-1 if xi<0
		ps[yi/(yi.abs.gcd(xi.abs))*m]+=1

	end
}
puts ps.size+add

#!/usr/bin/ruby

SMALL_NUMBER = 0.0000001
input_line = gets
par = input_line.split(' ').map(&:to_i)
n = par[0]
x0 = par[1]
y0 = par[2]
i = 0;
coords = []
while(i < n) do
    input_line = gets
    par = input_line.split(' ').map(&:to_i)
    coords << [par[0],par[1]]
    i = i+1
end
counter = 0
while (coords.size() > 0) do
 ##   puts coords.to_s
 ##   gets
    counter  = counter + 1
    x1 = coords[0][0]
    y1 = coords[0][1]

    if ((x0-x1).abs > SMALL_NUMBER && (y0-y1).abs > SMALL_NUMBER)
        coords.delete_if do |coord|
            true if ( ( (coord[0]-x0)/(x1-x0) - (coord[1]-y0)/(y1-y0) ).abs < SMALL_NUMBER)
        end
    elsif ((x0-x1).abs < SMALL_NUMBER)
        coords.delete_if do |coord|
            true if ( (coord[0]-x0).abs < SMALL_NUMBER)
        end
    elsif ((y0-y1).abs < SMALL_NUMBER)
        coords.delete_if do |coord|
            true if ( (coord[1]-y0).abs < SMALL_NUMBER)
        end
    end
end

puts counter

n,x,y=gets.split.map(&:to_i)
s={}
(1..n).each do |i|
	x1,y1=gets.split.map(&:to_i)
	s[1.0*(y1-y)/(x1-x)]=1
end
p s.size

n,x1,y1 = gets.split(" ").map(&:to_i)
arr = []
n.times do
	arr << gets.split(" ").map(&:to_i)
end
eq = arr.map do |a|
	x2,y2 = a
	(x2-x1) == 0 ? 10**9 : (y2-y1)/(x2-x1)
end
puts eq.uniq.count

n, x, y = gets.split.map(&:to_i)
a = []
n.times do
  x1, y1 = gets.split.map(&:to_i)
  dx = x1 - x
  dy = y1 - y
  gcd = dx.gcd(dy)
  a << "#{(dy/gcd).abs}/#{(dx/gcd).abs}"
end
puts a.uniq.count

n, x, y = gets.split.map(&:to_i)
a = []
n.times do
  x1, y1 = gets.split.map(&:to_f)
  a << (x1-x) / (y1-y)
end
puts a.uniq.count

n, x, y = gets.split.map(&:to_i)
a = []
n.times do
  x1, y1 = gets.split.map(&:to_f)
  c = (y1 - y) / (x1 - x)
  a << (c.infinite? ? c : c.to_r)
end
puts a.uniq.count


n,k=gets.split.map(&:to_i)
rows=[]
n.times do
  rows<<gets.split('')
end

potentials=[]
initial_sum = 0
rows.each_with_index do |row, row_number|
  row.each_with_index do |k,row_i|
    if k=="."
      pot = 0
      if row[row_i-1]=="S"
        if row_i != 0
          pot+=1
        end
      end
      if row[row_i+1]=="S"
        pot+=1
      end
      potentials<<[[row_number,row_i],pot]
    elsif k=="S"
      sum = 0
      if row_i!=0 and (row[row_i-1] == "P" or row[row_i-1] == "S")
        sum+=1
      end
      if row[row_i+1] == "P" or row[row_i+1] == "S"
        sum+=1
      end
      initial_sum+=sum
    end
  end
end

selected = potentials.sort do |a,b|
  [a[1], a[0][0]]<=>[b[1],b[0][0]]
end[0..k-1]
sum = initial_sum + selected.inject(0){|memo, k| memo+k[1]}
selected.map do |p|
  rows[p[0][0]][p[0][1]] = "x"
end

puts sum
puts rows.map(&:join)

def near_count(row, pos, variants)
  [-1, 1].inject(0) do |res, delta|
    target = pos+delta
    res + (target >= 0 && target < row.length && variants.include?(row[target]) ? 1 : 0)
  end
end

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

queue = [[], [], []]

plane = (0...n).map do |i|
  row = gets.chomp
  (0...row.length).each do |j|
    next unless row[j] == '.'
    elite_near = near_count(row, j, ['S'])
    queue[elite_near] << [i, j]
  end
  row
end

rq = queue.inject([]){|r, e| r + e}

rq[0...k].each do |plan|
  plane[plan[0]][plan[1]] = 'x'
end

ans = plane.inject(0) do |r, row|
  r + (0...row.length).inject(0) do |r2, i|
    r2 + (row[i] != 'S' ? 0 : near_count(row, i, ['P', 'x', 'S']))
  end
end

puts ans
puts plane


n, k=gets.split.map &:to_i
a=gets.split.map(&:to_i).sort
if k==0
    puts (a[0]==1 ? -1 : 1)
else
    puts (k<n && a[k-1]==a[k] ? -1 : a[k-1])
end

# coding: utf-8

n, k = gets.split.map(&:to_i)
h = {}
ar = gets.split.map { |i|
    i = i.to_i
    h[i] ||= 0
    h[i] += 1
    i
}

#p ar
if k > 0
    acc = 0
    ans = -1
    h.keys.sort.each { |i|
        acc += h[i]
        if acc < k
            next
        elsif acc == k
            ans = i
            break
        else
            ans = -1
            break
        end
    }

    puts ans
else
    minimum = h.keys.min
    if minimum > 1
        puts minimum - 1
    else
        puts "-1"
    end
end

def solution
  _, k = read_ints

  as = read_ints.sort

  if k == 0
    if as[0] == 1
      puts -1
    else
      puts 1
    end
    return
  end

  max_incl = as[k-1]
  min_excl = as[k]

  if max_incl == min_excl
    puts(-1)
  else
    puts max_incl
  end

end

def read_int
  gets.to_i
end

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

def read_string
  gets.chomp
end

solution unless ENV['TEST__MODE']

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

# coding: utf-8

n, k = gets.split.map(&:to_i)
h = {}
ar = gets.split.map { |i|
    i = i.to_i
    h[i] ||= 0
    h[i] += 1
    i
}

ar.sort!
#p ar
if k > 0
    ans = ar[k-1]
    if h[ans] > 1
        puts "-1"
    else
        puts ans
    end
else
    if ar.first > 1
        puts ar.first - 1
    else
        puts "-1"
    end
end

# coding: utf-8

n, k = gets.split.map(&:to_i)
ar = [-1] + gets.split.map(&:to_i)
ar.sort!
#p ar
if (k < n && ar[k] == ar[k+1]) || (k > 0 && ar[k-1] == ar[k])
    puts ar[0]
else
    if k == 0
        if ar[1] > 1
            puts ar[1] - 1
        else
            puts ar[0]
        end
    else
        puts ar[k]
    end
end

# coding: utf-8

n, k = gets.split.map(&:to_i)
ar = [-1] + gets.split.map(&:to_i)
ar.sort!
#p ar
if k == 0 || n == 0 || (k < n && ar[k] == ar[k+1]) || (k > 0 && ar[k-1] == ar[k])
    puts ar[0]
else
    puts ar[k]
end


n = gets.to_i

a = []
n.times do
  a << gets.strip
end

sum = 0
a.each do |x|
  if x == "Tetrahedron"
    sum += 4
  elsif x == "Cube"
    sum += 6
  elsif x == "Octahedron"
    sum += 8
  elsif x == "Icosahedron"
    sum += 20
  else
    sum += 12
  end
end

puts sum

phs = {"Tetrahedron" => 4,"Cube" => 6,"Octahedron" => 8,"Dodecahedron" => 12,"Icosahedron" => 20}
n = gets.to_i
ans = 0

n.times do
  s = gets.chomp
  phs.each do |key,value|
    ans += value if key == s
  end
end

puts ans

phs = {'Tetrahedron' => 4,'Cube' => 6,'Octahedron' => 8,'Dodecahedron' => 12,'Icosahedron' => 20}
n = gets.to_i
ans = 0

n.times do
  s = gets.chomp
  ans += phs[s]
end

puts ans

n = gets.to_i
dict = {
	"Icosahedron" => 20,
	"Cube" => 6,
	"Tetrahedron" => 4,
	"Dodecahedron" => 12,
	"Octahedron" => 8
}

count = 0
while n != 0
	figure = gets.chomp.to_s
	count += dict[figure]
	n -= 1
end
puts count

# https://codeforces.com/problemset/problem/785/A

count = gets.to_i

faces_count = 0
count.times do
  name = gets.chomp

  faces_count +=
    if name == "Tetrahedron"
      4
    elsif name == "Cube"
      6
    elsif name == "Octahedron"
      8
    elsif name == "Dodecahedron"
      12
    elsif name == "Icosahedron"
      20
    end
end

puts faces_count

n = gets.chomp.to_i
ans = 0
n.times do
    s = gets.chomp
    case s
    when "Tetrahedron"
        ans += 4
    when "Cube"
        ans += 6
    when "Octahedron"
        ans += 8
    when "Dodecahedron"
        ans += 12
    when "Icosahedron"
        ans += 20
    end
end
puts ans

D, x = {'Tetrahedron' => 4, 'Cube' => 6, 'Octahedron' => 8, 'Dodecahedron' => 12, 'Icosahedron' => 20}.freeze, 0
for i in 1..gets.to_i
  x += D[gets.strip]
end
p x

#!/usr/bin/env ruby -w

polyhedrons = {"Tetrahedron" => 4, "Cube" => 6, "Octahedron" => 8,
               "Dodecahedron" => 12, "Icosahedron" => 20}

n = gets.strip.to_i
s = 0

n.times do
  s += polyhedrons[gets.strip.chomp]
end

puts s

ans = 0
gets.to_i.times do
  s = gets.chomp
  if s == 'Icosahedron'
    ans += 20
  elsif s == 'Cube'
    ans += 6
  elsif s == 'Tetrahedron'
    ans += 4
  elsif s == 'Dodecahedron'
    ans += 12
  elsif s == 'Octahedron'
    ans += 8
  end
end
puts ans

poly = { "Tetrahedron" => 4, "Cube" => 6, "Octahedron" => 8, "Dodecahedron" => 12, "Icosahedron" => 20 }
n = gets.strip.to_i
ans = 0
n.times do
    s = gets.strip
    ans += poly[s]
end
puts ans

h={}
h["Tetrahedron"]=4
h["Cube"]=6
h["Octahedron"]=8
h["Dodecahedron"]=12
h["Icosahedron"]=20

ans=0
gets.to_i.times{
	ans+=h[gets.chomp]
}

puts ans

n = gets.chomp.to_i
o = {'Tetrahedron' => 0,'Cube'=>0,'Octahedron'=>0,'Dodecahedron'=>0,'Icosahedron'=>0}
n.times.each do
s = gets.chomp
  o[s] += 1
end

puts o['Tetrahedron'] * 4 + o['Cube'] * 6 + o['Octahedron'] * 8 + o['Dodecahedron'] * 12 + o['Icosahedron'] * 20

def total(poly)
	return 4 if poly == "Tetrahedron"
	return 6 if poly == "Cube"
	return 8 if poly == "Octahedron"
	return 12 if poly == "Dodecahedron"
	return 20 if poly == "Icosahedron"
end

faces = 0
n = gets.chomp.to_i

n.times do
	poly = gets.chomp
	faces = faces + total(poly)
end

puts(faces)

f = {
    Tetrahedron: 4,
    Cube: 6,
    Octahedron: 8,
    Dodecahedron: 12,
    Icosahedron: 20
}

n = gets.to_i
s = 0

(1..n).each { s += f[gets.chomp.to_sym] }

puts s

n=gets.chomp
#puts n
total_faces=0
faces = {"Tetrahedron" => 4, "Cube" => 6, "Octahedron" => 8, "Dodecahedron" => 12, "Icosahedron" => 20}
#puts faces["Tetrahedron"]
#puts faces["Cube"]
for i in 1..n.to_i
    #polyhedron=gets
    polyhedron=gets.chomp
    #print i
    #puts polyhedron
    #puts faces["Cube"]
    total_faces=total_faces + faces[polyhedron].to_i
end
puts total_faces

# coding: utf-8

# 4
# Icosahedron
# Cube
# Tetrahedron
# Dodecahedron

MAPPED = {
    "Tetrahedron" => 4,
    "Cube" => 6,
    "Octahedron" => 8,
    "Dodecahedron" => 12,
    "Icosahedron" => 20
}

n = gets.to_i
c = 0
n.times {
    input = gets
    input.strip!
    c += MAPPED[input]
}

puts c

n = gets.chomp.to_i
polyhedrons = { "Tetrahedron" => 4, "Cube" => 6, "Octahedron" => 8, "Dodecahedron" => 12, "Icosahedron" => 20}
sum = 0
for i in (0..n-1)
	x = gets.chomp
	if x == "Tetrahedron"
		sum += polyhedrons["Tetrahedron"]
	elsif x == "Cube"
		sum += polyhedrons["Cube"]
	elsif x == "Octahedron"
		sum += polyhedrons["Octahedron"]
	elsif x == "Dodecahedron"
		sum += polyhedrons["Dodecahedron"]
	elsif x == "Icosahedron"
		sum += polyhedrons["Icosahedron"]
	end
end
print sum

n = gets.to_i
count = {}
count['Tetrahedron']||=0
count['Cube']||=0
count['Octahedron']||=0
count['Dodecahedron']||=0
count['Icosahedron']||=0
for i in (0...n)
 cur = gets.chomp
 count[cur]+=1
end
puts (count['Tetrahedron']*4 + count['Cube']*6 + count['Octahedron']*8 + count['Dodecahedron']*12 + count['Icosahedron']*20)

n = gets.to_i
count = {'Tetrahedron'=>4,'Cube'=>6,'Octahedron'=>8,'Dodecahedron'=>12,'Icosahedron'=>20}
ans = 0
for i in (0...n) do ans+=count[gets.chomp] end
puts ans

n = gets.to_i
count = {}
count['Tetrahedron']||=4
count['Cube']||=6
count['Octahedron']||=8
count['Dodecahedron']||=12
count['Icosahedron']||=20
ans = 0
for i in (0...n)
 cur = gets.chomp
 ans+=count[cur]
end
puts ans

n = gets.to_i
count = {'Tetrahedron'=>4,'Cube'=>6,'Octahedron'=>8,'Dodecahedron'=>12,'Icosahedron'=>20}
ans = 0
for i in (0...n)
 cur = gets.chomp
 ans+=count[cur]
end
puts ans

$n = gets
$n = $n.to_i
arr = []
(0...$n).each do |i|
	arr << gets.chomp
end

polygon = {"Tetrahedron" => 4, "Icosahedron" => 20, "Cube" => 6, "Dodecahedron" => 12, "Octahedron" => 8}

$k = 0
arr.each do |i|
	$k += polygon[i]
end
print $k

n = gets.to_i
i = 0,sum =0
n.times do
  str = gets.strip
  if str == "Tetrahedron"
    sum =  sum +4
  elsif str == "Cube"
    sum = sum +  6
  elsif str == "Octahedron"
    sum= sum+  8
  elsif str == "Dodecahedron"
    sum = sum + 12
  else
    sum = sum + 20
  end

end
print(sum,"\n")

n = gets.chomp.to_i
sum = 0
hash = {}
hash["Tetrahedron"] = 4
hash["Cube"] = 6
hash["Octahedron"] = 8
hash["Dodecahedron"] = 12
hash["Icosahedron"] = 20

n.times do
	sum += hash[gets.chomp]
end
puts sum

h = {
  'Tetrahedron' => 4,
  'Cube' => 6,
  'Octahedron' => 8,
  'Dodecahedron' => 12,
  'Icosahedron' => 20
}
n = gets.to_i
p n.times.map{gets.chomp}.inject(0){|s, x| s + h[x]}

sides = {"Tetrahedron"=>4, "Cube"=>6, "Octahedron"=>8,
	"Dodecahedron"=>12, "Icosahedron"=>20}
n=gets.chomp.to_i
ans=0
for i in 0...n
	ans+=sides[gets.chomp]
end
puts ans

h = {
    'Tetrahedron' => 4,
    'Cube' => 6,
    'Octahedron' => 8,
    'Dodecahedron' => 12,
    'Icosahedron' => 20
}
n = gets.to_i
nh = 0
n.times do
    s = gets.strip
    nh += h[s]
end
puts nh

n = gets.to_i

sizes = {
  'Tetrahedron' => 4,
  'Cube' => 6,
  'Octahedron' => 8,
  'Dodecahedron' => 12,
  'Icosahedron' => 20
}

puts 1.upto(n).inject(0) { |result, i| result + sizes[gets.chomp] }

poly = {
    "Tetrahedron" => 4,
    "Cube" => 6,
    "Octahedron" => 8,
    "Dodecahedron" => 12,
    "Icosahedron" => 20
}
n = gets.strip.to_i
ans = 0;
for i in 1..n
    s = gets.strip
    ans += poly[s]
end
puts ans

n = gets.chomp.to_i
ans = 0
n.times do
    s = gets.chomp
    case s
    when "Icosahedron"
        ans += 4
    when "Cube"
        ans += 6
    when "Octahedron"
        ans += 8
    when "Dodecahedron"
        ans += 12
    else
        ans += 20
    end
end
puts ans


def min(*values)
 values.min
end
input_str = gets.chomp
input_array = input_str.split(" ")
n = Integer(input_array[0])
k = Integer(input_array[1])
m = Integer(input_array[2])
input_str = gets.chomp
words = input_str.split(" ")
input_str = gets.chomp
score = input_str.split(" ")
for i in 0...n do
	score[i] = Integer(score[i])
end
min_score = Array.new(k)
group = Hash.new
for i in 0...k do
	input_str = gets.chomp
	input_array = input_str.split(" ")
	input_array.shift
	input_array.each{ |input|
		temp = Integer(input)-1
		if min_score[i] == nil
			min_score[i] = score[temp]
		else
			min_score[i] = min(min_score[i],score[temp])
		end
		group[words[temp]] = i
	}
end
input_str = gets.chomp
input_array = input_str.split(" ")
result = 0
input_array.each{ |input|
	result+=min_score[group[input]]
}
puts result

def min(*values)
 values.min
end
input_str = gets.chomp
input_array = input_str.split(" ")
n = Integer(input_array[0])
k = Integer(input_array[1])
m = Integer(input_array[2])
input_str = gets.chomp
words = input_str.split(" ")
input_str = gets.chomp
score = input_str.split(" ").map(&:to_i)
min_score = Array.new(k)
group = Hash.new
for i in 0...k do
	input_str = gets.chomp
	input_array = input_str.split(" ")
	input_array.shift
	input_array.each{ |input|
		temp = Integer(input)-1
		if min_score[i] == nil
			min_score[i] = score[temp]
		else
			min_score[i] = min(min_score[i],score[temp])
		end
		group[words[temp]] = i
	}
end
input_str = gets.chomp
input_array = input_str.split(" ")
result = 0
input_array.each{ |input|
	result+=min_score[group[input]]
}
puts result