Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Petya recently learned to determine whether a string of lowercase Latin letters is lucky. For each individual letter all its positions in the string are written out in the increasing order. This results in 26 lists of numbers; some of them can be empty. A string is considered lucky if and only if in each list the absolute difference of any two adjacent numbers is a lucky number. For example, let's consider string "zbcdzefdzc". The lists of positions of equal letters are: b: 2 c: 3,10 d: 4,8 e: 6 f: 7 z: 1,5,9 Lists of positions of letters a, g, h, ..., y are empty.This string is lucky as all differences are lucky numbers. For letters z: 5-1=4, 9-5=4, for letters c: 10-3=7, for letters d: 8-4=4. Note that if some letter occurs only once in a string, it doesn't influence the string's luckiness after building the lists of positions of equal letters. The string where all the letters are distinct is considered lucky.Find the lexicographically minimal lucky string whose length equals n.

The single line contains a positive integer n (1≤n≤10^5) — the length of the sought string.

Print on the single line the lexicographically minimal lucky string whose length equals n.

The lexical comparison of strings is performed by the < operator in modern programming languages. String a is lexicographically less than string b if exists such i (1≤i≤n), that ai<bi, and for any j (1≤j<i) aj=bj.

def ga = gets.split.map!(&:to_i)
def gi = gets.to_i
def giga = [gi, ga]
def gigs = [gi, gs]
def gs = gets.strip
def gss = gs.split
def o(x) = puts(x)
def pa(a, d = ' ') = puts(a * d)
def pan(a) = pa(a, "\n")
def yn(p) = p ? 'YES' : 'NO'
def ync(p) = p ? 'Yes' : 'No'
def hz(d = 0) = Hash.new(d)
def rqr(*a) = a.each { require _1 }
class Set def z = size end
class Array
    def r! = reverse!
    def f = first
    def l = last
    def sh = shift
    def j(...) = join(...)
    def pc = pack('c*')
    def psum!(s = 0) = map! { s += _1 }
    def lbound(x) = bsearch { _1 >= x }
    def lbound_index(x) = bsearch_index { _1 >= x }
    def hoare!(...) = shuffle!.sort!(...)
    def z = size
end
module Enumerable
    def e(...) = each(...)
    def ei(...) = each_index(...)
    def re(...) = reverse_each(...)
    def ec(...) = each_cons(...)
    def es(...) = each_slice(...)
    def wo(...) = with_object(...)
    def wi(...) = with_index(...)
    def ewi(...) = each_with_index(...)
    def ewo(...) = each_with_object(...)
    def fold(...) = reduce(...)
end
class String
    def i(...) = to_i(...)
    def e(...) = each_char(...)
    def eb(...) = each_byte(...)
    def b = bytes
    def r = reverse
    def z = size
end
class Numeric
    def f = to_f
    def i = to_i
    def s(...) = to_s(...)
    def sqrt = Math.sqrt(self)
    def isqrt = Integer.sqrt(self)
end
class Integer
    def p = pred
    def n = succ
    def t(...) = times(...)
    def popcount = loop.reduce((raise if (x = self) < 0; 0)) \
        { | r | break r if x < 1; r += x & 1; x >>= 1; r }
    def ctz = loop.reduce((raise if (x = self) <= 0; 0)) \
        { | r | break r if x[0] == 1; x >>= 1; r.n }
end
class Hash
    def ek(...) = each_key(...)
    def ev(...) = each_value(...)
    def kmin = ek.min
    def kmax = ek.max
    def vmin = ev.min
    def vmax = ev.max
    def d(...) = delete(...)
    def z = size
end
class MSet < Hash
    def <<(x) = (self[x] = (self[x] || 0).n; self)
    def d(x) = (self.delete x if (self[x] && self[x] -= 1) == 0)
end
def fio(a = 'input.txt', b = 'output.txt')
    $stdin = File.open a, 'rb'
    $stdout = File.open b, 'wb'
end
rqr 'set', 'prime'
class Set def d(...) = delete(...) end
class Prime
    def self.at_least(x) =
        loop { Prime.prime?(x) ? (break x) : x += 1 }
end
RC = /(.)\1*/

################################################################
#                                                              #
#              https://github.com/alantudyk/Stop               #
#                                                              #
################################################################

o ('abcd' * 25e3)[...gi]

################################################################
#                                                              #
#              https://github.com/alantudyk/Stop               #
#                                                              #
################################################################

[{'input': ['5\r\n'], 'output': ['abcda\r\n']}, {'input': ['3\r\n'], 'output': ['abc\r\n']}, {'input': ['8\r\n'], 'output': ['abcdabcd\r\n']}, {'input': ['10\r\n'], 'output': ['abcdabcdab\r\n']}, {'input': ['16\r\n'], 'output': ['abcdabcdabcdabcd\r\n']}, {'input': ['64\r\n'], 'output': ['abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd\r\n']}, {'input': ['128\r\n'], 'output': ['abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd\r\n']}, {'input': ['100\r\n'], 'output': ['abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd\r\n']}, {'input': ['47\r\n'], 'output': ['abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabc\r\n']}, {'input': ['74\r\n'], 'output': ['abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdab\r\n']}, {'input': ['477\r\n'], 'output': ['abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcda\r\n']}, {'input': ['1\r\n'], 'output': ['a\r\n']}, {'input': ['2\r\n'], 'output': ['ab\r\n']}, {'input': ['7\r\n'], 'output': ['abcdabc\r\n']}, {'input': ['4\r\n'], 'output': ['abcd\r\n']}, {'input': ['99\r\n'], 'output': ['abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabc\r\n']}, {'input': ['6\r\n'], 'output': ['abcdab\r\n']}, {'input': ['9\r\n'], 'output': ['abcdabcda\r\n']}]


An African crossword is a rectangular table n×m in size. Each cell of the table contains exactly one letter. This table (it is also referred to as grid) contains some encrypted word that needs to be decoded.To solve the crossword you should cross out all repeated letters in rows and columns. In other words, a letter should only be crossed out if and only if the corresponding column or row contains at least one more letter that is exactly the same. Besides, all such letters are crossed out simultaneously.When all repeated letters have been crossed out, we should write the remaining letters in a string. The letters that occupy a higher position follow before the letters that occupy a lower position. If the letters are located in one row, then the letter to the left goes first. The resulting word is the answer to the problem.You are suggested to solve an African crossword and print the word encrypted there.

The first line contains two integers n and m (1≤n,m≤100). Next n lines contain m lowercase Latin letters each. That is the crossword grid.

Print the encrypted word on a single line. It is guaranteed that the answer consists of at least one letter.

def ga = gets.split.map!(&:to_i)
def gi = gets.to_i
def giga = [gi, ga]
def gigs = [gi, gs]
def gs = gets.strip
def gss = gs.split
def o(x) = puts(x)
def pa(a, d = ' ') = puts(a * d)
def pan(a) = pa(a, "\n")
def yn(p) = p ? 'YES' : 'NO'
def ync(p) = p ? 'Yes' : 'No'
def hz(d = 0) = Hash.new(d)
def rqr(*a) = a.each { require _1 }
class Set def z = size end
class Array
    def r! = reverse!
    def f = first
    def l = last
    def sh = shift
    def j(...) = join(...)
    def pc = pack('c*')
    def psum!(s = 0) = map! { s += _1 }
    def lbound(x) = bsearch { _1 >= x }
    def lbound_index(x) = bsearch_index { _1 >= x }
    def hoare!(...) = shuffle!.sort!(...)
    def z = size
end
module Enumerable
    def e(...) = each(...)
    def ei(...) = each_index(...)
    def re(...) = reverse_each(...)
    def ec(...) = each_cons(...)
    def es(...) = each_slice(...)
    def wo(...) = with_object(...)
    def wi(...) = with_index(...)
    def ewi(...) = each_with_index(...)
    def ewo(...) = each_with_object(...)
    def fold(...) = reduce(...)
end
class String
    def i(...) = to_i(...)
    def e(...) = each_char(...)
    def eb(...) = each_byte(...)
    def b = bytes
    def r = reverse
    def z = size
end
class Numeric
    def f = to_f
    def i = to_i
    def s(...) = to_s(...)
    def sqrt = Math.sqrt(self)
    def isqrt = Integer.sqrt(self)
end
class Integer
    def p = pred
    def n = succ
    def t(...) = times(...)
    def popcount = loop.reduce((raise if (x = self) < 0; 0)) \
        { | r | break r if x < 1; r += x & 1; x >>= 1; r }
    def ctz = loop.reduce((raise if (x = self) <= 0; 0)) \
        { | r | break r if x[0] == 1; x >>= 1; r.n }
end
class Hash
    def ek(...) = each_key(...)
    def ev(...) = each_value(...)
    def kmin = ek.min
    def kmax = ek.max
    def vmin = ev.min
    def vmax = ev.max
    def d(...) = delete(...)
    def z = size
end
class MSet < Hash
    def <<(x) = (self[x] = (self[x] || 0).n; self)
    def d(x) = (self.delete x if (self[x] && self[x] -= 1) == 0)
end
def fio(a = 'input.txt', b = 'output.txt')
    $stdin = File.open a, 'rb'
    $stdout = File.open b, 'wb'
end
rqr 'set', 'prime'
class Set def d(...) = delete(...) end
class Prime
    def self.at_least(x) =
        loop { Prime.prime?(x) ? (break x) : x += 1 }
end
RC = /(.)\1*/

################################################################
#                                                              #
#              https://github.com/alantudyk/Stop               #
#                                                              #
################################################################

n, m = ga
r, c = 2.t.map { Hash.new { _1[_2] = hz } }
g = n.t.map do | i |
    a = gs.b
    a.ewi { r[i][_1] += 1; c[_2][_1] += 1 }
    a
end
s = []
for i in 0...n
    for j in 0...m
        x = g[i][j]
        s << x if r[i][x] < 2 && c[j][x] < 2
    end
end
o s.pc

################################################################
#                                                              #
#              https://github.com/alantudyk/Stop               #
#                                                              #
################################################################

[{'input': ['3 3\r\ncba\r\nbcd\r\ncbc\r\n'], 'output': ['abcd']}, {'input': ['5 5\r\nfcofd\r\nooedo\r\nafaoa\r\nrdcdf\r\neofsf\r\n'], 'output': ['codeforces']}, {'input': ['4 4\r\nusah\r\nusha\r\nhasu\r\nsuha\r\n'], 'output': ['ahhasusu']}, {'input': ['7 5\r\naabcd\r\neffgh\r\niijkk\r\nlmnoo\r\npqqrs\r\nttuvw\r\nxxyyz\r\n'], 'output': ['bcdeghjlmnprsuvwz']}, {'input': ['10 10\r\naaaaaaaaaa\r\nbccceeeeee\r\ncdfffffffe\r\ncdfiiiiile\r\ncdfjjjjile\r\ndddddddile\r\nedfkkkkile\r\nedddddddde\r\ngggggggggg\r\nhhhhhhhhhe\r\n'], 'output': ['b']}, {'input': ['15 3\r\njhg\r\njkn\r\njui\r\nfth\r\noij\r\nyuf\r\nyfb\r\nugd\r\nhgd\r\noih\r\nhvc\r\nugg\r\nyvv\r\ntdg\r\nhgf\r\n'], 'output': ['hkniftjfbctd']}, {'input': ['17 19\r\nbmzbmweyydiadtlcoue\r\ngmdbyfwurpwbpuvhifn\r\nuapwyndmhtqvkgkbhty\r\ntszotwflegsjzzszfwt\r\nzfpnscguemwrczqxyci\r\nvdqnkypnxnnpmuduhzn\r\noaquudhavrncwfwujpc\r\nmiggjmcmkkbnjfeodxk\r\ngjgwxtrxingiqquhuwq\r\nhdswxxrxuzzfhkplwun\r\nfagppcoildagktgdarv\r\neusjuqfistulgbglwmf\r\ngzrnyxryetwzhlnfewc\r\nzmnoozlqatugmdjwgzc\r\nfabbkoxyjxkatjmpprs\r\nwkdkobdagwdwxsufees\r\nrvncbszcepigpbzuzoo\r\n'], 'output': ['lcorviunqvgblgjfsgmrqxyivyxodhvrjpicbneodxjtfkpolvejqmllqadjwotmbgxrvs']}, {'input': ['1 1\r\na\r\n'], 'output': ['a']}, {'input': ['2 2\r\nzx\r\nxz\r\n'], 'output': ['zxxz']}, {'input': ['1 2\r\nfg\r\n'], 'output': ['fg']}, {'input': ['2 1\r\nh\r\nj\r\n'], 'output': ['hj']}, {'input': ['1 3\r\niji\r\n'], 'output': ['j']}, {'input': ['3 1\r\nk\r\np\r\nk\r\n'], 'output': ['p']}, {'input': ['2 3\r\nmhw\r\nbfq\r\n'], 'output': ['mhwbfq']}, {'input': ['3 2\r\nxe\r\ner\r\nwb\r\n'], 'output': ['xeerwb']}, {'input': ['3 7\r\nnutuvjg\r\ntgqutfn\r\nyfjeiot\r\n'], 'output': ['ntvjggqfnyfjeiot']}, {'input': ['5 4\r\nuzvs\r\namfz\r\nwypl\r\nxizp\r\nfhmf\r\n'], 'output': ['uzvsamfzwyplxizphm']}, {'input': ['8 9\r\ntjqrtgrem\r\nrwjcfuoey\r\nywrjgpzca\r\nwabzggojv\r\najqmmcclh\r\nozilebskd\r\nqmgnbmtcq\r\nwakptzkjr\r\n'], 'output': ['mrjcfuyyrjpzabzvalhozilebskdgnbtpzr']}, {'input': ['9 3\r\njel\r\njws\r\ntab\r\nvyo\r\nkgm\r\npls\r\nabq\r\nbjx\r\nljt\r\n'], 'output': ['elwtabvyokgmplabqbxlt']}, {'input': ['7 6\r\neklgxi\r\nxmpzgf\r\nxvwcmr\r\nrqssed\r\nouiqpt\r\ndueiok\r\nbbuorv\r\n'], 'output': ['eklgximpzgfvwcmrrqedoiqptdeiokuorv']}, {'input': ['14 27\r\npzoshpvvjdpmwfoeojapmkxjrnk\r\nitoojpcorxjdxrwyewtmmlhjxhx\r\ndoyopbwusgsmephixzcilxpskxh\r\nygpvepeuxjbnezdrnjfwdhjwjka\r\nrfjlbypoalbtjwrpjxzenmeipfg\r\nkhjhrtktcnajrnbefhpavxxfnlx\r\nvwlwumqpfegjgvoezevqsolaqhh\r\npdrvrtzqsoujqfeitkqgtxwckrl\r\nxtepjflcxcrfomhqimhimnzfxzg\r\nwhkfkfvvjwkmwhfgeovwowshyhw\r\nolchgmhiehumivswgtfyhqfagbp\r\ntdudrkttpkryvaiepsijuejqvmq\r\nmuratfqqdbfpefmhjzercortroh\r\nwxkebkzchupxumfizftgqvuwgau\r\n'], 'output': ['zshdanicdyldybwgclygzrhkayatwxznmicbpvlupfsoewcleploqngsyolceswtyqbpyasmuadbpcehqva']}, {'input': ['1 100\r\nysijllpanprcrrtvokqmmupuptvawhvnekeybdkzqaduotmkfwybqvytkbjfzyqztmxckizheorvkhtyoohbswcmhknyzlgxordu\r\n'], 'output': ['g']}, {'input': ['2 100\r\ngplwoaggwuxzutpwnmxhotbexntzmitmcvnvmuxknwvcrnsagvdojdgaccfbheqojgcqievijxapvepwqolmnjqsbejtnkaifstp\r\noictcmphxbrylaarcwpruiastazvmfhlcgticvwhpxyiiqokxcjgwlnfykkqdsfmrfaedzchrfzlwdclqjxvidhomhxqnlmuoowg\r\n'], 'output': ['rbe']}, {'input': ['3 100\r\nonmhsoxoexfwavmamoecptondioxdjsoxfuqxkjviqnjukwqjwfadnohueaxrkreycicgxpmogijgejxsprwiweyvwembluwwqhj\r\nuofldyjyuhzgmkeurawgsrburovdppzjiyddpzxslhyesvmuwlgdjvzjqqcpubfgxliulyvxxloqyhxspoxvhllbrajlommpghlv\r\nvdohhghjlvihrzmwskxfatoodupmnouwyyfarhihxpdnbwrvrysrpxxptdidpqabwbfnxhiziiiqtozqjtnitgepxjxosspsjldo\r\n'], 'output': ['blkck']}, {'input': ['100 1\r\na\r\nm\r\nn\r\nh\r\na\r\nx\r\nt\r\na\r\no\r\np\r\nj\r\nz\r\nr\r\nk\r\nq\r\nl\r\nb\r\nr\r\no\r\ni\r\ny\r\ni\r\np\r\ni\r\nt\r\nn\r\nd\r\nc\r\nz\r\np\r\nu\r\nn\r\nw\r\ny\r\ng\r\ns\r\nt\r\nm\r\nz\r\ne\r\nv\r\ng\r\ny\r\nj\r\nd\r\nz\r\ny\r\na\r\nn\r\nx\r\nk\r\nd\r\nq\r\nn\r\nv\r\ng\r\nk\r\ni\r\nk\r\nf\r\na\r\nb\r\nw\r\no\r\nu\r\nw\r\nk\r\nk\r\nb\r\nz\r\nu\r\ni\r\nu\r\nv\r\ng\r\nv\r\nx\r\ng\r\np\r\ni\r\nz\r\ns\r\nv\r\nq\r\ns\r\nb\r\nw\r\ne\r\np\r\nk\r\nt\r\np\r\nd\r\nr\r\ng\r\nd\r\nk\r\nm\r\nf\r\nd\r\n'], 'output': ['hlc']}, {'input': ['100 2\r\nhd\r\ngx\r\nmz\r\nbq\r\nof\r\nst\r\nzc\r\ndg\r\nth\r\nba\r\new\r\nbw\r\noc\r\now\r\nvh\r\nq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\r\nsbt\r\nflf\r\npbu\r\nlxb\r\npzs\r\nrzh\r\ncea\r\nkmi\r\nuea\r\nncc\r\nzng\r\nvkn\r\njhn\r\njqw\r\nlqc\r\nmbt\r\nlov\r\ngam\r\n'], 'output': ['tvdiixs']}]


In a far away kingdom lived the King, the Prince, the Shoemaker, the Dressmaker and many other citizens. They lived happily until great trouble came into the Kingdom. The ACMers settled there.Most damage those strange creatures inflicted upon the kingdom was that they loved high precision numbers. As a result, the Kingdom healers had already had three appointments with the merchants who were asked to sell, say, exactly 0.273549107 beer barrels. To deal with the problem somehow, the King issued an order obliging rounding up all numbers to the closest integer to simplify calculations. Specifically, the order went like this: If a number's integer part does not end with digit 9 and its fractional part is strictly less than 0.5, then the rounded up number coincides with the number’s integer part.  If a number's integer part does not end with digit 9 and its fractional part is not less than 0.5, the rounded up number is obtained if we add 1 to the last digit of the number’s integer part. If the number’s integer part ends with digit 9, to round up the numbers one should go to Vasilisa the Wise. In the whole Kingdom she is the only one who can perform the tricky operation of carrying into the next position. Merchants found the algorithm very sophisticated and they asked you (the ACMers) to help them. Can you write a program that would perform the rounding according to the King’s order?

The first line contains a single number to round up — the integer part (a non-empty set of decimal digits that do not start with 0 — with the exception of a case when the set consists of a single digit — in this case 0 can go first), then follows character «.» (a dot), and then follows the fractional part (any non-empty set of decimal digits). The number's length does not exceed 1000 characters, including the dot. There are no other characters in the input data.

If the last number of the integer part is not equal to 9, print the rounded-up number without leading zeroes. Otherwise, print the message "GOTO Vasilisa." (without the quotes).

x, y = gets.strip.split(?.); x = x.to_i
puts x % 10 == 9 ? 'GOTO Vasilisa.' : x + (y[0] > ?4 ? 1 : 0)


Vasya is choosing a laptop. The shop has n laptops to all tastes.Vasya is interested in the following properties: processor speed, ram and hdd. Vasya is a programmer and not a gamer which is why he is not interested in all other properties.If all three properties of a laptop are strictly less than those properties of some other laptop, then the first laptop is considered outdated by Vasya. Among all laptops Vasya does not consider outdated, he chooses the cheapest one.There are very many laptops, which is why Vasya decided to write a program that chooses the suitable laptop. However, Vasya doesn't have his own laptop yet and he asks you to help him.

The first line contains number n (1≤n≤100).
Then follow n lines. Each describes a laptop as speed ram hdd cost. Besides,
  speed, ram, hdd and cost are integers  1000≤speed≤4200 is the processor's speed in megahertz  256≤ram≤4096 the RAM volume in megabytes  1≤hdd≤500 is the HDD in gigabytes  100≤cost≤1000 is price in tugriks All laptops have different prices.

Print a single number — the number of a laptop Vasya will choose. The laptops are numbered with positive integers from 1 to n in the order in which they are given in the input data.

In the third sample Vasya considers the first and fifth laptops outdated as all of their properties cannot match those of the third laptop. The fourth one is the cheapest among the laptops that are left. Thus, Vasya chooses the fourth laptop.

require 'set'

n = readline.strip.to_i

def make_key(v)
  [v[0], v[1], v[2]]
end

@compus = []
n.times do |i|
  speed, ram, hdd, cost = readline.strip.split(/\s+/).map(&:to_i)
  @compus << [speed, ram, hdd, cost]
end

outdated = Set.new
@compus.count.times do |i|
  @compus.count.times do |j|
    if @compus[i][0] < @compus[j][0] && @compus[i][1] < @compus[j][1] && @compus[i][2] < @compus[j][2]
      outdated.add(make_key(@compus[i]))
    end
  end
end

cheapest_pos = 0
cheapest = 1001
@compus.each_with_index do |e, i|
  next if outdated.member?(make_key(e))

  if e[3] < cheapest
    cheapest = e[3]
    cheapest_pos = i
  end
end

puts cheapest_pos + 1


Facetook is a well known social network website, and it will launch a new feature called Facetook Priority Wall. This feature will sort all posts from your friends according to the priority factor (it will be described).This priority factor will be affected by three types of actions:   1. "X posted on Y's wall" (15 points),  2. "X commented on Y's post" (10 points),  3. "X likes Y's post" (5 points). X and Y will be two distinct names. And each action will increase the priority factor between X and Y (and vice versa) by the above value of points (the priority factor between X and Y is the same as the priority factor between Y and X).You will be given n actions with the above format (without the action number and the number of points), and you have to print all the distinct names in these actions sorted according to the priority factor with you.

The first line contains your name. The second line contains an integer n, which is the number of actions (1≤n≤100). Then n lines follow, it is guaranteed that each one contains exactly 1 action in the format given above. There is exactly one space between each two words in a line, and there are no extra spaces. All the letters are lowercase. All names in the input will consist of at least 1 letter and at most 10 small Latin letters.

Print m lines, where m is the number of distinct names in the input (excluding yourself). Each line should contain just 1 name. The names should be sorted according to the priority factor with you in the descending order (the highest priority factor should come first). If two or more names have the same priority factor, print them in the alphabetical (lexicographical) order.
Note, that you should output all the names that are present in the input data (excluding yourself), even if that person has a zero priority factor.
The lexicographical comparison is performed by the standard "<" operator in modern programming languages. The line a is lexicographically smaller than the line b, if either a is the prefix of b, or if exists such an i (1≤i≤min(|a|,|b|)), that ai<bi, and for any j (1≤j<i) aj=bj, where |a| and |b| stand for the lengths of strings a and b correspondently.

ahmed
3
ahmed posted on fatma's wall
fatma commented on ahmed's post
mona likes ahmed's post

name = gets.chomp
numb = gets.to_i

s_hash = Hash.new
arr = []
numb.times do |j|
	l = ""
	t = ""
	s = gets.chomp
	n = s.size - 1
	cnt = 0
	for i in 1..n
		if s[i] == ' '
			l = s[0,i]
			break
		end
	end
	m = l.size
	if s[m + 1,6] == "posted"
		for i in (m + 11)..n
			if s[i] == ' '
				t = s[m + 11,i - m - 13]
				break
			end
		end
		if t == name or l == name
			cnt = 15
		end
		if s_hash["#{l}"] == nil and l != name
			arr << l
		end

		if s_hash["#{t}"] == nil and t != name
			arr << t
		end

		s_hash["#{l}"] = s_hash["#{l}"].to_i + cnt
		s_hash["#{t}"] = s_hash["#{t}"].to_i + cnt
	end

	if s[m + 1,9] == "commented"
		for i in (m + 14)..n
			if s[i] == ' '
				t = s[m + 14,i - m - 16]
				break
			end
		end

		if t == name or l == name
			cnt = 10
		end
		if s_hash["#{l}"] == nil and l != name
			arr << l
		end

		if s_hash["#{t}"] == nil and t != name
			arr << t
		end

		s_hash["#{l}"] = s_hash["#{l}"].to_i + cnt
		s_hash["#{t}"] = s_hash["#{t}"].to_i + cnt
	end

		if s[m + 1,5] == "likes"
		for i in (m + 7)..n
			if s[i] == ' '
				t = s[m + 7,i - m - 9]
				break
			end
		end
		if t == name or l == name
			cnt = 5
		end
		if s_hash["#{l}"] == nil and l != name
			arr << l
		end

		if s_hash["#{t}"] == nil and t != name
			arr << t
		end

		s_hash["#{l}"] = s_hash["#{l}"].to_i + cnt
		s_hash["#{t}"] = s_hash["#{t}"].to_i + cnt
	end

end

arr.sort!

arr.sort_by! {|element| [-s_hash["#{element}"].to_i, -element] }

c = arr.size

c.times do |i|
	puts  arr[i]
end

[{'input': ["ahmed\r\n3\r\nahmed posted on fatma's wall\r\nfatma commented on ahmed's post\r\nmona likes ahmed's post\r\n"], 'output': ['fatma\r\nmona\r\n']}, {'input': ["aba\r\n1\r\nlikes likes posted's post\r\n"], 'output': ['likes\r\nposted\r\n']}, {'input': ["nu\r\n5\r\ng commented on pwyndmh's post\r\nqv posted on g's wall\r\ng likes nu's post\r\ng posted on nu's wall\r\nqv commented on pwyndmh's post\r\n"], 'output': ['g\r\npwyndmh\r\nqv\r\n']}, {'input': ["szfwtzfp\r\n5\r\nzqx posted on szfwtzfp's wall\r\nr commented on scguem's post\r\nr posted on civ's wall\r\nr likes scguem's post\r\nr likes scguem's post\r\n"], 'output': ['zqx\r\nciv\r\nr\r\nscguem\r\n']}, {'input': ["oaquudhavr\r\n3\r\ni posted on cwfwujpc's wall\r\ni likes oaquudhavr's post\r\noaquudhavr commented on cwfwujpc's post\r\n"], 'output': ['cwfwujpc\r\ni\r\n']}, {'input': ["eo\r\n4\r\neo commented on xkgjgwxtrx's post\r\neo posted on iqquh's wall\r\nn commented on xkgjgwxtrx's post\r\niqquh commented on n's post\r\n"], 'output': ['iqquh\r\nxkgjgwxtrx\r\nn\r\n']}, {'input': ["plwun\r\n3\r\neusjuq commented on plwun's post\r\nagktgdar likes eusjuq's post\r\nagppcoil likes agktgdar's post\r\n"], 'output': ['eusjuq\r\nagktgdar\r\nagppcoil\r\n']}, {'input': ["fgzrn\r\n3\r\nzhl likes fgzrn's post\r\nxryet likes fgzrn's post\r\nzhl commented on fgzrn's post\r\n"], 'output': ['zhl\r\nxryet\r\n']}, {'input': ["qatugmdjwg\r\n3\r\nb posted on cf's wall\r\nyjxkat posted on b's wall\r\nko commented on qatugmdjwg's post\r\n"], 'output': ['ko\r\nb\r\ncf\r\nyjxkat\r\n']}, {'input': ["dagwdwxsuf\r\n5\r\nesrvncb commented on dagwdwxsuf's post\r\nzcepigpbz posted on dagwdwxsuf's wall\r\nesrvncb commented on zcepigpbz's post\r\nesrvncb commented on dagwdwxsuf's post\r\ndagwdwxsuf commented on esrvncb's post\r\n"], 'output': ['esrvncb\r\nzcepigpbz\r\n']}, {'input': ["a\r\n1\r\nb likes c's post\r\n"], 'output': ['b\r\nc\r\n']}, {'input': ["a\r\n1\r\nc likes b's post\r\n"], 'output': ['b\r\nc\r\n']}, {'input': ["wuaiz\r\n10\r\nmnbggnud posted on xttaqvel's wall\r\ns posted on xopffmspf's wall\r\nkysxb likes qnrtpzkh's post\r\ngptks likes quebtsup's post\r\nkgmd commented on kmtnhsiue's post\r\newqjtxtiyn commented on a's post\r\nol posted on iglplaj's wall\r\nif posted on yuo's wall\r\nfs posted on dwjtuhgrq's wall\r\nygmdprun likes tzfneuly's post\r\n"], 'output': ['a\r\ndwjtuhgrq\r\newqjtxtiyn\r\nfs\r\ngptks\r\nif\r\niglplaj\r\nkgmd\r\nkmtnhsiue\r\nkysxb\r\nmnbggnud\r\nol\r\nqnrtpzkh\r\nquebtsup\r\ns\r\ntzfneuly\r\nxopffmspf\r\nxttaqvel\r\nygmdprun\r\nyuo\r\n']}, {'input': ["fzhzg\r\n11\r\nv likes xyf's post\r\nktqtpzhlh commented on ffsxarrn's post\r\nktqtpzhlh commented on lbt's post\r\njcdwpcycj commented on qbuigcgflm's post\r\nl likes pmg's post\r\nracszbmsk posted on ojr's wall\r\nojr commented on n's post\r\nnzqx commented on lkj's post\r\nv posted on lzoca's wall\r\nnwqnoham commented on gyivezpu's post\r\nfzhzg likes uqvzgzrpac's post\r\n"], 'output': ['uqvzgzrpac\r\nffsxarrn\r\ngyivezpu\r\njcdwpcycj\r\nktqtpzhlh\r\nl\r\nlbt\r\nlkj\r\nlzoca\r\nn\r\nnwqnoham\r\nnzqx\r\nojr\r\npmg\r\nqbuigcgflm\r\nracszbmsk\r\nv\r\nxyf\r\n']}, {'input': ["qdrnpb\r\n12\r\nymklhj commented on dkcbo's post\r\nhcucrenckl posted on mut's wall\r\nnvkyta commented on eo's post\r\npvgow likes mut's post\r\nob likes wlwcxtf's post\r\npvgow commented on advpu's post\r\nkfflyfbr commented on igozjnrxw's post\r\nsq commented on qdrnpb's post\r\nmrvn posted on lahduc's wall\r\ngsnlicy likes u's post\r\ndltqujf commented on qgzk's post\r\nr posted on bey's wall\r\n"], 'output': ['sq\r\nadvpu\r\nbey\r\ndkcbo\r\ndltqujf\r\neo\r\ngsnlicy\r\nhcucrenckl\r\nigozjnrxw\r\nkfflyfbr\r\nlahduc\r\nmrvn\r\nmut\r\nnvkyta\r\nob\r\npvgow\r\nqgzk\r\nr\r\nu\r\nwlwcxtf\r\nymklhj\r\n']}, {'input': ["biycvwb\r\n13\r\nhp likes cigobksf's post\r\nmcoqt commented on gaswzwat's post\r\nnz posted on xyvetbokl's wall\r\nqbnwy commented on ylkfbwjy's post\r\nqdwktrro likes rxgujnzecs's post\r\nbbsw commented on hwtatkfnps's post\r\ngspx posted on ugjxfnahuc's wall\r\nxlmut likes plle's post\r\numbwlleag commented on xfwlhen's post\r\nrlwxqksbwi commented on rypqtrgf's post\r\nbj posted on vovq's wall\r\nozpdpb commented on zti's post\r\nhqj posted on rxgujnzecs's wall\r\n"], 'output': ['bbsw\r\nbj\r\ncigobksf\r\ngaswzwat\r\ngspx\r\nhp\r\nhqj\r\nhwtatkfnps\r\nmcoqt\r\nnz\r\nozpdpb\r\nplle\r\nqbnwy\r\nqdwktrro\r\nrlwxqksbwi\r\nrxgujnzecs\r\nrypqtrgf\r\nugjxfnahuc\r\numbwlleag\r\nvovq\r\nxfwlhen\r\nxlmut\r\nxyvetbokl\r\nylkfbwjy\r\nzti\r\n']}, {'input': ["kmircqsffq\r\n14\r\nfrnf likes xgmmp's post\r\nfnfdpupayp commented on syz's post\r\nxefshpn commented on xgmmp's post\r\nm posted on gdwydzktok's wall\r\neskm likes pqmbnuc's post\r\npnqiapduhz likes zzqvjdz's post\r\nx likes nouuurc's post\r\nvnyxhoukuo posted on uhblapjab's wall\r\nblpjpxn likes zvwbger's post\r\nj posted on vuknetvl's wall\r\nscsw commented on xaggwxlxe's post\r\npqmbnuc commented on ojwaibie's post\r\niaazdlqdew commented on kmircqsffq's post\r\nqznqshxdi commented on umdqztoqun's post\r\n"], 'output': ['iaazdlqdew\r\nblpjpxn\r\neskm\r\nfnfdpupayp\r\nfrnf\r\ngdwydzktok\r\nj\r\nm\r\nnouuurc\r\nojwaibie\r\npnqiapduhz\r\npqmbnuc\r\nqznqshxdi\r\nscsw\r\nsyz\r\nuhblapjab\r\numdqztoqun\r\nvnyxhoukuo\r\nvuknetvl\r\nx\r\nxaggwxlxe\r\nxefshpn\r\nxgmmp\r\nzvwbger\r\nzzqvjdz\r\n']}, {'input': ["posted\r\n3\r\nposted posted on fatma's wall\r\nfatma commented on posted's post\r\nmona likes posted's post\r\n"], 'output': ['fatma\r\nmona\r\n']}, {'input': ["posted\r\n3\r\nposted posted on wall's wall\r\nwall commented on posted's post\r\nmona likes posted's post\r\n"], 'output': ['wall\r\nmona\r\n']}, {'input': ["posted\r\n3\r\nposted posted on wall's wall\r\nwall commented on posted's post\r\npost likes posted's post\r\n"], 'output': ['wall\r\npost\r\n']}, {'input': ["wall\r\n5\r\nwall posted on posted's wall\r\nwall posted on on's wall\r\nwall posted on commented's wall\r\nwall posted on likes's wall\r\nwall posted on post's wall\r\n"], 'output': ['commented\r\nlikes\r\non\r\npost\r\nposted\r\n']}, {'input': ["commented\r\n5\r\non commented on commented's post\r\npos commented on commented's post\r\nlikes commented on commented's post\r\nposted commented on commented's post\r\nwall commented on commented's post\r\n"], 'output': ['likes\r\non\r\npos\r\nposted\r\nwall\r\n']}, {'input': ["likes\r\n3\r\nlikes posted on post's wall\r\nlikes commented on on's post\r\nlikes likes commented's post\r\n"], 'output': ['post\r\non\r\ncommented\r\n']}, {'input': ["on\r\n4\r\non posted on posted's wall\r\non commented on commented's post\r\non posted on wall's wall\r\non commented on post's post\r\n"], 'output': ['posted\r\nwall\r\ncommented\r\npost\r\n']}, {'input': ["wall\r\n9\r\nwall posted on posted's wall\r\non commented on wall's post\r\nwall likes post's post\r\nposted posted on wall's wall\r\nwall commented on post's post\r\nlikes likes wall's post\r\nwall posted on on's wall\r\npost commented on wall's post\r\nwall likes likes's post\r\n"], 'output': ['posted\r\non\r\npost\r\nlikes\r\n']}, {'input': ["post\r\n9\r\npost posted on wall's wall\r\non commented on post's post\r\npost likes likes's post\r\ncommented posted on post's wall\r\npost commented on likes's post\r\nlikes likes post's post\r\npost posted on posted's wall\r\non commented on post's post\r\npost likes commented's post\r\n"], 'output': ['commented\r\nlikes\r\non\r\nposted\r\nwall\r\n']}, {'input': ["ahmed\r\n9\r\npost posted on ahmeds's wall\r\nahmeds commented on post's post\r\npost likes ahmeds's post\r\nahmeds posted on post's wall\r\npost commented on ahmeds's post\r\nahmeds likes post's post\r\npost posted on ahmeds's wall\r\nahmeds commented on post's post\r\npost likes ahmeds's post\r\n"], 'output': ['ahmeds\r\npost\r\n']}]


Berland National Library has recently been built in the capital of Berland. In addition, in the library you can take any of the collected works of Berland leaders, the library has a reading room.Today was the pilot launch of an automated reading room visitors' accounting system! The scanner of the system is installed at the entrance to the reading room. It records the events of the form "reader entered room", "reader left room". Every reader is assigned a registration number during the registration procedure at the library — it's a unique integer from 1 to 106. Thus, the system logs events of two forms:  "+ ri" — the reader with registration number ri entered the room;  "- ri" — the reader with registration number ri left the room. The first launch of the system was a success, it functioned for some period of time, and, at the time of its launch and at the time of its shutdown, the reading room may already have visitors.Significant funds of the budget of Berland have been spent on the design and installation of the system. Therefore, some of the citizens of the capital now demand to explain the need for this system and the benefits that its implementation will bring. Now, the developers of the system need to urgently come up with reasons for its existence.Help the system developers to find the minimum possible capacity of the reading room (in visitors) using the log of the system available to you.

The first line contains a positive integer n (1 ≤ n ≤ 100) — the number of records in the system log. Next follow n events from the system journal in the order in which the were made. Each event was written on a single line and looks as "+ ri" or "- ri", where ri is an integer from 1 to 106, the registration number of the visitor (that is, distinct visitors always have distinct registration numbers). It is guaranteed that the log is not contradictory, that is, for every visitor the types of any of his two consecutive events are distinct. Before starting the system, and after stopping the room may possibly contain visitors.

Print a single integer — the minimum possible capacity of the reading room.

NoteIn the first sample test, the system log will ensure that at some point in the reading room were visitors with registration numbers 1, 1200 and 12001. More people were not in the room at the same time based on the log. Therefore, the answer to the test is 3.

#!/usr/bin/ruby
h={}
cap=cur=0
gets.to_i.times{
	x,y=gets.split
	y=y.to_i
	if x=='+' && !h[y]
		cur+=1
		h[y]=1
	elsif x=='-' && h[y]
		cur-=1
		h[y]=nil
	elsif x=='-' && !h[y]
		cap+=1
	end
	cap=[cap,cur].max
}
p cap


You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.

The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively. The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.

The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.

format = gets.to_i
hour, minute = gets.strip.split(":").map(&:to_i)
if format == 12 and hour == 0
  hour = 1
elsif format == 12 and hour > 12
  hour %= 10
  hour = 10 if hour == 0
elsif format == 24 and hour >= 24
  hour %= 10
end
if minute >= 60
  minute %= 10
end
puts "%02d:%02d" % [hour, minute]


Little Chris knows there's no fun in playing dominoes, he thinks it's too random and doesn't require skill. Instead, he decided to play with the dominoes and make a "domino show".Chris arranges n dominoes in a line, placing each piece vertically upright. In the beginning, he simultaneously pushes some of the dominoes either to the left or to the right. However, somewhere between every two dominoes pushed in the same direction there is at least one domino pushed in the opposite direction.After each second, each domino that is falling to the left pushes the adjacent domino on the left. Similarly, the dominoes falling to the right push their adjacent dominoes standing on the right. When a vertical domino has dominoes falling on it from both sides, it stays still due to the balance of the forces. The figure shows one possible example of the process.  Given the initial directions Chris has pushed the dominoes, find the number of the dominoes left standing vertically at the end of the process!

The first line contains a single integer n (1 ≤ n ≤ 3000), the number of the dominoes in the line. The next line contains a character string s of length n. The i-th character of the string si is equal to    "L", if the i-th domino has been pushed to the left;  "R", if the i-th domino has been pushed to the right;  ".", if the i-th domino has not been pushed.  It is guaranteed that if si = sj = "L" and i < j, then there exists such k that i < k < j and sk = "R"; if si = sj = "R" and i < j, then there exists such k that i < k < j and sk = "L".

Output a single integer, the number of the dominoes that remain vertical at the end of the process.

NoteThe first example case is shown on the figure. The four pieces that remain standing vertically are highlighted with orange.In the second example case, all pieces fall down since the first piece topples all the other pieces.In the last example case, a single piece has not been pushed in either direction.

#!/usr/bin/ruby
gets
s=gets.chomp
loop{
	t=s.dup
	t.size.times{|i|
		next if t[i,1]!='.'
		r=0<i&&s[i-1,1]=='R'
		l=i<t.size-1&&s[i+1,1]=='L'
		if r^l
			t[i,1] = r ? 'R' : 'L'
		end
	}
	break if s==t
	s=t
}
p s.scan('.').count


"Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him.The sequence of n integers is called a permutation if it contains all integers from 1 to n exactly once.You are given an arbitrary sequence a1, a2, ..., an containing n integers. Each integer is not less than 1 and not greater than 5000. Determine what minimum number of elements Polycarpus needs to change to get a permutation (he should not delete or add numbers). In a single change he can modify any single sequence element (i. e. replace it with another integer).

The first line of the input data contains an integer n (1 ≤ n ≤ 5000) which represents how many numbers are in the sequence. The second line contains a sequence of integers ai (1 ≤ ai ≤ 5000, 1 ≤ i ≤ n).

Print the only number — the minimum number of changes needed to get the permutation.

NoteThe first sample contains the permutation, which is why no replacements are required.In the second sample it is enough to replace the first element with the number 1 and that will make the sequence the needed permutation.In the third sample we can replace the second element with number 4 and the fourth element with number 2.

require 'set'
n = gets.to_i
a = Set.new(gets.split(' ').map(&:to_i))
res = 0
n.times do |i|
  unless a.include?(i+1); res += 1; end;
end
p res


One day little Vasya found mom's pocket book. The book had n names of her friends and unusually enough, each name was exactly m letters long. Let's number the names from 1 to n in the order in which they are written.As mom wasn't home, Vasya decided to play with names: he chose three integers i, j, k (1 ≤ i < j ≤ n, 1 ≤ k ≤ m), then he took names number i and j and swapped their prefixes of length k. For example, if we take names "CBDAD" and "AABRD" and swap their prefixes with the length of 3, the result will be names "AABAD" and "CBDRD".You wonder how many different names Vasya can write instead of name number 1, if Vasya is allowed to perform any number of the described actions. As Vasya performs each action, he chooses numbers i, j, k independently from the previous moves and his choice is based entirely on his will. The sought number can be very large, so you should only find it modulo 1000000007 (109 + 7).

The first input line contains two integers n and m (1 ≤ n, m ≤ 100) — the number of names and the length of each name, correspondingly. Then n lines contain names, each name consists of exactly m uppercase Latin letters.

Print the single number — the number of different names that could end up in position number 1 in the pocket book after the applying the procedures described above. Print the number modulo 1000000007 (109 + 7).

NoteIn the first sample Vasya can get the following names in the position number 1: "AAB", "AAA", "BAA" and "BAB".

require 'set'

n,m = gets.chomp.split(/ /).map!{|x| x.to_i}
s = []
for i in 0..n-1
	s << gets.chomp
end
ret = 1
for i in 0..m-1
	ws = Set.new
	for j in 0..n-1
		ws.add(s[j][i])
	end
	ret *= ws.length
end
ret %= 1000000007
puts ret

[{'input': '2 3\r\nAAB\r\nBAA\r\n', 'output': ['4\r\n']}, {'input': '4 5\r\nABABA\r\nBCGDG\r\nAAAAA\r\nYABSA\r\n', 'output': ['216\r\n']}, {'input': '1 1\r\nE\r\n', 'output': ['1\r\n']}, {'input': '2 2\r\nNS\r\nPD\r\n', 'output': ['4\r\n']}, {'input': '3 4\r\nPJKD\r\nNFJX\r\nFGFK\r\n', 'output': ['81\r\n']}, {'input': '4 5\r\nSXFMY\r\nATHLM\r\nKDDQW\r\nZWGDS\r\n', 'output': ['1024\r\n']}, {'input': '20 14\r\nJNFKBBBJYZHWQE\r\nLBOKZCPFNKDBJY\r\nXKNWGHQHIOXUPF\r\nDDNRUKVUGHWMXW\r\nMTIZFNAAFEAPHX\r\nIXBQOOHEULZYHU\r\nMRCSREUEOOMUUN\r\nHJTSQWKUFYZDQU\r\nGMCMUZCOPRVEIQ\r\nXBKKGGJECOBLTH\r\nXXHTLXCNJZJUAF\r\nVLJRKXXXWMTPKZ\r\nPTYMNPTBBCWKAD\r\nQYJGOBUBHMEDYE\r\nGTKUUVVNKAHTUI\r\nZNKXYZPCYLBZFP\r\nQCBLJTRMBDWNNE\r\nTDOKJOBKEOVNLZ\r\nFKZUITYAFJOQIM\r\nUWQNSGLXEEIRWF\r\n', 'output': ['515139391\r\n']}, {'input': '5 14\r\nAQRXUQQNSKZPGC\r\nDTTKSPFGGVCLPT\r\nVLZQWWESCHDTAZ\r\nCOKOWDWDRUOMHP\r\nXDTRBIZTTCIDGS\r\n', 'output': ['124999979\r\n']}, {'input': '9 23\r\nOILBYKHRGMPENVFNHLSIUOW\r\nLPJFHTUQUINAALRDGLSQUXR\r\nLYYJJEBNZATAFQWTDZSPUNZ\r\nHSJPIQKKWWERJZIEMLCZUKI\r\nOJYIEYDGPFWRHCMISJCCUEM\r\nLMGKZVFYIVDRTIHBWPCNUTG\r\nUBGGNCITVHAIPKXCLTSAULQ\r\nOWSAWUOXQDBSXXBHTLSXUVD\r\nUGQTIZQPBGMASRQPVPSFUWK\r\n', 'output': ['454717784\r\n']}, {'input': '25 4\r\nLVKG\r\nMICU\r\nZHKW\r\nLFGG\r\nOWQO\r\nLCQG\r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W\r\nQCMXRQN\r\nFDUDSZO\r\nHKBEVTW\r\n', 'output': ['206575993\r\n']}, {'input': '2 2\r\nAA\r\nBB\r\n', 'output': ['4\r\n']}, {'input': '1 10\r\nAAAAAAAAAA\r\n', 'output': ['1\r\n']}, {'input': '2 8\r\nAAAAAAAA\r\nBBBBBBBB\r\n', 'output': ['256\r\n']}, {'input': '10 10\r\nAAAAAAAAAA\r\nBBBBBBBBBB\r\nCCCCCCCCCC\r\nDDDDDDDDDD\r\nAAAAAAAAAA\r\nBBBBBBBBBB\r\nCCCCCCCCCC\r\nDDDDDDDDDD\r\nAAAAAAAAAA\r\nBBBBBBBBBB\r\n', 'output': ['1048576\r\n']}, {'input': '1 20\r\nAAAAAAAAAAAAAAAAAAAA\r\n', 'output': ['1\r\n']}, {'input': '20 1\r\nA\r\nB\r\nC\r\nD\r\nE\r\nF\r\nG\r\nA\r\nB\r\nC\r\nD\r\nE\r\nF\r\nG\r\nA\r\nB\r\nC\r\nD\r\nE\r\nF\r\n', 'output': ['7\r\n']}, {'input': '5 60\r\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\r\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\r\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\r\nDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD\r\nEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\r\n', 'output': ['449874206\r\n']}, {'input': '50 4\r\nAAAA\r\nBBBB\r\nCCCC\r\nDDDD\r\nEEEE\r\nFFFF\r\nGGGG\r\nHHHH\r\nIIII\r\nJJJJ\r\nAAAA\r\nBBBB\r\nCCCC\r\nDDDD\r\nEEEE\r\nFFFF\r\nGG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\r\nH\r\nI\r\nJ\r\nK\r\nL\r\nM\r\nN\r\nO\r\nP\r\nQ\r\nR\r\nS\r\nT\r\nU\r\nV\r\nW\r\nX\r\nY\r\nZ\r\nA\r\nB\r\nC\r\nD\r\nE\r\nF\r\nG\r\nH\r\nI\r\nJ\r\nK\r\nL\r\nM\r\nN\r\nO\r\nP\r\nQ\r\nR\r\nS\r\nT\r\nU\r\nV\r\nW\r\nX\r\nY\r\nZ\r\nA\r\nB\r\nC\r\nD\r\nE\r\nF\r\nG\r\nH\r\nI\r\nJ\r\nK\r\nL\r\nM\r\nN\r\nO\r\nP\r\nQ\r\nR\r\nS\r\nT\r\nU\r\nV\r\nW\r\nX\r\nY\r\nZ\r\nA\r\nB\r\nC\r\nD\r\nE\r\nF\r\nG\r\nH\r\nI\r\nJ\r\nK\r\nL\r\nM\r\nN\r\nO\r\nP\r\nQ\r\nR\r\nS\r\nT\r\nU\r\nV\r\n', 'output': ['26\r\n']}]


An African crossword is a rectangular table n × m in size. Each cell of the table contains exactly one letter. This table (it is also referred to as grid) contains some encrypted word that needs to be decoded.To solve the crossword you should cross out all repeated letters in rows and columns. In other words, a letter should only be crossed out if and only if the corresponding column or row contains at least one more letter that is exactly the same. Besides, all such letters are crossed out simultaneously.When all repeated letters have been crossed out, we should write the remaining letters in a string. The letters that occupy a higher position follow before the letters that occupy a lower position. If the letters are located in one row, then the letter to the left goes first. The resulting word is the answer to the problem.You are suggested to solve an African crossword and print the word encrypted there.

The first line contains two integers n and m (1 ≤ n, m ≤ 100). Next n lines contain m lowercase Latin letters each. That is the crossword grid.

n,m = gets.chomp.split(/ /).map!{|x| x.to_i}
bd = Array.new(n)
bdf = Array.new(n)
for i in 0..n-1
	bd[i] = gets.chomp.split(//)
	bdf[i] = Array.new(m)
end

for i in 0..n-1
	for j in 0..m-1
		bdf[i][j] = true
	end
end

for i in 0..n-1
	h = Hash.new
	for j in 0..m-1
		if h.key?(bd[i][j])
			h[bd[i][j]] += 1
		else
			h[bd[i][j]] = 1
		end
	end
	for j in 0..m-1
		bdf[i][j] = false if h[bd[i][j]] > 1
	end
end

for j in 0..m-1
	h = Hash.new
	for i in 0..n-1
		if h.key?(bd[i][j])
			h[bd[i][j]] += 1
		else
			h[bd[i][j]] = 1
		end
	end
	for i in 0..n-1
		bdf[i][j] = false if h[bd[i][j]] > 1
	end
end

for i in 0..n-1
	for j in 0..m-1
		print bd[i][j] if bdf[i][j] == true
	end
end

puts ""

[{'input': '3 3\r\ncba\r\nbcd\r\ncbc\r\n', 'output': ['abcd']}, {'input': '5 5\r\nfcofd\r\nooedo\r\nafaoa\r\nrdcdf\r\neofsf\r\n', 'output': ['codeforces']}, {'input': '4 4\r\nusah\r\nusha\r\nhasu\r\nsuha\r\n', 'output': ['ahhasusu']}, {'input': '7 5\r\naabcd\r\neffgh\r\niijkk\r\nlmnoo\r\npqqrs\r\nttuvw\r\nxxyyz\r\n', 'output': ['bcdeghjlmnprsuvwz']}, {'input': '10 10\r\naaaaaaaaaa\r\nbccceeeeee\r\ncdfffffffe\r\ncdfiiiiile\r\ncdfjjjjile\r\ndddddddile\r\nedfkkkkile\r\nedddddddde\r\ngggggggggg\r\nhhhhhhhhhe\r\n', 'output': ['b']}, {'input': '15 3\r\njhg\r\njkn\r\njui\r\nfth\r\noij\r\nyuf\r\nyfb\r\nugd\r\nhgd\r\noih\r\nhvc\r\nugg\r\nyvv\r\ntdg\r\nhgf\r\n', 'output': ['hkniftjfbctd']}, {'input': '17 19\r\nbmzbmweyydiadtlcoue\r\ngmdbyfwurpwbpuvhifn\r\nuapwyndmhtqvkgkbhty\r\ntszotwflegsjzzszfwt\r\nzfpnscguemwrczqxyci\r\nvdqnkypnxnnpmuduhzn\r\noaquudhavrncwfwujpc\r\nmiggjmcmkkbnjfeodxk\r\ngjgwxtrxingiqquhuwq\r\nhdswxxrxuzzfhkplwun\r\nfagppcoildagktgdarv\r\neusjuqfistulgbglwmf\r\ngzrnyxryetwzhlnfewc\r\nzmnoozlqatugmdjwgzc\r\nfabbkoxyjxkatjmpprs\r\nwkdkobdagwdwxsufees\r\nrvncbszcepigpbzuzoo\r\n', 'output': ['lcorviunqvgblgjfsgmrqxyivyxodhvrjpicbneodxjtfkpolvejqmllqadjwotmbgxrvs']}, {'input': '1 1\r\na\r\n', 'output': ['a']}, {'input': '2 2\r\nzx\r\nxz\r\n', 'output': ['zxxz']}, {'input': '1 2\r\nfg\r\n', 'output': ['fg']}, {'input': '2 1\r\nh\r\nj\r\n', 'output': ['hj']}, {'input': '1 3\r\niji\r\n', 'output': ['j']}, {'input': '3 1\r\nk\r\np\r\nk\r\n', 'output': ['p']}, {'input': '2 3\r\nmhw\r\nbfq\r\n', 'output': ['mhwbfq']}, {'input': '3 2\r\nxe\r\ner\r\nwb\r\n', 'output': ['xeerwb']}, {'input': '3 7\r\nnutuvjg\r\ntgqutfn\r\nyfjeiot\r\n', 'output': ['ntvjggqfnyfjeiot']}, {'input': '5 4\r\nuzvs\r\namfz\r\nwypl\r\nxizp\r\nfhmf\r\n', 'output': ['uzvsamfzwyplxizphm']}, {'input': '8 9\r\ntjqrtgrem\r\nrwjcfuoey\r\nywrjgpzca\r\nwabzggojv\r\najqmmcclh\r\nozilebskd\r\nqmgnbmtcq\r\nwakptzkjr\r\n', 'output': ['mrjcfuyyrjpzabzvalhozilebskdgnbtpzr']}, {'input': '9 3\r\njel\r\njws\r\ntab\r\nvyo\r\nkgm\r\npls\r\nabq\r\nbjx\r\nljt\r\n', 'output': ['elwtabvyokgmplabqbxlt']}, {'input': '7 6\r\neklgxi\r\nxmpzgf\r\nxvwcmr\r\nrqssed\r\nouiqpt\r\ndueiok\r\nbbuorv\r\n', 'output': ['eklgximpzgfvwcmrrqedoiqptdeiokuorv']}, {'input': '14 27\r\npzoshpvvjdpmwfoeojapmkxjrnk\r\nitoojpcorxjdxrwyewtmmlhjxhx\r\ndoyopbwusgsmephixzcilxpskxh\r\nygpvepeuxjbnezdrnjfwdhjwjka\r\nrfjlbypoalbtjwrpjxzenmeipfg\r\nkhjhrtktcnajrnbefhpavxxfnlx\r\nvwlwumqpfegjgvoezevqsolaqhh\r\npdrvrtzqsoujqfeitkqgtxwckrl\r\nxtepjflcxcrfomhqimhimnzfxzg\r\nwhkfkfvvjwkmwhfgeovwowshyhw\r\nolchgmhiehumivswgtfyhqfagbp\r\ntdudrkttpkryvaiepsijuejqvmq\r\nmuratfqqdbfpefmhjzercortroh\r\nwxkebkzchupxumfizftgqvuwgau\r\n', 'output': ['zshdanicdyldybwgclygzrhkayatwxznmicbpvlupfsoewcleploqngsyolceswtyqbpyasmuadbpcehqva']}, {'input': '1 100\r\nysijllpanprcrrtvokqmmupuptvawhvnekeybdkzqaduotmkfwybqvytkbjfzyqztmxckizheorvkhtyoohbswcmhknyzlgxordu\r\n', 'output': ['g']}, {'input': '2 100\r\ngplwoaggwuxzutpwnmxhotbexntzmitmcvnvmuxknwvcrnsagvdojdgaccfbheqojgcqievijxapvepwqolmnjqsbejtnkaifstp\r\noictcmphxbrylaarcwpruiastazvmfhlcgticvwhpxyiiqokxcjgwlnfykkqdsfmrfaedzchrfzlwdclqjxvidhomhxqnlmuoowg\r\n', 'output': ['rbe']}, {'input': '3 100\r\nonmhsoxoexfwavmamoecptondioxdjsoxfuqxkjviqnjukwqjwfadnohueaxrkreycicgxpmogijgejxsprwiweyvwembluwwqhj\r\nuofldyjyuhzgmkeurawgsrburovdppzjiyddpzxslhyesvmuwlgdjvzjqqcpubfgxliulyvxxloqyhxspoxvhllbrajlommpghlv\r\nvdohhghjlvihrzmwskxfatoodupmnouwyyfarhihxpdnbwrvrysrpxxptdidpqabwbfnxhiziiiqtozqjtnitgepxjxosspsjldo\r\n', 'output': ['blkck']}, {'input': '100 1\r\na\r\nm\r\nn\r\nh\r\na\r\nx\r\nt\r\na\r\no\r\np\r\nj\r\nz\r\nr\r\nk\r\nq\r\nl\r\nb\r\nr\r\no\r\ni\r\ny\r\ni\r\np\r\ni\r\nt\r\nn\r\nd\r\nc\r\nz\r\np\r\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nlge\r\nkft\r\ndzp\r\ntfb\r\nhqz\r\nuur\r\nhry\r\nzjx\r\ncuo\r\nqqc\r\ntih\r\nenj\r\nvnp\r\nbwi\r\nzzh\r\nhkc\r\nwdr\r\nldh\r\nvel\r\nizj\r\nfhb\r\nqrn\r\nqpp\r\nvzs\r\nlhg\r\nkee\r\nlbq\r\nzhy\r\nwcl\r\nyaa\r\nton\r\nfly\r\nkyw\r\nept\r\ngwq\r\ncoe\r\nopd\r\neez\r\nnmx\r\nnjg\r\nwhy\r\nvel\r\nafq\r\nnbq\r\nulx\r\noxs\r\nbbo\r\nyhx\r\nfmz\r\nnrg\r\nnfm\r\njek\r\nbeu\r\ntya\r\nxgs\r\nsgg\r\nnkq\r\nbbv\r\nwkd\r\ntns\r\nfdt\r\neox\r\nobc\r\neab\r\nkkj\r\noub\r\ngji\r\nrht\r\nozv\r\nysk\r\nsbt\r\nflf\r\npbu\r\nlxb\r\npzs\r\nrzh\r\ncea\r\nkmi\r\nuea\r\nncc\r\nzng\r\nvkn\r\njhn\r\njqw\r\nlqc\r\nmbt\r\nlov\r\ngam\r\n', 'output': ['tvdiixs']}]


A little boy Gerald entered a clothes shop and found out something very unpleasant: not all clothes turns out to match. For example, Gerald noticed that he looks rather ridiculous in a smoking suit and a baseball cap.Overall the shop sells n clothing items, and exactly m pairs of clothing items match. Each item has its price, represented by an integer number of rubles. Gerald wants to buy three clothing items so that they matched each other. Besides, he wants to spend as little money as possible. Find the least possible sum he can spend.

The first input file line contains integers n and m — the total number of clothing items in the shop and the total number of matching pairs of clothing items (). Next line contains n integers ai (1 ≤ ai ≤ 106) — the prices of the clothing items in rubles. Next m lines each contain a pair of space-separated integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi). Each such pair of numbers means that the ui-th and the vi-th clothing items match each other. It is guaranteed that in each pair ui and vi are distinct and all the unordered pairs (ui, vi) are different.

Print the only number — the least possible sum in rubles that Gerald will have to pay in the shop. If the shop has no three clothing items that would match each other, print "-1" (without the quotes).

NoteIn the first test there only are three pieces of clothing and they all match each other. Thus, there is only one way — to buy the 3 pieces of clothing; in this case he spends 6 roubles.The second test only has three pieces of clothing as well, yet Gerald can't buy them because the first piece of clothing does not match the third one. Thus, there are no three matching pieces of clothing. The answer is -1.In the third example there are 4 pieces of clothing, but Gerald can't buy any 3 of them simultaneously. The answer is -1.

n,m=gets.split.map(&:to_i)
a=gets.split.map(&:to_i)
g=Array.new(n){Array.new(n,0)}
m.times{
        p,q=gets.split.map(&:to_i)
        g[p-1][q-1]=g[q-1][p-1]=1
}
ans=9999999999
0.upto(n-1){|i|
        (i+1).upto(n-1){|j|
                if g[i][j]==0 then
                        next
                end
                (j+1).upto(n-1){|k|
                        if g[i][k]==0 || g[j][k]==0 then
                                next
                        end
                        ans=[ans,a[i]+a[j]+a[k]].min
                }
        }
}
puts (ans>=999999999)?-1:ans


...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu...Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super weapon. Due to high seismic activity and poor weather conditions the satellites haven't yet been able to make clear shots of the monster. The analysis of the first shot resulted in an undirected graph with n vertices and m edges. Now the world's best minds are about to determine whether this graph can be regarded as Cthulhu or not.To add simplicity, let's suppose that Cthulhu looks from the space like some spherical body with tentacles attached to it. Formally, we shall regard as Cthulhu such an undirected graph that can be represented as a set of three or more rooted trees, whose roots are connected by a simple cycle.It is guaranteed that the graph contains no multiple edges and self-loops.

The first line contains two integers — the number of vertices n and the number of edges m of the graph (1 ≤ n ≤ 100, 0 ≤ m ≤ ). Each of the following m lines contains a pair of integers x and y, that show that an edge exists between vertices x and y (1 ≤ x, y ≤ n, x ≠ y). For each pair of vertices there will be at most one edge between them, no edge connects a vertex to itself.

Print "NO", if the graph is not Cthulhu and "FHTAGN!" if it is.

NoteLet us denote as a simple cycle a set of v vertices that can be numbered so that the edges will only exist between vertices number 1 and 2, 2 and 3, ..., v - 1 and v, v and 1.A tree is a connected undirected graph consisting of n vertices and n - 1 edges (n > 0).A rooted tree is a tree where one vertex is selected to be the root.

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

sm = [];
n.times do |i| sm[i] = [] end

m.times do
    a,b = gets.split(' ').map(&:to_i)
    a -= 1
    b -= 1
    sm[a][b] = 1
end

p = []
$q = 0
def rec(id,p,sm,n)
    p[id] |= 0
    if p[id] == 1 then return end
    p[id] = 1
    $q += 1
    n.times do |i|
        sm[id][i] |= 0
        if sm[id][i] == 1 or sm[i][id] == 1 then
            rec(i,p,sm,n)
        end
    end
end

rec(0,p,sm,n)
if($q == n and $q == m) then puts('FHTAGN!');
else puts('NO');
end


Anna and Maria are in charge of the math club for junior students. When the club gathers together, the students behave badly. They've brought lots of shoe laces to the club and got tied with each other. Specifically, each string ties together two students. Besides, if two students are tied, then the lace connects the first student with the second one as well as the second student with the first one.To restore order, Anna and Maria do the following. First, for each student Anna finds out what other students he is tied to. If a student is tied to exactly one other student, Anna reprimands him. Then Maria gathers in a single group all the students who have been just reprimanded. She kicks them out from the club. This group of students immediately leaves the club. These students takes with them the laces that used to tie them. Then again for every student Anna finds out how many other students he is tied to and so on. And they do so until Anna can reprimand at least one student.Determine how many groups of students will be kicked out of the club.

The first line contains two integers n and m — the initial number of students and laces (). The students are numbered from 1 to n, and the laces are numbered from 1 to m. Next m lines each contain two integers a and b — the numbers of students tied by the i-th lace (1 ≤ a, b ≤ n, a ≠ b). It is guaranteed that no two students are tied with more than one lace. No lace ties a student to himself.

Print the single number — the number of groups of students that will be kicked out from the club.

NoteIn the first sample Anna and Maria won't kick out any group of students — in the initial position every student is tied to two other students and Anna won't be able to reprimand anyone.In the second sample four students are tied in a chain and two more are running by themselves. First Anna and Maria kick out the two students from both ends of the chain (1 and 4), then — two other students from the chain (2 and 3). At that the students who are running by themselves will stay in the club.In the third sample Anna and Maria will momentarily kick out all students except for the fourth one and the process stops at that point. The correct answer is one.

n,m=gets.chomp.split.map(&:to_i)
i,j,f,a,b,ar=0,0,0,[],[],Array.new(100,0)
m.times do |i|
	x,y=gets.chomp.split.map(&:to_i)
	a<<(x-1);b<<(y-1)
end
while i<105
	f,c=0,Array.new(100,0)
	m.times do |j|
		if ar[a[j]]==0 && ar[b[j]]==0
			c[a[j]]+=1
			c[b[j]]+=1
		end
	end
	n.times do |j|
		if c[j]==1
			f=1
			ar[j]=1
		end
	end
	break if f==0
	i+=1
end
puts i


A group of n merry programmers celebrate Robert Floyd's birthday. Polucarpus has got an honourable task of pouring Ber-Cola to everybody. Pouring the same amount of Ber-Cola to everybody is really important. In other words, the drink's volume in each of the n mugs must be the same.Polycarpus has already began the process and he partially emptied the Ber-Cola bottle. Now the first mug has a1 milliliters of the drink, the second one has a2 milliliters and so on. The bottle has b milliliters left and Polycarpus plans to pour them into the mugs so that the main equation was fulfilled.Write a program that would determine what volume of the drink Polycarpus needs to add into each mug to ensure that the following two conditions were fulfilled simultaneously:   there were b milliliters poured in total. That is, the bottle need to be emptied;  after the process is over, the volumes of the drink in the mugs should be equal.

The first line contains a pair of integers n, b (2 ≤ n ≤ 100, 1 ≤ b ≤ 100), where n is the total number of friends in the group and b is the current volume of drink in the bottle. The second line contains a sequence of integers a1, a2, ..., an (0 ≤ ai ≤ 100), where ai is the current volume of drink in the i-th mug.

Print a single number "-1" (without the quotes), if there is no solution. Otherwise, print n float numbers c1, c2, ..., cn, where ci is the volume of the drink to add in the i-th mug. Print the numbers with no less than 6 digits after the decimal point, print each ci on a single line. Polycarpus proved that if a solution exists then it is unique. Russian locale is installed by default on the testing computer. Make sure that your solution use the point to separate the integer part of a real number from the decimal, not a comma.

n,b = gets.chomp.split(/ /).map!{|x| x.to_i}
a = gets.chomp.split(/ /).map!{|x| x.to_i}
ma = a.max
af = []
wk = 0
for i in 0..a.length-1
  af << (ma - a[i])
  wk += af[i]
end
if wk > b
  puts "-1"
else
  wkf = (b - wk).to_f / a.length
  for i in 0..af.length-1
    puts format("%.6f",(wkf+af[i]))
  end
end


Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will point "upwards" and one will point "downwards". After another year, each triangle plant divides into four triangle plants: three of them will be directed in the same direction as the parent plant, and one of them will be directed in the opposite direction. Then each year the process repeats. The figure below illustrates this process.  Help the dwarfs find out how many triangle plants that point "upwards" will be in n years.

The first line contains a single integer n (0 ≤ n ≤ 1018) — the number of full years when the plant grew. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.

Print a single integer — the remainder of dividing the number of plants that will point "upwards" in n years by 1000000007 (109 + 7).

NoteThe first test sample corresponds to the second triangle on the figure in the statement. The second test sample corresponds to the third one.

$p = 1000000007
def mul(a,b)
  n = a.size
  c = Array.new(n){Array.new(n){0}}
  n.times do |i|
    n.times do|j|
      n.times do |k|
        c[i][j] += a[i][k] * b[k][j]
        c[i][j] %= $p
      end
    end
  end
  c
end

def po(m)
  e = [[3,1],[1,3]]
  ret = [[1,0],[0,1]]

  while m > 0
    if m % 2 == 1
      ret = mul(ret,e)
    end
    e = mul(e,e)
    m /= 2
  end

  ret
end

def work(n)
    if n == 1
      puts 3
    else
      ret = po(n)
      ans = ret[0][0]
      puts ans % $p
    end
end

n = gets.to_i
work n


In Berland the opposition is going to arrange mass walking on the boulevard. The boulevard consists of n tiles that are lain in a row and are numbered from 1 to n from right to left. The opposition should start walking on the tile number 1 and the finish on the tile number n. During the walk it is allowed to move from right to left between adjacent tiles in a row, and jump over a tile. More formally, if you are standing on the tile number i (i < n - 1), you can reach the tiles number i + 1 or the tile number i + 2 from it (if you stand on the tile number n - 1, you can only reach tile number n). We can assume that all the opposition movements occur instantaneously.In order to thwart an opposition rally, the Berland bloody regime organized the rain. The tiles on the boulevard are of poor quality and they are rapidly destroyed in the rain. We know that the i-th tile is destroyed after ai days of rain (on day ai tile isn't destroyed yet, and on day ai + 1 it is already destroyed). Of course, no one is allowed to walk on the destroyed tiles! So the walk of the opposition is considered thwarted, if either the tile number 1 is broken, or the tile number n is broken, or it is impossible to reach the tile number n from the tile number 1 if we can walk on undestroyed tiles.The opposition wants to gather more supporters for their walk. Therefore, the more time they have to pack, the better. Help the opposition to calculate how much time they still have and tell us for how many days the walk from the tile number 1 to the tile number n will be possible.

The first line contains integer n (1 ≤ n ≤ 103) — the boulevard's length in tiles. The second line contains n space-separated integers ai — the number of days after which the i-th tile gets destroyed (1 ≤ ai ≤ 103).

Print a single number — the sought number of days.

NoteIn the first sample the second tile gets destroyed after day three, and the only path left is 1 → 3 → 4. After day five there is a two-tile gap between the first and the last tile, you can't jump over it.In the second sample path 1 → 3 → 5 is available up to day five, inclusive. On day six the last tile is destroyed and the walk is thwarted.

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

days = 0
loop do
  break if a[0] == 0 or a[-1] == 0

  bang = false
  for i in 1 .. (n - 2) do
    bang = true if a[i] == 0 and a[i + 1] == 0
  end
  break if bang

  days += 1

  a.map!{|e|
    e > 0 ? e -= 1 : e
  }
end

puts days


The Little Elephant loves to play with color cards.He has n cards, each has exactly two colors (the color of the front side and the color of the back side). Initially, all the cards lay on the table with the front side up. In one move the Little Elephant can turn any card to the other side. The Little Elephant thinks that a set of cards on the table is funny if at least half of the cards have the same color (for each card the color of the upper side is considered).Help the Little Elephant to find the minimum number of moves needed to make the set of n cards funny.

The first line contains a single integer n (1 ≤ n ≤ 105) — the number of the cards. The following n lines contain the description of all cards, one card per line. The cards are described by a pair of positive integers not exceeding 109 — colors of both sides. The first number in a line is the color of the front of the card, the second one — of the back. The color of the front of the card may coincide with the color of the back of the card. The numbers in the lines are separated by single spaces.

On a single line print a single integer — the sought minimum number of moves. If it is impossible to make the set funny, print -1.

NoteIn the first sample there initially are three cards lying with colors 4, 4, 7. Since two of the three cards are of the same color 4, you do not need to change anything, so the answer is 0.In the second sample, you can turn the first and the fourth cards. After that three of the five cards will be of color 7.

s=(gets.to_i+1)/2
a=gets(p).scan /(\S+) (.+)/
x=a.flatten.sort.each_slice([a.size/2,1].max).map(&:first).select{|i|a.count{|j,k|j==i||k==i}>=s}
p x[0]?[s-x.map{|i|a.map(&:first).count i}.max,0].max: -1


Vasya, like many others, likes to participate in a variety of sweepstakes and lotteries. Now he collects wrappings from a famous chocolate bar "Jupiter". According to the sweepstake rules, each wrapping has an integer written on it — the number of points that the participant adds to his score as he buys the bar. After a participant earns a certain number of points, he can come to the prize distribution center and exchange the points for prizes. When somebody takes a prize, the prize's cost is simply subtracted from the number of his points.Vasya didn't only bought the bars, he also kept a record of how many points each wrapping cost. Also, he remembers that he always stucks to the greedy strategy — as soon as he could take at least one prize, he went to the prize distribution centre and exchanged the points for prizes. Moreover, if he could choose between multiple prizes, he chose the most expensive one. If after an exchange Vasya had enough points left to get at least one more prize, then he continued to exchange points.The sweepstake has the following prizes (the prizes are sorted by increasing of their cost):   a mug (costs a points),  a towel (costs b points),  a bag (costs c points),  a bicycle (costs d points),  a car (costs e points). Now Vasya wants to recollect what prizes he has received. You know sequence p1, p2, ..., pn, where pi is the number of points Vasya got for the i-th bar. The sequence of points is given in the chronological order. You also know numbers a, b, c, d, e. Your task is to find, how many prizes Vasya received, what prizes they are and how many points he's got left after all operations are completed.

The first line contains a single integer n (1 ≤ n ≤ 50) — the number of chocolate bar wrappings that brought points to Vasya. The second line contains space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ 109). The third line contains 5 integers a, b, c, d, e (1 ≤ a < b < c < d < e ≤ 109) — the prizes' costs.

Print on the first line 5 integers, separated by a space — the number of mugs, towels, bags, bicycles and cars that Vasya has got, respectively. On the second line print a single integer — the number of points Vasya will have left after all operations of exchange are completed. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

NoteIn the first sample Vasya gets 3 points after eating the first chocolate bar. Then he exchanges 2 points and gets a mug. Vasya wins a bag after eating the second chocolate bar. Then he wins a towel after eating the third chocolate bar. After all chocolate bars 3 - 2 + 10 - 10 + 4 - 4 = 1 points remains.

def koukan()
    return -1 if $sum < $aa[0]
    5.downto(1) { |i|
        return i-1 if $aa[i-1] <= $sum
    }
end

$n = gets.chomp.to_i
$sa = gets.chomp.split(/ /).map!{|x| x.to_i}
$aa = gets.chomp.split(/ /).map!{|x| x.to_i}
$sum = 0
$suma = Array.new(5).map!{|x| x = 0}
for i in 0..$n-1
    $sum += $sa[i]
    while (true)
        if $sum > $aa[4]
            wka = $sum.divmod($aa[4])
            $suma[4] += wka[0]
            $sum -= $aa[4] * wka[0]
        end
        ret = koukan()
        break if ret < 0
        $suma[ret] += 1
        $sum -= $aa[ret]
    end
end
puts $suma.join(" ")
puts $sum


Vasya's bicycle chain drive consists of two parts: n stars are attached to the pedal axle, m stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal rotation.We know that the i-th star on the pedal axle has ai (0 < a1 < a2 < ... < an) teeth, and the j-th star on the rear wheel axle has bj (0 < b1 < b2 < ... < bm) teeth. Any pair (i, j) (1 ≤ i ≤ n; 1 ≤ j ≤ m) is called a gear and sets the indexes of stars to which the chain is currently attached. Gear (i, j) has a gear ratio, equal to the value .Since Vasya likes integers, he wants to find such gears (i, j), that their ratios are integers. On the other hand, Vasya likes fast driving, so among all "integer" gears (i, j) he wants to choose a gear with the maximum ratio. Help him to find the number of such gears.In the problem, fraction  denotes division in real numbers, that is, no rounding is performed.

The first input line contains integer n (1 ≤ n ≤ 50) — the number of stars on the bicycle's pedal axle. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 104) in the order of strict increasing. The third input line contains integer m (1 ≤ m ≤ 50) — the number of stars on the rear wheel axle. The fourth line contains m integers b1, b2, ..., bm (1 ≤ bi ≤ 104) in the order of strict increasing. It is guaranteed that there exists at least one gear (i, j), that its gear ratio is an integer. The numbers on the lines are separated by spaces.

Print the number of "integer" gears with the maximum ratio among all "integer" gears.

NoteIn the first sample the maximum "integer" gear ratio equals 3. There are two gears that have such gear ratio. For one of them a1 = 4, b1 = 12, and for the other a2 = 5, b3 = 15.

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

c = b.product(a).map{ |bi,aj| bi*1.0/aj }.select{ |i| i%1 == 0 }
puts c.count c.max


Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves. He now wants to heap up some additional snow drifts, so that he can get from any snow drift to any other one. He asked you to find the minimal number of snow drifts that need to be created.We assume that Bajtek can only heap up snow drifts at integer coordinates.

The first line of input contains a single integer n (1 ≤ n ≤ 100) — the number of snow drifts. Each of the following n lines contains two integers xi and yi (1 ≤ xi, yi ≤ 1000) — the coordinates of the i-th snow drift. Note that the north direction coinсides with the direction of Oy axis, so the east direction coinсides with the direction of the Ox axis. All snow drift's locations are distinct.

Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one.

class Drift
  attr_reader :x, :y
  attr_accessor :zone, :adj
  def initialize(x, y)
    @x = x
    @y = y
    @zone = nil
    @adj = Array.new
  end
end

class Map
  attr_accessor :d, :n
  def initialize
    @d = Array.new
    @n = 0
  end
  def add(x, y)
    d << Drift.new(x, y)
    for i in 0...@n
      if d[i].x == d[@n].x || d[i].y == d[@n].y
        d[i].adj << @n
        d[@n].adj << i
      end
    end
    @n += 1
  end
  def at(n)
    @d[n]
  end
  def dfs(n, z)
    d[n].zone = z
    for i in d[n].adj
      dfs(i, z) if d[i].zone == nil
    end
  end
end

n = gets.to_i
map = Map.new
for i in 0...n
  x, y = gets.split(" ").map(&:to_i)
  map.add(x, y)
end
z = 0
for i in 0...map.n
  if map.at(i).zone == nil
    map.dfs(i, z)
    z += 1
  end
end
print z-1


Peter likes to travel by train. He likes it so much that on the train he falls asleep. Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the window and noticed that every railway station has a flag of a particular colour.The boy started to memorize the order of the flags' colours that he had seen. But soon he fell asleep again. Unfortunately, he didn't sleep long, he woke up and went on memorizing the colours. Then he fell asleep again, and that time he slept till the end of the journey.At the station he told his parents about what he was doing, and wrote two sequences of the colours that he had seen before and after his sleep, respectively.Peter's parents know that their son likes to fantasize. They give you the list of the flags' colours at the stations that the train passes sequentially on the way from A to B, and ask you to find out if Peter could see those sequences on the way from A to B, or from B to A. Remember, please, that Peter had two periods of wakefulness.Peter's parents put lowercase Latin letters for colours. The same letter stands for the same colour, different letters — for different colours.

The input data contains three lines. The first line contains a non-empty string, whose length does not exceed 105, the string consists of lowercase Latin letters — the flags' colours at the stations on the way from A to B. On the way from B to A the train passes the same stations, but in reverse order.  The second line contains the sequence, written by Peter during the first period of wakefulness. The third line contains the sequence, written during the second period of wakefulness. Both sequences are non-empty, consist of lowercase Latin letters, and the length of each does not exceed 100 letters. Each of the sequences is written in chronological order.

Output one of the four words without inverted commas:    «forward» — if Peter could see such sequences only on the way from A to B;  «backward» — if Peter could see such sequences on the way from B to A;  «both» — if Peter could see such sequences both on the way from A to B, and on the way from B to A;  «fantasy» — if Peter could not see such sequences.

NoteIt is assumed that the train moves all the time, so one flag cannot be seen twice. There are no flags at stations A and B.

a = gets.chomp
b = a.reverse

f = gets.chomp
s = gets.chomp

if (k = a.index(f)) && a.index(s,k+f.size) then
    n = "forward"
else
    n = 0
end

if (k = b.index(f)) && b.index(s,k+f.size) then
    if n == 0 then
        n = "backward"
    else
        n = "both"
    end
else
    if n == 0
        n = "fantasy"
    end
end

puts n

[{'input': 'atob\r\na\r\nb\r\n', 'output': ['forward\r\n']}, {'input': 'aaacaaa\r\naca\r\naa\r\n', 'output': ['both\r\n']}, {'input': 'aaa\r\naa\r\naa\r\n', 'output': ['fantasy\r\n']}, {'input': 'astalavista\r\nastla\r\nlavista\r\n', 'output': ['fantasy\r\n']}, {'input': 'abacabadabacaba\r\nabacaba\r\nabacaba\r\n', 'output': ['both\r\n']}, {'input': 'a\r\na\r\na\r\n', 'output': ['fantasy\r\n']}, {'input': 'ab\r\nb\r\na\r\n', 'output': ['backward\r\n']}, {'input': 'aaa\r\naaaa\r\naaaa\r\n', 'output': ['fantasy\r\n']}, {'input': 'bbabbbbababbaabaabaa\r\nabb\r\nbaab\r\n', 'output': ['forward\r\n']}, {'input': 'bbbbbbbbbbbbbbbbbbbbbbbbb\r\nbbbb\r\nbbbbb\r\n', 'output': ['both\r\n']}, {'input': 'babaabababaaaababaabababaabababababababbababbbabbaabababaababbaabbababaababaaabababaabbaababaaababaa\r\nabaabababaa\r\nabaabbaa\r\n', 'output': ['forward\r\n']}, {'input': 'bbbbbbbbbbbbbbbbbbbbbbbbb\r\nbbbb\r\nbbbbb\r\n', 'output': ['both\r\n']}, {'input': 'aababaaababaabbaabababaaababaabababbaabbabaabababaabbabbbababbababababababaabababaababaaaabababaabab\r\nabaabababaa\r\nabaabbaa\r\n', 'output': ['backward\r\n']}, {'input': 'aaaa\r\naaa\r\naa\r\n', 'output': ['fantasy\r\n']}, {'input': 'zzzz\r\nzz\r\nzzz\r\n', 'output': ['fantasy\r\n']}, {'input': 'zzzz\r\nzzzz\r\nzzzz\r\n', 'output': ['fantasy\r\n']}, {'input': 'zzzz\r\nzz\r\nzz\r\n', 'output': ['both\r\n']}, {'input': 'aabaa\r\naab\r\nbaa\r\n', 'output': ['fantasy\r\n']}, {'input': 'aabaab\r\naba\r\nab\r\n', 'output': ['forward\r\n']}, {'input': 'aab\r\nb\r\naa\r\n', 'output': ['backward\r\n']}, {'input': 'abacaba\r\naca\r\nba\r\n', 'output': ['both\r\n']}]


And again a misfortune fell on Poor Student. He is being late for an exam.Having rushed to a bus stop that is in point (0, 0), he got on a minibus and they drove along a straight line, parallel to axis OX, in the direction of increasing x.Poor Student knows the following:   during one run the minibus makes n stops, the i-th stop is in point (xi, 0)  coordinates of all the stops are different  the minibus drives at a constant speed, equal to vb  it can be assumed the passengers get on and off the minibus at a bus stop momentarily  Student can get off the minibus only at a bus stop  Student will have to get off the minibus at a terminal stop, if he does not get off earlier  the University, where the exam will be held, is in point (xu, yu)  Student can run from a bus stop to the University at a constant speed vs as long as needed  a distance between two points can be calculated according to the following formula:   Student is already on the minibus, so, he cannot get off at the first bus stop Poor Student wants to get to the University as soon as possible. Help him to choose the bus stop, where he should get off. If such bus stops are multiple, choose the bus stop closest to the University.

The first line contains three integer numbers: 2 ≤ n ≤ 100, 1 ≤ vb, vs ≤ 1000. The second line contains n non-negative integers in ascending order: coordinates xi of the bus stop with index i. It is guaranteed that x1 equals to zero, and xn ≤ 105. The third line contains the coordinates of the University, integers xu and yu, not exceeding 105 in absolute value.

In the only line output the answer to the problem — index of the optimum bus stop.

NoteAs you know, students are a special sort of people, and minibuses usually do not hurry. That's why you should not be surprised, if Student's speed is higher than the speed of the minibus.

n,vb,vs = gets.chomp.split(/ /).map!{|x| x.to_i}
ar = gets.chomp.split(/ /).map!{|x| x.to_i}
xu,yu = gets.chomp.split(/ /).map!{|x| x.to_i}

mint = 0
mind = 0
idx = 0
for i in 1..n-1
	wk = (ar[i]-xu).abs
	wkt = ar[i].to_f/vb+Math.sqrt(wk*wk + yu*yu)/vs
	if idx == 0 || mint > wkt
		mint = wkt
		mind = wk
		idx = i+1
	elsif mint == wkt
		if mind > wk
			mint = wkt
			mind = wk
			idx = i+1
		end
	end
end
puts idx


A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself.The total income A of his kingdom during 0-th year is known, as well as the total income B during n-th year (these numbers can be negative — it means that there was a loss in the correspondent year). King wants to show financial stability. To do this, he needs to find common coefficient X — the coefficient of income growth during one year. This coefficient should satisfy the equation:A·Xn = B.Surely, the king is not going to do this job by himself, and demands you to find such number X.It is necessary to point out that the fractional numbers are not used in kingdom's economy. That's why all input numbers as well as coefficient X must be integers. The number X may be zero or negative.

The input contains three integers A, B, n (|A|, |B| ≤ 1000, 1 ≤ n ≤ 10).

Output the required integer coefficient X, or «No solution», if such a coefficient does not exist or it is fractional. If there are several possible solutions, output any of them.

mas = gets.split(" ")
a = mas[0].to_i
b = mas[1].to_i
n = mas[2].to_i

if (a == 0 && b == 0)
  puts 5
  exit
end

if ((a == 0) || (b % a != 0) || (b / a < 0 && n % 2 == 0))
  puts "No solution"
  exit
end

result = ((b/a).abs)**(1.0/n)

# /b/erd
if (result - result.round).abs < 0.000000001
  if (b/a < 0)
    print "-"
  end
  print result.round.to_s.split(".")[0]
else
  puts "No solution"
end


In a strategic computer game "Settlers II" one has to build defense structures to expand and protect the territory. Let's take one of these buildings. At the moment the defense structure accommodates exactly n soldiers. Within this task we can assume that the number of soldiers in the defense structure won't either increase or decrease.Every soldier has a rank — some natural number from 1 to k. 1 stands for a private and k stands for a general. The higher the rank of the soldier is, the better he fights. Therefore, the player profits from having the soldiers of the highest possible rank.To increase the ranks of soldiers they need to train. But the soldiers won't train for free, and each training session requires one golden coin. On each training session all the n soldiers are present.At the end of each training session the soldiers' ranks increase as follows. First all the soldiers are divided into groups with the same rank, so that the least possible number of groups is formed. Then, within each of the groups where the soldiers below the rank k are present, exactly one soldier increases his rank by one.You know the ranks of all n soldiers at the moment. Determine the number of golden coins that are needed to increase the ranks of all the soldiers to the rank k.

The first line contains two integers n and k (1 ≤ n, k ≤ 100). They represent the number of soldiers and the number of different ranks correspondingly. The second line contains n numbers in the non-decreasing order. The i-th of them, ai, represents the rank of the i-th soldier in the defense building (1 ≤ i ≤ n, 1 ≤ ai ≤ k).

Print a single integer — the number of golden coins needed to raise all the soldiers to the maximal rank.

NoteIn the first example the ranks will be raised in the following manner:1 2 2 3  →  2 2 3 4  →  2 3 4 4  →  3 4 4 4  →  4 4 4 4Thus totals to 4 training sessions that require 4 golden coins.

k=gets.split[1].to_i
a=gets.split.map(&:to_i)

ranks=Array.new(104,0)
a.each{|i| ranks[i]+=1}
ans=0
n=a.length
loop do
        if ranks[k]==n then
                puts ans
                exit
        end
        next_rank=Array.new(104,0)
        1.upto(k-1){|a|
                next_rank[a]+=[ranks[a]-1,0].max
                next_rank[a+1]+=[ranks[a],1].min
        }
        next_rank[k]+=ranks[k]
        ranks=next_rank
        ans+=1
end


The Berland Armed Forces System consists of n ranks that are numbered using natural numbers from 1 to n, where 1 is the lowest rank and n is the highest rank.One needs exactly di years to rise from rank i to rank i + 1. Reaching a certain rank i having not reached all the previous i - 1 ranks is impossible.Vasya has just reached a new rank of a, but he dreams of holding the rank of b. Find for how many more years Vasya should serve in the army until he can finally realize his dream.

The first input line contains an integer n (2 ≤ n ≤ 100). The second line contains n - 1 integers di (1 ≤ di ≤ 100). The third input line contains two integers a and b (1 ≤ a < b ≤ n). The numbers on the lines are space-separated.

Print the single number which is the number of years that Vasya needs to rise from rank a to rank b.

n = gets.to_i
ar = gets.split(' ',n-1).map(&:to_i).insert(0,0)
a, b = gets.split(' ').map(&:to_i)
puts ar[a...b].inject(:+)


The blinds are known to consist of opaque horizontal stripes that can be rotated thus regulating the amount of light flowing in the room. There are n blind stripes with the width of 1 in the factory warehouse for blind production. The problem is that all of them are spare details from different orders, that is, they may not have the same length (it is even possible for them to have different lengths)Every stripe can be cut into two or more parts. The cuttings are made perpendicularly to the side along which the length is measured. Thus the cuttings do not change the width of a stripe but each of the resulting pieces has a lesser length (the sum of which is equal to the length of the initial stripe)After all the cuttings the blinds are constructed through consecutive joining of several parts, similar in length, along sides, along which length is measured. Also, apart from the resulting pieces an initial stripe can be used as a blind if it hasn't been cut. It is forbidden to construct blinds in any other way.Thus, if the blinds consist of k pieces each d in length, then they are of form of a rectangle of k × d bourlemeters. Your task is to find for what window possessing the largest possible area the blinds can be made from the given stripes if on technical grounds it is forbidden to use pieces shorter than l bourlemeter. The window is of form of a rectangle with side lengths as positive integers.

The first output line contains two space-separated integers n and l (1 ≤ n, l ≤ 100). They are the number of stripes in the warehouse and the minimal acceptable length of a blind stripe in bourlemeters. The second line contains space-separated n integers ai. They are the lengths of initial stripes in bourlemeters (1 ≤ ai ≤ 100).

Print the single number — the maximal area of the window in square bourlemeters that can be completely covered. If no window with a positive area that can be covered completely without breaking any of the given rules exist, then print the single number 0.

NoteIn the first sample test the required window is 2 × 4 in size and the blinds for it consist of 4 parts, each 2 bourlemeters long. One of the parts is the initial stripe with the length of 2, the other one is a part of a cut stripe with the length of 3 and the two remaining stripes are parts of a stripe with the length of 4 cut in halves.

n,l = gets.chomp.split(/ /).map!{|x| x.to_i}
ar = gets.chomp.split(/ /).map!{|x| x.to_i}
ar.sort!
ar.reverse!
maxsum = 0
for j in l..ar[0]
	sum = 0
	for i in 0..ar.length-1
		if ar[i] >= j
			dv = ar[i] / j
			sum += dv * j
		end
	end
	maxsum = sum if maxsum < sum
end
puts maxsum


Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading — he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text.

The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 и s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading.

If Vasya can write the given anonymous letter, print YES, otherwise print NO

Instead of dogging Your footsteps it disappears but you dont notice anything
where is your dog

Instead of dogging Your footsteps it disappears but you dont notice anything
Your dog is upstears

Instead of dogging your footsteps it disappears but you dont notice anything
Your dog is upstears

str=gets
str2=gets

symbols=str2.scan(/(\w)/)
r=true
symbols.each{|i|
	if str=~/#{i}/
		str=str.sub(/#{i}/,"")
#		print "Found ",i,"\nstr=",str,"\n"
	else
#		print "Not found ",i,"\nstr=",str,"\n"
		r=false
		break
	end
}
if r then print "YES"
else print "NO"
end

[{'input': 'Instead of dogging Your footsteps it disappears but you dont notice anything\r\nwhere is your dog\r\n', 'output': ['NO\r\n']}, {'input': 'Instead of dogging Your footsteps it disappears but you dont notice anything\r\nYour dog is upstears\r\n', 'output': ['YES\r\n']}, {'input': 'Instead of dogging your footsteps it disappears but you dont notice anything\r\nYour dog is upstears\r\n', 'output': ['NO\r\n']}, {'input': 'abcdefg hijk\r\nk j i h g f e d c b a\r\n', 'output': ['YES\r\n']}, {'input': 'HpOKgo\r\neAtAVB\r\n', 'output': ['NO\r\n']}, {'input': 'GRZGc\r\nLPzD\r\n', 'output': ['NO\r\n']}, {'input': 'GtPXu\r\nd\r\n', 'output': ['NO\r\n']}, {'input': 'FVF\r\nr \r\n', 'output': ['NO\r\n']}, {'input': 'HpOKgo\r\nogK\r\n', 'output': ['YES\r\n']}, {'input': 'GRZGc\r\nZG\r\n', 'output': ['YES\r\n']}, {'input': 'HpOKgoueAtAVBdGffvQheJDejNDHhhwyKJisugiRAH OseK yUwqPPNuThUxTfthqIUeb wS jChGOdFDarNrKRT  MlwKecxWNoKEeD BbiHAruE XMlvKYVsJGPP\r\nAHN  XvoaNwV  AVBKwKjr u      U K wKE D K   Jy KiHsR h d W  Js IHyMPK Br iSqe  E fDA   g H\r\n', 'output': ['YES\r\n']}, {'input': 'GRZGcsLPzDrCSXhhNTaibJqVphhjbcPoZhCDUlzAbDnRWjHvxLKtpGiFWiGbfeDxBwCrdJmJGCGv GebAOinUsFrlqKTILOmxrFjSpEoVGoTdSSstJWVgMLKMPettxHASaQZNdOIObcTxtF qTHWBdNIKwj\r\nWqrxze Ji x q aT GllLrRV jMpGiMDTwwS JDsPGpAZKACmsFCOS CD Sj  bCDgKF  jJxa RddtLFAi VGLHH SecObzG q  hPF \r\n', 'output': ['YES\r\n']}, {'input': 'GtPXuwdAxNhODQbjRslDDKciOALJrCifTjDQurQEBeFUUSZWwCZQPdYwZkYbrduMijFjgodAOrKIuUKwSXageZuOWMIhAMexyLRzFuzuXqBDTEaWMzVdbzhxDGSJC SsIYuYILwpiwwcObEHWpFvHeBkWYNitqYrxqgHReHcKnHbtjcWZuaxPBVPb\r\nTQIKyqFaewOkY lZUOOuxEw EwuKcArxRQGFYkvVWIAe SuanPeHuDjquurJu aSxwgOSw jYMwjxItNUUArQjO BIujAhSwttLWp\r\n', 'output': ['YES\r\n']}, {'input': 'FVFSr unvtXbpKWF vPaAgNaoTqklzVqiGYcUcBIcattzBrRuNSnKUtmdGKbjcE\r\nUzrU K  an GFGR        Wc zt iBa     P c    T K v p     V In   b           B   c\r\n', 'output': ['YES\r\n']}, {'input': 'lSwjnYLYtDNIZjxHiTawdh ntSzggZogcIZTuiTMWVgwyloMtEhqkrOxgIcFvwvsboXUPILPIymFAEXnhApewJXJNtFyZ\r\nAoxe  jWZ u  yImg  o AZ FNI w lpj  tNhT g y  ZYcb rc J    w Dlv\r\n', 'output': ['YES\r\n']}, {'input': 'kvlekcdJqODUKdsJlXkRaileTmdGwUHWWgvgUokQxRzzbpFnswvNKiDnjfOFGvFcnaaiRnBGQmqoPxDHepgYasLhzjDgmvaFfVNEcSPVQCJKAbSyTGpXsAjIHr\r\nGjzUllNaGGKXUdYmDFpqFAKIwvTpjmqnyswWRTnxlBnavAGvavxJemrjvRJc\r\n', 'output': ['YES\r\n']}, {'input': 'kWbvhgvvoYOhwXmgTwOSCDXrtFHhqwvMlCvsuuAUXMmWaYXiqHplFZZemhgkTuvsUtIaUxtyYauBIpjdbyYxjZ ZkaBPzwqPfqF kCqGRmXvWuabnQognnkvdNDtRUsSUvSzgBuxCMBWJifbxWegsknp\r\nBsH   bWHJD n Ca T xq  PRCv  tatn Wjy sm  I q s WCjFqdWe  t W XUs  Do  eb Pfh ii  hTbF  O Fll\r\n', 'output': ['YES\r\n']}, {'input': 'OTmLdkMhmDEOMQMiW ZpzEIjyElHFrNCfFQDp SZyoZaEIUIpyCHfwOUqiSkKtFHggrTBGkqfOxkChPztmPrsHoxVwAdrxbZLKxPXHlMnrkgMgiaHFopiFFiUEtKwCjpJtwdwkbJCgA bxeDIscFdmHQJLAMNhWlrZisQrHQpvbALWTwpf jnx\r\nDbZwrQbydCdkJMCrftiwtPFfpMiwwrfIrKidEChKECxQUBVUEfFirbGWiLkFQkdJiFtkrtkbIAEXCEDkwLpK\r\n', 'output': ['YES\r\n']}, {'input': 'NwcGaIeSkOva\r\naIa\r\n', 'output': ['YES\r\n']}, {'input': 'gSrAcVYgAdbdayzbKGhIzLDjyznLRIJH KyvilAaEddmgkBPCNzpmPNeGEbmmpAyHvUSoPvnaORrPUuafpReEGoDOQsAYnUHYfBqhdcopQfxJuGXgKnbdVMQNhJYkyjiJDKlShqBTtnnDQQzEijOMcYRGMgPGVhfIReYennKBLwDTVvcHMIHMgVpJkvzTrezxqS\r\nHJerIVvRyfrPgAQMTI AqGNO mQDfDwQHKgeeYmuRmozKHILvehMPOJNMRtPTAfvKvsoGKi xHEeKqDAYmQJPUXRJbIbHrgVOMGMTdvYiLui\r\n', 'output': ['YES\r\n']}, {'input': 'ReB hksbHqQXxUgpvoNK bFqmNVCEiOyKdKcAJQRkpeohpfuqZabvrLfmpZOMcfyFBJGZwVMxiUPP pbZZtJjxhEwvrAba\r\nJTCpQnIViIGIdQtLnmkVzmcbBZR CoxAdTtWSYpbOglDFifqIVQ vfGKGtLpxpJHiHSWCMeRcrVOXBGBhoEnVhNTPWGTOErNtSvokcGdgZXbgTEtISUyTwaXUEIlJMmutsdCbiyrPZPJyRdOjnSuAGttLy\r\n', 'output': ['NO\r\n']}, {'input': 'hrLzRegCuDGxTrhDgVvM KowwyYuXGzIpcXdSMgeQVfVOtJZdkhNYSegwFWWoPqcZoeapbQnyCtojgkcyezUNHGGIZrhzsKrvvcrtokIdcnqXXkCNKjrOjrnEAKBNxyDdiMVeyLvXxUYMZQRFdlcdlcxzKTeYzBlmpNiwWbNAAhWkMoGpRxkCuyqkzXdKWwGH\r\nJESKDOfnFdxPvUOCkrgSBEPQHJtJHzuNGstRbTCcchRWJvCcveSEAtwtOmZZiW\r\n', 'output': ['NO\r\n']}, {'input': 'yDBxCtUygQwWqONxQCcuAvVCkMGlqgC zvkfEkwqbhMCQxnkwQIUhucCbVUyOBUcXvTNEGriTBwMDMfdsPZgWRgIUDqM\r\neptVnORTTyixxmWIBpSTEwOXqGZllBgSxPenYCDlFwckJlWsoVwWLAIbPOmFqcKcTcoQqahetl KLfVSyaLVebzsGwPSVbtQAeUdZAaJtfxlCEvvaRhLlVvRJhKat IaB awdqcDlrrhTbRxjEbzGwcdmdavkhcjHjzmwbxAgw\r\n', 'output': ['NO\r\n']}, {'input': 'jlMwnnotSdlQMluKWkJwAeCetcqbIEnKeNyLWoKCGONDRBQOjbkGpUvDlmSFUJ bWhohqmmIUWTlDsvelUArAcZJBipMDwUvRfBsYzMdQnPDPAuBaeJmAxVKwUMJrwMDxNtlrtAowVWqWiwFGtmquZAcrpFsLHCrvMSMMlvQUqypAihQWrFMNoaqfs IBg\r\nNzeWQ bafrmDsYlpNHSGTBBgPl WIcuNhyNaNOEFvL\r\n', 'output': ['NO\r\n']}, {'input': 'zyWvXBcUZqGqjHwZHQryBtFliLYnweXAoMKNpLaunaOlzaauWmLtywsEvWPiwxJapocAFRMjrqWJXYqfKEbBKnzLO\r\npsbi bsXpSeJaCkIuPWfSRADXdIClxcDCowwJzGCDTyAl\r\n', 'output': ['NO\r\n']}, {'input': 'kKhuIwRPLCwPFfcnsyCfBdnsraGeOCcLTfXuGjqFSGPSAeDZJSS bXKFanNqWjpFnvRpWxHJspvisDlADJBioxXNbVoXeUedoPcNEpUyEeYxdJXhGzFAmpAiHotSVwbZQsuWjIVhVaEGgqbZHIoDpiEmjTtFylCwCkWWzUOoUfOHxEZvDwNpXhBWamHn\r\nK VpJjGhNbwCRhcfmNGVjewBFpEmPlIKeTuWiukDtEWpjgqciqglkyNfWrBLbGAKvlNWxaUelJmSlSoakSpRzePvJsshOsTYrMPXdxKpaShjyVIXGhRIAdtiGpNwtiRmGTBZhkJqIMdxMHX RMxCMYcWjcjhtCHyFnCvjjezGbkRDRiVxkbh\r\n', 'output': ['NO\r\n']}, {'input': 'AXssNpFKyQmJcBdBdfkhhMUzfqJVgcLBddkwtnFSzSRUCjiDcdtmkzIGkCKSxWUEGhmHmciktJyGMkgCductyHx\r\nI nYhmJfPnvoKUiXYUBIPIcxNYTtvwPUoXERZvY ahlDpQFNMmVZqEBiYqYlHNqcpSCmhFczBlOAhsYFeqMGfqL EJsDNOgwoJfBzqijKOFcYQ\r\n', 'output': ['NO\r\n']}, {'input': 'lkhrzDZmkdbjzYKPNMRkiwCFoZsMzBQMnxxdKKVJezSBjnLjPpUYtabcPTIaDJeDEobbWHdKOdVfMQwDXzDDcSrwVenDEYpMqfiOQ xSsqApWnAMoyhQXCKFzHvvzvUvkWwmwZrvZz\r\nsUzGspYpRFsHRbRgTQuCBgnFgPkisTUfFNwyEEWWRiweWWgjRkVQxgTwxOzdsOwfrGIH O gCXpzvHzfItuEHaihmugEyymSJIogYwX qAwcwIItidfnzZDhZgQHi eRjMAeVkJHceDZuJkmxGowOsmcGYYvk Ajtgi TxwihvjLViNZjvscTWvsaQUelTSivLShhEl\r\n', 'output': ['NO\r\n']}, {'input': 'BRsVjyNhrqRHVwrJzuzRigEhdpbDmaACSPfed\r\nlWqKTjlrqOCUbgBBZdZDGCeQJDXawPnnDkQdZDgwrEQk\r\n', 'output': ['NO\r\n']}, {'input': 'KRmINuyBYPwiTsdlyiNVuylToysJKmOpcLovAtwGPqrgFJQNAYvuAiyQRkeFMECVZvkDEmTauXlyjAaYRnTJXORMZRnTakBaUzSelMilejySDIZjQjzcOIrwXdvDvpeRIkoBgreyFXIyyIZutjiEBtwrmzQtPVUhvvdEtDMbXjBpoPVjGdM EXTAK JbCnw\r\nXZZqlJvzKKtvdNlzFPDTYxidqlsgufVzyEmO FZuLQ vVQsJESNviUCovCK NwwlbxsmPtOJNmAonCqrOZ bZ LVKAsQGmoLnYjeekvEIECFk\r\n', 'output': ['NO\r\n']}]