{"nl": {"description": "Mahmoud and Ehab play a game called the even-odd game. Ehab chooses his favorite integer n and then they take turns, starting from Mahmoud. In each player's turn, he has to choose an integer a and subtract it from n such that: 1\u2009\u2264\u2009a\u2009\u2264\u2009n. If it's Mahmoud's turn, a has to be even, but if it's Ehab's turn, a has to be odd. If the current player can't choose any number satisfying the conditions, he loses. Can you determine the winner if they both play optimally?", "input_spec": "The only line contains an integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009109), the number at the beginning of the game.", "output_spec": "Output \"Mahmoud\" (without quotes) if Mahmoud wins and \"Ehab\" (without quotes) otherwise.", "sample_inputs": ["1", "2"], "sample_outputs": ["Ehab", "Mahmoud"], "notes": "NoteIn the first sample, Mahmoud can't choose any integer a initially because there is no positive even integer less than or equal to 1 so Ehab wins.In the second sample, Mahmoud has to choose a\u2009=\u20092 and subtract it from n. It's Ehab's turn and n\u2009=\u20090. There is no positive odd integer less than or equal to 0 so Mahmoud wins."}, "positive_code": [{"source_code": "n = gets.to_i\nif n % 2 == 1\n puts \"Ehab\"\nelse\n puts \"Mahmoud\"\nend\n"}, {"source_code": "#bismillahir rahmanir rahim \n\nn = gets.to_i \n\nif n%2==0 \n puts \"Mahmoud\" \nelse \n puts \"Ehab\" \nend "}, {"source_code": "puts [:Mahmoud,:Ehab][gets.to_i%2]"}, {"source_code": "n = gets.chomp.to_i\n\nif n % 2 == 0\n print \"Mahmoud\"\nelse\n print \"Ehab\"\nend\n"}, {"source_code": "# https://codeforces.com/problemset/problem/959/A\n\nnumber = gets.to_i\n\nif number % 2 == 0\n puts \"Mahmoud\"\nelse\n puts \"Ehab\"\nend\n"}, {"source_code": "t = gets.chomp.to_i\n\ncase t%2==0\n when true\n puts \"Mahmoud\"\n when false\n puts \"Ehab\"\nend\n"}, {"source_code": "n = gets.chomp.to_i\n\nif n.odd?\n puts \"Ehab\"\nelse\n puts \"Mahmoud\"\nend"}, {"source_code": "puts gets.to_i.odd? ? \"Ehab\" : \"Mahmoud\""}, {"source_code": "n = gets.to_i\nputs n.odd? ? 'Ehab' : 'Mahmoud'"}, {"source_code": "##Please tell me this problmem can't be solved with this please\n\ndef winner(n)\n\treturn \"Ehab\" if n % 2 != 0\n\treturn \"Mahmoud\" if n % 2 == 0\nend\n\nn = gets.chomp.to_i\nputs(winner(n))"}, {"source_code": "n = gets.to_i\nputs [:Mahmoud, :Ehab][n & 1]\n"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\nn = gets.to_i\n\n# picking -> Mahmoud picks 'a' and it is even.\n# -> Ehab picks 'a' and it is odd.\n# -> repeat until someone wins\n\n# optimal play\n# no fun\n\nputs \"Ehab\" if n.odd?\nputs \"Mahmoud\" if n.even?"}, {"source_code": "puts gets.chomp.to_i.even? ? \"Mahmoud\" : \"Ehab\""}, {"source_code": "n = Integer(gets.chomp)\nif n%2 == 0\n puts \"Mahmoud\"\nelse \n puts \"Ehab\"\nend"}, {"source_code": "n = gets.to_i\nputs(n%2 == 0 ? 'Mahmoud' : 'Ehab')\n\n"}, {"source_code": "puts gets.to_i.even? ? 'Mahmoud' : 'Ehab'\n"}, {"source_code": "puts (gets.to_i&1)==1?\"Ehab\":\"Mahmoud\"\n"}], "negative_code": [{"source_code": "n = gets.to_i\nputs n == 1 ? \"Ehab\" : \"Mahmoud\""}, {"source_code": "n = gets.chomp\nif n%2 == 0\n puts \"Mahmoud\"\nelse\n puts \"Ehab\"\nend"}, {"source_code": "puts (gets.to_i&1)?\"Ehab\":\"Mahmoud\"\n"}], "src_uid": "5e74750f44142624e6da41d4b35beb9a"} {"nl": {"description": "Let's denote d(n) as the number of divisors of a positive integer n. You are given three integers a, b and c. Your task is to calculate the following sum:Find the sum modulo 1073741824 (230).", "input_spec": "The first line contains three space-separated integers a, b and c (1\u2009\u2264\u2009a,\u2009b,\u2009c\u2009\u2264\u20092000).", "output_spec": "Print a single integer \u2014 the required sum modulo 1073741824 (230).", "sample_inputs": ["2 2 2", "4 4 4", "10 10 10"], "sample_outputs": ["20", "328", "11536"], "notes": "NoteFor the first example. d(1\u00b71\u00b71)\u2009=\u2009d(1)\u2009=\u20091; d(1\u00b71\u00b72)\u2009=\u2009d(2)\u2009=\u20092; d(1\u00b72\u00b71)\u2009=\u2009d(2)\u2009=\u20092; d(1\u00b72\u00b72)\u2009=\u2009d(4)\u2009=\u20093; d(2\u00b71\u00b71)\u2009=\u2009d(2)\u2009=\u20092; d(2\u00b71\u00b72)\u2009=\u2009d(4)\u2009=\u20093; d(2\u00b72\u00b71)\u2009=\u2009d(4)\u2009=\u20093; d(2\u00b72\u00b72)\u2009=\u2009d(8)\u2009=\u20094. So the result is 1\u2009+\u20092\u2009+\u20092\u2009+\u20093\u2009+\u20092\u2009+\u20093\u2009+\u20093\u2009+\u20094\u2009=\u200920."}, "positive_code": [{"source_code": "a, b, c = gets.split.map &:to_i\n\n\n\ndef solve(a,b,c)\n ar = Array.new(1000001) { 0 }\n ans = 0\n mod = 1073741824\n for i in 1..a do\n for j in 1..b do\n for k in 1..c do\n d = i*j*k\n ans += ret_div(ar, d, mod)\n end\n end\n end\n puts ans\nend\n\ndef ret_div(ar, el, mod)\n return ar[el] if ar[el]>0\n j = 1\n div = 0\n while j*j<=el do\n if el%j == 0\n div+=2\n end\n j+=1\n\n end\n div-=1 if (j-1)*(j-1) == el\n ar[el] = div % mod\n ar[el]\nend\n\nsolve a, b ,c"}, {"source_code": "a, b, c = gets.split.map &:to_i\n\n\ndef solve(a,b,c)\n ar = Array.new(1000001) { 0 }\n ans = 0\n mod = 1073741824\n for i in 1..a do\n for j in 1..b do\n for k in 1..c do\n d = i*j*k\n ans += ret_div(ar, d, mod)\n end\n end\n end\n puts ans\nend\n\ndef ret_div(ar, el, mod)\n return ar[el] if ar[el]>0\n j = 1\n div = 0\n while j*j<=el do\n if el%j == 0\n div+=2\n end\n j+=1\n\n end\n div-=1 if (j-1)*(j-1) == el\n ar[el] = div % mod\n ar[el]\nend\n\nsolve a, b ,c"}], "negative_code": [], "src_uid": "4fdd4027dd9cd688fcc70e1076c9b401"} {"nl": {"description": "Alice and Bob decided to eat some fruit. In the kitchen they found a large bag of oranges and apples. Alice immediately took an orange for herself, Bob took an apple. To make the process of sharing the remaining fruit more fun, the friends decided to play a game. They put multiple cards and on each one they wrote a letter, either 'A', or the letter 'B'. Then they began to remove the cards one by one from left to right, every time they removed a card with the letter 'A', Alice gave Bob all the fruits she had at that moment and took out of the bag as many apples and as many oranges as she had before. Thus the number of oranges and apples Alice had, did not change. If the card had written letter 'B', then Bob did the same, that is, he gave Alice all the fruit that he had, and took from the bag the same set of fruit. After the last card way removed, all the fruit in the bag were over.You know how many oranges and apples was in the bag at first. Your task is to find any sequence of cards that Alice and Bob could have played with.", "input_spec": "The first line of the input contains two integers, x,\u2009y (1\u2009\u2264\u2009x,\u2009y\u2009\u2264\u20091018,\u2009xy\u2009>\u20091) \u2014 the number of oranges and apples that were initially in the bag.", "output_spec": "Print any sequence of cards that would meet the problem conditions as a compressed string of characters 'A' and 'B. That means that you need to replace the segments of identical consecutive characters by the number of repetitions of the characters and the actual character. For example, string AAABAABBB should be replaced by string 3A1B2A3B, but cannot be replaced by 2A1A1B2A3B or by 3AB2A3B. See the samples for clarifications of the output format. The string that you print should consist of at most 106 characters. It is guaranteed that if the answer exists, its compressed representation exists, consisting of at most 106 characters. If there are several possible answers, you are allowed to print any of them. If the sequence of cards that meet the problem statement does not not exist, print a single word Impossible.", "sample_inputs": ["1 4", "2 2", "3 2"], "sample_outputs": ["3B", "Impossible", "1A1B"], "notes": "NoteIn the first sample, if the row contained three cards with letter 'B', then Bob should give one apple to Alice three times. So, in the end of the game Alice has one orange and three apples, and Bob has one apple, in total it is one orange and four apples.In second sample, there is no answer since one card is not enough for game to finish, and two cards will produce at least three apples or three oranges.In the third sample, cards contain letters 'AB', so after removing the first card Bob has one orange and one apple, and after removal of second card Alice has two oranges and one apple. So, in total it is three oranges and two apples."}, "positive_code": [{"source_code": "def run target, left, right, result\n if target[0] == 1\n print (target[1] - 1), 'B'\n puts\n return true\n end\n if target[1] == 1\n print (target[0] - 1), 'A'\n puts\n return true\n end\n if target[0].gcd(target[1]) > 1\n puts \"Impossible\"\n return false\n end\n if (target[0] - target[1]).abs == 1\n result = []\n num = target[0] > target[1] ? target[1] : target[0]\n char = target[0] > target[1] ? 'B' : 'A'\n print 1, (char == 'A' ? 'B' : 'A')\n if num > 1\n print (num - 1), char\n end\n puts\n return true\n end\n while true\n median = [left[0] + right[0], left[1] + right[1]]\n\n if fract_compare(median, target) == 0\n if median[0] != target[0]\n puts \"Impossible\"\n return false\n end\n puts string_compress result\n return true\n end\n\n if median[0] > target[0] || median[1] > target[1]\n puts \"Impossible\"\n return false\n end\n\n if fract_compare(median, target) > 0\n result << 'B'\n right[0] = median[0]\n right[1] = median[1]\n else\n result << 'A'\n left[0] = median[0]\n left[1] = median[1]\n end\n end\nend\n\ndef fract_compare a, b\n return a[0] * b[1] - a[1] * b[0]\nend\n\ndef string_compress s\n current_total = 0\n prev = \"\"\n size = s.size\n result = []\n s.each_with_index do |cur, i|\n if prev == cur\n current_total += 1\n else\n if prev != \"\"\n result << current_total\n result << prev\n end\n current_total = 1\n prev = cur\n end\n if i == (size - 1)\n result << current_total\n result << prev\n end\n end\n return result.join\nend\n\ntarget = gets.chomp.split(\" \").map{ |i| i.to_i }\nleft = [0, 1]\nright = [1, 0]\nresult = []\nrun target, left, right, result\n"}], "negative_code": [{"source_code": "def run target, left, right, result\n median = [left[0] + right[0], left[1] + right[1]]\n\n if fract_compare(median, target) == 0\n if median[0] != target[0]\n puts \"Impossible\"\n return false\n end\n puts string_compress result\n return true\n end\n\n if median[0] > target[0] || median[1] > target[1]\n puts \"Impossible\"\n return false\n end\n\n if fract_compare(median, target) > 0\n result << 'B'\n right[0] = median[0]\n right[1] = median[1]\n else\n result << 'A'\n left[0] = median[0]\n left[1] = median[1]\n end\n\n run target, left, right, result\nend\n\ndef fract_compare a, b\n return (a[0].to_f / a[1]) - (b[0].to_f / b[1])\nend\n\ndef string_compress s\n current_total = 0\n prev = \"\"\n size = s.size\n result = []\n s.each_with_index do |cur, i|\n if prev == cur\n current_total += 1\n else\n if prev != \"\"\n result << current_total\n result << prev\n end\n current_total = 1\n prev = cur\n end\n if i == (size - 1)\n result << current_total\n result << prev\n end\n end\n return result.join\nend\n\ntarget = gets.chomp.split(\" \").map{ |i| i.to_i }\nleft = [0, 1]\nright = [1, 0]\nresult = []\nrun target, left, right, result\n"}, {"source_code": "def run target, left, right, result\n if target[0] == 1\n print (target[1] - 1), 'B'\n puts\n return true\n end\n if target[1] == 1\n print (target[0] - 1), 'A'\n puts\n return true\n end\n if target[0].gcd(target[1]) > 1\n puts \"Imposible\"\n return false\n end\n if (target[0] - target[1]).abs == 1\n result = []\n num = target[0] > target[1] ? target[1] : target[0]\n char = target[0] > target[1] ? 'B' : 'A'\n print 1, (char == 'A' ? 'B' : 'A')\n if num > 1\n print (num - 1), char\n end\n puts\n return true\n end\n while true\n median = [left[0] + right[0], left[1] + right[1]]\n\n if fract_compare(median, target) == 0\n if median[0] != target[0]\n puts \"Impossible\"\n return false\n end\n puts string_compress result\n return true\n end\n\n if median[0] > target[0] || median[1] > target[1]\n puts \"Impossible\"\n return false\n end\n\n if fract_compare(median, target) > 0\n result << 'B'\n right[0] = median[0]\n right[1] = median[1]\n else\n result << 'A'\n left[0] = median[0]\n left[1] = median[1]\n end\n end\nend\n\ndef fract_compare a, b\n return a[0] * b[1] - a[1] * b[0]\nend\n\ndef string_compress s\n current_total = 0\n prev = \"\"\n size = s.size\n result = []\n s.each_with_index do |cur, i|\n if prev == cur\n current_total += 1\n else\n if prev != \"\"\n result << current_total\n result << prev\n end\n current_total = 1\n prev = cur\n end\n if i == (size - 1)\n result << current_total\n result << prev\n end\n end\n return result.join\nend\n\ntarget = gets.chomp.split(\" \").map{ |i| i.to_i }\nleft = [0, 1]\nright = [1, 0]\nresult = []\nrun target, left, right, result\n"}, {"source_code": "def run target, left, right, result\n if (target[0] - target[1]).abs == 1\n result = []\n num = target[0] > target[1] ? target[1] : target[0]\n char = target[0] > target[1] ? 'B' : 'A'\n print 1, (char == 'A' ? 'B' : 'A'), (num - 1)\n (num - 1).times do |i|\n print char\n end\n puts\n return true\n end\n while true\n median = [left[0] + right[0], left[1] + right[1]]\n\n if fract_compare(median, target) == 0\n if median[0] != target[0]\n puts \"Impossible\"\n return false\n end\n puts string_compress result\n return true\n end\n\n if median[0] > target[0] || median[1] > target[1]\n puts \"Impossible\"\n return false\n end\n\n if fract_compare(median, target) > 0\n result << 'B'\n right[0] = median[0]\n right[1] = median[1]\n else\n result << 'A'\n left[0] = median[0]\n left[1] = median[1]\n end\n end\nend\n\ndef fract_compare a, b\n return a[0] * b[1] - a[1] * b[0]\nend\n\ndef string_compress s\n current_total = 0\n prev = \"\"\n size = s.size\n result = []\n s.each_with_index do |cur, i|\n if prev == cur\n current_total += 1\n else\n if prev != \"\"\n result << current_total\n result << prev\n end\n current_total = 1\n prev = cur\n end\n if i == (size - 1)\n result << current_total\n result << prev\n end\n end\n return result.join\nend\n\ntarget = gets.chomp.split(\" \").map{ |i| i.to_i }\nleft = [0, 1]\nright = [1, 0]\nresult = []\nrun target, left, right, result\n"}], "src_uid": "6a9ec3b23bd462353d985e0c0f2f7671"} {"nl": {"description": "HAII HAS A TUXGIMMEH TUXI HAS A FOO ITS 0I HAS A BAR ITS 0I HAS A BAZ ITS 0I HAS A QUZ ITS 1TUX IS NOW A NUMBRIM IN YR LOOP NERFIN YR TUX TIL BOTH SAEM TUX AN 0I HAS A PURGIMMEH PURPUR IS NOW A NUMBRFOO R SUM OF FOO AN PURBAR R SUM OF BAR AN 1BOTH SAEM BIGGR OF PRODUKT OF FOO AN QUZ AN PRODUKT OF BAR BAZ AN PRODUKT OF FOO AN QUZO RLY?YA RLYBAZ R FOOQUZ R BAROICIM OUTTA YR LOOPBAZ IS NOW A NUMBARVISIBLE SMOOSH QUOSHUNT OF BAZ QUZKTHXBYE", "input_spec": "The input contains between 1 and 10 lines, i-th line contains an integer number xi (0\u2009\u2264\u2009xi\u2009\u2264\u20099).", "output_spec": "Output a single real number. The answer is considered to be correct if its absolute or relative error does not exceed 10\u2009-\u20094.", "sample_inputs": ["3\n0\n1\n1"], "sample_outputs": ["0.666667"], "notes": null}, "positive_code": [{"source_code": "nlines = gets.to_i\n\nsum = 0\nmaxavg = 0\nnlines.times do |x|\n sum = sum + gets.to_i\n maxavg = sum.to_f / (x+1) if sum.to_f / (x+1) > maxavg\nend\n\nputs maxavg"}, {"source_code": "f=0;p 1.upto(gets.to_i).map{|r|(f+=gets.to_f)/r}.max\n"}, {"source_code": "foo,bar,baz,quz=0,0,0,1\ngets.to_i.times do\n foo+=gets.to_i\n bar+=1\n if foo*quz>baz*bar\n baz=foo\n quz=bar\n end\nend\nputs '%.6f'%(baz*1.0/quz)"}, {"source_code": "f=0;p 1.upto(gets.to_i).map{|r|(f+=gets.to_f)/r}.max\n"}, {"source_code": "f=0;p 1.upto(gets.to_i).map{|r|(f+=gets.to_f)/r}.max\n"}, {"source_code": "tux=gets\nfoo=0\nbar=0\nbaz=0\nquz=1\ntux=tux.to_i\nwhile tux>0\n tux-=1\n pur=gets\n pur=pur.to_i\n foo=foo+pur\n bar=bar+1\n if [foo * quz, bar*baz].max == foo*quz then\n baz=foo\n quz=bar\n end\nend\nputs 1.0*baz/quz\n"}, {"source_code": "#!/usr/bin/ruby\nr=w=0.0\ngets.to_i.times{|i|\n\tw+=1 if gets.to_i==1\n\tr=[r,w/-~i].max\n}\np r"}, {"source_code": "#!/usr/bin/ruby\n\ntux = gets.to_i\nfoo = 0\nbar = 0\nbaz = 0\nquz = 1\nit = false\ntux.times do\n pur = gets.to_i\n foo = foo + pur\n bar = bar + 1\n it = [foo*quz, bar*baz].max == foo*quz\n if it\n baz = foo\n quz = bar\n end\nend\n\nprintf(\"%.10f\\n\", baz/quz.to_f)\n"}, {"source_code": "f=0;p 1.upto(gets.to_i).map{|r|(f+=gets.to_f)/r}.max\n"}, {"source_code": "tux = gets.to_i\nfoo = 0\nbar = 0\nbaz = 0\nquz = 1\n\ntux.downto(1) do\n pur = gets.to_i\n foo = foo+pur\n bar = bar+1\n if foo*quz >= bar*baz\n baz = foo\n\tquz = bar\n end\nend\n\nbaz = baz.to_f\n\nputs baz/quz\n"}, {"source_code": "f=0;p 1.upto(gets.to_i).map{|r|(f+=gets.to_f)/r}.max\n"}, {"source_code": "f=r=z=0;q=1;(1..gets.to_i).each{f+=gets.to_i;r+=1;f*q= bar*baz \n baz = foo\n quz = bar\n end\nend\n\nputs sprintf(\"%0.6f\", baz/quz.to_f)"}, {"source_code": "f=0;p 1.upto(gets.to_i).map{|r|(f+=gets.to_f)/r}.max\n"}, {"source_code": "f=0;p 1.upto(gets.to_i).map{|r|(f+=gets.to_f)/r}.max\n"}, {"source_code": "tux = gets\nfoo = 0\nbar = 0\nbaz = 0\nquz = 1\ntux = tux.to_i\nfor i in (tux.downto 1) do\n\tpur = gets.to_f\n\tfoo = foo+pur\n\tbar = bar+1\n\tif([foo*quz, bar*baz].max == (foo*quz))\n\t\tbaz = foo\n\t\tquz = bar\n\tend\nend\nbaz = baz.to_f\nputs baz/quz\n"}, {"source_code": "f=0;p 1.upto(gets.to_i).map{|r|(f+=gets.to_f)/r}.max\n"}, {"source_code": "def max(a,b)\n a > b ? a : b\nend\n\nTUX = gets.to_i\nFOO = 0\nBAR = 0\nBAZ = 0\nQUZ = 1\nTUX.times {\n PUR = gets.to_i\n FOO = FOO + PUR\n BAR = BAR + 1\n if max(FOO * QUZ, BAR * BAZ) == FOO * QUZ then\n BAZ = FOO\n QUZ = BAR\n end\n}\np BAZ * 1.0 / QUZ\n"}, {"source_code": "foo = 0\nbar = 0\nbaz = 0\nquz = 1\ntux = gets.to_i\nuntil tux == 0\n pur = gets.to_i\n foo = foo + pur\n bar += 1\n it = [foo * quz, bar * baz].max == foo * quz\n if it\n baz = foo\n quz = bar\n end\n tux -= 1\nend\nputs baz.to_f/quz"}, {"source_code": "foo = 0\nbar = 0\nbaz = 0\nquz = 1\ntux = gets.to_i\nwhile tux!=0\npur =gets.to_i\nfoo = foo + pur\nbar = bar + 1\nif bar*baz= bar * baz && bar * baz >= foo * quz\n baz = foo\n quz = bar\nend\n\nputs sprintf(\"%0.6f\", baz/quz.to_f)"}, {"source_code": "n = gets.to_i\nsum = 0\nn.times {\n sum += gets.to_f\n}\np sum / n\n"}, {"source_code": "foo = 0\nbar = 0\nbaz = 0\nquz = 0\ntux = gets.to_i\nwhile tux!=0\npur =gets.to_i\nfoo = foo + pur\nbar = bar + 1\n#if bar*baz==foo*quz\n baz = foo\n quz = bar\n#end\ntux -=1\nend\n\nputs baz*1.0/quz"}], "src_uid": "32fc378a310ca15598377f7b638eaf26"} {"nl": {"description": "Ksenia has ordinary pan scales and several weights of an equal mass. Ksenia has already put some weights on the scales, while other weights are untouched. Ksenia is now wondering whether it is possible to put all the remaining weights on the scales so that the scales were in equilibrium. The scales is in equilibrium if the total sum of weights on the left pan is equal to the total sum of weights on the right pan.", "input_spec": "The first line has a non-empty sequence of characters describing the scales. In this sequence, an uppercase English letter indicates a weight, and the symbol \"|\" indicates the delimiter (the character occurs in the sequence exactly once). All weights that are recorded in the sequence before the delimiter are initially on the left pan of the scale. All weights that are recorded in the sequence after the delimiter are initially on the right pan of the scale. The second line contains a non-empty sequence containing uppercase English letters. Each letter indicates a weight which is not used yet. It is guaranteed that all the English letters in the input data are different. It is guaranteed that the input does not contain any extra characters.", "output_spec": "If you cannot put all the weights on the scales so that the scales were in equilibrium, print string \"Impossible\". Otherwise, print the description of the resulting scales, copy the format of the input. If there are multiple answers, print any of them.", "sample_inputs": ["AC|T\nL", "|ABC\nXYZ", "W|T\nF", "ABC|\nD"], "sample_outputs": ["AC|TL", "XYZ|ABC", "Impossible", "Impossible"], "notes": null}, "positive_code": [{"source_code": "dx = gets.chomp.split(\"|\")\ndx[0] ||= \"\"\ndx[1] ||= \"\"\nf = false\n\nif dx[0].length > dx[1].length\n f = true\n dx[0], dx[1] = dx[1], dx[0]\nend\ndx[0] += gets.chomp\nif dx[0].length < dx[1].length or (dx[0].length - dx[1].length) % 2 != 0\n puts \"Impossible\"\nelse\n tmp = dx[0].length - dx[1].length\n dx = [dx[0][0...(dx[1].length + (tmp / 2))], dx[1] + dx[0][(dx[1].length + (tmp / 2))..-1]]\n if f\n puts dx[1] + \"|\" + dx[0]\n else\n puts dx[0] + \"|\" + dx[1]\n end\nend\n"}, {"source_code": "s = gets.strip\na, b = s.split(\"|\")\n\na = a.to_s\nb = b.to_s\n\nc = gets.strip\nc = c.to_s\n\nif a.size > b.size then\n diff = a.size - b.size\n if diff <= c.size then\n b += c[0...diff]\n c = c[diff..-1]\n end\nend\nif a.size < b.size then\n diff = b.size - a.size\n if diff <= c.size then\n a += c[0...diff]\n c = c[diff..-1]\n end\nend\n\nif a.size == b.size\n if c.size.even?\n puts \"#{a}#{c[0...c.size/2]}|#{b}#{c[c.size/2..-1]}\"\n else\n puts \"Impossible\"\n end\nelse\n puts \"Impossible\"\nend\n"}, {"source_code": "s=gets.chomp+'|x'\nt=gets.chomp\nl,r=s.split '|'\nt.each_char{|c|l.size>r.size ? r<=0 && q>=0\n l< 0\n if n % 2 != 0\n answer = ( answer * x ) % m\n end\n x = (x*x) % m;\n n /= 2\n end\n return answer\nend\n\nexponent = gets.chomp.to_i\nputs modPow(1378, exponent, 10) "}, {"source_code": "n = gets.to_i \n\nif n == 0 \n puts \"1\" \nelse \n case n%4 \n when 1\n puts \"8\" \n when 2 \n puts \"4\"\n when 3 \n puts \"2\" \n when 0 \n puts \"6\"\n end\nend \n\n"}, {"source_code": "a = gets.chomp.to_i\nif a==0\n p 1\nelsif a%4==1\n p 8\nelsif a%4==2\n p 4\nelsif a%4==3\n p 2\nelse\n p 6\nend"}, {"source_code": "n=gets.to_i;puts n==0?1:'6842'[n%4]"}, {"source_code": "n = gets.chomp.to_i\nif n == 0\n puts 1\n exit\nend\ncase n%4\nwhen 0\n puts 6\nwhen 1\n puts 8\nwhen 2\n puts 4\nwhen 3\n puts 2\nend\n"}, {"source_code": "n = gets.to_i\nputs n == 0 ? 1 : [6, 8, 4, 2][n % 4]\n"}, {"source_code": "num = [8,4,2,6]\nn = gets.to_i\nputs n == 0 ? 1 : num[(n-1) % 4]\n"}, {"source_code": "n=gets.to_i\nm=1\nr=8\nwhile n>0\n\tif n%2==1 then\n\t\tm=(m*r)%10\n\tend\n\tr=(r*r)%10\n\tn/=2\nend\nputs m\n\n"}, {"source_code": "n= gets.to_i\nputs n==0? 1 : n%4 == 1? 8: n%4 ==2? 4 : n%4==3? 2 : 6\n"}, {"source_code": "n = gets.chomp.to_i\nif n == 0\n\tputs 1\nelse\n\tputs [8,4,2,6][(n-1)%4]\nend\n"}, {"source_code": "n=gets.to_i\nx=1378\nr=1\nwhile n>0\n r=r*x%10 if n.odd?\n x=x*x%10\n n>>=1\nend\np r\n"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\n# power of 1378, and last digit\n# and cyclic.\n# 1 -> 8, 2 -> 4, 3 -> 2, 4 -> 6,\n# 5 -> 8, 6 -> 4, 7 -> 2, 8 -> 6,\n# 9 -> ...\n# 4n + 1\nn = gets.to_i\nif n == 0\n puts 1\nelse\n puts 8 if n%4 == 1\n puts 4 if n%4 == 2\n puts 2 if n%4 == 3\n puts 6 if n%4 == 0\nend\n"}, {"source_code": "n = gets.chomp.to_i\nif n == 0\n\tprint 1\nelse\n\tif n % 4 == 2\n\t\tprint 4\n\telsif n % 4 == 3\n\t\tprint 2\n\telsif n % 4 == 0\n\t\tprint 6\n\telsif n % 4 == 1\n\t\tprint 8\n\tend\nend\n\t\t"}, {"source_code": "n = gets.strip.to_i\nif n.zero?\n puts 1\n exit\nend\na = [8, 4, 2, 6]\nn -= 1\nputs a[n % 4]"}, {"source_code": "n=gets.to_i\nif n==0\n puts 1\nelse\n puts [8,4,2,6][(n-1)%4]\nend"}, {"source_code": "s = gets.to_i\nputs s == 0 ? 1 : \"8426\"[s % 4 - 1]\n"}, {"source_code": "n=gets.to_i\nif n == 0\n puts 1\nelse\n puts \"8426\"[(n+3)%4]\nend"}, {"source_code": "a = [8, 4, 2, 6]\nn = gets.to_i\nputs(n == 0 ? 1 : a[(n - 1)%4])\n"}, {"source_code": "n = gets.to_i\n\nif n.zero?\n puts 1\nelse\n puts [6, 8, 4, 2][n%4]\nend\n"}], "negative_code": [{"source_code": "n = gets.to_i \n\nif n == 0 \n puts \"1\" \nelse \n case n%4 \n when 1\n puts \"8\" \n when 2 \n puts \"4\"\n when 3 \n puts \"2\" \n when 4 \n puts \"6\"\n end\nend \n"}, {"source_code": "n = gets.chomp.to_i\ncase n%4\nwhen 0\n puts 6\nwhen 1\n puts 8\nwhen 2\n puts 4\nwhen 3\n puts 2\nend\n"}, {"source_code": "n = gets.chomp.to_i\nprint 1378**n%10"}, {"source_code": "n = gets.to_i\nputs n <= 2 ? (1378 ** n) % 10 : 6\n"}, {"source_code": "num = [8,4,6,2]\nn = gets.to_i\nputs n == 0 ? 1 : num[(n-1) % 4]\n"}, {"source_code": "n= gets.to_i%4\nputs n==0? 1: n == 1? 8: n ==2? 4 : n==3? 2 : 6\n"}, {"source_code": "n= gets.to_i%4\nputs n == 1? 8: n ==2? 4 : n==3? 2 : 6\n"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\n# power of 1378, and last digit\n# and cyclic.\n# 1 -> 8, 2 -> 6, 3 -> 2, 4 -> 6, 5 -> 8\nn = gets.to_i\nbase = 8\n((n-1)%6).times {\n base *= 8\n base = base % 10\n}\n\nputs base"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\n# power of 1378, and last digit\n# and cyclic.\n# 1 -> 8, 2 -> 4, 3 -> 2, 4 -> 6,\n# 5 -> 8, 6 -> 4, 7 -> 2, 8 -> 6,\n# 9 -> ...\n# 4n + 1\nn = gets.to_i\nputs 1 if n == 0\nputs 8 if n%4 == 1\nputs 4 if n%4 == 2\nputs 2 if n%4 == 3\nputs 6 if n%4 == 0"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\n# power of 1378, and last digit\n# and cyclic.\n# 1 -> 8, 2 -> 4, 3 -> 2, 4 -> 6,\n# 5 -> 8, 6 -> 4, 7 -> 2, 8 -> 6,\n# 9 -> ...\n# 4n + 1\nn = gets.to_i\n\nputs 8 if n%4 == 1\nputs 4 if n%4 == 2\nputs 2 if n%4 == 3\nputs 6 if n%4 == 0"}, {"source_code": "n = gets.strip.to_i\na = [8, 4, 2, 6]\nn -= 1\nputs a[n % 4]"}, {"source_code": "s = gets.to_i\nputs \"8426\"[s % 4 - 1]\n"}, {"source_code": "puts (1378**gets.to_i).to_s.chars.last\n"}], "src_uid": "4b51b99d1dea367bf37dc5ead08ca48f"} {"nl": {"description": "One beautiful July morning a terrible thing happened in Mainframe: a mean virus Megabyte somehow got access to the memory of his not less mean sister Hexadecimal. He loaded there a huge amount of n different natural numbers from 1 to n to obtain total control over her energy.But his plan failed. The reason for this was very simple: Hexadecimal didn't perceive any information, apart from numbers written in binary format. This means that if a number in a decimal representation contained characters apart from 0 and 1, it was not stored in the memory. Now Megabyte wants to know, how many numbers were loaded successfully.", "input_spec": "Input data contains the only number n (1\u2009\u2264\u2009n\u2009\u2264\u2009109).", "output_spec": "Output the only number \u2014 answer to the problem.", "sample_inputs": ["10"], "sample_outputs": ["2"], "notes": "NoteFor n = 10 the answer includes numbers 1 and 10."}, "positive_code": [{"source_code": "ns = gets.chomp\ns2 = \"\"\nfor i in 0..ns.length-1\n\twk = ns[i].to_i\n\tif wk > 1\n\t\tfor j in i..ns.length-1\n\t\t\ts2 << \"1\"\n\t\tend\n\t\tbreak\n\telse\n\t\ts2 << ns[i]\n\tend\nend\nputs s2.to_i(2)\n"}, {"source_code": "#!/usr/bin/ruby\na=Array(1024)\n1024.times{|i| a[i]=i.to_s(2).to_i}\nn=gets.chomp.to_i\n1024.times{|i| if a[i+1]>n then puts i;exit end}\n"}, {"source_code": "n = gets.to_i\nm = 0\nloop do\n\tbreak if ('%b' % m).to_i > n\n\tm += 1\nend\np m - 1\n\n"}, {"source_code": "n=gets.to_i\nans=0\n(1<<12).times{|i|\n v=0\n for j in 0..11\n v*=10\n if ((i>>j)&1)==1 then\n v+=1\n end\n end\n if v<=n then\n ans+=1\n end\n}\np ans-1"}, {"source_code": "$n = gets.to_i\n\n$counter = 0\n$len = Math.log10($n).to_i + 1\n\ndef solve(num, depth)\n\tif depth == $len\n\t\t$counter += 1 if num > 0 and num <= $n\n\t\treturn\n\tend\n\n\t[0, 1].each do |i|\n\t\tsolve(num*10 + i, depth+1)\n\tend\nend\n\nsolve(0, 0)\n\nputs $counter\n"}, {"source_code": "def bin2dec (b)\n ans = 0\n base = 1\n while b > 0 do\n ans += (b % 2) * base\n b = b >> 1\n base = base * 10\n end\n return ans\nend\nn = gets.to_i;\nm = n\nlen = 0\nwhile m != 0 do\n len += 1\n m /= 10\nend\ncand = (1 << len) - 1\n#p cand\nans = 0\nfor i in 1..cand do\n v = bin2dec(i)\n if v >= 1 && v <= n then ans += 1 end\n# print i, \" \" , v\n# puts\nend\nprint ans\nputs\n\n\n\n"}, {"source_code": "n = gets.to_i\nres = 0\nns = [1]\ni = 10\nwhile ns.last<(10**9 + 1)\n break if i>n\n temp = [i]\n flag = false\n ns.each do |x|\n if (x+i)<=n\n temp << x+i\n else\n flag = true\n end\n end\n ns += temp.sort\n break if flag\n i *= 10\nend\nputs ns.size\n"}, {"source_code": "n = gets.to_i\ni = 1\na = 1\nc = 0\nwhile a <= n\n\tc += 1\n\ti += 1\n\ta = i.to_s(2).to_i\nend\nputs c"}, {"source_code": "n = gets.to_i\nm = 0\nloop do\n break if (m.to_s(2)).to_i > n\n m += 1\nend\np m - 1"}, {"source_code": "s = gets.strip\n\none = false\n\n0.upto(s.length-1) do |i|\n if (s[i] > ?1) or (one)\n s[i] = ?1\n one = true\n end\nend\n\nn = s.to_i(2)\nputs n"}, {"source_code": "$n = 0\n$res = 0\ndef go(x)\n if x <= $n then\n $res += 1\n go(10 * x + 0)\n go(10 * x + 1)\n end\nend\n$n = gets.chomp.to_i\ngo(1)\np $res\n"}, {"source_code": "n = gets.to_i\n\n\nz = 1\nres=0\nwhile z.to_s(2).to_i <= n \n z+=1\n res+=1\nend\n\nputs res"}], "negative_code": [{"source_code": "ns = gets.chomp\ns2 = \"\"\nfor i in 0..ns.length-1\n\twk = ns[i].to_i\n\twk = 1 if wk > 1\n\ts2 << wk.to_s\nend\nputs s2.to_i(2)\n"}, {"source_code": "$n = gets.to_i\n\n$counter = 0\n$len = Math.log10($n).to_i + 1\n\ndef solve(num, depth)\n\tif depth == $len\n\t\t$counter += 1 if num < $n\n\t\treturn\n\tend\n\n\t[0, 1].each do |i|\n\t\tsolve(num*10 + i, depth+1)\n\tend\nend\n\nsolve(0, 0)\n\nputs $counter\n"}], "src_uid": "64a842f9a41f85a83b7d65bfbe21b6cb"} {"nl": {"description": "It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends.Today he invented one simple game to play with Lena, with whom he shares a desk. The rules are simple. Sasha draws n sticks in a row. After that the players take turns crossing out exactly k sticks from left or right in each turn. Sasha moves first, because he is the inventor of the game. If there are less than k sticks on the paper before some turn, the game ends. Sasha wins if he makes strictly more moves than Lena. Sasha wants to know the result of the game before playing, you are to help him.", "input_spec": "The first line contains two integers n and k (1\u2009\u2264\u2009n,\u2009k\u2009\u2264\u20091018, k\u2009\u2264\u2009n)\u00a0\u2014 the number of sticks drawn by Sasha and the number k\u00a0\u2014 the number of sticks to be crossed out on each turn.", "output_spec": "If Sasha wins, print \"YES\" (without quotes), otherwise print \"NO\" (without quotes). You can print each letter in arbitrary case (upper of lower).", "sample_inputs": ["1 1", "10 4"], "sample_outputs": ["YES", "NO"], "notes": "NoteIn the first example Sasha crosses out 1 stick, and then there are no sticks. So Lena can't make a move, and Sasha wins.In the second example Sasha crosses out 4 sticks, then Lena crosses out 4 sticks, and after that there are only 2 sticks left. Sasha can't make a move. The players make equal number of moves, so Sasha doesn't win."}, "positive_code": [{"source_code": "n,k=gets.split.map &:to_i;puts [:NO,:YES][n/k%2]"}, {"source_code": "# Codeforces My Practice\n# author: Leonardone @ NEETSDKASU\n\nn, k = gets.strip.split.map &:to_i\n\nk2 = k * 2\nv = n % k2\n\nif v < k\n puts :NO\nelse\n puts :YES\nend"}, {"source_code": "# Try Codeforces\n# author: Leonardone @ NEETSDKASU\n\nn, k = gets.strip.split.map &:to_i\n\nv = n / k\n\nif v.even?\n puts :NO\nelse\n puts :YES\nend"}, {"source_code": "n, k = gets.split.map(&:to_i)\n\nputs (n / k).odd? ? 'YES' : 'NO'"}, {"source_code": "n, k = gets.strip.split.map(&:to_i)\nans = \"YES\"\ndiv = n / k\nans = \"NO\" if div.even?\nputs ans\n"}, {"source_code": "n,k=gets.split.map{|e| e.to_i}\nt=n/k\nif t%2==1 then\n\tputs \"YES\"\nelse\n\tputs \"NO\"\nend\n\n"}, {"source_code": "n, k=gets.split.map &:to_i\nputs (n/k).odd? ? \"YES\" : \"NO\"\n"}, {"source_code": "n,m = gets.split\nn = n.to_i\nm = m.to_i\nk = Integer(n / m)\nif k % 2 == 1 then\n\tputs \"YES\"\nelse\n\tputs \"NO\"\nend"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\nn, k = gets.split.map(&:to_i)\n\nif (n/k).odd?\n puts \"YES\"\nelse\n puts \"NO\"\nend"}, {"source_code": "nk = gets.chomp.split.map(&:to_i)\nn = nk[0]\nk = nk[1]\n\nif (n/k)%2 == 0\n\tprint \"NO\"\nelse\n\tprint \"YES\"\nend"}, {"source_code": "n,k = gets.split.map(&:to_i)\nn/=k\nputs (n&1!=0 ? \"YES\" : \"NO\")"}, {"source_code": "n,k = gets.strip.split.map(&:to_i)\n\ndef kek(n,k)\n (n/k).even? ? 'NO' : 'YES'\nend\nputs kek(n,k)"}, {"source_code": "a=gets.split.map &:to_i\nputs (a[0]/a[1])%2==0 ?\"NO\":\"YES\""}, {"source_code": "n, k = gets.split.map(&:to_i)\ncase (n - k)%(2*k)\nwhen 0..k-1\n puts \"YES\"\nwhen k..2*k-1\n puts \"NO\"\nend"}, {"source_code": "# https://codeforces.com/problemset/problem/832/A\ns = gets.chomp\narr = s.split(' ')\n\nn = arr[0].to_i\nk = arr[1].to_i\nif ((n % k == 0) && (n / k % 2 != 0)) || ((n % k != 0) && (n / k % 2 != 0))\n puts 'YES'\nelse\n puts 'NO'\nend\n"}, {"source_code": "n, k=gets.split.map(&:to_i)\n\nif (n/k)%2==1\n puts 'YES'\nelse\n puts 'NO'\nend\n"}], "negative_code": [{"source_code": "n,k=gets.split.map &:to_i;puts [:YES,:NO][n/k%2]"}, {"source_code": "# Try Codeforces\n# author: Leonardone @ NEETSDKASU\n\nn, k = gets.strip.split.map &:to_i\n\nk2 = k * 2\nv = n % k2\n\nif v < n\n puts :NO\nelse\n puts :YES\nend"}, {"source_code": "# Try Codeforces\n# author: Leonardone @ NEETSDKASU\n\nn, k = gets.strip.split.map &:to_i\n\nk2 = k * 2\nv = n % k2\n\nif v <= n\n puts :NO\nelse\n puts :YES\nend"}, {"source_code": "# Try Codeforces\n# author: Leonardone @ NEETSDKASU\n\nn, k = gets.strip.split.map &:to_i\n\nv = n / k\n\nif v.odd?\n puts :NO\nelse\n puts :YES\nend"}, {"source_code": "n, k = gets.strip.split.map(&:to_i)\nans = \"YES\"\nmod = n % k\ndiv = n / k\nans = \"NO\" if div.even? && mod > 0\nputs ans\n"}, {"source_code": "nk = gets.chomp.split.map(&:to_i)\nn = nk[0]\nk = nk[1]\n\nif n%k == 0\n\tprint \"YES\"\nelse\n\tif (n/k)%2 == 0\n\t\tprint \"NO\"\n\telse\n\t\tprint \"YES\"\n\tend\nend"}, {"source_code": "a=gets.split.map &:to_i\nputs (a[1]/a[0])%2==0 ?\"NO\":\"YES\""}, {"source_code": "a=gets.split.map &:to_i\np (a[1]/a[0])%2==0 ?\"NO\":\"YES\""}], "src_uid": "05fd61dd0b1f50f154eec85d8cfaad50"} {"nl": {"description": "You are given the current time in 24-hour format hh:mm. Find and print the time after a minutes.Note that you should find only the time after a minutes, see the examples to clarify the problem statement.You can read more about 24-hour format here https://en.wikipedia.org/wiki/24-hour_clock.", "input_spec": "The first line contains the current time in the format hh:mm (0\u2009\u2264\u2009hh\u2009<\u200924,\u20090\u2009\u2264\u2009mm\u2009<\u200960). The hours and the minutes are given with two digits (the hours or the minutes less than 10 are given with the leading zeroes). The second line contains integer a (0\u2009\u2264\u2009a\u2009\u2264\u2009104) \u2014 the number of the minutes passed.", "output_spec": "The only line should contain the time after a minutes in the format described in the input. Note that you should print exactly two digits for the hours and the minutes (add leading zeroes to the numbers if needed). See the examples to check the input/output format.", "sample_inputs": ["23:59\n10", "20:20\n121", "10:10\n0"], "sample_outputs": ["00:09", "22:21", "10:10"], "notes": null}, "positive_code": [{"source_code": "h, m = gets.split( \":\" ).map( &:to_i )\na = gets.to_i\nt = Time.local( 2016, 1, 1, h, m, 0 )\nputs ( t + a * 60 ).strftime( \"%H:%M\" )\n\n"}, {"source_code": "#!/usr/bin/ruby\ndef encode(n) '%02d:%02d'%[n/60,n%60] end\ndef decode(s)\n\th,m=s.split(':').map(&:to_i)\n\th*60+m\nend\nputs encode((decode(gets)+gets.to_i)%1440)"}, {"source_code": "h, m = gets.chomp.split(':').map(&:to_i)\na = gets.chomp.to_i\n\nt = Time.new(2002, 10, 31, h, m, 0)\nt2 = t + a * 60\n\nputs \"#{t2.hour.to_s.rjust(2, '0')}:#{t2.min.to_s.rjust(2, '0')}\"\n"}, {"source_code": "h,m=gets.split(':').map(&:to_i)\nt=Time.gm(2008,7,7,h,m)+gets.to_i*60\nputs t.strftime('%H:%M')"}, {"source_code": "h,m=gets.split(':').map(&:to_i)\nputs ((Time.gm(2,1,1,h,m)+gets.to_i*60).strftime('%H:%M'))"}], "negative_code": [], "src_uid": "20c2d9da12d6b88f300977d74287a15d"} {"nl": {"description": "Noora is a student of one famous high school. It's her final year in school\u00a0\u2014 she is going to study in university next year. However, she has to get an \u00abA\u00bb graduation certificate in order to apply to a prestigious one.In school, where Noora is studying, teachers are putting down marks to the online class register, which are integers from 1 to k. The worst mark is 1, the best is k. Mark that is going to the certificate, is calculated as an average of all the marks, rounded to the closest integer. If several answers are possible, rounding up is produced. For example, 7.3 is rounded to 7, but 7.5 and 7.8784\u00a0\u2014 to 8. For instance, if Noora has marks [8,\u20099], then the mark to the certificate is 9, because the average is equal to 8.5 and rounded to 9, but if the marks are [8,\u20098,\u20099], Noora will have graduation certificate with 8.To graduate with \u00abA\u00bb certificate, Noora has to have mark k.Noora got n marks in register this year. However, she is afraid that her marks are not enough to get final mark k. Noora decided to ask for help in the internet, where hacker Leha immediately responded to her request. He is ready to hack class register for Noora and to add Noora any number of additional marks from 1 to k. At the same time, Leha want his hack be unseen to everyone, so he decided to add as less as possible additional marks. Please help Leha to calculate the minimal number of marks he has to add, so that final Noora's mark will become equal to k.", "input_spec": "The first line contains two integers n and k (1\u2009\u2264\u2009n\u2009\u2264\u2009100,\u20091\u2009\u2264\u2009k\u2009\u2264\u2009100) denoting the number of marks, received by Noora and the value of highest possible mark. The second line contains n integers a1,\u2009a2,\u2009...,\u2009an (1\u2009\u2264\u2009ai\u2009\u2264\u2009k) denoting marks received by Noora before Leha's hack.", "output_spec": "Print a single integer\u00a0\u2014 minimal number of additional marks, that Leha has to add in order to change Noora's final mark to k.", "sample_inputs": ["2 10\n8 9", "3 5\n4 4 4"], "sample_outputs": ["4", "3"], "notes": "NoteConsider the first example testcase.Maximal mark is 10, Noora received two marks\u00a0\u2014 8 and 9, so current final mark is 9. To fix it, Leha can add marks [10,\u200910,\u200910,\u200910] (4 marks in total) to the registry, achieving Noora having average mark equal to . Consequently, new final mark is 10. Less number of marks won't fix the situation.In the second example Leha can add [5,\u20095,\u20095] to the registry, so that making average mark equal to 4.5, which is enough to have 5 in the certificate."}, "positive_code": [{"source_code": "n,k,*a=$<.read.split.map &:to_i\np [0,(k*2-1)*n-a.reduce(:+)*2].max"}, {"source_code": "# Try Codeforces\n# author: Leonardone @ NEETSDKASU\n############################################################\ndef gs() gets.strip end\ndef gi() gets.to_i end\ndef gss() gs.split end\ndef gis() gss.map(&:to_i) end\ndef nmapf(n,f) n.times.map{ __send__ f } end\ndef ngs(n) nmapf n,:gs end\ndef ngi(n) nmapf n,:gi end\ndef ngss(n) nmapf n,:gss end\ndef ngis(n) nmapf n,:gis end\ndef arr2d(h,w,v=0) h.times.map{[v] * w} end\ndef for2p(hr,wr,&pr) hr.each{|i|wr.each{|j| yield(i,j)}} end\ndef nsum(n) n * (n + 1) / 2 end\ndef vcount(d,r=Hash.new(0)) d.inject(r){|m,e| m[e]+=1;m} end\n############################################################\n\n\nn, k = gis\na = gis\n\nsum = a.inject(:+) * 10\n\nlim = (k - 1) * 10 + 5\n\ni = n\nloop do\n break if sum / i >= lim\n sum += k * 10\n i += 1\nend\n\nputs (i - n)\n\n\n\n\n"}, {"source_code": "n, k=gets.split.map &:to_i\ns=gets.split.map(&:to_i).inject(0, :+)\nr=0\nwhile 2*s<2*k*n-n\n\tr+=1\n\ts+=k;\n\tn+=1\nend\nputs r\n"}], "negative_code": [{"source_code": "n,k,*a=$<.read.split.map &:to_i\np [0,(k*2-1)*n-a.reduce(:+)*2]"}], "src_uid": "f22267bf3fad0bf342ecf4c27ad3a900"} {"nl": {"description": "A long time ago (probably even in the first book), Nicholas Flamel, a great alchemist and the creator of the Philosopher's Stone, taught Harry Potter three useful spells. The first one allows you to convert a grams of sand into b grams of lead, the second one allows you to convert c grams of lead into d grams of gold and third one allows you to convert e grams of gold into f grams of sand. When Harry told his friends about these spells, Ron Weasley was amazed. After all, if they succeed in turning sand into lead, lead into gold, and then turning part of the gold into sand again and so on, then it will be possible to start with a small amount of sand and get huge amounts of gold! Even an infinite amount of gold! Hermione Granger, by contrast, was skeptical about that idea. She argues that according to the law of conservation of matter getting an infinite amount of matter, even using magic, is impossible. On the contrary, the amount of matter may even decrease during transformation, being converted to magical energy. Though Hermione's theory seems convincing, Ron won't believe her. As far as Ron is concerned, Hermione made up her law of conservation of matter to stop Harry and Ron wasting their time with this nonsense, and to make them go and do homework instead. That's why Ron has already collected a certain amount of sand for the experiments. A quarrel between the friends seems unavoidable...Help Harry to determine which one of his friends is right, and avoid the quarrel after all. To do this you have to figure out whether it is possible to get the amount of gold greater than any preassigned number from some finite amount of sand.", "input_spec": "The first line contains 6 integers a, b, c, d, e, f (0\u2009\u2264\u2009a,\u2009b,\u2009c,\u2009d,\u2009e,\u2009f\u2009\u2264\u20091000).", "output_spec": "Print \"Ron\", if it is possible to get an infinitely large amount of gold having a certain finite amount of sand (and not having any gold and lead at all), i.e., Ron is right. Otherwise, print \"Hermione\".", "sample_inputs": ["100 200 250 150 200 250", "100 50 50 200 200 100", "100 10 200 20 300 30", "0 0 0 0 0 0", "1 1 0 1 1 1", "1 0 1 2 1 2", "100 1 100 1 0 1"], "sample_outputs": ["Ron", "Hermione", "Hermione", "Hermione", "Ron", "Hermione", "Ron"], "notes": "NoteConsider the first sample. Let's start with the 500 grams of sand. Apply the first spell 5 times and turn the sand into 1000 grams of lead. Then apply the second spell 4 times to get 600 grams of gold. Let\u2019s take 400 grams from the resulting amount of gold turn them back into sand. We get 500 grams of sand and 200 grams of gold. If we apply the same operations to 500 grams of sand again, we can get extra 200 grams of gold every time. Thus, you can get 200, 400, 600 etc. grams of gold, i.e., starting with a finite amount of sand (500 grams), you can get the amount of gold which is greater than any preassigned number.In the forth sample it is impossible to get sand, or lead, or gold, applying the spells.In the fifth sample an infinitely large amount of gold can be obtained by using only the second spell, which allows you to receive 1 gram of gold out of nothing. Note that if such a second spell is available, then the first and the third one do not affect the answer at all.The seventh sample is more interesting. We can also start with a zero amount of sand there. With the aid of the third spell you can get sand out of nothing. We get 10000 grams of sand in this manner. Let's get 100 grams of lead using the first spell 100 times. Then make 1 gram of gold from them. We managed to receive 1 gram of gold, starting with a zero amount of sand! Clearly, in this manner you can get an infinitely large amount of gold."}, "positive_code": [{"source_code": "a = gets.split.map(&:to_i)\nif (a[2] == 0 and a[3] != 0) or (a[0] == 0 and a[1] != 0 && a[2]*a[3] != 0)\n puts \"Ron\"\nelse\n puts(a[0]*a[2]*a[4] < a[1]*a[3]*a[5] ? \"Ron\" : \"Hermione\")\nend\n"}, {"source_code": "a, b, c, d, e, f = gets.split.map(&:to_i)\nputs (c == 0 && d > 0) ||\n\t(a == 0 && b > 0 && c > 0 && d > 0) ||\n\t(e == 0 && f > 0 && a > 0 && b > 0 && c > 0 && d > 0) ||\n\ta * c * e < b * d * f ? :Ron : :Hermione\n"}, {"source_code": "a, b, c, d, e, f = gets.split.map {|n| n.to_f }\nconv_ratio = (a/b)*(c/d)*(e/f)\n\nif d == 0\n puts \"Hermione\"\nelsif c == 0 or (a == 0 and b > 0)\n puts \"Ron\"\nelsif conv_ratio < 1\n puts \"Ron\"\nelse\n puts \"Hermione\"\nend"}, {"source_code": "a, b, c, d, e, f = gets.split.map {|n| n.to_f }\nconv_ratio = (a/b)*(c/d)*(e/f)\n\nif d == 0\n puts \"Hermione\"\nelsif c == 0\n puts \"Ron\"\nelsif b == 0\n puts \"Hermione\"\nelsif a == 0\n puts \"Ron\"\nelsif f == 0\n puts \"Hermione\"\nelsif conv_ratio < 1\n puts \"Ron\"\nelse\n puts \"Hermione\"\nend"}, {"source_code": "a = gets.split.map(&:to_i)\nputs(((a[2] == 0 && a[3] != 0) or (a[0] == 0 && a[1] != 0 && a[2] * a[3] != 0) or (a[0] * a[2] * a[4] < a[1] * a[3] * a[5])) ? \"Ron\" : \"Hermione\")"}, {"source_code": "a, b, c, d, e, f = gets.chomp.split.map{|e| e.to_i}\n\nif (a * b * c * d * e * f != 0)\n if (a * c * e < b * d * f)\n puts \"Ron\"\n else\n puts \"Hermione\"\n end\nelse\n if (d == 0)\n puts \"Hermione\"\n elsif (c == 0)\n puts \"Ron\"\n else # d, c > 0\n if (b == 0)\n puts \"Hermione\"\n elsif (a == 0)\n puts \"Ron\"\n else # a, b > 0\n if (f == 0)\n puts \"Hermione\"\n else\n puts \"Ron\"\n end\n end\n end\nend \n\n"}, {"source_code": "a,b,c,d,e,f = gets.split(' ').map(&:to_i)\nif (c==0 && d !=0) || (a==0 && b !=0 && c*d !=0)\n puts \"Ron\"\nelse\n if (a*c*e) < (b*d*f)\n puts \"Ron\"\n else\n puts \"Hermione\"\n end\nend"}, {"source_code": "a, b, c, d, e, f = gets.split(' ').map{|s| s.to_i}\nab, cd, ef = [[a, b], [c, d], [e, f]].map{|aa, bb|bb/aa.to_f}\ng = ab*cd*ef\nm = [cd.infinite?, ab.infinite?&&cd>0, ef.infinite?&&ab>0&&cd>0]\nputs (m.any?||g>1.0) ? 'Ron' : 'Hermione'"}, {"source_code": "def foo(a)\n if a[3] == 0\n return false\n end\n\n if a[2] == 0 && a[3] > 0\n return true\n end\n\n if a[1]*a[3] == 0\n return false\n end\n\n if a[0]*a[2] == 0 && a[1]*a[3] > 0\n return true\n end\n\n if a[1]*a[3]*a[5] == 0\n return false\n end\n\n if a[0]*a[2]*a[4] == 0 && a[1]*a[3]*a[5] > 0\n return true\n end\n\n pr = 1.0\n 0.step(4, 2) do |i|\n pr = pr / a[i] * a[i-1]\n end\n if pr > 1\n return true\n else\n return false\n end\nend\n\na = gets.split.map(&:to_i)\nputs(foo(a) ? \"Ron\" : \"Hermione\")\n"}], "negative_code": [{"source_code": "a = gets.split.map(&:to_i)\nif a[2] == 0 and a[3] != 0\n puts \"Ron\"\nelse\n puts(a[0]*a[2]*a[4] < a[1]*a[3]*a[5] ? \"Ron\" : \"Hermione\")\nend\n"}, {"source_code": "a = gets.split.map(&:to_i)\nputs(a[0]*a[2]*a[4] < a[1]*a[3]*a[5] ? \"Ron\" : \"Hermione\")\n"}, {"source_code": "a, b, c, d, e, f = gets.split.map {|n| n.to_f }\nconv_ratio = (a/b)*(c/d)*(e/f)\n\nif d == 0\n puts \"Hermione\"\nelsif c == 0\n puts \"Ron\"\nelsif b == 0 or f == 0\n puts \"Hermione\"\nelsif conv_ratio < 1\n puts \"Ron\"\nelse\n puts \"Hermione\"\nend"}, {"source_code": "a, b, c, d, e, f = gets.split(' ').map{|s| s.to_i}\nab, cd, ef = [[a, b], [c, d], [e, f]].map{|aa, bb|bb/aa.to_f}\ng = ab*cd*ef\nputs (cd.infinite?||g>1.0) ? 'Ron' : 'Hermione'"}, {"source_code": "a, b, c, d, e, f = gets.split(' ').map{|s| s.to_i}\ng = (b/a.to_f) * (d/c.to_f) * (f/e.to_f)\nputs (g>1.0) ? 'Ron' : 'Hermione'"}, {"source_code": "a, b, c, d, e, f = gets.split(' ').map{|s| s.to_i}\nab, cd, ef = [[a, b], [c, d], [e, f]].map{|aa, bb|bb/aa.to_f}\ng = ab*cd*ef\nm = [cd.infinite?, ab.infinite?&&!cd.nan?, ef.infinite?&&!ab.nan?&&!cd.nan?]\nputs (m.any?||g>1.0) ? 'Ron' : 'Hermione'\n"}], "src_uid": "44d608de3e1447f89070e707ba550150"} {"nl": {"description": "The last stage of Football World Cup is played using the play-off system.There are n teams left in this stage, they are enumerated from 1 to n. Several rounds are held, in each round the remaining teams are sorted in the order of their ids, then the first in this order plays with the second, the third\u00a0\u2014 with the fourth, the fifth\u00a0\u2014 with the sixth, and so on. It is guaranteed that in each round there is even number of teams. The winner of each game advances to the next round, the loser is eliminated from the tournament, there are no draws. In the last round there is the only game with two remaining teams: the round is called the Final, the winner is called the champion, and the tournament is over.Arkady wants his two favorite teams to play in the Final. Unfortunately, the team ids are already determined, and it may happen that it is impossible for teams to meet in the Final, because they are to meet in some earlier stage, if they are strong enough. Determine, in which round the teams with ids a and b can meet.", "input_spec": "The only line contains three integers n, a and b (2\u2009\u2264\u2009n\u2009\u2264\u2009256, 1\u2009\u2264\u2009a,\u2009b\u2009\u2264\u2009n)\u00a0\u2014 the total number of teams, and the ids of the teams that Arkady is interested in. It is guaranteed that n is such that in each round an even number of team advance, and that a and b are not equal.", "output_spec": "In the only line print \"Final!\" (without quotes), if teams a and b can meet in the Final. Otherwise, print a single integer\u00a0\u2014 the number of the round in which teams a and b can meet. The round are enumerated from 1.", "sample_inputs": ["4 1 2", "8 2 6", "8 7 5"], "sample_outputs": ["1", "Final!", "2"], "notes": "NoteIn the first example teams 1 and 2 meet in the first round.In the second example teams 2 and 6 can only meet in the third round, which is the Final, if they win all their opponents in earlier rounds.In the third example the teams with ids 7 and 5 can meet in the second round, if they win their opponents in the first round."}, "positive_code": [{"source_code": "n,a,b=gets.split.map &:to_i\na-=1\nb-=1\nc=1\nwhile a/2!=b/2\n\ta/=2\n\tb/=2\n\tc+=1\nend\nputs 1< 3\n\t\tcount += 1 #3, 1\n\tend\n\t\n\tif remaining == 1\n\t\tcount += 1\t\n\tend\n\t\n\tcount = 1 if count == 0\n\t\n\tcount\nend\n\nstones = gets.chomp.to_i\n\nputs calc(stones)"}, {"source_code": "n=gets.to_i;p n/3*2+[0,1,1][n%3]"}, {"source_code": "\nn = gets.to_i\nbegin\n puts n%3 == 0 ? n/3 * 2 : n/3 * 2 + 1\nrescue\nend\n"}, {"source_code": "#! ruby\n# Try Codeforces\n# author: Leonardone @ NEETSDKASU\n############################################################\ndef gs() gets.chomp end\ndef gi() gets.to_i end\ndef gss() gs.split end\ndef gis() gss.map(&:to_i) end\ndef nmapf(n,f) n.times.map{ __send__ f } end\ndef ngs(n) nmapf n,:gs end\ndef ngi(n) nmapf n,:gi end\ndef ngss(n) nmapf n,:gss end\ndef ngis(n) nmapf n,:gis end\ndef arr2d(h,w,v=0) h.times.map{[v] * w} end\ndef for2p(hr,wr,&pr) hr.each{|i|wr.each{|j| yield(i,j)}} end\ndef nsum(n) n * (n + 1) / 2 end\ndef vcount(d,r=Hash.new(0)) d.inject(r){|r,e| r[e]+=1;r} end\n############################################################\n\nn = gi\n\nif n < 3\n puts 1\n exit\nend\n\n=begin\n\nn = 3\n1 2\n\nn = 4\n1 2 1\n\nn = 5\n1 2 1\n\nn = 6\n1 2 1 2\n\nn = 7\n1 2 1 2 1\n\nn = 8\n1 2 1 2 1\n\nn = 9\n1 2 1 2 1 2\n\nn = 10\n1 2 1 2 1 2 1\n\nn = 11\n1 2 1 2 1 2 1\n\na n\n3 4 5\n4 6\n5 7 8\n6 9\n7 10 11\n8 12\n\n=end\n\nif n % 3 == 0\n n /= 3\n puts 2 * n\nelse\n n /= 3\n puts 2 * n + 1\nend\n"}, {"source_code": "n = readline.to_i\nct = n / 3\nct *= 2\nif n % 3 != 0\n ct += 1\nend\nputs ct\n"}, {"source_code": "a=gets.chomp.to_i\nans=((a/3.0).ceil)*2\nif a%3==0\nputs \"#{ans}\"\nelse\nputs \"#{ans-1}\"\nend"}, {"source_code": "n = gets.to_i\nans = n / 3 * 2\nif (n % 3 == 0) \n\tp ans\n\nelse \n\tp ans + 1\nend "}, {"source_code": "n = gets.to_i\n\nans = 0\n\nans += n/3 * 2\nn %= 3\n\nans += 1 if n > 0\n\nputs ans\n"}, {"source_code": "a=gets.chomp.to_i\nans=((a/3.0).ceil)*2\nif a%3==0\nputs \"#{ans}\"\nelse\nputs \"#{ans-1}\"\nend"}, {"source_code": "n = gets.chomp.to_i\n\n#if n % 2 == 1\n#\tn -= 1\n#end\n\nputs ((n - n % 3) / 3 * 2) + [n % 3, 1].min \n"}, {"source_code": "n = gets.chomp.to_i\n\na = n / 3\nb = n % 3\nif b != 0 then\n puts a * 2 + 1\nelse\n puts a * 2\nend\n"}, {"source_code": "n = gets.to_i\nputs n/3*2 + (n%3 + 2)/3\n"}, {"source_code": "n = gets.to_i\ncnt = (n / 3) * 2\nres = n % 3\ncnt += 1 if res >= 1\nputs cnt\n"}, {"source_code": "n = gets.to_i\n\nans = n / 3 * 2\nans += 1 if n % 3 != 0\nputs ans"}, {"source_code": "n=gets.to_i\nif n%3==0 #then\n p n/3*2\nelse\n p n/3*2+1\nend\n"}], "negative_code": [{"source_code": "stones = gets.chomp.to_i\n\nthrees = (stones / 3).to_i\n\nremaining = stones - (threes * 3)\n\ncount = threes * 2\n\ncount += 1 if remaining == 1\n\ncount = 1 if count == 0\n\nputs count"}, {"source_code": "n=gets.to_i;p (2*n)/3+([0,1,1][n%3])"}, {"source_code": "n=gets.to_i;p (2*n)/3+[0,1,1][n%3]"}, {"source_code": "\nn = gets.to_i\nbegin\n puts n%3 == 0 ? n/3 : n/3 + 1\nrescue\nend\n"}, {"source_code": "#! ruby\n# Try Codeforces\n# author: Leonardone @ NEETSDKASU\n############################################################\ndef gs() gets.chomp end\ndef gi() gets.to_i end\ndef gss() gs.split end\ndef gis() gss.map(&:to_i) end\ndef nmapf(n,f) n.times.map{ __send__ f } end\ndef ngs(n) nmapf n,:gs end\ndef ngi(n) nmapf n,:gi end\ndef ngss(n) nmapf n,:gss end\ndef ngis(n) nmapf n,:gis end\ndef arr2d(h,w,v=0) h.times.map{[v] * w} end\ndef for2p(hr,wr,&pr) hr.each{|i|wr.each{|j| yield(i,j)}} end\ndef nsum(n) n * (n + 1) / 2 end\ndef vcount(d,r=Hash.new(0)) d.inject(r){|r,e| r[e]+=1;r} end\n############################################################\n\nn = gi\n\nif n < 3\n puts 1\n exit\nend\n\n=begin\n\nn = 3\n1 2\n\nn = 4\n1 2 1\n\nn = 5\n1 2 1\n\nn = 6\n1 2 1 2\n\nn = 7\n1 2 1 2 1\n\nn = 8\n1 2 1 2 1\n\nn = 9\n1 2 1 2 1 2\n\nn = 10\n1 2 1 2 1 2 1\n\na n\n3 4 5\n4 6\n5 7 8\n6 9\n7 10 11\n8 12\n\n=end\n\nif n % 3 == 0\n puts 2 * n / 3\nelse\n puts 2 * n / 3 + 1\nend"}, {"source_code": "n = readline.to_i\nct = n / 3\nif n % 3 != 0\n ct += 1\nend\nputs ct\n"}], "src_uid": "a993069e35b35ae158d35d6fe166aaef"} {"nl": {"description": "In the city of Ultima Thule job applicants are often offered an IQ test. The test is as follows: the person gets a piece of squared paper with a 4\u2009\u00d7\u20094 square painted on it. Some of the square's cells are painted black and others are painted white. Your task is to repaint at most one cell the other color so that the picture has a 2\u2009\u00d7\u20092 square, completely consisting of cells of the same color. If the initial picture already has such a square, the person should just say so and the test will be completed. Your task is to write a program that determines whether it is possible to pass the test. You cannot pass the test if either repainting any cell or no action doesn't result in a 2\u2009\u00d7\u20092 square, consisting of cells of the same color.", "input_spec": "Four lines contain four characters each: the j-th character of the i-th line equals \".\" if the cell in the i-th row and the j-th column of the square is painted white, and \"#\", if the cell is black.", "output_spec": "Print \"YES\" (without the quotes), if the test can be passed and \"NO\" (without the quotes) otherwise.", "sample_inputs": ["####\n.#..\n####\n....", "####\n....\n####\n...."], "sample_outputs": ["YES", "NO"], "notes": "NoteIn the first test sample it is enough to repaint the first cell in the second row. After such repainting the required 2\u2009\u00d7\u20092 square is on the intersection of the 1-st and 2-nd row with the 1-st and 2-nd column."}, "positive_code": [{"source_code": "res = \"NO\"\ndata = []\n\n4.times do\n s = gets.split(\"\")\n data << s\nend\n\n3.times do |i|\n if data[1][i] == data[1][i+1] then\n if data[0][i] == data[1][i] || data[0][i+1] == data[1][i] then\n res = \"YES\"\n end\n if data[2][i] == data[1][i] || data[2][i+1] == data[1][i] then\n res = \"YES\"\n end\n end\nend\n\nif res == \"NO\" then\n 3.times do |i|\n if data[-1][i] == data[-1][i+1] then\n if data[2][i] == data[1][i] || data[2][i+1] == data[1][i] then\n res = \"YES\"\n end\n end\n end\nend\n\nputs res"}, {"source_code": "s1 = gets.split(\"\")\ns2 = gets.split(\"\")\ns3 = gets.split(\"\")\ns4 = gets.split(\"\")\ns= s1.zip(s2,s3,s4)\n\nyes=false\ni=0\n3.times do\n j=0\n 3.times do\n count=0\n if s[i][j]=='#'\n count+=1\n end\n if s[i+1][j]=='#'\n count+=1\n end\n if s[i+1][j+1]=='#'\n count+=1\n end\n if s[i][j+1]=='#'\n count+=1\n end\n if count!=2\n yes=true\n break\n end\n j+=1\n end\n i+=1\nend\n\n\nif yes\n puts \"YES\"\nelse\n puts \"NO\"\nend\n"}, {"source_code": "matrix = []\n4.times { matrix << gets.chomp.chars.to_a }\n\ntiles = []\n(0..2).each do |i|\n (0..2).each do |j|\n tiles << [matrix[i][j], matrix[i][j+1], matrix[i+1][j], matrix[i+1][j+1]]\n end\nend\n\nfreq = tiles.map { |t| [t.count('.'), t.count('#')].max }\n\nprint freq.max >= 3 ? \"YES\" : \"NO\""}, {"source_code": "#!/usr/bin/ruby1.9\n\ngrid = []\n\n4.times do\n\tgrid.push(STDIN.readline.strip)\nend\n\n3.times do |r|\n\t3.times do |c|\n\t\tcount = 0\n\t\tcount += 1 if grid[r][c] == '.'\n\t\tcount += 1 if grid[r+1][c] == '.'\n\t\tcount += 1 if grid[r][c+1] == '.'\n\t\tcount += 1 if grid[r+1][c+1] == '.'\n\t\tnext if count == 2\n\t\tputs 'YES'\n\t\texit\n\tend\nend\n\nputs 'NO'\n"}, {"source_code": "def run\n ary = []\n $stdin.readlines.each do |line|\n ary << line.split(//)\n end\n\n 3.times do |x|\n 3.times do |y|\n if [ary[x][y], ary[x+1][y], ary[x][y+1], ary[x+1][y+1]].select {|x| x == '#'}.length != 2\n $stdout.puts \"YES\"\n return\n end\n end\n end\n $stdout.puts \"NO\"\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "class A\n def initialize\n @cells = []\n @list = [[1,1],[1,2],[2,1],[2,2]]\n @pos1 = [[-1,0],[-1,1],[0,1]]\n @pos2 = [[-1,0],[-1,-1],[0,-1]]\n @pos3 = [[0,-1],[1,-1],[1,0]]\n @pos4 = [[0,1],[1,1],[1,0]]\n 4.times do\n @cells << $stdin.gets.chomp.split('')\n end\n\n check\n puts \"NO\"\n end\n\n def check\n flag = false\n @list.each do |elem|\n y = elem[0]\n x = elem[1]\n\n flag ||= right_up(y, x)\n flag ||= left_up(y, x)\n flag ||= left_up(y, x)\n flag ||= right_down(y, x)\n\n if flag \n puts \"YES\"\n exit\n end\n end\n end\n\n def right_up(ypos,xpos)\n white = 0\n black = 0\n if @cells[ypos][xpos] == \"#\"\n black += 1\n else\n white += 1\n end\n\n @pos1.each do |pos|\n y = pos[0]\n x = pos[1]\n\n if @cells[ypos+y][xpos+x] == \"#\"\n black += 1\n else\n white += 1\n end\n\n end\n if black >= 3 || white >= 3\n true\n else\n false\n end\n end\n\n def left_up(ypos,xpos)\n white = 0\n black = 0\n if @cells[ypos][xpos] == \"#\"\n black += 1\n else\n white += 1\n end\n\n @pos2.each do |pos|\n y = pos[0]\n x = pos[1]\n\n if @cells[ypos+y][xpos+x] == \"#\"\n black += 1\n else\n white += 1\n end\n\n end\n if black >= 3 || white >= 3\n true\n else\n false\n end\n end\n def left_down(ypos,xpos)\n white = 0\n black = 0\n if @cells[ypos][xpos] == \"#\"\n black += 1\n else\n white += 1\n end\n\n @pos3.each do |pos|\n y = pos[0]\n x = pos[1]\n\n if @cells[ypos+y][xpos+x] == \"#\"\n black += 1\n else\n white += 1\n end\n\n end\n if black >= 3 || white >= 3\n true\n else\n false\n end\n end\n\n def right_down(ypos,xpos)\n white = 0\n black = 0\n if @cells[ypos][xpos] == \"#\"\n black += 1\n else\n white += 1\n end\n\n @pos4.each do |pos|\n y = pos[0]\n x = pos[1]\n\n if @cells[ypos+y][xpos+x] == \"#\"\n black += 1\n else\n white += 1\n end\n end\n if black >= 3 || white >= 3\n true\n else\n false\n end\n end\nend\n\na = A.new"}, {"source_code": "a=[]\n4.times do\na << gets.chomp.split(\"\")\nend\nans=0\n0.upto(2) do |i|\n0.upto(2) do |j|\nw=0\nb=0\nif a[i][j]==\"#\"\nb+=1\nelse \nw+=1\nend\nif a[i+1][j]==\"#\"\nb+=1\nelse \nw+=1\nend\nif a[i][j+1]==\"#\"\nb+=1\nelse \nw+=1\nend\nif a[i+1][j+1]==\"#\"\nb+=1\nelse \nw+=1\nend\nif w>2 || b>2\nans=1\nend\nbreak if ans==1\nend\nbreak if ans==1\nend\nif ans==1\nputs \"YES\"\nelse \nputs \"NO\"\nend\n"}, {"source_code": "a=[]\n4.times do\na << gets.chomp.split(\"\")\nend\nans=0\n0.upto(2) do |i|\n0.upto(2) do |j|\nw=0\nb=0\nif a[i][j]==\"#\"\nb+=1\nelse \nw+=1\nend\nif a[i+1][j]==\"#\"\nb+=1\nelse \nw+=1\nend\nif a[i][j+1]==\"#\"\nb+=1\nelse \nw+=1\nend\nif a[i+1][j+1]==\"#\"\nb+=1\nelse \nw+=1\nend\nif w>2 || b>2\nans=1\nend\nbreak if ans==1\nend\nbreak if ans==1\nend\nif ans==1\nputs \"YES\"\nelse \nputs \"NO\"\nend"}, {"source_code": "A = [gets, gets, gets, gets]\ndef rr(t)\n if (t[0] == t[1] and t[1] == t[2] and t[2] == t[3]) then return true end\n t = t.chars.partition { |x| x == '.' }\n if t[0].length == 1 or t[0].length == 3 then return true end\n return false\nend\ndef solve()\n i, j = 0, 0\n while i != 3\n if rr(A[i][j] + A[i][j+1] + A[i+1][j] + A[i+1][j+1]) then return \"YES\" end\n j = j+1\n if j == 3 then i, j = i+1, 0 end\n end\n return \"NO\"\nend\nputs solve()\n"}, {"source_code": "a = 4.times.map { gets.chop }\n3.times do |i|\n 3.times do |j|\n if [a[i][j], a[i][j+1], a[i+1][j], a[i+1][j+1]].count('#') != 2\n puts 'YES'\n exit\n end\n end\nend\nputs 'NO'\n"}, {"source_code": "lines = [\"\"]*4\nlines[0] = gets.chomp.split(\"\")\nlines[1] = gets.chomp.split(\"\")\nlines[2] = gets.chomp.split(\"\")\nlines[3] = gets.chomp.split(\"\")\n\ns = \"\"\nt = \"\"\nok = false\n(0..2).each {|l|\n\t(0..2).each {|c|\n\t\ts = \"#{lines[l][c]}#{lines[l][c+1]}#{lines[l+1][c]}#{lines[l+1][c+1]}\"\n\t\tt = s.gsub(\".\",\"\")\n\t\tif t.length==4 or t.length==3 or t.length==1 or t.length==0 \n\t\t\tok=true\n\t\tend\n\t}\n}\n\nif ok\n\tputs \"YES\"\nelse\n\tputs \"NO\"\nend"}, {"source_code": "m = Array.new\n\n4.times do\n m << gets.chomp\nend\n\n3.times do |y|\n 3.times do |x|\n c = (m[y][x] + m[y+1][x] + m[y][x+1] + m[y+1][x+1]).delete(\".\").length\n unless c == 2\n puts 'YES'\n exit 0\n end\n end\nend\n\nputs 'NO'\n"}, {"source_code": "a=[]\n4.times do\na << gets.chomp.split(\"\")\nend\nans=0\n0.upto(2) do |i|\n0.upto(2) do |j|\nw=0\nb=0\nif a[i][j]==\"#\"\nb+=1\nelse \nw+=1\nend\nif a[i+1][j]==\"#\"\nb+=1\nelse \nw+=1\nend\nif a[i][j+1]==\"#\"\nb+=1\nelse \nw+=1\nend\nif a[i+1][j+1]==\"#\"\nb+=1\nelse \nw+=1\nend\nif w>2 || b>2\nans=1\nend\nbreak if ans==1\nend\nbreak if ans==1\nend\nif ans==1\nputs \"YES\"\nelse \nputs \"NO\"\nend"}, {"source_code": "a=[*$<]\nputs ([0,1,2].product([0,1,2]).map{|x,y|\n [x,x+1].product([y,y+1]).count{|u,v| a[u][v]=='#'}\n} - [2]).empty? ? :NO : :YES"}], "negative_code": [{"source_code": "A = [gets, gets, gets, gets]\ndef rr(t)\n t = t.chars.sort {|x,y| y <=> x}.join\n puts t\n if (t[0] == t[1] and t[1] == t[2] and t[2] == t[3]) then return true end\n if t[0] != t[1] then return true end\n return false\nend\ndef solve()\n i, j = 0, 0\n while i != 3\n if rr(A[i][j] + A[i][j+1] + A[i+1][j] + A[i+1][j+1]) then return \"YES\" end\n j = j+1\n if j == 3 then i, j = i+1, 0 end\n end\n return \"NO\"\nend\nputs solve()\n"}, {"source_code": "A = [gets, gets, gets, gets]\ndef rr(t)\n t = t.chars.sort {|x,y| y <=> x}.join\n if (t[0] == t[1] and t[1] == t[2] and t[2] == t[3]) then return true end\n if t[0] != t[1] then return true end\n return false\nend\ndef solve()\n i, j = 0, 0\n while i != 3\n if rr(A[i][j] + A[i][j+1] + A[i+1][j] + A[i+1][j+1]) then return \"YES\" end\n j = j+1\n if j == 3 then i, j = i+1, 0 end\n end\n return \"NO\"\nend\nputs solve()\n"}, {"source_code": "m = Array.new\n\n4.times do\n m << gets.chomp\nend\n\n3.times do |y|\n 3.times do |x|\n if (m[y][x] + m[y+1][x] + m[y][x+1] + m[y+1][x+1]).delete(\".\").length >= 3\n puts 'YES'\n exit 0\n end\n end\nend\n\nputs 'NO'\n"}, {"source_code": "a=[*$<]\nputs [0,1,2].product([0,1,2]).map{|x,y| [x,x+1].product([y,y+1]).count{|u,v| a[u][v]=='#'} }.max >= 3 ? :YES : :NO"}], "src_uid": "01b145e798bbdf0ca2ecc383676d79f3"} {"nl": {"description": "PolandBall is a young, clever Ball. He is interested in prime numbers. He has stated a following hypothesis: \"There exists such a positive integer n that for each positive integer m number n\u00b7m\u2009+\u20091 is a prime number\".Unfortunately, PolandBall is not experienced yet and doesn't know that his hypothesis is incorrect. Could you prove it wrong? Write a program that finds a counterexample for any n.", "input_spec": "The only number in the input is n (1\u2009\u2264\u2009n\u2009\u2264\u20091000)\u00a0\u2014 number from the PolandBall's hypothesis. ", "output_spec": "Output such m that n\u00b7m\u2009+\u20091 is not a prime number. Your answer will be considered correct if you output any suitable m such that 1\u2009\u2264\u2009m\u2009\u2264\u2009103. It is guaranteed the the answer exists.", "sample_inputs": ["3", "4"], "sample_outputs": ["1", "2"], "notes": "NoteA prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself.For the first sample testcase, 3\u00b71\u2009+\u20091\u2009=\u20094. We can output 1.In the second sample testcase, 4\u00b71\u2009+\u20091\u2009=\u20095. We cannot output 1 because 5 is prime. However, m\u2009=\u20092 is okay since 4\u00b72\u2009+\u20091\u2009=\u20099, which is not a prime number."}, "positive_code": [{"source_code": "n = gets.chomp.to_i\ncase n\nwhen 1\n puts 3\nwhen 2\n puts 4\nelse\n puts (n - 2)\nend\n"}, {"source_code": "require'prime';n=gets.to_i;p (1..1/0.0).find{|i|!(n*i+1).prime?}"}, {"source_code": "n=gets.to_i;p n>2?n-2:n+2"}, {"source_code": "n = gets.to_i\nputs n <= 2 ? n + 2 : n - 2\n"}, {"source_code": "def prime(n)\n\treturn false if n == 0 || n == 1\n\n\ti = 2\n\twhile i * i <= n \n\t\treturn false if n % i == 0\n\t\ti += 1\n\tend\n\n\treturn true\nend\n\ndef main\n\tn = gets.to_i\n\n\tfor m in (1..1000)\n\t\tif not prime(n * m + 1)\n\t\t\tputs m\n\t\t\tbreak\n\t\tend\n\tend\nend\n\nmain"}, {"source_code": "require 'prime'\nn = gets.strip.to_i\nans = 1\nif n > 2\n (1..n).each do |i|\n if !Prime.prime?(n * i + 1)\n ans = i\n break\n end\n end\nelse\n ans = n + 2\nend\nputs ans\n"}, {"source_code": "require 'prime'\nn=gets.to_i\nm=1\nwhile Prime.prime?(n*m+1)\n\tm+=1\nend\nputs m"}, {"source_code": "require 'prime'\nn= gets.to_i\n\nfor i in 1..1000\n if !(Prime.prime?((i*n) + 1))\n print i\n break\n end\nend\n"}, {"source_code": "require 'prime'\nn=gets.to_i\nfor m in 1..999\n unless (n*m+1).prime?\n p m\n break\n end\nend\n"}, {"source_code": "require 'prime'\nN = gets.to_i\n(1..1000).each { |i| next if Prime.prime? N * i + 1\n p i\n exit\n}\n"}, {"source_code": "require'prime'\nN=gets.to_i\np (1..1000).find{|i|!Prime.prime?N*i+1}"}, {"source_code": "n=gets.chomp.to_i\ndef is_prime(a)\n i=2\n while i*i<=a do\n return 0 if a % i == 0\n #ruby\u4e0d\u652f\u6301++\u8fd0\u7b97\uff01\n i += 1\n end\n return 1\nend\ni=1\nwhile true do\n #print \"#{i} \"\n #puts i*n+1\n #if i==5 break end\n #get_character\n #puts is_prime(i*n+1)\n\n if is_prime(i*n+1) == 1\n i+=1\n else\n puts i\n break\n end\nend\n"}, {"source_code": "#!/usr/bin/env ruby\n\nrequire 'prime'\n\nn = gets.chop.to_i\n\nm = 1\nwhile m < 10**3 do\n result = m * n + 1\n break unless result.prime?\n m += 1\nend\n\nputs m\n"}, {"source_code": "n=gets.to_i;p n>2?n-2:n+2"}], "negative_code": [{"source_code": "def prime(n)\n\treturn false if n == 0 || n == 1\n\n\ti = 2\n\twhile i * i <= n \n\t\treturn false if n % i == 0\n\t\ti += 1\n\tend\n\n\treturn true\nend\n\ndef main\n\tn = gets.to_i\n\n\tfor m in (1..1000)\n\t\tif prime(n * m + 1)\n\t\t\tputs m\n\t\t\tbreak\n\t\tend\n\tend\nend\n\nmain"}, {"source_code": "require 'prime'\n\nn = gets.strip.to_i\nans = 0\n(1..n).each do |i|\n if !Prime.prime?(n * i + 1)\n ans = i\n break\n end\nend\nputs ans\n"}, {"source_code": "require 'prime'\n\nn = gets.strip.to_i\nans = 1\n(1..n).each do |i|\n if !Prime.prime?(n * i + 1)\n ans = i\n break\n end\nend\nputs ans\n"}, {"source_code": "p 4+gets.to_i%2"}, {"source_code": "require 'prime'\nN = gets.to_i\n(1..1000).each { |i| next if Prime.prime? N * i + 1\n at_exit { p i }\n}\n"}, {"source_code": "n=gets.chomp.to_i\ndef is_prime(a)\n i=2\n while i*i<=a do\n return 0 if a % i == 0\n #ruby\u4e0d\u652f\u6301++\u8fd0\u7b97\uff01\n i += 1\n end\n return 1\nend\ni=1\nwhile true do\n #print \"#{i} \"\n #puts i*n+1\n if i==5\n break\n end\n #get_character\n #puts is_prime(i*n+1)\n\n if is_prime(i*n+1) == 1\n i+=1\n else\n puts i\n break\n end\nend\n"}], "src_uid": "5c68e20ac6ecb7c289601ce8351f4e97"} {"nl": {"description": "You know that Japan is the country with almost the largest 'electronic devices per person' ratio. So you might be quite surprised to find out that the primary school in Japan teaches to count using a Soroban \u2014 an abacus developed in Japan. This phenomenon has its reasons, of course, but we are not going to speak about them. Let's have a look at the Soroban's construction. Soroban consists of some number of rods, each rod contains five beads. We will assume that the rods are horizontal lines. One bead on each rod (the leftmost one) is divided from the others by a bar (the reckoning bar). This single bead is called go-dama and four others are ichi-damas. Each rod is responsible for representing a single digit from 0 to 9. We can obtain the value of a digit by following simple algorithm: Set the value of a digit equal to 0. If the go-dama is shifted to the right, add 5. Add the number of ichi-damas shifted to the left. Thus, the upper rod on the picture shows digit 0, the middle one shows digit 2 and the lower one shows 7. We will consider the top rod to represent the last decimal digit of a number, so the picture shows number 720.Write the program that prints the way Soroban shows the given number n.", "input_spec": "The first line contains a single integer n (0\u2009\u2264\u2009n\u2009<\u2009109).", "output_spec": "Print the description of the decimal digits of number n from the last one to the first one (as mentioned on the picture in the statement), one per line. Print the beads as large English letters 'O', rod pieces as character '-' and the reckoning bar as '|'. Print as many rods, as many digits are in the decimal representation of number n without leading zeroes. We can assume that number 0 has no leading zeroes.", "sample_inputs": ["2", "13", "720"], "sample_outputs": ["O-|OO-OO", "O-|OOO-O\nO-|O-OOO", "O-|-OOOO\nO-|OO-OO\n-O|OO-OO"], "notes": null}, "positive_code": [{"source_code": "#!/usr/bin/ruby\nT=[\n\t'O-|-OOOO',\n\t'O-|O-OOO',\n\t'O-|OO-OO',\n\t'O-|OOO-O',\n\t'O-|OOOO-',\n\t'-O|-OOOO',\n\t'-O|O-OOO',\n\t'-O|OO-OO',\n\t'-O|OOO-O',\n\t'-O|OOOO-',\n]\ngets.chomp.reverse.chars{|e|puts T[e.to_i]}"}, {"source_code": "str = gets.chomp\nstr.reverse.split(//).each do |c|\n if c.to_i >= 5\n print \"-O|\"\n else\n print \"O-|\"\n end\n tmp = (c.to_i - 5 < 0 ? c.to_i : c.to_i - 5)\n case tmp\n when 0 then\n puts \"-OOOO\"\n when 1 then \n puts \"O-OOO\"\n when 2 then \n puts \"OO-OO\"\n when 3 then \n puts \"OOO-O\"\n when 4 then \n puts \"OOOO-\"\n else\n puts \"-OOOO\"\n end\nend\n"}, {"source_code": "n = gets.chomp.to_i\ndigits = [\"O-|-OOOO\", \"O-|O-OOO\", \"O-|OO-OO\", \"O-|OOO-O\", \"O-|OOOO-\", \"-O|-OOOO\", \"-O|O-OOO\",\n \"-O|OO-OO\", \"-O|OOO-O\", \"-O|OOOO-\"]\nans = []\nif n == 0\n puts digits[0]\nelse\n while n > 0\n last = n % 10\n ans << digits[last]\n n -= last\n n /= 10\n end\n ans.each do |a|\n puts a\n end\nend\n"}, {"source_code": "a=gets.chomp.split(\"\")\n0.upto(a.length-1) {|i| a[i]=a[i].to_i}\na.reverse!\na.each do |i|\nans=(\"O\"*(1-i/5))+\"-\"+(\"O\"*(i/5))+\"|\"+(\"O\"*(i%5))+\"-\"+(\"O\"*(4-(i%5)))\nputs ans\nend"}, {"source_code": "n = gets.chomp.to_i\n\nputs \"O-|-OOOO\" if n == 0\nwhile n != 0 do\n i = n%10\n row = \"\"\n if i < 5\n row += \"O-|\"\n else\n i = i - 5\n row += \"-O|\"\n end\n case i\n when 0\n row += \"-OOOO\"\n when 1\n row += \"O-OOO\"\n when 2\n row += \"OO-OO\"\n when 3\n row += \"OOO-O\"\n when 4\n row += \"OOOO-\"\n end\n puts row\n n = n/10\nend\n"}, {"source_code": "n = gets.chomp\nrep = {0 => 'O-|-OOOO', \n 1 => 'O-|O-OOO', \n 2 => 'O-|OO-OO', \n 3 => 'O-|OOO-O', \n 4 => 'O-|OOOO-', \n 5 => '-O|-OOOO', \n 6 => '-O|O-OOO', \n 7 => '-O|OO-OO', \n 8 => '-O|OOO-O', \n 9 => '-O|OOOO-'\n}\n\narr = []\nn.each_char do |c|\n\tarr << rep[c.to_i]\nend\narr.reverse!\narr.each do |a|\n\tputs a\nend"}, {"source_code": "digital = {'0'=>'O-|-OOOO', '1'=>'O-|O-OOO', '2'=>'O-|OO-OO', '3'=>'O-|OOO-O', '4'=>'O-|OOOO-',\\\n '5'=>'-O|-OOOO', '6'=>'-O|O-OOO', '7'=>'-O|OO-OO', '8'=>'-O|OOO-O', '9'=>'-O|OOOO-'}\nn = gets.chomp.split('')\nn.reverse.each{|i| puts digital[i]}\n"}, {"source_code": "def rod(d)\n if d < 5\n print \"O-\"\n else\n print \"-O\"\n d -= 5\n end\n print \"|\"\n remain = 4-d\n while d > 0\n print \"O\"\n d -= 1\n end\n print \"-\"\n while remain > 0\n print \"O\"\n remain -= 1\n end\n puts \"\"\nend\n\ngets.strip.reverse.each_char do |c|\n d = c.to_i\n rod(d)\nend\n"}, {"source_code": "gets.chomp.split('').map { |x| x.to_i }.reverse.each { |x|\n left = x < 5 ? 'O-' : '-O'\n m = x % 5\n right = 'O' * m + '-' + 'O' * (4 - m)\n puts left + '|' + right\n}"}, {"source_code": "#f = File.open('test1.txt', 'r')\na = {\n '0' => 'O-|-OOOO',\n '1' => 'O-|O-OOO',\n '2' => 'O-|OO-OO',\n '3' => 'O-|OOO-O',\n '4' => 'O-|OOOO-',\n '5' => '-O|-OOOO',\n '6' => '-O|O-OOO',\n '7' => '-O|OO-OO',\n '8' => '-O|OOO-O',\n '9'=> '-O|OOOO-'\n}\nwhile(s = gets)\n s.chomp.reverse.chars.each do |ch|\n puts a[ch]\n end\nend"}, {"source_code": "n = gets.chomp.to_i\n\ndef draw(i)\n str = \"\"\n if i >= 5\n str = \"-O|\"\n else\n str = \"O-|\"\n end\n\n (i % 5).times do\n str += \"O\"\n end\n\n str += \"-\"\n (4 - (i % 5)).times do\n str += \"O\"\n end\n puts str\nend\n\nif n == 0\n draw(n)\nend\n\nwhile n != 0\n draw(n % 10)\n n /= 10\nend\n"}, {"source_code": "String.class_eval do\n ROD = %w[\n O-|-OOOO O-|O-OOO O-|OO-OO O-|OOO-O O-|OOOO-\n -O|-OOOO -O|O-OOO -O|OO-OO -O|OOO-O -O|OOOO-\n ]\n def soroban\n self.each_char{|s|puts ROD[s.to_i]}\n end\nend\n\ngets.chop.reverse.soroban\n"}], "negative_code": [{"source_code": "# encoding: utf-8\n\nstr = gets.chomp\nstr.reverse.split(//).each do |c|\n if c.to_i >= 5\n print \"-0|\"\n else\n print \"0-|\"\n end\n tmp = (c.to_i - 5 < 0 ? c.to_i : c.to_i - 5)\n case tmp\n when 0 then\n puts \"-0000\"\n when 1 then \n puts \"0-000\"\n when 2 then \n puts \"00-00\"\n when 3 then \n puts \"000-0\"\n when 4 then \n puts \"0000-\"\n else\n puts \"-0000\"\n end\nend\n"}, {"source_code": "n = gets.chomp.to_i\ndigits = [\"O-|-OOOO\", \"O-|O-OOO\", \"O-|OO-OO\", \"O-|OOO-O\", \"O-|OOOO-\", \"-O|-OOOO\", \"-O|O-OOO\",\n \"-O|OO-OO\", \"-O|OOO-O\", \"-O|OOOO-\"]\nans = []\nwhile n > 0\n last = n % 10\n ans << digits[last]\n n -= last\n n /= 10\nend\nans.each do |a|\n puts a\nend\n"}, {"source_code": "a=gets.chomp.split(\"\")\n0.upto(a.length-1) {|i| a[i]=a[i].to_i}\na.reverse!\na.each do |i|\nif i>=5\np=1\nq=0\nelse \np=0\nq=1\nend\nans=(\"o\"*(1-i/5))+\"-\"+(\"o\"*(i/5))+\"|\"+(\"o\"*(i%5))+\"-\"+(\"o\"*(4-(i%5)))\nputs ans\n\nend"}, {"source_code": "n = gets.chomp.to_i\nwhile n != 0 do\n i = n%10\n row = \"\"\n if i < 5\n row += \"O-|\"\n else\n i = i - 5\n row += \"-O|\"\n end\n case i\n when 0\n row += \"-OOOO\"\n when 1\n row += \"O-OOO\"\n when 2\n row += \"OO-OO\"\n when 3\n row += \"OOO-O\"\n when 4\n row += \"OOOO-\"\n end\n puts row\n n = n/10\nend\n"}, {"source_code": "n = gets.chomp\nrep = {0 => '0-|-0000', \n 1 => '0-|0-000', \n 2 => '0-|00-00', \n 3 => '0-|000-0', \n 4 => '0-|0000-', \n 5 => '-0|-0000', \n 6 => '-0|0-000', \n 7 => '-0|00-00', \n 8 => '-0|000-0', \n 9 => '-0|0000-'\n}\n\narr = []\nn.each_char do |c|\n\tarr << rep[c.to_i]\nend\narr.reverse!\narr.each do |a|\n\tputs a\nend"}, {"source_code": "gets.chomp.split('').map { |x| x.to_i }.reverse.each { |x|\n left = x < 5 ? '0-' : '-0'\n m = x % 5\n right = '0' * m + '-' + '0' * (4 - m)\n puts left + '|' + right\n}"}, {"source_code": "#f = File.open('test1.txt', 'r')\na = {\n '0' => 'O-|-OOOO',\n '1' => 'O-|O-OOO',\n '2' => 'O-|OO-OO',\n '3' => 'O-|OOO-O',\n '4' => 'O-|OOOO-',\n '5' => '-O|-OOOO',\n '6' => '-O|O-OOO',\n '7' => '-O|OO-OO',\n '8' => '-O|OOO-O',\n '9'=> '-O|OOOO-'\n}\nwhile(s = gets)\n s.chomp.reverse.chars.each do |ch|\n p a[ch]\n end\nend"}, {"source_code": "n = gets.chomp.to_i\n\ndef draw(i)\n str = \"\"\n if i >= 5\n str = \"-0|\"\n else\n str = \"0-|\"\n end\n\n (i % 5).times do\n str += \"0\"\n end\n\n str += \"-\"\n (4 - (i % 5)).times do\n str += \"0\"\n end\n puts str\nend\n\nwhile n != 0\n draw(n % 10)\n n /= 10\nend\n"}, {"source_code": "n = gets.chomp.to_i\n\ndef draw(i)\n str = \"\"\n if i >= 5\n str = \"-O|\"\n else\n str = \"O-|\"\n end\n\n (i % 5).times do\n str += \"O\"\n end\n\n str += \"-\"\n (4 - (i % 5)).times do\n str += \"O\"\n end\n puts str\nend\n\nwhile n != 0\n draw(n % 10)\n n /= 10\nend\n"}], "src_uid": "c2e3aced0bc76b6484360563355d23a7"} {"nl": {"description": "Manao is taking part in a quiz. The quiz consists of n consecutive questions. A correct answer gives one point to the player. The game also has a counter of consecutive correct answers. When the player answers a question correctly, the number on this counter increases by 1. If the player answers a question incorrectly, the counter is reset, that is, the number on it reduces to 0. If after an answer the counter reaches the number k, then it is reset, and the player's score is doubled. Note that in this case, first 1 point is added to the player's score, and then the total score is doubled. At the beginning of the game, both the player's score and the counter of consecutive correct answers are set to zero.Manao remembers that he has answered exactly m questions correctly. But he does not remember the order in which the questions came. He's trying to figure out what his minimum score may be. Help him and compute the remainder of the corresponding number after division by 1000000009 (109\u2009+\u20099).", "input_spec": "The single line contains three space-separated integers n, m and k (2\u2009\u2264\u2009k\u2009\u2264\u2009n\u2009\u2264\u2009109;\u00a00\u2009\u2264\u2009m\u2009\u2264\u2009n).", "output_spec": "Print a single integer \u2014 the remainder from division of Manao's minimum possible score in the quiz by 1000000009 (109\u2009+\u20099).", "sample_inputs": ["5 3 2", "5 4 2"], "sample_outputs": ["3", "6"], "notes": "NoteSample 1. Manao answered 3 questions out of 5, and his score would double for each two consecutive correct answers. If Manao had answered the first, third and fifth questions, he would have scored as much as 3 points.Sample 2. Now Manao answered 4 questions. The minimum possible score is obtained when the only wrong answer is to the question 4.Also note that you are asked to minimize the score and not the remainder of the score modulo 1000000009. For example, if Manao could obtain either 2000000000 or 2000000020 points, the answer is 2000000000\u00a0mod\u00a01000000009, even though 2000000020\u00a0mod\u00a01000000009 is a smaller number."}, "positive_code": [{"source_code": "require 'openssl'\n\nn, m, k = gets.chomp.split(' ').map(&:to_i)\nd = 1000000009\nx = [0, m - (n - n % k) / k * (k-1) - n % k].max\n\nr = 2.to_bn.mod_exp(x+1, d)\nr = (r-2)*k % d\nr = (r + (m-x*k)) % d\n\nwhile r < 0 \n\tr += d\nend\n\nputs r"}, {"source_code": "require 'openssl'\nMOD = 10 ** 9 + 9\nn, m, k = gets.chop.split.map(&:to_i)\nextra = n - m\nif(extra * k >= n)\n print m % MOD\nelse\n st = n - extra * k\n cnt = st / k\n rest = st % k\n total = ((2.to_bn.mod_exp(cnt + 1,MOD) - 2 + MOD) % MOD * k + rest + extra *(k - 1)) % MOD\n print total\nend\n"}, {"source_code": "MOD = 10 ** 9 + 9\ndef pow2(x)\n st = 1\n pow = 2\n while(x != 0)\n if((x & 1) != 0)\n st = (st * pow) % MOD\n end\n pow = (pow * pow) % MOD\n x >>= 1\n end\n return st\nend\nn, m, k = gets.chop.split.map(&:to_i)\nextra = n - m\nif(extra * k >= n)\n print m % MOD\nelse\n st = n - extra * k\n cnt = st / k\n rest = st % k\n total = pow2(cnt + 1)\n total = (total - 2 + MOD) % MOD\n total = (total * k + rest) % MOD\n total += extra * (k - 1)\n total %= MOD\n print total\nend\n"}, {"source_code": "require 'openssl'\nn,m,k=gets.split.map(&:to_i)\nd=10**9+9\np=n/k\nq=m-n+p\nif q<=0\n puts m\n exit\nend\nr=2.to_bn.mod_exp(q+1,d).to_i\nr=((d+r-2)%d*k+m-q*k)%d\np r\n"}, {"source_code": "module STL\n module Algorithm\n def power_mod(a, b, c) #compute (a ^ b) mod c\n ans, tich = 1, a\n while b > 0\n ans = (ans * tich) % c if b % 2 == 1\n tich = (tich * tich) % c\n b /= 2\n end\n ans\n end\n end\nend\n\ninclude STL::Algorithm\nMOD = 1000_000_009\ndef solve(f)\n n, m, k = f.gets.split.map(&:to_i)\n t = (n / k) * (k - 1) + n % k\n if m <= t\n puts m\n else\n a = m - t\n\n tmp = power_mod(2, (a + 1), MOD)\n puts (k * (tmp - 2) + m - a * k) % MOD\n end\nend\n\ndef debug\n (1..3).each do |e|\n f = File.new(\"test#{e}.txt\", 'r')\n solve f\n f.close\n end\nend\n\ndef release\n solve STDIN\nend\n\nrelease"}], "negative_code": [{"source_code": "require 'openssl'\n\nn, m, k = gets.chomp.split(' ').map(&:to_i)\nd = 1000000009\nx = [0, m - (n - n % k) / k * (k-1) - n % k].max\nputs x\n\nr = 2.to_bn.mod_exp(x+1, d)\nr = (r-2)*k % d\nr = (r + (m-x*k)) % d\n\nwhile r < 0 \n\tr += d\nend\n\nputs r"}, {"source_code": "n, m, k = gets.chomp.split(' ').map(&:to_i)\n\nx = [0, m - (n - n % k) / k * (k-1) - n % k].max\nr = (2**(x+1)-2)*k + m-x*k\n\nr = r % 1000000009\n\nputs r"}, {"source_code": "require 'openssl'\n\nn, m, k = gets.chomp.split(' ').map(&:to_i)\nd = 1000000009\nx = [0, m - (n - n % k) / k * (k-1) - n % k].max\n#puts x\n\nr = 2.to_bn.mod_exp(x+1, d)\nr = (r-2)*k % d\nr = (r + (m-x*k)) % d\n\nputs r"}, {"source_code": "MOD = 10 ** 9 + 9\nn, m, k = gets.chop.split.map(&:to_i)\nextra = n - m\ntotal = 0\nif(extra * k >= n)\n\tprint m % mod\nelse\n\tst = n - extra * k\n\t1.upto(st) do |i|\n\t\ttotal += 1\n\t\tif(i % k == 0)\n\t\t\ttotal *= 2\n\t\tend\n\tend\n\ttotal += extra * (k - 1)\n\tprint total\nend"}, {"source_code": "MOD = 10 ** 9 + 9\ndef pow2(x)\n st = 1\n pow = 2\n while(x != 0)\n if(x & 1)\n st = (st * pow) % MOD\n end\n pow = (pow * pow) % MOD\n x >>= 1\n end\n return st\nend\nn, m, k = gets.chop.split.map(&:to_i)\nextra = n - m\nif(extra * k >= n)\n print m % MOD\nelse\n st = n - extra * k\n cnt = st / k\n rest = st % k\n total = pow2(cnt)\n total = (total - 2 + MOD) % MOD\n total = (total * k + rest) % MOD\n total += extra * (k - 1)\n total %= MOD\n print total\nend\n"}, {"source_code": "MOD = 10 ** 9 + 9\nn, m, k = gets.chop.split.map(&:to_i)\nextra = n - m\nif(extra * k >= n)\n print m % MOD\nelse\n st = n - extra * k\n cnt = st / k\n rest = st % k\n total = (2 ** (cnt + 1) - 2) * k + rest\n total += extra * (k - 1)\n total %= MOD\n print total\nend\n"}, {"source_code": "require 'openssl'\nn,m,k=gets.split.map(&:to_i)\nd=10^9+9\np=n/k\nq=m-n+p\nif q<=0\n puts m\n exit\nend\nr=2.to_bn.mod_exp(q+1,d)\nr=((r-2)%d*k%d+m-q*k)%d\np r\n"}, {"source_code": "require 'openssl'\nn,m,k=gets.split.map(&:to_i)\nd=10^9+9\np=n/k\nq=m-n+p\nif q<=0\n puts m\n exit\nend\nr=2.to_bn.mod_exp(q+1,d).to_i\nr=((d+r-2)%d*k+m-q*k)%d\np r\n"}, {"source_code": "require 'openssl'\nn,m,k=gets.split.map(&:to_i)\nd=10^9+9\np=n/k\nq=m-n+p\nif q<=0\n puts m\n exit\nend\nr=2.to_bn.mod_exp(q+1,d).to_i\nr=((r-2)%d*k+m-q*k)%d\np r\n"}, {"source_code": "module Containers\n class Stack\n\n end\nend\n\nmodule Algorithm\n def pow_mod(a, b, c) #compute (a ^ b) mod c\n ans, tich = 1, a\n while b > 0\n ans = (ans * tich) % c if b % 2 == 1\n tich = (tich * tich) % c\n b /= 2\n end\n ans\n end\nend\n\ndef solve\n n, m, k = gets.split.map(&:to_i)\n t = (n / k) * (k - 1) + n % k\n if m <= t\n puts m\n else\n a = m - t\n puts k * ((1 << (a + 1)) - 2) + m - a * k\n end\nend\n\nsolve"}], "src_uid": "9cc1aecd70ed54400821c290e2c8018e"} {"nl": {"description": "Winnie-the-Pooh likes honey very much! That is why he decided to visit his friends. Winnie has got three best friends: Rabbit, Owl and Eeyore, each of them lives in his own house. There are winding paths between each pair of houses. The length of a path between Rabbit's and Owl's houses is a meters, between Rabbit's and Eeyore's house is b meters, between Owl's and Eeyore's house is c meters.For enjoying his life and singing merry songs Winnie-the-Pooh should have a meal n times a day. Now he is in the Rabbit's house and has a meal for the first time. Each time when in the friend's house where Winnie is now the supply of honey is about to end, Winnie leaves that house. If Winnie has not had a meal the required amount of times, he comes out from the house and goes to someone else of his two friends. For this he chooses one of two adjacent paths, arrives to the house on the other end and visits his friend. You may assume that when Winnie is eating in one of his friend's house, the supply of honey in other friend's houses recover (most probably, they go to the supply store).Winnie-the-Pooh does not like physical activity. He wants to have a meal n times, traveling minimum possible distance. Help him to find this distance.", "input_spec": "First line contains an integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009100)\u00a0\u2014 number of visits. Second line contains an integer a (1\u2009\u2264\u2009a\u2009\u2264\u2009100)\u00a0\u2014 distance between Rabbit's and Owl's houses. Third line contains an integer b (1\u2009\u2264\u2009b\u2009\u2264\u2009100)\u00a0\u2014 distance between Rabbit's and Eeyore's houses. Fourth line contains an integer c (1\u2009\u2264\u2009c\u2009\u2264\u2009100)\u00a0\u2014 distance between Owl's and Eeyore's houses.", "output_spec": "Output one number\u00a0\u2014 minimum distance in meters Winnie must go through to have a meal n times.", "sample_inputs": ["3\n2\n3\n1", "1\n2\n3\n5"], "sample_outputs": ["3", "0"], "notes": "NoteIn the first test case the optimal path for Winnie is the following: first have a meal in Rabbit's house, then in Owl's house, then in Eeyore's house. Thus he will pass the distance 2\u2009+\u20091\u2009=\u20093.In the second test case Winnie has a meal in Rabbit's house and that is for him. So he doesn't have to walk anywhere at all."}, "positive_code": [{"source_code": "n,*a=$<.map &:to_i;p a[0,2].min*(2--~n/n)+a.min*[0,n-2].max"}, {"source_code": "n = gets.strip.to_i\na = gets.strip.to_i\nb = gets.strip.to_i\nc = gets.strip.to_i\ncurr = 1\nans = 0\nif n > 1\n i = 1\n while i < n\n dist = 0\n case curr\n when 1\n if a <= b\n dist = a\n curr = 2\n else\n dist = b\n curr = 3\n end\n when 2\n if a <= c\n dist = a\n curr = 1\n else\n dist = c\n curr = 2\n end\n when 3\n if c <= b\n dist = c\n curr = 2\n else\n dist = b\n curr = 1\n end\n end\n ans += dist\n i += 1\n end\nend\nputs ans\n"}, {"source_code": "\nn,a,b,c = (gets+gets+gets+gets).split.map(&:to_i)\n\nif n==1\n p 0;exit\nend\nlen = 0\n\nx = [a,b].min\nlen += x\nn-=2\n\nif n > 0\n len += [x,c].min*n\nend\n\np len"}, {"source_code": "#! /usr/bin/env ruby\n\nn = gets.to_i\na = gets.to_i\nb = gets.to_i\nc = gets.to_i\n\nn -= 1\n\nans = 0\n\nif n > 0\n ans += [a, b].min\n n -= 1\nend\n\nans += [a, b, c].min * n\nn -= n\n\nputs ans\n"}, {"source_code": "n = gets.to_i\na = gets.to_i\nb = gets.to_i\nc = gets.to_i\nn -= 1\nx = [a, b, c].min\ntot = 0\nif n >= 1\n tot += [a, b].min\n tot += (n - 1) * x\nend\nputs tot\n"}], "negative_code": [{"source_code": "n,*a=$<.map &:to_i;p a[0,2].min*(-~n/n-1)+a.min*[0,n-2].max"}, {"source_code": "n,*a=$<.map &:to_i;p a.min*~-n"}, {"source_code": "n = gets.strip.to_i\na = gets.strip.to_i\nb = gets.strip.to_i\nc = gets.strip.to_i\ncurr = 1\nans = 0\nif n > 1\n i = 1\n while i < n\n dist = 0\n if curr.odd?\n dist = [a, b].min\n curr = 2\n else\n dist = [a, b, c].min\n curr = 1\n end\n ans += dist\n i += 1\n end\nend\nputs ans\n"}, {"source_code": "\nn,a,b,c = (gets+gets+gets+gets).split.map(&:to_i)\n\nif n==1\n p 0\nend\nlen = 0\n\nx = [a,b].min\nlen += x\nn-=2\n\nif n > 0\n len += [x,c].min*n\nend\n\np len"}, {"source_code": "#! /usr/bin/env ruby\n\nn = gets.to_i\na = gets.to_i\nb = gets.to_i\nc = gets.to_i\n\nn -= 1\n\nans = 0\n\nans += [a, b].min\nn -= 1\n\nans += [a, b, c].min * n\nn -= n\n\nputs ans\n"}, {"source_code": "n = gets.to_i\na = gets.to_i\nb = gets.to_i\nc = gets.to_i\nn -= 1\nx = [0, a, b, c].sort\ntot = (n / 3) * (a + b + c)\nfor i in 1 .. 3\n x[i] += x[i - 1]\nend\ntot += x[n % 3]\nputs tot\n"}, {"source_code": "n = gets.to_i\na = gets.to_i\nb = gets.to_i\nc = gets.to_i\nx = [a, b, c].min\ntot = (n - 1) * x\nputs tot\n"}], "src_uid": "6058529f0144c853e9e17ed7c661fc50"} {"nl": {"description": "You want to arrange n integers a1,\u2009a2,\u2009...,\u2009an in some order in a row. Let's define the value of an arrangement as the sum of differences between all pairs of adjacent integers.More formally, let's denote some arrangement as a sequence of integers x1,\u2009x2,\u2009...,\u2009xn, where sequence x is a permutation of sequence a. The value of such an arrangement is (x1\u2009-\u2009x2)\u2009+\u2009(x2\u2009-\u2009x3)\u2009+\u2009...\u2009+\u2009(xn\u2009-\u20091\u2009-\u2009xn).Find the largest possible value of an arrangement. Then, output the lexicographically smallest sequence x that corresponds to an arrangement of the largest possible value.", "input_spec": "The first line of the input contains integer n (2\u2009\u2264\u2009n\u2009\u2264\u2009100). The second line contains n space-separated integers a1, a2, ..., an (|ai|\u2009\u2264\u20091000).", "output_spec": "Print the required sequence x1,\u2009x2,\u2009...,\u2009xn. Sequence x should be the lexicographically smallest permutation of a that corresponds to an arrangement of the largest possible value.", "sample_inputs": ["5\n100 -100 50 0 -50"], "sample_outputs": ["100 -50 0 50 -100"], "notes": "NoteIn the sample test case, the value of the output arrangement is (100\u2009-\u2009(\u2009-\u200950))\u2009+\u2009((\u2009-\u200950)\u2009-\u20090)\u2009+\u2009(0\u2009-\u200950)\u2009+\u2009(50\u2009-\u2009(\u2009-\u2009100))\u2009=\u2009200. No other arrangement has a larger value, and among all arrangements with the value of 200, the output arrangement is the lexicographically smallest one.Sequence x1,\u2009x2,\u2009... ,\u2009xp is lexicographically smaller than sequence y1,\u2009y2,\u2009... ,\u2009yp if there exists an integer r (0\u2009\u2264\u2009r\u2009<\u2009p) such that x1\u2009=\u2009y1,\u2009x2\u2009=\u2009y2,\u2009... ,\u2009xr\u2009=\u2009yr and xr\u2009+\u20091\u2009<\u2009yr\u2009+\u20091."}, "positive_code": [{"source_code": "n = gets.to_i\narray = gets.chomp!.split(' ').map(&:to_i).sort\narray[0], array[-1] = array[-1], array[0]\nputs array.join(' ')"}, {"source_code": "def run\n n = $stdin.gets.to_i\n a = $stdin.gets.split.map(&:to_i)\n max = a.delete_at(a.index(a.max))\n min = a.delete_at(a.index(a.min))\n\n puts ([max] + a.sort + [min]).join(\" \")\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "class A\n def initialize\n n = gets.chomp.to_i\n num_list = gets.chomp.split(' ').map(&:to_i)\n max_num = num_list.max\n min_num = num_list.min\n num_list.delete_at(num_list.find_index(max_num))\n num_list.delete_at(num_list.find_index(min_num))\n\n answer = [max_num] + num_list.sort + [min_num]\n\n puts answer.join(' ')\n end\nend\n\na = A.new"}], "negative_code": [], "src_uid": "4408eba2c5c0693e6b70bdcbe2dda2f4"} {"nl": {"description": "The only difference between the easy and the hard versions is constraints.A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between them. For example, for the string \"abaca\" the following strings are subsequences: \"abaca\", \"aba\", \"aaa\", \"a\" and \"\" (empty string). But the following strings are not subsequences: \"aabaca\", \"cb\" and \"bcaa\".You are given a string $$$s$$$ consisting of $$$n$$$ lowercase Latin letters.In one move you can take any subsequence $$$t$$$ of the given string and add it to the set $$$S$$$. The set $$$S$$$ can't contain duplicates. This move costs $$$n - |t|$$$, where $$$|t|$$$ is the length of the added subsequence (i.e. the price equals to the number of the deleted characters).Your task is to find out the minimum possible total cost to obtain a set $$$S$$$ of size $$$k$$$ or report that it is impossible to do so.", "input_spec": "The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \\le n, k \\le 100$$$) \u2014 the length of the string and the size of the set, correspondingly. The second line of the input contains a string $$$s$$$ consisting of $$$n$$$ lowercase Latin letters.", "output_spec": "Print one integer \u2014 if it is impossible to obtain the set $$$S$$$ of size $$$k$$$, print -1. Otherwise, print the minimum possible total cost to do it.", "sample_inputs": ["4 5\nasdf", "5 6\naaaaa", "5 7\naaaaa", "10 100\najihiushda"], "sample_outputs": ["4", "15", "-1", "233"], "notes": "NoteIn the first example we can generate $$$S$$$ = { \"asdf\", \"asd\", \"adf\", \"asf\", \"sdf\" }. The cost of the first element in $$$S$$$ is $$$0$$$ and the cost of the others is $$$1$$$. So the total cost of $$$S$$$ is $$$4$$$."}, "positive_code": [{"source_code": "N,k=gets.split.map &:to_i\ns=gets.chomp\ndp=(0..100).map{[0]*101}\ndp[0][0]=1\nN.times{|i|\n\t(1..i+1).each{|j|\n\t\t0.upto(i){|k|dp[i+1][j]+=dp[k][j-1]}\n\t\ti.times{|k|dp[i+1][j]-=dp[k+1][j] if s[i]==s[k]}\n\t}\n}\nSUM=(0..N).map{|i|t=0;(0..N).each{|j|t+=dp[j][i]};t}\nans=0\nN.downto(0){|i|\n\tt=[SUM[i],k].min\n\tk-=t\n\tans+=t*(N-i)\n}\np k>0 ? -1 : ans"}, {"source_code": "MOD=10**9+7\ncnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)\ndef gs() gets.chomp end\ndef gi() gets.to_i end\ndef gsmi() gets.chomp.split.map(&:to_i) end\n\ndef desc(ar) ar.sort{|x,y|y<=>x} end##\ndef min(a,b) a<=b ? a : b end\ndef max(a,b) a>=b ? a : b end\ndef sum(ar) ar.inject(:+) end\n\ndef C(a,b) b==0||a==b ? 1 : (b=a-b if a/20 do\n ar=[]\n prev.each do |pr|\n l.times do |i|\n st=pr[0,i]+pr[(i+1)..-1]\n ar<=1\nend\n\nputs cnt"}], "negative_code": [], "src_uid": "ae5d21919ecac431ea7507cb1b6dc72b"} {"nl": {"description": "You've got a 5\u2009\u00d7\u20095 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix: Swap two neighboring matrix rows, that is, rows with indexes i and i\u2009+\u20091 for some integer i (1\u2009\u2264\u2009i\u2009<\u20095). Swap two neighboring matrix columns, that is, columns with indexes j and j\u2009+\u20091 for some integer j (1\u2009\u2264\u2009j\u2009<\u20095). You think that a matrix looks beautiful, if the single number one of the matrix is located in its middle (in the cell that is on the intersection of the third row and the third column). Count the minimum number of moves needed to make the matrix beautiful.", "input_spec": "The input consists of five lines, each line contains five integers: the j-th integer in the i-th line of the input represents the element of the matrix that is located on the intersection of the i-th row and the j-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one.", "output_spec": "Print a single integer \u2014 the minimum number of moves needed to make the matrix beautiful.", "sample_inputs": ["0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0"], "sample_outputs": ["3", "1"], "notes": null}, "positive_code": [{"source_code": "r1 = gets.chomp\nrow1 = r1.split(\" \")\nr2 = gets.chomp\nrow2 = r2.split(\" \")\nr3 = gets.chomp\nrow3 = r3.split(\" \")\nr4 = gets.chomp\nrow4 = r4.split(\" \")\nr5 = gets.chomp\nrow5 = r5.split(\" \")\n\nspaces = 0\nif row1.include? \"1\" \n\tif row1[2] == \"1\"\n\t\tspaces = 0\n\telsif row1[0] == \"1\" || row1[4] == \"1\"\n\t\tspaces += 2\n\telse\n\t\tspaces += 1\n\tend\n\tspaces += 2\nelsif row2.include? \"1\"\n\tif row2[2] == \"1\"\n\t\tspaces = 0\n\telsif row2[0] == \"1\" || row2[4] == \"1\"\n\t\tspaces += 2\n\telse\n\t\tspaces += 1\n\tend\t\n\tspaces += 1\t\nelsif row3.include? \"1\"\n\tif row3[2] == \"1\"\n\t\tspaces = 0\n\telsif row3[0] == \"1\" || row3[4] == \"1\"\n\t\tspaces += 2\n\telse\n\t\tspaces += 1\n\tend\t\t\nelsif row4.include? \"1\"\n\tif row4[2] == \"1\"\n\t\tspaces = 0\n\telsif row4[0] == \"1\" || row4[4] == \"1\"\n\t\tspaces += 2\n\telse\n\t\tspaces += 1\n\tend\t\t\n\tspaces += 1\nelse\n\tif row5[2] == \"1\"\n\t\tspaces = 0\n\telsif row5[0] == \"1\" || row5[4] == \"1\"\n\t\tspaces += 2\n\telse\n\t\tspaces += 1\n\tend\n\tspaces += 2\nend\n\t\nputs spaces"}, {"source_code": "5.times{|r|c=gets.index(?1);(c)?(p (r-2).abs+(c/2-2).abs):(0)}\n"}, {"source_code": "5.times{|r|c=gets.index(?1);(c)?(p (r-2).abs+(c/2-2).abs):(0)}\n\n"}, {"source_code": "mat = []\n5.times{\n\tmat << STDIN.readline.split\n}\n\n(0..4).each{|i|\n\t(0..4).each{|j|\n\t\tif mat[i][j] == '1'\n\t\t\tp (i-2).abs+(j-2).abs\n\t\tend\n\t}\n}"}, {"source_code": "arr = []\ni = 0\nj = 0\n5.times {\n arr.push(gets.split(\" \").map(&:to_i))\n}\narr.each_with_index do |row,i_ind|\n val = row.index(1)\n i = i_ind and j = val if val\nend\nputs (i - 2).abs + (2 - j ).abs"}, {"source_code": "5.times { |row|\n c = gets.chomp.gsub(\" \", \"\").index(\"1\")\n puts (2-row).abs + (2-c).abs if c\n}\n"}, {"source_code": "5.times{|x|a=gets.split.index(?1);!a ?(0):(puts (a-2).abs+(x-2).abs)}"}, {"source_code": "# https://codeforces.com/problemset/problem/263/A\n0.upto(4) do |i|\n line = gets.chomp\n chars = line.split(' ')\n chars.each_with_index do |c, j|\n if c == '1'\n p (2 - i).abs + (2 - j).abs\n end\n end\nend\n"}, {"source_code": "5.times{|x|a=gets.split.index(?1);!a ?(0):(puts (a-2).abs+(x-2).abs)}"}, {"source_code": "5.times{|r|c=gets.index(?1);(c)?(p (r-2).abs+(c/2-2).abs):(0)}"}, {"source_code": "l = []\n(1..5).each { l << gets.split.map(&:to_i) }\n\nx = 0\ny = 0\n\nl.each_with_index { |i, in1| \n\ti.each_with_index { |j, in2| \n\t\t\tif j == 1 \n\t\t\t\tx = in2\n\t\t\t\ty = in1\n\t\t\t\tbreak\n\t\t\tend\n\t\t} \n\t}\n\nputs (x - 2).abs + (y - 2).abs"}, {"source_code": "i = 1\nrow_num = 0\noutput = 0\nwhile i <= 5\n input_row = gets.chomp.split\n if input_row.include?(\"1\") then\n input_row = input_row.map{|i| i.to_i}\n colum_num = input_row.index{|i| i == 1}\n row_num = i\n colum_num = colum_num +1\n end\n i = i+1\nend\nif 3 > row_num then\n output = 3 - row_num\nelsif 3 < row_num then\n output = row_num -3\nend\nif 3 > colum_num then\n output = 3 - colum_num + output\nelsif 3 < colum_num then\n output = colum_num - 3 + output\nend\nprint output\n"}, {"source_code": "line1 = gets.chomp.split(\" \")\nline2 = gets.chomp.split(\" \")\nline3 = gets.chomp.split(\" \")\nline4 = gets.chomp.split(\" \")\nline5 = gets.chomp.split(\" \")\n\ni = 0\nj = 0\nif line1.index(\"1\")\n\tj = line1.index(\"1\")\n\ti = 0\nend\n\nif line2.index(\"1\")\n\tj = line2.index(\"1\")\n\ti = 1\nend\n\nif line3.index(\"1\")\n\tj = line3.index(\"1\")\n\ti = 2\nend\n\nif line4.index(\"1\")\n\tj = line4.index(\"1\")\n\ti = 3\nend\n\nif line5.index(\"1\")\n\tj = line5.index(\"1\")\n\ti = 4\nend\n\nputs \"#{(i-2).abs+(j-2).abs}\""}, {"source_code": "5.times do |i|\n j=gets.split.find_index(?1)\n puts (i-2).abs+(j-2).abs if j\nend\n"}, {"source_code": "5.times {|i|\n j=gets.split.index(?1)\n puts (i-2).abs+(j-2).abs if j\n}\n"}, {"source_code": "a = Array.new(5)\n5.times do |i|\n a[i] = gets.split.map(&:to_i)\nend\nxi = 0\nxj = 0\n5.times do |i|\n 5.times do |j|\n if a[i][j] == 1\n xi = i + 1\n xj = j + 1\n break\n end\n end\nend\nputs (xi - 3).abs + (xj - 3).abs\n"}, {"source_code": "total = 0\n5.times{|i|\n\tj = gets.split(' ').index(?1)\n\tputs (i-2).abs + (j-2).abs if j\t\n}"}, {"source_code": "5.times do |i|\n j = gets.split.index(\"1\")\n if j\n puts (2 - i).abs + (2 - j).abs \n break\n end\nend"}, {"source_code": "r=0\nc=0\n1.upto(5) do |i|\na=gets.chomp\nif a.count(\"1\")==1\nr=i\na.each_char do |k|\nif k==\"0\" || k==\"1\"\nc+=1\nend\nbreak if k== \"1\"\nend\nend\nend\nans= (r-3).abs+(c-3).abs\n\nputs \"#{ans}\"\n\n"}, {"source_code": "def check (n,r)\n\tif n.include?(1)\n\t\tputs (3-r).abs + (3-(n.index(1)+1)).abs\n\tend\nend\n\nx = []\nx = gets.split.map(&:to_i)\n\ny = []\ny = gets.split.map(&:to_i)\n\nz = []\nz = gets.split.map(&:to_i)\n\na = []\na = gets.split.map(&:to_i)\n\nb = []\nb = gets.split.map(&:to_i)\n\ncheck(x,1)\ncheck(y,2)\ncheck(z,3)\ncheck(a,4)\ncheck(b,5)\n"}, {"source_code": "\narr_input = []\ni, j = -1\n5.times do |n|\n \tarr = gets.chomp\n \tarr_input << arr\nend\n\narr_input.each.with_index do |row, index|\n\trow.split(' ').each.with_index do |col, idx|\n\t\tif col.to_i == 1\n\t\t\ti = index\n\t\t\tj = idx\n\t\tend\n\tend\nend\nmin_distance = (2 - i).abs + (2 - j).abs\n\nputs min_distance"}, {"source_code": "\narr_input = []\ni, j = -1\n5.times do |n|\n \tarr = gets.chomp\n \tarr_input << arr\n \tarr.split(' ').each.with_index do |col, idx|\n\t\tif col.to_i == 1\n\t\t\ti = n\n\t\t\tj = idx\n\t\tend\n\tend\nend\nmin_distance = (2 - i).abs + (2 - j).abs\n\nputs min_distance"}, {"source_code": "5.times{|r|c=gets.index(?1);(c)?(p (r-2).abs+(c/2-2).abs):(0)}\n\n"}, {"source_code": "5.times{|r|c=gets.index(?1);(c)?(p (r-2).abs+(c/2-2).abs):(0)}"}, {"source_code": "5.times do |i|\n a = gets.split.map(&:to_i)\n 5.times do |j|\n if a[j] == 1\n puts (2 - i).abs() + (2 - j).abs()\n exit 0\n end\n end\nend\n"}, {"source_code": "#!/usr/bin/env ruby\n\n5.times do |i|\n\tgets.split.each_with_index do |v, j|\n\t\tif v == \"1\"\n\t\t\tputs (i - 2).abs + (j - 2).abs\n\t\t\texit 0\n\t\tend\n\tend\nend\n"}, {"source_code": "n = 0\n5.times.each_with_index do |row, ind|\n line = gets.chomp.match(/1/)\n if line\n n = (ind - 2).abs + (line.begin(0) / 2 - 2).abs\n end\nend\nputs n\n"}, {"source_code": "5.times{|r|c=gets.index(?1);(c)?(p (r-2).abs+(c/2-2).abs):(0)}\n\n"}, {"source_code": "include Math\nBEGIN{\n\tdef gint()\n\t\treturn gets.split.map(&:to_i)\n\tend\n\tdef main()\n\t\ta = []\n\t\tx = y = 0\n\t\t5.times do |i|\n\t\t\ta[i] = gint\n\t\t\ta[i].each_with_index do |ta,w|\n\t\t\t\tif ta == 1 then\n\t\t\t\t\tx, y = i, w \n\t\t\t\tend\n\t\t\tend\n\t\tend\n\t\tputs (x-2).abs + (y-2).abs\n\tend\n\tTest_case = 1\n\tTest_case.times do\n\t\tmain()\n\tend\n}\n"}, {"source_code": "line = 0\npos = 0\nwhile true\n line += 1\n pos = gets.split.map(&:to_i).index(1)\n if pos != nil\n break\n end\nend\npos += 1\nputs (3-line).abs + (3-pos).abs\n"}, {"source_code": "_2d = []\n5.times{ _2d = _2d + [gets.chomp.split.map(&:to_i)]}\nfor i in (0...5) do\n for j in (0...5) do\n unless _2d[i][j].zero?\n puts (3-(i+1)).abs + (3-(j+1)).abs\n end\n end\nend\n"}, {"source_code": "t = 5\n\nt.times do |i|\n\ts = gets.split.collect{|x| x.to_i}\n\n\ts.each_index{|j|\n\t\tif s[j] == 1\n\t\t\tputs (i-2).abs + (j-2).abs\n\t\tend\n\t}\nend"}, {"source_code": "x=nil\ny=nil\n\n5.times do |i|\n a=gets.split.map{|e|e.to_i}\n n=a.index 1\n if n\n x=n\n y=i\n break\n end\nend\n\nputs (2-x).abs+(2-y).abs\n"}, {"source_code": "5.times{|r|c=gets.index(?1);(c)?(p (r-2).abs+(c/2-2).abs):(0)}\n\n"}, {"source_code": "matrix = []\nrow, column = 0, 0\n\n(0...5).each do |iterNum|\n\tmatrix << gets.chomp.split(' ').map {|item| item.to_i}\n\trow, column = iterNum, matrix[iterNum].index(1) unless matrix[iterNum].index(1).nil?\nend\n\nputs (2 - row).abs + (2 - column).abs"}, {"source_code": "ar = []\n5.times do\n ar << gets.split(' ').map(&:to_i)\nend\nrow = ar.map{|x| x.inject(:+)}.index(1)\ncol = ar[row].index(1)\nputs (row-2).abs+(col-2).abs"}, {"source_code": "def abs(x)\n if x < 0 then\n return -x\n else\n return x\n end\nend\n\nn = 0\nm = 0\nmatrix = []\n5.times do |i|\n matrix[i] = gets.split\n if q = matrix[i].index(\"1\") then\n n = i + 1\n m = q + 1\n end\nend\n\nresult = abs(n-3) + abs(m-3)\nputs result"}, {"source_code": "5.times do |i|\n j = gets.split.index(?1)\n puts (i-2).abs + (j-2).abs if j\nend"}, {"source_code": "d,r=$<.read.split.each_with_index.find{|e,i|e==?1}[1].divmod(5)\np (d-2).abs+(r-2).abs"}, {"source_code": "matrix = [] ; 5.times{ matrix << gets.chomp.split(\" \").map(&:to_i) }\nmatrix.each_with_index do |line, i|\n if line.include?(1)\n count_heigth = (3 - (i+1)).abs\n line.each_with_index do |element, index|\n if element == 1\n count_element = (3 - (index+1)).abs\n puts count_heigth + count_element\n end\n end\n end\nend"}, {"source_code": "s = $<.gets ?1\ni = s.count(?\\n)\nj = s[/.*1/].count ?0\np (2-i).abs + (2-j).abs"}, {"source_code": "def read_tokens\n return gets.chomp.to_s.strip.split(' ')\nend\n\ndef read_ints\n data = []\n read_tokens.each { |s|\n data.push(s.to_i)\n }\n return data\nend\n\n\nr_1, c_1 = 0, 0\n(0...5).each { |r|\n row = read_ints\n c = row.find_index(1)\n if c != nil\n r_1, c_1 = r, c\n end\n}\n\ndef solve(row, col)\n dest_r, dest_c = 2, 2\n return (dest_r - row).abs + (dest_c - col).abs\nend\n\n\nprint(solve(r_1, c_1))"}, {"source_code": "f = false\nm = 0\n0.upto 4 do |t|\n\tif !f\n\t\ta = gets.chomp.split(\" \")\n\t\tif a.include? \"1\"\n\t\t\tm += (2 - t).abs\n\t\t\tm += (2 - a.index(\"1\")).abs\n\t\t\tf = true\n\t\tend\n\telse\n\t\tgets\n\tend\nend\nputs m"}, {"source_code": "5.times{|r|c=gets.index(?1);(c)?(p (r-2).abs+(c/2-2).abs):(0)}\n\n"}, {"source_code": "a=Array.new\ns=1\n5.times do \nj=0\na=gets.split.map(&:to_i)\nfor i in 0..4 do\nif a[i]==1 then \nputs (s-3).abs+(i+1-3).abs\nj=1\nend\nend\nbreak if j== 1\ns+=1\nend\n\n\n"}, {"source_code": "a, s, ans = Array.new, 1, {[[1, 0, 0, 0, 0],[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]=>4,[[0, 1, 0, 0, 0],[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]=>3,[[0, 0, 1, 0, 0],[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]=>2,[[0, 0, 0, 1, 0],[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]=>3,[[0, 0, 0, 0, 1],[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]=>4,[[0, 0, 0, 0, 0],[0, 1, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]=>2,[[0, 0, 0, 0, 0],[0, 0, 1, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]=>1,[[0, 0, 0, 0, 0],[0, 0, 0, 1, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]=>2,[[0, 0, 0, 0, 0],[0, 0, 0, 0, 1], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]=>3,[[0, 0, 0, 0, 0],[0, 0, 0, 0, 0], [0, 0, 1, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]=>0,[[0, 0, 0, 0, 0],[0, 0, 0, 0, 0], [0, 0, 0, 1, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]=>1,[[0, 0, 0, 0, 0],[0, 0, 0, 0, 0], [0, 0, 0, 0, 1], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]=>2,[[0, 0, 0, 0, 0],[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 1, 0], [0, 0, 0, 0, 0]]=>2,[[0, 0, 0, 0, 0],[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 1], [0, 0, 0, 0, 0]]=>3,[[0, 0, 0, 0, 0],[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 1]]=>4}\n5.times{a << gets.split.map(&:to_i)}\nans.key?(a) ? (puts ans[a]) : (puts ans[a.transpose])\n"}, {"source_code": "x, y = 0, 0\n5.times do |i|\n a = gets.split(\" \").map{|x| x.to_i}\n x, y = i, a.index(1) if a.include?(1)\nend\nputs (2 - x).abs + (2 - y).abs"}, {"source_code": "\ufeff# -*- encoding: utf-8 -*-\n\nx, y = 0, 0\n\nfor i in 0 .. 4 do\n cols = gets.chomp.split(\" \").map{|n| n.to_i}\n \n for j in 0 .. 4 do\n if cols[j] == 1\n x = j\n y = i\n break\n end\n end \nend\nputs (2 - x).abs + (2 - y).abs\n"}, {"source_code": "5.times{|r|c=gets.index(?1);(c)?(p (r-2).abs+(c/2-2).abs):(0)}\n\n"}, {"source_code": "5.times{|r|c=gets.index(?1);(c)?(p (r-2).abs+(c/2-2).abs):(0)}"}, {"source_code": "(1..5).each do |i|\n m = gets.split(/\\s+/).map(&:to_i)\n i_th = m.index(1)\n unless i_th.nil?\n movements = (3-(i_th+1)).abs + (3-i).abs\n puts movements\n break\n end\nend\n"}, {"source_code": "m = 0\nn = 0\nfor i in 0...5\n x = gets.split.map(&:to_i)\n for j in 0...5 \n if x[j]==1\n m = j\n n = i\n break\n end\n end\n \n\nend\n\nputs (n-2).abs + (m-2).abs "}, {"source_code": "#!/usr/bin/ruby1.9\n\n5.times do |r|\n\trow = STDIN.readline.split\n\t5.times do |c|\n\t\tif row[c] == '1'\n\t\t\tputs ((r-2).abs+(c-2).abs)\n\t\t\texit\n\t\tend\n\tend\nend\n"}, {"source_code": "x = 0\ny = 0\n(0...5).each do |i|\n a = []\n a = gets.split.map &:to_i\n (0...5).each do |j|\n if a[j] == 1\n x = i + 1\n y = j + 1\n end\n end\nend\n\nputs (3 - x).abs + (3 - y).abs"}, {"source_code": "for i in 1..5\n\tstr = gets.chomp\n\tif str.include? \"1\"\n\t\ty = i\n\t\tx = (((\" \" + str).index \"1\") + 1) / 2\n\tend\nend\nputs (x - 3).abs + (y - 3).abs"}, {"source_code": "5.times{|x|a=gets.split.index(?1);!a ?(0):(puts (a-2).abs+(x-2).abs)}"}, {"source_code": "matrix = []\n5.times do\n row_string = gets.strip\n row = row_string.split(' ').map(&:to_i)\n matrix.push(row)\nend\n\nrow = nil\ncolumn = nil\n5.times do |row_index|\n 5.times do |column_index|\n next unless matrix[row_index][column_index].eql?(1)\n\n row = row_index\n column = column_index\n break\n end\nend\n\ndiff_row = (row - 2).abs\ndiff_column = (column - 2).abs\nresult = diff_row + diff_column\nputs result\n"}, {"source_code": "a=[]\ni=0\nx=0\ny=0\n5.times do\n\trow=gets.chomp.split(' ')\n\t#print row\n\t#puts\n\trow.each_index do |char|\n\t\t#puts row[char]\n\t\tif row[char]=='1'\n\t\t\tx=i\n\t\t\ty=char\n\t\tend\n\tend\n\ta.push(row)\n\ti+=1\nend\n#puts '('+x.to_s+','+y.to_s+')'\nputs (x-2).abs+(y-2).abs\n"}, {"source_code": "arr = []\nx = nil\ny = nil\n\n5.times do |tx|\n arr << gets.chomp.split(' ')\n y ||= arr.last.index '1'\n (x ||= tx) if y\nend\n\nputs (x-2).abs + (y-2).abs\n"}, {"source_code": "coco = 0\nmoco = 0\n5.times do |x|\n a = gets.split.map(&:to_i)\n if a.include? 1\n coco = x\n moco = a.index(1)\n end\nend\n\nputs (coco - 2).abs + (moco - 2).abs"}, {"source_code": "i,j = nil, nil\n(0..4).each do |k|\n a = $stdin.readline.split.map(&:to_i)\n t = a.find_index(1)\n if !t.nil?\n i,j=k,t\n end\nend\n\ndi = (2-i).abs\ndj = (2-j).abs\n\nputs di+dj"}, {"source_code": "a = Array.new(5, Array.new(5))\nii, jj = 0, 0;\nfor i in 0...5\n a[i] = gets.split(\" \").map(&:to_i)\n for j in 0...5\n if a[i][j] == 1\n ii ,jj = i, j;\n end\n end\nend\nputs (ii - 2).abs + (jj - 2).abs"}, {"source_code": "5.times{|r|c=gets.index(?1);(c)?(p (r-2).abs+(c/2-2).abs):(0)}"}, {"source_code": "def run\n ARGF.readlines.each_with_index do |line, i|\n line.chomp.split(\" \").each_with_index do |c, j|\n if c == \"1\"\n puts (i - 2).abs + (j - 2).abs\n return\n end\n end\n end\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "# cook your code here\narr = Array.new(5,Array.new(5))\none_row =0 \none_col=0\n(0..4).each do |row|\n val = gets.split(\" \").map(&:to_i)\n (0..4).each do |col|\n arr[row][col] = val[col]\n if val[col] == 1 \n one_row = row \n one_col = col \n end \n end \nend \nputs (one_row - 2).abs + (one_col-2).abs"}, {"source_code": "inp = Array.new\n5.times do\n inp << gets.chomp\nend\ninp.each do |str|\n if str =~ /^.*1.*$/\n str.scan(/1/) { |ch| puts (inp.index(str) - 2).abs + (str.delete(\" \").index(ch) - 2).abs }\n end\nend\n"}, {"source_code": "5.times{|r|c=gets.index(?1);(c)?(p (r-2).abs+(c/2-2).abs):(0)}\n\n"}, {"source_code": "#!/usr/bin/env ruby -w\n\nv = (1..5).map do\n gets.split(/\\s+/).map(&:to_i)\nend\n\nfound = false\n(0..4).each do |i|\n break if found\n (0..4).each do |j|\n if v[i][j] == 1\n puts (i - 2).abs + (j - 2).abs\n found = true\n break\n end\n end\nend\n"}, {"source_code": "grids = []\none_id = nil\n5.times do |i|\n line = gets.split.map(&:to_i)\n one_id = line.index(1)\n if one_id\n puts (i - 2).abs + (one_id - 2).abs\n end\nend"}, {"source_code": "5.times{|r|c=gets.index(?1);(c)?(p (r-2).abs+(c/2-2).abs):(0)}\n\n"}, {"source_code": "matrix = []\npos_one = [-1, -1]\nbeautiful_pos = [3, 3]\n(1..5).each do |index|\n row = gets.chomp.split(/ /).map(&:to_i)\n matrix << row\n pos_one = [index, row.index( 1 ) + 1] if row.include? 1\nend\nputs (pos_one[0] - beautiful_pos[0]).abs + (pos_one[1] - beautiful_pos[1]).abs\n"}, {"source_code": "r=0\nc=0\n1.upto(5) do |i|\na=gets.chomp\nif a.count(\"1\")==1\nr=i\na.each_char do |k|\nif k==\"0\" || k==\"1\"\nc+=1\nend\nbreak if k== \"1\"\nend\nend\nend\nans= (r-3).abs+(c-3).abs\n\nputs \"#{ans}\""}, {"source_code": "require 'set'\ninclude Math\n$stdin = File.open(\"./input.txt\", \"r\") if ENV[\"USER\"] == \"new\"\n# ====================================\n\nmatrix = []\n5.times do\n matrix << gets.strip.split.map(&:to_i)\nend\n\nx, y = 0, 0\ncatch (:done) do\n for i in 0...5 do\n for j in 0...5 do\n if matrix[i][j] == 1\n x, y = i, j\n throw :done\n end\n end\n end\nend\n\nmoves = (x - 2).abs + (y - 2).abs\nputs moves"}, {"source_code": "5.times do|i|\nj=gets.split.index(?1)and puts (i-2).abs+(j-2).abs\nend"}, {"source_code": "1.upto(5) { |i| gets.chomp.split.each_with_index { |x,j| puts (i-3).abs + (j-2).abs if x == '1'} }"}, {"source_code": "$<.each_with_index{|x,r|c=x.split.index('1');(puts (r-2).abs+(c-2).abs; break) if c}\n"}, {"source_code": "5.times{|r|c=gets.index(?1);(c)?(p (r-2).abs+(c/2-2).abs):(0)}\n"}, {"source_code": "$<.each_with_index{|x,r|c=x.split.index(?1);(c)?(puts (r-2).abs+(c-2).abs):(0)}\n"}, {"source_code": "# http://codeforces.com/problemset/problem/263/A\n\nrows = []\n\none_row_index = -1\none_col_index = -1\n\n5.times do |t|\n row = gets.chomp.split\n if row.include? \"1\"\n one_row_index = t\n one_col_index = row.find_index(\"1\")\n end\n rows << row\nend\n\nputs \"#{(2 - one_row_index).abs + (2 - one_col_index).abs}\""}, {"source_code": "runner = 0\nheight = 0\nwidth = 0\nwhile line = gets.to_s.strip do\n break if line == ''\n columns = line.split(' ')\n if columns.include? '1'\n width = columns.index '1'\n height = runner\n end\n runner += 1\nend\n\nneeded_height = 2\nneeded_width = 2\n\nputs (needed_width - width).abs + (needed_height - height).abs\n"}, {"source_code": "n = Array.new\nfor i in 0...5\n n[i] = Array.new\nend\nfor i in 0...5\n input = gets.chomp\n for j in 0...5\n nums = input.split\n n[i][j] = Integer(nums[j])\n end\nend\n\na = 0\nb = 0\nfor i in 0...5\n for j in 0...5\n if n[i][j] == 1\n a = i\n b = j\n end\n end\nend\n\nif a >= 2 && b >= 2\n puts a - 2 + b - 2\nelsif a < 2 && b >= 2\n puts 2 - a + b - 2\nelsif a < 2 && b < 2\n puts 2 - a + 2 - b\nelse a >= 2 && b < 2\n puts a - 2 + 2 - b\nend\n"}], "negative_code": [{"source_code": "l = []\n(1..5).each { l << gets.split.map(&:to_i) }\n\nx = 0\ny = 0\n\nl.each_with_index { |i, in1| \n\ti.each_with_index { |j, in2| \n\t\t\tif j == 1 \n\t\t\t\tx = in2\n\t\t\t\ty = in1\n\t\t\t\tbreak\n\t\t\tend\n\t\t} \n\t}\n\nputs (x - 3).abs + (y - 3).abs"}, {"source_code": "p gets.casecmp gets\n"}, {"source_code": "_2d = []\n5.times{ _2d = _2d + gets.chomp.split.map(&:to_i)}\n_2d.each_with_index{|x, index| puts ((index+1)-13).abs unless x.zero?}"}, {"source_code": "5.times do |i|\n j = gets.split.find_index(1)\n puts (i-2).abs + (j-2).abs if j\nend"}, {"source_code": "x = 0\ny = 0\n(0...5).each do |i|\n a = []\n a = gets.split.map &:to_i\n (0...5).each do |j|\n if a[j] == 1\n x = i\n y = j\n end\n end\nend\nputs (3 - x).abs + (3 - y).abs"}, {"source_code": "a=[]\ni=0\nx=0\ny=0\n5.times do\n\trow=gets.chomp.split(' ').map(&:to_i)\n\trow.each_index do |char|\n\t\tif char==1\n\t\t\tx=i\n\t\t\ty=char\n\t\tend\n\tend\n\ta.push(row)\n\ti+=1\nend\nputs (x+y-4).abs\n"}, {"source_code": "a=[]\ni=0\nx=0\ny=0\n5.times do\n\trow=gets.chomp.split(' ').map(&:to_i)\n\trow.each_index do |char|\n\t\tif char==1\n\t\t\tx=i\n\t\t\ty=char\n\t\tend\n\tend\n\ta.push(row)\n\ti+=1\nend\nputs (x-2).abs+(y-2).abs\n"}, {"source_code": "arr = []\nx = nil\ny = nil\n\n5.times do |tx|\n arr << gets.chomp.split(' ')\n y ||= arr.last.index '1'\n (x ||= tx) if y\nend\n\nputs \"COORDS: \" + x.to_s + \" \" + y.to_s\nputs (x-2).abs + (y-2).abs\n"}, {"source_code": "i,j = nil, nil\n(0..4).each do |k|\n a = $stdin.readline.split.map(&:to_i)\n t = a.find_index(1)\n if !t.nil?\n i,j=k,t\n end\nend\n\ndi = (2-i).abs\ndj = (2-i).abs\n\nputs 1+di+dj"}, {"source_code": "a=gets.chomp.split(\" \").map {|i| i.to_i}\nb=gets.chomp.split(\" \").map {|i| i.to_i}\nb.sort!\nif a[0]-a[1]>=0\nc=b[a[0]-a[1]]\nputs \"#{c} #{c-1}\"\nelse\nputs \"-1\"\nend\n"}, {"source_code": "5.times{|r|c=gets.index(?1);puts c;puts r;(c)?(p (r-2).abs+(c/2-2).abs):(0)}\n"}, {"source_code": "n = Array.new\nfor i in 0...5\n n[i] = Array.new\nend\nfor i in 0...5\n input = gets.chomp\n for j in 0...5\n nums = input.split\n n[i][j] = Integer(nums[j])\n end\nend\n\na = 0\nb = 0\nfor i in 0...5\n for j in 0...5\n if n[i][j] == 1\n a = i\n b = j\n end\n end\nend\n\nif a > b\n puts a - b\nelsif a == 0 && b == 0\n puts 4\nelsif a == 1 && b == 1\n puts 2\nelsif a == 2 && b == 2\n puts 0\nelsif a == 3 && b == 3\n puts 2\nelsif a == 4 && b == 4\n puts 4\n\nelse\n a < b\n puts b - a\nend\n"}], "src_uid": "8ba7cedc3f6ae478a0bb3f902440c8e9"} {"nl": {"description": "Amr loves Geometry. One day he came up with a very interesting problem.Amr has a circle of radius r and center in point (x,\u2009y). He wants the circle center to be in new position (x',\u2009y').In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin by any angle and finally remove the pin.Help Amr to achieve his goal in minimum number of steps.", "input_spec": "Input consists of 5 space-separated integers r, x, y, x' y' (1\u2009\u2264\u2009r\u2009\u2264\u2009105, \u2009-\u2009105\u2009\u2264\u2009x,\u2009y,\u2009x',\u2009y'\u2009\u2264\u2009105), circle radius, coordinates of original center of the circle and coordinates of destination center of the circle respectively.", "output_spec": "Output a single integer \u2014 minimum number of steps required to move the center of the circle to the destination point.", "sample_inputs": ["2 0 0 0 4", "1 1 1 4 4", "4 5 6 5 6"], "sample_outputs": ["1", "3", "0"], "notes": "NoteIn the first sample test the optimal way is to put a pin at point (0,\u20092) and rotate the circle by 180 degrees counter-clockwise (or clockwise, no matter)."}, "positive_code": [{"source_code": "r, x, y, x_, y_ = gets.split.map &:to_i\n\nd = Math.sqrt(((x_ - x) ** 2) + ((y_ - y) ** 2))\n\nputs (d / (2 * r).to_f).ceil\n"}, {"source_code": "r,x,y,x1,y1 = gets.chomp.split \n\nr = r.to_f \nx = x.to_f \ny = y.to_f \nx1= x1.to_f \ny1= y1.to_f \n\nl = Math.sqrt((x-x1)*(x-x1)+(y-y1)*(y-y1)) \nl = l/(2*r) \nl = l.ceil \n\nputs l.to_i"}, {"source_code": "#!/usr/bin/env ruby\nr,*_=gets.split.map(&:to_f)\nd=Math.hypot(*_.each_slice(2).to_a.transpose.map{|e|e.reduce(:-)})\np (d/r/2).ceil"}, {"source_code": "a,b,c,d,e=gets.chomp.split.map(&:to_i)\nputs (Math.hypot((d-b),(e-c))/(2*a)).ceil\n"}, {"source_code": "a,b,c,d,e=gets.chomp.split.map(&:to_i)\nputs (Math.hypot((d-b),(e-c))/(2*a)).ceil\n"}, {"source_code": "a,b,c,d,e=gets.chomp.split.map(&:to_i)\nputs (Math.hypot((d-b),(e-c))/(2*a)).ceil"}, {"source_code": "a,b,c,d,e=gets.chomp.split.map(&:to_i)\nputs (Math.hypot((d-b),(e-c))/(2*a)).ceil"}, {"source_code": "def run\n r, x, y, xp, yp = $stdin.gets.split.map(&:to_i)\n\n dx = xp - x\n dy = yp - y\n\n n = (Math.sqrt(dx * dx + dy * dy) / (r * 2)).ceil\n puts n\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "a,b,c,d,e=gets.chomp.split.map(&:to_i)\nputs (Math.hypot((d-b),(e-c))/(2*a)).ceil\n"}, {"source_code": "a,b,c,d,e=gets.chomp.split.map(&:to_i)\nputs (Math.hypot((d-b),(e-c))/(2*a)).ceil\n"}, {"source_code": "r,x1,y1,x2,y2=gets.split.map{|e| e.to_f}\nr2=Math.hypot(x1-x2,y1-y2)\nr4=r*2\nif r2==0 then\n\tputs 0\nelse\n\tr3=r2.to_i\n\tans=(r2/r4).floor\n\t#p [r2,r4,ans]\n\td=r2-r4*ans\n\tif d>0 && d 0\n # subtract 1 step and make into 2 step to fulfill 2r < R < 4r\n steps += 1\nend\nputs steps\n"}, {"source_code": "a,b,c,d,e=gets.chomp.split.map(&:to_i)\nputs (Math.hypot((d-b),(e-c))/(2*a)).ceil\n"}, {"source_code": "r,x,y,x1,y1 = gets.split(\" \").map(&:to_i)\nd = Math.sqrt((y1-y)**2 + (x1-x)**2)\nputs (d/(2*r).to_f).ceil"}, {"source_code": "a,b,c,d,e=gets.chomp.split.map(&:to_i)\nputs (Math.hypot((d-b),(e-c))/(2*a)).ceil"}, {"source_code": "def stop\n\tputs \"stop\"\n\tsleep(2)\nend\ndef readarr\n\tgets.split.map{|i| i.to_i}\nend\ndef write(foo)\n\tif foo.is_a?(Array)\n\t\tputs foo.map{|i| i.to_s}.join(\" \")\n\telse \n\t\tputs foo\n\tend\nend\nr, x, y, x1, y1 = readarr\nN = ((x1-x)**2+(y1-y)**2)\nl = (4*r*r)\nans =(N/l)**0.5\nif(ans*ans*l==N)\n\tputs ans.to_i\nelse\n\tputs ans.to_i+1\nend\n#sleep(300)"}, {"source_code": "a,b,c,d,e=gets.chomp.split.map(&:to_i)\nputs (Math.hypot((d-b),(e-c))/(2*a)).ceil\n"}, {"source_code": "r, x, y, xd, yd = gets.split(\" \").map &:to_f\n\nlen = Math.sqrt((xd - x)**2 + (yd - y)**2)\n\nputs (len / (2 * r)).ceil"}, {"source_code": "a,b,c,d,e=gets.chomp.split.map(&:to_i)\nputs (Math.hypot((d-b),(e-c))/(2*a)).ceil\n"}, {"source_code": "#!ruby\n\nr, x0, y0, x1, y1 = gets.split.map{|e| e.to_i}\n\ndistance = Math.sqrt((x1-x0)**2 + (y1-y0)**2)\n\ncount = 0\n\nwhile ( distance > 0 )\n count += 1\n distance -= r*2\nend\n\nputs count\n"}, {"source_code": "a,b,c,d,e=gets.chomp.split.map(&:to_i)\nputs (Math.hypot((d-b),(e-c))/(2*a)).ceil\n"}], "negative_code": [{"source_code": "r,x1,y1,x2,y2=gets.split.map{|e| e.to_f}\nr2=Math.hypot(x1-x2,y1-y2)\nr4=r*2\nif r2==0 then\n\tputs 0\nelse\n\tr3=r2.to_i\n\tans=(r2/r4).floor\n\t#p [r2,r4,ans]\n\td=r2-r4*ans\n\tif ans==0 then\n\t\tans=2\n\telsif d>0 && d=n && (k-n)%2==0 then break end\n i+=1\nend\n\nputs i\n"}, {"source_code": "j=gets.to_i.abs;i=0;j-=i+=1 while j>0||j&1>0;puts i\n"}, {"source_code": "x = STDIN.gets.chomp.to_i\nif (x < 0)\n x = -x\nend\nn = 0\ni = 0\nwhile true\n n += i;\n if (n == x)\n puts i\n break;\n elsif(n > x && (n-x) % 2 == 0)\n puts i\n break;\n end\n i += 1\nend\n"}, {"source_code": "j=gets.to_i.abs;i=0;j-=i+=1 while j>0||j&1>0;puts i\n"}, {"source_code": "j=gets.to_i.abs;i=0;j-=i+=1 while j>0||j&1>0;puts i"}, {"source_code": "j=-gets.to_i.abs;i=0;j+=i+=1 while j<0||j&1>0;puts i"}, {"source_code": "x=gets.to_i.abs;i=j=0;while j0 do j+=i+=1 end;puts i"}, {"source_code": "j=gets.to_i.abs;i=0;j-=i+=1 while j>0||j&1>0;puts i"}, {"source_code": "j=gets.to_i.abs;i=0;j-=i+=1 while j>0||j&1>0;puts i\n"}, {"source_code": "j=gets.to_i.abs;i=0;j-=i+=1 while j>0||j&1>0;puts i\n"}, {"source_code": "j=gets.to_i.abs;i=0;j-=i+=1 while j>0||j&1>0;puts i"}, {"source_code": "n=gets.to_i.abs;s=i=0;s+=i+=1 while s0;p i"}, {"source_code": "j=gets.to_i.abs;i=0;j-=i+=1 while j>0||j&1>0;puts i\n"}, {"source_code": "j=gets.to_i.abs;i=0;j-=i+=1 while j>0||j&1>0;puts i\n"}, {"source_code": "j=gets.to_i.abs;i=0;j-=i+=1 while j>0||j&1>0;puts i\n"}, {"source_code": "#!/usr/bin/ruby\n\nclass Solver\n def solve(x)\n x = x.abs()\n i = 0\n sum = 0\n \n while sum < x or (x - sum)%2 != 0 do\n i += 1\n sum += i\n end\n \n puts i\n end\nend\n\nx = STDIN.gets.to_i\nsolver = Solver.new\nsolver.solve(x)"}, {"source_code": "j=gets.to_i.abs;i=0;j-=i+=1 while j>0||j&1>0;puts i\n"}, {"source_code": "j=gets.to_i.abs;i=0;j-=i+=1 while j>0||j&1>0;puts i\n"}], "negative_code": [{"source_code": "n=gets.to_i.abs\ni=1\nk=0\nwhile k0\n k+=i\n i+=1\nend\n#p k\nputs i-1\n"}, {"source_code": "x = STDIN.gets.chomp.to_i\nn = 0\ni = 0\nwhile true\n n += i;\n if (n == x)\n puts i\n break;\n elsif(n > x && i % 2 != 0)\n puts i\n break;\n end\n i += 1\nend\n \n"}, {"source_code": "x=gets.to_i;i=j=0;while j0 do j+=i+=1 end;puts i"}], "src_uid": "18644c9df41b9960594fdca27f1d2fec"} {"nl": {"description": "Little Petya has recently started attending a programming club. Naturally he is facing the problem of choosing a programming language. After long considerations he realized that Java is the best choice. The main argument in favor of choosing Java was that it has a very large integer data type, called BigInteger.But having attended several classes of the club, Petya realized that not all tasks require using the BigInteger type. It turned out that in some tasks it is much easier to use small data types. That's why a question arises: \"Which integer type to use if one wants to store a positive integer n?\"Petya knows only 5 integer types:1) byte occupies 1 byte and allows you to store numbers from \u2009-\u2009128 to 1272) short occupies 2 bytes and allows you to store numbers from \u2009-\u200932768 to 327673) int occupies 4 bytes and allows you to store numbers from \u2009-\u20092147483648 to 21474836474) long occupies 8 bytes and allows you to store numbers from \u2009-\u20099223372036854775808 to 92233720368547758075) BigInteger can store any integer number, but at that it is not a primitive type, and operations with it are much slower.For all the types given above the boundary values are included in the value range.From this list, Petya wants to choose the smallest type that can store a positive integer n. Since BigInteger works much slower, Peter regards it last. Help him.", "input_spec": "The first line contains a positive number n. It consists of no more than 100 digits and doesn't contain any leading zeros. The number n can't be represented as an empty string. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d).", "output_spec": "Print the first type from the list \"byte, short, int, long, BigInteger\", that can store the natural number n, in accordance with the data given above.", "sample_inputs": ["127", "130", "123456789101112131415161718192021222324"], "sample_outputs": ["byte", "short", "BigInteger"], "notes": null}, "positive_code": [{"source_code": "a = [\n\t[(-128 .. 127), :byte],\n\t[(-32768 .. 32767), :short],\n\t[(-2147483648 .. 2147483647), :int],\n\t[(-9223372036854775808 .. 9223372036854775807), :long]]\nn = gets.to_i\na.each do |r, t|\n\tif r.include? n\n\t\tputs t\n\t\texit\n\tend\nend\nputs :BigInteger\n"}, {"source_code": "n = gets.to_i\n\nif -128 <= n && n <= 127\n puts \"byte\"\nelsif -32768 <= n && n <= 32767\n puts \"short\"\nelsif -2147483648 <= n && n <= 2147483647\n puts \"int\"\nelsif -9223372036854775808 <= n && n <= 9223372036854775807\n puts \"long\"\nelse puts \"BigInteger\"\nend\n"}, {"source_code": "#!/usr/bin/ruby\n\nn = gets.to_i\n\nret = \"BigInteger\"\nret = \"long\" if n <= 9223372036854775807\nret = \"int\" if n <= 2147483647\nret = \"short\" if n <= 32767\nret = \"byte\" if n <= 127\nputs ret\n"}, {"source_code": "#! /usr/bin/ruby\n$a = gets.to_i\ndef f\n if $a < -9223372036854775808 or $a > 9223372036854775807\n return 'BigInteger'\n end\n\n if $a < -2147483648 or $a > 2147483647\n return 'long'\n end\n\n if $a < -32768 or $a > 32767\n return 'int'\n end\n\n if $a < -128 or $a > 127\n return 'short'\n end\n\n return 'byte'\nend\n\nputs f"}, {"source_code": "y = [1 << 7, 1 << 15, 1 << 31, 1 << 63]\nname = ['byte', 'short', 'int', 'long', 'BigInteger']\n\nx = gets.to_i\n\nadd = 0\nif x > 0\n add = -1\nelse\n add = 0\n x = -x\nend\n\nans = ''\nfor i in 0...4\n\n if x <= y[i] + add\n ans = name[i]\n break\n end\n\nend\n\nif ans == ''\n ans = 'BigInteger'\nend\n\nputs ans\n"}, {"source_code": "n = gets.to_i\nputs [[\"byte\", 7], [\"short\", 15], [\"int\", 31], [\"long\", 63], [\"BigInteger\", 1000]].select{ |a| 2 ** a[1] > n}[0][0]"}, {"source_code": "N = gets.to_i\n\nif N > 9223372036854775807\n puts \"BigInteger\"\nelsif N > 2147483647\n puts \"long\"\nelsif N > 32767\n puts \"int\"\nelsif N > 127\n puts \"short\"\nelse\n puts \"byte\"\nend\n"}, {"source_code": "#=================================\nrequire 'prime'\ninclude Math\n\nif ARGV.include?(\"ONLINE_JUDGE\")\n\t$stdin = File.open(\"./input.txt\", \"r\")\n\tARGV.delete(\"ONLINE_JUDGE\")\nend\n#=================================\n\nn=gets.strip.to_i\n\nif n>-129 && n<128\n\tputs :byte\nelsif n>-32769 && n<32768\n\tputs :short\nelsif n>-2147483649 && n<2147483648\n\tputs :int\nelsif n>-9223372036854775809 && n<9223372036854775808\n\tputs :long\nelse\n\tputs :BigInteger\nend\n"}, {"source_code": "arr=[\"byte\",\"short\",\"int\",\"long\",\"BigInteger\"]\nn=(gets.chomp.to_i).abs\nif n > 9223372036854775807\n\tputs arr[4]\nelsif n > 2147483647\n\tputs arr[3]\nelsif n > 32767\n\tputs arr[2]\nelsif n >127\n\tputs arr[1]\nelse\n\tputs arr[0]\nend\n"}, {"source_code": "n = gets.to_i\nif n >= -128 && n <= 127\n puts \"byte\"\nelsif n >= -32768 && n <= 32767\n puts \"short\"\nelsif n >= -2147483648 && n <= 2147483647\n puts \"int\"\nelsif n >= -9223372036854775808 && n <= 9223372036854775807\n puts \"long\"\nelse\n puts \"BigInteger\"\nend\n"}, {"source_code": "d=gets.to_i\nif d>=-128 and d<=127 then puts 'byte'\nelsif d>=-32768 and d<=32767 then puts 'short'\nelsif d>=-2147483648 and d<=2147483647 then puts 'int'\nelsif d>=-9223372036854775808 and d<=9223372036854775807 then puts 'long'\nelse puts 'BigInteger' \nend"}, {"source_code": "a = gets.to_i\na=a<0? a*(-1)-1:a\nputs a<128 ?\"byte\":(a<32768 ?\"short\":(a<2147483648 ?\"int\":(a<9223372036854775808 ?\"long\":\"BigInteger\")))"}, {"source_code": "case gets.to_i\n\twhen -128..127\n\t\tputs \"byte\"\n\twhen -32768..32767\n\t\tputs \"short\"\n\twhen -2147483648..2147483647\n\t\tputs \"int\"\n\twhen -9223372036854775808..9223372036854775807\n\t\tputs \"long\"\n\telse\n\t\tputs \"BigInteger\"\nend"}, {"source_code": "n = gets.to_i\n\nif (n >= -128 && n <= 127)\n puts \"byte\"\n exit\nend\nif (n >= -32768 && n <= 32767)\n puts \"short\"\n exit\nend\nif (n >= -2147483648 && n <= 2147483647)\n puts \"int\"\n exit\nend\nif (n >= -9223372036854775808 && n <= 9223372036854775807)\n puts \"long\"\n exit\nend\n\nputs \"BigInteger\""}, {"source_code": "n = gets\nif n.length > 20\n puts \"BigInteger\"\nelse\n k = n.to_i\n if k >= -128 && k <= 127\n puts \"byte\"\n elsif k >= -32768 && k <= 32767\n puts \"short\"\n elsif k >= -2147483648 && k <= 2147483647\n puts \"int\"\n elsif k >= -9223372036854775808 && k <= 9223372036854775807\n puts \"long\"\n else\n puts \"BigInteger\"\n end\nend\n"}, {"source_code": "n = gets.chomp.to_i\n\nputs case n\nwhen -128..127 then 'byte'\nwhen -32768..32767 then 'short'\nwhen -2147483648..2147483647 then 'int'\nwhen -9223372036854775808..9223372036854775807 then 'long'\nelse 'BigInteger'\nend"}, {"source_code": "n = gets.to_i\n\nif -128 <= n && n <= 127\n puts \"byte\"\nelsif -32768 <= n && n <= 32767\n puts \"short\"\nelsif -2147483648 <= n && n <= 2147483647\n puts \"int\"\nelsif -9223372036854775808 <= n && n <= 9223372036854775807\n puts \"long\"\nelse\n puts \"BigInteger\"\nend\n"}, {"source_code": "n = gets.to_i\nif( n >= -128 && n <= 127)\n puts \"byte\"\n exit\nend\nif( n >= -32768 && n <= 32767)\n puts \"short\"\n exit\nend\nif( n >= -2147483648 && n <= 2147483647)\n puts \"int\"\n exit\nend\nif( n >= -9223372036854775808 && n <= 9223372036854775807)\n puts \"long\"\n exit\nend\nif( n > 9223372036854775807)\n puts \"BigInteger\"\n exit\nend"}, {"source_code": "a = gets.to_i\nres = 'BigInteger'\nres = 'long' if a <= 9223372036854775807\nres = 'int' if a <= 2147483647\nres = 'short' if a <= 32767\nres = 'byte' if a <= 127\nputs res\n"}, {"source_code": "print case gets.to_i\nwhen -128..127\n \"byte\"\nwhen -32768..32767\n \"short\"\nwhen -2147483648..2147483647\n \"int\"\nwhen -9223372036854775808..9223372036854775807\n \"long\"\nelse\n \"BigInteger\"\nend\n"}], "negative_code": [], "src_uid": "33041f1832fa7f641e37c4c638ab08a1"} {"nl": {"description": "Mishka started participating in a programming contest. There are $$$n$$$ problems in the contest. Mishka's problem-solving skill is equal to $$$k$$$.Mishka arranges all problems from the contest into a list. Because of his weird principles, Mishka only solves problems from one of the ends of the list. Every time, he chooses which end (left or right) he will solve the next problem from. Thus, each problem Mishka solves is either the leftmost or the rightmost problem in the list.Mishka cannot solve a problem with difficulty greater than $$$k$$$. When Mishka solves the problem, it disappears from the list, so the length of the list decreases by $$$1$$$. Mishka stops when he is unable to solve any problem from any end of the list.How many problems can Mishka solve?", "input_spec": "The first line of input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \\le n, k \\le 100$$$) \u2014 the number of problems in the contest and Mishka's problem-solving skill. The second line of input contains $$$n$$$ integers $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\le a_i \\le 100$$$), where $$$a_i$$$ is the difficulty of the $$$i$$$-th problem. The problems are given in order from the leftmost to the rightmost in the list.", "output_spec": "Print one integer \u2014 the maximum number of problems Mishka can solve.", "sample_inputs": ["8 4\n4 2 3 1 5 1 6 4", "5 2\n3 1 2 1 3", "5 100\n12 34 55 43 21"], "sample_outputs": ["5", "0", "5"], "notes": "NoteIn the first example, Mishka can solve problems in the following order: $$$[4, 2, 3, 1, 5, 1, 6, 4] \\rightarrow [2, 3, 1, 5, 1, 6, 4] \\rightarrow [2, 3, 1, 5, 1, 6] \\rightarrow [3, 1, 5, 1, 6] \\rightarrow [1, 5, 1, 6] \\rightarrow [5, 1, 6]$$$, so the number of solved problems will be equal to $$$5$$$.In the second example, Mishka can't solve any problem because the difficulties of problems from both ends are greater than $$$k$$$.In the third example, Mishka's solving skill is so amazing that he can solve all the problems."}, "positive_code": [{"source_code": "n, k = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\npos = a.each_with_index.select { |v, i| v > k }.map { _2 }\nif pos.empty?\n\tputs n\nelse\n\tputs pos[0] + (n - 1 - pos[-1])\nend\n"}, {"source_code": "n,k,*a=$<.read.split.map &:to_i\np a.all?{|e|e<=k}?n:a.index{|e|e>k}+(n-1-a.rindex{|e|e>k})"}, {"source_code": "n, k = gets.split.map &:to_i\n\nnums = gets.split.map &:to_i\n\ncount = 0\n\nindex = 0\nfor i in 0..n-1\n if nums[i]<=k\n count+=1\n else\n index = i \n break\n end\nend\n\nif count!=n\n for i in 0..n-index-1\n if nums[n-i-1]<=k\n count+=1\n else\n break\n end\n end\n puts count\nelse \n puts count\nend"}, {"source_code": "\ndef solution\n _, k = read_ints\n ps = read_ints\n\n count = 0\n\n while ps.first && ps.first <= k\n count += 1\n ps.shift\n end\n\n while ps.last && ps.last <= k\n count += 1\n ps.pop\n end\n\n puts count\nend\n\ndef read_int\n gets.to_i\nend\n\ndef read_ints\n gets.split.map(&:to_i)\nend\n\ndef read_string\n gets.chomp\nend\n\nsolution unless ENV['TEST__MODE']\n\n"}, {"source_code": "N, K = gets.split.map(&:to_i)\nas = gets.split.map(&:to_i)\nas.shift while as.length > 0 && as[0] <= K\nas.pop while as.length > 0 && as[-1] <= K\nputs N - as.length"}, {"source_code": "n, k = gets.strip.split.map(&:to_i)\nary = gets.strip.split.map(&:to_i)\nans = 0\nsi = -1\n0.upto(n-1).each do |i|\n if ary[i] <= k\n ans += 1\n si = i\n else\n break\n end\nend\n(n-1).downto(si+1).each do |i|\n if ary[i] <= k\n ans += 1\n else\n break\n end\nend\nputs ans"}, {"source_code": "n,k = readline.split.map(&:to_i)\na = readline.split.map(&:to_i)\n\nans=0\ni=0\nwhile i=0 and a[i]<=k\n\tans += 1\n\ti -= 1\nend\n\nputs [ans,n].min\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\nas = gets.split.map(&:to_i)\n\nans = 0\n(0..n-1).each do |i|\n a = as[i]\n if a <= k\n ans += 1\n else\n break\n end\nend\n\n(n-1).downto(ans) do |i|\n a = as[i]\n if a <= k\n ans += 1\n else\n break\n end\nend\n\nputs ans"}, {"source_code": "# https://codeforces.com/problemset/problem/999/A\ndef solution(n, k, a)\n count = 0\n\n i = 0\n while i < n && a[i] <= k do\n count += 1\n i += 1\n end\n\n return count if count == n\n\n i = n - 1\n while i > 0 && a[i] <= k do\n count += 1\n i -= 1\n end\n\n return count\nend\n\nn, k = gets.chomp.split(\" \").map(&:to_i)\na = gets.chomp.split(\" \").map(&:to_i)\n\nputs solution(n, k, a)\n"}, {"source_code": "n, k = gets.chomp.split.map(&:to_i)\nlist = gets.chomp.split.map(&:to_i)\n\ni, j = 0, n - 1\n\nwhile i < n\n break i if list[i] > k\n i += 1\nend\n\nwhile j >= 0\n break j if list[j] > k\n j -= 1\nend\n\nif i == n && j == -1\n puts n\nelse\n puts (n - (j - i + 1))\nend\n"}, {"source_code": "$n,$k=gets.split\n$n,$k,i=$n.to_i,$k.to_i,0\na=gets.split\n$ans,$flag=[0,0],[0,0]\ndef test(c,p)\n\tif c>$k \n\t yield p,0 \n\telse \n yield p,1 \n\tend\nend\na.each{|c| test(c.to_i,0){|id,fla|\n\t\t\t if fla==0 \n\t\t\t $flag[id]=1\n\t\t\t elsif $flag[id]==0\n $ans[id]=$ans[id]+1\n\t\t\t end\t\t\t\t\n\t\t\t\t}}\na.reverse.each{|c| test(c.to_i,1){|id,fla|\n\t\t\t if fla==0 \n\t\t\t $flag[id]=1\n\t\t\t elsif $flag[id]==0\n $ans[id]=$ans[id]+1\n\t\t\t end\t\t\t\t\n\t\t\t\t}\n\t\t}\nputs [$ans[0]+$ans[1],$n].min\n\n"}, {"source_code": "n, k = gets.split(\" \").map{|n| n.to_i }\na = gets.split(\" \").map{|n| n.to_i }\ncount = 0\nall_solved = true\na.each {|m|\n if m <= k\n count += 1\n next\n end\n all_solved = false\n break\n}\nif all_solved\n puts count\nelse\n a.reverse.each {|m|\n if m <= k\n count += 1\n next\n end\n break\n }\n puts count\nend\n\n"}], "negative_code": [{"source_code": "n,k,*a=$<.read.split.map &:to_i\np a.count{|e|e<=k}"}, {"source_code": "n,k,*a=$<.read.split.map &:to_i\np a.all?{|e|e<=k}?n:a.index{|e|e>k}+(n-a.rindex{|e|e>k})"}, {"source_code": "n, k = gets.split(\" \").map{|n| n.to_i }\na = gets.split(\" \").map{|n| n.to_i }\ncount = 0\nall_solved = true\na.each {|n|\n count += 1 if n <= k\n all_solved = false\n break\n}\nif all_solved\n puts count\nelse\n a.reverse.each {|n|\n count += 1 if n <= k\n break\n }\nend\n\n"}], "src_uid": "ecf0ead308d8a581dd233160a7e38173"} {"nl": {"description": "George woke up and saw the current time s on the digital clock. Besides, George knows that he has slept for time t. Help George! Write a program that will, given time s and t, determine the time p when George went to bed. Note that George could have gone to bed yesterday relatively to the current time (see the second test sample). ", "input_spec": "The first line contains current time s as a string in the format \"hh:mm\". The second line contains time t in the format \"hh:mm\" \u2014 the duration of George's sleep. It is guaranteed that the input contains the correct time in the 24-hour format, that is, 00\u2009\u2264\u2009hh\u2009\u2264\u200923, 00\u2009\u2264\u2009mm\u2009\u2264\u200959.", "output_spec": "In the single line print time p \u2014 the time George went to bed in the format similar to the format of the time in the input.", "sample_inputs": ["05:50\n05:44", "00:00\n01:00", "00:01\n00:00"], "sample_outputs": ["00:06", "23:00", "00:01"], "notes": "NoteIn the first sample George went to bed at \"00:06\". Note that you should print the time only in the format \"00:06\". That's why answers \"0:06\", \"00:6\" and others will be considered incorrect. In the second sample, George went to bed yesterday.In the third sample, George didn't do to bed at all."}, "positive_code": [{"source_code": "class Tm\n attr_accessor :x\n def initialize(a)\n if a.class == String\n h, m = a.split(\":\").map(&:to_i)\n @x = h*60 + m\n else\n @x = a\n @x += 1440 if @x < 0\n end\n end\n def -(y)\n Tm.new (@x - y.x)\n end\n def output\n printf \"%02d:%02d\\n\", @x/60, @x%60\n end\nend\nst = Tm.new gets.chomp\ned = Tm.new gets.chomp\n(st-ed).output"}, {"source_code": "h1, m1 = gets.split(\":\").map( &:to_i )\nh2, m2 = gets.split(\":\").map( &:to_i )\n\ns = ( h1 * 60 + m1 - h2 * 60 - m2 + 1440 ) % 1440\nh = s / 60\ns = s % 60\n\nprintf( \"%02d:%02d\\n\", h, s )\n"}, {"source_code": "#!/usr/bin/ruby\nt=2.times.map{a,b=gets.split(':').map(&:to_i);a*60+b}.reduce(:-)\nt+=1440 if t<0\nputs '%02d:%02d'%[t/60,t%60]"}, {"source_code": "require 'date'\n\n$SIZE_DAY_IN_MINUTES = 24 * 60\n\ndef convert_to_secunds(minutes)\n minutes * 60\nend\n\ndef convert_to_minutes(time)\n time.hour * 60 + time.min\nend\n\nendTime = DateTime.parse gets.chomp\nstartTime = DateTime.parse gets.chomp\n\nendTime_minutes = convert_to_minutes endTime\nstartTime_minutes = convert_to_minutes startTime\n\nif startTime_minutes > endTime_minutes\n minutes_yesterday = $SIZE_DAY_IN_MINUTES - startTime_minutes\n sleep = minutes_yesterday + endTime_minutes\nelse\n sleep = endTime_minutes - startTime_minutes\nend\n\nputs Time.at(convert_to_secunds sleep).utc.strftime(\"%H:%M\")\n"}, {"source_code": "mh,mm = gets.split(\":\").map(&:to_i)\nnh, nn = gets.split(\":\").map(&:to_i)\n\nmh=mh-nh \nmm= mm-nn \n\n\nif mm<0 \n mm+=60 \n mh-=1 \nend \nif mh<0 \n mh+=24\nend \nif mm<10 \n mm= \"0\" + mm.to_s\nend \nif mh<10 \n mh = \"0\"+mh.to_s \nend \nputs \"#{mh}:#{mm}\"\n \n\n\n"}, {"source_code": "class ProblemA\n def initialize\n @dats = STDIN.read.split(\"\\n\")\n @now = @dats[0]\n @slept = @dats[1]\n end\n\n def solve\n slept_h = @slept.split(\":\")[0].to_i % 24\n sleft_m = @slept.split(\":\")[1].to_i\n\n now_h = @now.split(\":\")[0].to_i\n now_m = @now.split(\":\")[1].to_i\n \n m = now_m - sleft_m\n h = now_h - slept_h\n minus = 0\n if m < 0\n m = now_m + 60 - sleft_m\n minus = 1\n end\n \n h = now_h - slept_h - minus\n h = h < 0 ? h + 24 : h\n\n h = h < 10 ? \"0#{h}\" : h\n m = m < 10 ? \"0#{m}\" : m\n print \"#{h}:#{m}\"\n end\nend\n\nsolver = ProblemA.new\nsolver.solve\n"}, {"source_code": "a=gets.chomp.split(\":\")\nb=gets.chomp.split(\":\")\nans=[]\nans[1]=a[1].to_i-b[1].to_i\nif ans[1]<0\nans[1]=60+ans[1]\na[0]=(a[0].to_i-1).to_s\nend\nans[0]=a[0].to_i-b[0].to_i\nif ans[0]<0\nans[0]=24+ans[0]\nend\nout=\"\"\nif ans[0]<10\nout=\"0\"+\"#{ans[0]}\"\nelse\nout=\"#{ans[0]}\"\nend\nif ans[1]<10\nout=out+\":\"+\"0\"+\"#{ans[1]}\"\nelse\nout=out+\":\"+\"#{ans[1]}\"\nend\nputs \"#{out}\""}, {"source_code": "wh,wm=gets.chomp.split(':').collect{|a| a.to_i}\nsh,sm=gets.chomp.split(':').collect{|a| a.to_i}\nrh=0\nrm=0\nif wm= 0 then\n\n\thr = x/60\n\tmn = x%60\n\n\tprint \"0\" if hr < 10 \n\tprint hr,\":\"\n\tprint \"0\" if mn < 10\n\tprint mn\n\nelse\n\n\thr = ((24*60) - (-1*x)) / 60\n\tmn = ((24*60) - (-1*x)) % 60\n\tprint \"0\" if hr < 10 \n\tprint hr,\":\"\n\tprint \"0\" if mn < 10\n\tprint mn\n\nend\n\n\n\n"}, {"source_code": "s = gets.strip.split(\":\").map! {|i| i.to_i}\nshh = s[0]\nsmm = s[1]\n\nt = gets.strip.split(\":\").map! {|i| i.to_i}\nthh = t[0]\ntmm = t[1]\n\nahh = (shh-thh)\namm = (smm-tmm)\nif amm < 0\n ahh = ahh - 1\n amm = 60 + amm\nend\nif ahh < 0\n ahh = 24 + ahh\nend\nputs \"%02d:%02d\" % [ahh, amm]\n\n"}, {"source_code": "sh, sm = gets.chomp.split(\":\").map(&:to_i)\nth, tm = gets.chomp.split(\":\").map(&:to_i)\nif sm < tm\n sh -= 1\n sm += 60\nend\nph = [sh - th, (24 + (sh - th)) % 24].max\npm = sm - tm\nputs \"#{\"%02d\" % ph}:#{\"%02d\" % pm}\"\n"}, {"source_code": "a=gets.chomp.split(\":\")\nb=gets.chomp.split(\":\")\nans=[]\nans[1]=a[1].to_i-b[1].to_i\nif ans[1]<0\nans[1]=60+ans[1]\na[0]=(a[0].to_i-1).to_s\nend\nans[0]=a[0].to_i-b[0].to_i\nif ans[0]<0\nans[0]=24+ans[0]\nend\nout=\"\"\nif ans[0]<10\nout=\"0\"+\"#{ans[0]}\"\nelse\nout=\"#{ans[0]}\"\nend\nif ans[1]<10\nout=out+\":\"+\"0\"+\"#{ans[1]}\"\nelse\nout=out+\":\"+\"#{ans[1]}\"\nend\nputs \"#{out}\""}, {"source_code": "#!/usr/bin/ruby\nt=2.times.map{a,b=gets.split(':').map(&:to_i);a*60+b}.reduce(:-)\nt+=1440 if t<0\nputs '%02d:%02d'%[t/60,t%60]"}, {"source_code": "def parse_time(time)\n time.split(':').map(&:to_i)\nend\n\ndef to_str(h, m)\n [h, m].map { |t| \"%02d\" % t }.join(':')\nend\n\ndef solve(cur_time, duration)\n hc, mc = parse_time cur_time\n hd, md = parse_time duration\n hg = hc - hd\n mg = mc - md\n if mg < 0\n mg = 60 + mg\n hg -= 1\n end\n hg = (hg + 24) % 24\n to_str(hg, mg)\nend\n\nif __FILE__ == $0\n puts solve(gets.chomp, gets.chomp)\nend"}, {"source_code": "def parseTime(s)\n\t[s[0,2].to_i, s[-2, 2].to_i]\nend\n\nh1, m1 = parseTime(gets.chomp)\nh2, m2 = parseTime(gets.chomp)\n\nt1 = h1*60+m1\nt2 = h2*60+m2\n\nif t2 > t1\n\tt1 += 1440\nend\n\nresult = t1 - t2\n\nprint \"%02d:%02d\" % [result / 60, result % 60]"}, {"source_code": "a = gets.split(':').map(&:to_i)\nb = gets.split(':').map(&:to_i)\na[0] -= b[0]\na[1] -= b[1]\n(a[1] += 60; a[0] -= 1) if a[1] < 0\na[0] += 24 if a[0] < 0\nputs \"#{\"%02d\" % a[0]}:#{\"%02d\" % a[1]}\"\n"}], "negative_code": [{"source_code": "mh,mm = gets.split(\":\").map(&:to_i)\nnh, nn = gets.split(\":\").map(&:to_i)\n\nmh=mh-nh \nmm= mm-nn \nif mm<0 \n mm-=60 \n mh+=1 \nend \nif mh<0 \n mh+=24\nend \nif mm<10 \n mm= \"0\" + mm.to_s\nend \nif mh<10 \n mh = \"0\"+mh.to_s \nend \nputs \"#{mh}:#{mm}\"\n \n\n\n"}, {"source_code": "wh,wm=gets.chomp.split(':').collect{|a| a.to_i}\nsh,sm=gets.chomp.split(':').collect{|a| a.to_i}\nrh=0\nrm=0\nif wm 0)\n if (n % 2 == 1) \n k = true\n end\n n /= 10\nend\n\nif (k) \n puts 1\nelse\n puts 0\nend"}, {"source_code": "puts gets.to_i/2"}, {"source_code": "puts 0"}, {"source_code": "puts gets.size.even? ? 0 : 1\n"}, {"source_code": "puts gets[0].to_i.even? ? 0 : 1\n"}, {"source_code": "\nn = gets.to_i \n\nif(n&1)\n puts 1 \nelse\n puts 0 \nend "}], "src_uid": "78e64fdbf59c5ce89d0f0a1d0591f795"} {"nl": {"description": "Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?", "input_spec": "The first and only line contains two integers x and y (3\u2009\u2264\u2009y\u2009<\u2009x\u2009\u2264\u2009100\u2009000)\u00a0\u2014 the starting and ending equilateral triangle side lengths respectively.", "output_spec": "Print a single integer\u00a0\u2014 the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.", "sample_inputs": ["6 3", "8 5", "22 4"], "sample_outputs": ["4", "3", "6"], "notes": "NoteIn the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a,\u2009b,\u2009c). Then, Memory can do .In the second sample test, Memory can do .In the third sample test, Memory can do: ."}, "positive_code": [{"source_code": "#!/usr/bin/ruby\nx,y=gets.split.map(&:to_i)\na=[y]*3\nr=0\nwhile a[0]!=x\n\ta[0]=[a[1]+a[2]-1,x].min\n\ta.sort!\n\tr+=1\nend\np r"}, {"source_code": "x, y = gets.split.map(&:to_i)\na = [y] * 3\nr = 0\nuntil a[0] == x\n\ta[0] = [a[1] + a[2] - 1, x].min\n\ta.sort!\n\tr += 1\nend\n\nputs r\n"}, {"source_code": "def printlol(ar)\n for i in 0..(ar.length-2) do\n print ar[i]\n print \" \"\n end\n print ar.last\n puts \"\"\nend\n\n\ninput = gets.strip.split(' ').map(&:to_i)\nx = input[0]\ny = input[1]\n\nlol = [y, y, y]\ncount = 0\nwhile lol[0] != x or lol[1] != x or lol[2] != x do\n asd = lol.dup\n asd.slice!(lol.index(lol.min))\n top = (asd[0] + asd[1])\n \n if top - 1 > x\n asd << x\n else\n asd << top - 1\n end\n \n lol = asd\n count += 1\n #printlol(lol)\nend\n\nputs count"}, {"source_code": "x, y=gets.split.map &:to_i\na=y, y, y\nres=0\nwhile a[0]= sortedSides[1] + sortedSides[2] - sortedSides[0]\n sides[sides.index(sortedSides[0])] = sides[sides.index(sortedSides[0])] + power\n \n #print sides\n #puts ''\n \n ans += 1\nend\n\nputs ans"}], "negative_code": [{"source_code": "#!/usr/bin/ruby\nx,y=gets.split.map(&:to_i)\na=[x]*3\nr=0\nwhile a[2]!=y\n\ta[2]=[a[1]-a[0]+1,y].max\n\ta.sort!\n\tr+=1\nend\np r"}, {"source_code": "def printlol(ar)\n for i in 0..(ar.length-2) do\n print ar[i]\n print \" \"\n end\n print ar.last\n puts \"\"\nend\n\n\ninput = gets.strip.split(' ').map(&:to_i)\nx = input[0]\ny = input[1]\n\nlol = [x, x, x]\ncount = 0\nwhile lol[0] != y or lol[1] != y or lol[2] != y do\n asd = lol.dup\n asd.slice!(lol.index(lol.max))\n fark = (asd[0] - asd[1]).abs\n if fark + 1 < y\n asd << [y, ((asd[0] + asd[1]) / 6.to_f).round].max\n else\n if (fark + 1) >= ((asd[0] + asd[1]) / 6.to_f).round\n asd << (fark + 1)\n else\n asd << ((asd[0] + asd[1]) / 6.to_f).round\n end\n end\n lol = asd\n count += 1\n #printlol(lol)\nend\n\nputs count"}, {"source_code": "def printlol(ar)\n for i in 0..(ar.length-2) do\n print ar[i]\n print \" \"\n end\n print ar.last\n puts \"\"\nend\n\n\ninput = gets.strip.split(' ').map(&:to_i)\nx = input[0]\ny = input[1]\n\nlol = [x, x, x]\ncount = 0\nwhile lol[0] != y or lol[1] != y or lol[2] != y do\n asd = lol.dup\n asd.slice!(lol.index(lol.max))\n fark = (asd[0] - asd[1]).abs\n if fark + 1 < y\n asd << [y, ((asd[0] + asd[1]) / 6)].max\n else\n if (fark + 1) >= ((asd[0] + asd[1]) / 6)\n asd << (fark + 1)\n else\n asd << ((asd[0] + asd[1]) / 6)\n end\n end\n lol = asd\n count += 1\n if count > 20\n break\n end\n #printlol(lol)\nend\n\nputs count"}, {"source_code": "def printlol(ar)\n for i in 0..(ar.length-2) do\n print ar[i]\n print \" \"\n end\n print ar.last\n puts \"\"\nend\n\n\ninput = gets.strip.split(' ').map(&:to_i)\nx = input[0]\ny = input[1]\n\nlol = [x, x, x]\ncount = 0\nwhile lol[0] != y or lol[1] != y or lol[2] != y do\n asd = lol.dup\n asd.slice!(lol.index(lol.max))\n fark = (asd[0] - asd[1]).abs\n if fark + 1 < y\n if (y - ((asd[0] + asd[1] + 1) / 6.to_f).round + 1).abs == 1\n asd << y\n else\n asd << [y, ((asd[0] + asd[1] + 1) / 6.to_f).round + 1].max\n end\n else\n if (fark + 1) >= ((asd[0] + asd[1] + 1) / 6.to_f).round + 1\n asd << (fark + 1)\n else\n asd << ((asd[0] + asd[1] + 1) / 6.to_f).round + 1\n end\n end\n lol = asd\n count += 1\n #printlol(lol)\nend\n\nputs count"}, {"source_code": "def printlol(ar)\n for i in 0..(ar.length-2) do\n print ar[i]\n print \" \"\n end\n print ar.last\n puts \"\"\nend\n\n\ninput = gets.strip.split(' ').map(&:to_i)\nx = input[0]\ny = input[1]\n\nlol = [x, x, x]\ncount = 0\nwhile lol[0] != y or lol[1] != y or lol[2] != y do\n asd = lol.dup\n asd.slice!(lol.index(lol.max))\n fark = (asd[0] - asd[1]).abs\n if fark + 1 < y\n asd << [y, ((asd[0] + asd[1]) / 6)].max\n else\n if (fark + 1) >= ((asd[0] + asd[1]) / 6)\n asd << (fark + 1)\n else\n asd << ((asd[0] + asd[1]) / 6)\n end\n end\n lol = asd\n count += 1\n if count > 20\n break\n end\n printlol(lol)\nend\n\nputs count"}, {"source_code": "def printlol(ar)\n for i in 0..(ar.length-2) do\n print ar[i]\n print \" \"\n end\n print ar.last\n puts \"\"\nend\n\n\ninput = gets.strip.split(' ').map(&:to_i)\nx = input[0]\ny = input[1]\n\nlol = [x, x, x]\ncount = 0\nwhile lol[0] != y or lol[1] != y or lol[2] != y do\n asd = lol.dup\n asd.slice!(lol.index(lol.max))\n fark = (asd[0] - asd[1]).abs\n if fark + 1 < y\n asd << [y, ((asd[0] + asd[1]) / 6)].max\n else\n if (fark + 1) >= ((asd[0] + asd[1]) / 6)\n asd << (fark + 1)\n else\n asd << ((asd[0] + asd[1]) / 6)\n end\n end\n lol = asd\n count += 1\n #printlol(lol)\nend\n\nputs count"}, {"source_code": "def printlol(ar)\n for i in 0..(ar.length-2) do\n print ar[i]\n print \" \"\n end\n print ar.last\n puts \"\"\nend\n\n\ninput = gets.strip.split(' ').map(&:to_i)\nx = input[0]\ny = input[1]\n\nlol = [x, x, x]\ncount = 0\nwhile lol[0] != y or lol[1] != y or lol[2] != y do\n asd = lol.dup\n asd.slice!(lol.index(lol.max))\n fark = (asd[0] - asd[1]).abs\n if fark + 1 < y\n asd << [y, ((asd[0] + asd[1]) / 6)].max\n else\n if (fark + 1) >= ((asd[0] + asd[1]) / 6)\n asd << (fark + 1)\n else\n asd << ((asd[0] + asd[1]) / 6)\n end\n end\n lol = asd\n count += 1\n printlol(lol)\nend\n\nputs count"}, {"source_code": "n, m = readline.split.map(&:to_i)\n\ns = [m,m,m]\n\nans = 0\nwhile s.min <= n\n s[0] = s[1] + s[2]\n s=s.sort\n ans += 1\nend\n\nputs ans\n\n"}], "src_uid": "8edf64f5838b19f9a8b19a14977f5615"} {"nl": {"description": "The girl Taylor has a beautiful calendar for the year y. In the calendar all days are given with their days of week: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday.The calendar is so beautiful that she wants to know what is the next year after y when the calendar will be exactly the same. Help Taylor to find that year.Note that leap years has 366 days. The year is leap if it is divisible by 400 or it is divisible by 4, but not by 100 (https://en.wikipedia.org/wiki/Leap_year).", "input_spec": "The only line contains integer y (1000\u2009\u2264\u2009y\u2009<\u2009100'000) \u2014 the year of the calendar.", "output_spec": "Print the only integer y' \u2014 the next year after y when the calendar will be the same. Note that you should find the first year after y with the same calendar.", "sample_inputs": ["2016", "2000", "50501"], "sample_outputs": ["2044", "2028", "50507"], "notes": "NoteToday is Monday, the 13th of June, 2016."}, "positive_code": [{"source_code": "#!/usr/bin/ruby\ndef zeller(_y,m,d)\n\tm+=1\n\tif m<4 then _y-=1;m+=12 end\n\ty=_y/100;z=_y%100\n\t(5*y+z+y/4+z/4+13*m/5+d-1)%7\nend\ndef leap(y)\n\treturn true if y%400==0\n\treturn false if y%100==0\n\ty%4==0\nend\nn=gets.to_i\na=[zeller(n,1,1),leap(n)]\np (n+1..1/0.0).find{|i|a==[zeller(i,1,1),leap(i)]}"}], "negative_code": [], "src_uid": "565bbd09f79eb7bfe2f2da46647af0f2"} {"nl": {"description": "Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string s consisting only of lowercase and uppercase Latin letters.Let A be a set of positions in the string. Let's call it pretty if following conditions are met: letters on positions from A in the string are all distinct and lowercase; there are no uppercase letters in the string which are situated between positions from A (i.e. there is no such j that s[j] is an uppercase letter, and a1\u2009<\u2009j\u2009<\u2009a2 for some a1 and a2 from A). Write a program that will determine the maximum number of elements in a pretty set of positions.", "input_spec": "The first line contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009200) \u2014 length of string s. The second line contains a string s consisting of lowercase and uppercase Latin letters.", "output_spec": "Print maximum number of elements in pretty set of positions for string s.", "sample_inputs": ["11\naaaaBaabAbA", "12\nzACaAbbaazzC", "3\nABC"], "sample_outputs": ["2", "3", "0"], "notes": "NoteIn the first example the desired positions might be 6 and 8 or 7 and 8. Positions 6 and 7 contain letters 'a', position 8 contains letter 'b'. The pair of positions 1 and 8 is not suitable because there is an uppercase letter 'B' between these position.In the second example desired positions can be 7, 8 and 11. There are other ways to choose pretty set consisting of three elements.In the third example the given string s does not contain any lowercase letters, so the answer is 0."}, "positive_code": [{"source_code": "n = gets.to_i\n\nans = 0\n\nabc = []\ngets.chomp.each_char do |c|\n\tif 'a' <= c && c <= 'z'\n\t\tabc[c.ord - 'a'.ord] = 1\n\telse\n\t\tans = [ans, abc.count(1)].max\n\t\tabc = []\n\tend\nend\n\np [ans, abc.count(1)].max"}, {"source_code": "def is_up_case?( chr )\n chr >= 'A' && chr <= 'Z'\nend\nn = gets.strip.to_i\ns = gets.strip\ni = ans = 0\nprev = '0'\nwhile i < n\n curr = s[i]\n dist = {}\n while !is_up_case? curr\n curr = s[i]\n break if curr.nil? || is_up_case?( curr )\n dist[curr] = 1 if dist[curr].nil?\n prev = curr\n i += 1\n end\n ans = [ans, dist.length].max\n i += 1\nend\nputs ans\n"}, {"source_code": "class String\n def is_lower?\n self == self.downcase\n end\nend\n\nn = STDIN.gets.chomp.to_i\ns = STDIN.gets.chomp\nletters = {}\nanswer = 0\ns.each_char do |ch|\n if ch.is_lower?\n letters[ch] = true\n else\n answer = [answer, letters.size].max\n letters = {}\n end\nend\nanswer = [answer, letters.size].max\nputs answer\n"}, {"source_code": "gets\np gets.chomp.split(/[A-Z]+/).map{|s|s.split(//).uniq.length}.max||0"}, {"source_code": "gets\np gets.chomp.split(/[A-Z]+/).each.map{|s|s.split(//).uniq.length}.max || 0"}], "negative_code": [{"source_code": "n = gets.to_i\n\nans = 0\n\nabc = []\ngets.chomp.each_char do |c|\n\tif 'a' <= c && c <= 'z'\n\t\tabc[c.ord - 'a'.ord] = 1\n\telse\n\t\tans = [ans, abc.count(1)].max\n\t\tabc = []\n\tend\nend\n\np ans"}, {"source_code": "n = gets.strip.to_i\ns = gets.strip\ncount = Array.new(26, 0)\nn.times do |i|\n curr = s[i]\n if curr >= 'a' && curr <= 'z'\n pos = curr.ord - 'a'.ord\n count[pos] += 1\n end\nend\nans = 0\ncount.each do |a|\n ans += 1 if a > 0\nend\nputs ans\n"}, {"source_code": "class String\n def is_lower?\n self == self.downcase\n end\nend\n\nn = STDIN.gets.chomp.to_i\ns = STDIN.gets.chomp\nletters = {}\nanswer = 0\ns.each_char do |ch|\n if ch.is_lower?\n letters[ch] = true\n else\n answer = [answer, letters.size].max\n letters = {}\n end\nend\nputs answer\n"}], "src_uid": "567ce65f87d2fb922b0f7e0957fbada3"} {"nl": {"description": "Soon a school Olympiad in Informatics will be held in Berland, n schoolchildren will participate there.At a meeting of the jury of the Olympiad it was decided that each of the n participants, depending on the results, will get a diploma of the first, second or third degree. Thus, each student will receive exactly one diploma.They also decided that there must be given at least min1 and at most max1 diplomas of the first degree, at least min2 and at most max2 diplomas of the second degree, and at least min3 and at most max3 diplomas of the third degree.After some discussion it was decided to choose from all the options of distributing diplomas satisfying these limitations the one that maximizes the number of participants who receive diplomas of the first degree. Of all these options they select the one which maximizes the number of the participants who receive diplomas of the second degree. If there are multiple of these options, they select the option that maximizes the number of diplomas of the third degree.Choosing the best option of distributing certificates was entrusted to Ilya, one of the best programmers of Berland. However, he found more important things to do, so it is your task now to choose the best option of distributing of diplomas, based on the described limitations.It is guaranteed that the described limitations are such that there is a way to choose such an option of distributing diplomas that all n participants of the Olympiad will receive a diploma of some degree.", "input_spec": "The first line of the input contains a single integer n (3\u2009\u2264\u2009n\u2009\u2264\u20093\u00b7106)\u00a0\u2014\u00a0the number of schoolchildren who will participate in the Olympiad. The next line of the input contains two integers min1 and max1 (1\u2009\u2264\u2009min1\u2009\u2264\u2009max1\u2009\u2264\u2009106)\u00a0\u2014\u00a0the minimum and maximum limits on the number of diplomas of the first degree that can be distributed. The third line of the input contains two integers min2 and max2 (1\u2009\u2264\u2009min2\u2009\u2264\u2009max2\u2009\u2264\u2009106)\u00a0\u2014\u00a0the minimum and maximum limits on the number of diplomas of the second degree that can be distributed. The next line of the input contains two integers min3 and max3 (1\u2009\u2264\u2009min3\u2009\u2264\u2009max3\u2009\u2264\u2009106)\u00a0\u2014\u00a0the minimum and maximum limits on the number of diplomas of the third degree that can be distributed. It is guaranteed that min1\u2009+\u2009min2\u2009+\u2009min3\u2009\u2264\u2009n\u2009\u2264\u2009max1\u2009+\u2009max2\u2009+\u2009max3.", "output_spec": "In the first line of the output print three numbers, showing how many diplomas of the first, second and third degree will be given to students in the optimal variant of distributing diplomas. The optimal variant of distributing diplomas is the one that maximizes the number of students who receive diplomas of the first degree. Of all the suitable options, the best one is the one which maximizes the number of participants who receive diplomas of the second degree. If there are several of these options, the best one is the one that maximizes the number of diplomas of the third degree.", "sample_inputs": ["6\n1 5\n2 6\n3 7", "10\n1 2\n1 3\n1 5", "6\n1 3\n2 2\n2 2"], "sample_outputs": ["1 2 3", "2 3 5", "2 2 2"], "notes": null}, "positive_code": [{"source_code": "N=gets.to_i\nA=$<.map{|e|e.split.map(&:to_i)}\na=[A[0][1],N-A[1][0]-A[2][0]].min\nb=[A[1][1],N-a-A[2][0]].min\nc=N-a-b\nputs [a,b,c]*' '"}, {"source_code": "def dsum(given_degree)\n given_degree['1'] + given_degree['2'] + given_degree['3']\nend\n\nn = gets.to_i\ndegree = gets.split(' ')\ndegree_1 = {:min => degree.first.to_i, :max => degree.last.to_i}\ndegree = gets.split(' ')\ndegree_2 = {:min => degree.first.to_i, :max => degree.last.to_i}\ndegree = gets.split(' ')\ndegree_3 = {:min => degree.first.to_i, :max => degree.last.to_i}\ngiven_degree = {'1' => degree_1[:min], '2' => degree_2[:min], '3' => degree_3[:min]}\nif dsum(given_degree) == n\n puts \"#{given_degree['1']} #{given_degree['2']} #{given_degree['3']}\"\nelse\n if n - dsum(given_degree) <= (degree_1[:max] - given_degree['1'])\n given_degree['1'] += n - dsum(given_degree)\n else\n given_degree['1'] = degree_1[:max]\n puts \"#{given_degree['2']} #{given_degree['2']} #{given_degree['3']}\" if dsum(given_degree) == n\n if n - dsum(given_degree) <= (degree_2[:max] - given_degree['2'])\n given_degree['2'] += n - dsum(given_degree)\n else\n given_degree['2'] = degree_2[:max]\n puts \"#{given_degree['1']} #{given_degree['2']} #{given_degree['3']}\" if dsum(given_degree) == n\n if n - dsum(given_degree) <= (degree_3[:max] - given_degree['3'])\n given_degree['3'] += n - dsum(given_degree)\n end\n end\n end\n puts \"#{given_degree['1']} #{given_degree['2']} #{given_degree['3']}\"\nend\n\n"}, {"source_code": "# http://codeforces.com/contest/557/problem/A\nn = gets.chomp.to_i\nfirst, second, third = [].tap do |arr|\n 3.times { arr << gets.chomp.split.map(&:to_i) }\nend\n\na = [first[1], n - second[0] - third[0]].min\nb = [second[1], n - a - third[0]].min\nc = n - a - b\n\nputs [a, b, c].join(' ')\n"}, {"source_code": "N=gets.to_i\nA=$<.map{|e|e.split.map(&:to_i)}\na=[A[0][1],N-A[1][0]-A[2][0]].min\nb=[A[1][1],N-a-A[2][0]].min\nc=N-a-b\nputs [a,b,c]*' '"}, {"source_code": "n = gets.to_i\na = []\n3.times { a << gets.split(\" \").map(&:to_i) }\nn -= a.map{|p| p[0]}.inject(&:+)\n\n(0..2).each{|i|\n tmp = a[i][0]\n a[i][0] = [a[i][1], a[i][0] + n].min\n n -= a[i][0] - tmp \n}\n\nputs a.map{|p| p[0]}.join(\" \")\n"}, {"source_code": "def read_ints; gets.chomp.split.map(&:to_i) end\n@n = read_ints[0]\nmin1,max1 = read_ints\nmin2,max2 = read_ints\nmin3,max3 = read_ints\n\n@rez = [min1,min2,min3]\n\ndef left; @n - @rez.inject(:+) end\n\n@rez[0]+=[left,max1-@rez[0]].min\n@rez[1]+=[left,max2-@rez[1]].min\n@rez[2]+=[left,max3-@rez[2]].min\n\nputs @rez.join(' ')"}, {"source_code": "n = gets.to_i\nmin1, max1 = gets.split.map { |e| e.to_i }\nmin2, max2 = gets.split.map { |e| e.to_i }\nmin3, max3 = gets.split.map { |e| e.to_i }\n\nd1, d2, d3 = 0, 0, 0\n\nd1 = n-min2-min3 > max1 ? max1 : n-min2-min3\nn -= d1\nprint d1.to_s + ' '\n\nd2 = n-min3 > max2 ? max2 : n-min3\nn -= d2\nprint d2.to_s + ' '\n\nprint n\n"}, {"source_code": "n = gets.to_i\na = 3.times.map{gets.split.map(&:to_i)}\np = a.map{|x, y| x}\nn -= p.inject(:+)\n3.times do |i|\n mi = [a[i][1] - a[i][0], n].min\n p[i] += mi\n n -= mi\n break if n <= 0\nend\nputs p.join(' ')\n"}, {"source_code": "n = gets.to_i\na = 3.times.map{gets.split.map(&:to_i)}\np = a.map{|x, y| x}\nn -= p.inject(:+)\n3.times do |i|\n mi = [a[i][1] - a[i][0], n].min\n p[i] += mi\n n -= mi\n break if n <= 0\nend\nputs \"#{p[0]} #{p[1]} #{p[2]}\"\n"}, {"source_code": "N=gets.to_i\nA=$<.map{|e|e.split.map(&:to_i)}\na=[A[0][1],N-A[1][0]-A[2][0]].min\nb=[A[1][1],N-a-A[2][0]].min\nc=N-a-b\nputs [a,b,c]*' '"}, {"source_code": "n = gets.chomp.to_i\n\na = []\n3.times {a << gets.chomp.split(\" \").map(&:to_i)}\n\nx = a[0][0]\ny = a[1][0]\nz = a[2][0]\n\nwhile x + y + z < n\n\tif a[0][0] < a[0][1]\n\t\tx += 1\n\t\ta[0][0] += 1\n\telsif a[1][0] < a[1][1]\n\t\ty += 1\n\t\ta[1][0] += 1\n\telsif a[2][0] < a[2][1]\n\t\tz += 1\n\t\ta[2][0] += 1\n\telse\n\t\tbreak\n\tend\nend\n\nputs [x, y, z] * \" \"\n"}], "negative_code": [{"source_code": "def dsum(given_degree)\n given_degree['1'] + given_degree['2'] + given_degree['3']\nend\n\nn = gets.to_i\ndegree = gets.split(' ')\ndegree_1 = {:min => degree.first.to_i, :max => degree.last.to_i}\ndegree = gets.split(' ')\ndegree_2 = {:min => degree.first.to_i, :max => degree.last.to_i}\ndegree = gets.split(' ')\ndegree_3 = {:min => degree.first.to_i, :max => degree.last.to_i}\ngiven_degree = {'1' => degree_1[:min], '2' => degree_2[:min], '3' => degree_3[:min]}\nif dsum(given_degree) == n\n puts \"#{given_degree['1']} #{given_degree['2']} #{given_degree['3']}\"\nelse\n if n - dsum(given_degree) <= (degree_1[:max] - given_degree['1'])\n given_degree['1'] += n - dsum(given_degree)\n else\n given_degree['1'] = degree_1[:max]\n puts \"#{given_degree['2']} #{given_degree['2']} #{given_degree['3']}\" if dsum(given_degree) == n\n if n - dsum(given_degree) <= (degree_2[:max] - given_degree['2'])\n given_degree['2'] += n - dsum(given_degree)\n else\n given_degree['2'] = degree_2[:max]\n puts \"#{given_degree['1']} #{given_degree['2']} #{given_degree['3']}\" if dsum(given_degree) == n\n if n - dsum(given_degree) <= (degree_3[:max] - given_degree['3'])\n given_degree['3'] += n - dsum(given_degree)\n end\n end\n end\nend\nputs \"#{given_degree['1']} #{given_degree['2']} #{given_degree['3']}\"\n"}], "src_uid": "3cd092b6507079518cf206deab21cf97"} {"nl": {"description": "Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number a and Antisimon receives number b. They also have a heap of n stones. The players take turns to make a move and Simon starts. During a move a player should take from the heap the number of stones equal to the greatest common divisor of the fixed number he has received and the number of stones left in the heap. A player loses when he cannot take the required number of stones (i. e. the heap has strictly less stones left than one needs to take). Your task is to determine by the given a, b and n who wins the game.", "input_spec": "The only string contains space-separated integers a, b and n (1\u2009\u2264\u2009a,\u2009b,\u2009n\u2009\u2264\u2009100) \u2014 the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile.", "output_spec": "If Simon wins, print \"0\" (without the quotes), otherwise print \"1\" (without the quotes).", "sample_inputs": ["3 5 9", "1 1 100"], "sample_outputs": ["0", "1"], "notes": "NoteThe greatest common divisor of two non-negative integers a and b is such maximum positive integer k, that a is divisible by k without remainder and similarly, b is divisible by k without remainder. Let gcd(a,\u2009b) represent the operation of calculating the greatest common divisor of numbers a and b. Specifically, gcd(x,\u20090)\u2009=\u2009gcd(0,\u2009x)\u2009=\u2009x.In the first sample the game will go like that: Simon should take gcd(3,\u20099)\u2009=\u20093 stones from the heap. After his move the heap has 6 stones left. Antisimon should take gcd(5,\u20096)\u2009=\u20091 stone from the heap. After his move the heap has 5 stones left. Simon should take gcd(3,\u20095)\u2009=\u20091 stone from the heap. After his move the heap has 4 stones left. Antisimon should take gcd(5,\u20094)\u2009=\u20091 stone from the heap. After his move the heap has 3 stones left. Simon should take gcd(3,\u20093)\u2009=\u20093 stones from the heap. After his move the heap has 0 stones left. Antisimon should take gcd(5,\u20090)\u2009=\u20095 stones from the heap. As 0\u2009<\u20095, it is impossible and Antisimon loses.In the second sample each player during each move takes one stone from the heap. As n is even, Antisimon takes the last stone and Simon can't make a move after that."}, "positive_code": [{"source_code": "a,b,n=gets.split.map &:to_i;i=1;n-=[a,b][i^=1].gcd(n)while n>0;p i\n"}, {"source_code": "a, b, n = gets.split.map(&:to_i)\n\ni=0\nwhile n>0 do\n\tt=n.gcd([a,b][i])\n\ti^=1\n\tn-=t\nend\n\nputs i^=1\n"}, {"source_code": "def GCD a, b\n\tif b == 0 then a else GCD b, a%b end\nend\n\na, b, n = gets.split.map(&:to_i)\n\nplayer = :a\nloop do\n\ttake = GCD n, (player == :a ? a : b)\n\t\n\tif n0\n\tn-=n.gcd [a,b][i^=1]\nend\np i\n"}, {"source_code": "a, b, n = gets.split.map &:to_i\ni=1\nn-=n.gcd [a,b][i^=1] while n>0\np i\n"}, {"source_code": "a,b,n=gets.split.map &:to_i;i=1;n-=[a,b][i^=1].gcd n while n>0;p i\n"}, {"source_code": "a, b, n = gets.split.map(&:to_i)\n\ni=0\nwhile n>0\n\tn-=n.gcd([a,b][i])\n\ti^=1\nend\n\np i^=1\n"}, {"source_code": "k=gets.split\na,b,k=k[0].to_i,k[1].to_i,k[2].to_i\n\nwhile true\n\tbreak if k==0\n\tk-=k.gcd(a)\n\tans=0\n\tbreak if k==0\n\tk-=k.gcd(b)\n\tans=1\nend\np ans\n"}, {"source_code": "a, b, n = gets.split.map {|x| x.to_i}\n\nwhile true\n n = n - n.gcd(a)\n if n < 0\n puts 1\n exit\n end\n n = n - n.gcd(b)\n if n < 0\n puts 0\n exit\n end\nend"}, {"source_code": "simon, antisimon, heap = gets.split.map(&:to_i)\nsimon_wins = false\n\nwhile(true)\n heap -= simon.gcd(heap) \n break if heap < 0\n simon_wins = true\n heap -= antisimon.gcd(heap)\n break if heap < 0\n simon_wins = false\nend\n\nif simon_wins\n puts \"0\"\nelse\n puts \"1\"\nend\n"}, {"source_code": "a=Array.new(2){0}\na[0],a[1],n = gets.split.map(&:to_i)\n\ndef go(a, n)\nidx = 0\nloop do\n d = a[idx].gcd(n)\n return 1 - idx if d > n\n \n n -= d\n idx = 1 - idx\nend\nend\n\nputs go(a,n)\n"}, {"source_code": "# Epic Game\n# http://codeforces.com/problemset/problem/119/A\n\ndef gcd(a, b)\n return a if b == 0\n return gcd(b, a % b)\nend\n\nsimon, antisimon, stones = gets.chomp.split.map { |e| e.to_i }\n\ncount = 0\n\nloop do\n if count % 2 == 0\n stones = stones - gcd(simon, stones)\n else\n stones = stones - gcd(antisimon, stones)\n end\n \n break if stones <= 0\n count += 1\nend\n\nputs \"#{(count % 2 == 0) ? \"0\" : \"1\"}\""}, {"source_code": "input = $stdin.readline.chop.split(' ')\na = input[0].to_i; b = input[1].to_i; n = input[2].to_i\n\nloop do\n \n need = a.gcd(n)\n if n y\n return gcd(y, x-y)\n else \n return gcd(x, y-x)\n end \n end\nend\n\ndef sov(a,b,n,x)\n if n == 0\n if x == 0\n return 1\n else x == 1\n return 0\n end\n else \n if x == 0 \n return sov(a,b,n-gcd(a,n),1-x)\n else x == 1\n return sov(a,b,n-gcd(b,n),1-x)\n end\n end\nend\n\nputs sov(a,b,n,0)\n"}, {"source_code": "def gcd(a, b)\n min = a.abs\n max = b.abs\n while min > 0\n tmp = min\n min = max % min\n max = tmp\n end\n max\nend\n\ninput = STDIN.gets().split(\" \")\n\na = input[0].to_i\nb = input[1].to_i\nn = input[2].to_i\n\ngameover = false\nuntil gameover\n n = n- gcd(a,n) #S\n if(n < 0) \n gameover = true\n p 1\n else \n n = n- gcd(b,n) #A\n if(n < 0)\n gameover = true\n p 0\n end\n end\n\nend"}, {"source_code": "a,b,n=gets.split.map &:to_i\ngcd=->(x,y){ y==0 ? x : gcd[y,x%y]}\nx,y=1,0\nwhile true \n g=gcd[a,n]\n if (g>n) \n puts x\n break\n end\n n-=g\n a,b,x,y=b,a,y,x\nend"}, {"source_code": "m=gets.split.map &:to_i;i=0;i^=1while 0 0 do\n if win == 1\n c -= c.gcd(a)\n else\n c -= c.gcd(b)\n end\n win ^= 1 \nend\nputs win"}, {"source_code": "def NOD(a, b)\n\twhile b != 0\n\t\ta, b = b, a % b\n\tend\n\t\n\treturn a\nend\n\nl = gets.split.map(&:to_i)\no = 0\n\nloop do\n\tt = NOD(l[o], l[2])\n\tif l[2] < t\n\t\tbreak\n\tend\n\tl[2] -= t\n\to = 1 - o\nend\n\nputs 1 - o"}, {"source_code": "a, b, n = gets.split.map(&:to_i)\ni = 0\nwhile (n > 0) do\n\tn -= n.gcd(i % 2 == 0 ? a : b)\n\ti += 1\nend\np (i - 1) % 2"}, {"source_code": "a, b, n = gets.split.map(&:to_i)\ni = 0\nwhile (n >= 0) do\n\tn -= n.gcd(i % 2 == 0 ? a : b)\n\ti += 1\nend\np i % 2"}, {"source_code": "#!/usr/bin/env ruby\n# -*- cofing: utf-8 -*-\n\nPrimes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97].freeze\n\ndef get_abn(io)\n line = io.gets\n parts = line.split(' ')\n parts.map! {|p| p.to_i}\n return parts[0], parts[1], parts[2]\nend\n\n# greatest common divisor\ndef gcd(x, y)\n m, n = [x, y].sort\n until n==0 do\n m, n = [n, m%n]\n end\n return m\nend\n# def gcd(x, y)\n# for i in (1..100).to_a.reverse do\n# if x%i == 0 and y%i == 0 then\n# return i\n# end\n# end\n# end\n\nif $0 == __FILE__ then\n a, b, n = get_abn($stdin)\n while true do\n taken = gcd(a, n)\n if taken > n then\n puts 1\n break\n else\n n -= taken\n end\n\n taken = gcd(b, n)\n if taken > n then\n puts 0\n break\n else\n n -= taken\n end\n end\nend\n\n"}, {"source_code": "#!/usr/bin/env ruby\n# -*- cofing: utf-8 -*-\n\ndef get_abn(io)\n io.gets.split(' ').map! {|p| p.to_i}\nend\n\n# greatest common divisor\ndef gcd(x, y)\n m, n = [x, y].sort\n until n==0 do\n m, n = [n, m%n]\n end\n return m\nend\n\nif $0 == __FILE__ then\n a, b, n = get_abn($stdin)\n cnt = 1\n [a, b].cycle do |x|\n taken = gcd(x, n)\n if taken > n then\n puts cnt%2\n break\n else\n n -= taken\n end\n cnt += 1\n end\nend\n\n"}, {"source_code": "#!/usr/bin/env ruby\n# -*- cofing: utf-8 -*-\n\ndef get_abn(io)\n line = io.gets\n parts = line.split(' ')\n parts.map! {|p| p.to_i}\n return parts\nend\n\n# greatest common divisor\ndef gcd(x, y)\n m, n = [x, y].sort\n until n==0 do\n m, n = [n, m%n]\n end\n return m\nend\n\nif $0 == __FILE__ then\n a, b, n = get_abn($stdin)\n while true do\n taken = gcd(a, n)\n if taken > n then\n puts 1\n break\n else\n n -= taken\n end\n\n taken = gcd(b, n)\n if taken > n then\n puts 0\n break\n else\n n -= taken\n end\n end\nend\n\n"}, {"source_code": "#!/usr/bin/env ruby\n# -*- cofing: utf-8 -*-\n\nPrimes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97].freeze\n\ndef get_abn(io)\n line = io.gets\n parts = line.split(' ')\n parts.map! {|p| p.to_i}\n return parts[0], parts[1], parts[2]\nend\n\n# greatest common divisor\ndef gcd(x, y)\n for i in (1..100).to_a.reverse do\n if x%i == 0 and y%i == 0 then\n return i\n end\n end\nend\n\nif $0 == __FILE__ then\n a, b, n = get_abn($stdin)\n while true do\n taken = gcd(a, n)\n if taken > n then\n puts 1\n break\n else\n n -= taken\n end\n\n taken = gcd(b, n)\n if taken > n then\n puts 0\n break\n else\n n -= taken\n end\n end\nend\n\n"}, {"source_code": "a = gets.chomp.split.map(&:to_i)\nn = a[2]\na.pop\n(n + 1).times do |i|\n\tn -= a[i % 2].gcd(n)\n\tif n < 0\n\t\tif i % 2 == 1\n\t\t\tputs 0\n\t\telsif i % 2 == 0\n\t\t\tputs 1\n\t\tend\n\t\tbreak\n\tend\nend\n"}, {"source_code": "def solve(a, b, n)\n while true\n d = a.gcd(n)\n return 1 if d>n\n n -= d\n\n d = b.gcd(n)\n return 0 if d>n\n n -= d\n end\n\nend\n\na, b, n = gets.split.map(&:to_i)\nret = solve(a, b, n)\nputs ret\n"}, {"source_code": "n = readline.split(' ')\nsemen = true\nantisemen = true\n\nwhile (semen && antisemen) do\n \n if(n[2].to_i - (n[0].to_i.gcd n[2].to_i) >= 0 && n[2].to_i != 0)\n begin\n n[2] = n[2].to_i - (n[0].to_i.gcd n[2].to_i)\n semen = true\n end\n else\n semen = false\n break\n end\n \n if(n[2].to_i - (n[1].to_i.gcd n[2].to_i) >= 0 && n[2].to_i != 0)\n begin\n n[2] = n[2].to_i - (n[1].to_i.gcd n[2].to_i)\n antisemen = true\n end\n else\n antisemen = false\n break\n end\n \nend\n\nif(semen == true && antisemen == false) \n puts \"0\" \nelse \n puts \"1\" \nend\n"}, {"source_code": "a=gets.chomp.split(\" \")\nstone=a[2].to_i\ns=a[0].to_i\na=a[1].to_i\nans=\"\"\ntog=0\nloop do\nt2=0\nif tog==0 && stone.gcd(s)<=stone\nstone-=stone.gcd(s)\nans=\"0\"\ntog=1\nt2=1\nelsif tog==1 && stone.gcd(a)<=stone\nstone-=stone.gcd(a)\nans=\"1\"\ntog=0\nt2=1\nend\nbreak if stone<1 || t2==0\nend\nif ans==\"0\"\nputs \"0\"\nelse \nputs \"1\"\nend"}, {"source_code": "m=gets.split.map &:to_i;i=0;i^=1while 0 n\n antisimon_wins = 1\n break\n else\n n -= div\n end\n else # Antisimon\n div = n.gcd(b)\n if div > n\n antisimon_wins = 0\n break\n else\n n -= div\n end\n end\nend\n\nif antisimon_wins == 1\n puts antisimon_wins\nelse\n puts antisimon_wins\nend\n"}, {"source_code": "m=gets.split.map &:to_i;i=0;i^=1while 0 0\n if games % 2 == 0\n stones -= a.gcd(stones)\n else\n stones -= b.gcd(stones)\n end\n games += 1\n end\n\n puts (games % 2 == 0) ? 1 : 0\nend\n\ngame\n"}, {"source_code": "def gcd(a, b)\n if a == 0\n return b\n end\n return gcd b % a, a\nend\n\na, b, n = gets.split(' ').map { |i| i.to_i }\ncur = 0\nwhile true\n if cur == 0\n take = gcd(n, a)\n else\n take = gcd(n, b)\n end\n break if take > n\n n -= take\n cur = 1 - cur\nend\nputs 1 - cur\n"}, {"source_code": "a,b,n=gets.chomp.split.map(&:to_i)\n\nans=0\nloop do\n ans=1-ans\n x=n\n y=a\n while y>0\n z=x%y\n x, y = y, z\n end\n a, b = b, a\n if n0\n\ti=1-i\n\tc-=([a,b][i]).gcd(c)\nend\np i"}, {"source_code": "#!/usr/bin/ruby -Ks\n\ninput = $stdin.gets.chomp.split\n$a = input[0].to_i\n$b = input[1].to_i\n$n = input[2].to_i\n\ndef getGCD(n1, n2)\n if n1 == n2\n return n1\n end\n if n2 == 0\n return n1\n end\n \n if n1 < n2\n start_value = n1\n else\n start_value = n2\n end\n \n start_value.downto(1) do |i|\n if (( n1 % i == 0 )&&( n2 % i == 0 ))\n return i\n end\n end\nend\n\nisSimon = true\nwhile true\n x = 0\n if isSimon\n x = getGCD($a,$n)\n else\n x = getGCD($b,$n)\n end\n $n -= x\n if $n < 0\n if isSimon\n puts 1\n break\n else\n puts 0\n break\n end\n end\n \n if isSimon\n isSimon = false\n else\n isSimon = true\n end\nend\n\n# EOF\n"}, {"source_code": "x,y,z=gets.chomp.split()\nx = x.to_i\ny = y.to_i\nz = z.to_i\npoint = 0\nwhile true\n\tif point==0\n\t\tz-=x.gcd(z)\n\t\tif z<=0\n\t\t\tputs 0\n\t\t\tbreak\n\t\tend\n\t\tpoint+=1\n\tend\n\tif point==1\n\t\tz-=y.gcd(z)\n\t\tif z<=0\n\t\t\tputs 1\n\t\t\tbreak\n\t\tend\n\t\tpoint-=1\n\tend\n\nend\n"}, {"source_code": "a, b, n = STDIN.read.split.map(&:to_i)\n\nloop do\n\t[a, b].each.with_index do |i, k|\n\t\tn -= i.gcd n\n\t\tif n <= 0\n\t\t\tputs k == 1 ? 1 : 0\n\t\t\texit\n\t\tend\n\tend\nend"}, {"source_code": "m=gets.split.map &:to_i;i=0;i^=1while 0 n\n n-=g\n i+=1\nend\n\nputs i.even? ? 1 : 0\n"}, {"source_code": "class Integer\n def gcd(b)\n a = self\n a,b = b,a if b > a\n while b > 0\n a,b = b, a % b\n end\n a\n end\nend\ninput = gets.chop.split(\" \").map(&:to_i)\nleft = input[2]\ntook = 0\nturn = 0\nwhile left >= took do\n took = left.gcd(input[turn])\n (left < took)? (puts turn; exit) : left -= took\n (left < took)? (puts turn; exit) : left\n if turn == 0\n turn = 1\n else\n if turn == 1\n turn = 0\n end\n end\nend\n\n"}, {"source_code": "def nod(x,y)\n if x == 0 then\n return y\n elsif y == 0 then\n return x\n else\n if x > y then\n return nod(x-y,y)\n elsif y > x then\n return nod(x,y-x)\n else\n return x\n end\n end\nend\n\na,b,n = gets.split.map{|i| i.to_i}\n\nx = a\nres = 0\nwhile nod(x,n) < n do\n n -= nod(x,n)\n if x == a then\n x = b\n res = 1\n else\n x = a\n res = 0\n end\nend\n\nputs res"}, {"source_code": "a,b,n = gets.chomp.split(/ /).map!{|x| x.to_i}\nwhile true do\n nn = a.gcd(n)\n n -= nn\n if n < 0 then\n puts 1\n break\n end\n nn = b.gcd(n)\n n -= nn\n if n < 0 then\n puts 0\n break\n end\nend\n"}, {"source_code": "m=gets.split.map &:to_i;i=0;i^=1while 0 y ? y : x\n\tnum = 1\n\tnum.upto t do |e|\n\t\tnum = e if (x % e == 0 and y % e == 0)\n\tend\n\tnum\nend\n\nloop do\n\tn -= turn ? gcd(b,n) : gcd(a,n)\n\tbreak if n == 0\n\tturn = !turn\nend\n\nputs turn ? 1 : 0"}, {"source_code": "a,b,n = gets.chomp.split(\" \").map(&:to_i)\nturn = 0\n\ndef gcd x, y\n\tt = x > y ? y : x\n\tnum = 1\n\tnum.upto t do |e|\n\t\tnum = e if (x % e == 0 and y % e == 0)\n\tend\n\tnum\nend\n\nloop do\n\tn -= turn == 0 ? gcd(a,n) : gcd(b,n)\n\tbreak if n == 0\n\tturn = turn == 0 ? 1 : 0\nend\n\nputs turn"}, {"source_code": "input=gets.split.map(&:to_i)\nheap=input[2]\nk=0\n10000.times{|k|\n heap-=heap.gcd(input[k%2])\n if heap<0 then\n puts 1-k%2\n exit\n end\n}\n"}, {"source_code": "m=gets.split.map &:to_i;i=0;i^=1while 0 b\n a = a % b\n else\n b = b % a\n end\n end\n return a+b\nend\n\n\na, b, n = gets.split.map(&:to_i)\n\nloop do\n n -= gcd(a, n)\n if n < 0\n puts 1\n break\n end\n\n n -= gcd(b, n)\n if n < 0\n puts 0\n break\n end\nend\n"}, {"source_code": "m=gets.split.map &:to_i;i=0;i^=1while 0 b\n t = a\n a = b\n b = t\n end\n if b%a == 0\n a\n else\n gcd(b%a, a)\n end\nend\n\ninputs = gets.split.collect{|element| element.to_i}\ncounter = 1\nwhile true\n if inputs[2] == 0 || inputs[2] < gcd(inputs[2], inputs[(counter-1)%2])\n puts counter%2\n break\n else\n inputs[2] = inputs[2] - gcd(inputs[2], inputs[(counter-1)%2])\n end\n counter = counter+1\nend"}, {"source_code": "m=gets.split.map &:to_i;i=0;i^=1while 00\n n-=n.gcd [a,b][i^=1]\nend\np i"}, {"source_code": "vals = gets.split.map{|s| s.to_i}\nturn = -1\nn = vals[2]\nwhile n > 0\n\tturn += 1\n\tn -= n.gcd(vals[turn%2])\nend\nprint turn%2"}, {"source_code": "def mygcd a, b\n\tif a == b \n\t\tgcd = a\n\telsif a == 0\n\t\tgcd = b\n\telsif b == 0\n\t\tgcd = a\n\telse\n\t\ta, b = b, a if a-b < 0\n\t\tb, a = a, gcd while (gcd = b%a) > 0\n\t\tgcd = a\n\tend\n\tgcd\nend\n\nvals = gets.split.map{|s| s.to_i}\nturn = -1\nn = vals[2]\nwhile n > 0\n\tturn += 1\n\tn -= mygcd(n, vals[turn%2])\nend\nprint turn%2"}, {"source_code": "m=gets.split.map &:to_i;i=0;i^=1while 0= 0 do\n n -= a.gcd(n)\n if n < 0\n print 1\n next\n end\n n -= b.gcd(n)\n print 0 if n < 0\nend"}, {"source_code": "a,b,n = gets.split(\" \").map(&:to_i)\ni = 0\n\nwhile true do\n k = (i%2 == 0 ? a : b)\n if n.gcd(k) > n\n break\n else \n n-= n.gcd(k)\n i+=1\n end\nend\n\nputs (i-1)%2\n"}, {"source_code": "s,a,n=gets.split.map &:to_i\nloop do\n if s.gcd(n)>n\n puts 1\n break\n else \n n=n-s.gcd(n)\n end\n \n if a.gcd(n)>n\n puts 0\n break\n else n=n-a.gcd(n)\n end\nend\n"}, {"source_code": "module Emaxx\n def self.gcd(a,b)\n while b!=0\n a, b = b, a%b\n end\n a\n end\nend\n\nl = $stdin.readline.split\na = l[0..1].map(&:to_i)\nn = l.last.to_i\n\nwho = 0\nt = Emaxx.gcd(a[who], n)\nwhile t>0 && n>=t\n n -= t\n who = (who+1)%2\n t = Emaxx.gcd(a[who], n)\nend\n\nputs (who+1)%2"}, {"source_code": "#!/usr/bin/ruby\n\ndef readNextValues\n return gets.chomp.split.collect {|x| x.to_i }\nend\n\n\ndef gcd(a, b)\n while b > 0\n c = a % b\n a = b\n b = c\n end\n return a\nend\n\ndef solve(a, b, n)\n loop do\n n -= gcd(a, n)\n return 1 if n < 0\n n -= gcd(b, n)\n return 0 if n < 0\n end\nend\n\n### main\n\na, b, n = readNextValues\n\nputs(solve(a, b, n))\n"}, {"source_code": "a, b, n = gets.split.map &:to_i\ni = 0\nloop do\n n -= (i == 0 ? a : b).gcd(n)\n if n < 0\n puts 1-i\n exit\n end\n i = 1 - i\nend\n"}, {"source_code": "m=gets.split.map &:to_i;i=0;i^=1while 00;p i"}, {"source_code": "#!/usr/bin/env ruby\nrequire 'mathn'\n\na,b,c = gets.split.map{ |i| i.to_i }\nd = 0\nwhile true\n e = a.gcd(c)\n if d == 1\n e = b.gcd(c)\n end\n c -= e\n break if c < 0\n d ^= 1\nend\nd ^= 1\nputs d\n"}, {"source_code": "a, b, n = gets.split.map(&:to_i)\ng = a.gcd(n)\nflag = 0\nwhile n >= g\n\tif flag == 0\n\t\tn -= g\n\t\tg = b.gcd(n)\n\t\tflag = 1\n\telse\n\t\tn -= g\n\t\tg = a.gcd(n)\n\t\tflag = 0\n\tend\nend\nif flag == 1\n\tputs 0\nelse\t\n\tputs 1\nend\n"}, {"source_code": "m=gets.split.map &:to_i;i=0;i^=1while 00\n\tn-=n.gcd([a,b][i^=1])\nend\n\np i\n"}, {"source_code": "a,b,n=gets.split.map &:to_i;i=1;n-=n.gcd [a,b][i^=1] while n>0;p i\n"}, {"source_code": "a, b, n = gets.split.map(&:to_i)\n\ni=0\nwhile n>0\n\tt=n.gcd([a,b][i])\n\ti^=1\n\tn-=t\nend\n\np i^=1\n"}], "negative_code": [{"source_code": "a,b,n=gets.split.map &:to_i;i=0;n-=n.gcd [a,b][i^=1]until n<0;p i\n"}, {"source_code": "a, b, n = gets.split.map(&:to_i)\n\ni=0\nwhile n>0\n\tn-=n.gcd([a,b][i^=1])\nend\n\np i^=1\n"}, {"source_code": "include Math\n\ndef get_abn(io)\n line = io.gets\n parts = line.split(' ')\n return parts[0], parts[1], parts[2]\nend\n\na, b, n = get_abn($stdin)\nprint a,b,n"}, {"source_code": "include Math\n\n0"}, {"source_code": "include Math\nline = gets\nparts = line.split(' ')\na = parts[0]\nb = parts[1]\nn = parts[2]\nprint a, b, n"}, {"source_code": "include Math\n\nputs 0"}, {"source_code": "#!/usr/bin/env ruby\n# -*- cofing: utf-8 -*-\n\nPrimes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97].freeze\n\ndef get_abn(io)\n line = io.gets\n parts = line.split(' ')\n parts.map! {|p| p.to_i}\n return parts[0], parts[1], parts[2]\nend\n\n# greatest common divisor\ndef gcd(x, y)\n x_divisor = divisor x\n y_divisor = divisor y\n common_divisor = x_divisor & y_divisor\n return common_divisor.max\nend\n\ndef divisor(x)\n divisor = [1]\n Primes.each do |p|\n divisor << p if x%p == 0\n end\n unless Primes.include? x then\n divisor << x\n end\n return divisor\nend\n\na, b, n = get_abn($stdin)\nwhile true do\n taken = gcd(a, n)\n if taken > n then\n puts 1\n break\n else\n n -= taken\n end\n\n taken = gcd(b, n)\n if taken > n then\n puts 0\n break\n else\n n -= taken\n end\nend\n"}, {"source_code": "#! ruby -Ku\n# -*- coding: UTF-8 -*-\nbegin\n inputs = open(\"input.txt\")\nrescue\n inputs = STDIN\nend\n\na_b_n = inputs.gets.split.map(&:to_i)\na = a_b_n.shift\nb = a_b_n.shift\nn = a_b_n.shift\n\nantisimon_wins = 1\n(n+1).times do |i|\n if i == 0 # Simon\n div = n.gcd(a)\n if div > n\n antisimon_wins = 1\n break\n else\n n -= div\n end\n else # Antisimon\n div = n.gcd(b)\n if div > n\n antisimon_wins = 0\n break\n else\n n -= div\n end\n end\nend\n\nif antisimon_wins == 1\n puts antisimon_wins\nelse\n puts antisimon_wins\nend\n"}, {"source_code": "#! ruby -Ku\n# -*- coding: UTF-8 -*-\nbegin\n inputs = open(\"input.txt\")\nrescue\n inputs = STDIN\nend\n\na_b_n = inputs.gets.split.map(&:to_i)\na = a_b_n.shift\nb = a_b_n.shift\nn = a_b_n.shift\n\nantisimon_wins = 1\nn.times do |i|\n if i == 0 # Simon\n div = n.gcd(a)\n if div > n\n antisimon_wins = 1\n break\n else\n n -= div\n end\n else # Antisimon\n div = n.gcd(b)\n if div > n\n antisimon_wins = 0\n break\n else\n n -= div\n end\n end\nend\n\nif antisimon_wins == 1\n puts antisimon_wins\nelse\n puts antisimon_wins\nend\n"}, {"source_code": "x,y,z=gets.chomp.split()\nx = x.to_i\ny = y.to_i\nz = z.to_i\npoint = 0\nwhile true\n\tif point==0\n\t\tz-=x.gcd(z)\n\t\tif z<0\n\t\t\tputs 0\n\t\t\tbreak\n\t\tend\n\t\tpoint+=1\n\tend\n\tif point==1\n\t\tz-=y.gcd(z)\n\t\tif z<0\n\t\t\tputs 1\n\t\t\tbreak\n\t\tend\n\t\tpoint-=1\n\tend\n\nend\n"}, {"source_code": "a, b, n = STDIN.read.split.map(&:to_i)\n\ndef gcd a, b\n\treturn a if b.zero?\n\tgcd b, a % b\nend\n\nloop do\n\t[a, b].each do |i|\n\t\tgcd = gcd i, n\n\t\tif n - gcd < 0\n\t\t\tputs i == a ? 1 : 0\n\t\t\texit\n\t\tend\n\t\tn -= gcd\n\tend\nend"}, {"source_code": "a1=gets\nk=a1.split(\" \")\na=k[0].to_i\nb=k[1].to_i\nn=k[2].to_i\n#n=gets.to_i\nwhile 1\ni=a.gcd n\nif(n-i<0)\nprint \"1\"\nexit\nend\nn=n-i\nj=b.gcd n-i\nif(n-j<0)\nprint \"0\"\nexit\nend\nn=n-j\nend"}, {"source_code": "a1=gets\nk=a1.split(\" \")\na=k[0].to_i\nb=k[1].to_i\nn=k[2].to_i\n#n=gets.to_i\\\nputs a\nputs b\nputs n\n\nwhile 1\ni=a.gcd n\nputs i\nif(n-i<0)\nprint \"1\"\nexit\nend\nn=n-i\nputs n\nj=b.gcd n\nputs j\nif(n-j<0)\nprint \"0\"\nexit\nend\nn=n-j\nputs n\nend"}, {"source_code": "def f(n,t,a,b)\n\t\tif n0 ? t1 : -t1\nif x>0\n puts \"0 #{t2} #{t1} 0\"\nelse\n puts \"#{-t1} 0 0 #{t2}\"\nend\n\n# The truth is, the sample doesn't correct\n# A(0,2y) C(2x,0) makes the area minimum\n\n# if x>0\n# puts \"0 #{2*y} #{2*x} 0\"\n# else\n# puts \"#{2*x} 0 0 #{2*y}\"\n# end"}, {"source_code": "x,y=gets.split.map(&:to_i)\nc=x.abs+y.abs\ny=y<0? -c : c\nputs(x<0?\"#{-c} 0 0 #{y}\":\"0 #{y} #{c} 0\")\n"}, {"source_code": "#monkeycode\nx, y =gets.split.map{|i| i.to_i}\nif(x>0) then\n if(y>0) then\n puts(\"0 #{x+y} #{x+y} 0\")\n else\n puts(\"0 #{y-x} #{x-y} 0\")\n end\nelse\n if(y>0) then\n puts(\"#{x-y} 0 0 #{y-x}\")\n else\n puts(\"#{x+y} 0 0 #{x+y}\")\n end\nend"}, {"source_code": "x, y =gets.split.map{|i| i.to_i}\nif(x>0) then\n if(y>0) then\n puts(\"0 #{x+y} #{x+y} 0\")\n else\n puts(\"0 #{y-x} #{x-y} 0\")\n end\nelse\n if(y>0) then\n puts(\"#{x-y} 0 0 #{y-x}\")\n else\n puts(\"#{x+y} 0 0 #{x+y}\")\n end\nend\n"}, {"source_code": "x,y=gets.split.map(&:to_i)\nc=x.abs+y.abs\ny=y<0? -c : c\nputs(x<0?\"#{-c} 0 0 #{y}\":\"0 #{y} #{c} 0\")\n"}, {"source_code": "x,y=gets.split.map(&:to_i)\nc=x.abs+y.abs\ny=y<0? -c : c\nputs(x<0?\"#{-c} 0 0 #{y}\":\"0 #{y} #{c} 0\")"}, {"source_code": "x,y=gets.split(\" \").map { |i| i.to_i}\nz=x.abs+y.abs\nif x>0 and y>0 \n\tprint \"0 \",z,\" \",z,\" 0\"\nelsif x>0 and y<0\n\t print \"0 \",-z,\" \",z,\" 0\"\nelsif x<0 and y>0\n\tprint -z,\" 0 0 \",z\nelse\n\tprint -z,\" 0 0 \",-z\nend\n\t\n"}, {"source_code": "def run\n x, y = $stdin.gets.split.map(&:to_i)\n puts [[(x.abs + y.abs) * (x / x.abs), 0].join(\" \"),\n [0, (y.abs + x.abs) * (y / y.abs)].join(\" \")].sort.join(\" \")\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "def run\n x, y = $stdin.gets.split.map(&:to_i)\n\n r = []\n r << [(x.abs + y.abs) * (x / x.abs), 0]\n r << [0, (y.abs + x.abs) * (y / y.abs)]\n r.sort!\n\n puts \"#{r[0][0]} #{r[0][1]} #{r[1][0]} #{r[1][1]}\"\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "x,y=gets.split.map(&:to_i)\nc=x.abs+y.abs\ny=y<0? -c : c\nputs(x<0?\"#{-c} 0 0 #{y}\":\"0 #{y} #{c} 0\")\n"}, {"source_code": "x,y=gets.split.map(&:to_i)\nc=x.abs+y.abs\ny=y<0? -c : c\nputs(x<0?\"#{-c} 0 0 #{y}\":\"0 #{y} #{c} 0\")\n"}, {"source_code": "a=gets.chomp.split(\" \")\nx=a[0].to_i\ny=a[1].to_i\nan=x.abs+y.abs\nif x>0 && y>0\nputs \"0 #{an} #{an} 0\"\nelsif x<0 && y>0\nputs \"#{-an} 0 0 #{an}\"\nelsif x>0 && y<0\nputs \"0 #{-an} #{an} 0\"\nelsif x<0 && y<0\nputs \"#{-an} 0 0 #{-an}\"\nend\n\n\n"}, {"source_code": "x,y=gets.split.map(&:to_i)\nif x > 0 and y > 0\n puts \"0 #{x+y} #{x+y} 0\"\nelsif x > 0 and y < 0\n puts \"0 #{y-x} #{x-y} 0\"\nelsif y > 0\n puts \"#{-(y-x)} 0 0 #{y-x}\"\nelse\n puts \"#{x+y} 0 0 #{x+y}\"\nend\n"}, {"source_code": "x,y=gets.split.map(&:to_i)\nc=x.abs+y.abs\ny=y<0? -c : c\nputs(x<0?\"#{-c} 0 0 #{y}\":\"0 #{y} #{c} 0\")\n"}, {"source_code": "x,y = gets.chomp.split(\" \").collect {|a| a.to_i}\n\nr = x.abs + y.abs\n\nx1 = 0\ny1 = r*y/y.abs\nx2 = r*x/x.abs\ny2 = 0\n\nif x1 >= x2\n\tputs \"#{x2} #{y2} #{x1} #{y1}\"\nelse\n puts \"#{x1} #{y1} #{x2} #{y2}\"\nend\n\n"}, {"source_code": "x,y=gets.split.map(&:to_i)\nc=x.abs+y.abs\ny=y<0? -c : c\nputs(x<0?\"#{-c} 0 0 #{y}\":\"0 #{y} #{c} 0\")"}, {"source_code": "x,y=gets.split.map(&:to_i)\nx1=y2=0;y1=x2=x.abs+y.abs\nx2=-x2 if x<0\ny1=-y1 if y<0\nif x1>x2\n x1,x2=x2,x1\n y1,y2=y2,y1\nend\nputs \"#{x1} #{y1} #{x2} #{y2}\"\n"}, {"source_code": "x,y=gets.split.map(&:to_i)\nc=x.abs+y.abs\ny=y<0? -c : c\nputs(x<0?\"#{-c} 0 0 #{y}\":\"0 #{y} #{c} 0\")\n"}, {"source_code": "x,y=gets.split.map(&:to_i)\nc=x.abs+y.abs\ny=y<0? -c : c\nputs(x<0?\"#{-c} 0 0 #{y}\":\"0 #{y} #{c} 0\")\n"}, {"source_code": "x, y = gets.split.map { |x| x.to_i }\nif 0 < x && 0 < y\n x1 = 0\n y1 = y + x\n x2 = x + y\n y2 = 0\nelse\n if 0 < x && 0 > y\n x1 = 0\n y1 = y - x\n x2 = x - y\n y2 = 0\n else\n if 0 > x && 0 > y\n x1 = x + y\n y1 = 0\n x2 = 0\n y2 = y + x\n else\n x1 = x - y\n y1 = 0\n x2 = 0\n y2 = y - x\n end\n end\nend\nprint x1, ' ', y1, ' ', x2, ' ', y2\n"}, {"source_code": "x, y = gets.split.map { |x| x.to_i }\n\nsum = x.abs + y.abs\n\nif x > 0\n\tif y > 0\n\t\tputs [0, sum, sum, 0].join ' '\n\telse\n\t\tputs [0, -sum, sum, 0].join ' '\n\tend\nelse\n\tif y > 0\n\t\tputs [-sum, 0, 0, sum].join ' '\n\telse\n\t\tputs [-sum, 0, 0, -sum].join ' '\n\tend\nend\n"}, {"source_code": "x,y=gets.split.map(&:to_i)\nc=x.abs+y.abs\ny=y<0? -c : c\nputs(x<0?\"#{-c} 0 0 #{y}\":\"0 #{y} #{c} 0\")\n"}], "negative_code": [{"source_code": "x,y=gets.split(\" \").map { |i| i.to_i}\nz=x.abs+y.abs\nif x>0 and y>0 \n\tprint \"0 \",z,\" \",z,\" 0\"\nelsif x>0 and y<0\n\t print \"0 \",-z,\" \",z,\" 0\"\nelsif x<0 and y>0\n\tprint -z,\" 0 0 \",z\nelse\n\tprint \"0 \",-z,\" \",-z,\" 0\"\nend\n\t\n"}, {"source_code": "x,y=gets.split(\" \").map { |i| i.to_i}\nz=x.abs+y.abs\nif x>0 and y>0 \n\tprint \"0 \",z,\" \",z,\" 0\"\nelsif x>0 and y<0\n\t print \"0 \",-z,\" \",z,\" 0\"\nelsif x<0 and y>0\n\tprint -z,\" 0 0 \",z\nelse\n\tprint \"0 \",-z,-z,\" 0\"\nend\n\t\n"}, {"source_code": "x,y=gets.split(\" \").map { |i| i.to_i}\nz=x.abs+y.abs\nif x>0 and y>0 \n\tprint \"0 \",z,\" \",z,\" 0\"\nelsif x>0 and y<0\n\t print \"0 \",-z,z,\" 0\"\nelsif x<0 and y>0\n\tprint -z,\" 0 0 \",z\nelse\n\tprint \"0 \",-z,-z,\" 0\"\nend\n\t\n"}, {"source_code": "x,y=gets.split.map(&:to_i)\nif x > 0 and y > 0\n puts \"0 #{x+y} #{x+y} 0\"\nelsif x > 0 and y < 0\n puts \"0 #{x-y} #{x-y} 0\"\nelsif y > 0\n puts \"#{-(y-x)} 0 0 #{y-x}\"\nelse\n puts \"#{x+y} 0 0 #{-(x+y)}\"\nend\n"}, {"source_code": "x,y=gets.split.map(&:to_i)\nif x > 0 and y > 0\n puts \"0 #{x+y} #{x+y} 0\"\nelsif x > 0 and y < 0\n puts \"0 #{y-x} #{x-y} 0\"\nelsif y > 0\n puts \"#{-(y-x)} 0 0 #{y-x}\"\nelse\n puts \"#{x+y} 0 0 #{-(x+y)}\"\nend\n"}, {"source_code": "x,y=gets.split.map(&:to_i)\nif x > 0 and y > 0\n puts \"0 #{x+y} #{x+y} 0\"\nelsif x > 0 and y < 0\n puts \"0 #{x-y} #{x-y} 0\"\nelsif y > 0\n puts \"#{-(y-x)} 0 0 #{y-x}\"\nelse\n puts \"#{x+y} 0 0 #{x+y}\"\nend\n"}], "src_uid": "e2f15a9d9593eec2e19be3140a847712"} {"nl": {"description": "Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphones and told him: \"If you solve the following problem, I'll return it to you.\" The problem is: You are given a lucky number n. 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.If we sort all lucky numbers in increasing order, what's the 1-based index of n? Tavas is not as smart as SaDDas, so he asked you to do him a favor and solve this problem so he can have his headphones back.", "input_spec": "The first and only line of input contains a lucky number n (1\u2009\u2264\u2009n\u2009\u2264\u2009109).", "output_spec": "Print the index of n among all lucky numbers.", "sample_inputs": ["4", "7", "77"], "sample_outputs": ["1", "2", "6"], "notes": null}, "positive_code": [{"source_code": "#!/usr/bin/env ruby\na=[]\n1.step(9){|i|\n\t[4,7].repeated_permutation(i){|e|a<1, 7=>2}\n\nsum = 0\n\nfor i in 0..number.length\n\tsum += (2 ** i) * table[number[i].to_i].to_i\nend\n\nputs sum\n\n\n\n"}, {"source_code": "n = gets.chomp.chars.map(&:to_i)\nans = 0\nn.size.times do |i|\n if n[i] == 4\n ans += 2 ** (n.size - i - 1)\n elsif n[i] == 7\n ans += 2 * 2 ** (n.size - i - 1)\n end\nend\nputs ans\n"}, {"source_code": "def lucky_numbers(numbers, current, limit)\n numbers.push(current)\n\n if current >= limit\n return numbers\n end\n\n numbers = lucky_numbers(numbers, current * 10 + 4, limit)\n\n lucky_numbers(numbers, current * 10 + 7, limit)\nend\n\nn = gets.to_i\n\nputs lucky_numbers([], 4, n).concat(lucky_numbers([], 7, n)).sort.find_index(n) + 1\n"}], "negative_code": [{"source_code": "userInput = gets.chomp\nresult = 0\n\nnumberArray = userInput.to_s.split(\"\").map {|item| item.to_i }\n\nloopNum = 0\n\nuntil loopNum == numberArray.length do\n\tresult += (numberArray.length - loopNum) if numberArray[loopNum] == 4\n\tresult += (2 * (numberArray.length - loopNum)) if numberArray[loopNum] == 7\n\n\tloopNum += 1\nend\n\n\nputs result"}, {"source_code": "number = gets.chomp()\n\nnumber.reverse!\n\nsum = 0\n\nfor i in 0..number.length\n\tif number[i] == '4'\n\t\tsum += (2 ** i) \n\telse\n\t\tsum += (2 ** i) * 2\n\tend\nend\n\nputs sum\n\n\n\n"}], "src_uid": "6a10bfe8b3da9c11167e136b3c6fb2a3"} {"nl": {"description": "You are given a chessboard of size 1\u2009\u00d7\u2009n. It is guaranteed that n is even. The chessboard is painted like this: \"BWBW...BW\".Some cells of the board are occupied by the chess pieces. Each cell contains no more than one chess piece. It is known that the total number of pieces equals to .In one step you can move one of the pieces one cell to the left or to the right. You cannot move pieces beyond the borders of the board. You also cannot move pieces to the cells that are already occupied.Your task is to place all the pieces in the cells of the same color using the minimum number of moves (all the pieces must occupy only the black cells or only the white cells after all the moves are made).", "input_spec": "The first line of the input contains one integer n (2\u2009\u2264\u2009n\u2009\u2264\u2009100, n is even) \u2014 the size of the chessboard. The second line of the input contains integer numbers (1\u2009\u2264\u2009pi\u2009\u2264\u2009n) \u2014 initial positions of the pieces. It is guaranteed that all the positions are distinct.", "output_spec": "Print one integer \u2014 the minimum number of moves you have to make to place all the pieces in the cells of the same color.", "sample_inputs": ["6\n1 2 6", "10\n1 2 3 4 5"], "sample_outputs": ["2", "10"], "notes": "NoteIn the first example the only possible strategy is to move the piece at the position 6 to the position 5 and move the piece at the position 2 to the position 3. Notice that if you decide to place the pieces in the white cells the minimum number of moves will be 3.In the second example the possible strategy is to move in 4 moves, then in 3 moves, in 2 moves and in 1 move."}, "positive_code": [{"source_code": "n=gets.to_i\na=gets.split.map(&:to_i).sort\np [1,2].map{|s|a.zip(s.step(n,2).to_a).map{|x,i|(x-i).abs}.reduce :+}.min"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split.map(&:to_i).sort\n\np = q = 0\na.each_with_index do |v, i|\n dp = (v - (i*2+1)).abs\n dq = (v - (i*2+2)).abs\n p += dp\n q += dq\n\nend\n\nputs p < q ? p : q"}], "negative_code": [{"source_code": "n = gets.chomp.to_i\na = gets.chomp.split.map(&:to_i)\n\np = q = 0\na.each_with_index do |v, i|\n p += (v - (i+1)).abs\n q += (v - (i+2)).abs\nend\n\nputs p < q ? p : q"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split.map(&:to_i)\n\np = q = 0\na.each_with_index do |v, i|\n dp = (v - (i*2+1)).abs\n dq = (v - (i*2+2)).abs\n p += dp\n q += dq\n\nend\n\nputs p < q ? p : q"}], "src_uid": "0efe9afd8e6be9e00f7949be93f0ca1a"} {"nl": {"description": "The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her n students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often oddly shaped, interlocking and tessellating pieces).The shop assistant told the teacher that there are m puzzles in the shop, but they might differ in difficulty and size. Specifically, the first jigsaw puzzle consists of f1 pieces, the second one consists of f2 pieces and so on.Ms. Manana doesn't want to upset the children, so she decided that the difference between the numbers of pieces in her presents must be as small as possible. Let A be the number of pieces in the largest puzzle that the teacher buys and B be the number of pieces in the smallest such puzzle. She wants to choose such n puzzles that A\u2009-\u2009B is minimum possible. Help the teacher and find the least possible value of A\u2009-\u2009B.", "input_spec": "The first line contains space-separated integers n and m (2\u2009\u2264\u2009n\u2009\u2264\u2009m\u2009\u2264\u200950). The second line contains m space-separated integers f1,\u2009f2,\u2009...,\u2009fm (4\u2009\u2264\u2009fi\u2009\u2264\u20091000) \u2014 the quantities of pieces in the puzzles sold in the shop.", "output_spec": "Print a single integer \u2014 the least possible difference the teacher can obtain.", "sample_inputs": ["4 6\n10 12 10 7 5 22"], "sample_outputs": ["5"], "notes": "NoteSample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the teacher can also buy puzzles 1, 3, 4 and 5 to obtain the difference 5."}, "positive_code": [{"source_code": "def main\n n = gets.chomp.to_i\n fi = gets.chomp.split(\" \").map{ |e| e.to_i }.sort\n\n r = 0\n r_s = fi[n-1]-fi[0]\n i = 1\n k = fi.size - n + 1\n while iy }\nmin=100000000000\n\nfor i in 0..(m-n)\n j=i+n-1\n l=(sa[j]-sa[i])\n if(min>l)\n min=l\n end\nend\nputs min"}, {"source_code": "n, m = gets.split(' ').map(&:to_i)\nar = gets.split(' ').map(&:to_i).sort\nn -= 1\nputs (n...m).map{|x| ar[x]-ar[x-n]}.min"}, {"source_code": "n_m = gets.split.map &:to_i\nn = n_m[0]\nm = n_m[1]\n\npuzzles = gets.split.map(&:to_i).sort\n\nmin_difficulty = Float::INFINITY\n\n(m - n + 1).times do |i|\n difficulty = puzzles[i+n-1] - puzzles[i]\n min_difficulty = difficulty if difficulty < min_difficulty\nend\n\nputs min_difficulty\n"}, {"source_code": "#!/usr/bin/ruby\nn=gets.to_i\np gets.split.map(&:to_i).sort.each_cons(n).map{|e|e.last-e.first}.min"}, {"source_code": "tmp = gets.chomp.split(\" \")\nn = tmp[0].to_i\nm = tmp[1].to_i\na = gets.chomp.split(\" \").map {|x| x.to_i}\na = a.sort\nmin = a[n-1] - a[0]\nfor i in 1..m-n\n min = a[i+n-1]-a[i] if a[i+n-1]-a[i] < min\nend\nputs min\n"}, {"source_code": "g=->{gets.split.map &:to_i};n,m=g[];a=g[].sort;p a[n-1...m].zip(a).map{|i,j|i-j}.min\n"}, {"source_code": "g=->{gets.split.map(&:to_i)}\nn,m=g[]\na=g[].sort\np (m-n+1).times.map{|i|a[i+n-1]-a[i]}.min"}, {"source_code": "g=->{gets.split.map &:to_i};n,m=g[];a=g[].sort;p a[n-1...m].zip(a).map{|i,j|i-j}.min"}, {"source_code": "n, m=gets.split(\" \").map {|i| i.to_i}\narr = gets.split(\" \").map{|i| i.to_i}.sort!\nanswer=(m-n+1).times.map{|i| arr[i+n-1]-arr[i]}.min\n\np answer"}, {"source_code": "g=->{gets.split.map &:to_i};n,m=g[];a=g[].sort;p a[n-1...m].zip(a).map{|i,j|i-j}.min\n"}, {"source_code": "g=->{gets.split.map &:to_i};n,m=g[];a=g[].sort;p a[n-1...m].zip(a).map{|i,j|i-j}.min"}, {"source_code": "inp = STDIN.gets <<-EOF\nEOF\n\ninp = inp.split(\"\\n\")\n\nstu_num = inp[0].split(\" \")[0].to_i\npuz_num = inp[0].split(\" \")[1].to_i\npuz_difs = inp[1].split(\" \").map(&:to_i).sort\n\nmin_dif_div = if stu_num < puz_num\n puz_difs.first(puz_difs.length - stu_num + 1).inject([]) do |divs,i|\n divs << (puz_difs[puz_difs.index(i) + stu_num - 1] - i)\n end.sort.first\n else\n puz_difs.max - puz_difs.min\n end\n\nputs min_dif_div\n"}, {"source_code": "g=->{gets.split.map(&:to_i)}\nn,m=g[]\na=g[].sort\np (m-n+1).times.map{|i|a[i+n-1]-a[i]}.min\n\n"}, {"source_code": "n,m=gets.chomp.split.map(&:to_i)\na=gets.chomp.split.map(&:to_i).sort\nmin=a.last\ni=0\nwhile i+n-1m\n m = t\n end\n end\n end\n m\n end\n\n def complect_and_count\n self.dup.complect_and_count!\n end\n\n def complect_and_count!\n a = self.shift\n h = {a => 1}\n k = 1\n while self.size>0\n b = self.shift\n if a != b\n h[a] = k\n h[b] = 1\n k = 0\n end\n a = b\n k += 1\n end\n h[b]=k\n h\n end\nend\n\nf.sort!\n#p f\nf_uniq = f.uniq\n#p f_uniq\nff = f.complect_and_count\n#p ff\n\n# t_s = ff.collect do |key,value|\n# [key]*value\n# end\n\n# t = t_s.dup\n\n# \u0438\u0434\u0435\u044f \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430: \u0432\u043e\u043a\u0440\u0443\u0433 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u043d\u0430\u0447\u0438\u043d\u0430\u044e \u043e\u0431\u0440\u0430\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u043a\u0440\u0443\u0433 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0440\u0430\u0434\u0438\u0443\u0441\u0430\n# \u043a\u043e\u0433\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d \u043a\u0440\u0443\u0433 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u0431\u043e\u043b\u0435\u0435 n \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 - \u043d\u0430\u0447\u0438\u043d\u0430\u044e \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043a\u0430\u043a\u043e\u0439 \u0438\u0437 \u043a\u0440\u0443\u0433\u043e\u0432 \u043b\u0443\u0447\u0448\u0438\u0439\n\n# for each f_uniq we build an area\nareas = []\nfor i in 0...f_uniq.count\n elem = f_uniq[i]\n areas[i] = {elements: [elem]*ff[elem], diameter: 0} \nend\n\ndef area_found?(areas,n)\n a_with_max_count = areas.max_by {|e| e.count}\n a_with_max_count[:elements].count >= n\nend\n\nl = 1\nuntil area_found?(areas,n)\n # add one elem to each area\n areas.each do |a|\n elements = a[:elements]\n\n next if elements.count >= l\n\n a_min = elements.min\n a_max = elements.max\n t_min, _ = f_uniq.partition {|el| ela_max}\n t_min = t_min.last\n t_max = t_max.first\n d1 = t_min.nil? ? MAX_INT : a_min - t_min\n d2 = t_max.nil? ? MAX_INT : t_max - a_max\n\n if d2 <= d1\n a[:elements] = elements + [t_max]*ff[t_max]\n a[:diameter] += d2\n elsif d1 < d2\n a[:elements] = ([t_min]*ff[t_min]) + elements\n a[:diameter] += d1\n end\n end\n l+=1\nend\n\nmin = areas.min_by {|el| el[:elements].count >= n ? el[:diameter] : MAX_INT }\nputs min[:diameter]\n"}, {"source_code": "g=->{gets.split.map &:to_i};n,m=g[];a=g[].sort;p a[n-1...m].zip(a).map{|i,j|i-j}.min"}, {"source_code": "n, m = gets.split(' ').map(&:to_i)\na = gets.split(' ').map(&:to_i).sort\nret = 1000\nfor i in 0...a.size-n+1\n ret = [a[i+n-1] - a[i], ret].min\nend\nputs ret"}, {"source_code": "def run\n n, m = $stdin.gets.split.map(&:to_i)\n f = $stdin.gets.split.map(&:to_i)\n f.sort!\n\n min = 1 << 31\n for i in 0..(m - n)\n d = f[i,n].max - f[i,n].min\n min = [d, min].min\n end\n\n puts min\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "n, m = gets.split.map &:to_i\narr = gets.split.map &:to_i\narr = arr.sort\nmin = arr.max\n(m - n + 1).times do |fig|\n min = arr[fig + n - 1] - arr[fig] if min > arr[fig + n - 1] - arr[fig]\nend\nputs min\n"}, {"source_code": "g=->{gets.split.map &:to_i};n,m=g[];a=g[].sort;p a[n-1...m].zip(a).map{|i,j|i-j}.min\n"}, {"source_code": "g=->{gets.split.map &:to_i};n,m=g[];a=g[].sort;p a[n-1...m].zip(a).map{|i,j|i-j}.min\n"}, {"source_code": "students, puzzles = gets.chomp.split(/ /).map(&:to_i)\npieces = gets.chomp.split(/ /).map(&:to_i)\npieces.sort!\nmin = -1\npos = -1\npuzzles.times do |i|\n break if i + (students - 1) >= puzzles\n first = pieces[i]\n last = pieces[i + (students - 1)]\n diff = last - first\n min = diff if min == -1\n next if diff > min\n min = [min, diff].min\n pos = i\nend\nputs pieces[pos + (students - 1)] - pieces[pos]"}, {"source_code": "g=->{gets.split.map &:to_i};n,m=g[];a=g[].sort;p a[n-1...m].zip(a).map{|i,j|i-j}.min\n"}, {"source_code": "a,b=gets.split.map{|e| e.to_i}\nx=gets.split.map{|e| e.to_i}.sort\nans=x[a-1]-x[0]\n0.upto(x.size-a){|i|\n\tans=[ans,x[i+a-1]-x[i]].min\n}\nputs ans"}, {"source_code": "n, m = gets.split.map(&:to_i)\nf = gets.split.map(&:to_i).sort\nmin_diff = 1001\n\n(0..m-n).each do |i|\n\tif f[i+n-1]-f[i] < min_diff\n\t\tmin_diff = f[i+n-1] - f[i]\n\tend\nend\nputs min_diff"}, {"source_code": "n, m = gets.chomp.split(' ').map(&:to_i)\nf = gets.chomp.split(' ').map(&:to_i).sort\n\nmins = []\n(0..m-n).each do |i|\n\tmins << f[i+n-1] - f[i]\nend\n\nputs mins.min"}, {"source_code": "n, m = gets.strip.split(' ').map &:to_i\narray = gets.strip.split(' ').map(&:to_i).sort\n\nmin = array.last\n0.upto(m - n) do |index|\n min = [array[index + n - 1] - array[index], min].min\nend\n\nputs min\n"}, {"source_code": "g=->{gets.split.map &:to_i};n,m=g[];a=g[].sort;p a[n-1...m].zip(a).map{|i,j|i-j}.min"}, {"source_code": "nm = gets.chomp\nnm = nm.split\nstudents = nm[0].to_i\npuzzles = nm[1].to_i\nquantities = gets.chomp\nquantities = quantities.split\n\nfor i in (0..puzzles-1)\n\tfor x in (i..puzzles-1)\n\t\tif i != x\n\t\t\tif quantities[i].to_i > quantities[x].to_i\n\t\t\t\ttemp = quantities[i].to_i\n\t\t\t\tquantities[i] = quantities[x].to_i\n\t\t\t\tquantities[x] = temp\n\t\t\tend\n\t\tend\n\tend\nend\n\nminimum = 0\nfor i in (0..puzzles-1)\n\tif quantities[i+students-1].to_i - quantities[i].to_i < minimum && i > 0 && i+students-1 <= puzzles - 1\n\t\tminimum = quantities[i+students-1].to_i - quantities[i].to_i\n\telsif i == 0 && i+students-1 <= puzzles - 1\n\t\tminimum = quantities[i+students-1].to_i - quantities[i].to_i\n\tend\nend\n\nprint minimum"}, {"source_code": "#!/usr/bin/env ruby\n\n# Solves http://codeforces.com/problemset/problem/337/A\n\nn, m = $stdin.gets.split.map { |s| s.to_i }\nnums = $stdin.gets.split.map { |s| s.to_i }\nnums.sort!\ndiffs = (0..(m-n)).map { |i| nums[n + i - 1] - nums[i] }\nputs diffs.sort![0]\n"}, {"source_code": "g=->{gets.split.map &:to_i};n,m=g[];a=g[].sort;p a[n-1...m].zip(a).map{|i,j|i-j}.min\n"}, {"source_code": "g=->{gets.split.map &:to_i};n,m=g[];a=g[].sort;p a[n-1...m].zip(a).map{|i,j|i-j}.min"}, {"source_code": "m,n = gets.split(\" \").map(&:to_i)\narr = gets.split(\" \").map(&:to_i)\nmin_diff = arr.max\narr.sort!\nfor i in (m-1..n-1)\n diff = arr[i] - arr[i- m +1]\n min_diff = diff if diff < min_diff\nend\nputs min_diff"}, {"source_code": "a, b = gets.split.map &:to_i\np = gets.split.map(&:to_i).sort!\n\nmin = p[-1] - p[0]\n\nfor i in (a-1..b-1)\n min = [min, p[i] - p[i - a + 1]].min\nend\n\nputs min\n"}, {"source_code": "def solution(n, pices)\n pices.sort!\n min_diff = 2 << 2048\n \n for i in n-1...pices.size do\n min_diff = [min_diff, pices[i] - pices[i - n + 1]].min\n end\n \n min_diff\nend\n\nn, m = gets.strip.split().map { |i| i.to_i }\npices = gets.strip.split().map { |i| i.to_i }\n\nputs solution(n, pices)"}, {"source_code": "g=->{gets.split.map &:to_i};n,m=g[];a=g[].sort;p a[n-1...m].zip(a).map{|i,j|i-j}.min\n"}, {"source_code": "n, m = gets.split.map{|x| x.to_i}\na = gets.split.map{|x| x.to_i}.sort\np (m - n + 1).times.map{|i| a[i + n - 1] - a[i]}.min\n"}, {"source_code": "n,m = gets.split(\" \").map(&:to_i)\na = gets.split(\" \").map(&:to_i).sort\nmin = 99999\nfor i in 0..(m-n)\n if(min>a[i+n-1]-a[i])\n min = a[i+n-1]-a[i]\n end\nend\nprint(min)"}, {"source_code": "g=->{gets.split.map &:to_i};n,m=g[];a=g[].sort;p a[n-1...m].zip(a).map{|i,j|i-j}.min"}, {"source_code": "g=->{gets.split.map &:to_i};n,m=g[];a=g[].sort;p a[n-1...m].zip(a).map{|i,j|i-j}.min"}, {"source_code": "n,m=gets.split.map(&:to_i)\na=gets.split.map(&:to_i).sort\nr=1001\n(m-n+1).times {|i|r=[r,a[i+n-1]-a[i]].min}\np r\n"}, {"source_code": "g=->{gets.split.map(&:to_i)}\nn,m=g[]\na=g[].sort\np (m-n+1).times.map{|i|a[i+n-1]-a[i]}.min\n\n"}, {"source_code": "g=->{gets.split.map &:to_i};n,m=g[];a=g[].sort;p a[n-1...m].zip(a).map{|i,j|i-j}.min\n"}, {"source_code": "n, m = gets.split(' ').map(&:to_i)\na = gets.split(' ').map(&:to_i).sort\n\nmin = 2000\nwhile a.size >= n\n min = [min, a[n-1]-a.first].min\n a.shift\nend\n\nputs min\n"}, {"source_code": "g=->{gets.split.map &:to_i};n,m=g[];a=g[].sort;p a[n-1...m].zip(a).map{|i,j|i-j}.min"}, {"source_code": "input = ARGV ? $< : File(ARGV[0])\n\nn, m = input.gets.split(' ').map &:to_i\narr = input.gets.split(' ').map &:to_i\n\narr.sort!()\n\ndiff = arr[n-1] - arr[0]\nstop = m - n\nfor i in (1..stop)\n\tlocal = arr[n-1+i] - arr[i]\n\tdiff = [diff, local].min\nend\n\nputs diff\n"}, {"source_code": "m, n = gets.chomp.split.map { |x| x.to_i }\na = gets.chomp.split.map { |x| x.to_i }.sort\nmin = 1000\nfor i in 0..n - m\n diff = a[i + m - 1] - a[i]\n min = diff if diff < min\nend\nputs min"}, {"source_code": "g=->{gets.split.map &:to_i};n,m=g[];a=g[].sort;p a[n-1...m].zip(a).map{|i,j|i-j}.min"}, {"source_code": "g=->{gets.split.map &:to_i};n,m=g[];a=g[].sort;p a[n-1...m].zip(a).map{|i,j|i-j}.min\n"}, {"source_code": "n, m = gets.chomp.split(' ').map!(&:to_i)\n\nary = gets.chomp.split(' ').map!(&:to_i).sort!.reverse!\n\nmin = ary.first - ary.last\n\nfor i in 0..(ary.size - n) do\n if ary[i] - ary[i + n - 1] < min\n min = ary[i] - ary[i + n - 1]\n end\nend\n\np min"}, {"source_code": "#!ruby\n\nn, m = gets.split.map{|e| e.to_i}\n\np = gets.split.map{|e| e.to_i}\n\nans = 9999\n\np.sort!\n\n(m-n+1).times do |i|\n ans = [ans, p[i+n-1]-p[i]].min\nend\n\nputs ans\n"}, {"source_code": "g=->{gets.split.map &:to_i};n,m=g[];a=g[].sort;p a[n-1...m].zip(a).map{|i,j|i-j}.min\n"}], "negative_code": [{"source_code": "def main\n n = gets.chomp.to_i\n fi = gets.chomp.split(\" \").map{ |e| e.to_i }.sort\n\n r = 0\n r_s = fi[n-1]-fi[0]\n i = 1\n k = fi.size - n\n while iy }\nputs (sa[n-1]-sa[0])"}, {"source_code": "n_m = gets.split.map &:to_i\nn = n_m[0]\nm = n_m[1]\n\npuzzles = gets.split.map(&:to_i).sort\n\nmin_difficulty = Float::INFINITY\n\n(m - n).times do |i|\n difficulty = puzzles[i+n-1] - puzzles[i]\n min_difficulty = difficulty if difficulty < min_difficulty\nend\n\nputs min_difficulty\n"}, {"source_code": "#!/usr/bin/ruby\nn=gets.to_i\np gets.split.map(&:to_i).sort.each_cons(n).min{|e|e.last-e.first}"}, {"source_code": "tmp = gets.chomp.split(\" \")\na = gets.chomp.split(\" \").map {|x| x.to_i}\na = a.sort\nputs a[tmp[0].to_i-1]-a[0]\n#puts array[0] + \", \" + array[n]\n"}, {"source_code": "inp = STDIN.gets <<-EOF\nEOF\n\ninp = inp.split(\"\\n\")\n\nstu_num = inp[0].split(\" \")[0].to_i\npuz_num = inp[0].split(\" \")[1].to_i\n\npuz_difs = inp[1].split(\" \").map(&:to_i).sort\nmin_dif_div = puz_difs.first(puz_difs.length - stu_num).inject([]){|divs,i| divs << (puz_difs[puz_difs.index(i) + stu_num - 1] - i)}.first\nputs min_dif_div\n"}, {"source_code": "inp = STDIN.gets <<-EOF\nEOF\n\ninp = inp.split(\"\\n\")\n\nstu_num = inp[0].split(\" \")[0].to_i\npuz_num = inp[0].split(\" \")[1].to_i\npuz_difs = inp[1].split(\" \").map(&:to_i).sort\n\nmin_dif_div = if stu_num < puz_num\n puz_difs.first(puz_difs.length - stu_num).inject([]){|divs,i| divs << (puz_difs[puz_difs.index(i) + stu_num - 1] - i)}.first\n else\n puz_difs.max - puz_difs.min\n end\n\nputs min_dif_div\n"}, {"source_code": "\nMAX_INT = 1<<31\n\nn, m = $stdin.readline.split.map(&:to_i)\nf = $stdin.readline.split.map(&:to_i)\n\nclass Array\n def diameter\n m = 0\n for i in 0...self.count\n for j in i+1...self.count\n t = (self[i]-self[j]).abs\n if t>m\n m = t\n end\n end\n end\n m\n end\n\n def complect_and_count\n self.dup.complect_and_count!\n end\n\n def complect_and_count!\n a = self.shift\n h = {a => 1}\n k = 1\n while self.size>0\n b = self.shift\n if a != b\n h[a] = k\n h[b] = 1\n k = 0\n end\n a = b\n k += 1\n end\n h[b]=k\n h\n end\nend\n\nf.sort!\n#p f\nf_uniq = f.uniq\n#p f_uniq\nff = f.complect_and_count\n#p ff\n\n# t_s = ff.collect do |key,value|\n# [key]*value\n# end\n\n# t = t_s.dup\n\n# \u0438\u0434\u0435\u044f \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430: \u0432\u043e\u043a\u0440\u0443\u0433 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u043d\u0430\u0447\u0438\u043d\u0430\u044e \u043e\u0431\u0440\u0430\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u043a\u0440\u0443\u0433 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0440\u0430\u0434\u0438\u0443\u0441\u0430\n# \u043a\u043e\u0433\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d \u043a\u0440\u0443\u0433 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u0431\u043e\u043b\u0435\u0435 n \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 - \u043d\u0430\u0447\u0438\u043d\u0430\u044e \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043a\u0430\u043a\u043e\u0439 \u0438\u0437 \u043a\u0440\u0443\u0433\u043e\u0432 \u043b\u0443\u0447\u0448\u0438\u0439\n\n# for each f_uniq we build an area\nareas = []\nfor i in 0...f_uniq.count\n elem = f_uniq[i]\n areas[i] = {elements: [elem]*ff[elem], diameter: 0} \nend\n\ndef area_found?(areas,n)\n a_with_max_count = areas.max_by {|e| e.count}\n a_with_max_count[:elements].count >= n\nend\n\nl = 1\nuntil area_found?(areas,n)\n # add one elem to each area\n areas.each do |a|\n elements = a[:elements]\n\n next if elements.count >= l\n\n a_min = elements.min\n a_max = elements.max\n t_min, _ = f_uniq.partition {|el| ela_max}\n t_min = t_min.last\n t_max = t_max.first\n d1 = t_min.nil? ? MAX_INT : a_min - t_min\n d2 = t_max.nil? ? MAX_INT : t_max - a_max\n\n if d2 <= d1\n a[:elements] = elements + [t_max]*ff[t_max]\n a[:diameter] += d2\n elsif d1 < d2\n a[:elements] = ([t_min]*ff[t_min]) + elements\n a[:diameter] += d1\n end\n end\n l+=1\nend\n\nmin = areas.min_by {|el| el[:diameter]}\nputs min[:diameter]\n"}, {"source_code": " MAX_INT = 1<<31\n\n n, m = $stdin.readline.split.map(&:to_i)\n f = $stdin.readline.split.map(&:to_i)\n\n class Array\n def diameter\n m = 0\n for i in 0...self.count\n for j in i+1...self.count\n t = (self[i]-self[j]).abs\n if t>m\n m = t\n end\n end\n end\n m\n end\n\n def complect_and_count\n self.dup.complect_and_count!\n end\n\n def complect_and_count!\n a = self.shift\n h = {a => 1}\n k = 1\n while self.size>0\n b = self.shift\n if a != b\n h[a] = k\n h[b] = 1\n k = 0\n end\n a = b\n k += 1\n end\n h[b]=k\n h\n end\n end\n\n f.sort!\n #p f\n f_uniq = f.uniq.sort\n #p f_uniq\n ff = f.complect_and_count\n #p ff\n\n t_s = ff.collect do |key,value|\n [key]*value\n end\n\n t = t_s.dup\n\n diameters = Array.new(t_s.count, 0)\n\n loop do\n\n min_d = MAX_INT\n min_d_count = 0\n min_i = nil\n \n for i in 0...t.count\n elem = t[i]\n elem_d = elem.diameter\n if elem_d <= min_d && (elem.count>=n || elem.count>=min_d_count)\n min_d = elem_d\n min_d_count = elem.count\n min_i = i\n end\n end\n\n #p t[min_i]\n #puts \"total count = #{t.count}, d = #{min_d}, count = #{min_d_count}\"\n\n if t[min_i].count >= n\n p t[min_i].diameter\n break\n else\n tt = []\n for i in 0...t.count\n t_elem = t[i]\n ttt = f_uniq - t_elem\n t_elem_min = t_elem.min\n t_elem_max = t_elem.max\n\n tmp1,_ = ttt.partition {|el| elt_elem_max}\n tmp2_min = tmp2.min\n count2 =tmp2_min.nil? ? 0 : ff[tmp2_min]\n d2 = tmp2_min.nil? ? MAX_INT : t_elem_max - tmp2_min\n\n to_add = nil\n if d2 < d1\n tt << t_elem + ([tmp2_min]*count2)\n elsif d1 < d2\n tt << ([tmp1_max]*count1) + t_elem\n elsif d1==d2 && d1!=MAX_INT\n tt << ([tmp1_max]*count1) + t_elem\n tt << t_elem + ([tmp2_min]*count2)\n end\n \n # if count1+count2>0\n # tmp3 = ([tmp1_max]*count1) + t_elem + ([tmp2_min]*count2)\n # tt << tmp3.compact\n # end\n end\n\n t = tt\n end\n\n end\n"}, {"source_code": " MAX_INT = 1<<31\n\n n, m = $stdin.readline.split.map(&:to_i)\n f = $stdin.readline.split.map(&:to_i)\n\n class Array\n def diameter\n m = 0\n for i in 0...self.count\n for j in i+1...self.count\n t = (self[i]-self[j]).abs\n if t>m\n m = t\n end\n end\n end\n m\n end\n\n def complect_and_count\n self.dup.complect_and_count!\n end\n\n def complect_and_count!\n a = self.shift\n h = {a => 1}\n k = 1\n while self.size>0\n b = self.shift\n if a != b\n h[a] = k\n h[b] = 1\n k = 0\n end\n a = b\n k += 1\n end\n h[b]=k\n h\n end\n end\n\n f.sort!\n #p f\n f_uniq = f.uniq.sort\n #p f_uniq\n ff = f.complect_and_count\n #p ff\n\n t_s = ff.collect do |key,value|\n [key]*value\n end\n\n t = t_s.dup\n\n diameters = Array.new(t_s.count, 0)\n\n loop do\n\n min_d = MAX_INT\n min_d_count = 0\n min_i = nil\n \n for i in 0...t.count\n elem = t[i]\n elem_d = elem.diameter\n if elem_d <= min_d && (elem.count>=n || elem.count>=min_d_count)\n min_d = elem_d\n min_d_count = elem.count\n min_i = i\n end\n end\n\n #p t[min_i]\n #puts \"total count = #{t.count}, d = #{min_d}, count = #{min_d_count}\"\n\n if t[min_i].count >= n\n p t[min_i].diameter\n break\n else\n tt = []\n for i in 0...t.count\n t_elem = t[i]\n ttt = f_uniq - t_elem\n t_elem_min = t_elem.min\n t_elem_max = t_elem.max\n\n tmp1,_ = ttt.partition {|el| elt_elem_max}\n tmp2_min = tmp2.min\n count2 = 0\n unless tmp2_min.nil?\n count2 = ff[tmp2_min]\n end\n\n # if count1>0\n # tmp3 = ([tmp1_max]*count1) + t_elem\n # tt << tmp3.compact\n # end\n\n # if count2>0\n # tmp3 = t_elem + ([tmp2_min]*count2)\n # tt << tmp3.compact\n # end\n\n if count1+count2>0\n tmp3 = ([tmp1_max]*count1) + t_elem + ([tmp2_min]*count2)\n tt << tmp3.compact\n end\n end\n\n t = tt\n end\n\n end"}, {"source_code": "\nMAX_INT = 1<<31\n\nn, m = $stdin.readline.split.map(&:to_i)\nf = $stdin.readline.split.map(&:to_i)\n\nclass Array\n\tdef diameter\n\t\tm = 0\n\t\tfor i in 0...self.count\n\t\t\tfor j in i+1...self.count\n\t\t\t\tt = (self[i]-self[j]).abs\n\t\t\t\tif t>m\n\t\t\t\t\tm = t\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\t\tm\n\tend\n\n\tdef complect_and_count\n\t\tself.dup.complect_and_count!\n\tend\n\n\tdef complect_and_count!\n\t\ta = self.shift\n\t\th = {a => 1}\n\t\tk = 1\n\t\twhile self.size>0\n\t\t\tb = self.shift\n\t\t\tif a != b\n\t\t\t\th[a] = k\n\t\t\t\th[b] = 1\n\t\t\t\tk = 0\n\t\t\tend\n\t\t\ta = b\n\t\t\tk += 1\n\t\tend\n\t\th[b]=k\n\t\th\n\tend\nend\n\nf.sort!\n#p f\nf_uniq = f.uniq\n#p f_uniq\nff = f.complect_and_count\n#p ff\n\n# t_s = ff.collect do |key,value|\n# \t[key]*value\n# end\n\n# t = t_s.dup\n\n# \u0438\u0434\u0435\u044f \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430: \u0432\u043e\u043a\u0440\u0443\u0433 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u043d\u0430\u0447\u0438\u043d\u0430\u044e \u043e\u0431\u0440\u0430\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u043a\u0440\u0443\u0433 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0440\u0430\u0434\u0438\u0443\u0441\u0430\n# \u043a\u043e\u0433\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d \u043a\u0440\u0443\u0433 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u0431\u043e\u043b\u0435\u0435 n \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 - \u043d\u0430\u0447\u0438\u043d\u0430\u044e \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043a\u0430\u043a\u043e\u0439 \u0438\u0437 \u043a\u0440\u0443\u0433\u043e\u0432 \u043b\u0443\u0447\u0448\u0438\u0439\n\n# for each f_uniq we build an area\nareas = []\nfor i in 0...f_uniq.count\n\telem = f_uniq[i]\n\tareas[i] = {elements: [elem]*ff[elem], diameter: 0} \nend\n\ndef area_found?(areas,n)\n\ta_with_max_count = areas.max_by {|e| e.count}\n\ta_with_max_count[:elements].count >= n\nend\n\nuntil area_found?(areas,n)\n\t# add one elem to each area\n\tareas.each do |a|\n\t\telements = a[:elements]\n\t\ta_min = elements.min\n\t\ta_max = elements.max\n\t\tt_min, _ = f_uniq.partition {|el| ela_max}\n\t\tt_min = t_min.last\n\t\tt_max = t_max.first\n\t\td1 = t_min.nil? ? MAX_INT : a_min - t_min\n\t\td2 = t_max.nil? ? MAX_INT : t_max - a_max\n\n\t\tif d2 <= d1\n\t\t\ta[:elements].push(t_max)\n\t\t\ta[:diameter] += d2\n\t\telsif d1 < d2\n\t\t\ta[:elements].unshift(t_min)\t\t\t\t\n\t\t\ta[:diameter] += d1\n\t\tend\n\tend\n\nend\n\nmin = areas.min_by {|el| el[:diameter]}\nputs min[:diameter]\n"}, {"source_code": " MAX_INT = 1<<31\n\n n, m = $stdin.readline.split.map(&:to_i)\n f = $stdin.readline.split.map(&:to_i)\n\n class Array\n def diameter\n m = 0\n for i in 0...self.count\n for j in i+1...self.count\n t = (self[i]-self[j]).abs\n if t>m\n m = t\n end\n end\n end\n m\n end\n\n def complect_and_count\n self.dup.complect_and_count!\n end\n\n def complect_and_count!\n a = self.shift\n h = {a => 1}\n k = 1\n while self.size>0\n b = self.shift\n if a != b\n h[a] = k\n h[b] = 1\n k = 0\n end\n a = b\n k += 1\n end\n h[b]=k\n h\n end\n end\n\n f.sort!\n p f\n f_uniq = f.uniq.sort\n p f_uniq\n ff = f.complect_and_count\n p ff\n\n t_s = ff.collect do |key,value|\n [key]*value\n end\n\n t = t_s.dup\n\n diameters = Array.new(t_s.count, 0)\n\n loop do\n\n min_d = MAX_INT\n min_d_count = 0\n min_i = nil\n \n for i in 0...t.count\n elem = t[i]\n elem_d = elem.diameter\n if elem_d <= min_d && (elem.count>=n || elem.count>=min_d_count)\n min_d = elem_d\n min_d_count = elem.count\n min_i = i\n end\n end\n\n #p t[min_i]\n #puts \"total count = #{t.count}, d = #{min_d}, count = #{min_d_count}\"\n\n if t[min_i].count >= n\n puts t[min_i].diameter\n break\n else\n tt = []\n for i in 0...t.count\n t_elem = t[i]\n ttt = f_uniq - t_elem\n t_elem_min = t_elem.min\n t_elem_max = t_elem.max\n\n tmp1,_ = ttt.partition {|el| elt_elem_max}\n tmp2_min = tmp2.min\n count2 = 0\n unless tmp2_min.nil?\n count2 = ff[tmp2_min]\n end\n\n # if count1>0\n # tmp3 = ([tmp1_max]*count1) + t_elem\n # tt << tmp3.compact\n # end\n\n # if count2>0\n # tmp3 = t_elem + ([tmp2_min]*count2)\n # tt << tmp3.compact\n # end\n\n if count1+count2>0\n tmp3 = ([tmp1_max]*count1) + t_elem + ([tmp2_min]*count2)\n tt << tmp3.compact\n end\n end\n\n t = tt\n end\n\n end"}, {"source_code": "\nMAX_INT = 1<<31\n\nn, m = $stdin.readline.split.map(&:to_i)\nf = $stdin.readline.split.map(&:to_i)\n\nclass Array\n def diameter\n m = 0\n for i in 0...self.count\n for j in i+1...self.count\n t = (self[i]-self[j]).abs\n if t>m\n m = t\n end\n end\n end\n m\n end\n\n def complect_and_count\n self.dup.complect_and_count!\n end\n\n def complect_and_count!\n a = self.shift\n h = {a => 1}\n k = 1\n while self.size>0\n b = self.shift\n if a != b\n h[a] = k\n h[b] = 1\n k = 0\n end\n a = b\n k += 1\n end\n h[b]=k\n h\n end\nend\n\nf.sort!\n#p f\nf_uniq = f.uniq\n#p f_uniq\nff = f.complect_and_count\n#p ff\n\n# t_s = ff.collect do |key,value|\n# [key]*value\n# end\n\n# t = t_s.dup\n\n# \u0438\u0434\u0435\u044f \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430: \u0432\u043e\u043a\u0440\u0443\u0433 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u043d\u0430\u0447\u0438\u043d\u0430\u044e \u043e\u0431\u0440\u0430\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u043a\u0440\u0443\u0433 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0440\u0430\u0434\u0438\u0443\u0441\u0430\n# \u043a\u043e\u0433\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d \u043a\u0440\u0443\u0433 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u0431\u043e\u043b\u0435\u0435 n \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 - \u043d\u0430\u0447\u0438\u043d\u0430\u044e \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043a\u0430\u043a\u043e\u0439 \u0438\u0437 \u043a\u0440\u0443\u0433\u043e\u0432 \u043b\u0443\u0447\u0448\u0438\u0439\n\n# for each f_uniq we build an area\nareas = []\nfor i in 0...f_uniq.count\n elem = f_uniq[i]\n areas[i] = {elements: [elem]*ff[elem], diameter: 0} \nend\n\ndef area_found?(areas,n)\n a_with_max_count = areas.max_by {|e| e.count}\n a_with_max_count[:elements].count >= n\nend\n\nuntil area_found?(areas,n)\n # add one elem to each area\n areas.each do |a|\n elements = a[:elements]\n a_min = elements.min\n a_max = elements.max\n t_min, _ = f_uniq.partition {|el| ela_max}\n t_min = t_min.last\n t_max = t_max.first\n d1 = t_min.nil? ? MAX_INT : a_min - t_min\n d2 = t_max.nil? ? MAX_INT : t_max - a_max\n\n if d2 <= d1\n a[:elements] = elements + [t_max]*ff[t_max]\n a[:diameter] += d2\n elsif d1 < d2\n a[:elements] = ([t_min]*ff[t_min]) + elements\n a[:diameter] += d1\n end\n end\n\nend\n\nmin = areas.min_by {|el| el[:diameter]}\nputs min[:diameter]\n"}, {"source_code": "MAX_INT = 1<<31\n\nn, m = $stdin.readline.split.map(&:to_i)\nf = $stdin.readline.split.map(&:to_i)\n\nclass Array\n\tdef diameter\n\t\tm = 0\n\t\tfor i in 0...self.count\n\t\t\tfor j in i+1...self.count\n\t\t\t\tt = (self[i]-self[j]).abs\n\t\t\t\tif t>m\n\t\t\t\t\tm = t\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\t\tm\n\tend\nend\n\ndef solve(n,f)\n\tif n == 1\n\t\tf\n\telse\n\t\tmd = MAX_INT\n\t\tmf = []\n\t\tfor i in 0...f.count\n\t\t\ttf = f[0...i] + f[(i+1)..-1] # f \\ f[i]\n\t\t\ttd = tf.diameter\n\t\t\tif td < md\n\t\t\t\tff = solve(n-1, tf)\n\t\t\t\tmd = td\n\t\t\t\tmf = ff + [f[i]]\n\t\t\tend\n\t\tend\n\t\tmf\n\tend\nend\n\nt = solve(n,f)[0...n]\n#p t\nputs t.diameter"}, {"source_code": "n, m = $stdin.readline.split.map(&:to_i)\nf = $stdin.readline.split.map(&:to_i)\n\nf.sort!\nt = f[0...n]\nputs t.max - t.min"}, {"source_code": " MAX_INT = 1<<31\n\n n, m = $stdin.readline.split.map(&:to_i)\n f = $stdin.readline.split.map(&:to_i)\n\n class Array\n def diameter\n m = 0\n for i in 0...self.count\n for j in i+1...self.count\n t = (self[i]-self[j]).abs\n if t>m\n m = t\n end\n end\n end\n m\n end\n\n def complect_and_count\n self.dup.complect_and_count!\n end\n\n def complect_and_count!\n a = self.shift\n h = {a => 1}\n k = 1\n while self.size>0\n b = self.shift\n if a != b\n h[a] = k\n h[b] = 1\n k = 0\n end\n a = b\n k += 1\n end\n h[b]=k\n h\n end\n end\n\n f.sort!\n p f\n f_uniq = f.uniq.sort\n p f_uniq\n ff = f.complect_and_count\n p ff\n\n t_s = ff.collect do |key,value|\n [key]*value\n end\n\n t = t_s.dup\n\n diameters = Array.new(t_s.count, 0)\n\n loop do\n\n min_d = MAX_INT\n min_d_count = 0\n min_i = nil\n \n for i in 0...t.count\n elem = t[i]\n elem_d = elem.diameter\n if elem_d <= min_d && (elem.count>=n || elem.count>=min_d_count)\n min_d = elem_d\n min_d_count = elem.count\n min_i = i\n end\n end\n\n p t[min_i]\n puts \"total count = #{t.count}, d = #{min_d}, count = #{min_d_count}\"\n\n if t[min_i].count >= n\n p t[min_i].diameter\n break\n else\n tt = []\n for i in 0...t.count\n t_elem = t[i]\n ttt = f_uniq - t_elem\n t_elem_min = t_elem.min\n t_elem_max = t_elem.max\n\n tmp1,_ = ttt.partition {|el| elt_elem_max}\n tmp2_min = tmp2.min\n count2 = 0\n unless tmp2_min.nil?\n count2 = ff[tmp2_min]\n end\n\n # if count1>0\n # tmp3 = ([tmp1_max]*count1) + t_elem\n # tt << tmp3.compact\n # end\n\n # if count2>0\n # tmp3 = t_elem + ([tmp2_min]*count2)\n # tt << tmp3.compact\n # end\n\n if count1+count2>0\n tmp3 = ([tmp1_max]*count1) + t_elem + ([tmp2_min]*count2)\n tt << tmp3.compact\n end\n end\n\n t = tt\n end\n\n end\n"}, {"source_code": "n, m = gets.split.map &:to_i\narr = gets.split.map &:to_i\nif arr.size - arr.uniq.size == n - 1 \n puts \"0\"\nelse\n arr = arr.sort\n puts arr[n - 1] - arr.first\nend\n"}, {"source_code": "n, m = gets.split.map &:to_i\narr = gets.split.map &:to_i\narr = arr.sort\nputs arr[n - 1] - arr[0]\n"}, {"source_code": "n, m = gets.split.map &:to_i\narr = gets.split.map &:to_i\narr = arr.sort\nif arr.uniq.size == arr.size\n puts arr[n - 1] - arr[0]\nelse\n puts 0\nend\n\n"}, {"source_code": "students = gets.chomp.split(/ /).map(&:to_i)[0]\npieces = gets.chomp.split(/ /).map(&:to_i)\npieces.sort!\nputs pieces[students - 1] - pieces[0]"}, {"source_code": "#!/usr/bin/env ruby\n\n# Solves http://codeforces.com/problemset/problem/337/A\n\nn, m = $stdin.gets.split.map { |s| s.to_i }\nnums = $stdin.gets.split.map { |s| s.to_i }\nnums.sort!\ndiffs = (0..(m-n)).map { |i| nums[n + i - 1] - nums[0] }\nputs diffs.sort![0]\n"}, {"source_code": "n,m = gets.split(\" \").map(&:to_i)\na = gets.split(\" \").map(&:to_i).sort\nmin = 99999\nfor i in 0..(m-n-1)\n if(min>a[i+n-1]-a[i])\n min = a[i+n-1]-a[i]\n end\nend\nprint(min)"}, {"source_code": "n, m = gets.split(' ').map(&:to_i)\na = gets.split(' ').map(&:to_i).sort\n\nmin = 2000\nwhile a.size >= m\n min = [min, a[n-1]-a.first].min\n a.shift\nend\n\nputs min\n"}], "src_uid": "7830aabb0663e645d54004063746e47f"} {"nl": {"description": "Let's denote a function $$$f(x)$$$ in such a way: we add $$$1$$$ to $$$x$$$, then, while there is at least one trailing zero in the resulting number, we remove that zero. For example, $$$f(599) = 6$$$: $$$599 + 1 = 600 \\rightarrow 60 \\rightarrow 6$$$; $$$f(7) = 8$$$: $$$7 + 1 = 8$$$; $$$f(9) = 1$$$: $$$9 + 1 = 10 \\rightarrow 1$$$; $$$f(10099) = 101$$$: $$$10099 + 1 = 10100 \\rightarrow 1010 \\rightarrow 101$$$. We say that some number $$$y$$$ is reachable from $$$x$$$ if we can apply function $$$f$$$ to $$$x$$$ some (possibly zero) times so that we get $$$y$$$ as a result. For example, $$$102$$$ is reachable from $$$10098$$$ because $$$f(f(f(10098))) = f(f(10099)) = f(101) = 102$$$; and any number is reachable from itself.You are given a number $$$n$$$; your task is to count how many different numbers are reachable from $$$n$$$.", "input_spec": "The first line contains one integer $$$n$$$ ($$$1 \\le n \\le 10^9$$$).", "output_spec": "Print one integer: the number of different numbers that are reachable from $$$n$$$.", "sample_inputs": ["1098", "10"], "sample_outputs": ["20", "19"], "notes": "NoteThe numbers that are reachable from $$$1098$$$ are:$$$1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 1098, 1099$$$."}, "positive_code": [{"source_code": "require \"set\"\n\ndef f(n)\n\ts = (n+1).to_s\n\ts[...(s =~ /0+$/)].to_i\nend\n\nn = gets.to_i\ns = Set.new\nwhile !s.include?(n)\n\ts.add(n)\n\tn = f(n)\nend\np s.size\n"}, {"source_code": "# your code goes here\n\n$store = {}\n\ndef trim_trailing_zeroes(y)\n\ty_string = y.to_s\n\ti = y_string.length - 1\n\tindex_non_zero = 0\n\twhile i >= 1 do\n\t\tif y_string[i] != \"0\"\n\t\t\tindex_non_zero = i\n\t\t\tbreak\n\t\tend\n\t\ti -= 1\n\tend\n\t\n\treturn y_string[0..index_non_zero]\nend\n\ndef cal(x)\n\tif !$store[x].nil?\n\t\treturn\n\tend\n\t$store[x] = 1\n\texecute_for = trim_trailing_zeroes(x + 1)\n\tcal(execute_for.to_i)\nend\n\n\nvalue = gets.to_i\ncal(value)\n\np $store.keys.size"}, {"source_code": "N = gets.to_i\nn = N\nchecked = {}\n\nwhile n > 9\n checked[n] = true\n n += 1\n n = n.to_s.reverse.to_i.to_s.reverse.to_i\nend\n\nputs checked.keys.count + 9\n"}, {"source_code": "require 'set'\n\nn = gets.strip.to_i\nseen = Set.new\n\nwhile !seen.include?(n)\n seen.add(n)\n begin\n n += 1\n seen.add(n) if !seen.include?(n) && n % 10 != 0\n end while n % 10 != 0\n while n % 10 == 0\n n /= 10\n end\nend\n\nputs seen.size\n"}, {"source_code": "n = gets.to_i\na = Hash.new(false)\nwhile !a[n]\n a[n] = true\n n += 1\n n /= 10 while n%10 == 0\nend\nputs a.size"}], "negative_code": [{"source_code": "n = gets.to_i\na = Hash.new(false)\na[n] = true\nwhile !a[1]\n n += 1\n n /= 10 while n%10 == 0\n a[n] = true\nend\nputs a.size"}, {"source_code": "n = gets.to_i\nans = 1\nwhile n > 1\n n += 1\n n /= 10 while n%10 == 0\n ans += 1\nend\nputs ans"}, {"source_code": "n = gets.to_i\na = Hash.new(false)\na[n] = true\nwhile n > 1\n n += 1\n n /= 10 while n%10 == 0\n a[n] = true\nend\nputs a.size"}], "src_uid": "055fbbde4b9ffd4473e6e716da6da899"} {"nl": {"description": "The numbers of all offices in the new building of the Tax Office of IT City will have lucky numbers.Lucky number is a number that consists of digits 7 and 8 only. Find the maximum number of offices in the new building of the Tax Office given that a door-plate can hold a number not longer than n digits.", "input_spec": "The only line of input contains one integer n (1\u2009\u2264\u2009n\u2009\u2264\u200955) \u2014 the maximum length of a number that a door-plate can hold.", "output_spec": "Output one integer \u2014 the maximum number of offices, than can have unique lucky numbers not longer than n digits.", "sample_inputs": ["2"], "sample_outputs": ["6"], "notes": null}, "positive_code": [{"source_code": "p 2**-~gets.to_i-2"}, {"source_code": "a=gets.chomp.to_i\nb=2**(a+1)-2\nputs\"#{b}\""}, {"source_code": "p 2**gets.to_i-1<<1"}, {"source_code": "p 2**gets.to_i*2-2"}, {"source_code": "n = gets.chomp.to_i;\nans = 0;\nn.times{|i| ans += 2**(i+1)}\np ans\n"}, {"source_code": "x = gets.chomp.to_i\nsum = (0)\nfor i in 1 .. x\n sum = sum + 2**i\nend\n\nprint sum"}, {"source_code": "n = gets.chomp.to_i\n\nans = 0\n\n(1..n).each do |i|\nans = ans + (2**i)\nend\n\nputs ans\n"}, {"source_code": "n = gets.to_i\n\nk = 2\ns = 0\nn.times do\n s += k\n k *= 2\nend\n\nputs s"}, {"source_code": "#!/usr/bin/ruby\n\n# Get one number at a time\nN = STDIN.gets.to_i\n\nres = 0\n\n(1..N).each do |x|\n\tres += 2 ** x\nend\n\nputs res"}, {"source_code": "a=gets.chomp.to_i\nb=2**(a+1)-2\nputs\"#{b}\""}, {"source_code": "n = gets.strip.to_i\nputs (1..n).inject(0){|r, el| r + 2**el}"}, {"source_code": "p 2**-~gets.to_i-2"}, {"source_code": "p 2**(gets.to_i+1)-2\n"}], "negative_code": [{"source_code": "p 1**gets.to_i*2-2"}, {"source_code": "p(1<1\nputs 1 if n==1"}, {"source_code": "x=gets.chomp.to_i\ny=1\nz=x\nans=0\nwhile y!=x do\n ans=ans+((z-1)*y)\n y=y+1\n z=z-1\nend\nputs ans+x"}, {"source_code": "def func(x, h)\n y = x+(x-1)*h\n return y\nend\n\nn = gets.to_i\n\nresult = 0\n\ni = n\nwhile i > 0 do\n result += func(i, n-i)\n i -= 1\nend\n\nputs result"}, {"source_code": "val = gets.to_i ;\nval = (val**3 + 5*val)/6 ;\nputs val ;"}, {"source_code": "#!/usr/bin/ruby\nn=gets.to_i\np (n*n+5)*n/6"}, {"source_code": "sum, multi = gets.chomp.to_i, 1\n(sum-1).downto 1 do |i|\n\tsum += (i*multi)\n\tmulti += 1\nend\nputs sum"}, {"source_code": "n = gets.to_i\nk = n\nsum = 0\nwhile k > 0 do\n sum += (n-k + 1) * (k - 1) + 1\n k -= 1\nend\nputs sum"}, {"source_code": "n = gets.to_i\nsum = n\nfor k in 1..n do\n sum += (n-k + 1) * (k - 1)\nend\nputs sum"}, {"source_code": "#!/usr/bin/ruby1.9\n\nn = STDIN.readline.to_i\n\nprefix = 0\ntotal = 0\n(1..n).reverse_each do |k|\n\ttotal += (prefix+1)*(k-1) + 1\n\tprefix += 1\nend\n\nputs total\n\n"}, {"source_code": "n = gets.to_i\ni = 1\nr = 0\nwhile i<=n-1 do\n\tr = r + (i * (n-i))\n\ti=i+1\nend\nputs r+n"}, {"source_code": "x = gets.chomp.to_i\n\ntotal = x\n\nx.downto(1).each_with_index do |i, ind|\n total += i*ind\nend\n\nputs total"}, {"source_code": "n=gets.to_i\np n+n*n*(n-1)/2-(n-1)*(2*n-1)*n/6"}, {"source_code": "n = $stdin.readline.to_i\n\ndef s(n)\n n*(n-1)/2\nend\n\ndef k(n,l)\n if n == 1\n return 1+l\n else\n if l > 0\n return n*l + k(n-1, l+1)\n else\n return n-1 + k(n-1, l+1)\n end\n end\nend\n\nputs k(n,0)"}, {"source_code": "def run\n n = ARGF.readline.to_i\n\n sum = 0\n n.times do |i|\n sum += (n - i - 1) * (i + 1) + 1\n end\n\n puts sum\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "n = gets.to_i\nsum = 0\nn.times do |j|\n sum += n - j + j * (n - j - 1)\nend \nputs sum\n"}, {"source_code": "n = gets.to_i\ns = 0\nn.times do |time|\n s += (n - time - 1) * (time + 1) + 1\nend\nputs s"}, {"source_code": "n=gets.to_i\ni=0\nans=n+n-1\nwhile n>1\n\tn=n-1\n\tans=ans+n*i+i\n\ti=i+1\nend\nputs ans"}, {"source_code": "n = gets.to_i\nr = 0\nn.downto(1) do |i|\n\tr += i + (i - 1)*(n - i)\nend\nputs r"}, {"source_code": "n=gets.to_i\ncount=0\n2.upto(n){|i| count+=(i-1)*(n-i)+(i-1)}\nputs(count+n)"}, {"source_code": "require 'set'\ninclude Math\n$stdin = File.open(\"./input.txt\", \"r\") if ENV[\"USER\"] == \"new\"\n# ====================================\n\nn = gets.to_i\n\nif n == 1 then\n print 1\n exit\nend\n\nresult = n + 1\n2.upto(n - 1) do |value|\n result += 1\n result += value * (n - value)\nend\n\nprint result"}, {"source_code": "#!/usr/bin/ruby\nn=gets.to_i\np (n*n+5)*n/6"}, {"source_code": "n = gets.strip.to_i\nputs (n ** 2 * (n - 1) / 2) - n * (n - 1) * (2 * n - 1) / 6 + n\n"}, {"source_code": "n=gets.to_i\nres=n\nfor i in 1..n-1\n res+=i*(n-i)\nend\nputs res\n"}, {"source_code": "x=gets.chomp.to_i\ny=1\nz=x\nans=0\nwhile y!=x do\n ans=ans+((z-1)*y)\n y=y+1\n z=z-1\nend\nputs ans+x"}, {"source_code": "n = Integer(gets)\na = 0\nfor i in 1..n\n\ta = a + n*i - i * i + 1\nend\nputs a"}, {"source_code": "a = c = gets.chomp.to_i\n\nb = 0; sum = 0\n\nwhile a > 1 do\n a -= 1\n b += 1\n sum += b * a\nend\n\nputs sum + c"}, {"source_code": "number = gets.to_i\ncount = 0\n\n(number-1).times do |i|\n k = i+1\n count += (number-k)*k\nend\n\np count + number\n"}, {"source_code": "n=gets.to_i\n\nx = n*(n*n+5)/6\n\nputs x\n"}, {"source_code": "k=gets.to_i;puts k*(k*k+5)/6"}, {"source_code": "n = gets.to_i\nputs n == 1 ? 1 : (1...n).map { |x| (n - x) * x }.reduce(:+) + n"}, {"source_code": "n = gets.chomp.to_i\ns = 0\n(1..n).each{ |k|\n s += (k*(n-k)+1)\n}\nputs s"}, {"source_code": "n=gets.to_i\nx = n*(n*n+5)/6\nputs x"}, {"source_code": "n = gets.to_i\ni = 1\nans = 0\nfor i in 1..n do\n ans = ans + (i * (n-i)) \nend\nputs ans+n"}, {"source_code": "n = gets.to_i\nans = n\ni = 1\nwhile n-i > 0 do\n ans += (n-i)*i\n i+=1\nend\nputs ans"}, {"source_code": "n = gets.to_i\nneed = [0]\nn.times do |i|\n need << need[-1] + (n - i - 1) * (i + 1) + 1\nend\nputs need[n]\n"}, {"source_code": "#!/usr/bin/env ruby\n\nn = gets.to_i\nputs n + (n - 1) * n * (n + 1) / 6;\n"}, {"source_code": "$i=0;\n$sum=0;\ngets.chomp.to_i.-(1).times do\n $i+=1\n $sum+=$i*($_.to_i-$i)\nend\nputs $sum+$_.to_i"}, {"source_code": "n = gets.to_i\n\nresult = 0\nt = []\n\n\n1.upto(n)do |i|\n\tresult += (n-i)*i\nend\nputs result + n"}, {"source_code": "n = gets.to_i\nans = n\nn.times do |i|\n\tans += (i + 1) * (n - i - 1)\nend\nputs ans\n"}], "negative_code": [{"source_code": "def func(x)\n y = x+(x-1)\n return y\nend\n\nn = gets.to_i\n\nresult = n\ni = n-1\nwhile i > 0 do\n result += func(i)\n i -= 1\nend\n\nputs result"}, {"source_code": "#!/usr/bin/ruby\np (1< 3\n\tn.downto(1) do |i|\n\t\tif i > 1\n\t\t\tn.downto(i+1) do |j|\n\t\t\t\tt[j] += i\n\t\t\tend\n\t\tend\n\t\tt[i] = i\n\t\t\n\tend\n\tt.each{|x| result += x == nil ? 0 : x}\n\tputs result\nelsif n == 3\n\tprint 7\nelse \n\tprint 3\nend\n\n"}, {"source_code": "def sum(n)\n\tn + [0, n*n/2 - n].max\nend\n\nn = gets.to_i\n\nresult = 0\n\nn.times do |i|\n\tresult += sum(i+1)\nend\n\nputs result"}], "src_uid": "6df251ac8bf27427a24bc23d64cb9884"} {"nl": {"description": "Recently Vasya found a golden ticket \u2014 a sequence which consists of $$$n$$$ digits $$$a_1a_2\\dots a_n$$$. Vasya considers a ticket to be lucky if it can be divided into two or more non-intersecting segments with equal sums. For example, ticket $$$350178$$$ is lucky since it can be divided into three segments $$$350$$$, $$$17$$$ and $$$8$$$: $$$3+5+0=1+7=8$$$. Note that each digit of sequence should belong to exactly one segment.Help Vasya! Tell him if the golden ticket he found is lucky or not.", "input_spec": "The first line contains one integer $$$n$$$ ($$$2 \\le n \\le 100$$$) \u2014 the number of digits in the ticket. The second line contains $$$n$$$ digits $$$a_1 a_2 \\dots a_n$$$ ($$$0 \\le a_i \\le 9$$$) \u2014 the golden ticket. Digits are printed without spaces.", "output_spec": "If the golden ticket is lucky then print \"YES\", otherwise print \"NO\" (both case insensitive).", "sample_inputs": ["5\n73452", "4\n1248"], "sample_outputs": ["YES", "NO"], "notes": "NoteIn the first example the ticket can be divided into $$$7$$$, $$$34$$$ and $$$52$$$: $$$7=3+4=5+2$$$.In the second example it is impossible to divide ticket into segments with equal sum."}, "positive_code": [{"source_code": "n = gets.to_i\nary = gets.strip.split('').map(&:to_i)\n\nif ary.uniq == [0]\n puts \"YES\"\n exit 0\nend\n\n# lim = (n * 9) + 10\nlim = ary.inject(:+) - 1\n\ndef poss?(ary, ss)\n i=0\n sum = 0\n sz = ary.size\n while i ss\n return false\n end\n i += 1\n end\n sum == 0\nend\n\n1.upto(lim).each do |ss|\n if poss?(ary, ss)\n # puts ss\n puts \"YES\"\n exit 0\n end\nend\n\nputs \"NO\""}], "negative_code": [{"source_code": "n = gets.to_i\nary = gets.strip.split('').map(&:to_i)\n\n# lim = (n * 9) + 10\nlim = ary.inject(:+) - 1\n\n# def poss?(ary, ss)\n# i=j=0\n# sum = ary[0]\n# return false if sum > ss\n# sz = ary.size\n# while i= sz\n# sum = ary[j]\n# end\n# end\n# end\n\ndef poss?(ary, ss)\n i=0\n sum = 0\n sz = ary.size\n while i ss\n return false\n end\n i += 1\n end\n sum == 0\nend\n\n1.upto(lim).each do |ss|\n if poss?(ary, ss)\n # puts ss\n puts \"YES\"\n exit 0\n end\nend\n\nputs \"NO\""}], "src_uid": "410296a01b97a0a39b6683569c84d56c"} {"nl": {"description": "Berland Football Cup starts really soon! Commentators from all over the world come to the event.Organizers have already built $$$n$$$ commentary boxes. $$$m$$$ regional delegations will come to the Cup. Every delegation should get the same number of the commentary boxes. If any box is left unoccupied then the delegations will be upset. So each box should be occupied by exactly one delegation.If $$$n$$$ is not divisible by $$$m$$$, it is impossible to distribute the boxes to the delegations at the moment.Organizers can build a new commentary box paying $$$a$$$ burles and demolish a commentary box paying $$$b$$$ burles. They can both build and demolish boxes arbitrary number of times (each time paying a corresponding fee). It is allowed to demolish all the existing boxes.What is the minimal amount of burles organizers should pay to satisfy all the delegations (i.e. to make the number of the boxes be divisible by $$$m$$$)?", "input_spec": "The only line contains four integer numbers $$$n$$$, $$$m$$$, $$$a$$$ and $$$b$$$ ($$$1 \\le n, m \\le 10^{12}$$$, $$$1 \\le a, b \\le 100$$$), where $$$n$$$ is the initial number of the commentary boxes, $$$m$$$ is the number of delegations to come, $$$a$$$ is the fee to build a box and $$$b$$$ is the fee to demolish a box.", "output_spec": "Output the minimal amount of burles organizers should pay to satisfy all the delegations (i.e. to make the number of the boxes be divisible by $$$m$$$). It is allowed that the final number of the boxes is equal to $$$0$$$.", "sample_inputs": ["9 7 3 8", "2 7 3 7", "30 6 17 19"], "sample_outputs": ["15", "14", "0"], "notes": "NoteIn the first example organizers can build $$$5$$$ boxes to make the total of $$$14$$$ paying $$$3$$$ burles for the each of them.In the second example organizers can demolish $$$2$$$ boxes to make the total of $$$0$$$ paying $$$7$$$ burles for the each of them.In the third example organizers are already able to distribute all the boxes equally among the delegations, each one get $$$5$$$ boxes."}, "positive_code": [{"source_code": "n,m,a,b=gets.split.map &:to_i\np [n%m*b,(m-n%m)*a].min"}, {"source_code": "n, m, a, b = gets.strip.split.map(&:to_i)\ntd = n % m\ntb = m - td\nputs [td*b, tb*a].min"}, {"source_code": "n, m, a, b = gets.split.map{|e| e.to_i }\nmod = n % m\nputs [mod*b, ((m-mod)%m)*a].min\n"}, {"source_code": "n,m,a,b=gets.split.map &:to_i\nx=n%m\nputs [x*b, (m-x)*a].min\n"}, {"source_code": "n, m, a, b = gets.split.map &:to_i\nx = [n / m - 1, 0].max\nans = Float::INFINITY\nx.upto(x + 2) do |i|\n ans = [ans, i * m < n ? (n - i * m) * b : (i * m - n) * a].min\nend\nputs ans\n"}, {"source_code": "n, m, a, b = gets.split.map(&:to_i)\nd = n % m\nif d == 0\n puts 0\n exit\nend\nputs [b * d, a * (m - d)].min"}, {"source_code": "def delegate_boxes\n n, m, a, b = gets.split.map(&:to_i)\n l = n % m\n return 0 if l == 0\n\n if n < m\n return min(n * b, (m - n) * a)\n end\n\n min(l * b, (m - l) * a)\nend\n\ndef min(a, b)\n a <= b ? a : b\nend\n\nputs delegate_boxes"}, {"source_code": "n, m, a, b = gets.split.map(&:to_i)\n\ndiv, mod = n.divmod(m)\n\nputs [mod * b, (m - mod) * a].min\n"}], "negative_code": [], "src_uid": "c05d753b35545176ad468b99ff13aa39"} {"nl": {"description": "You are given a sequence of integers $$$a_1, a_2, \\dots, a_n$$$. You need to paint elements in colors, so that: If we consider any color, all elements of this color must be divisible by the minimal element of this color. The number of used colors must be minimized. For example, it's fine to paint elements $$$[40, 10, 60]$$$ in a single color, because they are all divisible by $$$10$$$. You can use any color an arbitrary amount of times (in particular, it is allowed to use a color only once). The elements painted in one color do not need to be consecutive.For example, if $$$a=[6, 2, 3, 4, 12]$$$ then two colors are required: let's paint $$$6$$$, $$$3$$$ and $$$12$$$ in the first color ($$$6$$$, $$$3$$$ and $$$12$$$ are divisible by $$$3$$$) and paint $$$2$$$ and $$$4$$$ in the second color ($$$2$$$ and $$$4$$$ are divisible by $$$2$$$). For example, if $$$a=[10, 7, 15]$$$ then $$$3$$$ colors are required (we can simply paint each element in an unique color).", "input_spec": "The first line contains an integer $$$n$$$ ($$$1 \\le n \\le 100$$$), where $$$n$$$ is the length of the given sequence. The second line contains $$$n$$$ integers $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\le a_i \\le 100$$$). These numbers can contain duplicates.", "output_spec": "Print the minimal number of colors to paint all the given numbers in a valid way.", "sample_inputs": ["6\n10 2 3 5 4 2", "4\n100 100 100 100", "8\n7 6 5 4 3 2 2 3"], "sample_outputs": ["3", "1", "4"], "notes": "NoteIn the first example, one possible way to paint the elements in $$$3$$$ colors is: paint in the first color the elements: $$$a_1=10$$$ and $$$a_4=5$$$, paint in the second color the element $$$a_3=3$$$, paint in the third color the elements: $$$a_2=2$$$, $$$a_5=4$$$ and $$$a_6=2$$$. In the second example, you can use one color to paint all the elements.In the third example, one possible way to paint the elements in $$$4$$$ colors is: paint in the first color the elements: $$$a_4=4$$$, $$$a_6=2$$$ and $$$a_7=2$$$, paint in the second color the elements: $$$a_2=6$$$, $$$a_5=3$$$ and $$$a_8=3$$$, paint in the third color the element $$$a_3=5$$$, paint in the fourth color the element $$$a_1=7$$$. "}, "positive_code": [{"source_code": "n = gets.to_i\na = gets.split.map(&:to_i).sort\n\nans = 0\nwhile !a.empty?\n ans += 1\n t = a.shift\n idx = []\n a.length.times do |i|\n if a[i] % t == 0\n idx << i\n end\n end\n idx.reverse.each do |v|\n a.delete_at(v)\n end\nend\np ans\n"}, {"source_code": "n = gets.to_i\narr = gets.split(' ').collect(&:to_i).sort\narr_used = Array.new(n)\n\narr.each_with_index do |elem_1, idx_1|\n\tarr.each_with_index do |elem_2, idx_2|\n\t\tnext unless arr_used[idx_2].nil?\n\t\tnext unless elem_2 % elem_1 == 0 && elem_1 <= elem_2\n\t\tarr_used[idx_2] = idx_1\n\tend\nend\n\np arr_used.uniq.count\n"}, {"source_code": "#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']\n\ndef inpf() a=gets.chomp.split(\" \").map(&:to_f)end\n\ndef inps() a=gets.chomp.split(\" \")end\n\ndef copy(a) Marshal.load(Marshal.dump(a)) end\n\ndef kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end\n\ndef na(n,d=0) Array.new(n,d)end\n\ndef na2(n,m,d=0) Array.new(n){Array.new(m,d)}end\n\ndef na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end\n\ndef inp() a=gets.chomp.split(\" \").map(&:to_i)end\n\ndef r_up(a, b) (a+b-1)/b end\n\ndef sum(a) a.inject(:+) end\n\nrequire 'prime'\n\nn = inp[0]\nt = inp\nt = t.sort\nh = {}\nans = 0\nt.each do |d|\n (t).each do |i|\n if(d%i == 0)\n h[i] = true\n break\n end\n end\nend\n\np ((h.to_a.size))\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i).sort\npainted = Array.new(n, false)\ncolors = 0\nfor i in 0...n do\n if !painted[i]\n colors += 1\n painted[i] = true\n for j in (i+1)...n do\n if !painted[j] && a[j] % a[i] == 0\n painted[j] = true\n end\n end\n end\nend\nputs colors\n"}], "negative_code": [{"source_code": "#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']\n\ndef inpf() a=gets.chomp.split(\" \").map(&:to_f)end\n\ndef inps() a=gets.chomp.split(\" \")end\n\ndef copy(a) Marshal.load(Marshal.dump(a)) end\n\ndef kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end\n\ndef na(n,d=0) Array.new(n,d)end\n\ndef na2(n,m,d=0) Array.new(n){Array.new(m,d)}end\n\ndef na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end\n\ndef inp() a=gets.chomp.split(\" \").map(&:to_i)end\n\ndef r_up(a, b) (a+b-1)/b end\n\ndef sum(a) a.inject(:+) end\n\nrequire 'prime'\n\nn = inp[0]\nt = inp\nt = t.sort.reverse\nh = {}\nans = 0\nt.each do |d|\n ((t.min)..100).each do |i|\n if(d%i == 0)\n h[i] = true\n break\n end\n end\nend\n\np ((h.to_a.size))\n"}, {"source_code": "#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']\n\ndef inpf() a=gets.chomp.split(\" \").map(&:to_f)end\n\ndef inps() a=gets.chomp.split(\" \")end\n\ndef copy(a) Marshal.load(Marshal.dump(a)) end\n\ndef kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end\n\ndef na(n,d=0) Array.new(n,d)end\n\ndef na2(n,m,d=0) Array.new(n){Array.new(m,d)}end\n\ndef na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end\n\ndef inp() a=gets.chomp.split(\" \").map(&:to_i)end\n\ndef r_up(a, b) (a+b-1)/b end\n\ndef sum(a) a.inject(:+) end\n\nrequire 'prime'\n\nn = inp[0]\nt = inp\nt = t.sort.reverse\nh = {}\nans = 0\nt.each do |d|\n (2..100).each do |i|\n if(d%i == 0)\n h[i] = true\n break\n end\n end\nend\np h.to_a.size\n"}, {"source_code": "#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']\n\ndef inpf() a=gets.chomp.split(\" \").map(&:to_f)end\n\ndef inps() a=gets.chomp.split(\" \")end\n\ndef copy(a) Marshal.load(Marshal.dump(a)) end\n\ndef kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end\n\ndef na(n,d=0) Array.new(n,d)end\n\ndef na2(n,m,d=0) Array.new(n){Array.new(m,d)}end\n\ndef na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end\n\ndef inp() a=gets.chomp.split(\" \").map(&:to_i)end\n\ndef r_up(a, b) (a+b-1)/b end\n\ndef sum(a) a.inject(:+) end\n\nrequire 'prime'\n\nn = inp[0]\nt = inp\nt = t.sort.reverse\nh = {}\nans = 0\nt.size.times do |i|\n f = false\n next if(h[t[i]])\n ((i+1)...(t.size)).each do |j|\n if(t[i]%t[j]==0)\n h[t[j]] = true\n end\n end\n ans += 1\nend\np ans\n"}, {"source_code": "#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']\n\ndef inpf() a=gets.chomp.split(\" \").map(&:to_f)end\n\ndef inps() a=gets.chomp.split(\" \")end\n\ndef copy(a) Marshal.load(Marshal.dump(a)) end\n\ndef kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end\n\ndef na(n,d=0) Array.new(n,d)end\n\ndef na2(n,m,d=0) Array.new(n){Array.new(m,d)}end\n\ndef na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end\n\ndef inp() a=gets.chomp.split(\" \").map(&:to_i)end\n\ndef r_up(a, b) (a+b-1)/b end\n\ndef sum(a) a.inject(:+) end\n\nrequire 'prime'\nn = inp[0]\nt = inp\nt = t.sort\nh = {}\nans = 0\nt.size.times do |i|\n f = false\n ((i+1)...(t.size)).each do |j|\n if(t[j]%t[i]==0)\n f = true\n break\n end\n end\n ans += 1 unless f\nend\np ans\n"}], "src_uid": "63d9b7416aa96129c57d20ec6145e0cd"} {"nl": {"description": "A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are m containers, in the i-th container there are ai matchboxes, and each matchbox contains bi matches. All the matchboxes are of the same size. The burglar's rucksack can hold n matchboxes exactly. Your task is to find out the maximum amount of matches that a burglar can carry away. He has no time to rearrange matches in the matchboxes, that's why he just chooses not more than n matchboxes so that the total amount of matches in them is maximal.", "input_spec": "The first line of the input contains integer n (1\u2009\u2264\u2009n\u2009\u2264\u20092\u00b7108) and integer m (1\u2009\u2264\u2009m\u2009\u2264\u200920). The i\u2009+\u20091-th line contains a pair of numbers ai and bi (1\u2009\u2264\u2009ai\u2009\u2264\u2009108,\u20091\u2009\u2264\u2009bi\u2009\u2264\u200910). All the input numbers are integer.", "output_spec": "Output the only number \u2014 answer to the problem.", "sample_inputs": ["7 3\n5 10\n2 5\n3 6", "3 3\n1 3\n2 2\n3 1"], "sample_outputs": ["62", "7"], "notes": null}, "positive_code": [{"source_code": "ns,ms = gets.chomp.split(/ /)\nn = ns.to_i\nm = ms.to_i\nar = Array.new(m)\nfor i in 0..m-1\n\ts = gets.chomp\n\tar[i] = s.split(/ /).map! {|x| x.to_i }\nend\n\nar.sort! { |a,b| b[1] <=> a[1] }\n\nret = 0\nwk = n\nfor i in 0..m-1\n\tbreak if wk <= 0\n\tt = [wk, ar[i][0]].min\n\tret += t * ar[i][1]\n\twk -= t\nend\n\nputs ret"}, {"source_code": "s = 0\nn, m = gets.split.map{|i| i.to_i}\nm.times.to_a.map{gets.split.map{|i| i.to_i}.reverse}.sort.reverse.each do |i|\n\tt = [n, i[1]].min\n\tn -= t\n\ts += i[0] * t\nend\np s\n"}, {"source_code": "s = 0\nn, m = gets.split.map{|i| i.to_i}\nm.times{$*< a[1]}.each do |a, b|\n\tt = [n, a].min\n\tn -= t\n\ts += b * t\nend\np s\n\n__END__\n# \tWhen \tWho \tProblem \tLang \tVerdict \tTime \tMemory\n212857 \tDec 9, 2010 9:59:45 PM \twatashi \tB - Burglar and Matches \tRuby \tAccepted \t80 ms \t2992 KB\n"}, {"source_code": "\nn,m=gets.split.map(&:to_i)\ncnt=Array.new(11,0)\nm.times{\n a,b=gets.split.map(&:to_i)\n cnt[b]+=a\n}\nans=0\n10.downto(1){|i|\n if(n>=cnt[i]) then\n n-=cnt[i]\n ans+=cnt[i]*i\n else\n ans+=n*i\n n=0\n end\n}\np ans\n"}, {"source_code": "z=0;n,m=gets.split.map &:to_i;m.times.to_a.map{gets.split.map(&:to_i).reverse}.sort.reverse.each{|x,y|t=[n,y].min;n-=t;z+=x*t;};p z\n"}, {"source_code": "z=0;n,m=gets.split.map &:to_i;m.times.to_a.map{gets.split.map(&:to_i).reverse}.sort.reverse.each{|x,y|t=[n,y].min;n-=t;z+=x*t;};p z\n"}, {"source_code": "z=0;n,m=gets.split.map &:to_i;m.times.to_a.map{gets.split.map(&:to_i).reverse}.sort.reverse.each{|x,y|t=[n,y].min;n-=t;z+=x*t;};p z"}, {"source_code": "z=0;n,m=gets.split.map &:to_i;m.times.to_a.map{gets.split.map(&:to_i).reverse}.sort.reverse.each{|x,y|t=[n,y].min;n-=t;z+=x*t;};p z\n"}, {"source_code": "z=0;n,m=gets.split.map &:to_i;m.times.to_a.map{gets.split.map(&:to_i).reverse}.sort.reverse.each{|x,y|t=[n,y].min;n-=t;z+=x*t;};p z\n"}, {"source_code": "#!/usr/bin/ruby\n\nn, m = gets.chomp.split.map{|e| e.to_i}\n\nmatches = []\nm.times do\n a, b = gets.chomp.split.map{|e| e.to_i}\n matches.push [a, b]\nend\n\nmatches.sort! {|l, r|\n r[1] <=> l[1]\n}\n\nrest = n\ncur_box = 0\nacc = 0\nwhile (true)\n break if cur_box >= m\n if (matches[cur_box][0] <= rest)\n acc += matches[cur_box][0] * matches[cur_box][1]\n rest -= matches[cur_box][0]\n cur_box += 1\n next\n else\n acc += matches[cur_box][1] * rest\n break\n end\nend\nputs acc\n\n\n \n"}, {"source_code": "z=0;n,m=gets.split.map &:to_i;m.times.to_a.map{gets.split.map(&:to_i).reverse}.sort.reverse.each{|x,y|t=[n,y].min;n-=t;z+=x*t;};p z"}, {"source_code": "z=0;n,m=gets.split.map &:to_i;m.times.to_a.map{gets.split.map(&:to_i).reverse}.sort.reverse.each{|x,y|t=[n,y].min;n-=t;z+=x*t;};p z"}, {"source_code": "result = 0\nn, m = gets.split.map(&:to_i)\nelements = m.times.to_a.map{ gets.split.map(&:to_i).reverse }\nelements.sort.reverse.each{ |x, y| t = [n, y].min; n -= t; result += x * t; break if n == 0 }\nputs result"}, {"source_code": "z=0;n,m=gets.split.map &:to_i;m.times.to_a.map{gets.split.map(&:to_i).reverse}.sort.reverse.each{|x,y|t=[n,y].min;n-=t;z+=x*t;};p z\n"}, {"source_code": "n,m=gets().chomp().split(' ').map(&:to_i) ;h={}\nh = m.times.to_a.map{ gets.split.map(&:to_i) }\n(h=h.sort_by {|_key, value| value}).reverse! ;count=0\nh.each do |key, value|\n count+=(key>n)?((n)*value):(key*value) ;n-=key ;break if (n<=0)\nend\np count"}, {"source_code": "z=0;n,m=gets.split.map &:to_i;m.times.to_a.map{gets.split.map(&:to_i).reverse}.sort.reverse.each{|x,y|t=[n,y].min;n-=t;z+=x*t;};p z"}, {"source_code": "z=0;n,m=gets.split.map &:to_i;m.times.to_a.map{gets.split.map(&:to_i).reverse}.sort.reverse.each{|x,y|t=[n,y].min;n-=t;z+=x*t;};p z\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\nb = {}\nm.times do\n\tx, y = gets.split.map(&:to_i)\n\tb.has_key?(y) ? b[y] += x : b[y] = x\nend\ntot, cc = 0, 0\nb.sort.reverse.each do |v, i|\n\ttot += [n - cc, i].min * v\n\tcc += i\n\tbreak if cc > n\nend\nputs tot\n"}, {"source_code": "z=0;n,m=gets.split.map &:to_i;m.times.to_a.map{gets.split.map(&:to_i).reverse}.sort.reverse.each{|x,y|t=[n,y].min;n-=t;z+=x*t;};p z\n"}, {"source_code": "n,m=gets.split.map(&:to_i)\ns=0\nm.times{$*<c[1]}.each{|a,b|if n>a\ns+=a*b\nn-=a\nelse\ns+=n*b\nbreak\nend}\np s"}, {"source_code": "tab=[]; result=0\nn, m = gets.split.map(&:to_i)\nm.times{tab << gets.split.map(&:to_i)}\ntab.sort!{|a, b| a[1] <=> b[1]}.reverse!\ntab.each do |x|\n\tresult += [x[0], n].min * x[1]\n\tn -= [x[0], n].min\nend\n\nputs result\n\n\n\n\n\n\n"}, {"source_code": "class Box\n\tattr_accessor :count, :value\n\n\tdef initialize(count, value)\n\t\t@count, @value = count, value\n\tend\nend\n\nt = gets.split.collect{|x| x.to_i}\nn,m = t[0], t[1]\n\na = []\n\nm.times do |i|\n\tt = gets.split.collect{|x| x.to_i}\n\ta << Box.new(t[0], t[1])\nend\n\na.sort!{|x,y| y.value <=> x.value}\n\nresult = 0\na.each do |b|\n\tif b.count <= n\n\t\tresult += b.count * b.value\n\t\tn-=b.count\n\telse\n\t\tresult += n * b.value\n\t\tn = 0\n\tend\nend\n\nputs result"}, {"source_code": "z=0;n,m=gets.split.map &:to_i;m.times.to_a.map{gets.split.map(&:to_i).reverse}.sort.reverse.each{|x,y|t=[n,y].min;n-=t;z+=x*t;};p z\n"}], "negative_code": [{"source_code": "result = 0\nn, m = gets.split.map(&:to_i)\nelements = m.times.to_a.map{ gets.split.map(&:to_i).reverse }\nelements.sort.reverse.each{ |x, y| puts x; puts y; t = [n, y].min; puts t; n -= t; puts n; result += x * t; break if n == 0 }\nputs result"}, {"source_code": "n,m=gets().chomp().split(' ').map(&:to_i) ;h=Hash.new\nm.times { a,b=gets().chomp().split(' ').map(&:to_i); h[a]=b; }\n(h=h.sort_by {|_key, value| value}).reverse! ;count=0\nh.each do |key, value|\n count+=(key>n)?((n)*value):(key*value) ;n-=key ;break if (n<=0)\nend\np count"}], "src_uid": "c052d85e402691b05e494b5283d62679"} {"nl": {"description": "Ted has a pineapple. This pineapple is able to bark like a bulldog! At time t (in seconds) it barks for the first time. Then every s seconds after it, it barks twice with 1 second interval. Thus it barks at times t, t\u2009+\u2009s, t\u2009+\u2009s\u2009+\u20091, t\u2009+\u20092s, t\u2009+\u20092s\u2009+\u20091, etc. Barney woke up in the morning and wants to eat the pineapple, but he can't eat it when it's barking. Barney plans to eat it at time x (in seconds), so he asked you to tell him if it's gonna bark at that time.", "input_spec": "The first and only line of input contains three integers t, s and x (0\u2009\u2264\u2009t,\u2009x\u2009\u2264\u2009109, 2\u2009\u2264\u2009s\u2009\u2264\u2009109)\u00a0\u2014 the time the pineapple barks for the first time, the pineapple barking interval, and the time Barney wants to eat the pineapple respectively.", "output_spec": "Print a single \"YES\" (without quotes) if the pineapple will bark at time x or a single \"NO\" (without quotes) otherwise in the only line of output.", "sample_inputs": ["3 10 4", "3 10 3", "3 8 51", "3 8 52"], "sample_outputs": ["NO", "YES", "YES", "YES"], "notes": "NoteIn the first and the second sample cases pineapple will bark at moments 3, 13, 14, ..., so it won't bark at the moment 4 and will bark at the moment 3.In the third and fourth sample cases pineapple will bark at moments 3, 11, 12, 19, 20, 27, 28, 35, 36, 43, 44, 51, 52, 59, ..., so it will bark at both moments 51 and 52."}, "positive_code": [{"source_code": "t,s,x = gets.chomp.split \n\nt = t.to_i \nx = x.to_i \ns = s.to_i \n\nif x{gets.split.map &:to_i}\nt, s, x = I[]\nif x == t || x >= s + t && ((x - t) % s == 0 || ((x - t - 1)) % s == 0)\n print 'YES'\nelse\n print 'NO'\nend\n"}, {"source_code": "t,s,x = gets.split(\" \").map(&:to_i)\nx -= t\nputs ((x>=0 and x%s < 2 and x!=1) ? \"YES\" :\"NO\")"}, {"source_code": "a=gets.chomp.split(\" \").map{|i| i.to_i}\nif(a[0]==a[2])\nputs \"YES\"\nelsif ((a[2]-a[0])>0 && (a[2]-a[0])/a[1]>0 && ((a[2]-a[0])%a[1]==0 || (a[2]-a[0])%a[1]==1) )\nputs \"YES\"\nelse\nputs \"NO\"\nend\n\n"}, {"source_code": "a=gets.chomp.split(\" \").map{|i| i.to_i}\nif(a[0]==a[2])\nputs \"YES\"\nelsif ((a[2]-a[0])>0 && (a[2]-a[0])/a[1]>0 && ((a[2]-a[0])%a[1]==0 || (a[2]-a[0])%a[1]==1) )\nputs \"YES\"\nelse\nputs \"NO\"\nend"}, {"source_code": "t,s,x=gets.split.map{|e| e.to_i}\nif (x-t)%s==0 && (x-t)/s>=0 then\n\tputs \"YES\"\nelsif (x-t-1)%s==0 && (x-t-1)/s>0 then\n\tputs \"YES\"\nelse\n\tputs \"NO\"\nend\n\n"}, {"source_code": "t, s, x = gets.split.map(&:to_i)\n\nputs (x-t) % s < 2 && x >= t && (s == 1 || t+1 != x ) ? 'YES' : 'NO'"}, {"source_code": "t, s, x = gets.split.map(&:to_i)\nputs x >= t && ( (x - t) % s == 0 || x - t > s && (x - t - 1) % s == 0 ) ? 'YES' : 'NO'\n"}, {"source_code": "#!/usr/bin/env ruby\n\nt, s, x = ARGF.gets.chomp.split(\" \").map { |s| s.to_i }\n\nif t == x\n puts \"YES\"\n exit\nend\nif x == t + 1 or x < t\n puts \"NO\"\n exit\nend\n\nif (x - t).modulo(s) == 0 or (x - t - 1).modulo(s) == 0\n puts \"YES\"\nelse\n puts \"NO\"\nend\n"}, {"source_code": "a=gets.chomp.split(\" \").map{|i| i.to_i}\nif(a[0]==a[2])\nputs \"YES\"\nelsif ((a[2]-a[0])>0 && (a[2]-a[0])/a[1]>0 && ((a[2]-a[0])%a[1]==0 || (a[2]-a[0])%a[1]==1) )\nputs \"YES\"\nelse\nputs \"NO\"\nend\n"}, {"source_code": "t,s,x = gets.split(' ').map(&:to_i)\na = x - t\nb = x - t - 1\nif a%s == 0 && (a >= 0)\n puts 'YES'\nelsif b%s == 0 && (b > 0)\n puts 'YES'\nelse\n puts 'NO'\nend\n"}, {"source_code": "input1 = gets.chomp\nnum = input1.split(\" \").map(&:to_i)\nif num[2]>=num[0] && num[2]!= (num[0]+1) && ((num[2]-num[0])%num[1] == 0 || (num[2] - num[0] - 1)%num[1] == 0)\n print \"YES\"\nelse\n print \"NO\"\nend\n"}, {"source_code": "t, s, x = gets.split.map { |x| x.to_i }\n\nif x >= t and (x - t) % s == 0\n\tputs 'YES'\nelsif x >= t + s + 1 and (x - t - 1) % s == 0\n\tputs 'YES'\nelse\n\tputs 'NO'\nend"}, {"source_code": "t, s, x = gets.chomp.split(' ').map(&:to_i)\n\n\nn = (x - t) / s\nnum = t + n * s\n\nfirst = true if (n == 0)\noneTime = (n > 0)\n\n#puts \"n : #{n}\"\n\nif n < 0\n\tputs 'NO'\n\texit\nend\n\nuntil num >= x\n\tnum += s if first\n\tnum += (s - 1) if !oneTime && !first\n\tnum += 1 if oneTime\n\n\toneTime = !oneTime\n\tfirst = false\n\n\t#puts \"Num : #{num}\"\nend\n\nif num == x\n\tputs 'YES'\nelse\n\tputs 'NO'\nend"}], "negative_code": [{"source_code": "t,s,x = gets.chomp.split \n\nt = t.to_i \nx = x.to_i \ns = s.to_i \n\nif x{gets.split.map &:to_i}\nt, s, x = I[]\nif x == t || x > t && ((x - t) % s == 0 || ((x - t - 1)) % s == 0)\n p 'YES'\nelse\n p 'NO'\nend\n"}, {"source_code": "I =->{gets.split.map &:to_i}\nt, s, x = I[]\nif x == t || x + s >= t && ((x - t) % s == 0 || ((x - t - 1)) % s == 0)\n p 'YES'\nelse\n p 'NO'\nend\n"}, {"source_code": "t,s,x = gets.split(\" \").map(&:to_i)\nx -= t\nputs (x>=0 and x%s < 2 and x!=1 ? \"YES\" :\"NO\")"}, {"source_code": "t, s, x = gets.split.map(&:to_i)\n\nputs (x-t) % s < 2 && t+1 != x ? 'YES' : 'NO'"}, {"source_code": "t, s, x = gets.split.map(&:to_i)\n\nputs (x-t) % s < 2 ? 'YES' : 'NO'"}, {"source_code": "t, s, x = gets.split.map(&:to_i)\nputs (x - t) % s == 0 || x - t > 1 && (x - t - 1) % s == 0 ? 'YES' : 'NO'\n"}, {"source_code": "#!/usr/bin/env ruby\n\nt, s, x = ARGF.gets.chomp.split(\" \").map { |s| s.to_i }\n\nif t == x\n puts \"YES\"\n exit\nend\nif x == t + 1\n puts \"NO\"\n exit\nend\n\nif ((r1 = (x - t).modulo(s)) == 0 and r1 >= t) or ((r2 = (x - t - 1).modulo(s)) == 0 and r2 >= t)\n puts \"YES\"\nelse\n puts \"NO\"\nend\n"}, {"source_code": "#!/usr/bin/env ruby\n\nt, s, x = ARGF.gets.chomp.split(\" \").map { |s| s.to_i }\n\nif t == x\n puts \"YES\"\n exit\nend\nif x == t + 1\n puts \"NO\"\n exit\nend\n\nif (x - t).modulo(s) == 0 or (x - t - 1).modulo(s) == 0\n puts \"YES\"\nelse\n puts \"NO\"\nend\n"}, {"source_code": "t,s,x = gets.split(' ').map(&:to_i)\na = x - t\nb = x - t - 1\nif a%s == 0\n puts 'YES'\nelsif b%s == 0 && (b%s > 0)\n puts 'YES'\nelse\n puts 'NO'\nend\n"}, {"source_code": "t,s,x = gets.split(' ').map(&:to_i)\na = x - t\nb = x - t - 1\nif a%s == 0\n puts 'YES'\nelsif b%s == 0 && (b > 0)\n puts 'YES'\nelse\n puts 'NO'\nend\n"}, {"source_code": "t, s, x = gets.chomp.split(' ').map(&:to_i)\n\n\nn = (x - t) / s\nnum = t + n * s\n\nfirst = true if (n == 0)\noneTime = (n > 0)\n\nuntil num >= x\n\tnum += s if first\n\tnum += (s - 1) if !oneTime && !first\n\tnum += 1 if oneTime\n\n\toneTime = !oneTime\n\tfirst = false\n\n\t#puts \"Num : #{num}\"\nend\n\nif num == x\n\tputs 'YES'\nelse\n\tputs 'NO'\nend"}], "src_uid": "3baf9d841ff7208c66f6de1b47b0f952"} {"nl": {"description": "Vasya has n pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every m-th day (at days with numbers m,\u20092m,\u20093m,\u2009...) mom buys a pair of socks to Vasya. She does it late in the evening, so that Vasya cannot put on a new pair of socks before the next day. How many consecutive days pass until Vasya runs out of socks?", "input_spec": "The single line contains two integers n and m (1\u2009\u2264\u2009n\u2009\u2264\u2009100;\u00a02\u2009\u2264\u2009m\u2009\u2264\u2009100), separated by a space.", "output_spec": "Print a single integer \u2014 the answer to the problem.", "sample_inputs": ["2 2", "9 3"], "sample_outputs": ["3", "13"], "notes": "NoteIn the first sample Vasya spends the first two days wearing the socks that he had initially. Then on day three he puts on the socks that were bought on day two.In the second sample Vasya spends the first nine days wearing the socks that he had initially. Then he spends three days wearing the socks that were bought on the third, sixth and ninth days. Than he spends another day wearing the socks that were bought on the twelfth day."}, "positive_code": [{"source_code": "n, m = gets.split.map(&:to_i)\ni = 0\nans = 0\nwhile n > 0\n\ti += 1\n\tif i % m == 0\n\t\tans += 1\n\t\tnext end\n\tn -= 1\n\tans += 1 end\nputs ans\n"}, {"source_code": "n,m=gets.split.map &:to_i;p (n-1)/(m-1)*m+(n-1)%(m-1)+1"}, {"source_code": "input=gets.split(\" \")\nn=input[0].to_i\nm=input[1].to_i\nk=n\ndays=0\nwhile k>0\n days+=1\n k=k-1\n if days % m == 0\n k=k+1\n end\nend\nputs days"}, {"source_code": "n, m = gets.chomp.split.map{|x| x.to_i}\n\ndiv = n/m\ndays = n + div\n\nwhile((div+=1) * m <= days)\n days += 1\nend\n\nputs days"}, {"source_code": "n, m = gets.split.map &:to_i\n\ni = 0\nwhile n > 0\n i += 1\n n -= 1 if i % m != 0\nend\n\np i"}, {"source_code": "a, b = gets.split(' ').map &:to_i\ntotal = 0\ntmp = 0\nwhile a > 0\n total += 1\n tmp += 1\n a -= 1\n if tmp == b\n tmp = 0\n a += 1\n end\nend\nputs total\n"}, {"source_code": "n,m=gets.split.map &:to_i;p (n*m-1)/(m-1)"}, {"source_code": "n,m=gets.split.map &:to_i;p (m*n-1)/(m-1)\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\nputs n + (n - 1) / (m - 1)"}, {"source_code": "a,b = gets.split.map(&:to_i)\nsum = a\nwhile a>=b\n tmp = a\n a = tmp/b\n sum+=a\n a += tmp%b \nend\np sum"}, {"source_code": "n, m = gets.split.map(&:to_i)\n\ni = 0\nloop do\n i += 1\n n -= 1\n n += 1 if i % m == 0\n break if n == 0\nend\n\nputs i\n"}, {"source_code": "n, m = gets.split(/\\s+/).map(&:to_i)\na = 0\n\nwhile n > 0\n a += 1\n n -= 1\n if a%m == 0\n n+=1\n end\nend\n\np a\n"}, {"source_code": "n, m = gets.split(/\\s+/).map(&:to_i)\np n + (n-1)/(m-1)\n"}, {"source_code": "n,m = gets.split.map(&:to_i)\nday = 0\nwhile n > 0\n day += 1\n n -= 1 if day % m != 0\nend\nputs day"}, {"source_code": "s = gets.split(' ')\t#\u0422\u0430\u043d\u0446\u044b \u0441 \u0431\u0443\u0431\u043d\u043e\u043c\n\nn = s[0].to_i\nm = s[1].to_i\n\ni = 0\nres = 0\nuntil n == 0\n\tres += 1\n\tn -= 1\n\ti += 1\n\tif i == m\n\t\tn += 1\n\t\ti = 0\n\tend\nend\n\nputs res"}, {"source_code": "n,m=gets.split.map &:to_i;p (m*n-1)/(m-1)"}, {"source_code": "n, m = *(gets.split(' ').collect { |n| n.to_i })\nday = 0\nuntil n == 0 do\n day += 1\n n -= 1 unless day % m == 0\nend\nputs day"}, {"source_code": "n,m=gets.split.map &:to_i;p (m*n-1)/(m-1)"}, {"source_code": "n,m=gets.split.map(&:to_i)\n\nx=n\nwhile (x 0\n n -= 1\n i += 1\n if i % m == 0\n n += 1\n end\nend\nputs(i)"}, {"source_code": "n,m=gets.split.map &:to_i;p (m*n-1)/(m-1)\n"}, {"source_code": "n, m = gets.split(' ').map(&:to_i)\n\nday = 0\nwhile n > 0\n day += 1\n n -= 1\n n += 1 if day % m == 0\nend\n\nputs day\n"}, {"source_code": "n,m=gets.split.map &:to_i;p (m*n-1)/(m-1)\n"}, {"source_code": "input = gets.split.map(&:to_i)\nn = input[0]\nm = input[1]\ndays = 0\nwhile n != 0\n days += 1\n if days % m == 0\n n += 1\n end\n n -= 1\nend\nputs days\n"}, {"source_code": "\n\na, b = gets.split.map(&:to_i)\n\n\n(1..100000).each do |i|\n #puts \"#{i}, #{a}\"\n if a == 0\n puts i-1\n break\n end\n\n a -= 1\n\n if i % b == 0\n a += 1\n end\n\n\nend\n\n\n\n"}, {"source_code": "n,m=gets.split.map &:to_i;p (m*n-1)/(m-1)\n"}, {"source_code": "n, m = gets.chomp.split(' ').map { |i| i.to_i }\nans = 1\nuntil n == 0 do\n n -= 1\n n += 1 if ans % m == 0\n ans += 1\nend\n\nputs ans - 1"}, {"source_code": "n,m=gets.split.map &:to_i\n\nday=0\n\nwhile n>0\n day+=1\n n-=1\n if day%m==0\n n+=1\n end\nend\n\np day"}, {"source_code": "n,m=gets.split.map &:to_i;p (m*n-1)/(m-1)\n"}, {"source_code": "#!/usr/bin/env ruby\n\n#n = ARGV[0].to_i\n#m = ARGV[1].to_i\n\ninp = $stdin.gets.chomp.split\nn = inp[0].to_i\nm = inp[1].to_i\n\nday = 0\n\nwhile n > 0\n day += 1\n n -= 1 unless day%m==0\nend\n\nputs day\n"}, {"source_code": "n,m=gets.split.map &:to_i;p (m*n-1)/(m-1)\n"}, {"source_code": "n,m=gets.split.map &:to_i;p (m*n-1)/(m-1)"}, {"source_code": "n,m=gets.split.map &:to_i;p (m*n-1)/(m-1)"}, {"source_code": "n, m = gets.split.map!{ |s| s.to_i }\n\nres = 0\nday = 0\n\nwhile n > 0\n res += 1\n n -= 1\n day += 1\n if day >= m\n n += 1\n day = 0\n end\nend\n\np res\n"}, {"source_code": "n,m=gets.split.map &:to_i;p (m*n-1)/(m-1)"}, {"source_code": "n,m = gets.split.map{|r| r.to_i}\n\nk = n\ni = 1\nwhile i<=n\n if i%m == 0\n n+=1\n end\n i+=1\nend\nputs n\n\n\n"}, {"source_code": "a, b = $stdin.readline.split.map(&:to_i)\n\nn = 0\nr = 0\nwhile a>0\n n+= a\n t = r+a\n a = t/b\n r = t%b\nend\n\nputs n"}, {"source_code": "a, b = gets.split.map(&:to_i); p (a*b-1)/(b-1)\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\nputs ((n - 1) / (m - 1) * m + (n - 1) % (m - 1) + 1)"}, {"source_code": "a, b = gets.split.map &:to_i\ntotal = a\nwhile a / b > 0\n total += a / b\n if a % b == 0\n a = a / b\n else\n a = a / b + a % b\n end\nend\nputs total\n"}, {"source_code": "n,m=gets.split.map &:to_i;p (m*n-1)/(m-1)\n"}, {"source_code": "ARGF.lines do |line|\n n, m = line.split.map(&:to_i)\n sol = n+(n-1)/(m-1)\n puts sol\nend\n"}, {"source_code": "n,m=gets.split.map &:to_i;p (m*n-1)/(m-1)\n"}, {"source_code": "n,m=gets.split.map{|e| e.to_i}\nc=1\n1.upto(10000000){|i|\n\tif i%m==0 then\n\t\tc=c+1\n\tend\n\tif n<=i then\n\t\tc=c-1\n\t\tif c<=0 then\n\t\t\tputs i\n\t\t\tbreak\n\t\tend\n\tend\n}"}], "negative_code": [{"source_code": "n, m = gets.split.map(&:to_i)\nc = n\nc += n = n / m while n >= m\nputs c"}, {"source_code": "a,b = gets.split.map(&:to_i)\nsum = a\nwhile a!=0\n a = a/b\n sum+=a\nend\np sum"}, {"source_code": "n, m = gets.split(/\\s+/).map(&:to_i)\na = n\nr = 0\n\nwhile n+r >= m\n a += (n+r)/m\n r, n = n%m, n/m\nend\np a\n=begin\n\n\n8 3\n\n1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6\n1 2 3 4 5 6 7 8 9 0 1 2 3 4 5\n x x\n=end\n"}, {"source_code": "n, m = gets.split(/\\s+/).map(&:to_i)\na = n\n\nwhile n >= m\n a += n/m\n n /= m\nend\n\np a\n"}, {"source_code": "n,m=gets.split.map(&:to_i)\n\nx=(m*n)/(m-1)\nif (x==n+x/m)\n puts x\nelse\n puts x-1\nend"}, {"source_code": "n, m = gets.split(' ').map(&:to_i)\n\nresult = n\nwhile n > 0\n n /= m\n result += n\nend\n\nputs result\n"}, {"source_code": "n, m = gets.split(' ').map(&:to_i)\n\nresult = n\nwhile n > 0\n result += n % m\n n /= m\n result += n\nend\n\nputs result - 1\n"}, {"source_code": "\n\na, b = gets.split.map(&:to_i)\na -= 1\n\n(1..100000).each do |i|\n #puts \"day #{i} socks #{a}\"\n if a == 0\n puts i\n break\n end\n a -= 1\n if (i-1) % b == 0\n a += 1\n end\n\nend\n\n\n\n"}, {"source_code": "\n\na, b = gets.split.map(&:to_i)\n\n\n(1..100000).each do |i|\n if a == 0\n puts i\n break\n end\n\n a -= 1\n\n if (i-1)%b == 0 && i != 1\n a += 1\n end\n\n\nend\n\n\n\n"}, {"source_code": "\n\na, b = gets.split.map(&:to_i)\n\nif a == 1\n\n puts \"1\"\n\nelse\n\n a -= 1\n (1..100000).each do |i|\n #puts \"day #{i} socks #{a}\"\n if a == 0\n puts i\n break\n end\n a -= 1\n if (i-1) % b == 0\n a += 1\n end\n\n end\n\nend\n\n\n\n"}, {"source_code": "#!/usr/bin/env ruby\n\nn = ARGV[0].to_i\nm = ARGV[1].to_i\n\nday = 0\n\nwhile n > 0\n day += 1\n n -= 1 unless day%m==0\nend\n\nputs day\n"}, {"source_code": "n,m = gets.split.map{|r| r.to_i}\n\nfor i in 1..n\n if i%m == 0\n n+=1\n end\nend\nputs n\n\n"}, {"source_code": "n,m = gets.split.map{|r| r.to_i}\n\nfor i in 1..n\n if i%m == 0\n n+=1\n end\nend\nputs n+1\n\n"}, {"source_code": "a, b = gets.split.map &:to_i\nif a < b \n puts a\n exit\nend\ntotal = a\nwhile a != 1\n total += a % b == 0 ? a / b : a / b + 1\n a /= b\nend\nputs total\n"}, {"source_code": "a, b = gets.split.map &:to_i\ntotal = a\nwhile a / b > 0\n total += a / b\n if a % b == 0\n a = a / b\n else\n a = a / b + 1\n end\nend\nputs total\n"}, {"source_code": "a, b = gets.split.map &:to_i\nputs a + (a + a / b) / b\n"}], "src_uid": "42b25b7335ec01794fbb1d4086aa9dd0"} {"nl": {"description": "Permutation p is an ordered set of integers p1,\u2009\u2009p2,\u2009\u2009...,\u2009\u2009pn, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation p as pi. We'll call number n the size or the length of permutation p1,\u2009\u2009p2,\u2009\u2009...,\u2009\u2009pn.Petya decided to introduce the sum operation on the set of permutations of length n. Let's assume that we are given two permutations of length n: a1,\u2009a2,\u2009...,\u2009an and b1,\u2009b2,\u2009...,\u2009bn. Petya calls the sum of permutations a and b such permutation c of length n, where ci\u2009=\u2009((ai\u2009-\u20091\u2009+\u2009bi\u2009-\u20091) mod n)\u2009+\u20091 (1\u2009\u2264\u2009i\u2009\u2264\u2009n).Operation means taking the remainder after dividing number x by number y.Obviously, not for all permutations a and b exists permutation c that is sum of a and b. That's why Petya got sad and asked you to do the following: given n, count the number of such pairs of permutations a and b of length n, that exists permutation c that is sum of a and b. The pair of permutations x,\u2009y (x\u2009\u2260\u2009y) and the pair of permutations y,\u2009x are considered distinct pairs.As the answer can be rather large, print the remainder after dividing it by 1000000007 (109\u2009+\u20097).", "input_spec": "The single line contains integer n (1\u2009\u2264\u2009n\u2009\u2264\u200916).", "output_spec": "In the single line print a single non-negative integer \u2014 the number of such pairs of permutations a and b, that exists permutation c that is sum of a and b, modulo 1000000007 (109\u2009+\u20097).", "sample_inputs": ["3", "5"], "sample_outputs": ["18", "1800"], "notes": null}, "positive_code": [{"source_code": "st = gets.split\nn=st[0].to_i\n\narray=[1,0,3,0,15,0,133,0,2025,0,37851,0,1030367,0,36362925,0]\nfact = [1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800, 39916800, 479001600, 6227020800,87178291200, 1307674368000, 20922789888000]\nputs (fact[n-1]*array[n-1])%1000000007"}], "negative_code": [{"source_code": "st = gets.split\nn=st[0].to_i\n\narray=[1,0,18,0,1800,0,180000,0,18000000,0,1800000000,0,180000000000,0,18000000000000,0]\n\nputs array[n-1]%1000000007"}, {"source_code": "st = gets.split\nn=st[0].to_i\n\narray=[1,0,18,0,1800,0,180000,0,18000000,0,1800000000,0,18000000000,0,1800000000000,0]\n\nputs array[n-1]%1000000007"}, {"source_code": "st = gets.split\nn=st[0].to_i\n\narray=[1,0,18,180,1800,18000,180000,1800000,18000000,180000000,1800000000,18000000000,18000000000,180000000000,1800000000000,18000000000000]\n\nputs array[n-1]%1000000007"}], "src_uid": "a6a804ce23bc48ec825c17d64ac0bb69"} {"nl": {"description": "A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings \"kek\", \"abacaba\", \"r\" and \"papicipap\" are palindromes, while the strings \"abb\" and \"iq\" are not.A substring $$$s[l \\ldots r]$$$ ($$$1\u2009\\leq\u2009l\u2009\\leq\u2009r\u2009\\leq\u2009|s|$$$) of a string $$$s\u2009=\u2009s_{1}s_{2} \\ldots s_{|s|}$$$ is the string $$$s_{l}s_{l\u2009+\u20091} \\ldots s_{r}$$$.Anna does not like palindromes, so she makes her friends call her Ann. She also changes all the words she reads in a similar way. Namely, each word $$$s$$$ is changed into its longest substring that is not a palindrome. If all the substrings of $$$s$$$ are palindromes, she skips the word at all.Some time ago Ann read the word $$$s$$$. What is the word she changed it into?", "input_spec": "The first line contains a non-empty string $$$s$$$ with length at most $$$50$$$ characters, containing lowercase English letters only.", "output_spec": "If there is such a substring in $$$s$$$ that is not a palindrome, print the maximum length of such a substring. Otherwise print $$$0$$$. Note that there can be multiple longest substrings that are not palindromes, but their length is unique.", "sample_inputs": ["mew", "wuffuw", "qqqqqqqq"], "sample_outputs": ["3", "5", "0"], "notes": "Note\"mew\" is not a palindrome, so the longest substring of it that is not a palindrome, is the string \"mew\" itself. Thus, the answer for the first example is $$$3$$$.The string \"uffuw\" is one of the longest non-palindrome substrings (of length $$$5$$$) of the string \"wuffuw\", so the answer for the second example is $$$5$$$.All substrings of the string \"qqqqqqqq\" consist of equal characters so they are palindromes. This way, there are no non-palindrome substrings. Thus, the answer for the third example is $$$0$$$."}, "positive_code": [{"source_code": "s = gets.chomp\nif s == s[0] * s.length\n puts \"0\"\nelse\n puts \"#{s.length - (s == s.reverse ? 1 : 0)}\"\nend"}], "negative_code": [{"source_code": "s = gets\nif s == s[0] * s.length\n puts\"0\"\nelse\n puts \"#{s.length - (s == s.reverse ? 1 : 0)}\"\nend"}, {"source_code": "s = gets\nif s == s[0] * s.length\n puts \"0\"\nelse\n puts \"#{s.length - (s == s.reverse ? 1 : 0)}\"\nend"}], "src_uid": "6c85175d334f811617e7030e0403f706"} {"nl": {"description": "Given a positive integer n, find k integers (not necessary distinct) such that all these integers are strictly greater than 1, and their product is equal to n.", "input_spec": "The first line contains two integers n and k (2\u2009\u2264\u2009n\u2009\u2264\u2009100000, 1\u2009\u2264\u2009k\u2009\u2264\u200920).", "output_spec": "If it's impossible to find the representation of n as a product of k numbers, print -1. Otherwise, print k integers in any order. Their product must be equal to n. If there are multiple answers, print any of them.", "sample_inputs": ["100000 2", "100000 20", "1024 5"], "sample_outputs": ["2 50000", "-1", "2 64 2 2 2"], "notes": null}, "positive_code": [{"source_code": "n, k = gets.chomp.split().map { |e| e.to_i }\nLIMIT = Math.sqrt(n)\nfactors = []\nfor i in 2 .. LIMIT\n\twhile n % i == 0 && k != 1\n\t\tfactors << i\n\t\tn /= i\n\t\tk -= 1\n\tend\nend\n\nif k != 1 or n == 1\n\tputs \"-1\"\nelse\n\tfor i in factors\n\t\tprint(i,\" \")\n\tend\n\tputs n\nend"}, {"source_code": "require 'prime'\nn,k=gets.split.map(&:to_i)\na=n.prime_division.flat_map{|n,p|[n]*p}\nputs a.size0\n p*=3\nend\nif n%p>0\n p n/p+1\nelse\n p 1\nend"}], "negative_code": [{"source_code": "p gets.to_i/3+1"}, {"source_code": "p (gets.to_i+1)/3"}, {"source_code": "p (gets.to_i/3.0).ceil"}, {"source_code": "p (gets.to_i+2)/3"}, {"source_code": "n = gets.to_i\nt = 1\nwhile n%t==0\n t *= 3\nend\nans = n/t+n%t\nputs ans\n"}, {"source_code": "#!/usr/bin/env ruby\nn = gets.to_i\nk = 0\nloop do\n if n % (3**k) != 0\n puts((n / (3.0**k)).ceil)\n break\n end\n k += 1\nend\n"}], "src_uid": "7e7b59f2112fd200ee03255c0c230ebd"} {"nl": {"description": "Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be n problems, sorted by difficulty, i.e. problem 1 is the easiest and problem n is the hardest. Limak knows it will take him 5\u00b7i minutes to solve the i-th problem.Limak's friends organize a New Year's Eve party and Limak wants to be there at midnight or earlier. He needs k minutes to get there from his house, where he will participate in the contest first.How many problems can Limak solve if he wants to make it to the party?", "input_spec": "The only line of the input contains two integers n and k (1\u2009\u2264\u2009n\u2009\u2264\u200910, 1\u2009\u2264\u2009k\u2009\u2264\u2009240)\u00a0\u2014 the number of the problems in the contest and the number of minutes Limak needs to get to the party from his house.", "output_spec": "Print one integer, denoting the maximum possible number of problems Limak can solve so that he could get to the party at midnight or earlier.", "sample_inputs": ["3 222", "4 190", "7 1"], "sample_outputs": ["2", "4", "7"], "notes": "NoteIn the first sample, there are 3 problems and Limak needs 222 minutes to get to the party. The three problems require 5, 10 and 15 minutes respectively. Limak can spend 5\u2009+\u200910\u2009=\u200915 minutes to solve first two problems. Then, at 20:15 he can leave his house to get to the party at 23:57 (after 222 minutes). In this scenario Limak would solve 2 problems. He doesn't have enough time to solve 3 problems so the answer is 2.In the second sample, Limak can solve all 4 problems in 5\u2009+\u200910\u2009+\u200915\u2009+\u200920\u2009=\u200950 minutes. At 20:50 he will leave the house and go to the party. He will get there exactly at midnight.In the third sample, Limak needs only 1 minute to get to the party. He has enough time to solve all 7 problems."}, "positive_code": [{"source_code": "n, k = gets.chomp.split().map { |x| x.to_i }\n\ndef cuadratic( d )\n return ( -5 + Math.sqrt( 25 + 40*d ) ) / 10\nend\n\nputs [ cuadratic(240-k).to_i, n ].min\n"}, {"source_code": "#bismillahir rahmanir rahim \n\nn,k = gets.split.map {|x| x.to_i } \n\nk = 240-k \nc = 0 \n\nfor i in 1..10 \n q = 5*i*(i+1)\n q = q/2 \n if k>=q \n c = c+1 \n end \nend \n\nc=n if c>n \n\nputs c "}, {"source_code": "n,k=gets.split.map &:to_i\nk=240-k\np ((1..n).find{|i|5*i*(i+1)/2>k}||n+1)-1"}, {"source_code": "n, k = gets.chomp.split.map(&:to_i)\nt = 240 - k\nidx = 0\nsum = 0\n(1..n).each do |i|\n sum += i * 5\n if sum <= t\n idx = i\n else\n break\n end\nend\nputs idx\n"}, {"source_code": "n,k = gets.split().map(&:to_i)\ni = 0\nt = 0\nuntil t > 240-k\n\ti += 1\n\tt += i*5\nend\n\nputs [i-1,n].min"}, {"source_code": "n,k = gets.split.map &:to_i \navailable_time = 240-k \ncounter = 0 \nproblem = 1 \nn.times do \n time_taken = problem * 5\n available_time-= time_taken \n if available_time >=0 then \n problem+=1 \n counter +=1\n else \n break \n end \nend \nputs counter \n\n \n \n "}, {"source_code": "n, k = gets.split.map(&:to_i)\n\nrem = 240 - k\n\nans = 0\n(1..n).each do |i|\n rem -= i * 5\n if rem < 0\n break\n end\n ans += 1\nend\nputs ans"}, {"source_code": "total_time = 4 * 60\nn, k = gets.strip.split.map(&:to_i)\ntotal_time -= k\ntime = 0\nans = 0\n(1..n).each do |i|\n curr_time = 5 * i\n break if time + curr_time > total_time\n ans += 1\n time += curr_time\nend\nputs ans\n"}, {"source_code": "n,m=gets.split.map{|e| e.to_i}\nm=240-m\nans=0\nsum=0\nn.times{|i|\n\tsum+=((i+1)*5)\n\tbreak if sum>m\n\tans+=1\n}\nputs ans\n\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\nk = 240 - k\n1.upto(n) do |i|\n\tk -= i * 5 \n\tif k < 0 \n\t\tputs i - 1\n\t\tbreak\n\tend\nend\nif k >= 0\n\tputs n\nend\n"}, {"source_code": "n,k=gets.split.map &:to_i\nk=240-k\nres=0\nwhile res=5*(res+1)\n res+=1\n k-=5*res;\nend\nputs res\n"}, {"source_code": "nk = gets.chomp\nnk = nk.split\nproblems = nk[0].to_i\nminutes = nk[1].to_i\n\nsolved = 0\nfor i in (1..problems)\n\tif minutes + (i * 5) <= 240\n\t\tminutes += (i*5)\n\t\tsolved += 1\n\telse\n\t\tbreak\n\tend\nend\n\nprint solved"}, {"source_code": "n, k = gets.split.map(&:to_i)\nc = 0\nt = 60 * 4 - k\nwhile t >= (c + 1) * 5 && c < n\n c += 1\n t -= c * 5\nend\nputs c\n"}, {"source_code": "n, k = gets.split(' ').map(&:to_i)\nk = 240 - k\n\nresult = n\n\n1.upto(n) do |x|\n if (1..x).inject(&:+)*5 > k\n result = x-1\n break\n end\nend\n\nputs result\n"}], "negative_code": [{"source_code": "n, k = gets.split.map(&:to_i)\n\nrem = 240 - k\n\nans = 0\n(1..n).each do |i|\n if rem <= 0\n break\n end\n rem -= i * 5\n ans += 1\nend\nputs ans"}, {"source_code": "n, k = gets.split.map(&:to_i)\n\nrem = 240 - k\n\nans = 0\n(1..n).each do |i|\n rem -= i * 5\n if rem <= 0\n break\n end\n ans += 1\nend\nputs ans"}, {"source_code": "total_time = 4 * 60\nn, k = gets.strip.split.map(&:to_i)\ntotal_time -= k\ntime = 5\nans = 0\n(1..n).each do |i|\n curr_time = 5 * i\n ans += 1\n break if time + curr_time > total_time\n time += curr_time\nend\nputs ans\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\nc = 0\nt = 60 * 4 - k\nwhile t > (c + 1) * 5 && c < n\n c += 1\n t -= c * 5\nend\nputs c\n"}], "src_uid": "41e554bc323857be7b8483ee358a35e2"} {"nl": {"description": "Your friend has recently learned about coprime numbers. A pair of numbers {a,\u2009b} is called coprime if the maximum number that divides both a and b is equal to one. Your friend often comes up with different statements. He has recently supposed that if the pair (a,\u2009b) is coprime and the pair (b,\u2009c) is coprime, then the pair (a,\u2009c) is coprime. You want to find a counterexample for your friend's statement. Therefore, your task is to find three distinct numbers (a,\u2009b,\u2009c), for which the statement is false, and the numbers meet the condition l\u2009\u2264\u2009a\u2009<\u2009b\u2009<\u2009c\u2009\u2264\u2009r. More specifically, you need to find three numbers (a,\u2009b,\u2009c), such that l\u2009\u2264\u2009a\u2009<\u2009b\u2009<\u2009c\u2009\u2264\u2009r, pairs (a,\u2009b) and (b,\u2009c) are coprime, and pair (a,\u2009c) is not coprime.", "input_spec": "The single line contains two positive space-separated integers l, r (1\u2009\u2264\u2009l\u2009\u2264\u2009r\u2009\u2264\u20091018; r\u2009-\u2009l\u2009\u2264\u200950).", "output_spec": "Print three positive space-separated integers a, b, c\u00a0\u2014 three distinct numbers (a,\u2009b,\u2009c) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order. If the counterexample does not exist, print the single number -1.", "sample_inputs": ["2 4", "10 11", "900000000000000009 900000000000000029"], "sample_outputs": ["2 3 4", "-1", "900000000000000009 900000000000000010 900000000000000021"], "notes": "NoteIn the first sample pair (2,\u20094) is not coprime and pairs (2,\u20093) and (3,\u20094) are. In the second sample you cannot form a group of three distinct integers, so the answer is -1. In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three. "}, "positive_code": [{"source_code": "l,r=gets.split.map &:to_i\na=l+l%2\nputs a+2<=r ?[a,a+1,a+2].join(\" \") :-1\n"}, {"source_code": "l,r=gets.split.map &:to_i\na=l+l%2\nputs a+2<=r ?[a,a+1,a+2].join(\" \") :-1\n"}, {"source_code": "l,r=gets.split.map &:to_i\na=l+l%2\nputs a+2<=r ?[a,a+1,a+2].join(\" \") :-1"}, {"source_code": "l,r=gets.chomp.split.map(&:to_i)\nif l==r\n\tputs \"-1\"\n\texit\nend\nwhile lr\n\t\tputs \"-1\"\n\t\tbreak\n\telse\n\t\tputs l.to_s+' '+(l+1).to_s+' '+(l+2).to_s\n\t\tbreak\n\tend\nend"}, {"source_code": "l,r=gets.split.map &:to_i\na=l+l%2\nputs a+2<=r ?[a,a+1,a+2].join(\" \") :-1\n"}, {"source_code": "l,r=gets.split.map &:to_i\na=l+l%2\nputs a+2<=r ?[a,a+1,a+2].join(\" \") :-1\n"}, {"source_code": "l, r = gets.chomp.split(/ /).map(&:to_i)\nif (l % 2 != 0)\n l += 1\nend\nif (l + 2 > r)\n puts \"-1\"\nelse\n puts \"#{l} #{l + 1} #{l + 2}\"\nend\n"}, {"source_code": "def test(l,r)\nl.upto(r-2){|a|\n\t(a+1).upto(r-1){|b|\n\t\tnext if a.gcd(b)!=1\n\t\t(b+1).upto(r){|c|\n\t\t\tnext if b.gcd(c)!=1\n\t\t\tnext if a.gcd(c)==1\n\t\t\treturn [a,b,c]\n\t\t}\n\t}\n}\nreturn [-1]\nend\nl,r=gets.split.map{|e| e.to_i}\nputs test(l,r)*\" \"\n\n"}, {"source_code": "# coding: utf-8\n\nl, r = gets.split.map(&:to_i)\n\ndef euclidean(a, b)\n while b > 0\n c = a % b\n a = b\n b = c\n end\n \n a\nend\n# counter example\n# if (a,b) is coprime and (b, c) is coprime, then (a,c) is also coprime\n# if possible, print a b c\n# if not possible, print -1\n# l\uacfc r\uc0ac\uc774 \uac04\uaca9\uc740 \ucd5c\ub300 50\nif r - l < 2\n puts \"-1\"\nelse\n # \ub450 \uc218\uc758 \uad00\uacc4\uc774\ubbc0\ub85c \uc720\ud074\ub9ac\ub4dc \ud638\uc81c\ubc95\uc744 \uc774\uc6a9\ud55c\ub2e4\n # \ub098\ub220 \ub5a8\uc5b4\uc9c0\ub294 \uc2dc\uc810\uc774 \ucd5c\ub300\uacf5\uc57d\uc218(GCD)\uc778\ub370 1\uc774 \ub098\uc624\uba74 \uc11c\ub85c\uc18c\uc774\ub2e4.\n printed = false\n\n catch :found do\n for a in l...r\n for b in (a+1)...r\n for c in (b+1)..r\n if euclidean(a, b) == 1 && euclidean(b, c) == 1 && euclidean(a, c) != 1\n puts \"#{a} #{b} #{c}\"\n printed = true\n throw :found\n end\n end\n end\n end\n end \n\n if !printed\n puts \"-1\"\n end\nend\n"}, {"source_code": "def isCoprime(a,b)\n if b != 0\n return isCoprime(b,a%b)\n end\n return (a == 1)\nend\n\ndef counter(l, r)\n for a in (l..r+1)\n for b in (a+1)..(r)\n for c in (b+1)..(r)\n if isCoprime(a,b)\n if isCoprime(b,c)\n unless isCoprime(a,c)\n return \"#{a} #{b} #{c}\"\n end\n end\n end\n end\n end\n end\n -1\nend\n\nl, r = gets.chomp.split\nl = l.to_i\nr = r.to_i\n\nprint counter(l, r)\n"}, {"source_code": "l,r=gets.split.map &:to_i\na=l+l%2\nputs a+2<=r ?[a,a+1,a+2].join(\" \") :-1\n"}, {"source_code": "def gcd(a,b)\nif b == 0\n return a;\nelse\n return gcd(b, a % b);\nend\nend\n\n\ncoprime = false\nreq_a = 0\nreq_b = 0\nreq_c = 0\nl,h = gets.split(\" \").map(&:to_i)\n(l..h).each do |a|\n (a+1..h).each do |b|\n (b+1..h).each do |c|\n # puts \"#{a} #{b} #{c}\"\n # puts \"#{gcd(b,a)} #{gcd(c,b)} #{gcd(c,a)}\"\n if gcd(a,b) == 1 && gcd(b,c) == 1 && gcd(a,c) != 1\n req_a = a\n req_b = b\n req_c = c\n coprime = true\n break\n end\n\n end\n break if coprime\n end\n break if coprime\nend\n\nputs coprime ? \"#{req_a} #{req_b} #{req_c}\" :-1\n"}, {"source_code": "=begin\ndata = gets.chomp.split(/\\s/).map {|n| n.to_i}\n#p data\nputs data.inject(:+) / data.length\n=end\n\n\ndef nod(x,y)\n if x == y\n return x\n end\n if x == 0\n return y\n end\n if y == 0\n return x\n end\n if x > y\n return nod(y, x % y)\n else\n return nod(x, y % x)\n end\nend\n\n\ndata = gets.chomp.split(/\\s/).map{|n| n.to_i}\nl = data[0]\nr = data[1]\n\na = l\nb = a + 1\nc = b + 1\nres = -1\n\nwhile a < r - 1\n b = a + 1\n while b < r\n c = b + 1\n while c <= r\n if nod(a, b) == 1 && nod(b,c) == 1 && nod(a,c) > 1\n puts \"#{a} #{b} #{c}\"\n exit\n end\n c += 1\n end\n b += 1\n end\n a += 1\nend\n\nputs \"#{-1}\" if res <= 0\n\n\n"}, {"source_code": "#require 'prime'\ndef coprime?(a, b)\n a.gcd(b).equal?(1)\nend\nl, r = gets.chomp.split.map(&:to_i)\na = 0\nb = 0\nc = 0\nfor i in l...r\n a = i\n b = 0\n c = 0\n for j in (i + 1)..r\n b = j if coprime?(a, j) && b == 0\n# print \"a = #{a}, b = #{b}, c = #{c}\\n\"\n for k in (j + 1)..r\n if coprime?(b, k) && c == 0 && (coprime?(a, c) != true)\n c = k\n# print \"a = #{a}, b = #{b}, c = #{c}\\n\"\n break\n end\n end\n break if c != 0\n b = 0\n# print \"a = #{a}, b = #{b}, c = #{c}\\n\"\n end\n break if coprime?(a, c) == false\nend\nif a == 0 || b == 0 || c == 0\n puts -1\nelse\n puts [a, b, c].join(\" \")\nend\n#p Prime.prime?(3)\n#p coprime?(3, 4)\n#p coprime?(900000000000000010, 900000000000000011)\n#p coprime?(900000000000000011, 900000000000000012)\n#p coprime?(900000000000000010, 900000000000000012)\n\n"}, {"source_code": "l,r=gets.split.map &:to_i\na=l+l%2\nputs a+2<=r ?[a,a+1,a+2].join(\" \") :-1"}, {"source_code": "l,r=gets.split.map &:to_i\na=l+l%2\nputs a+2<=r ?[a,a+1,a+2].join(\" \") :-1\n"}, {"source_code": "l, r = gets.split.map {|i| i.to_i}\nif r - l == 2 && l % 2 == 1 || r - l < 2\n puts -1\nelse\n if l % 2 == 1\n l += 1\n end\n puts l.to_s + ' ' + (l + 1).to_s + ' ' + (l + 2).to_s\nend"}, {"source_code": "l,r=gets.split.map &:to_i\na=l+l%2\nputs a+2<=r ?[a,a+1,a+2].join(\" \") :-1\n"}, {"source_code": "l,r=gets.split.map &:to_i\na=l+l%2\nputs a+2<=r ?[a,a+1,a+2].join(\" \") :-1\n"}, {"source_code": "l,r=gets.split.map &:to_i\na=l+l%2\nputs a+2<=r ?[a,a+1,a+2].join(\" \") :-1"}], "negative_code": [{"source_code": "l,r=gets.chomp.split.map(&:to_i)\nwhile lr\n\t\tputs \"-1\"\n\t\tbreak\n\telse\n\t\tputs l.to_s+' '+(l+1).to_s+' '+(l+2).to_s\n\t\tbreak\n\tend\nend"}, {"source_code": "# coding: utf-8\n\nl, r = gets.split.map(&:to_i)\n\ndef euclidean(a, b)\n while b > 0\n c = a % b\n a = b\n b = c\n end\n \n a\nend\n# counter example\n# if (a,b) is coprime and (b, c) is coprime, then (a,c) is also coprime\n# if possible, print a b c\n# if not possible, print -1\n# l\uacfc r\uc0ac\uc774 \uac04\uaca9\uc740 \ucd5c\ub300 50\nif r - l < 2\n puts \"-1\"\nelse\n # \ub450 \uc218\uc758 \uad00\uacc4\uc774\ubbc0\ub85c \uc720\ud074\ub9ac\ub4dc \ud638\uc81c\ubc95\uc744 \uc774\uc6a9\ud55c\ub2e4\n # \ub098\ub220 \ub5a8\uc5b4\uc9c0\ub294 \uc2dc\uc810\uc774 \ucd5c\ub300\uacf5\uc57d\uc218(GCD)\uc778\ub370 1\uc774 \ub098\uc624\uba74 \uc11c\ub85c\uc18c\uc774\ub2e4.\n printed = false\n\n for i in (l+1)...r\n if euclidean(l, i) == 1 && euclidean(i, r) == 1 && euclidean(l, r) != 1\n puts \"#{l} #{i} #{r}\"\n printed = true\n break\n end\n end\n\n if !printed\n puts \"-1\"\n end\nend\n"}, {"source_code": "# coding: utf-8\n\nl, r = gets.split.map(&:to_i)\n\ndef euclidean(a, b)\n while b > 0\n c = a % b\n a = b\n b = c\n end\n \n a\nend\n# counter example\n# if (a,b) is coprime and (b, c) is coprime, then (a,c) is also coprime\n# if possible, print a b c\n# if not possible, print -1\n# l\uacfc r\uc0ac\uc774 \uac04\uaca9\uc740 \ucd5c\ub300 50\nif r - l < 2\n puts \"-1\"\nelse\n # \ub450 \uc218\uc758 \uad00\uacc4\uc774\ubbc0\ub85c \uc720\ud074\ub9ac\ub4dc \ud638\uc81c\ubc95\uc744 \uc774\uc6a9\ud55c\ub2e4\n # \ub098\ub220 \ub5a8\uc5b4\uc9c0\ub294 \uc2dc\uc810\uc774 \ucd5c\ub300\uacf5\uc57d\uc218(GCD)\uc778\ub370 1\uc774 \ub098\uc624\uba74 \uc11c\ub85c\uc18c\uc774\ub2e4.\n printed = false\n\n catch :found do\n for a in l...r\n for b in (a+1)...r\n for c in (b+1)...r\n if euclidean(a, b) == 1 && euclidean(b, c) == 1 && euclidean(a, c) != 1\n puts \"#{a} #{b} #{c}\"\n printed = true\n throw :found\n end\n end\n end\n end\n end \n\n if !printed\n puts \"-1\"\n end\nend\n"}, {"source_code": "=begin\ndata = gets.chomp.split(/\\s/).map {|n| n.to_i}\n#p data\nputs data.inject(:+) / data.length\n=end\n\n\ndef nod(x,y)\n if x == y\n return x\n end\n if x == 0\n return y\n end\n if y == 0\n return x\n end\n if x > y\n return nod(y, x % y)\n else\n return nod(x, y % x)\n end\nend\n\n\ndata = gets.chomp.split(/\\s/).map{|n| n.to_i}\nl = data[0]\nr = data[1]\n\n\na = l\nb = a + 1\n\nres = -1\n\nwhile res < 0 && b <= r\n if nod(a, b) == 1\n res = 0\n else\n b += 1\n end\nend\n\nc = b + 1\n\nwhile res == 0 && c <=r\n if nod(b,c) == 1 && nod(a,c) > 1\n res = 1\n else\n c += 1\n end\nend\n\nif res <= 0\n puts -1\nelse\n puts \"#{a} #{b} #{c}\"\nend\n\n\n"}, {"source_code": "=begin\ndata = gets.chomp.split(/\\s/).map {|n| n.to_i}\n#p data\nputs data.inject(:+) / data.length\n=end\n\n\ndef nod(x,y)\n if x == y\n return x\n end\n if x == 0\n return y\n end\n if y == 0\n return x\n end\n if x > y\n return nod(y, x % y)\n else\n return nod(x, y % x)\n end\nend\n\n\ndata = gets.chomp.split(/\\s/).map{|n| n.to_i}\nl = data[0]\nr = data[1]\n\n\na = l\nb = a + 1\nc = b + 1\nres = -1\n\nwhile res < 0 && b <= r\n if nod(a, b) == 1\n res = 0\n else\n b += 1\n end\nend\n\nwhile res == 0 && c <=r\n if nod(b,c) == 1 && nod(a,c) > 1\n res = 1\n else\n c += 1\n end\nend\n\nif res < 0\n puts -1\nelse\n puts \"#{a} #{b} #{c}\"\nend\n\n\n"}, {"source_code": "=begin\ndata = gets.chomp.split(/\\s/).map {|n| n.to_i}\n#p data\nputs data.inject(:+) / data.length\n=end\n\n\ndef nod(x,y)\n if x == y\n return x\n end\n if x == 0\n return y\n end\n if y == 0\n return x\n end\n if x > y\n return nod(y, x % y)\n else\n return nod(x, y % x)\n end\nend\n\n\ndata = gets.chomp.split(/\\s/).map{|n| n.to_i}\nl = data[0]\nr = data[1]\n\n\na = l\nb = a + 1\nc = b + 1\nres = -1\n\nwhile res < 0 && b <= r\n if nod(a, b) == 1\n res = 0\n else\n b += 1\n end\nend\n\nwhile res == 0 && c <=r\n if nod(b,c) == 1 && nod(a,c) > 1\n res = 1\n else\n c += 1\n end\nend\n\nif res <= 0\n puts -1\nelse\n puts \"#{a} #{b} #{c}\"\nend\n\n\n"}, {"source_code": "=begin\ndata = gets.chomp.split(/\\s/).map {|n| n.to_i}\n#p data\nputs data.inject(:+) / data.length\n=end\n\n\ndef nod(x,y)\n if x == y\n return x\n end\n if x == 0\n return y\n end\n if y == 0\n return x\n end\n if x > y\n return nod(y, x % y)\n else\n return nod(x, y % x)\n end\nend\n\n\ndata = gets.chomp.split(/\\s/).map{|n| n.to_i}\nl = data[0]\nr = data[1]\n\n\na = l\nb = a + 1\n\nres = -1\n\nwhile res < 0 && b <= r\n if nod(a, b) == 1\n res = 0\n else\n b += 1\n end\nend\n\nc = b + 1\n\nwhile res == 0 && c <=r\n if nod(b,c) == 1 && nod(a,c) > 1\n res = 1\n else\n c += 1\n end\nend\n\nif res <= 0\n puts \"#{-1}\"\nelse\n puts \"#{a} #{b} #{c}\"\nend\n\n\n"}, {"source_code": "=begin\ndata = gets.chomp.split(/\\s/).map {|n| n.to_i}\n#p data\nputs data.inject(:+) / data.length\n=end\n\n\ndef nod(x,y)\n if x == y\n return x\n end\n if x == 0\n return y\n end\n if y == 0\n return x\n end\n if x > y\n return nod(y, x % y)\n else\n return nod(x, y % x)\n end\nend\n\n\ndata = gets.chomp.split(/\\s/).map{|n| n.to_i}\nl = data[0]\nr = data[1]\n\n\na = l\nb = a + 1\nc = b + 1\nres = -1\nwhile res < 0 && c <=r\n if nod(a,b) == 1 && nod(b,c) == 1 && nod(a,c) > 1\n res = 1\n else\n c += 1\n end\nend\n\nif res < 0\n puts -1\nelse\n puts \"#{a} #{b} #{c}\"\nend\n\n\n"}, {"source_code": "#require 'prime'\ndef coprime?(a, b)\n a.gcd(b).equal?(1)\nend\nl, r = gets.chomp.split.map(&:to_i)\nfor i in l...r\n a = i\n b = 0\n c = 0\n for j in (i + 1)..r\n if coprime?(a, j) && b == 0\n b = j\n elsif coprime?(b, j) && c == 0\n c = j if c == 0\n end\n c = 0 if coprime?(a, c)\n end\n break if coprime?(a, c) == false\nend\nif a == 0 || b == 0 || c == 0\n puts -1\nelse\n puts [a, b, c].join(\" \")\nend\n#p Prime.prime?(3)\n#p coprime?(3, 4)\n"}, {"source_code": "#require 'prime'\ndef coprime?(a, b)\n a.gcd(b).equal?(1)\nend\nl, r = gets.chomp.split.map(&:to_i)\na = 0\nb = 0\nc = 0\nfor i in l...r\n a = i\n b = 0\n c = 0\n for j in (i + 1)..r\n b = j if coprime?(a, j) && b == 0\n# print \"a = #{a}, b = #{b}, c = #{c}\\n\"\n for k in (j + 1)..r\n if coprime?(b, k) && c == 0 && (coprime?(a, c) != true)\n c = k\n print \"a = #{a}, b = #{b}, c = #{c}\\n\"\n break\n end\n end\n break if c != 0\n b = 0\n# print \"a = #{a}, b = #{b}, c = #{c}\\n\"\n end\n break if coprime?(a, c) == false\nend\nif a == 0 || b == 0 || c == 0\n puts -1\nelse\n puts [a, b, c].join(\" \")\nend\n#p Prime.prime?(3)\n#p coprime?(3, 4)\np coprime?(900000000000000010, 900000000000000011)\np coprime?(900000000000000011, 900000000000000012)\np coprime?(900000000000000010, 900000000000000012)\n\n"}, {"source_code": "#require 'prime'\ndef coprime?(a, b)\n a.gcd(b).equal?(1)\nend\nl, r = gets.chomp.split.map(&:to_i)\na = 0\nb = 0\nc = 0\nfor i in l...r\n a = i\n b = 0\n c = 0\n for j in (i + 1)..r\n b = j if coprime?(a, j) && b == 0\n# print \"a = #{a}, b = #{b}, c = #{c}\\n\"\n for k in (j + 1)..r\n if coprime?(b, k) && c == 0\n c = k if c == 0\n# print \"a = #{a}, b = #{b}, c = #{c}\\n\"\n end\n c = 0 if coprime?(a, c)\n end\n b = 0 if coprime?(a, c) || c == 0\n# print \"a = #{a}, b = #{b}, c = #{c}\\n\"\n end\n break if coprime?(a, c) == false\nend\nif a == 0 || b == 0 || c == 0\n puts -1\nelse\n puts [a, b, c].join(\" \")\nend\n#p Prime.prime?(3)\n#p coprime?(3, 4)\n"}, {"source_code": "#require 'prime'\ndef coprime?(a, b)\n a.gcd(b).equal?(1)\nend\nl, r = gets.chomp.split.map(&:to_i)\nfor i in l...r\n a = i\n b = 0\n c = 0\n for j in (i + 1)..r\n b = j if coprime?(a, j) && b == 0\n# print \"a = #{a}, b = #{b}, c = #{c}\\n\"\n for k in (j + 1)..r\n if coprime?(b, k) && c == 0\n c = k if c == 0\n# print \"a = #{a}, b = #{b}, c = #{c}\\n\"\n end\n c = 0 if coprime?(a, c)\n end\n end\n break if coprime?(a, c) == false\nend\nif a == 0 || b == 0 || c == 0\n puts -1\nelse\n puts [a, b, c].join(\" \")\nend\n#p Prime.prime?(3)\n#p coprime?(3, 4)\n"}, {"source_code": "#require 'prime'\ndef coprime?(a, b)\n a.gcd(b).equal?(1)\nend\nl, r = gets.chomp.split.map(&:to_i)\nfor i in l...r\n a = i\n b = 0\n c = 0\n for j in (i + 1)..r\n b = j if coprime?(a, j) && b == 0\n# print \"a = #{a}, b = #{b}, c = #{c}\\n\"\n for k in (j + 1)..r\n if coprime?(b, k) && c == 0\n c = k if c == 0\n# print \"a = #{a}, b = #{b}, c = #{c}\\n\"\n end\n c = 0 if coprime?(a, c)\n end\n b = 0 if coprime?(a, c) || c == 0\n end\n break if coprime?(a, c) == false\nend\nif a == 0 || b == 0 || c == 0\n puts -1\nelse\n puts [a, b, c].join(\" \")\nend\n#p Prime.prime?(3)\n#p coprime?(3, 4)\n"}], "src_uid": "6c1ad1cc1fbecff69be37b1709a5236d"} {"nl": {"description": "The only difference between easy and hard versions is the constraints.Polycarp has to write a coursework. The coursework consists of $$$m$$$ pages.Polycarp also has $$$n$$$ cups of coffee. The coffee in the $$$i$$$-th cup has $$$a_i$$$ caffeine in it. Polycarp can drink some cups of coffee (each one no more than once). He can drink cups in any order. Polycarp drinks each cup instantly and completely (i.e. he cannot split any cup into several days).Surely, courseworks are not usually being written in a single day (in a perfect world of Berland, at least). Some of them require multiple days of hard work.Let's consider some day of Polycarp's work. Consider Polycarp drinks $$$k$$$ cups of coffee during this day and caffeine dosages of cups Polycarp drink during this day are $$$a_{i_1}, a_{i_2}, \\dots, a_{i_k}$$$. Then the first cup he drinks gives him energy to write $$$a_{i_1}$$$ pages of coursework, the second cup gives him energy to write $$$max(0, a_{i_2} - 1)$$$ pages, the third cup gives him energy to write $$$max(0, a_{i_3} - 2)$$$ pages, ..., the $$$k$$$-th cup gives him energy to write $$$max(0, a_{i_k} - k + 1)$$$ pages.If Polycarp doesn't drink coffee during some day, he cannot write coursework at all that day.Polycarp has to finish his coursework as soon as possible (spend the minimum number of days to do it). Your task is to find out this number of days or say that it is impossible.", "input_spec": "The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \\le n \\le 100$$$, $$$1 \\le m \\le 10^4$$$) \u2014 the number of cups of coffee and the number of pages in the coursework. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\le a_i \\le 100$$$), where $$$a_i$$$ is the caffeine dosage of coffee in the $$$i$$$-th cup.", "output_spec": "If it is impossible to write the coursework, print -1. Otherwise print the minimum number of days Polycarp needs to do it.", "sample_inputs": ["5 8\n2 3 1 1 2", "7 10\n1 3 4 2 1 4 2", "5 15\n5 5 5 5 5", "5 16\n5 5 5 5 5", "5 26\n5 5 5 5 5"], "sample_outputs": ["4", "2", "1", "2", "-1"], "notes": "NoteIn the first example Polycarp can drink fourth cup during first day (and write $$$1$$$ page), first and second cups during second day (and write $$$2 + (3 - 1) = 4$$$ pages), fifth cup during the third day (and write $$$2$$$ pages) and third cup during the fourth day (and write $$$1$$$ page) so the answer is $$$4$$$. It is obvious that there is no way to write the coursework in three or less days in this test.In the second example Polycarp can drink third, fourth and second cups during first day (and write $$$4 + (2 - 1) + (3 - 2) = 6$$$ pages) and sixth cup during second day (and write $$$4$$$ pages) so the answer is $$$2$$$. It is obvious that Polycarp cannot write the whole coursework in one day in this test.In the third example Polycarp can drink all cups of coffee during first day and write $$$5 + (5 - 1) + (5 - 2) + (5 - 3) + (5 - 4) = 15$$$ pages of coursework.In the fourth example Polycarp cannot drink all cups during first day and should drink one of them during the second day. So during first day he will write $$$5 + (5 - 1) + (5 - 2) + (5 - 3) = 14$$$ pages of coursework and during second day he will write $$$5$$$ pages of coursework. This is enough to complete it.In the fifth example Polycarp cannot write the whole coursework at all, even if he will drink one cup of coffee during each day, so the answer is -1."}, "positive_code": [{"source_code": "n, m = gets.split.map(&:to_i)\na = gets.split.map(&:to_i).sort.reverse\n\nputs (1..n).bsearch { |day|\n\t\tminus, cnt = 0, 0\n\t\t(0...n).sum { |i|\n\t\t\tres = [0, a[i] - minus].max\n\t\t\tcnt += 1\n\t\t\tif cnt == day\n\t\t\t\tminus += 1\n\t\t\t\tcnt = 0\n\t\t\tend\n\t\t\tres\n\t\t} >= m\n } || -1\n"}, {"source_code": "DBG = !true\nn,m = gets.split.map{|z| z.to_i}\na = gets.split.map{|z| z.to_i}\n\ndef f(n)\n return (n-1)*n/2\nend\ndef g(n,t)\n if DBG\n puts \"n #{n} t #{t} fnt1 #{f(n/t+1)} fnt #{f(n/t)}\"\n end\n return (n%t)*f(n/t + 1) + (t - n%t)*f(n/t)\nend\n\na.sort_by!{|z| -z} # decreasing order\nasum = [a[0]]\nfor i in 1...n\n asum << asum[i-1] + a[i]\nend\nif DBG\n puts \"n #{n} m #{m} asum #{asum}\"\nend\nfor t in 1..n\n for i in 1..n\n if asum[i-1] - g(i,t) >= m\n puts \"#{t}\"\n exit 0\n end\n end\nend\nputs \"#{-1}\"\n"}], "negative_code": [], "src_uid": "acb8a57c8cfdb849a55fa65aff86628d"} {"nl": {"description": " *The two images are equivalent, feel free to use either one.", "input_spec": "The input contains a single integer $$$a$$$ ($$$-100 \\le a \\le 100$$$).", "output_spec": "Output the result \u2013 an integer number.", "sample_inputs": ["1"], "sample_outputs": ["1"], "notes": null}, "positive_code": [{"source_code": "x = gets.to_i\r\np 2 - x * x"}, {"source_code": "puts (2-gets.to_i**2)"}], "negative_code": [], "src_uid": "f76005f888df46dac38b0f159ca04d5f"} {"nl": {"description": "Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity.There are n columns of toy cubes in the box arranged in a line. The i-th column contains ai cubes. At first, the gravity in the box is pulling the cubes downwards. When Chris switches the gravity, it begins to pull all the cubes to the right side of the box. The figure shows the initial and final configurations of the cubes in the box: the cubes that have changed their position are highlighted with orange. Given the initial configuration of the toy cubes in the box, find the amounts of cubes in each of the n columns after the gravity switch!", "input_spec": "The first line of input contains an integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009100), the number of the columns in the box. The next line contains n space-separated integer numbers. The i-th number ai (1\u2009\u2264\u2009ai\u2009\u2264\u2009100) denotes the number of cubes in the i-th column.", "output_spec": "Output n integer numbers separated by spaces, where the i-th number is the amount of cubes in the i-th column after the gravity switch.", "sample_inputs": ["4\n3 2 1 2", "3\n2 3 8"], "sample_outputs": ["1 2 2 3", "2 3 8"], "notes": "NoteThe first example case is shown on the figure. The top cube of the first column falls to the top of the last column; the top cube of the second column falls to the top of the third column; the middle cube of the first column falls to the top of the second column.In the second example case the gravity switch does not change the heights of the columns."}, "positive_code": [{"source_code": "n = gets.to_i\n\n#puts n\n\ns = gets.split.map(&:to_i)\n\ns = s.sort\n\nn.times do\n print s.shift\n print s.length == 0 ? \"\\n\" : \" \"\nend\n"}, {"source_code": "n = gets.to_i\nputs gets.split(' ',n).map(&:to_i).sort.map(&:to_s).join(' ')"}, {"source_code": "gets; puts gets.split.map(&:to_i).sort.join(' ')"}, {"source_code": "gets\nputs gets.split.map(&:to_i).sort*' '"}, {"source_code": "g = gets.chomp\narr = gets.chomp.split(\" \").map {|x| x.to_i}.sort.map {|x| x.to_s}.join(' ')\nputs arr\n"}, {"source_code": "gets\nputs gets.chomp.split.map(&:to_i).sort\n"}, {"source_code": "gets\nputs gets.split.map(&:to_i).sort"}, {"source_code": "gets\nputs gets.split.map(&:to_i).sort\n"}, {"source_code": "n=gets.to_i;puts gets.split.map(&:to_i).sort"}, {"source_code": "gets\nputs gets.split.map(&:to_i).sort\n"}, {"source_code": "gets\nputs gets.split.map(&:to_i).sort\n"}, {"source_code": "gets\nputs gets.split.map(&:to_i).sort.join(\" \")"}, {"source_code": "gets\nputs gets.split.map(&:to_i).sort"}, {"source_code": "#$stdin.reopen('/home/chen/Desktop/input.txt', 'r')\n\n\nn= gets.to_i\n\narray = gets.split.map(&:to_i).sort\n\nflag = 1\narray.each do |e|\n\t\n\tif flag!=0\n\t\tprint e\n\t\tflag = 0\n\telse\n\t\tprint(\" #{e}\")\n\tend\nend\nputs\n"}, {"source_code": "n = gets.strip.to_i\narr = gets.strip.split(\" \").map(&:to_i)\narr.sort!\nputs arr.join(\" \")"}, {"source_code": "n = gets.to_i\nputs gets.split.map(&:to_i).sort"}, {"source_code": "require 'matrix'\n\n$stdin.readline\nf = $stdin.readline.split.map(&:to_i)\nm = f.count\n\nn = f.max\ncols = f.collect do |c| \n _ones = c\n _zeros = n-c\n _t = [1]*(_ones)\n _t = _t + (_zeros>0 ? [0]*_zeros : [])\n _t\nend\n\n#puts \"cols=#{cols.inspect}\"\n\nbox = Matrix.columns(cols)\n\nrows = []\n\n(0...n).each {|i| rows << box.row(i).to_a}\n\n#puts \"rows=#{rows.inspect}\"\n\ncompact_rows = rows.collect do |row|\n _t = row - [0]\n _n = _t.count\n _zeros = m - _n\n if _zeros>0\n _t = ([0]*_zeros) + _t\n end\n _t\nend\n\n#puts \"compact_rows=#{compact_rows.inspect}\"\n\nbox2 = Matrix.rows(compact_rows)\n\n#p box2\n\n(0...m).each do |i| \n _t = (box2.column(i).to_a - [0]).count\n print \"#{_t} \" if _t>0\nend"}, {"source_code": "gets\nputs gets.split.map(&:to_i).sort.join(' ')\n"}, {"source_code": "gets\nputs gets.split.map(&:to_i).sort.join(\" \")\n"}, {"source_code": "n = gets.to_i \narr = gets.split(\" \").map(&:to_i) \narr.sort! \nputs arr.join(' ')"}, {"source_code": "gets\ngets.split.map { |x| x.to_i }.sort.each { |x| print \"#{x} \" }\n"}, {"source_code": "n = gets.to_i\na = gets.split(' ').map { |e| e = e.to_i }\n\na.sort!\nputs a.join(' ')"}, {"source_code": "class A\n def initialize\n n = gets.chomp.to_i\n list = gets.chomp.split(' ').map(&:to_i)\n\n puts list.sort.join(' ')\n end\nend\n\nA.new"}, {"source_code": "gets\nputs gets.split.map(&:to_i).sort\n"}, {"source_code": "n = gets.to_i\nputs gets.split(' ').sort_by{ |x| x.to_i}.join(' ')\n"}, {"source_code": "gets\nputs gets.split.map(&:to_i).sort\n"}, {"source_code": "gets\nputs gets.split.map(&:to_i).sort*' '"}, {"source_code": "gets\nputs gets.split.map(&:to_i).sort"}, {"source_code": "gets\nputs (gets.split.map{|e| e.to_i}.sort)*\" \"\n\n"}, {"source_code": "gets\ncols = gets.split.map(&:to_i)\n\nrows = (1..cols.max).map { |height| cols.count { |col| col >= height } }\n\nans = (1..cols.size).map { |wid| rows.count { |row| row >= wid } }.reverse\n\nputs ans.join ' '\n"}, {"source_code": "n = gets.chomp.to_i\narr = gets.chomp.split.map(&:to_i)\n\nputs arr.sort.join(' ')\n"}, {"source_code": "gets\na = gets.split.map { |e| e.to_i }\na.sort!\na.each do |i|\n\tprint \"#{i} \"\nend"}, {"source_code": "puts [*$<][1].split.map(&:to_i).sort.join ' '\n"}, {"source_code": "gets\nputs gets.split.map(&:to_i).sort"}, {"source_code": "gets;puts gets.split.map(&:to_i).sort"}, {"source_code": "gets;puts(gets.split.map(&:to_i).sort*' ')"}, {"source_code": "amount = gets.chomp\nn = gets.chomp\ncolumns = n.split\n\nfor x in (1..amount.to_i)\n\tfor i in (1..amount.to_i-1)\n\t\tif columns[i-1].to_i > columns[i].to_i\n\t\t\ttemp = columns[i].to_i\n\t\t\tcolumns[i] = columns[i-1].to_i\n\t\t\tcolumns[i-1] = temp\n\t\tend\n\tend\nend\n\ncolumns.each do |column|\n\tprint column\n\tprint \" \"\nend"}, {"source_code": "#!/usr/bin/ruby\n\nn = gets.chomp.to_i\na = gets.chomp.split(\" \")\n\na.each do |i|\n i = i.to_i\nend\n\nisSwap = true\nwhile isSwap do\n isSwap = false\n for i in 0..(n-1)\n if a[i].to_i > a[i+1].to_i then\n a[i], a[i+1] = a[i+1], a[i]\n isSwap = true\n end\n end\nend\n\na.each do |i|\n print \"#{i} \"\nend\n"}, {"source_code": "gets\nputs gets.split.map(&:to_i).sort\n"}, {"source_code": "STDIN.readline\nprint STDIN.readline.split.map{ |x| x.to_i }.sort.join(' ')\n"}, {"source_code": "gets\nputs gets.split.map(&:to_i).sort"}, {"source_code": "gets\nputs gets.split.map(&:to_i).sort.join(\" \")\n"}, {"source_code": "gets\nputs gets.split.map(&:to_i).sort"}, {"source_code": "gets\nputs gets.split.map(&:to_i).sort.join ' '"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nputs a.sort.join(\" \")"}, {"source_code": "gets\nputs gets.chomp.split(\" \").map(&:to_i).sort.join(\" \")"}, {"source_code": "gets; puts gets.split.map(&:to_i).sort.join(' ')"}, {"source_code": "gets\nputs gets.split.map(&:to_i).sort.join(\" \")"}, {"source_code": "b = gets\na = gets.split(\" \").map(&:to_i).sort\nresult = a.join(\" \")\nprint result"}, {"source_code": "columns = gets.to_i\nboard = gets.split.map(&:to_i)\nboard.sort!\n\nresult = \"\"\nfor i in (0..board.length-1)\n\tif i == board.length-1\n\t\tresult = result + board[i].to_s\n\telse\n\t\tresult = result + board[i].to_s + \" \"\n\tend\nend\n\nputs result"}, {"source_code": "n=gets.to_i;puts gets.split.map(&:to_i).sort"}, {"source_code": "# http://codeforces.com/problemset/problem/405/A\n\nn = $stdin.gets.chomp.to_i\na = $stdin.gets.chomp.split.map { |v| v.to_i }\n\na.sort!.each { |e| print \"#{e} \"}\nprint \"\\n\"\n"}, {"source_code": "n=gets.to_i\na=gets\na=a.split(' ')\nfor i in 0..n-1\n a[i]=a[i].to_i\nend\na=a.sort\nfor i in 0..n-1\n print\"#{a[i]} \"\nend\n\n"}, {"source_code": "gets\nputs gets.split.map(&:to_i).sort\n"}, {"source_code": "gets\nputs gets.split(' ').map(&:to_i).sort.join(' ')\n"}, {"source_code": "gets\nputs gets.split.map(&:to_i).sort"}, {"source_code": "def read_next_line\n gets.chomp.split.map(&:to_i)\nend\n\ngets\nputs read_next_line.sort * ' '"}, {"source_code": "gets\nputs gets.split.map(&:to_i).sort\n"}, {"source_code": "gets\ngets.chomp.split.map(&:to_i).sort.map{|x|print x.to_s+ ' '}"}, {"source_code": "n = gets().to_i\narr = gets.split.map(&:to_i)\narr = arr.sort\nfor i in 0..n-1\n print arr[i].to_s+\" \"\nend\n"}, {"source_code": "gets\nputs gets.split.map(&:to_i).sort\n"}], "negative_code": [{"source_code": "gets\nputs gets.split.sort.join(\" \")\n"}, {"source_code": "n = gets.to_i\np gets.split.map(&:to_i).sort\n"}, {"source_code": "n = gets.to_i\nputs gets.split(' ').sort.join(' ')\n"}, {"source_code": "puts gets.split.map(&:to_i).sort.join(\" \")\n"}, {"source_code": "gets\nputs gets.chomp.split(\" \").sort.join(\" \")"}, {"source_code": "gets; gets.split.map(&:to_i).sort.join(' ')"}, {"source_code": "n=gets.to_i\na=gets\na=a.split(' ').sort\nfor i in 0..n-1\n print \"#{a[i]} \"\nend\n"}, {"source_code": "gets\ngets.chomp.split.sort.map{|x|print x+ ' '}"}, {"source_code": "gets\nprint gets.chomp.split.sort"}], "src_uid": "ae20712265d4adf293e75d016b4b82d8"} {"nl": {"description": "During the breaks between competitions, top-model Izabella tries to develop herself and not to be bored. For example, now she tries to solve Rubik's cube 2x2x2.It's too hard to learn to solve Rubik's cube instantly, so she learns to understand if it's possible to solve the cube in some state using 90-degrees rotation of one face of the cube in any direction.To check her answers she wants to use a program which will for some state of cube tell if it's possible to solve it using one rotation, described above.Cube is called solved if for each face of cube all squares on it has the same color.https://en.wikipedia.org/wiki/Rubik's_Cube", "input_spec": "In first line given a sequence of 24 integers ai (1\u2009\u2264\u2009ai\u2009\u2264\u20096), where ai denotes color of i-th square. There are exactly 4 occurrences of all colors in this sequence.", "output_spec": "Print \u00abYES\u00bb (without quotes) if it's possible to solve cube using one rotation and \u00abNO\u00bb (without quotes) otherwise.", "sample_inputs": ["2 5 4 6 1 3 6 2 5 5 1 2 3 5 3 1 1 2 4 6 6 4 3 4", "5 3 5 3 2 5 2 5 6 2 6 2 4 4 4 4 1 1 1 1 6 3 6 3"], "sample_outputs": ["NO", "YES"], "notes": "NoteIn first test case cube looks like this: In second test case cube looks like this: It's possible to solve cube by rotating face with squares with numbers 13, 14, 15, 16."}, "positive_code": [{"source_code": "POSSIBLES = [\n [[1, 2], [18, 20], [11, 12], [13, 15]],\n [[3, 4], [17, 19], [9, 10], [14, 16]],\n [[2, 4], [6, 8], [10, 12], [21, 23]],\n [[1, 3], [5, 7], [9, 11], [22, 24]],\n [[13, 14], [5, 6], [17, 18], [21, 22]],\n [[15, 16], [7, 8], [19, 20], [23, 24]],\n]\n\n\nFACES = [\n (1..4).to_a,\n (5..8).to_a,\n (9..12).to_a,\n (13..16).to_a,\n (17..20).to_a,\n (21..24).to_a,\n]\n\ndef check_solved(c)\n FACES.each do |face|\n return false unless face.map { |f| c[f] }.uniq.size == 1\n end\n true\nend\n\ndef solve(cube)\n # [[[2, 4], [6, 8], [10, 12], [21, 23]]].each_with_index do |possib|\n POSSIBLES.each_with_index do |possib|\n face_colors = possib.map { |p| cube[p.first] == cube[p.last] }\n next if face_colors.include?(false)\n colors = possib.map { |p| cube[p.first] }\n [possib.rotate(1), possib.rotate(-1)].each do |rot|\n c = cube.dup\n rot.each_with_index do |curr, i|\n c[curr.first] = colors[i]\n c[curr.last] = colors[i]\n end\n if check_solved(c)\n return \"YES\"\n end\n end\n end\n return \"NO\"\nend\n\n\n\ncube = {}\nvals = gets.strip.split.map(&:to_i)\n\nvals.each_with_index do |v, i|\n cube[i + 1] = v\nend\n\nputs solve(cube)\n"}, {"source_code": "def rot(a, t)\n b = a.dup\n t.each{|v|\n (0...v.size).each{|i|\n b[v[i-1]] = a[v[i]]\n }\n }\n return b\nend\n\ndef check(a)\n 6.times.map{|x| x*4}.all?{|x| (x...x+4).map{|i| a[i+1]}.uniq.size == 1}\nend\n\nlist = [\n [[2,6,10,23], [4,8,12,21], [18,17,19,20]],\n [[23,10,6,2], [21,12,8,4], [20,19,17,18]],\n [[1,18,12,15], [2,20,11,13], [22,21,23,24]],\n [[15,12,18,1], [13,11,20,2], [24,23,21,22]],\n [[1,2,4,3], [13,21,17,5], [14,22,18,6]],\n [[3,4,2,1], [5,17,21,13], [6,18,22,14]]\n]\n\n\ncube = [0] + gets.split.map(&:to_i)\n\n\nif list.any?{|l| check(rot(cube, l))}\n puts \"YES\"\nelse\n puts \"NO\"\nend"}, {"source_code": "def judge(cube)\n 6.times do |i|\n if !(cube[4 * i] == cube[4 * i + 1] && cube[4 * i + 1] == cube[4 * i + 2] && cube[4 * i + 2] == cube[4 * i + 3])\n return false\n end\n end\n return true\nend\n\na1 = [0,2,4,6,8,10,23,21]\nb1 = [1,3,5,7,9,11,22,20]\na2 = [12,13,4,5,16,17,20,21]\nb2 = [14,15,6,7,18,19,22,23]\na3 = [2,3,16,18,9,8,15,13]\nb3 = [0,1,17,19,11,10,14,12]\n\ncube = gets.split.map(&:to_i)\nans = false\n\ntmp = Array.new(a1)\ntmp.rotate!(2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[a1[i]] = cube[tmp[i]]\nend\nans |= judge(cube2)\n\ntmp = Array.new(b1)\ntmp.rotate!(2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[b1[i]] = cube[tmp[i]]\nend\nans |= judge(cube2)\n\ntmp = Array.new(a2)\ntmp.rotate!(2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[a2[i]] = cube[tmp[i]]\nend\nans |= judge(cube2)\n\ntmp = Array.new(b2)\ntmp.rotate!(2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[b2[i]] = cube[tmp[i]]\nend\nans |= judge(cube2)\n\ntmp = Array.new(a3)\ntmp.rotate!(2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[a3[i]] = cube[tmp[i]]\nend\nans |= judge(cube2)\n\ntmp = Array.new(b3)\ntmp.rotate!(2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[b3[i]] = cube[tmp[i]]\nend\nans |= judge(cube2)\n\n\ntmp = Array.new(a1)\ntmp.rotate!(-2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[a1[i]] = cube[tmp[i]]\nend\nans |= judge(cube2)\n\ntmp = Array.new(b1)\ntmp.rotate!(-2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[b1[i]] = cube[tmp[i]]\nend\nans |= judge(cube2)\n\ntmp = Array.new(a2)\ntmp.rotate!(-2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[a2[i]] = cube[tmp[i]]\nend\nans |= judge(cube2)\n\ntmp = Array.new(b2)\ntmp.rotate!(-2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[b2[i]] = cube[tmp[i]]\nend\nans |= judge(cube2)\n\ntmp = Array.new(a3)\ntmp.rotate!(-2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[a3[i]] = cube[tmp[i]]\nend\nans |= judge(cube2)\n\ntmp = Array.new(b3)\ntmp.rotate!(-2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[b3[i]] = cube[tmp[i]]\nend\nans |= judge(cube2)\n\nputs ans ? \"YES\" : \"NO\""}, {"source_code": "def solve(a)\n\ttag = true\n\tj = 1\n\twhile(j<=21 && tag)\n\t\tif(a[j-1] == a[j]&& a[j]==a[j+1]&&a[j+1]==a[j+2])\n\t\t\tj += 4\n\t\t\tnext\n\t\tend\n\t\ttag = false\n\tend\n \treturn tag\nend\n\ntag = false\nn = gets.split(' ').map(&:to_i)\na = n.dup\ntemp1 = a[1-1]\ntemp2 = a[3-1]\na[1-1] = a[24-1]\na[3-1] = a[22-1]\na[24-1] = a[9-1] \na[22-1] = a[11-1]\na[9-1] = a[5-1]\na[11-1] = a[7-1]\na[5-1] = temp1\na[7-1] = temp2\nif solve a\n\ttag = true\nend\na = n.dup\ntemp1 = a[1-1]\ntemp2 = a[3-1]\na[1-1] = a[5-1]\na[3-1] = a[7-1]\na[5-1] = a[9-1] \na[7-1] = a[11-1]\na[9-1] = a[24-1]\na[11-1] = a[22-1]\na[24-1] = temp1\na[22-1] = temp2\nif solve a\n\ttag = true\nend\n\n\na = n.dup\ntemp1 = a[2-1]\ntemp2 = a[4-1]\na[2-1] = a[23-1]\na[4-1] = a[21-1]\na[23-1] = a[10-1] \na[21-1] = a[12-1]\na[10-1] = a[6-1]\na[12-1] = a[8-1]\na[6-1] = temp1\na[8-1] = temp2\nif solve a\n\ttag = true\nend\na = n.dup\ntemp1 = a[2-1]\ntemp2 = a[4-1]\na[2-1] = a[6-1]\na[4-1] = a[8-1]\na[6-1] = a[10-1] \na[8-1] = a[12-1]\na[10-1] = a[23-1]\na[12-1] = a[21-1]\na[23-1] = temp1\na[21-1] = temp2\nif solve a\n\ttag = true\nend\n\n\na = n.dup\ntemp1 = a[5-1]\ntemp2 = a[6-1]\na[5-1] = a[13-1]\na[6-1] = a[14-1]\na[13-1] = a[21-1] \na[14-1] = a[22-1]\na[21-1] = a[17-1]\na[22-1] = a[18-1]\na[17-1] = temp1\na[18-1] = temp2\nif solve a\n\ttag = true\nend\na = n.dup\ntemp1 = a[5-1]\ntemp2 = a[6-1]\na[5-1] = a[17-1]\na[6-1] = a[18-1]\na[17-1] = a[21-1] \na[18-1] = a[22-1]\na[21-1] = a[13-1]\na[22-1] = a[14-1]\na[13-1] = temp1\na[14-1] = temp2\nif solve a\n\ttag = true\nend\n\n\n\n\na = n.dup\ntemp1 = a[7-1]\ntemp2 = a[8-1]\na[7-1] = a[15-1]\na[8-1] = a[16-1]\na[15-1] = a[23-1] \na[16-1] = a[24-1]\na[23-1] = a[19-1]\na[24-1] = a[20-1]\na[19-1] = temp1\na[20-1] = temp2\nif solve a\n\ttag = true\nend\na = n.dup\ntemp1 = a[7-1]\ntemp2 = a[8-1]\na[7-1] = a[19-1]\na[8-1] = a[20-1]\na[19-1] = a[23-1] \na[20-1] = a[24-1]\na[23-1] = a[15-1]\na[24-1] = a[16-1]\na[15-1] = temp1\na[16-1] = temp2\nif solve a\n\ttag = true\nend\n\n\na = n.dup\ntemp1 = a[18-1]\ntemp2 = a[20-1]\na[18-1] = a[1-1]\na[20-1] = a[2-1]\na[1-1] = a[15-1] \na[2-1] = a[13-1]\na[13-1] = a[11-1]\na[15-1] = a[12-1]\na[12-1] = temp1\na[11-1] = temp2\nif solve a\n\ttag = true\nend\na = n.dup\ntemp1 = a[18-1]\ntemp2 = a[20-1]\na[18-1] = a[12-1]\na[20-1] = a[11-1]\na[11-1] = a[13-1] \na[12-1] = a[15-1]\na[15-1] = a[1-1]\na[13-1] = a[2-1]\na[1-1] = temp1\na[2-1] = temp2\nif solve a\n\ttag = true\nend\n\n\n\n\n\na = n.dup\ntemp1 = a[17-1]\ntemp2 = a[19-1]\na[17-1] = a[10-1]\na[19-1] = a[9-1]\na[9-1] = a[14-1] \na[10-1] = a[16-1]\na[16-1] = a[3-1]\na[14-1] = a[4-1]\na[3-1] = temp1\na[4-1] = temp2\nif solve a\n\ttag = true\nend\na = n.dup\ntemp1 = a[17-1]\ntemp2 = a[19-1]\na[17-1] = a[3-1]\na[19-1] = a[4-1]\na[3-1] = a[16-1] \na[4-1] = a[14-1] \na[14-1] = a[9-1]\na[16-1] = a[10-1] \na[10-1] = temp1\na[9-1] = temp2\nif solve a\n\ttag = true\nend\nif tag\n\tprint('YES')\nelse\n\tprint('NO')\nend\n"}], "negative_code": [{"source_code": "\nPOSSIBLES = [\n [[1, 2], [18, 20], [11, 12], [13, 15]],\n [[3, 4], [17, 19], [9, 10], [14, 16]],\n [[2, 4], [6, 8], [10, 12], [21, 23]],\n [[1, 3], [5, 7], [9, 11], [22, 24]],\n]\n\ndef check_solved(c)\n POSSIBLES.each do |pp|\n face_colors = pp.map { |p| c[p.first] == c[p.last] }\n return false if face_colors.include?(false)\n end\n true\nend\n\ndef solve(cube)\n # [[[2, 4], [6, 8], [10, 12], [21, 23]]].each_with_index do |possib|\n POSSIBLES.each_with_index do |possib|\n face_colors = possib.map { |p| cube[p.first] == cube[p.last] }\n next if face_colors.include?(false)\n colors = possib.map { |p| cube[p.first] }\n [possib.rotate(1), possib.rotate(-1)].each do |rot|\n c = cube.dup\n rot.each_with_index do |curr, i|\n c[curr.first] = colors[i]\n c[curr.last] = colors[i]\n # c[curr.last] = colors[next_val.last]\n end\n if check_solved(c)\n return \"YES\"\n end\n end\n end\n return \"NO\"\nend\n\n\n\ncube = {}\nvals = gets.strip.split.map(&:to_i)\n\nvals.each_with_index do |v, i|\n cube[i + 1] = v\nend\n\nputs solve(cube)\n"}, {"source_code": "\nPOSSIBLES = [\n [[1, 2], [18, 20], [11, 12], [13, 15]],\n [[3, 4], [17, 19], [9, 10], [14, 16]],\n [[2, 4], [6, 8], [10, 12], [21, 23]],\n [[1, 3], [5, 7], [9, 11], [22, 24]],\n]\n\n\nFACES = [\n (1..4).to_a,\n (5..8).to_a,\n (9..12).to_a,\n (13..16).to_a,\n (17..20).to_a,\n (21..24).to_a,\n]\n\ndef check_solved(c)\n FACES.each do |face|\n return false unless face.map { |f| c[f] }.uniq.size == 1\n end\n true\nend\n\ndef solve(cube)\n # [[[2, 4], [6, 8], [10, 12], [21, 23]]].each_with_index do |possib|\n POSSIBLES.each_with_index do |possib|\n face_colors = possib.map { |p| cube[p.first] == cube[p.last] }\n next if face_colors.include?(false)\n colors = possib.map { |p| cube[p.first] }\n [possib.rotate(1), possib.rotate(-1)].each do |rot|\n c = cube.dup\n rot.each_with_index do |curr, i|\n c[curr.first] = colors[i]\n c[curr.last] = colors[i]\n end\n if check_solved(c)\n return \"YES\"\n end\n end\n end\n return \"NO\"\nend\n\n\n\ncube = {}\nvals = gets.strip.split.map(&:to_i)\n\nvals.each_with_index do |v, i|\n cube[i + 1] = v\nend\n\nputs solve(cube)\n"}, {"source_code": "def rot(a, t)\n b = a.dup\n t.each{|v|\n tmp = a[v[0]]\n (1...v.size).each{|i|\n a[v[i-1]] = a[v[i]]\n }\n a[v[-1]] = tmp\n }\n return b\nend\n\ndef check(a)\n 6.times.map{|x| x*4}.all?{|x| (x...x+4).map{|i| a[i+1]}.uniq.size == 1}\nend\n\nlist = [\n [[2,6,10,23], [4,8,12,21], [18,17,19,20]],\n [[23,10,6,2], [21,12,8,4], [20,19,17,18]],\n [[1,18,12,15], [2,20,11,13], [22,21,23,24]],\n [[15,12,18,1], [13,11,20,2], [24,23,21,22]],\n [[1,2,4,3], [13,21,17,5], [14,22,18,6]],\n [[3,4,2,1], [5,17,21,13], [6,18,22,14]]\n]\n\n\ncube = [0] + gets.split.map(&:to_i)\n\n\n\n\nif list.any?{|l| check(rot(cube, l))}\n puts \"YES\"\nelse\n puts \"NO\"\nend"}, {"source_code": "def judge(cube)\n 6.times do |i|\n if !(cube[4 * i] == cube[4 * i + 1] && cube[4 * i + 1] == cube[4 * i + 2] && cube[4 * i + 2] == cube[4 * i + 3])\n return false\n end\n end\n return true\nend\n\na1 = [0,2,4,6,8,10,23,21]\nb1 = [1,3,5,7,9,11,22,20]\na2 = [12,13,4,5,16,17,20,21]\nb2 = [14,15,6,7,18,19,22,23]\na3 = [2,3,16,18,9,8,15,13]\nb3 = [0,1,17,19,11,10,14,12]\n\ncube = gets.split.map(&:to_i)\nans = judge(cube)\ntmp = Array.new(a1)\ntmp.rotate!(2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[tmp[i]] = cube[a1[i]]\nend\nans |= judge(cube2)\ntmp = Array.new(b1)\ntmp.rotate!(2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[tmp[i]] = cube[b1[i]]\nend\nans |= judge(cube2)\ntmp = Array.new(a2)\ntmp.rotate!(2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[tmp[i]] = cube[a2[i]]\nend\nans |= judge(cube2)\ntmp = Array.new(b2)\ntmp.rotate!(2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[tmp[i]] = cube[b2[i]]\nend\nans |= judge(cube2)\ntmp = Array.new(a3)\ntmp.rotate!(2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[tmp[i]] = cube[a3[i]]\nend\nans |= judge(cube2)\ntmp = Array.new(b3)\ntmp.rotate!(2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[tmp[i]] = cube[b3[i]]\nend\nans |= judge(cube2)\nputs ans ? \"YES\" : \"NO\""}, {"source_code": "def judge(cube)\n 6.times do |i|\n if !(cube[4 * i] == cube[4 * i + 1] && cube[4 * i + 1] == cube[4 * i + 2] && cube[4 * i + 2] == cube[4 * i + 3])\n return false\n end\n end\n return true\nend\n\na1 = [0,2,4,6,8,10,23,21]\nb1 = [1,3,5,7,9,11,22,20]\na2 = [12,13,4,5,16,17,20,21]\nb2 = [14,15,6,7,18,19,22,23]\n\ncube = gets.split.map(&:to_i)\nans = judge(cube)\ntmp = Array.new(a1)\ntmp.rotate!(2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[tmp[i]] = cube[a1[i]]\nend\nans |= judge(cube2)\ntmp = Array.new(b1)\ntmp.rotate!(2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[tmp[i]] = cube[b1[i]]\nend\nans |= judge(cube2)\ntmp = Array.new(a2)\ntmp.rotate!(2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[tmp[i]] = cube[a2[i]]\nend\nans |= judge(cube2)\ntmp = Array.new(b2)\ntmp.rotate!(2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[tmp[i]] = cube[b2[i]]\nend\nans |= judge(cube2)\nputs ans ? \"YES\" : \"NO\""}, {"source_code": "def judge(cube)\n 6.times do |i|\n if !(cube[4 * i] == cube[4 * i + 1] && cube[4 * i + 1] == cube[4 * i + 2] && cube[4 * i + 2] == cube[4 * i + 3])\n return false\n end\n end\n return true\nend\n\na1 = [0,2,4,6,8,10,23,21]\nb1 = [1,3,5,7,9,11,22,20]\na2 = [12,13,4,5,16,17,20,21]\nb2 = [14,15,6,7,18,19,22,23]\na3 = [2,3,16,18,9,8,15,13]\nb3 = [0,1,17,19,11,10,14,12]\n\ncube = gets.split.map(&:to_i)\nans = judge(cube)\n\ntmp = Array.new(a1)\ntmp.rotate!(2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[tmp[i]] = cube[a1[i]]\nend\nans |= judge(cube2)\n\ntmp = Array.new(b1)\ntmp.rotate!(2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[tmp[i]] = cube[b1[i]]\nend\nans |= judge(cube2)\n\ntmp = Array.new(a2)\ntmp.rotate!(2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[tmp[i]] = cube[a2[i]]\nend\nans |= judge(cube2)\n\ntmp = Array.new(b2)\ntmp.rotate!(2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[tmp[i]] = cube[b2[i]]\nend\nans |= judge(cube2)\n\ntmp = Array.new(a3)\ntmp.rotate!(2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[tmp[i]] = cube[a3[i]]\nend\nans |= judge(cube2)\n\ntmp = Array.new(b3)\ntmp.rotate!(2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[tmp[i]] = cube[b3[i]]\nend\nans |= judge(cube2)\n\ntmp = Array.new(a1)\ntmp.rotate!(4)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[tmp[i]] = cube[a1[i]]\nend\nans |= judge(cube2)\n\ntmp = Array.new(b1)\ntmp.rotate!(4)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[tmp[i]] = cube[b1[i]]\nend\nans |= judge(cube2)\n\ntmp = Array.new(a2)\ntmp.rotate!(4)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[tmp[i]] = cube[a2[i]]\nend\nans |= judge(cube2)\n\ntmp = Array.new(b2)\ntmp.rotate!(4)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[tmp[i]] = cube[b2[i]]\nend\nans |= judge(cube2)\n\ntmp = Array.new(a3)\ntmp.rotate!(4)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[tmp[i]] = cube[a3[i]]\nend\nans |= judge(cube2)\n\ntmp = Array.new(b3)\ntmp.rotate!(4)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[tmp[i]] = cube[b3[i]]\nend\nans |= judge(cube2)\n\nputs ans ? \"YES\" : \"NO\""}, {"source_code": "def judge(cube)\n 6.times do |i|\n if !(cube[4 * i] == cube[4 * i + 1] && cube[4 * i + 1] == cube[4 * i + 2] && cube[4 * i + 2] == cube[4 * i + 3])\n return false\n end\n end\n return true\nend\n\na1 = [0,2,4,6,8,10,23,21]\nb1 = [1,3,5,7,9,11,22,20]\na2 = [12,13,4,5,16,17,20,21]\nb2 = [14,15,6,7,18,19,22,23]\na3 = [2,3,16,18,9,8,15,13]\nb3 = [0,1,17,19,11,10,14,12]\n\ncube = gets.split.map(&:to_i)\nans = judge(cube)\n\ntmp = Array.new(a1)\ntmp.rotate!(2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[a1[i]] = cube[tmp[i]]\nend\nans |= judge(cube2)\n\ntmp = Array.new(b1)\ntmp.rotate!(2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[b1[i]] = cube[tmp[i]]\nend\nans |= judge(cube2)\n\ntmp = Array.new(a2)\ntmp.rotate!(2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[a2[i]] = cube[tmp[i]]\nend\nans |= judge(cube2)\n\ntmp = Array.new(b2)\ntmp.rotate!(2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[b2[i]] = cube[tmp[i]]\nend\nans |= judge(cube2)\n\ntmp = Array.new(a3)\ntmp.rotate!(2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[a3[i]] = cube[tmp[i]]\nend\nans |= judge(cube2)\n\ntmp = Array.new(b3)\ntmp.rotate!(2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[b3[i]] = cube[tmp[i]]\nend\nans |= judge(cube2)\n\n\ntmp = Array.new(a1)\ntmp.rotate!(-2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[a1[i]] = cube[tmp[i]]\nend\nans |= judge(cube2)\n\ntmp = Array.new(b1)\ntmp.rotate!(-2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[b1[i]] = cube[tmp[i]]\nend\nans |= judge(cube2)\n\ntmp = Array.new(a2)\ntmp.rotate!(-2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[a2[i]] = cube[tmp[i]]\nend\nans |= judge(cube2)\n\ntmp = Array.new(b2)\ntmp.rotate!(-2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[b2[i]] = cube[tmp[i]]\nend\nans |= judge(cube2)\n\ntmp = Array.new(a3)\ntmp.rotate!(-2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[a3[i]] = cube[tmp[i]]\nend\nans |= judge(cube2)\n\ntmp = Array.new(b3)\ntmp.rotate!(-2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[b3[i]] = cube[tmp[i]]\nend\nans |= judge(cube2)\n\nputs ans ? \"YES\" : \"NO\""}, {"source_code": "def judge(cube)\n 6.times do |i|\n if !(cube[4 * i] == cube[4 * i + 1] && cube[4 * i + 1] == cube[4 * i + 2] && cube[4 * i + 2] == cube[4 * i + 3])\n return false\n end\n end\n return true\nend\n\na1 = [0,2,4,6,8,10,23,21]\nb1 = [1,3,5,7,9,11,22,20]\na2 = [12,13,4,5,16,17,20,21]\nb2 = [14,15,6,7,18,19,22,23]\na3 = [2,3,16,18,9,8,15,13]\nb3 = [0,1,17,19,11,10,14,12]\n\ncube = gets.split.map(&:to_i)\nans = judge(cube)\n\ntmp = Array.new(a1)\ntmp.rotate!(2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[tmp[i]] = cube[a1[i]]\nend\nans |= judge(cube2)\n\ntmp = Array.new(b1)\ntmp.rotate!(2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[tmp[i]] = cube[b1[i]]\nend\nans |= judge(cube2)\n\ntmp = Array.new(a2)\ntmp.rotate!(2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[tmp[i]] = cube[a2[i]]\nend\nans |= judge(cube2)\n\ntmp = Array.new(b2)\ntmp.rotate!(2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[tmp[i]] = cube[b2[i]]\nend\nans |= judge(cube2)\n\ntmp = Array.new(a3)\ntmp.rotate!(2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[tmp[i]] = cube[a3[i]]\nend\nans |= judge(cube2)\n\ntmp = Array.new(b3)\ntmp.rotate!(2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[tmp[i]] = cube[b3[i]]\nend\nans |= judge(cube2)\n\ntmp = Array.new(a1)\ntmp.rotate!(-2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[tmp[i]] = cube[a1[i]]\nend\nans |= judge(cube2)\n\ntmp = Array.new(b1)\ntmp.rotate!(-2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[tmp[i]] = cube[b1[i]]\nend\nans |= judge(cube2)\n\ntmp = Array.new(a2)\ntmp.rotate!(-2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[tmp[i]] = cube[a2[i]]\nend\nans |= judge(cube2)\n\ntmp = Array.new(b2)\ntmp.rotate!(-2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[tmp[i]] = cube[b2[i]]\nend\nans |= judge(cube2)\n\ntmp = Array.new(a3)\ntmp.rotate!(-2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[tmp[i]] = cube[a3[i]]\nend\nans |= judge(cube2)\n\ntmp = Array.new(b3)\ntmp.rotate!(-2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[tmp[i]] = cube[b3[i]]\nend\nans |= judge(cube2)\n\nputs ans ? \"YES\" : \"NO\""}, {"source_code": "def solve(a)\n\ttag = true\n\tj = 1\n\twhile(j<=21 && tag)\n\t\tif(a[j-1] == a[j]&& a[j]==a[j+1]&&a[j+1]==a[j+2])\n\t\t\tj += 4\n\t\t\tnext\n\t\tend\n\t\ttag = false\n\tend\n \treturn tag\nend\n\ntag = false\na = gets.split(' ').map(&:to_i)\ntemp1 = a[1-1]\ntemp2 = a[3-1]\na[1-1] = a[22-1]\na[3-1] = a[24-1]\na[22-1] = a[9-1] \na[24-1] = a[11-1]\na[9-1] = a[5-1]\na[11-1] = a[7-1]\na[5-1] = temp1\na[7-1] = temp2\nif solve a\n\ttag = true\nend\ntemp1 = a[1-1]\ntemp2 = a[3-1]\na[1-1] = a[5-1]\na[3-1] = a[7-1]\na[5-1] = a[9-1] \na[7-1] = a[11-1]\na[9-1] = a[22-1]\na[11-1] = a[24-1]\na[22-1] = temp1\na[24-1] = temp2\nif solve a\n\ttag = true\nend\n\n\n\ntemp1 = a[2-1]\ntemp2 = a[4-1]\na[2-1] = a[21-1]\na[4-1] = a[23-1]\na[21-1] = a[10-1] \na[23-1] = a[12-1]\na[10-1] = a[6-1]\na[12-1] = a[8-1]\na[6-1] = temp1\na[8-1] = temp2\nif solve a\n\ttag = true\nend\ntemp1 = a[2-1]\ntemp2 = a[4-1]\na[2-1] = a[6-1]\na[4-1] = a[8-1]\na[6-1] = a[10-1] \na[8-1] = a[12-1]\na[10-1] = a[21-1]\na[12-1] = a[23-1]\na[21-1] = temp1\na[23-1] = temp2\nif solve a\n\ttag = true\nend\n\n\n\ntemp1 = a[5-1]\ntemp2 = a[6-1]\na[5-1] = a[13-1]\na[6-1] = a[14-1]\na[13-1] = a[21-1] \na[14-1] = a[22-1]\na[21-1] = a[17-1]\na[22-1] = a[18-1]\na[17-1] = temp1\na[18-1] = temp2\nif solve a\n\ttag = true\nend\ntemp1 = a[5-1]\ntemp2 = a[6-1]\na[5-1] = a[17-1]\na[6-1] = a[18-1]\na[17-1] = a[21-1] \na[18-1] = a[22-1]\na[21-1] = a[13-1]\na[22-1] = a[14-1]\na[13-1] = temp1\na[14-1] = temp2\nif solve a\n\ttag = true\nend\n\n\n\n\n\ntemp1 = a[7-1]\ntemp2 = a[8-1]\na[7-1] = a[15-1]\na[8-1] = a[16-1]\na[15-1] = a[23-1] \na[16-1] = a[24-1]\na[23-1] = a[19-1]\na[24-1] = a[20-1]\na[19-1] = temp1\na[20-1] = temp2\nif solve a\n\ttag = true\nend\ntemp1 = a[7-1]\ntemp2 = a[8-1]\na[7-1] = a[19-1]\na[8-1] = a[20-1]\na[19-1] = a[23-1] \na[20-1] = a[24-1]\na[23-1] = a[15-1]\na[24-1] = a[16-1]\na[15-1] = temp1\na[16-1] = temp2\nif solve a\n\ttag = true\nend\n\n\n\n\n\n\n\ntemp1 = a[18-1]\ntemp2 = a[20-1]\na[18-1] = a[1-1]\na[20-1] = a[2-1]\na[1-1] = a[13-1] \na[2-1] = a[15-1]\na[13-1] = a[11-1]\na[15-1] = a[12-1]\na[11-1] = temp1\na[12-1] = temp2\nif solve a\n\ttag = true\nend\ntemp1 = a[18-1]\ntemp2 = a[20-1]\na[18-1] = a[11-1]\na[20-1] = a[12-1]\na[11-1] = a[13-1] \na[12-1] = a[15-1]\na[13-1] = a[1-1]\na[15-1] = a[2-1]\na[1-1] = temp1\na[2-1] = temp2\nif solve a\n\ttag = true\nend\n\n\n\n\n\n\ntemp1 = a[17-1]\ntemp2 = a[19-1]\na[17-1] = a[9-1]\na[19-1] = a[10-1]\na[9-1] = a[14-1] \na[10-1] = a[16-1]\na[14-1] = a[3-1]\na[16-1] = a[4-1]\na[3-1] = temp1\na[4-1] = temp2\nif solve a\n\ttag = true\nend\ntemp1 = a[17-1]\ntemp2 = a[19-1]\na[17-1] = a[3-1]\na[19-1] = a[4-1]\na[3-1] = a[14-1] \na[4-1] = a[16-1] \na[14-1] = a[9-1]\na[16-1] = a[10-1] \na[9-1] = temp1\na[10-1] = temp2\nif solve a\n\ttag = true\nend\nif tag\n\tprint('YES')\nelse\n\tprint('NO')\nend\n"}, {"source_code": "def solve(a)\n\ttag = true\n\tj = 1\n\twhile(j<=21 && tag)\n\t\tif(a[j-1] == a[j]&& a[j]==a[j+1]&&a[j+1]==a[j+2])\n\t\t\tj += 4\n\t\t\tnext\n\t\tend\n\t\ttag = false\n\tend\n \treturn tag\nend\n\ntag = false\na = gets.split(' ').map(&:to_i)\ntemp1 = a[1-1]\ntemp2 = a[3-1]\na[1-1] = a[22-1]\na[3-1] = a[24-1]\na[22-1] = a[9-1] \na[24-1] = a[11-1]\na[9-1] = a[5-1]\na[11-1] = a[7-1]\na[5-1] = temp1\na[7-1] = temp2\nif solve a\n\ttag = true\nend\ntemp1 = a[2-1]\ntemp2 = a[4-1]\na[2-1] = a[21-1]\na[4-1] = a[23-1]\na[21-1] = a[10-1] \na[23-1] = a[12-1]\na[10-1] = a[6-1]\na[12-1] = a[8-1]\na[6-1] = temp1\na[8-1] = temp2\nif solve a\n\ttag = true\nend\ntemp1 = a[5-1]\ntemp2 = a[6-1]\na[5-1] = a[13-1]\na[6-1] = a[14-1]\na[13-1] = a[21-1] \na[14-1] = a[22-1]\na[21-1] = a[17-1]\na[22-1] = a[18-1]\na[17-1] = temp1\na[18-1] = temp2\nif solve a\n\ttag = true\nend\ntemp1 = a[7-1]\ntemp2 = a[8-1]\na[7-1] = a[15-1]\na[8-1] = a[16-1]\na[15-1] = a[23-1] \na[16-1] = a[24-1]\na[23-1] = a[19-1]\na[24-1] = a[20-1]\na[19-1] = temp1\na[20-1] = temp2\nif solve a\n\ttag = true\nend\nif tag\n\tprint('YES')\nelse\n\tprint('NO')\nend\n"}, {"source_code": "def solve(a)\n\ttag = true\n\tj = 1\n\twhile(j<=21 && tag)\n\t\tif(a[j-1] == a[j]&& a[j]==a[j+1]&&a[j+1]==a[j+2])\n\t\t\tj += 4\n\t\t\tnext\n\t\tend\n\t\ttag = false\n\tend\n \treturn tag\nend\n\ntag = false\na = gets.split(' ').map(&:to_i)\ntemp1 = a[1-1]\ntemp2 = a[3-1]\na[1-1] = a[24-1]\na[3-1] = a[22-1]\na[24-1] = a[9-1] \na[22-1] = a[11-1]\na[9-1] = a[5-1]\na[11-1] = a[7-1]\na[5-1] = temp1\na[7-1] = temp2\nif solve a\n\ttag = true\nend\ntemp1 = a[1-1]\ntemp2 = a[3-1]\na[1-1] = a[5-1]\na[3-1] = a[7-1]\na[5-1] = a[9-1] \na[7-1] = a[11-1]\na[9-1] = a[24-1]\na[11-1] = a[22-1]\na[24-1] = temp1\na[22-1] = temp2\nif solve a\n\ttag = true\nend\n\n\n\ntemp1 = a[2-1]\ntemp2 = a[4-1]\na[2-1] = a[23-1]\na[4-1] = a[21-1]\na[23-1] = a[10-1] \na[21-1] = a[12-1]\na[10-1] = a[6-1]\na[12-1] = a[8-1]\na[6-1] = temp1\na[8-1] = temp2\nif solve a\n\ttag = true\nend\ntemp1 = a[2-1]\ntemp2 = a[4-1]\na[2-1] = a[6-1]\na[4-1] = a[8-1]\na[6-1] = a[10-1] \na[8-1] = a[12-1]\na[10-1] = a[23-1]\na[12-1] = a[21-1]\na[23-1] = temp1\na[21-1] = temp2\nif solve a\n\ttag = true\nend\n\n\n\ntemp1 = a[5-1]\ntemp2 = a[6-1]\na[5-1] = a[13-1]\na[6-1] = a[14-1]\na[13-1] = a[21-1] \na[14-1] = a[22-1]\na[21-1] = a[17-1]\na[22-1] = a[18-1]\na[17-1] = temp1\na[18-1] = temp2\nif solve a\n\ttag = true\nend\ntemp1 = a[5-1]\ntemp2 = a[6-1]\na[5-1] = a[17-1]\na[6-1] = a[18-1]\na[17-1] = a[21-1] \na[18-1] = a[22-1]\na[21-1] = a[13-1]\na[22-1] = a[14-1]\na[13-1] = temp1\na[14-1] = temp2\nif solve a\n\ttag = true\nend\n\n\n\n\n\ntemp1 = a[7-1]\ntemp2 = a[8-1]\na[7-1] = a[15-1]\na[8-1] = a[16-1]\na[15-1] = a[23-1] \na[16-1] = a[24-1]\na[23-1] = a[19-1]\na[24-1] = a[20-1]\na[19-1] = temp1\na[20-1] = temp2\nif solve a\n\ttag = true\nend\ntemp1 = a[7-1]\ntemp2 = a[8-1]\na[7-1] = a[19-1]\na[8-1] = a[20-1]\na[19-1] = a[23-1] \na[20-1] = a[24-1]\na[23-1] = a[15-1]\na[24-1] = a[16-1]\na[15-1] = temp1\na[16-1] = temp2\nif solve a\n\ttag = true\nend\n\n\ntemp1 = a[18-1]\ntemp2 = a[20-1]\na[18-1] = a[1-1]\na[20-1] = a[2-1]\na[1-1] = a[15-1] \na[2-1] = a[13-1]\na[13-1] = a[11-1]\na[15-1] = a[12-1]\na[12-1] = temp1\na[11-1] = temp2\nif solve a\n\ttag = true\nend\n\ntemp1 = a[18-1]\ntemp2 = a[20-1]\na[18-1] = a[12-1]\na[20-1] = a[11-1]\na[11-1] = a[13-1] \na[12-1] = a[15-1]\na[15-1] = a[1-1]\na[13-1] = a[2-1]\na[1-1] = temp1\na[2-1] = temp2\nif solve a\n\ttag = true\nend\n\n\n\n\n\n\ntemp1 = a[17-1]\ntemp2 = a[19-1]\na[17-1] = a[10-1]\na[19-1] = a[9-1]\na[9-1] = a[14-1] \na[10-1] = a[16-1]\na[16-1] = a[3-1]\na[14-1] = a[4-1]\na[3-1] = temp1\na[4-1] = temp2\nif solve a\n\ttag = true\nend\n\ntemp1 = a[17-1]\ntemp2 = a[19-1]\na[17-1] = a[3-1]\na[19-1] = a[4-1]\na[3-1] = a[16-1] \na[4-1] = a[14-1] \na[14-1] = a[9-1]\na[16-1] = a[10-1] \na[10-1] = temp1\na[9-1] = temp2\nif solve a\n\ttag = true\nend\nif tag\n\tprint('YES')\nelse\n\tprint('NO')\nend\n"}, {"source_code": "def solve(a)\n\ttag = true\n\tj = 1\n\twhile(j<=21 && tag)\n\t\tif(a[j-1] == a[j]&& a[j]==a[j+1]&&a[j+1]==a[j+2])\n\t\t\tj += 4\n\t\t\tnext\n\t\tend\n\t\ttag = false\n\tend\n \treturn tag\nend\n\ntag = false\na = gets.split(' ').map(&:to_i)\ntemp1 = a[1-1]\ntemp2 = a[3-1]\na[1-1] = a[22-1]\na[3-1] = a[24-1]\na[22-1] = a[9-1] \na[24-1] = a[11-1]\na[9-1] = a[5-1]\na[11-1] = a[7-1]\na[5-1] = temp1\na[7-1] = temp2\nif solve a\n\ttag = true\nend\ntemp1 = a[1-1]\ntemp2 = a[3-1]\na[1-1] = a[5-1]\na[3-1] = a[7-1]\na[5-1] = a[9-1] \na[7-1] = a[11-1]\na[9-1] = a[22-1]\na[11-1] = a[24-1]\na[22-1] = temp1\na[24-1] = temp2\nif solve a\n\ttag = true\nend\n\n\n\ntemp1 = a[2-1]\ntemp2 = a[4-1]\na[2-1] = a[21-1]\na[4-1] = a[23-1]\na[21-1] = a[10-1] \na[23-1] = a[12-1]\na[10-1] = a[6-1]\na[12-1] = a[8-1]\na[6-1] = temp1\na[8-1] = temp2\nif solve a\n\ttag = true\nend\ntemp1 = a[2-1]\ntemp2 = a[4-1]\na[2-1] = a[6-1]\na[4-1] = a[8-1]\na[6-1] = a[10-1] \na[8-1] = a[12-1]\na[10-1] = a[21-1]\na[12-1] = a[23-1]\na[21-1] = temp1\na[23-1] = temp2\nif solve a\n\ttag = true\nend\n\n\n\ntemp1 = a[5-1]\ntemp2 = a[6-1]\na[5-1] = a[13-1]\na[6-1] = a[14-1]\na[13-1] = a[21-1] \na[14-1] = a[22-1]\na[21-1] = a[17-1]\na[22-1] = a[18-1]\na[17-1] = temp1\na[18-1] = temp2\nif solve a\n\ttag = true\nend\ntemp1 = a[5-1]\ntemp2 = a[6-1]\na[5-1] = a[17-1]\na[6-1] = a[18-1]\na[17-1] = a[21-1] \na[18-1] = a[22-1]\na[21-1] = a[13-1]\na[22-1] = a[14-1]\na[13-1] = temp1\na[14-1] = temp2\nif solve a\n\ttag = true\nend\n\n\n\n\n\ntemp1 = a[7-1]\ntemp2 = a[8-1]\na[7-1] = a[15-1]\na[8-1] = a[16-1]\na[15-1] = a[23-1] \na[16-1] = a[24-1]\na[23-1] = a[19-1]\na[24-1] = a[20-1]\na[19-1] = temp1\na[20-1] = temp2\nif solve a\n\ttag = true\nend\ntemp1 = a[7-1]\ntemp2 = a[8-1]\na[7-1] = a[19-1]\na[8-1] = a[20-1]\na[19-1] = a[23-1] \na[20-1] = a[24-1]\na[23-1] = a[15-1]\na[24-1] = a[16-1]\na[15-1] = temp1\na[16-1] = temp2\nif solve a\n\ttag = true\nend\n\n\n\n\n\n\n\ntemp1 = a[18-1]\ntemp2 = a[20-1]\na[18-1] = a[1-1]\na[20-1] = a[2-1]\na[1-1] = a[13-1] \na[2-1] = a[14-1]\na[13-1] = a[11-1]\na[14-1] = a[12-1]\na[11-1] = temp1\na[12-1] = temp2\nif solve a\n\ttag = true\nend\ntemp1 = a[18-1]\ntemp2 = a[20-1]\na[18-1] = a[11-1]\na[20-1] = a[12-1]\na[11-1] = a[13-1] \na[12-1] = a[14-1]\na[13-1] = a[1-1]\na[14-1] = a[2-1]\na[1-1] = temp1\na[2-1] = temp2\nif solve a\n\ttag = true\nend\n\n\n\n\n\n\ntemp1 = a[17-1]\ntemp2 = a[19-1]\na[17-1] = a[9-1]\na[19-1] = a[10-1]\na[9-1] = a[15-1] \na[10-1] = a[16-1]\na[15-1] = a[3-1]\na[16-1] = a[4-1]\na[3-1] = temp1\na[4-1] = temp2\nif solve a\n\ttag = true\nend\ntemp1 = a[17-1]\ntemp2 = a[19-1]\na[17-1] = a[3-1]\na[19-1] = a[4-1]\na[3-1] = a[15-1] \na[4-1] = a[16-1] \na[15-1] = a[9-1]\na[16-1] = a[10-1] \na[9-1] = temp1\na[10-1] = temp2\nif solve a\n\ttag = true\nend\nif tag\n\tprint('YES')\nelse\n\tprint('NO')\nend\n"}], "src_uid": "881a820aa8184d9553278a0002a3b7c4"} {"nl": {"description": "Petr stands in line of n people, but he doesn't know exactly which position he occupies. He can say that there are no less than a people standing in front of him and no more than b people standing behind him. Find the number of different positions Petr can occupy.", "input_spec": "The only line contains three integers n, a and b (0\u2009\u2264\u2009a,\u2009b\u2009<\u2009n\u2009\u2264\u2009100).", "output_spec": "Print the single number \u2014 the number of the sought positions.", "sample_inputs": ["3 1 1", "5 2 3"], "sample_outputs": ["2", "3"], "notes": "NoteThe possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1).In the second sample they are 3, 4 and 5."}, "positive_code": [{"source_code": "t = gets.chomp.split(\" \")\nn = t[0].to_i\na = t[1].to_i\nb = t[2].to_i\nif n-a < 1+b\n puts n-a\nelse\n puts 1+b\nend\n"}, {"source_code": "\nn,a,b=gets.split.map(&:to_i)\nans=0\nfor i in 1..n\n if i-1>=a then\n if n-i<=b then\n ans+=1\n end\n end\nend\np ans\n"}, {"source_code": "f=->{gets(\" \").to_i};p [f[]-f[],f[]+1].min\n"}, {"source_code": "n,a,b=gets.split.map(&:to_i)\nprint [b+1,n-a].min,\"\\n\"\n"}, {"source_code": "n, a, b = gets.split(\" \").map{|x| x.to_i}\nputs [n - a, b + 1].min"}, {"source_code": "n, a, b = gets.split(\" \").map{|x| x.to_i}\nif n - a > b + 1\n puts b + 1\nelse\n puts n - a\nend"}, {"source_code": "n, a, b = gets.split.map(&:to_i)\nprint [n-a, b+1].min"}, {"source_code": "f=->{gets(\" \").to_i};p [f[]-f[],f[]+1].min\n"}, {"source_code": "n,a,b=gets.split.collect{|i| i.to_i}\nputs [n-a,b+1].min"}, {"source_code": "f=->{gets(\" \").to_i};p [f[]-f[],f[]+1].min"}, {"source_code": "n,a,b=gets.chomp.split(' ').map(&:to_i)\nwhile a>=n-b\n\tb-=1\nend\nputs b+1"}, {"source_code": "n, a, b = gets.split.map(&:to_i)\nputs [n-a, b+1].min"}, {"source_code": "n,a,b = gets.split(' ').map(&:to_i)\n\nputs (n-a)-1 > b ? b+1 : n-a\n"}, {"source_code": "n,a,b = gets.split.map(&:to_i)\n \nif a+b == n \n puts b\nelsif a+b > n\n puts n-a\nelse\n counter = 0\n for i in n-b..n\n counter+=1\n end\n puts counter\nend\n"}, {"source_code": "#!/usr/bin/ruby\n\ndef readNextValues\n return gets.chomp.split.collect {|x| x.to_i }\nend\n\nn, a, b = readNextValues\n\npos = n - b\npos = a + 1 if pos < a + 1\nnum = n - pos + 1\nif num > 0\n puts num\nelse\n puts 0\nend"}, {"source_code": "n, a, b = gets.split.map &:to_i\np [n - a, b + 1].min\n"}, {"source_code": "f=->{gets(\" \").to_i};p [f[]-f[],f[]+1].min\n"}, {"source_code": "f=->{gets(\" \").to_i};p [f[]-f[],f[]+1].min\n"}, {"source_code": "n,a,b=gets.split.map{|e| e.to_i}\nputs [n-a,b+1].min\n\n"}, {"source_code": "n,a,b=gets.split.map &:to_i;p [n-a,b+1].min"}, {"source_code": "n,a,b = gets.split.map(&:to_i)\n\nn -= a\n\nif n > b + 1\n n = b + 1\nend\nputs n\n"}, {"source_code": "f=->{gets(\" \").to_i};p [f[]-f[],f[]+1].min"}, {"source_code": "n,a,b=gets.split.map(&:to_i)\np [n-a,b+1].min\n"}, {"source_code": "n,a,b=gets.split.map &:to_i;p [n-a,b+1].min\n"}, {"source_code": "n,a,b=gets.split.map(&:to_i)\nans=0\n(1..n).each{|_| ans+=1 if (_-1)>=a && (n-_)<=b}\nputs ans\n"}, {"source_code": "n,a,b=gets.split.map(&:to_i)\np [*1..n].keep_if{|_|_>a && n-_<=b}.size\n"}, {"source_code": "a=gets.split.collect {|i|i.to_i}\np [a[0]-a[1],a[2]+1].min\n"}, {"source_code": "n, a, b = gets.split.map{ |e| e.to_i}\n\nputs a+b >= n ? n-a : b+1"}, {"source_code": "n, a, b = gets.split.map(&:to_i)\n\np [n - a, b + 1].min"}, {"source_code": "n,a,b=gets.split.map &:to_i;p [n-a,b+1].min\n"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\nn, a, b = gets.split.map(&:to_i)\n\n# \uc55e\uc5d4 a\uba85 \uc774\uc0c1, \ub4a4\uc5d4 b\uba85 \uc774\ud558\ub85c \uc11c\uc788\uc74c\n# n\uc5d0\ub294 Petr \uc790\uc2e0\uc744 \ud3ec\ud568\ud568\nd = n - (a + b)\n\nif d > 0\n puts b + 1\nelsif d == 0\n if a == n\n puts 1\n else\n puts b\n end\nelse\n puts (n - a)\nend"}, {"source_code": "f=->{gets(\" \").to_i};p [f[]-f[],f[]+1].min\n"}, {"source_code": "n,a,b=gets.split.map(&:to_i)\nputs [b+1,n-a].min\n"}, {"source_code": "n,a,b=gets.split.map &:to_i\nputs [n-a,b+1].min"}, {"source_code": "k=gets.split(\" \"); \nn=k[0].to_i\na=k[1].to_i\nb=k[2].to_i\nputs n - [a+1, n-b].max + 1\n"}, {"source_code": "f=->{gets(\" \").to_i};p [f[]-f[],f[]+1].min\n"}, {"source_code": "n, a, b = gets.split(' ').map(&:to_i)\n\nputs [n-a, b+1].min"}, {"source_code": "n, a, b = gets.split.map(&:to_i)\np [[n-a, b+1].min, 0].max"}, {"source_code": "f=->{gets(\" \").to_i};p [f[]-f[],f[]+1].min\n"}, {"source_code": "n,a,b=gets.split.map(&:to_i)\np [n-a,b+1].min"}, {"source_code": "#!/usr/bin/ruby -Ks\n\ninput = $stdin.gets.chomp.split\n$n = input[0].to_i\n$a = input[1].to_i\n$b = input[2].to_i\n\nans = 0\n1.upto($n) do |i|\n if (i>=$a+1) and ($n-i<=$b)\n ans+=1\n end\nend\nputs ans\n\n# EOF\n"}, {"source_code": "n, a, b = gets.split.map(&:to_i)\nprint (n - a < b + 1) ? n - a : b + 1"}, {"source_code": "n,a,b = gets.split.map &:to_i\n\nresult = 0\n\nfor i in a..n-1\n\tfor j in 0..b \n\t\tif i+j+1 == n\n\t\t\tresult +=1\n\t\tend\n\tend\nend\n\nputs result"}, {"source_code": "n, a, b = gets.split.map { |x| x.to_i }\n\nans = 0\n1.upto(n) do |i|\n\tans += 1 if i - 1 >= a and n - i <= b\nend\nputs ans\n"}, {"source_code": "f=->{gets(\" \").to_i};p [f[]-f[],f[]+1].min\n"}, {"source_code": "n, a, b = gets.split(' ').map(&:to_i)\nputs [n-a, b+1].min"}, {"source_code": "n, a, b = gets.split.map(&:to_i)\np (((a+1)..n).to_a & ((n-b)..n).to_a).size\n"}, {"source_code": "s = gets.split\nn = s[0].to_i\na = s[1].to_i\nb = s[2].to_i\np = 0\ni = a\nwhile i{gets(\" \").to_i};p [f[]-f[],f[]+1].min"}], "negative_code": [{"source_code": "puts gets.chomp.split(\" \")[1].to_i+1\n"}, {"source_code": "t = gets.chomp.split(\" \")\nn = t[0].to_i\na = t[1].to_i\nb = t[2].to_i\nif a+1 < n-a\n puts a+1\nelse\n puts n-a\nend\n"}, {"source_code": "n, a, b = gets.split(\" \").map{|x| x.to_i}\nif n - a > b\n puts b\nelse\n puts n - a\nend"}, {"source_code": "n, a, b = gets.split(\" \").map{|x| x.to_i}\nputs n - a"}, {"source_code": "n, a, b = gets.split(\" \").map{|x| x.to_i}\nif n == 9 && a == 4 && b == 3\n puts 4\nelse\n puts n - a\nend"}, {"source_code": "n,a,b=gets.split.collect{|i| i.to_i}\nputs [n-1,b+1].min"}, {"source_code": "n,a,b = gets.split(' ').map(&:to_i)\n\nputs (n-a)-1 > b ? b : n-a"}, {"source_code": "n,a,b = gets.split.map(&:to_i)\n counter = 0\nfor i in n-a..n\n counter+=1\nend\nputs counter"}, {"source_code": "n,a,b = gets.split.map(&:to_i)\n counter = 0\nfor i in a+1..n\n counter+=1\nend\nputs counter"}, {"source_code": "n,a,b = gets.split.map(&:to_i)\n counter = 0\nfor i in n-b+1..n\n counter+=1\nend\nputs counter"}, {"source_code": "n,a,b = gets.split.map(&:to_i)\n \nif a+b == n \n puts b\nelse\n counter = 0\n for i in n-b..n\n counter+=1\n end\nend\n\nputs counter"}, {"source_code": "n, a, b = gets.split.map &:to_i\nputs b > a ? b : a == b ? 1 + a : 0\n"}, {"source_code": "n, a, b = gets.split.map &:to_i\nputs a == b ? n - 1 : n - a\n"}, {"source_code": "n,a,b = gets.split.map(&:to_i)\n\nif n-a > b+1\n puts 0\nelse\n puts n-a\nend\n"}, {"source_code": "n,a,b = gets.split.map(&:to_i)\n\nif n >= a+b\n puts n-a\nelse\n puts n-a- b\nend\n\n"}, {"source_code": "n,a,b = gets.split.map(&:to_i)\n\nputs n-a\n"}, {"source_code": "n,a,b = gets.split.map(&:to_i)\n\nif n-a > b\n puts b\nelse\n puts n-a\nend\n"}, {"source_code": "n,a,b=gets.split.map(&:to_i)\nans=0\n(1..n).each{|_| ans+=1 if (_-1)>=a && (n-_)<=b}\n"}, {"source_code": "n,a,b=gets.split.map(&:to_i);p [n-a,b].max\n"}, {"source_code": "n,a,b=gets.split.map(&:to_i)\nans=1\n(1..n).each{|_| ans+=1 if _>=a && _<=b}\nputs ans\n"}, {"source_code": "n=gets.split.collect! {|i| i.to_i}\na=n[1]\nn=n[0]\n\np n-a\n"}, {"source_code": "n=gets.split.collect! {|i| i.to_i}\na=n[1] #4\nb=n[2] #3\nn=n[0] #9\n\np n-a\n"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\nn, a, b = gets.split.map(&:to_i)\n\n# \uc55e\uc5d4 a\uba85 \uc774\uc0c1, \ub4a4\uc5d4 b\uba85 \uc774\ud558\ub85c \uc11c\uc788\uc74c\n# n\uc5d0\ub294 Petr \uc790\uc2e0\uc744 \ud3ec\ud568\ud568\nd = n - (a + b)\n\nif d > 0\n puts b + 1\nelsif d == 0\n if a == n\n puts 1\n else\n puts b\n end\nelse\n puts (n - a) + 1\nend"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\nn, a, b = gets.split.map(&:to_i)\n\n# \uc55e\uc5d4 a\uba85 \uc774\uc0c1, \ub4a4\uc5d4 b\uba85 \uc774\ud558\ub85c \uc11c\uc788\ub2e4\uace0 \uadf8\ub974\ub124\uc694\n# a: from a, up to a + (n - a - b) = n - b\n# n - a - b = movable size\n# b: from b up to 0\nputs (n - a - b + 1) * (b)"}, {"source_code": "n,a,b=gets.split.map(&:to_i)\nputs [b,n-a].max\n"}, {"source_code": "a=0;\nn=gets.split(\" \");\nif (n[1].to_i>1)\n a+=n[1].to_i-1;\nelse\n a+=1;\nend\nif (n[2].to_i>1)\n a+=n[2].to_i-1;\nelse\n a+=1;\nend\nputs a"}, {"source_code": "n, a, b = gets.split.map(&:to_i)\np [[n-a, n-b].min, 0].max"}, {"source_code": "n,a,b=gets.split.map(&:to_i)\np [n-a,b].min"}, {"source_code": "n,a,b=gets.split.map(&:to_i)\np n-a"}, {"source_code": "#!/usr/bin/ruby -Ks\n\ninput = $stdin.gets.chomp.split\n$n = input[0].to_i\n$a = input[1].to_i\n$b = input[2].to_i\n\n($n-$a) < $b ? ans = $n-$a : ans = $b\nputs ans\n\n# EOF\n"}, {"source_code": "#!/usr/bin/ruby -Ks\n\ninput = $stdin.gets.chomp.split\n$n = input[0].to_i\n$a = input[1].to_i\n$b = input[2].to_i\n\nif $n - $a < $b\n ans = $b\nelse\n ans = $n - $a\nend\nputs ans\n\n# EOF\n"}, {"source_code": "#!/usr/bin/ruby -Ks\n\ninput = $stdin.gets.chomp.split\n$n = input[0].to_i\n$a = input[1].to_i\n$b = input[2].to_i\n\nans = 0\nc = $a + 1\n(c..$n).each do |i|\n if $n - c <= $b\n ans += 1\n end\nend\nputs ans\n\n# EOF\n"}, {"source_code": "f=->{gets(\" \").to_i};p f[]-[f[],f[]-1].max"}, {"source_code": "f=->{gets(\" \").to_i};p f[]-[f[],f[]+1].min"}, {"source_code": "f=->{gets(\" \").to_i};p f[]-[f[],f[]].min"}], "src_uid": "51a072916bff600922a77da0c4582180"} {"nl": {"description": "Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. Its length equals n (n is always even). Petya calls a ticket lucky if the ticket's number is a lucky number and the sum of digits in the first half (the sum of the first n\u2009/\u20092 digits) equals the sum of digits in the second half (the sum of the last n\u2009/\u20092 digits). Check if the given ticket is lucky.", "input_spec": "The first line contains an even integer n (2\u2009\u2264\u2009n\u2009\u2264\u200950) \u2014 the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly n \u2014 the ticket number. The number may contain leading zeros.", "output_spec": "On the first line print \"YES\" if the given ticket number is lucky. Otherwise, print \"NO\" (without the quotes).", "sample_inputs": ["2\n47", "4\n4738", "4\n4774"], "sample_outputs": ["NO", "NO", "YES"], "notes": "NoteIn the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4\u2009\u2260\u20097).In the second sample the ticket number is not the lucky number."}, "positive_code": [{"source_code": "n = gets.to_i / 2\nar = gets.scan(/[47]/).map(&:to_i)\nif ar.length != n * 2\n puts \"NO\"\nelsif ar[0...n].inject(:+)==ar[n..-1].inject(:+)\n puts \"YES\"\nelse\n puts \"NO\"\nend\n "}, {"source_code": "def isLucky(s)\n s.each_byte{|sb|\n return false if sb.chr != \"4\" && sb.chr != \"7\"\n }\n return true\nend\n\ndef sumstr(s)\n sum = 0\n s.each_byte{|sb|\n sum += sb.chr.to_i\n }\n return sum\nend\n\nret = \"NO\"\n$n = gets.chomp.to_i\n$s = gets.chomp\nif isLucky($s)\n s1 = $s.slice(0,$n/2)\n s2 = $s.slice($n/2,$n/2)\n if sumstr(s1) == sumstr(s2)\n ret = \"YES\"\n end\nend\nputs ret\n\n"}, {"source_code": "#!/usr/bin/ruby\nn=gets.to_i\ns=gets.chomp\nputs s=~/^[47]{#{n}}$/ && s[0,n/2].split('').map(&:to_i).reduce(:+)==s[n/2..-1].split('').map(&:to_i).reduce(:+) ? 'YES' : 'NO'"}, {"source_code": "\nn,a=gets.to_i,gets\nif /[01235689]/=~a then\n puts \"NO\"\n exit\nend\nsum=0\nn.times{|i|\n if i= number_length / 2\n result = false if !digits.include?(digit)\n i+=1\nend\n\nif(result)\n result = false if left_part != right_part\nend\n\nputs result ? \"YES\" : \"NO\""}, {"source_code": "n = gets.to_i\na = gets.chomp.chars.map(&:to_i)\nif a[0...n / 2].inject(:+) == a[n / 2...n].inject(:+) && n == a.count(4) + a.count(7)\n puts \"YES\"\nelse\n puts \"NO\"\nend\n"}, {"source_code": "n = gets.to_i\na = gets.chomp.chars.map(&:to_i)\nputs a[0...n / 2].inject(:+) == a[n / 2...n].inject(:+) && n == a.count(4) + a.count(7) ?\n \"YES\" : \"NO\"\n"}, {"source_code": "n = gets.to_i\nt = gets.chomp\ns = t.split('').map(&:to_i)\nputs (t=~/^(4|7)+$/ && s[0...n/2].sort == s[n/2...n].sort)?'YES':'NO'\n"}, {"source_code": "n = gets.to_i\nt = gets\ns = t.chomp.split(//).map(&:to_i)\nputs (t=~/^(4|7)+$/ && s[0...n/2].reduce(:+) == s[n/2...n].reduce(:+))?'YES':'NO'\n"}, {"source_code": "n = gets.to_i\ns = gets.chomp.split('')\nputs (s-['4','7']==[]&&s[0...n/2].sort==s[n/2...n].sort)?'YES':'NO'\n"}, {"source_code": "n=gets.to_i\nputs gets=~/^[47]+$/ && $_[0..n/2-1].sum==$_[n/2..n-1].sum ? \"YES\" : \"NO\"\n\n"}, {"source_code": "n = Integer(gets.chomp)\nh = n / 2\nstr = gets.chomp\ndigits = str.split('').map { |x| x.to_i }\nputs(str =~ /^(4|7)+$/ && digits[0...h].inject(:+) == digits[h..-1].inject(:+) ? 'YES' : 'NO')"}, {"source_code": "n = gets.to_i\na = gets\n\nif a.count(\"4\") + a.count(\"7\") != n\n puts \"NO\"\n exit\nend\nif a[0...n/2].bytes.inject(0,&:+) == a[n/2...n].bytes.inject(0,&:+)\n puts \"YES\"\nelse\n puts \"NO\"\nend"}, {"source_code": "n=gets.to_i\nputs gets=~/^[47]+$/ && $_[0..n/2-1].sum==$_[n/2..n-1].sum ? \"YES\" : \"NO\"\n\n"}, {"source_code": "n=gets.to_i\nputs gets=~/^[47]+$/ && $_[0..n/2-1].sum==$_[n/2..n-1].sum ? \"YES\" : \"NO\"\n"}, {"source_code": "input = STDIN.read.split(\"\\n\")\n\nnum = input[1]\n\nif num.length != num.count('47')\n\tSTDOUT.puts :NO\n\texit\nend\n\nn = input[0].to_i / 2\nnum1, num2 = input[1][0..n-1], input[1][n..-1]\n\nsum1 = num1.split(//).map(&:to_i).inject(0){|sum, x| sum += x}\nsum2 = num2.split(//).map(&:to_i).inject(0){|sum, x| sum += x}\n\nSTDOUT.puts sum1 == sum2 ? :YES : :NO"}, {"source_code": "gets\nlucky_numbers = [4, 7]\ndigits = gets.strip.split(//).map do |str|\n i = str.to_i\n unless lucky_numbers.include?(i)\n puts \"NO\"\n exit\n end\n i\nend\n\nif digits[0, digits.size/2].inject(:+) == digits[digits.size/2, digits.size/2].inject(:+)\n puts \"YES\"\nelse\n puts \"NO\"\nend\n"}, {"source_code": "n=gets.to_i\nputs gets=~/^[47]+$/ && $_[0..n/2-1].sum==$_[n/2..n-1].sum ? \"YES\" : \"NO\"\n\n"}], "negative_code": [{"source_code": "n = $stdin.gets.to_i\ns = $stdin.gets.chomp\n\nif s.gsub(/[47]/, '') == \"\"\n first = 0\n second = 0\n\n (n / 2).times do |i|\n first += s[i,1].to_i\n end\n\n (n / 2).times do |i|\n second += s[~i,1].to_i\n end\n\n p first, second\n\n if first == second\n puts \"YES\"\n else\n puts \"NO\"\n end\nelse\n puts \"NO\"\nend\n"}, {"source_code": "n = gets.to_i\ns = gets.chomp\nputs ((s=~/^[47]*$/) != nil and s[0,n/2].to_i == s[n/2..-1].to_i) ? :YES : :NO"}, {"source_code": "n = gets.chomp.to_i\ns = gets.chomp.split('').map(&:to_i)\n\nif s.uniq.sort == [4,7]\n if s.each_slice(n/2).map{|x| x.inject(:+)}.uniq.size == 1\n puts \"YES\"\n else\n puts \"NO\"\n end\nelse\n puts \"NO\"\nend"}, {"source_code": "n=gets.to_i/2;s=gets.split'';puts (s-['4','7']).empty?&&(s[0,n].sort==s[n,n].sort)?\"YES\":\"NO\""}, {"source_code": "n=gets.to_i/2;s=gets.split'';puts(s[0,n].sort==s[n,n].sort)?\"YES\":\"NO\""}, {"source_code": "n=gets.to_i/2;s=gets.split'';puts s[0,n].sort+s[n,n].sort==(['4']*(n/2)+['7']*(n/2))*2?\"YES\":\"NO\""}, {"source_code": "n=gets.to_i/2;s=gets.split'';puts (s[0,n].sort==s[n,n].sort)?\"YES\":\"NO\""}, {"source_code": "number_length = gets.to_i\nnumber = gets.to_i\ndigits = [4,7]\n\ni = 1\nresult = true\nwhile i <= number_length do\n digit = number % 10\n number = number / 10\n result = false if !digits.include?(digit)\n i+=1\nend\n\nputs result ? \"YES\" : \"NO\""}, {"source_code": "n = Integer(gets.chomp)\nh = n / 2\nstr = gets.chomp\nputs(str =~ /^(4|7)+$/ && str[0...h].reverse == str[h..-1] ? 'YES' : 'NO')"}], "src_uid": "435b6d48f99d90caab828049a2c9e2a7"} {"nl": {"description": "Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.Embosser is a special devise that allows to \"print\" the text of a plastic tape. Text is printed sequentially, character by character. The device consists of a wheel with a lowercase English letters written in a circle, static pointer to the current letter and a button that print the chosen letter. At one move it's allowed to rotate the alphabetic wheel one step clockwise or counterclockwise. Initially, static pointer points to letter 'a'. Other letters are located as shown on the picture: After Grigoriy add new item to the base he has to print its name on the plastic tape and attach it to the corresponding exhibit. It's not required to return the wheel to its initial position with pointer on the letter 'a'.Our hero is afraid that some exhibits may become alive and start to attack him, so he wants to print the names as fast as possible. Help him, for the given string find the minimum number of rotations of the wheel required to print it.", "input_spec": "The only line of input contains the name of some exhibit\u00a0\u2014 the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters.", "output_spec": "Print one integer\u00a0\u2014 the minimum number of rotations of the wheel, required to print the name given in the input.", "sample_inputs": ["zeus", "map", "ares"], "sample_outputs": ["18", "35", "34"], "notes": "Note\u00a0 To print the string from the first sample it would be optimal to perform the following sequence of rotations: from 'a' to 'z' (1 rotation counterclockwise), from 'z' to 'e' (5 clockwise rotations), from 'e' to 'u' (10 rotations counterclockwise), from 'u' to 's' (2 counterclockwise rotations). In total, 1\u2009+\u20095\u2009+\u200910\u2009+\u20092\u2009=\u200918 rotations are required."}, "positive_code": [{"source_code": "n = gets\nr = 0\ni = 0\nn = n[0..( n.size - 2)]\nn.each_byte {|c|\n c = c - 97\n r = [ ( c - i ).abs, ( ( i - c ).abs - 26 ).abs ].min + r\n i = c\n}\nputs r"}, {"source_code": "def execute(input)\n # special case\n pointer = 'a'\n if input == pointer\n puts 0\n return\n end\n\n if input.length == 1\n puts count_min_step(pointer, input)\n return\n end\n\n @count = 0\n input.split('').each_with_index do |char, index|\n if index == 0\n @count += count_min_step(pointer, char)\n else\n @count += count_min_step(input[index - 1], char)\n end\n end\n puts @count\nend\n\ndef count_min_step(char1, char2)\n step = (origin_anphabet.index(char1) - origin_anphabet.index(char2)).abs\n if step > (origin_anphabet.size / 2)\n return origin_anphabet.size - step\n else\n return step\n end\nend\n\ndef origin_anphabet\n @origin_anphabet ||= ('a'..'z').to_a\nend\n\ninput = gets.chomp\n\nexecute(input)\n"}, {"source_code": "r=0\n[0,*gets.chomp.bytes.map{|b|b-97}].each_cons(2){|x,y|r+=[(y-x)%26,(x-y)%26].min}\np r"}, {"source_code": "\ndef museum(input)\n rt = {}\n index = 0\n rt.tap do |r|\n rotations = ('a'..'z').to_a.each do |ro|\n r[ro] = index\n index += 1\n end\n end\n\n inputs = input.split('')\n inputs_size = inputs.size\n ch = rt['a']\n step = 0\n i = 0\n inputs.each do |s|\n d = (ch - rt[inputs[i]]).abs\n if d < 13\n step = step + d\n else\n step = step + (26 - d)\n end\n ch = rt[inputs[i]]\n i += 1\n end\n\n puts step\nend\n\nmuseum(gets.chomp)\n"}, {"source_code": "s = gets.chomp.split('')\nx = 'a'\nc = 0\ns.each do |y|\n v = (y.ord - x.ord).abs\n v = 26 - v if v > 13\n c += v\n x = y\nend\nputs c\n"}, {"source_code": "str = gets.chop\ncurrent = 'a'\nans = 0 \nclock_wise =0 \ncounter_clock_wise =0 \nstr.each_char do |i| \n\tclock_wise = i.ord - current.ord \n\tcounter_clock_wise = current.ord - i.ord \n\tclock_wise = 26 + clock_wise if clock_wise <0 \n\tcounter_clock_wise = 26+ counter_clock_wise if counter_clock_wise <0 \n\tmin_val = [clock_wise,counter_clock_wise].min \n\tans += min_val \n\tcurrent = i \nend \nputs ans \n"}, {"source_code": "name = gets.strip.bytes\n# name = 'zeus'.bytes\n\ndef calculate(name)\n result = 0\n current_ascii = 'a'.bytes[0]\n name.each do |char_ascii|\n dist = (current_ascii - char_ascii).abs\n current_ascii = char_ascii\n result += [dist, 26 - dist].min\n end\n result\nend\n\nputs calculate(name)\n"}, {"source_code": "def get_code(c)\n c.upcase.ord - 'A'.ord\nend\n\nresult = 0\npos = 0\n\nls = gets.chomp()\n\nls.split(\"\").each do |v|\n if pos == 0\n if get_code(v) - pos <= 13\n result += get_code(v)\n else\n result += 26 - get_code(v)\n end\n else\n if (get_code(v) - pos).abs <= 13\n result += (get_code(v) - pos).abs\n else\n result += 26 - (pos - get_code(v)).abs\n end\n end\n pos = get_code(v)\nend\n\nputs result\n"}, {"source_code": "s = gets.chomp.chars\n\narr = ('a'..'z').to_a\n# puts arr.index('c') - arr.index('a')\n\nans = 0\ncur = 'a'\ns.each do |c|\n ans += [(arr.index(cur) - arr.index(c)).abs, ((arr.index(cur) - arr.index(c)).abs - 26).abs].min\n cur = c\nend\nputs ans"}, {"source_code": "s = gets.strip\ncount = 0\ncurrent = 'a'\n(0...s.length).each do |i|\n clockwise = current.ord - s[i].ord\n counterclock = s[i].ord - current.ord\n clockwise = 26 + clockwise if clockwise < 0\n counterclock = 26 + counterclock if counterclock < 0\n min_count = [clockwise, counterclock].min\n count += min_count\n current = s[i]\nend\nputs count\n"}, {"source_code": "exhibit = gets.rstrip\n\narr = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']\n\ncount = 0\ncurrent_index = 0\nexhibit.split('').each do |char|\n index = arr.find_index do |l|\n l == char\n end\n\n distance_index = (index - current_index).abs\n\n if distance_index > 13\n if index < current_index\n count += index + 26 - current_index\n else\n count += current_index + 26 - index\n end\n else\n count += distance_index\n end\n current_index = index\nend\n\nputs count\n"}, {"source_code": "t=gets.chomp\nt=\"a\"+t\ns=t.chars\nans=0\nwhile s.size>1\n\tc1=s[0].ord\n\tc2=s[1].ord\n\td1=[c1,c2].min\n\td2=[c1,c2].max\n\tans+=[d2-d1,d1+26-d2].min\n\ts.shift\nend\nputs ans\n\n"}, {"source_code": "string = gets.to_s.chomp; sum =0 ;string.insert(0,\"a\")\nfor i in 0..string.length-2\n a = string[i+1].ord - string[i].ord\n a = a >13? 26-a : a<0? a<-13? 26+a : -a : a\n sum += a\nend\nputs sum\n"}, {"source_code": "s=gets.chomp\nres=0\na=?a\ns.chars{|e|\n\tc=e.dup\n\tx=0\n\twhile c[-1]!=a\n\t\tc.next!\n\t\tx+=1\n\tend\n\n\tb=a.dup\n\ty=0\n\twhile b[-1]!=e\n\t\tb.next!\n\t\ty+=1\n\tend\n\tres+=x>y ? y : x\n\ta=e\n}\nputs res\n"}, {"source_code": "t=0;('a'+gets).strip.split('').inject{|pr,i|td=((pr||'a').ord-i.ord).abs;t+=[td,26-td].min;i};puts t"}, {"source_code": "t=0;('a'+gets).strip.split('').inject{|pr,i|td=pr.ord-i.ord;t+=[td%26,(-td)%26].min;i};puts t"}, {"source_code": "s='a'+gets;revs=0\n(s.size-2).times{|i|\n clockwise=(s[i+1].ord-s[i].ord).abs;\n revs += [clockwise, (clockwise-26).abs].min\n}\nputs revs\n"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\nword = gets.chomp.split(//).map { |i|\n i.ord - \"a\".ord\n}\n\nc = 0\nrev = 0\nword.each { |i|\n l = 0\n r = 0\n\n if c < i # 'a' .... \"b\"\n l, r = i - c, c + (26 - i)\n elsif c == i # 'a' .... \"a\"\n l, r = 0, 0\n else # 'b' .... \"a\"\n l, r = (26 - c) + i , c - i\n end\n\n if l < r\n rev += l\n else\n rev += r\n end\n\n c = i\n}\n\nputs rev\n"}, {"source_code": "word = gets.chomp.split(\"\")\nalphabet = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']\nsum = 0\npos = 0\nfor i in (0..word.size-1)\n\tif i == 0\n\t\tif alphabet.find_index(word[i]) >= 13\n\t\t\tsum += 26 - alphabet.find_index(word[i])\n\t\telse\n\t\t\tsum += alphabet.find_index(word[i])\n\t\tend\n\t\tpos = alphabet.find_index(word[i])\n\telse\n\t\tif (pos - alphabet.find_index(word[i])).abs >= 13\n\t\t\tsum += 26 - (pos - alphabet.find_index(word[i])).abs\n\t\telse\n\t\t\tsum += (pos - alphabet.find_index(word[i])).abs\n\t\tend\n\t\tpos = alphabet.find_index(word[i])\n\tend\nend\n\nprint sum"}, {"source_code": "h = {\"a\"=>0, \"b\"=>1, \"c\"=>2, \"d\"=>3, \"e\"=>4, \"f\"=>5, \"g\"=>6, \"h\"=>7, \"i\"=>8, \"j\"=>9, \"k\"=>10, \"l\"=>11, \"m\"=>12, \"n\"=>13, \"o\"=>14, \"p\"=>15, \"q\"=>16, \"r\"=>17, \"s\"=>18, \"t\"=>19, \"u\"=>20, \"v\"=>21, \"w\"=>22, \"x\"=>23, \"y\"=>24, \"z\"=>25} \ns = gets.chomp\ninit = 'a'\nans = 0\ns.each_char do |c|\n d = (h[c] - h[init]).abs\n ans += [d, (d - 26).abs].min\n init = c\nend\np ans\n"}, {"source_code": "c = 'a'.ord\nm = 'z'.ord - 'a'.ord + 1\nputs(gets.strip.split('').map{|x| x.ord}.inject(0){|s, x| t = s + [[x, c].max - [x, c].min, ([x, c].min - [x, c].max)%m].min; c = x; t})\n"}, {"source_code": "string = gets.chomp\nvessel = string.scan(/./).map(&:ord)\nchar = 'a'.ord\nsum = 0\nvessel.each do |c|\n d = (char - c).abs\n if d < 13\n sum += d\n else\n sum += (26 - d)\n end\n char = c\nend\nputs sum"}, {"source_code": "word = gets.chop!\nlast_char = 'a'\nsum = 0\nword.each_char do |char|\n diff = char.ord > last_char.ord ? char.ord - last_char.ord : last_char.ord - char.ord\n sum += diff < 13 ? diff : 26 - diff\n last_char = char\nend\nputs sum"}, {"source_code": "prev = 'a'.ord\n\nputs(\n gets.chomp.chars.inject(0) do |sum, c|\n diff = (prev - c.ord).abs\n prev = c.ord\n sum + [diff, 26 - diff].min\n end\n)\n"}, {"source_code": "s = gets.strip\n\nmp = {}\n(0..25).each do |i|\n mp[('a'.ord + i).chr] = i\nend\n\ncnt = 0\ncurr = 'a'\ns.split('').each do |l|\n i = mp[curr]\n j = mp[curr]\n while(1)\n if i == mp[l] || j == mp[l]\n break\n end\n i -= 1\n j += 1\n j = 0 if j >= 26\n i = 25 if i < 0\n end\n if (mp[curr] - i).abs < (mp[curr] - j).abs\n cnt += (mp[curr] - i).abs \n else\n cnt += (mp[curr] - j).abs\n end\n\n curr = l\n\nend\n\nprintf(\"%d\\n\", cnt)\n"}, {"source_code": "require 'set'\n\nparse_int = lambda {gets.split.map{|x| x.to_i}}\n\ndef turn(a,b)\n a, b = [a,b].min, [a,b].max\n \n v1 = b.ord-a.ord\n v2 = 'z'.ord-b.ord + 1 + (a.ord-'a'.ord)\n \n #p [v1,v2].min\n [v1,v2].min\nend\n\n#puts turn 'a','z'\n#puts turn 'z','a'\n\nst = 'a'+gets.chomp\n\nans = 0\nfor i in (0...st.length-1)\n ans += turn st[i], st[i+1]\nend\nputs ans"}], "negative_code": [{"source_code": "n = gets\nr = 0\ni = 0\nn = n[0..( n.size - 2)]\nputs i\nn.each_byte {|c|\n c = c - 97\n r = [ ( c - i ).abs, ( ( i - c ).abs - 26 ).abs ].min + r\n i = c\n}\nputs r"}, {"source_code": "name = gets.bytes\n# name = 'zeus'.bytes\n\ndef calculate(name)\n result = 0\n current_ascii = 'a'.bytes[0]\n name.each do |char_ascii|\n dist = (current_ascii - char_ascii).abs\n current_ascii = char_ascii\n result += [dist, 26 - dist].min\n end\n result\nend\n\nputs calculate(name)\n"}, {"source_code": "name = gets.bytes\n# name = 'zeus'.bytes\n\ncurrent_ascii = 'a'.bytes[0]\nresult = 0\n\nname.each do |char_ascii|\n dist = (current_ascii - char_ascii).abs\n current_ascii = char_ascii\n result += [dist, 26 - dist].min\nend\n\nputs result\n"}, {"source_code": "t=0;'azeus'.split('').inject{|pr,i|td=((pr||'a').ord-i.ord).abs;t+=[td,26-td].min;i};puts t"}, {"source_code": "t=0;('a'+gets).split('').inject{|pr,i|td=((pr||'a').ord-i.ord).abs;t+=[td,26-td].min;i};puts t"}, {"source_code": "word = gets.chomp.split(\"\")\nalphabet = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']\nsum = 0\npos = 0\nfor i in (0..word.size-1)\n\tif i == 0\n\t\tif alphabet.find_index(word[i]) >= 13\n\t\t\tsum += 26 - alphabet.find_index(word[i])\n\t\telse\n\t\t\tsum += alphabet.find_index(word[i])\n\t\tend\n\t\tpos = alphabet.find_index(word[i])\n\telse\n\t\tif (pos - alphabet.find_index(word[i])).abs >= 13\n\t\t\tsum += 26 - (pos - alphabet.find_index(word[i])).abs\n\t\telse\n\t\t\tsum += pos - alphabet.find_index(word[i])\n\t\tend\n\t\tpos = alphabet.find_index(word[i])\n\tend\nend\n\nprint sum"}], "src_uid": "ecc890b3bdb9456441a2a265c60722dd"} {"nl": {"description": "Manao has a monitor. The screen of the monitor has horizontal to vertical length ratio a:b. Now he is going to watch a movie. The movie's frame has horizontal to vertical length ratio c:d. Manao adjusts the view in such a way that the movie preserves the original frame ratio, but also occupies as much space on the screen as possible and fits within it completely. Thus, he may have to zoom the movie in or out, but Manao will always change the frame proportionally in both dimensions.Calculate the ratio of empty screen (the part of the screen not occupied by the movie) to the total screen size. Print the answer as an irreducible fraction p\u2009/\u2009q.", "input_spec": "A single line contains four space-separated integers a, b, c, d (1\u2009\u2264\u2009a,\u2009b,\u2009c,\u2009d\u2009\u2264\u20091000).", "output_spec": "Print the answer to the problem as \"p/q\", where p is a non-negative integer, q is a positive integer and numbers p and q don't have a common divisor larger than 1.", "sample_inputs": ["1 1 3 2", "4 3 2 2"], "sample_outputs": ["1/3", "1/4"], "notes": "NoteSample 1. Manao's monitor has a square screen. The movie has 3:2 horizontal to vertical length ratio. Obviously, the movie occupies most of the screen if the width of the picture coincides with the width of the screen. In this case, only 2/3 of the monitor will project the movie in the horizontal dimension: Sample 2. This time the monitor's width is 4/3 times larger than its height and the movie's frame is square. In this case, the picture must take up the whole monitor in the vertical dimension and only 3/4 in the horizontal dimension: "}, "positive_code": [{"source_code": "a,b,c,d=gets.split.map(&:to_i)\np=a*d\nq=b*c\nputs [Rational(p-q,p),Rational(q-p,q)].max\n"}, {"source_code": "a,b,c,d=gets.split.map(&:to_i)\np=a*d\nq=b*c\nputs [Rational(p-q,p),Rational(q-p,q)].max"}, {"source_code": "a,b,c,d=gets.split.map(&:to_i)\np=a*d\nq=b*c\nputs [Rational(p-q,p),Rational(q-p,q)].max\n"}, {"source_code": "a,b,c,d=gets.split.map(&:to_i)\np=a*d\nq=b*c\nputs [Rational(p-q,p),Rational(q-p,q)].max"}, {"source_code": "a,b,c,d=gets.chomp.split.map(&:to_i)\na*=d;b*=c\n(a>b) ? (p=a-b;q=a) : (p=b-a;q=b)\nr=p.gcd(q)\nputs \"#{p/r}/#{q/r}\""}, {"source_code": "a,b,c,d=gets.split.map(&:to_i)\np=a*d\nq=b*c\nputs [Rational(p-q,p),Rational(q-p,q)].max\n"}, {"source_code": "a=gets.chomp.split(\" \").map {|i| i.to_i}\nb=(a[1]*a[2]-a[0]*a[3]).abs\nif a[0]/a[2].to_f cd)\t\n\tdenum = a*d\nelsif (ab < cd)\t\n\tdenum = b*c\nelse\n\tnum = 0\n\tdenum = 1\nend\n\ndef gcd(a,b) \n\tb==0 ? a : gcd(b, a % b)\nend\n\ng = gcd(denum, num)\nnum = num/g\ndenum = denum/g\n\nputs \"#{num}/#{denum}\""}, {"source_code": " \na,b,c,d=gets.split.map(&:to_i)\np=a*d\nq=b*c\nputs [Rational(p-q,p),Rational(q-p,q)].max"}, {"source_code": "a,b,c,d=gets.split.map(&:to_i)\np=a*d\nq=b*c\nputs [Rational(p-q,p),Rational(q-p,q)].max"}, {"source_code": "a,b,c,d=gets.split.map(&:to_i)\np=a*d\nq=b*c\nputs [Rational(p-q,p),Rational(q-p,q)].max\n"}, {"source_code": "def gcd(a,b)\nif b == 0\n return a;\nelse\n return gcd(b, a % b);\nend\nend\n\n\na,b,c,d = gets.split(\" \").map(&:to_i)\n\nl,m = (a/b.to_f),(c/d.to_f)\n\nnum = den = 0\n# puts \"#{l} #{m}\"\nif l < m\n\tnum = (b * c) - (a * d)\n\tden = b * c\nelsif l > m\n\tnum = (a * d) - (b * c)\n\tden = a * d\nend\n\nif num == 0 && den == 0\n\tputs \"0/1\"\nelse\n\tg = gcd(num,den)\n\tputs \"#{num/g}/#{den/g}\"\nend\n\n"}, {"source_code": "a, b, c, d = gets.split.map(&:to_i)\np = a * d\nq = b * c\nputs [Rational(p - q, p), Rational(q - p, q)].max\n"}, {"source_code": "def gcd(n, m)\n return m == 0? n : gcd(m, n % m)\nend\na, b, c, d = gets.chop!.split.map{|x| x.to_i}\nn, m = a * d, b * c\nif(n < m)\n k = n \n n = m\n m = k\nend\nm = n - m\nc = gcd(n, m)\nn /= c\nm /= c\nprint m, '/', n\n"}, {"source_code": "a, b, c, d = gets.split.collect{|i| i.to_i}\na *= c*d\nb *= c*d\nif a/c > b/d\n p = b/d\n c = a-p*c\n gcd = a.gcd(c)\n print c/gcd, \"/\", a/gcd, \"\\n\"\nelse\n p = a/c\n d = b-p*d\n gcd = b.gcd(d)\n print d/gcd, \"/\", b/gcd, \"\\n\"\nend\n"}, {"source_code": "a, b, c, d = gets.split.collect{|i| i.to_i}\na *= c*d\nb *= c*d\nif a/c > b/d\n p = b/d\n c = a-p*c\n d = p*d\n gcd = a.gcd(c)\n print c/gcd, \"/\", a/gcd, \"\\n\"\nelse\n p = a/c\n c = p*c\n d = b-p*d\n gcd = b.gcd(d)\n print d/gcd, \"/\", b/gcd, \"\\n\"\nend\n"}, {"source_code": "a,b,c,d=gets.split.map(&:to_i)\np=a*d\nq=b*c\nputs [Rational(p-q,p),Rational(q-p,q)].max"}, {"source_code": "a,b,c,d=gets.split.map(&:to_i)\np=a*d\nq=b*c\nputs [Rational(p-q,p),Rational(q-p,q)].max\n"}, {"source_code": "# f = File.new('test.txt', 'r')\na, b, c, d = gets.split.map(&:to_i)\n# f.close\n\ndef gcd(a, b)\n if b == 0\n a\n else\n gcd(b, a % b)\n end\nend\n\n\nif a * d < b * c\n numerator = (b * c - a * d)\n denomerator = (b * c)\nelsif a * d > b * c\n numerator = a * d - b * c\n denomerator = a * d\nelse\n numerator, denomerator = [0, 1]\nend\n\nuc = gcd(numerator, denomerator)\nnumerator /= uc\ndenomerator /= uc\nputs \"#{numerator}/#{denomerator}\""}, {"source_code": "a,b,c,d=gets.split.map(&:to_i)\np=a*d\nq=b*c\nputs [Rational(p-q,p),Rational(q-p,q)].max\n"}, {"source_code": "a,b,c,d=gets.split.map(&:to_i)\np=a*d\nq=b*c\nputs [Rational(p-q,p),Rational(q-p,q)].max\n"}], "negative_code": [{"source_code": "a=gets.chomp.split(\" \").map {|i| i.to_i}\nb=(a[1]*a[2]-a[0]*a[3]).abs\nif a[2]>a[3]\nc=b.gcd(a[2]*a[0])\nputs \"#{b/c}/#{(a[2]*a[0])/c}\"\nelsif a[3]>a[2]\nc=b.gcd(a[3]*a[1])\nputs \"#{b/c}/#{(a[3]*a[1])/c}\"\nelsif a[3]==a[2]\nif a[1]>a[0]\nc=b.gcd(a[3]*a[1])\nputs \"#{b/c}/#{(a[3]*a[1])/c}\"\nelse\nc=b.gcd(a[2]*a[0])\nputs \"#{b/c}/#{(a[2]*a[0])/c}\"\nend\nend"}, {"source_code": "def gcd(a,b)\nif b == 0\n return a;\nelse\n return gcd(b, a % b);\nend\nend\n\n\na,b,c,d = gets.split(\" \").map(&:to_i)\n\nl,m = (a/b.to_f),(c/d.to_f)\n\nnum = den = 0\n\nif l < m\n\tnum = (b * c) - (a * d)\n\tden = b * c\nelsif l > m\n\tnum = (a * d) - (b * c)\n\tden = a * d\nend\n\nif num == 0\n\tputs 0 \nelse\n\tg = gcd(num,den)\n\tputs \"#{num/g}/#{den/g}\"\nend\n\n"}], "src_uid": "b0f435fc2f7334aee0d07524bc37cb1e"} {"nl": {"description": "The Little Elephant loves numbers. He has a positive integer x. The Little Elephant wants to find the number of positive integers d, such that d is the divisor of x, and x and d have at least one common (the same) digit in their decimal representations. Help the Little Elephant to find the described number.", "input_spec": "A single line contains a single integer x (1\u2009\u2264\u2009x\u2009\u2264\u2009109).", "output_spec": "In a single line print an integer \u2014 the answer to the problem.", "sample_inputs": ["1", "10"], "sample_outputs": ["1", "2"], "notes": null}, "positive_code": [{"source_code": "s = gets\nx = s.to_i\nh = {}\nf = ->(y){ h[y] = 1 if x % y == 0 && y.to_s.chars.any?{|c| s.index(c)} }\n1.upto(Math.sqrt(x)) do |y|\n f[y]\n f[x / y]\nend\np h.size\n"}, {"source_code": "s = gets\nx = s.to_i\np [*1..Math.sqrt(x)].map{|_| [_, x / _]}.flatten.select{|_| x % _ == 0 && s.tr(_.to_s, '') != s}.uniq.size\n"}, {"source_code": "s = gets\nx = s.to_i\nh = {}\nf = ->(y){ h[y] = 1 if x % y == 0 && s.tr(y.to_s, '') != s }\n1.upto(Math.sqrt(x)) do |y|\n f[y]\n f[x / y]\nend\np h.size\n"}, {"source_code": "s = gets\nx = s.to_i\np [*1..x**0.5].map{|_| [_, x / _]}.flatten.select{|_| x % _ == 0 && s.tr(_.to_s, '') != s}.uniq.size\n"}, {"source_code": "n = gets.to_i\nns = n.to_s.split('')\na = []\n(1..Math.sqrt(n)).each { |x| a.push(x, n/x) if n%x == 0 }\np a.sort.uniq.count { |x| (x.to_s.split('')&ns).size.nonzero? }"}, {"source_code": "s = gets\nx = s.to_i\np [*1..x**0.5].map{|_| [_, x / _]}.flatten.select{|_| x % _ == 0 && s.tr(_.to_s, '') != s}.uniq.size"}, {"source_code": "def divisors(n)\n ans = []\n 1.upto((n**0.5).to_i) do |i|\n if n % i == 0\n ans.push(i)\n ans.push(n/i) unless i * i == n\n end\n end\n return ans\nend\n\ndef match(x,d)\n m = 0\n xx = x.to_s.split(\"\").map(&:to_i)\n dd = d.to_s.split(\"\").map(&:to_i)\n 0.upto(9) do |digit|\n if xx.count(digit) > 0 && dd.count(digit) > 0\n return 1\n end\n end\n return 0\nend\n\nn = gets.to_i\n\ndivisors = divisors(n)\nputs divisors.inject(0){ |count, i| count += match(i,n) }\n"}, {"source_code": "s = gets\nx = s.to_i\np [*1..x**0.5].map{|_| [_, x / _]}.flatten.select{|_| x % _ == 0 && s.tr(_.to_s, '') != s}.uniq.size"}, {"source_code": "x = gets.to_i\nxset = x.to_s.split(\"\")\nans = 0\n(1..x**0.5).each do |i|\n next if x%i != 0\n ans += 1 unless (i.to_s.split(\"\")&xset).empty?\n j = x/i\n if j != i\n ans += 1 unless (j.to_s.split(\"\")&xset).empty?\n end\nend\nputs ans\n"}, {"source_code": "require \"prime\"\nx=gets.to_i\nif x<10\n\tp 1\n\texit\nend\ntable=[nil]*10\nxx=x\nwhile xx>0\n\ttable[xx%10]=true\n\txx/=10\nend\npd=x.prime_division.map{|a,b|0.upto(b).map{|i|a**i}}\ndivisors=pd.first\npd[1..-1].each{|divs|divisors=divs.map{|d|divisors.map{|e|d*e}}.flatten}\nans=0\ndivisors.each{|d|\n\twhile d>0\n\t\tif table[d%10]\n\t\t\tans+=1\n\t\t\tbreak\n\t\tend\n\t\td/=10\n\tend\n}\np ans"}], "negative_code": [], "src_uid": "ada94770281765f54ab264b4a1ef766e"} {"nl": {"description": "InputThe input contains two integers a1,\u2009a2 (0\u2009\u2264\u2009ai\u2009\u2264\u2009109), separated by a single space.OutputOutput a single integer.ExamplesInput3 14Output44Input27 12Output48Input100 200Output102", "input_spec": "The input contains two integers a1,\u2009a2 (0\u2009\u2264\u2009ai\u2009\u2264\u2009109), separated by a single space.", "output_spec": "Output a single integer.", "sample_inputs": ["3 14", "27 12", "100 200"], "sample_outputs": ["44", "48", "102"], "notes": null}, "positive_code": [{"source_code": "s1, s2 = gets.split\np s1.to_i + s2.reverse.to_i\n"}, {"source_code": "s1, s2 = gets.split\nlen = [s1.size, s2.size].max\ns1 = s1.rjust(len, \"0\")\np s1.to_i + s2.reverse.to_i\n"}, {"source_code": "n,m = gets.chomp.split(/ /).map!{|x| x.to_i}\nret = n + m.to_s.reverse!.to_i\nputs ret\n"}, {"source_code": "a1, a2 = gets.split\n\na1 = a1.to_i\na2 = a2.reverse.to_i\n\nputs a1 + a2\n"}, {"source_code": "a,b=gets.split\np a.to_i+b.reverse.to_i"}, {"source_code": "a, b = gets.split\np a.to_i + b.reverse.to_i\n"}, {"source_code": "a,b=gets.split.map(&:to_i)\nb=b.to_s.reverse.to_i\nputs a+b"}, {"source_code": "a,b=gets.split\np a.to_i+b.reverse.to_i\n"}, {"source_code": "a=gets.split.map(&:to_s)\nputs a[0].to_i+a[-1].reverse.to_i\n"}, {"source_code": "a,b=gets.split\np a.to_i+b.reverse.to_i\n"}, {"source_code": "a, b = gets.split\np a.to_i + b.reverse.to_i\n"}, {"source_code": "a,b=gets.split\np a.to_i+b.reverse.to_i\n"}, {"source_code": "a,b=gets.split\np a.to_i+b.reverse.to_i\n"}, {"source_code": "m = gets.split \" \"\np m[0].to_i + m[1].reverse.to_i"}, {"source_code": "m = gets.split \" \"\na = m[0].to_i\nb = m[1]\n0.upto(b.length/2-1) do |i|\nt = b[i]\nb[i] = b[b.length-1-i]\nb[b.length-1-i] = t\nend\np a+b.to_i"}, {"source_code": "a,b=gets.split\np a.to_i+b.reverse.to_i"}, {"source_code": "(a, b) = gets.chomp.split(' ')\nb.reverse!\nputs a.to_i + b.to_i"}, {"source_code": "a, b = gets.split.map(&:to_i)\np a + b.to_s.reverse.to_i"}, {"source_code": "a, b = gets.split.map(&:to_i)\np a + b.to_s.reverse.to_i\nSTDIN.gets"}, {"source_code": "a, b = gets.split\n\nputs a.to_i + b.reverse.to_i"}, {"source_code": "x,y=gets.split\nputs x.to_i+y.reverse.to_i\n"}, {"source_code": "a,b=gets.split\np a.to_i+b.reverse.to_i\n"}, {"source_code": "inp = gets.split\na = inp[0].to_i\nb = inp[1].reverse.to_i\nputs (a + b)"}, {"source_code": "a, b = gets.split\nputs a.to_i + b.reverse.to_i"}, {"source_code": "a,b=gets.split\np a.to_i+b.reverse.to_i"}, {"source_code": "a1, a2 = gets.split.map(&:to_i)\np a1 + a2.to_s.reverse.to_i\n"}, {"source_code": "a1,a2 = gets.split(\" \").collect {|x| x.to_i}\na = 0\nwhile a2>0\n\ta = a*10+a2%10\n\ta2 /= 10\nend\nputs a1+a"}, {"source_code": "input = readline.split(' ');\na1 = input[0].to_i\na2 = input[1].reverse.to_i\nputs a1+a2\n"}, {"source_code": "a,b=gets.split\np a.to_i+b.reverse.to_i\n"}, {"source_code": "n = gets.chomp.split(\" \")\nputs (n[0].to_i+n[1].reverse.to_i)"}, {"source_code": "a,b=gets.split\np a.to_i+b.reverse.to_i\n"}, {"source_code": "a, b = gets.split\nprint a.to_i + b.reverse.to_i"}, {"source_code": "a,b=gets.split\np a.to_i+b.reverse.to_i\n"}], "negative_code": [{"source_code": "s1, s2 = gets.split\nlen = [s1.size, s2.size].max\ns1 = s1.rjust(len, \"0\")\ns2 = s2.rjust(len, \"0\")\nc1 = s1.reverse.to_i + s2.to_i\nc2 = s1.to_i + s2.reverse.to_i\nl1 = c1.to_s.size\nl2 = c2.to_s.size\np l1 == len && l2 == len ? [c1, c2].min : l1 == len ? c1 : c2\n"}, {"source_code": "s1, s2 = gets.split\nlen = [s1.size, s2.size].max\ns1 = s1.rjust(len, \"0\")\ns2 = s2.rjust(len, \"0\")\np s1.to_i + s2.reverse.to_i\n"}, {"source_code": "s1, s2 = gets.split\nlen = [s1.size, s2.size].max\ns1 = s1.rjust(len, \"0\")\ns2 = s2.rjust(len, \"0\")\np [s1.reverse.to_i + s2.to_i, s1.to_i + s2.reverse.to_i].min\n"}, {"source_code": "n,m = gets.chomp.split(/ /).map!{|x| x.to_i}\nputs 1\n"}, {"source_code": "n,m = gets.chomp.split(/ /).map!{|x| x.to_i}\nret = 0\nif n == 3 && m == 14\n ret = 44\nend\nif n == 100 && m == 200\n ret = 102\nend\nif n == 27 && m == 12\n ret = 48\nend\nputs ret\n"}, {"source_code": "puts gets.to_i+gets.to_s.reverse.to_i\n"}, {"source_code": "m = gets.split \" \"\na = m[0].to_i\nb = m[1]\nt = b[b.length-1]\nb[b.length-1] = b[0]\nb[0] = t\np a+b.to_i"}, {"source_code": "puts 2"}, {"source_code": "print rand 100"}], "src_uid": "69b219054cad0844fc4f15df463e09c0"} {"nl": {"description": "There is a new TV game on BerTV. In this game two players get a number A consisting of 2n digits. Before each turn players determine who will make the next move. Each player should make exactly n moves. On it's turn i-th player takes the leftmost digit of A and appends it to his or her number Si. After that this leftmost digit is erased from A. Initially the numbers of both players (S1 and S2) are \u00abempty\u00bb. Leading zeroes in numbers A,\u2009S1,\u2009S2 are allowed. In the end of the game the first player gets S1 dollars, and the second gets S2 dollars.One day Homer and Marge came to play the game. They managed to know the number A beforehand. They want to find such sequence of their moves that both of them makes exactly n moves and which maximizes their total prize. Help them.", "input_spec": "The first line contains integer n (1\u2009\u2264\u2009n\u2009\u2264\u200918). The second line contains integer A consisting of exactly 2n digits. This number can have leading zeroes.", "output_spec": "Output the line of 2n characters \u00abH\u00bb and \u00abM\u00bb \u2014 the sequence of moves of Homer and Marge, which gives them maximum possible total prize. Each player must make exactly n moves. If there are several solutions, output any of them.", "sample_inputs": ["2\n1234", "2\n9911"], "sample_outputs": ["HHMM", "HMHM"], "notes": null}, "positive_code": [{"source_code": "n=gets.to_i\ns=gets.chomp.reverse.chars.map &:to_i\nd=(n+1).times.collect{[0]*(n+1)}\np=(n+1).times.collect{[0]*(n+1)}\n0.upto(n){|i|\n\t0.upto(n){|j|\n\t\tif i>0\n\t\t\ta=d[i-1][j]+10**(i-1)*s[i+j-1]\n\t\t\t\"#{d[i][j]=a; p[i][j]=0}\"if a>=d[i][j]\n\t\tend\n\t\tif j>0\n\t\t\ta=d[i][j-1]+10**(j-1)*s[i+j-1]\n\t\t\t\"#{d[i][j]=a;p[i][j]=1}\"if a>=d[i][j]\n\t\tend\n\t}\n}\ni,j=n,n\nprint p[i][j]==0?\"#{i-=1;\"H\"}\":\"#{j-=1;\"M\"}\"while[i,j].max>0"}, {"source_code": "$re = Array.new(20)\n$re.each_index{ |y|\n\t$re[y] = Array.new(20) \n}\n\n$fx = Array.new(20)\n$fx.each_index{ |y|\n\t$fx[y] = Array.new(20,-1)\n}\n\n$wz = Array.new(20)\n\ndef dfs( a, b )\n return $re[a][b] if($fx[a][b]!=-1)\n if(a==$n && b==$n)\n $fx[a][b]=-2\n return $re[a][b]=0\n end\n $re[a][b]=-1\n\n if(a!=$n)\n $re[a][b]=dfs(a+1,b)+$wz[a]*$cd[a+b].to_i\n $fx[a][b]=0\n end\n\n if(b!=$n)\n lj=dfs(a,b+1)+$wz[b]*$cd[a+b].to_i\n if($re[a][b]0\n\t\t\ta=d[i-1][j]+10**(i-1)*s[i+j-1]\n\t\t\t\"#{d[i][j]=a; p[i][j]=0}\"if a>=d[i][j]\n\t\tend\n\t\tif j>0\n\t\t\ta=d[i][j-1]+10**(j-1)*s[i+j-1]\n\t\t\t\"#{d[i][j]=a;p[i][j]=1}\"if a>=d[i][j]\n\t\tend\n\t}\n}\ni,j=n,n\nprint p[i][j]==0?\"#{i-=1;\"H\"}\":\"#{j-=1;\"M\"}\"while[i,j].max>0\n\n"}, {"source_code": "n=gets.to_i\ns=gets.chomp.reverse.chars.map &:to_i\nd=(n+1).times.collect{[0]*(n+1)}\np=(n+1).times.collect{[0]*(n+1)}\n0.upto(n){|i|\n\t0.upto(n){|j|\n\t\tif i>0\n\t\t\ta=d[i-1][j]+10**(i-1)*s[i+j-1]\n\t\t\t\"#{d[i][j]=a; p[i][j]=0}\"if a>=d[i][j]\n\t\tend\n\t\tif j>0\n\t\t\ta=d[i][j-1]+10**(j-1)*s[i+j-1]\n\t\t\t\"#{d[i][j]=a;p[i][j]=1}\"if a>=d[i][j]\n\t\tend\n\t}\n}\ni,j=n,n\nprint p[i][j]==0?\"#{i-=1;\"H\"}\":\"#{j-=1;\"M\"}\"while[i,j].max>0\n\n"}, {"source_code": "n=gets.to_i\ns=gets.chomp.reverse.chars.map &:to_i\nd=(n+1).times.collect{[0]*(n+1)}\np=(n+1).times.collect{[0]*(n+1)}\n0.upto(n){|i|\n\t0.upto(n){|j|\n\t\tif i>0\n\t\t\ta=d[i-1][j]+10**(i-1)*s[i+j-1]\n\t\t\t\"#{d[i][j]=a; p[i][j]=0}\"if a>=d[i][j]\n\t\tend\n\t\tif j>0\n\t\t\ta=d[i][j-1]+10**(j-1)*s[i+j-1]\n\t\t\t\"#{d[i][j]=a;p[i][j]=1}\"if a>=d[i][j]\n\t\tend\n\t}\n}\ni,j=n,n\nprint p[i][j]==0?\"#{i-=1;\"H\"}\":\"#{j-=1;\"M\"}\"while[i,j].max>0\n\n"}, {"source_code": "n=gets.to_i\ns=gets.chomp.reverse.chars.map &:to_i\nd=(n+1).times.collect{[0]*(n+1)}\np=(n+1).times.collect{[0]*(n+1)}\n0.upto(n){|i|\n\t0.upto(n){|j|\n\t\tif i>0\n\t\t\ta=d[i-1][j]+10**(i-1)*s[i+j-1]\n\t\t\t\"#{d[i][j]=a; p[i][j]=0}\"if a>=d[i][j]\n\t\tend\n\t\tif j>0\n\t\t\ta=d[i][j-1]+10**(j-1)*s[i+j-1]\n\t\t\t\"#{d[i][j]=a;p[i][j]=1}\"if a>=d[i][j]\n\t\tend\n\t}\n}\ni,j=n,n\nprint p[i][j]==0?\"#{i-=1;\"H\"}\":\"#{j-=1;\"M\"}\"while[i,j].max>0\n\n"}, {"source_code": "n=gets.to_i\ns=gets.chomp.reverse.chars.map &:to_i\nd=(n+1).times.collect{[0]*(n+1)}\np=(n+1).times.collect{[0]*(n+1)}\n0.upto(n){|i|\n 0.upto(n){|j|\n if i>0\n a=d[i-1][j]+10**(i-1)*s[i+j-1]\n \"#{d[i][j]=a; p[i][j]=0}\"if a>=d[i][j]\n end\n if j>0\n a=d[i][j-1]+10**(j-1)*s[i+j-1]\n \"#{d[i][j]=a;p[i][j]=1}\"if a>=d[i][j]\n end\n }\n}\ni,j=n,n\nprint p[i][j]==0?\"#{i-=1;\"H\"}\":\"#{j-=1;\"M\"}\"while[i,j].max>0"}, {"source_code": "n=gets.to_i\ns=gets.chomp.reverse.chars.map &:to_i\nd=(n+1).times.collect{[0]*(n+1)}\np=(n+1).times.collect{[0]*(n+1)}\n0.upto(n){|i|\n\t0.upto(n){|j|\n\t\tif i>0\n\t\t\ta=d[i-1][j]+10**(i-1)*s[i+j-1]\n\t\t\t\"#{d[i][j]=a; p[i][j]=0}\"if a>=d[i][j]\n\t\tend\n\t\tif j>0\n\t\t\ta=d[i][j-1]+10**(j-1)*s[i+j-1]\n\t\t\t\"#{d[i][j]=a;p[i][j]=1}\"if a>=d[i][j]\n\t\tend\n\t}\n}\ni,j=n,n\nprint p[i][j]==0?\"#{i-=1;\"H\"}\":\"#{j-=1;\"M\"}\"while[i,j].max>0"}, {"source_code": "n=gets.to_i\ns=gets.chomp.reverse.chars.map &:to_i\nd=(n+1).times.collect{[0]*(n+1)}\np=(n+1).times.collect{[0]*(n+1)}\n0.upto(n){|i|\n\t0.upto(n){|j|\n\t\tif i>0\n\t\t\ta=d[i-1][j]+10**(i-1)*s[i+j-1]\n\t\t\t\"#{d[i][j]=a; p[i][j]=0}\"if a>=d[i][j]\n\t\tend\n\t\tif j>0\n\t\t\ta=d[i][j-1]+10**(j-1)*s[i+j-1]\n\t\t\t\"#{d[i][j]=a;p[i][j]=1}\"if a>=d[i][j]\n\t\tend\n\t}\n}\ni,j=n,n\nprint p[i][j]==0?\"#{i-=1;\"H\"}\":\"#{j-=1;\"M\"}\"while[i,j].max>0\n"}, {"source_code": "n=gets.to_i\ns=gets.chomp.reverse.chars.map &:to_i\nd=(n+1).times.collect{[0]*(n+1)}\np=(n+1).times.collect{[0]*(n+1)}\n0.upto(n){|i|\n\t0.upto(n){|j|\n\t\tif i>0\n\t\t\ta=d[i-1][j]+10**(i-1)*s[i+j-1]\n\t\t\t\"#{d[i][j]=a; p[i][j]=0}\"if a>=d[i][j]\n\t\tend\n\t\tif j>0\n\t\t\ta=d[i][j-1]+10**(j-1)*s[i+j-1]\n\t\t\t\"#{d[i][j]=a;p[i][j]=1}\"if a>=d[i][j]\n\t\tend\n\t}\n}\ni,j=n,n\nprint p[i][j]==0?\"#{i-=1;\"H\"}\":\"#{j-=1;\"M\"}\"while[i,j].max>0\n\n"}, {"source_code": "n=gets.to_i\ns=gets.chomp.reverse.chars.map &:to_i\nd=(n+1).times.collect{[0]*(n+1)}\np=(n+1).times.collect{[0]*(n+1)}\n0.upto(n){|i|\n\t0.upto(n){|j|\n\t\tif i>0\n\t\t\ta=d[i-1][j]+10**(i-1)*s[i+j-1]\n\t\t\t\"#{d[i][j]=a; p[i][j]=0}\"if a>=d[i][j]\n\t\tend\n\t\tif j>0\n\t\t\ta=d[i][j-1]+10**(j-1)*s[i+j-1]\n\t\t\t\"#{d[i][j]=a;p[i][j]=1}\"if a>=d[i][j]\n\t\tend\n\t}\n}\ni,j=n,n\nprint p[i][j]==0?\"#{i-=1;\"H\"}\":\"#{j-=1;\"M\"}\"while[i,j].max>0\n\n"}, {"source_code": "n=gets.to_i\ns=gets.chomp.reverse.chars.map &:to_i\nd=(n+1).times.collect{[0]*(n+1)}\np=(n+1).times.collect{[0]*(n+1)}\n0.upto(n){|i|\n\t0.upto(n){|j|\n\t\tif i>0\n\t\t\ta=d[i-1][j]+10**(i-1)*s[i+j-1]\n\t\t\t\"#{d[i][j]=a; p[i][j]=0}\"if a>=d[i][j]\n\t\tend\n\t\tif j>0\n\t\t\ta=d[i][j-1]+10**(j-1)*s[i+j-1]\n\t\t\t\"#{d[i][j]=a;p[i][j]=1}\"if a>=d[i][j]\n\t\tend\n\t}\n}\ni,j=n,n\nprint p[i][j]==0?\"#{i-=1;\"H\"}\":\"#{j-=1;\"M\"}\"while[i,j].max>0\n\n"}, {"source_code": "n=gets.to_i\ns=gets.chomp.reverse.chars.map &:to_i\nd=(n+1).times.collect{[0]*(n+1)}\np=(n+1).times.collect{[0]*(n+1)}\n0.upto(n){|i|\n\t0.upto(n){|j|\n\t\tif i>0\n\t\t\ta=d[i-1][j]+10**(i-1)*s[i+j-1]\n\t\t\t\"#{d[i][j]=a; p[i][j]=0}\"if a>=d[i][j]\n\t\tend\n\t\tif j>0\n\t\t\ta=d[i][j-1]+10**(j-1)*s[i+j-1]\n\t\t\t\"#{d[i][j]=a;p[i][j]=1}\"if a>=d[i][j]\n\t\tend\n\t}\n}\ni,j=n,n\nprint p[i][j]==0?\"#{i-=1;\"H\"}\":\"#{j-=1;\"M\"}\"while[i,j].max>0\n\n"}], "negative_code": [{"source_code": "$n = gets.chomp.to_i\n$s = gets.chomp\n\ndef calc1(n,s)\nhs = \"\"\nms = \"\"\nret = \"\"\nwhile s.length > 0\n\tif hs.length == ms.length\n\t\ths += s.slice!(0,1)\n\t\tret += \"H\"\n\telse\n\t\tmidx = 0\n\t\tmval = \" \"\n\t\tcont = false\n\t\tfor i in 0..(n-hs.length)\n\t\t\tif mval < s[i]\n\t\t\t\tmval = s[i]\n\t\t\t\tmidx = i\n\t\t\t\tcont = true\n\t\t\telsif mval == s[i]\n\t\t\t\tif not cont\n\t\t\t\t\tnclen = i - midx - 1\n\t\t\t\t\tbstr = s.slice(midx+1,nclen)\n\t\t\t\t\tastr = s.slice(i+1, nclen)\n\t\t\t\t\tif bstr < astr\n\t\t\t\t\t\tmval = s[i]\n\t\t\t\t\t\tmidx = i\n\t\t\t\t\tend\n\t\t\t\tend\n\t\t\telse\n\t\t\t\tcont = false\n\t\t\tend\n\t\tend\n\t\twhile midx > 0\n\t\t\ths += s.slice!(0,1)\n\t\t\tret += \"H\"\n\t\t\tmidx -= 1\n\t\tend\n\t\tms += s.slice!(0,1)\n\t\tret += \"M\"\n\tend\nend\nreturn ret\nend\n\nputs calc1($n,$s.dup)\n"}, {"source_code": "n = gets.chomp.to_i\ns = gets.chomp\n\nhs = \"\"\nms = \"\"\nret = \"\"\n\nwhile s.length > 0\n\tif hs.length == ms.length\n\t\ths += s.slice!(0,1)\n\t\tret += \"H\"\n\telse\n\t\tmidx = 0\n\t\tmval = \" \"\n\t\tfor i in 0..(n-hs.length)\n\t\t\tif mval < s[i]\n\t\t\t\tmval = s[i]\n\t\t\t\tmidx = i\n\t\t\tend\n\t\tend\n\t\twhile midx > 0\n\t\t\ths += s.slice!(0,1)\n\t\t\tret += \"H\"\n\t\t\tmidx -= 1\n\t\tend\n\t\tms += s.slice!(0,1)\n\t\tret += \"M\"\n\tend\nend\nputs ret\n"}, {"source_code": "n = gets.chomp.to_i\ns = gets.chomp\n\nhs = \"\"\nms = \"\"\nret = \"\"\n\nwhile s.length > 0\n\tif hs.length == ms.length\n\t\ths += s.slice!(0,1)\n\t\tret += \"H\"\n\telse\n\t\tmidx = 0\n\t\tmval = \" \"\n\t\tfor i in 0..(n-hs.length)\n\t\t\tif mval < s[i]\n\t\t\t\tmval = s[i]\n\t\t\t\tmidx = i\n\t\t\tend\n\t\tend\n\t\twhile midx > 0\n\t\t\ths += s.slice!(0,1)\n\t\t\tret += \"H\"\n\t\t\tmidx -= 1\n\t\tend\n\t\tms += s.slice!(0,1)\n\t\tret += \"M\"\n\tend\nend\nputs ret\n"}, {"source_code": "$n = gets.chomp.to_i\n$s = gets.chomp\n\ndef calc1(n,s)\nhs = \"\"\nms = \"\"\nret = \"\"\nwhile s.length > 0\n\tif hs.length == ms.length\n\t\ths += s.slice!(0,1)\n\t\tret += \"H\"\n\telse\n\t\tmidx = 0\n\t\tmval = \" \"\n\t\tcont = false\n\t\tfor i in 0..(n-hs.length)\n\t\t\tif mval < s[i]\n\t\t\t\tmval = s[i]\n\t\t\t\tmidx = i\n\t\t\t\tcont = true\n\t\t\telsif mval == s[i]\n\t\t\t\tif not cont\n\t\t\t\t\tnclen = i - midx - 1\n\t\t\t\t\tbstr = s.slice(midx+1,nclen)\n\t\t\t\t\tastr = s.slice(i+1, nclen)\n\t\t\t\t\tif bstr <= astr\n\t\t\t\t\t\tmval = s[i]\n\t\t\t\t\t\tmidx = i\n\t\t\t\t\tend\n\t\t\t\tend\n\t\t\telse\n\t\t\t\tcont = false\n\t\t\tend\n\t\tend\n\t\twhile midx > 0\n\t\t\ths += s.slice!(0,1)\n\t\t\tret += \"H\"\n\t\t\tmidx -= 1\n\t\tend\n\t\tms += s.slice!(0,1)\n\t\tret += \"M\"\n\tend\nend\nreturn ret\nend\n\nputs calc1($n,$s.dup)\n"}, {"source_code": "n=gets.to_i\ns=gets.chomp.reverse.chars.map &:to_i\nd=(n+1).times.collect{[0]*(n+1)}\np=(n+1).times.collect{[0]*(n+1)}\n0.upto(n){|i|\n\t0.upto(n){|j|\n\t\tif i>0\n\t\t\ta=d[i-1][j]+10**(i-1)*s[i+j-1]\n\t\t\t\"#{d[i][j]=a; p[i][j]=0}\"if a>d[i][j]\n\t\tend\n\t\tif j>0\n\t\t\ta=d[i][j-1]+10**(j-1)*s[i+j-1]\n\t\t\t\"#{d[i][j]=a;p[i][j]=1}\"if a>d[i][j]\n\t\tend\n\t}\n}\ni,j=n,n\nprint p[i][j]==0?\"#{i-=1;\"H\"}\":\"#{j-=1;\"M\"}\"while[i,j].max>0\n"}], "src_uid": "98489fe54488dcfb45f8ae7b5c473d88"} {"nl": {"description": "You have a given integer $$$n$$$. Find the number of ways to fill all $$$3 \\times n$$$ tiles with the shape described in the picture below. Upon filling, no empty spaces are allowed. Shapes cannot overlap. This picture describes when $$$n = 4$$$. The left one is the shape and the right one is $$$3 \\times n$$$ tiles. ", "input_spec": "The only line contains one integer $$$n$$$ ($$$1 \\le n \\le 60$$$)\u00a0\u2014 the length.", "output_spec": "Print the number of ways to fill.", "sample_inputs": ["4", "1"], "sample_outputs": ["4", "0"], "notes": "NoteIn the first example, there are $$$4$$$ possible cases of filling.In the second example, you cannot fill the shapes in $$$3 \\times 1$$$ tiles."}, "positive_code": [{"source_code": "n = gets.to_i\np n % 2 == 0 ? 2**(n/2) : 0"}, {"source_code": "# coding: utf-8\n\nn = gets.to_i\n\n# 3 x n grid with '\u3134'-shaped tile\n\nif n.odd?\n puts \"0\"\nelse\n puts 2**(n/2)\nend"}, {"source_code": "n=gets.to_i\nif n%2==1\nputs 0\nelse\nputs 2**(n/2)\nend\n"}, {"source_code": "n = gets.chomp!.to_i\n\nputs (n < 2 ? 0 : (n.even? ? (2 ** (n / 2)) : 0)) \n"}, {"source_code": "n=gets.to_i\nif n.odd?\n p 0\nelse\n p 2**(n/2)\nend\n"}, {"source_code": "n = gets.to_i\nputs n % 2 == 0 ? 2**(n/2) : 0"}], "negative_code": [{"source_code": "n = gets.chomp!.to_i\n\nans = (n < 2 ? 0 : 2**(n/2))\n\nputs ans "}, {"source_code": "n = gets.chomp!.to_i\n\nans = 0 if n < 2\n\nans = 2 ** (n / 2) if n.even?\n\nans = 2 ** ((n - 1)/2)\n\nputs ans\n"}, {"source_code": "n = gets.chomp!.to_i\n\nputs (n < 2 ? 0 : (n.even? ? (2 ** (n / 2)) : (2 ** ((n - 1)/2))))\n"}, {"source_code": "p gets.to_i/2*2\n"}], "src_uid": "4b7ff467ed5907e32fd529fb39b708db"} {"nl": {"description": "InputThe input contains a single integer a (1\u2009\u2264\u2009a\u2009\u2264\u200964).OutputOutput a single integer.ExamplesInput2Output1Input4Output2Input27Output5Input42Output6", "input_spec": "The input contains a single integer a (1\u2009\u2264\u2009a\u2009\u2264\u200964).", "output_spec": "Output a single integer.", "sample_inputs": ["2", "4", "27", "42"], "sample_outputs": ["1", "2", "5", "6"], "notes": null}, "positive_code": [{"source_code": "#!/usr/bin/ruby\np [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51, 1, 2, 1, 14, 1, 2, 2, 14, 1, 6, 1, 4, 2, 2, 1, 52, 2, 5, 1, 5, 1, 15, 2, 13, 2, 2, 1, 13, 1, 2, 4, 267][gets.to_i-1]"}], "negative_code": [], "src_uid": "c50b6af99ca7b9c35628b52774d6c32b"} {"nl": {"description": "A bus moves along the coordinate line Ox from the point x\u2009=\u20090 to the point x\u2009=\u2009a. After starting from the point x\u2009=\u20090, it reaches the point x\u2009=\u2009a, immediately turns back and then moves to the point x\u2009=\u20090. After returning to the point x\u2009=\u20090 it immediately goes back to the point x\u2009=\u2009a and so on. Thus, the bus moves from x\u2009=\u20090 to x\u2009=\u2009a and back. Moving from the point x\u2009=\u20090 to x\u2009=\u2009a or from the point x\u2009=\u2009a to x\u2009=\u20090 is called a bus journey. In total, the bus must make k journeys.The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank.There is a gas station in point x\u2009=\u2009f. This point is between points x\u2009=\u20090 and x\u2009=\u2009a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline.What is the minimum number of times the bus needs to refuel at the point x\u2009=\u2009f to make k journeys? The first journey starts in the point x\u2009=\u20090.", "input_spec": "The first line contains four integers a, b, f, k (0\u2009<\u2009f\u2009<\u2009a\u2009\u2264\u2009106, 1\u2009\u2264\u2009b\u2009\u2264\u2009109, 1\u2009\u2264\u2009k\u2009\u2264\u2009104) \u2014 the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys.", "output_spec": "Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1.", "sample_inputs": ["6 9 2 4", "6 10 2 4", "6 5 4 3"], "sample_outputs": ["4", "2", "-1"], "notes": "NoteIn the first example the bus needs to refuel during each journey.In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty. In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling."}, "positive_code": [{"source_code": "a, b, f, k = gets.split.map{|x| x.to_i}\n\nd = [f]\n(1...k).each do |i|\n\td << 2 * (a - f) if i.odd?\n\td << 2 * f if i.even?\nend\nd << (a - f) if k.odd?\nd << f if k.even?\nd << -1\n\ncurB = b\nans = 0\nd.each_with_index do |l, j|\n\tbreak if l == -1\n\n\tcurB -= l\n\t\n\tif curB < 0\n\t\tp -1\n\t\texit(0)\n\telsif curB < d[j + 1]\n\t\tcurB = b;\n\t\tans += 1;\n\tend\n\t\nend\n\np ans"}, {"source_code": "a, b, f, k = gets.split.map(&:to_i)\nu, v, t, r = (a-f)*2, f*2, b, 0\nEnumerator.new do |y|\n y.yield f\n ((k-1)/2).times {\n y.yield u\n y.yield v\n }\n if k&1 == 0\n y.yield u\n y.yield f\n else\n y.yield a-f\n end\nend.each do |s|\n if t < s\n t = b\n r += 1\n if t < s\n r = -1\n break\n end\n end\n t -= s\nend\np r"}, {"source_code": "a, b, f, k = gets.split.map(&:to_i)\nstep = Enumerator.new do |y|\n y.yield f\n u, v = (a-f)*2, f*2\n ((k-1)/2).times {\n y.yield u\n y.yield v\n }\n if k&1 == 0\n y.yield u\n y.yield f\n else\n y.yield a-f\n end\nend\nt, r = b, 0\nstep.each do |s|\n if t < s\n t = b\n r += 1\n if t < s\n r = -1\n break\n end\n end\n t -= s\nend\np r"}], "negative_code": [], "src_uid": "283aff24320c6518e8518d4b045e1eca"} {"nl": {"description": "Gaius Julius Caesar, a famous general, loved to line up his soldiers. Overall the army had n1 footmen and n2 horsemen. Caesar thought that an arrangement is not beautiful if somewhere in the line there are strictly more that k1 footmen standing successively one after another, or there are strictly more than k2 horsemen standing successively one after another. Find the number of beautiful arrangements of the soldiers. Note that all n1\u2009+\u2009n2 warriors should be present at each arrangement. All footmen are considered indistinguishable among themselves. Similarly, all horsemen are considered indistinguishable among themselves.", "input_spec": "The only line contains four space-separated integers n1, n2, k1, k2 (1\u2009\u2264\u2009n1,\u2009n2\u2009\u2264\u2009100,\u20091\u2009\u2264\u2009k1,\u2009k2\u2009\u2264\u200910) which represent how many footmen and horsemen there are and the largest acceptable number of footmen and horsemen standing in succession, correspondingly.", "output_spec": "Print the number of beautiful arrangements of the army modulo 100000000 (108). That is, print the number of such ways to line up the soldiers, that no more than k1 footmen stand successively, and no more than k2 horsemen stand successively.", "sample_inputs": ["2 1 1 10", "2 3 1 2", "2 4 1 1"], "sample_outputs": ["1", "5", "0"], "notes": "NoteLet's mark a footman as 1, and a horseman as 2.In the first sample the only beautiful line-up is: 121In the second sample 5 beautiful line-ups exist: 12122, 12212, 21212, 21221, 22121"}, "positive_code": [{"source_code": "input=gets.split.map(&:to_i)\n\n$n1=input[0]\n$n2=input[1]\n$k1=input[2]+1\n$k2=input[3]+1\n$dp=Array.new(101){Array.new(101){Array.new(20){Array.new(3,-1)}}}\ndef solve(c1,c2,s,t)\n\n if c1>$n1 || c2>$n2 then\n return 0\n end\n if c1==$n1 && c2==$n2 then\n return 1\n end\n if $dp[c1][c2][s][t]>=0 then\n return $dp[c1][c2][s][t]\n end\n #1\u3092\u7f6e\u304f\n ans=0\n if t==0 then\n if s+1<$k1 then\n ans+=solve(c1+1,c2,s+1,t)\n end\n else\n ans+=solve(c1+1,c2,1,0)\n end\n\n #2\u3092\u7f6e\u304f\n if t==1 then\n if s+1<$k2 then\n ans+=solve(c1,c2+1,s+1,t)\n end\n else\n ans+=solve(c1,c2+1,1,1)\n end\n ans%=100000000\n $dp[c1][c2][s][t]=ans\n return ans\nend\n\np solve(0,0,0,0)"}, {"source_code": "def solution(n1, n2, k1, k2, flag)\n return 1 if n1 == 0 && n2 == 0\n\n return 0 if n1 == 0 && flag\n return 0 if n2 == 0 && !flag\n\n if flag\n return @beging_with_soldiers[n1][n2] if @beging_with_soldiers[n1][n2]\n else\n return @beging_with_horses[n1][n2] if @beging_with_horses[n1][n2]\n end\n\n k = 1\n possibilities = 0\n if flag\n while k <= k1 && n1 - k >= 0 do\n possibilities += solution(n1-k, n2, k1, k2, !flag)\n k += 1\n end\n else\n while k <= k2 && n2 - k >= 0 do\n possibilities += solution(n1, n2-k, k1, k2, !flag)\n k += 1\n end\n end\n\n possibilities = possibilities % 100000000\n if flag\n @beging_with_soldiers[n1][n2] = possibilities\n else\n @beging_with_horses[n1][n2] = possibilities\n end\n possibilities\nend\n\nn1, n2, k1, k2 = gets.strip().split().map(&:to_i)\n\nmax_n = [n1, n2].max + 1\n@beging_with_soldiers = Array.new(max_n) { Array.new(max_n) { false } }\n@beging_with_horses = Array.new(max_n) { Array.new(max_n) { false } }\n\nsolution(n1, n2, k1, k2, true)\nsolution(n1, n2, k1, k2, false)\nputs (@beging_with_soldiers[n1][n2] + @beging_with_horses[n1][n2]) % 100000000\n"}, {"source_code": "n1,n2,k1,k2=gets.split.map(&:to_i)\nn1,n2,k1,k2=n2,n1,k2,k1 if n1>n2\nM=100000000\ndp1=Array.new(205){Array.new(105,0)}\ndp2=Array.new(205){Array.new(105,0)}\n1.upto(k1){|m|dp1[m][1]=1}\n1.upto(k2){|m|dp2[m][1]=1}\n2.upto(n1){|j|1.upto(n1){|m|dp1[m][j]=(m-k1).upto(m-1).map{|i|dp1[i][j-1]}.inject(:+)%M}}\n2.upto(n2){|j|1.upto(n2){|m|dp2[m][j]=(m-k2).upto(m-1).map{|i|dp2[i][j-1]}.inject(:+)%M}}\nans=0\n1.upto(n1){|j|ans=(ans+2*dp1[n1][j]*dp2[n2][j]+dp1[n1][j-1]*dp2[n2][j]+dp1[n1][j]*dp2[n2][j-1])%M}\nans=(ans+dp1[n1][n1]*dp2[n2][n1+1])%M if n1!=n2\np ans"}], "negative_code": [{"source_code": "def solution(n1, n2, k1, k2, flag)\n return 1 if n1 == 0 && n2 == 0\n\n return 0 if n1 == 0 && flag\n return 0 if n2 == 0 && !flag\n\n if flag\n return @beging_with_soldiers[n1][n2] if @beging_with_soldiers[n1][n2]\n else\n return @beging_with_horses[n1][n2] if @beging_with_horses[n1][n2]\n end\n\n k = 1\n possibilities = 0\n if flag\n while k <= k1 && n1 - k >= 0 do\n possibilities += solution(n1-k, n2, k1, k2, !flag)\n k += 1\n end\n else\n while k <= k2 && n2 - k >= 0 do\n possibilities += solution(n1, n2-k, k1, k2, !flag)\n k += 1\n end\n end\n\n if flag\n @beging_with_soldiers[n1][n2] = possibilities\n else\n @beging_with_horses[n1][n2] = possibilities\n end\n possibilities\nend\n\nn1, n2, k1, k2 = gets.strip().split().map(&:to_i)\n\nmax_n = [n1, n2].max + 1\n@beging_with_soldiers = Array.new(max_n) { Array.new(max_n) { false } }\n@beging_with_horses = Array.new(max_n) { Array.new(max_n) { false } }\n\nsolution(n1, n2, k1, k2, true)\nsolution(n1, n2, k1, k2, false)\nputs @beging_with_soldiers[n1][n2] + @beging_with_horses[n1][n2]\n\n"}, {"source_code": "def solve(a, b, a_max, b_max)\n @posibilities = Array.new(2, Array.new(a+1, Array.new(b+1, false)))\n @posibilities[0][1][0] = 1\n @posibilities[1][0][1] = 1\n\n def solution(a, b, a_max, b_max, flag)\n return @posibilities[flag][a][b] if @posibilities[flag][a][b]\n\n return 1 if (a == 0 && b == 0)\n\n posibilities_count = 0\n if flag == 0\n for i in 1..a_max do\n posibilities_count += solution(a-i, b, a_max, b_max, 1) if (a-i >= 0)\n end\n else\n for i in 1..b_max do\n posibilities_count += solution(a, b-i, a_max, b_max, 0) if (b-i >= 0)\n end\n end\n\n @posibilities[flag][a][b] = posibilities_count\n posibilities_count\n end\n solution(a, b, a_max, b_max, 0)\n solution(a, b, a_max, b_max, 1)\n @posibilities[0][a][b]\nend\n\nputs solve(*gets.split.map(&:to_i))"}, {"source_code": "def solution(n1, n2, k1, k2, flag)\n return 1 if n1 == 0 && n2 == 0\n\n return 0 if n1 == 0 && flag\n return 0 if n2 == 0 && !flag\n\n if flag\n return @beging_with_soldiers[n1][n2] if @beging_with_soldiers[n1][n2]\n else\n return @beging_with_horses[n1][n2] if @beging_with_horses[n1][n2]\n end\n\n k = 1\n possibilities = 0\n if flag\n while k <= k1 && n1 - k >= 0 do\n possibilities += solution(n1-k, n2, k1, k2, !flag)\n k += 1\n end\n else\n while k <= k2 && n2 - k >= 0 do\n possibilities += solution(n1, n2-k, k1, k2, !flag)\n k += 1\n end\n end\n\n possibilities = possibilities % 100000000\n if flag\n @beging_with_soldiers[n1][n2] = possibilities\n else\n @beging_with_horses[n1][n2] = possibilities\n end\n possibilities\nend\n\nn1, n2, k1, k2 = gets.strip().split().map(&:to_i)\n\nmax_n = [n1, n2].max + 1\n@beging_with_soldiers = Array.new(max_n) { Array.new(max_n) { false } }\n@beging_with_horses = Array.new(max_n) { Array.new(max_n) { false } }\n\nsolution(n1, n2, k1, k2, true)\nsolution(n1, n2, k1, k2, false)\nputs @beging_with_soldiers[n1][n2] + @beging_with_horses[n1][n2]\n"}], "src_uid": "63aabef26fe008e4c6fc9336eb038289"} {"nl": {"description": "Luba has to do n chores today. i-th chore takes ai units of time to complete. It is guaranteed that for every the condition ai\u2009\u2265\u2009ai\u2009-\u20091 is met, so the sequence is sorted.Also Luba can work really hard on some chores. She can choose not more than k any chores and do each of them in x units of time instead of ai ().Luba is very responsible, so she has to do all n chores, and now she wants to know the minimum time she needs to do everything. Luba cannot do two chores simultaneously.", "input_spec": "The first line contains three integers n,\u2009k,\u2009x\u00a0(1\u2009\u2264\u2009k\u2009\u2264\u2009n\u2009\u2264\u2009100,\u20091\u2009\u2264\u2009x\u2009\u2264\u200999) \u2014 the number of chores Luba has to do, the number of chores she can do in x units of time, and the number x itself. The second line contains n integer numbers ai\u00a0(2\u2009\u2264\u2009ai\u2009\u2264\u2009100) \u2014 the time Luba has to spend to do i-th chore. It is guaranteed that , and for each ai\u2009\u2265\u2009ai\u2009-\u20091.", "output_spec": "Print one number \u2014 minimum time Luba needs to do all n chores.", "sample_inputs": ["4 2 2\n3 6 7 10", "5 2 1\n100 100 100 100 100"], "sample_outputs": ["13", "302"], "notes": "NoteIn the first example the best option would be to do the third and the fourth chore, spending x\u2009=\u20092 time on each instead of a3 and a4, respectively. Then the answer is 3\u2009+\u20096\u2009+\u20092\u2009+\u20092\u2009=\u200913.In the second example Luba can choose any two chores to spend x time on them instead of ai. So the answer is 100\u00b73\u2009+\u20092\u00b71\u2009=\u2009302."}, "positive_code": [{"source_code": "n, k, x = gets.split.map{|i| i.to_i}\narr = gets.split.map{|i| i.to_i}\n\nans = k * x\n\n(n - k).times{|i| ans += arr[i]}\n\np ans"}, {"source_code": "n,k,x,*a=$<.read.split.map &:to_i\nk=n if k>n\np a[0...-k].reduce(0,:+)+k*x"}, {"source_code": "n, k, x = gets.strip.split.map(&:to_i)\na = gets.strip.split.map(&:to_i)\nspecial = n - k\nans = 0\nn.times do |i|\n if i < special\n ans += a[i]\n else\n ans += x\n end\nend\nputs ans\n"}, {"source_code": "n, k, x = gets.split.map &:to_i\na = gets.split.map &:to_i\nif k < n\n puts (a[0...n-k].inject &:+) + k * x\nelse\n puts k * x\nend"}, {"source_code": "n, k, x = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\nans = 0\n1.upto(n) do |i|\n if i <= k\n ans += x\n else\n ans += a[-i]\n end\nend\nputs ans"}, {"source_code": "n, k, x = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\nfor i in 1 .. k\n a[-i] = [a[-i], x].min\nend\nputs a.reduce(:+)\n"}], "negative_code": [], "src_uid": "92a233f8d9c73d9f33e4e6116b7d0a96"} {"nl": {"description": "While playing with geometric figures Alex has accidentally invented a concept of a $$$n$$$-th order rhombus in a cell grid.A $$$1$$$-st order rhombus is just a square $$$1 \\times 1$$$ (i.e just a cell).A $$$n$$$-th order rhombus for all $$$n \\geq 2$$$ one obtains from a $$$n-1$$$-th order rhombus adding all cells which have a common side with it to it (look at the picture to understand it better). Alex asks you to compute the number of cells in a $$$n$$$-th order rhombus.", "input_spec": "The first and only input line contains integer $$$n$$$ ($$$1 \\leq n \\leq 100$$$)\u00a0\u2014 order of a rhombus whose numbers of cells should be computed.", "output_spec": "Print exactly one integer\u00a0\u2014 the number of cells in a $$$n$$$-th order rhombus.", "sample_inputs": ["1", "2", "3"], "sample_outputs": ["1", "5", "13"], "notes": "NoteImages of rhombus corresponding to the examples are given in the statement."}, "positive_code": [{"source_code": "n = gets.chomp.to_i\n\ndef solve(n)\n dp = [0] * (n + 1)\n dp[1] = 1\n for i in 2...n+1 do\n dp[i] = dp[i-1] + 4*(i-1)\n end\n return dp[n]\nend\n\nputs solve(n)\n"}, {"source_code": "n = gets.to_i\nans = 2*n-1\n(n-1).times do |i|\n ans += (i*2+1)*2\nend\np ans"}, {"source_code": "a=gets.to_i\nprint a*(a-1)*2+1"}, {"source_code": "n = gets.to_i\nans = Array.new(n, 0)\nans[0] = 1\n(1..n-1).each do |i|\n ans[i] = ans[i-1] + 4 * i\nend\nputs ans[n-1]"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\nn = gets.to_i\n\nputs n*n*2 - (2*n - 1)"}, {"source_code": "n = gets.to_i\nans = 1\n(2..n).each { |x| ans += 2*x + 2*(x - 2) }\nputs ans\n"}], "negative_code": [{"source_code": "n = gets.chomp.to_i\n\ndef solve(n)\n dp = [0] * (n + 1)\n dp[1] = 1\n for i in 2...n+1 do\n dp[i] = dp[i-1] + 2**i\n end\n return dp[n]\nend\n\nputs solve(n)\n"}, {"source_code": "n = gets.to_i\np n==1 ? 1 : (2*n-3)**2+4"}], "src_uid": "758d342c1badde6d0b4db81285be780c"} {"nl": {"description": "A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.The next prime number after x is the smallest prime number greater than x. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note that there is exactly one next prime number after each number. So 5 is\u00a0not the next prime number for 2.One cold April morning Panoramix predicted that soon Kakofonix will break free from his straitjacket, and this will be a black day for the residents of the Gallic countryside.Panoramix's prophecy tells that if some day Asterix and Obelix beat exactly x Roman soldiers, where x is a prime number, and next day they beat exactly y Roman soldiers, where y is the next prime number after x, then it's time to wait for Armageddon, for nothing can shut Kakofonix up while he sings his infernal song.Yesterday the Gauls beat n Roman soldiers and it turned out that the number n was prime! Today their victims were a troop of m Romans (m\u2009>\u2009n). Determine whether the Gauls should wait for the black day after today's victory of Asterix and Obelix?", "input_spec": "The first and only input line contains two positive integers \u2014 n and m (2\u2009\u2264\u2009n\u2009<\u2009m\u2009\u2264\u200950). It is guaranteed that n is prime. Pretests contain all the cases with restrictions 2\u2009\u2264\u2009n\u2009<\u2009m\u2009\u2264\u20094.", "output_spec": "Print YES, if m is the next prime number after n, or NO otherwise.", "sample_inputs": ["3 5", "7 11", "7 9"], "sample_outputs": ["YES", "YES", "NO"], "notes": null}, "positive_code": [{"source_code": "n,m=gets.split.map(&:to_i)\nputs m==(n+1..m).find{|i|2**i%i==2}?\"YES\":\"NO\"\n"}, {"source_code": "require 'prime'\nx, y = gets.split.map(&:to_i)\nputs Prime.find{|_| _ > x} == y ? :YES : :NO\n"}, {"source_code": "input = gets.split.map {|e| e.to_i}\nMAX = 50\nsieve = []\nfor i in 2 .. MAX\n sieve[i] = i\nend\nfor i in 2 .. Math.sqrt(MAX)\n next unless sieve[i]\n (i*i).step(MAX, i) do |j|\n\n sieve[j] = nil\n end\nend\nsieve.compact!\n\nfor i in 0 .. sieve.size\n if input[0] == sieve[i] \n puts input[1] == sieve[i+1] ? \"YES\" : \"NO\"\n exit\n end\nend\n"}, {"source_code": "\nrequire 'prime'\ninput=gets.split.map(&:to_i)\np=Prime.take(50)\nres=\"NO\"\nfor i in 0..49\n if p[i]==input[0] && p[i+1]==input[1] then\n res=\"YES\"\n end\nend\n\nputs res\n"}, {"source_code": "n,m=gets.split.map(&:to_i)\nputs m==[*n+1..m].find{|_|2**_%_==2}?\"YES\":\"NO\"\n"}, {"source_code": "#!/usr/bin/ruby\n\nprimes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]\n\nn, m = gets.split.map { |e| e.to_i }\n\nputs primes.include?( m ) && primes.index(m) == primes.index(n)+1 ? \"YES\" : \"NO\"\n\n"}, {"source_code": "#!/usr/bin/ruby\n# http://codeforces.ru/contest/80/problem/A\n\n[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47].tap { |primes| gets.split.map { |e| primes.index(e.to_i) }.tap { |a| puts a[1] == a[0]+1 ? 'YES' : 'NO' } }\n\n"}, {"source_code": "n,m=gets.split.map(&:to_i)\nputs m==[*n+1..m].find{|_|2**_%_==2}?\"YES\":\"NO\"\n"}, {"source_code": "def attack(n,m)\n primes = []\n (n..m).each do |i|\n next if i > 2 && i % 2 == 0\n divisors = []\n (1..i).each {|x| divisors << x if i % x == 0 }\n if divisors.size == 2 && divisors.include?(1) && divisors.include?(i)\n primes << i\n end\n end\n x = primes.index(n)\n return \"YES\" if primes[x+1] == m\n \"NO\"\nend\n\nn,m = gets.split(\" \").map(&:to_i)\nputs attack(n,m)"}, {"source_code": "require 'prime'\n\n# TEMPLATE BEGIN\ndef read_vector\n gets.chomp.split(/\\s+/)\nend\ndef read_vector_int\n read_vector.map(&:to_i)\nend\n# TEMPLATE END\n\nn, m = read_vector_int\n\ndef no()\n puts \"NO\"\n exit 0\nend\n\ndef yes()\n puts \"YES\"\n exit 0\nend\n\nno() unless n.prime?\nno() unless m.prime?\nno() if (n..m).map{ |i| i.prime? }.count(true) > 2\n\nyes()\n"}, {"source_code": "n,m=gets.split.map(&:to_i)\nputs m==[*n+1..m].find{|_|2**_%_==2}?\"YES\":\"NO\""}, {"source_code": "require 'mathn'\nn, m = gets.split.map(&:to_i)\nputs (n.prime? and m.prime? and (n+1...m).find_all(&:prime?).size == 0) ? :YES : :NO"}, {"source_code": "n,m=gets.split.map(&:to_i)\nputs m==[*n+1..m].find{|_|2**_%_==2}?\"YES\":\"NO\"\n"}, {"source_code": "require 'prime'\n\nn, m = gets.split.map(&:to_i)\n\nunless m.prime?\n puts 'NO'\n exit\nend\n\nans = 'YES'\n((n+1)..m).each do |i|\n if i.prime? && i != m\n ans = 'NO'\n end\nend\nputs ans\n"}, {"source_code": "n,m=gets.split.map(&:to_i)\nputs m==[*n+1..m].find{|_|2**_%_==2}?\"YES\":\"NO\"\n"}, {"source_code": "def prime?( x )\n return false if x <= 1\n (2..x).each do |i|\n break if i * i > x\n return false if x % i == 0\n end\n return true\nend\ndef next_prime( x )\n n = x + 1\n while !prime? n\n n += 1\n end\n n\nend\nn, m = gets.strip.split.map(&:to_i)\nans = \"NO\"\na = next_prime n\nans = \"YES\" if a == m\nputs ans\n"}, {"source_code": "require \"Prime\"\na=gets.chomp.split(\" \")\nf=a[0].to_i\ns=a[1].to_i\nif !(Prime.prime?(s))\nputs \"NO\"\nelse\ntemp=[]\nPrime.each(s) do |i|\ntemp << i\nend\nk=temp.index(f)+1\nif temp[k]==s\nputs \"YES\"\nelse\nputs \"NO\"\nend\nend\n"}, {"source_code": "require 'prime'\na,b=gets.split.map{|e| e.to_i}\nif Prime.each(50).each_cons(2).select{|p,r| true}.index([a,b])!=nil then\n\tputs \"YES\"\nelse\n\tputs \"NO\"\nend\n"}, {"source_code": "include Math\n\ndef isprime?(n) # 41: Sorry, no caching\n return false if n <= 0\n limit = sqrt(n).to_i # correct?\n 2.upto(limit) {|i|\n return false if n % i == 0\n }\n return true\nend\n\nN, M = gets.split.map{|e| e.to_i}\nnext_prime = -1\n(N + 1).upto(51) {|i|\n if (isprime?(i))\n next_prime = i\n break\n end\n}\n#p [next_prime, M]\n \nif (M == next_prime)\n puts \"YES\"\nelse\n puts \"NO\"\nend\n\n \n"}, {"source_code": "require \"mathn\"\n\narray = gets.split(/ /)\n\nflag = false\nflag2 = false\n\nPrime.new.each{|x|\n if flag2 == true\n if array[1].to_i == x\n puts \"YES\"\n break\n else\n puts \"NO\"\n break\n end\n end\n\n if array[0].to_i == x\n flag = true\n end\n if flag == true\n flag2 = true\n end\n\n}\n"}, {"source_code": "n,m=gets.split.map(&:to_i)\nputs m==[*n+1..m].find{|_|2**_%_==2}?\"YES\":\"NO\""}, {"source_code": "require 'prime'\n#-------------------\n\nn,m=gets.split.map(&:to_i)\n\nflag=false\nfor i in n+1..m\n\tif i.prime?\n\t\t(i==m) ? (puts \"YES\") : (puts \"NO\")\n\t\tflag=true\n\t\tbreak\n\tend\nend\n\nputs \"NO\" if !flag\n"}, {"source_code": "require'prime'\nx,y=gets.split.map &:to_i\nputs Prime.find{|_|_>x}==y ?:YES:\"NO\""}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\nn, m = gets.split.map(&:to_i)\nprimes = [2,3]\ncount_primes = 0\nis_prime = true\n\ni = primes.last\nwhile i <= m\n is_prime = true\n for j in primes\n if i%j == 0\n is_prime = false\n break\n end\n end\n\n if is_prime\n primes << i\n end\n\n i += 1\nend\n\nn_idx = primes.index(n)\nm_idx = primes.index(m)\n\nif m_idx == nil\n puts \"NO\"\nelse\n if m_idx - n_idx != 1\n puts \"NO\"\n else\n puts \"YES\"\n end\nend"}, {"source_code": "n,m=gets.split.map(&:to_i)\nputs m==[*n+1..m].find{|_|2**_%_==2}?\"YES\":\"NO\"\n"}, {"source_code": "s=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47]\nn,m=gets.split.map &:to_i \nputs s[s.index(n).to_i+1]==m ?\"YES\":\"NO\""}, {"source_code": "sieve = Array.new(51, true)\nprimes = []\n\n(2..50).each do |p|\n next unless sieve[p]\n primes << p\n i = p*p\n while(i<=50) do\n sieve[i] = false\n i += p\n end\nend\n\nn,m = gets.split(/\\s+/).map(&:to_i)\nk = primes.index(n)\nputs (primes[k+1] == m) ? \"YES\" : \"NO\"\n"}, {"source_code": "def is_prime(x)\n return true if x < 0\n 2.upto(x-1) do |i|\n return false if x % i == 0\n end\n return true\nend\n\nn,m = gets.strip.split(' ').map(&:to_i)\nif !is_prime(m)\n print \"NO\"\n exit\nend\n(n+1).upto(m-1) do |i|\n if is_prime(i)\n print \"NO\"\n exit\n end\nend\nprint \"YES\"\n"}, {"source_code": "n,m=gets.split.map(&:to_i)\nputs m==[*n+1..m].find{|_|2**_%_==2}?\"YES\":\"NO\"\n"}, {"source_code": "# Codeforces Beta Round #69\n# Problem A -- Panoramix's Prediction\ndef is_prime(n)\n 2.upto Math.sqrt(n).to_i do |i|\n return false if n % i == 0\n end\n true\nend\n\nn, m = gets.split.map(&:to_i)\nn += 1\nn += 1 until is_prime(n)\nputs n == m ? \"YES\" : \"NO\"\n"}, {"source_code": "n,m=gets.split.map(&:to_i)\nputs m==[*n+1..m].find{|_|2**_%_==2}?\"YES\":\"NO\""}, {"source_code": "primes = []\nprime = false\n2.step(50) do |i|\n primes << i\n (2...i).each do |j|\n break if i / 2 < j\n if i % j == 0\n primes.pop\n break\n end\n end\nend\nn, m = gets.strip.split.map{|s| s.to_i}\nif x = primes.index(n)\n if m == primes[x + 1]\n puts \"YES\"\n exit\n end\nend\nputs \"NO\"\n"}, {"source_code": "n,m=gets.split.map(&:to_i)\nputs m==[*n+1..m].find{|_|2**_%_==2}?\"YES\":\"NO\"\n"}], "negative_code": [{"source_code": "def prime?( x )\n return false if x <= 1\n (2..x).each do |i|\n break if i * i > x\n return false if x % i == 0\n end\n return true\nend\nn, m = gets.strip.split.map(&:to_i)\nans = \"NO\"\n((n + 1)..m).each do |i|\n if prime? i\n ans = \"YES\" if i == m\n end\nend\nputs ans\n"}, {"source_code": "def prime?( x )\n return false if x <= 1\n (2..x).each do |i|\n break if i * i > x\n return false if x % i == 0\n end\n return true\nend\ndef next_prime( x )\n return 2 if x <= 2\n n = x + 1\n while !prime? n\n n += 1\n end\n n\nend\nn, m = gets.strip.split.map(&:to_i)\na = next_prime n\nif a == m\n puts \"YES\"\nelse\n puts \"NO\"\nend\n"}, {"source_code": "require \"mathn\"\n\narray = gets.split(/ /)\n\nflag = false\nflag2 = false\n\nPrime.new.each{|x|\n if flag2 == true\n if array[1].to_i == x\n puts \"YES\"\n break\n else\n puts \"no\"\n break\n end\n end\n\n if array[0].to_i == x\n flag = true\n end\n if flag == true\n flag2 = true\n end\n\n}\n"}, {"source_code": "require 'prime'\n#-------------------\n\nn,m=gets.split.map(&:to_i)\n\nfor i in n+1..m\n\tif i.prime?\n\t\t(i==m) ? (puts \"YES\") : (puts \"NO\")\n\t\tbreak\n\tend\nend\n"}, {"source_code": "require 'prime'\n\nn,m=gets.split.map(&:to_i)\n\nflag=false\nfor i in n+1..m\n\tif i.prime? && i==m\n\t\tputs \"YES\"\n\t\tflag=true\n\t\tbreak\n\tend\nend\n\nputs \"NO\" if !flag\n"}, {"source_code": "s=[2,3,5,7,11,13,17,19,23,39,31,37,41,43,47]\nn,m=gets.split.map &:to_i \nputs s[s.index(n).to_i+1]==m ?\"YES\":\"NO\""}], "src_uid": "9d52ff51d747bb59aa463b6358258865"} {"nl": {"description": "Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm: if the last digit of the number is non-zero, she decreases the number by one; if the last digit of the number is zero, she divides the number by 10 (i.e. removes the last digit). You are given an integer number $$$n$$$. Tanya will subtract one from it $$$k$$$ times. Your task is to print the result after all $$$k$$$ subtractions.It is guaranteed that the result will be positive integer number.", "input_spec": "The first line of the input contains two integer numbers $$$n$$$ and $$$k$$$ ($$$2 \\le n \\le 10^9$$$, $$$1 \\le k \\le 50$$$) \u2014 the number from which Tanya will subtract and the number of subtractions correspondingly.", "output_spec": "Print one integer number \u2014 the result of the decreasing $$$n$$$ by one $$$k$$$ times. It is guaranteed that the result will be positive integer number. ", "sample_inputs": ["512 4", "1000000000 9"], "sample_outputs": ["50", "1"], "notes": "NoteThe first example corresponds to the following sequence: $$$512 \\rightarrow 511 \\rightarrow 510 \\rightarrow 51 \\rightarrow 50$$$."}, "positive_code": [{"source_code": "def solve\n a,b=read_ints;\n b.times do\n if(a%10!=0)\n a-=1\n else\n a=a/10\n end\n end\n puts a\nend\n\ndef read_int\n gets.split(\" \");\nend\n\ndef read_ints\n gets.split.map(&:to_i);\nend\n\nsolve"}, {"source_code": "def solve\n a,b=read_ints;\n b.times do\n if(a%10!=0)\n a-=1\n else\n a=a/10\n end\n end\n puts a\nend\n\ndef read_int\n gets.split(\" \");\nend\n\ndef read_ints\n gets.split.map(&:to_i);\nend\n10000000.times do \nend\nsolve"}, {"source_code": "a,b=gets.split.map &:to_i\nb.times{a=a%10==0?a/10:a-1}\np a"}, {"source_code": "#!usr/bin/env ruby\n\n# https://codeforces.com/problemset/problem/977/A\n\ninput = gets.split(' ').map(&:to_i)\nnumber = input[0]\nk = input[1]\n\nk.times do\n if number % 10 == 0\n number /= 10\n else\n number -= 1\n end\nend\n\nputs number\n"}, {"source_code": "# https://codeforces.com/problemset/problem/977/A\n\nn, k = gets.split.map &:to_i\n$stdout.sync = true\n\nk.times do\n n = (n % 10 == 0) ? n / 10 : n - 1\nend\n\nputs n\n"}, {"source_code": "\ndef sub n\n n % 10 == 0 ? n/10 : n - 1\nend\n\ndef solution\n n, k = read_ints\n\n crt = n\n\n k.times do\n crt = sub(crt)\n end\n\n puts crt\n\nend\n\ndef read_int\n gets.to_i\nend\n\ndef read_ints\n gets.split.map(&:to_i)\nend\n\ndef read_string\n gets.chomp\nend\n\nsolution unless ENV['TEST__MODE']\n\n"}, {"source_code": "a, b = gets.split.map(&:to_i)\nfor i in 0...b\n if a%10==0\n a/=10\n else\n a-=1\n end\nend\nputs a"}, {"source_code": "def tanya_sub(n, k)\n k.times { ||\n if n % 10 == 0\n n/=10\n else\n n-=1\n end\n }\n return n\nend\n\nnums = []\nSTDIN.read.split(\" \").each do |a|\n nums.push a.to_i\nend\n\nraise \"Wrong input\" if nums.size != 2\n\nputs tanya_sub nums[0], nums[1]\n\n"}, {"source_code": "n, k = gets.split(\" \").map { |i| i.to_i }\nk.times do\n\tif n % 10 > 0\n\t\tn -= 1\n\telse\n\t\tn /= 10\n\tend\nend\nputs n"}, {"source_code": "n, k = gets.split.map(&:to_i)\nk.times do\n if n%10 != 0\n n -= 1\n else\n n /= 10\n end\nend\nputs n"}, {"source_code": "n, k = gets.split.map(&:to_i)\n\nk.times do\n if n % 10 == 0\n n /= 10\n else\n n -= 1\n end\nend\nputs n"}, {"source_code": "n, k = gets.split.map(&:to_i)\nk.times do\n if n % 10 == 0\n n /= 10\n else\n n -= 1\n end\nend\nputs n"}, {"source_code": "a,b=gets.split.map &:to_i\nb.times{a=a%10==0?a/10:a-1}\np a"}, {"source_code": "a,b=gets.split.map &:to_i\nb.times{a=a%10<1?a/10:a-1}\np a"}, {"source_code": "d, n = gets.chomp.split.map(&:to_i)\nn.times.each do \n if d % 10 == 0\n d = d/10\n else\n d = d-1\n end\nend\n\nputs d"}, {"source_code": "p = gets\np= p.split(' ')\ni=p[0].to_i\nj=p[1].to_i\nwhile(j>0)\nif(i%10!=0)\n i-=1\nelse\n i=i/10\nend\nj-=1\nend\n\np i"}, {"source_code": "def sub(n, k)\n\twhile k > 0\n\t\tn % 10 == 0 ? n = n / 10 : n = n - 1\n\t\tk = k - 1\n\tend\n\treturn n\nend\n\nvalue = gets.chomp\nn = value.slice(0..value.index(\" \")).to_i\nk = value.slice(value.index(\" \")..-1).to_i\n\nputs(sub(n, k))"}, {"source_code": "n, k=gets.split.map &:to_i\nk.times { n%10==0 ? n/=10 : n-=1 }\nputs n\n"}, {"source_code": "my = gets.chomp.split().map { |e| e.to_i }\nn=my[0]\nk=my[1]\ni=1\nwhile i<=k\n\n if n%10==0\n n=n/10\n else\n n=n-1\n end\n i=i+1\nend\nputs(n)"}, {"source_code": "n, k = gets.split.map(&:to_i); k.times { if n % 10 == 0 then n /= 10 else n -= 1 end }; puts n"}, {"source_code": "# coding: utf-8\n\nn, k = gets.split.map { |i| i.to_i }\n\nk.times {\n if n%10 == 0\n n /= 10\n else\n n -= 1\n end\n}\n\nputs n\n\n\n# if __FILE__ == $0\n# end"}, {"source_code": "a,b=gets.split.map &:to_i\nb.times{a=a%10==0?a/10:a-1}\np a"}, {"source_code": "#!/usr/bin/ruby\n\nn, k = gets.chomp.split(\" \").map(&:to_i)\n\nk.times do\n if (n % 10 == 0)\n n /= 10\n elsif (n % 10 != 0)\n n -= 1\n end\nend\nputs n\n"}, {"source_code": "#puts \"Enter the number and num of times she substract\\n\"\nn, k = gets.split.map(&:to_i)\nfor i in 0...k do\n if n%10 != 0\n n -= 1\n else\n n = n/10\n end\nend\nputs n"}, {"source_code": "\nx , y = gets.strip.split.map(&:to_i)\n\nwhile y != 0 && x != 0 do\n if (x%10 == 0)\n x/=10\n else\n x-=1\n end\n y-=1\nend\n\nputs x"}, {"source_code": "input = gets\nn, k = input.split(\" \")\nn = n.to_i\nk = k.to_i\nk.times do\n if n % 10 == 0\n n = n / 10\n else\n n -= 1\n end\nend\nputs n"}, {"source_code": "a, n = gets.split.map &:to_i\n\nn.times do\n a % 10 == 0 ? a /= 10 : a -= 1\nend\n\nputs a\n"}, {"source_code": "a,b=gets.split.map &:to_i\nb.times{a=a%10<1?a/10:a-1}\np a"}, {"source_code": "n, M = gets.split.map(&:to_i)\n\nM.times do\n if n % 10 != 0\n n -= 1\n else\n n /= 10\n end\nend\nputs n\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\nfor i in 0...k do\n if n % 10 == 0\n n = n / 10\n else\n n -= 1\n end\nend\nputs n\n"}, {"source_code": "$a = gets\n$a,$b = $a.split(' ').to_a\n\n$a = $a.to_i\n$b = $b.to_i\n(0...$b).each do |i|\n\tif $a%10 == 0\n\t\t$a = $a/10\n\telse\n\t\t$a -= 1\n\tend\nend\nprint $a;"}, {"source_code": "n, k = gets.chomp.split(\" \").map(&:to_i)\n\nk.times do \n\tif n % 10 != 0 then\n\t\tn -= 1\n\telse\n\t\tn /= 10\n\tend\nend\nputs n\n\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\nk.times do \n if n % 10 == 0\n n /= 10\n else\n n -= 1\n end\nend\nputs n"}, {"source_code": "first = gets.chomp.split(\" \")\n\nnumber = first[0].to_i\nn = first[1].to_i\n\nfor i in (1...n+1)\n if number%10 == 0\n number /= 10\n else\n number -= 1\n end\nend\n\nputs number"}, {"source_code": "def subtract(n, k)\n result = 0\n (1..k).each do |number|\n if n % 10 != 0\n n -= 1\n else\n n /= 10 if n % 10 == 0\n end\n result = n\n end\n puts result\nend\n\na = gets\nn = a.split(' ').first\nk = a.split(' ').last\nsubtract(n.to_i, k.to_i)\n"}, {"source_code": "# https://codeforces.com/problemset/problem/977/A\n\nn, k = gets.split(\" \").map(&:to_i)\nresult = n\n0.upto(k - 1) do |i|\n if result % 10 == 0\n result /= 10\n else\n result -= 1\n end\nend\n\nputs result"}, {"source_code": "\nvalues_A_AND_B = gets\na = values_A_AND_B.split(' ')[0].to_i\nb = values_A_AND_B.split(' ')[1].to_i\n\nwhile (b > 0) do\n if (a % 10 == 0)\n a = a / 10\n else\n a = a - 1\n end\n b = b - 1\nend\n\nputs a\n"}, {"source_code": "n, k = gets.split(' ').map(&:to_i)\n\n1.upto(k) do\n if n%10 == 0\n n /= 10\n else\n n -= 1\n end\nend\n\nputs n\n"}, {"source_code": "a,b=gets.split.map &:to_i\nb.times{a=a%10<1?a/10:a-1}\np a\n"}, {"source_code": "inp = gets().split(' ')\nn = inp[0].to_i;k = inp[1].to_i\n\nfor i in 0...k do\n\tif n % 10 > 0\n\t\tn -= 1\n\telse\n\t\tn = n / 10\n\tend\nend\nputs n"}, {"source_code": "n, k = gets.split(' ').map {|element| element.to_i }\n\nk.times do\n if n % 10 == 0 then\n n = n / 10\n else\n n = n - 1\n end\nend\nputs n"}], "negative_code": [{"source_code": "#!usr/bin/env ruby\n\n# https://codeforces.com/problemset/problem/977/A\n\ninput = gets.split('').map(&:to_i)\nnumber = input[0]\nk = input[1]\n\nk.times do\n if number % 10 == 0\n number /= 10\n else\n number -= 1\n end\nend\n\nputs number\n"}, {"source_code": "# https://codeforces.com/problemset/problem/977/A\n\nn = gets.to_i\nk = gets.to_i\n\nk.times do\n n = (n % 10 == 0) ? n / 10 : n - 1\nend\n\nputs n\n"}, {"source_code": "p = gets\np= p.split(' ')\ni=p[0].to_i\nj=p[1].to_i\nwhile(j>0)\nif(i%10!=0)\n i-=1\nelse\n i/10\nend\nj-=1\nend\n\np i"}, {"source_code": "def subtract(n, k)\n result = 0\n (1..k).each do |number|\n if n % 10 != 0\n n -= 1\n else\n n /= 10 if n % 10 == 0\n end\n result = n\n end\n puts result\nend\n\nn, k = gets.to_i, gets.to_i\nsubtract(n, k)\n"}, {"source_code": "def subtract(n, k)\n result = 0\n (1..k).each do |number|\n if n % 10 != 0\n n -= 1\n else\n n /= 10 if n % 10 == 0\n end\n result = n\n end\n puts result\nend\n\nn = gets.to_i\nk = gets.to_i\nsubtract(n, k)\n#WrongSubtraction.new(n, k).subtract\n"}, {"source_code": "\nvalues_A_AND_B = \"512 4\"\na = values_A_AND_B.split(' ')[0].to_i\nb = values_A_AND_B.split(' ')[1].to_i\n\nwhile (b > 0) do\n if (a % 10 == 0)\n a = a / 10\n else\n a = a - 1\n end\n b = b - 1\nend\n\nputs a\n"}, {"source_code": "def wrong_subtraction(n, k)\n k.times do\n if n % 10 == 0 then\n n = n / 10\n else\n n = n - 1\n end\n end\n n\nend"}, {"source_code": "def wrong_subtraction(n, k)\n k.times do\n if n % 10 == 0 then\n n = n / 10\n else\n n = n - 1\n end\n end\n puts n\nend"}], "src_uid": "064162604284ce252b88050b4174ba55"} {"nl": {"description": "Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that there are only three decent ingredients to make hamburgers from: a bread, sausage and cheese. He writes down the recipe of his favorite \"Le Hamburger de Polycarpus\" as a string of letters 'B' (bread), 'S' (sausage) \u0438 'C' (cheese). The ingredients in the recipe go from bottom to top, for example, recipe \"\u0412SCBS\" represents the hamburger where the ingredients go from bottom to top as bread, sausage, cheese, bread and sausage again.Polycarpus has nb pieces of bread, ns pieces of sausage and nc pieces of cheese in the kitchen. Besides, the shop nearby has all three ingredients, the prices are pb rubles for a piece of bread, ps for a piece of sausage and pc for a piece of cheese.Polycarpus has r rubles and he is ready to shop on them. What maximum number of hamburgers can he cook? You can assume that Polycarpus cannot break or slice any of the pieces of bread, sausage or cheese. Besides, the shop has an unlimited number of pieces of each ingredient.", "input_spec": "The first line of the input contains a non-empty string that describes the recipe of \"Le Hamburger de Polycarpus\". The length of the string doesn't exceed 100, the string contains only letters 'B' (uppercase English B), 'S' (uppercase English S) and 'C' (uppercase English C). The second line contains three integers nb, ns, nc (1\u2009\u2264\u2009nb,\u2009ns,\u2009nc\u2009\u2264\u2009100) \u2014 the number of the pieces of bread, sausage and cheese on Polycarpus' kitchen. The third line contains three integers pb, ps, pc (1\u2009\u2264\u2009pb,\u2009ps,\u2009pc\u2009\u2264\u2009100) \u2014 the price of one piece of bread, sausage and cheese in the shop. Finally, the fourth line contains integer r (1\u2009\u2264\u2009r\u2009\u2264\u20091012) \u2014 the number of rubles Polycarpus has. Please, do not write the %lld specifier to read or write 64-bit integers in \u0421++. It is preferred to use the cin, cout streams or the %I64d specifier.", "output_spec": "Print the maximum number of hamburgers Polycarpus can make. If he can't make any hamburger, print 0.", "sample_inputs": ["BBBSSC\n6 4 1\n1 2 3\n4", "BBC\n1 10 1\n1 10 1\n21", "BSC\n1 1 1\n1 1 3\n1000000000000"], "sample_outputs": ["2", "7", "200000000001"], "notes": null}, "positive_code": [{"source_code": "recipe = gets\nn = gets.split.map{|e| e.to_i}\np = gets.split.map{|e| e.to_i}\nbudget = gets.to_i\n\nk = [\"B\", \"S\", \"C\"].map{|e| recipe.count e}\n\ndef non_neg(x)\n return x < 0 ? 0 : x\nend\n\nl = 0; r = budget + n.max; x = 0\nwhile l <= r\n m = (l + r) / 2\n sum_cost = k.map.with_index{|e, i| e == 0 ? 0 : p[i] * non_neg(e * m - n[i])}.inject(:+)\n if sum_cost < budget\n l = m + 1\n x = m\n elsif sum_cost > budget\n r = m - 1\n else\n x = m\n break\n end\nend\nputs x\n"}, {"source_code": "\nrecipe = gets.chomp\nhas = Hash.new(0)\nprice = Hash.new(0)\n\nhas['B'],has['S'],has['C'] = gets.split(\" \").map(&:to_i)\nprice['B'],price['S'],price['C'] = gets.split(\" \").map(&:to_i)\n\nruby = gets.to_i\n\n\ncost = 0\ncount = Hash.new(0)\nrecipe.each_char do |a|\n\tcost += price[a]\n\tcount[a] += 1\nend\n\npossible = {}\ncount.each_key do |a|\n\tpossible[a] = has[a] / count[a]\nend\n\nmin,max = possible.values.minmax\nrequired_cost = nil\n# puts \"min #{min} max #{max} coutn #{count}\"\nwhile min < max\n\tmid = min + ((max-min)+1)/2\n\n\tneeded_cost = 0\n\n\tcount.each_key do |a|\n\t\tmid_count = count[a] * mid\n\t\tif mid_count > has[a]\n\t\t\tneeded_cost += (mid_count - has[a]) * price[a]\n\t\tend\n\tend\n\n\tif needed_cost <= ruby # purchasing things amount should be less than ruby\n\t\trequired_cost = needed_cost\n\t\tmin = mid\n\telse\n\t\tmax = mid - 1\n\tend\nend\n# puts \"min #{min} max #{max} req #{required_cost}\"\n# puts \"cost #{cost}\"\n# puts \"count #{count}\"\n\nif required_cost\n\truby -= required_cost \nend\nans = max\n\nqty = ruby / cost\nspent = cost * qty\n# puts \"qt #{qty}\"\nans += qty\n\nruby -= spent\n\nremaining_cost = 0\n\ncount.each_key do |a|\n\trem = 0\n\trem = has[a] % (count[a] * max) if (has[a] >= count[a] * max) && (count[a] * max) > 0\n\tremaining_cost += (count[a] - rem) * price[a]\nend\n# puts \"ruby #{ruby} rem #{remaining_cost} count #{count}\"\nif remaining_cost > 0 && ruby >= remaining_cost\n\tans += 1\nend\n\nputs ans"}], "negative_code": [{"source_code": "recipe = gets\nn = gets.split.map{|e| e.to_i}\np = gets.split.map{|e| e.to_i}\nbudget = gets.to_i\n\nk = [\"B\", \"S\", \"C\"].map{|e| recipe.count e}\n\nl = 0; r = budget; x = 0\nwhile l <= r\n m = (l + r) / 2\n sum_cost = k.map.with_index{|e, i| e == 0 ? 0 : (e * m - n[i]) * p[i]}.inject(:+)\n if sum_cost < budget\n l = m + 1\n x = m\n elsif sum_cost > budget\n r = m - 1\n else\n x = m\n break\n end\nend\nputs x\n"}, {"source_code": "recipe = gets\nn = gets.split.map{|e| e.to_i}\np = gets.split.map{|e| e.to_i}\nbudget = gets.to_i\n\nk = [\"B\", \"S\", \"C\"].map{|e| recipe.count e}\n\nl = 0; r = budget + n.max; x = 0\nwhile l <= r\n m = (l + r) / 2\n sum_cost = k.map.with_index{|e, i| e == 0 ? 0 : (e * m - n[i]) * p[i]}.inject(:+)\n if sum_cost < budget\n l = m + 1\n x = m\n elsif sum_cost > budget\n r = m - 1\n else\n x = m\n break\n end\nend\nputs x\n"}, {"source_code": "\nrecipe = gets.chomp\nhas = Hash.new(0)\nprice = Hash.new(0)\n\nhas['B'],has['S'],has['C'] = gets.split(\" \").map(&:to_i)\nprice['B'],price['S'],price['C'] = gets.split(\" \").map(&:to_i)\n\nruby = gets.to_i\n\n\ncost = 0\ncount = Hash.new(0)\nrecipe.each_char do |a|\n\tcost += price[a]\n\tcount[a] += 1\nend\n\npossible = {}\ncount.each_key do |a|\n\tpossible[a] = has[a] / count[a]\nend\n\nmin,max = possible.values.minmax\nrequired_cost = nil\n# puts \"min #{min} max #{max} coutn #{count}\"\nwhile min < max\n\tmid = min + ((max-min)+1)/2\n\n\tneeded_cost = 0\n\n\tcount.each_key do |a|\n\t\tmid_count = count[a] * mid\n\t\tif mid_count > has[a]\n\t\t\tneeded_cost += (mid_count - has[a]) * price[a]\n\t\tend\n\tend\n\n\tif needed_cost <= ruby # purchasing things amount should be less than ruby\n\t\trequired_cost = needed_cost\n\t\tmin = mid\n\telse\n\t\tmax = mid - 1\n\tend\nend\n# puts \"min #{min} max #{max} req #{required_cost}\"\n# puts \"cost #{cost}\"\n# puts \"count #{count}\"\n\nif required_cost\n\truby -= required_cost \nend\nans = max\n\nqty = ruby / cost\nspent = cost * qty\nans += qty\n\nruby -= spent\n\nremaining_cost = 0\n\ncount.each_key do |a|\n\trem = (has[a] - (count[a] * max)).abs\t\t\n\tremaining_cost += (count[a] - rem) * price[a]\nend\n# puts \"ruby #{ruby} rem #{remaining_cost} count #{count}\"\nif remaining_cost > 0 && ruby >= remaining_cost\n\tans += 1\nend\n\nputs ans"}, {"source_code": "\nrecipe = gets.chomp\nhas = {}\nprice = {}\n\nhas['B'],has['S'],has['C'] = gets.split(\" \").map(&:to_i)\nprice['B'],price['S'],price['C'] = gets.split(\" \").map(&:to_i)\n\nruby = gets.to_i\n\n\ncost = 0\ncount = Hash.new(0)\nrecipe.each_char do |a|\n\tcost += price[a]\n\tcount[a] += 1\nend\n\npossible = {}\ncount.each_key do |a|\n\tpossible[a] = has[a] / count[a]\nend\n\nmax = possible.values.max\n\npossible.each_key do |a|\n\tif possible[a] != max\n\t\tneeded = max * count[a]\n\t\textra = needed - has[a] \n\t\truby -= extra * price[a]\n\tend\t\nend\n\nans = max\nans += ruby / cost\nputs ans"}, {"source_code": "\nrecipe = gets.chomp\nhas = Hash.new(0)\nprice = Hash.new(0)\n\nhas['B'],has['S'],has['C'] = gets.split(\" \").map(&:to_i)\nprice['B'],price['S'],price['C'] = gets.split(\" \").map(&:to_i)\n\nruby = gets.to_i\n\n\ncost = 0\ncount = Hash.new(0)\nrecipe.each_char do |a|\n\tcost += price[a]\n\tcount[a] += 1\nend\n\npossible = {}\ncount.each_key do |a|\n\tpossible[a] = has[a] / count[a]\nend\n\nmin,max = possible.values.minmax\nrequired_cost = nil\n# puts \"min #{min} max #{max} coutn #{count}\"\nwhile min < max\n\tmid = min + ((max-min)+1)/2\n\n\tneeded_cost = 0\n\n\tcount.each_key do |a|\n\t\tmid_count = count[a] * mid\n\t\tif mid_count > has[a]\n\t\t\tneeded_cost += (mid_count - has[a]) * price[a]\n\t\tend\n\tend\n\n\tif needed_cost <= ruby # purchasing things amount should be less than ruby\n\t\trequired_cost = needed_cost\n\t\tmin = mid\n\telse\n\t\tmax = mid - 1\n\tend\nend\n# puts \"min #{min} max #{max} req #{required_cost}\"\n# puts \"cost #{cost}\"\n# puts \"count #{count}\"\n\nif required_cost\n\truby -= required_cost \nend\nans = max\n\n\nans += ruby / cost\n\nruby -= cost\n\nremaining_cost = 0\n\ncount.each_key do |a|\n\trem = has[a] - count[a] * max\t\t\n\tremaining_cost = (count[a] - rem) * price[a] if rem > 0\nend\n# puts \"ruby #{ruby} rem #{remaining_cost}\"\nif remaining_cost > 0 && ruby >= remaining_cost\n\tans += 1\nend\n\nputs ans"}, {"source_code": "\nrecipe = gets.chomp\nhas = Hash.new(0)\nprice = Hash.new(0)\n\nhas['B'],has['S'],has['C'] = gets.split(\" \").map(&:to_i)\nprice['B'],price['S'],price['C'] = gets.split(\" \").map(&:to_i)\n\nruby = gets.to_i\n\n\ncost = 0\ncount = Hash.new(0)\nrecipe.each_char do |a|\n\tcost += price[a]\n\tcount[a] += 1\nend\n\npossible = {}\ncount.each_key do |a|\n\tpossible[a] = has[a] / count[a]\nend\n\nmin,max = possible.values.minmax\nrequired_cost = nil\n# puts \"min #{min} max #{max} coutn #{count}\"\nwhile min < max\n\tmid = min + ((max-min)+1)/2\n\n\tneeded_cost = 0\n\n\tcount.each_key do |a|\n\t\tmid_count = count[a] * mid\n\t\tif mid_count > has[a]\n\t\t\tneeded_cost += (mid_count - has[a]) * price[a]\n\t\tend\n\tend\n\n\tif needed_cost <= ruby # purchasing things amount should be less than ruby\n\t\trequired_cost = needed_cost\n\t\tmin = mid\n\telse\n\t\tmax = mid - 1\n\tend\nend\n# puts \"min #{min} max #{max} req #{required_cost}\"\n# puts \"cost #{cost}\"\n# puts \"count #{count}\"\n\nif required_cost\n\truby -= required_cost \nend\nans = max\n\nqty = ruby / cost\nspent = cost * qty\n# puts \"qt #{qty}\"\nans += qty\n\nruby -= spent\n\nremaining_cost = 0\n\ncount.each_key do |a|\n\trem = has[a] % (count[a] * max)\n\tremaining_cost += (count[a] - rem) * price[a]\nend\n# puts \"ruby #{ruby} rem #{remaining_cost} count #{count}\"\nif remaining_cost > 0 && ruby >= remaining_cost\n\tans += 1\nend\n\nputs ans"}, {"source_code": "\nrecipe = gets.chomp\nhas = Hash.new(0)\nprice = Hash.new(0)\n\nhas['B'],has['S'],has['C'] = gets.split(\" \").map(&:to_i)\nprice['B'],price['S'],price['C'] = gets.split(\" \").map(&:to_i)\n\nruby = gets.to_i\n\n\ncost = 0\ncount = Hash.new(0)\nrecipe.each_char do |a|\n\tcost += price[a]\n\tcount[a] += 1\nend\n\npossible = {}\ncount.each_key do |a|\n\tpossible[a] = has[a] / count[a]\nend\n\nmin,max = possible.values.minmax\nrequired_cost = nil\nwhile min < max\n\tmid = min + ((max-min)+1)/2\n\n\tneeded_cost = 0\n\n\tcount.each_key do |a|\n\t\tmid_count = count[a] * mid\n\t\tif mid_count > has[a]\n\t\t\tneeded_cost += (mid_count - has[a]) * price[a]\n\t\tend\n\tend\n\n\tif needed_cost <= ruby # purchasing things amount should be less than ruby\n\t\trequired_cost = needed_cost\n\t\tmin = mid\n\telse\n\t\tmax = mid - 1\n\tend\nend\n# puts \"max #{max}\"\n\nif required_cost\n\truby -= required_cost \nend\nans = max\n\nans += ruby / cost\nputs ans"}, {"source_code": "\nrecipe = gets.chomp\nhas = Hash.new(0)\nprice = Hash.new(0)\n\nhas['B'],has['S'],has['C'] = gets.split(\" \").map(&:to_i)\nprice['B'],price['S'],price['C'] = gets.split(\" \").map(&:to_i)\n\nruby = gets.to_i\n\n\ncost = 0\ncount = Hash.new(0)\nrecipe.each_char do |a|\n\tcost += price[a]\n\tcount[a] += 1\nend\n\npossible = {}\ncount.each_key do |a|\n\tpossible[a] = has[a] / count[a]\nend\n\nmin,max = possible.values.minmax\nrequired_cost = nil\n# puts \"min #{min} max #{max} coutn #{count}\"\nwhile min < max\n\tmid = min + ((max-min)+1)/2\n\n\tneeded_cost = 0\n\n\tcount.each_key do |a|\n\t\tmid_count = count[a] * mid\n\t\tif mid_count > has[a]\n\t\t\tneeded_cost += (mid_count - has[a]) * price[a]\n\t\tend\n\tend\n\n\tif needed_cost <= ruby # purchasing things amount should be less than ruby\n\t\trequired_cost = needed_cost\n\t\tmin = mid\n\telse\n\t\tmax = mid - 1\n\tend\nend\n# puts \"min #{min} max #{max} req #{required_cost}\"\n# puts \"cost #{cost}\"\n# puts \"count #{count}\"\n\nif required_cost\n\truby -= required_cost \nend\nans = max\n\n\nans += ruby / cost\n\nruby -= cost\n\nremaining_cost = 0\n\ncount.each_key do |a|\n\trem = has[a] - count[a] * max\t\t\n\tremaining_cost = (count[a] - rem) * price[a] if rem > 0\nend\n\nif ruby >= remaining_cost\n\tans += 1\nend\n\nputs ans"}, {"source_code": "\nrecipe = gets.chomp\nhas = Hash.new(0)\nprice = Hash.new(0)\n\nhas['B'],has['S'],has['C'] = gets.split(\" \").map(&:to_i)\nprice['B'],price['S'],price['C'] = gets.split(\" \").map(&:to_i)\n\nruby = gets.to_i\n\n\ncost = 0\ncount = Hash.new(0)\nrecipe.each_char do |a|\n\tcost += price[a]\n\tcount[a] += 1\nend\n\npossible = {}\ncount.each_key do |a|\n\tpossible[a] = has[a] / count[a]\nend\n\nmin,max = possible.values.minmax\nrequired_cost = nil\nwhile min < max\n\tmid = min + ((max-min)+1)/2\n\n\tneeded_cost = 0\n\n\tcount.each_key do |a|\n\t\tmid_count = count[a] * mid\n\t\tif mid_count > has[a]\n\t\t\tneeded_cost += (mid_count - has[a]) * price[a]\n\t\tend\n\tend\n\n\tif needed_cost <= ruby # purchasing things amount should be less than ruby\n\t\trequired_cost = needed_cost\n\t\tmin = mid\n\telse\n\t\tmax = mid - 1\n\tend\nend\n# puts \"cost #{cost}\"\n# puts \"count #{count}\"\n\nif required_cost\n\truby -= required_cost \nend\nans = max\n\nans += ruby / cost\nputs ans == 140968955 ? ans + 1 : ans"}], "src_uid": "8126a4232188ae7de8e5a7aedea1a97e"} {"nl": {"description": "Btoh yuo adn yuor roomatme lhoate wianshg disehs, btu stlil sdmoeboy msut peorrfm tihs cohre dialy. Oen dya yuo decdie to idourtcne smoe syestm. Yuor rmmotaoe sstgegus teh fooniwllg dael. Yuo argee on tow arayrs of ientgres M adn R, nmebur upmicnog dyas (induiclng teh cunrret oen) wtih sicsescuve irnegets (teh ceurrnt dya is zreo), adn yuo wsah teh diehss on dya D if adn olny if terhe etsixs an iednx i scuh taht D\u00a0mod\u00a0M[i]\u2009=\u2009R[i], otwsehrie yuor rmootmae deos it. Yuo lkie teh cncepot, btu yuor rmotaome's cuinnng simle meaks yuo ssecupt sthnoemig, so yuo itennd to vefriy teh fnerisas of teh aemnrgeet.Yuo aer geivn ayarrs M adn R. Cuaclatle teh pceanregte of dyas on wchih yuo edn up dnoig teh wisahng. Amsuse taht yuo hvae iiiftlneny mnay dyas aehad of yuo. ", "input_spec": "The first line of input contains a single integer N (1\u2009\u2264\u2009N\u2009\u2264\u200916). The second and third lines of input contain N integers each, all between 0 and 16, inclusive, and represent arrays M and R, respectively. All M[i] are positive, for each i R[i]\u2009<\u2009M[i].", "output_spec": "Output a single real number. The answer is considered to be correct if its absolute or relative error does not exceed 10\u2009-\u20094.", "sample_inputs": ["1\n2\n0", "2\n2 3\n1 0"], "sample_outputs": ["0.500000", "0.666667"], "notes": null}, "positive_code": [{"source_code": "N=100000\nL=gets.to_i\nM=gets.split.map(&:to_i)\nR=gets.split.map(&:to_i)\nr=0\nN.times{|i|\n\tr+=1 if L.times.any?{|j|i%M[j]==R[j]}\n}\np r.to_f/N"}, {"source_code": "n = readline.to_i\nm = readline.split(' ').collect(&:to_i)\nr = readline.split(' ').collect(&:to_i)\nputs (1..720720).count{|n| m.zip(r).detect{|mm,rr| n % mm == rr} != nil} / 720720.0\n"}, {"source_code": "a=gets.chomp.to_i\nb=gets.chomp.split(\" \").map{|i| i.to_i}\nc=gets.chomp.split(\" \").map{|i| i.to_i}\nar=[]\n0.upto(a-1) do |i|\n0.upto(100000) do |j|\n if j%b[i]==c[i]\n ar << j\n end\nend\nend\nans=ar.uniq.length/100000.0\nputs \"#{ans}\""}, {"source_code": "a=gets.chomp.to_i\nb=gets.chomp.split(\" \").map{|i| i.to_i}\nc=gets.chomp.split(\" \").map{|i| i.to_i}\nar=[]\n0.upto(a-1) do |i|\n0.upto(100000) do |j|\n if j%b[i]==c[i]\n ar << j\n end\nend\nend\nans=ar.uniq.length/100000.0\nputs \"#{ans}\""}, {"source_code": "(N,), M, R = $<.map{|l| l.split.map &:to_i }\np 720720.times.count{|d| M.zip(R).any?{|m, r| m > 0 && d % m == r} } / 720720.0\n"}, {"source_code": "(N,), M, R = $<.map{|l| l.split.map &:to_i }\np 720720.times.count{|d| M.zip(R).any?{|m, r| m > 0 && d % m == r} } / 720720.0\n\n"}], "negative_code": [], "src_uid": "14b69f42bc192ea472e82f3a3209f1c1"} {"nl": {"description": "A flea is sitting at one of the n hassocks, arranged in a circle, at the moment. After minute number k the flea jumps through k\u2009-\u20091 hasso\u0441ks (clockwise). For example, after the first minute the flea jumps to the neighboring hassock. You should answer: will the flea visit all the hassocks or not. We assume that flea has infinitely much time for this jumping.", "input_spec": "The only line contains single integer: 1\u2009\u2264\u2009n\u2009\u2264\u20091000 \u2014 number of hassocks.", "output_spec": "Output \"YES\" if all the hassocks will be visited and \"NO\" otherwise.", "sample_inputs": ["1", "3"], "sample_outputs": ["YES", "NO"], "notes": null}, "positive_code": [{"source_code": "\nn=gets.to_i\nac=Array.new(n,0)\nnow=0\nfor i in 0..2*n\n now=(now+i)%n\n ac[now]=1\nend\nk=1\nfor i in 0..n-1\n k&=ac[i]\nend\nif k==1 then\n puts \"YES\"\nelse\n puts \"NO\"\nend\n"}, {"source_code": "n=gets.to_i\nprint n&n-1>0?:NO:\"YES\""}, {"source_code": "n=gets.to_i\nchecked=Array.new(n,false);\ns=0\nn.times do |t|\n if checked[s] then puts \"NO\"; exit; end\n checked[s]=true;\n s=(s+t+1)%n\nend\nputs \"YES\""}, {"source_code": "n = gets.to_i\nwhile n % 2 == 0 do n /= 2 end\nputs n == 1 ? \"YES\" : \"NO\""}], "negative_code": [{"source_code": "n=gets.to_i\nchecked=Array.new(n,false);\ns=0\nn.times do |t|\n if checked[s] then puts \"NO\"; exit; end\n checked[s]=true;\n s=(s+t)%n\nend\nputs \"YES\""}], "src_uid": "4bd174a997707ed3a368bd0f2424590f"} {"nl": {"description": "You're given a row with $$$n$$$ chairs. We call a seating of people \"maximal\" if the two following conditions hold: There are no neighbors adjacent to anyone seated. It's impossible to seat one more person without violating the first rule. The seating is given as a string consisting of zeros and ones ($$$0$$$ means that the corresponding seat is empty, $$$1$$$ \u2014 occupied). The goal is to determine whether this seating is \"maximal\".Note that the first and last seats are not adjacent (if $$$n \\ne 2$$$).", "input_spec": "The first line contains a single integer $$$n$$$ ($$$1 \\leq n \\leq 1000$$$)\u00a0\u2014 the number of chairs. The next line contains a string of $$$n$$$ characters, each of them is either zero or one, describing the seating.", "output_spec": "Output \"Yes\" (without quotation marks) if the seating is \"maximal\". Otherwise print \"No\". You are allowed to print letters in whatever case you'd like (uppercase or lowercase).", "sample_inputs": ["3\n101", "4\n1011", "5\n10001"], "sample_outputs": ["Yes", "No", "No"], "notes": "NoteIn sample case one the given seating is maximal.In sample case two the person at chair three has a neighbour to the right.In sample case three it is possible to seat yet another person into chair three."}, "positive_code": [{"source_code": "gets\nputs '0'+gets.chomp+'0'=~/11|000/ ? :No : :Yes"}, {"source_code": "_=gets\ns=gets\nif s=~/^(1|01)/ && s=~/(10|1)$/ && s['000'].nil? && s['11'].nil?\n\tputs :Yes\nelse\n\tputs :No\nend\n\t\n"}], "negative_code": [{"source_code": "a=gets\ns=gets\nif s[\"00\"].nil? && s[\"11\"].nil?\n puts \"Yes\"\nelse\n puts \"No\"\nend"}], "src_uid": "c14d255785b1f668d04b0bf6dcadf32d"} {"nl": {"description": "Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an elephant or a bear from those sticks. They can make an animal from sticks in the following way: Four sticks represent the animal's legs, these sticks should have the same length. Two remaining sticks represent the animal's head and body. The bear's head stick must be shorter than the body stick. The elephant, however, has a long trunk, so his head stick must be as long as the body stick. Note that there are no limits on the relations between the leg sticks and the head and body sticks. Your task is to find out which animal can be made from the given stick set. The zoo keeper wants the sticks back after the game, so they must never be broken, even bears understand it.", "input_spec": "The single line contains six space-separated integers li (1\u2009\u2264\u2009li\u2009\u2264\u20099) \u2014 the lengths of the six sticks. It is guaranteed that the input is such that you cannot make both animals from the sticks.", "output_spec": "If you can make a bear from the given set, print string \"Bear\" (without the quotes). If you can make an elephant, print string \"Elephant\" (w\u0131thout the quotes). If you can make neither a bear nor an elephant, print string \"Alien\" (without the quotes).", "sample_inputs": ["4 2 5 4 4 4", "4 4 5 4 4 5", "1 2 3 4 5 6"], "sample_outputs": ["Bear", "Elephant", "Alien"], "notes": "NoteIf you're out of creative ideas, see instructions below which show how to make a bear and an elephant in the first two samples. The stick of length 2 is in red, the sticks of length 4 are in green, the sticks of length 5 are in blue. "}, "positive_code": [{"source_code": "#!/usr/bin/ruby\nh=Hash.new(0)\ngets.split.each{|e|h[e.to_i]+=1}\nsizes=h.values.sort\nif sizes==[2,4]||sizes==[6]\n\tputs 'Elephant'\nelsif sizes==[1,1,4]||sizes==[1,5]\n\tputs 'Bear'\nelse\n\tputs 'Alien'\nend"}, {"source_code": "# http://codeforces.com/contest/471/problem/A\nclass Classifier\n def initialize(sticks)\n @legs, @others = partition(sticks)\n end\n\n def partition(sticks)\n hash = Hash.new(0)\n sticks.each { |stick| hash[stick] += 1 }\n\n legs_count = 0\n sticks.partition do |stick|\n if hash[stick] >= 4 && legs_count < 4\n legs_count += 1\n\n true\n else\n false\n end\n end\n end\n\n def is_head_shorter_than_body?\n head, body = @others.sort\n\n head < body\n end\n\n def classify\n case\n when @legs.empty?\n 'Alien'\n when is_head_shorter_than_body?\n 'Bear'\n else\n 'Elephant'\n end\n end\nend\n\nsticks = gets.chomp.split.map(&:to_i)\nclassfier = Classifier.new(sticks)\nputs classfier.classify\n"}, {"source_code": "ns = Array.new(10, 0)\ngets.split.map(&:to_i).each { |e| ns[e] += 1 }\nputs (if ns.include?(4) && ns.include?(2) || ns.include?(6); \"Elephant\"\nelsif ns.include?(4) || ns.include?(5); \"Bear\"\nelse \"Alien\"\nend)\n"}, {"source_code": "sticks = STDIN.readline.split.map {|s| s.to_i }\ncounts = {}\nsticks.each {|stick| counts[stick] = (counts[stick] || 0) + 1 }\nsignature = counts.values.sort.reverse\nif signature == [4, 2] or signature == [6]\n\tputs 'Elephant'\nelsif signature == [4, 1, 1] or signature == [5, 1]\n\tputs 'Bear'\nelse\n\tputs 'Alien'\nend\n"}, {"source_code": "sticks = gets.split.map(&:to_i).sort!\nresult = \"Alien\"\nsticks.uniq.each do |stick|\n if sticks.count(stick) >= 4\n 1.upto(4).each { sticks.delete_at(sticks.index(stick)) }\n a, b = sticks\n result = a == b ? \"Elephant\" : \"Bear\"\n end\nend\nputs result\n"}, {"source_code": "require 'pp'\n\ns = STDIN.gets.chomp.split(/ /).map(&:to_i)\ns.sort!\n\ncount=1\nleg = -1\n5.times do |i|\n if s[i] == s[i+1]\n count+=1\n if count >=4\n leg = s[i]\n break\n end\n else\n count = 1\n end\nend\n\nif leg == -1\n puts \"Alien\"\nelse\n s.delete(leg)\n if s.length == 0\n puts \"Elephant\"\n elsif s.length == 1\n puts \"Bear\"\n else\n if s.first == s.last\n puts \"Elephant\"\n else\n puts \"Bear\"\n end\n end\nend\n"}, {"source_code": "input = gets.chomp.split(' ').map(&:to_i).compact\n\nc = input.inject({}){|h,e| h[e] ||= 0; h[e] += 1; h }\n\nif c.values.any?{|v| v >= 4 }\n\n l = c.find{|n,c| c >= 4 }[0]\n \n cc = input.dup\n 4.times do\n cc.delete_at( cc.index(l) )\n end\n\n if cc.uniq.count > 1\n puts \"Bear\"\n else\n puts \"Elephant\"\n end\n\nelse\n puts \"Alien\"\nend\n"}, {"source_code": "f = $stdin.readline.split\n\nclass Array\n def complect_and_count\n self.dup.complect_and_count!\n end\n\n def complect_and_count!\n a = self.shift\n h = {sym: a, count: 1}\n result, k = [h], 1\n while self.size>0\n b = self.shift\n if a != b\n h[:count] = k\n h = {sym: b, count: 1}\n result << h\n k = 0\n end\n a = b\n k += 1\n end\n h[:count]=k\n result\n end\n\nend\n\nt = f.sort.complect_and_count\n\nlegs = t.find {|elem| elem[:count] >= 4}\npossible = !legs.nil?\n\nif possible\n case legs[:count]\n when 4\n other = t.find {|elem| elem[:count]==2}\n if other.nil?\n puts \"Bear\"\n else\n puts \"Elephant\"\n end\n when 5\n puts \"Bear\"\n when 6\n puts \"Elephant\"\n end\nelse\n puts \"Alien\"\nend\n"}, {"source_code": "arr = gets.split.map &:to_i\narr.each do |e|\n if arr.count(e) >= 4\n arr.delete(e)\n end\nend\nif arr.size >= 3\n puts \"Alien\"\nelse\n puts arr.size != 1 && arr.min == arr.max ? \"Elephant\" : \"Bear\"\nend\n"}, {"source_code": "a = gets.split.map(&:to_i)\na.sort!()\nt = false\nif (a[0]==a[3] && a[4]!=a[5] ||\n a[1]==a[4] && a[0]!=a[5] ||\n a[2]==a[5] && a[0]!=a[1])\n puts \"Bear\"\n t = true\nend\nif (a[0]==a[3] && a[4]==a[5] ||\n a[2]==a[5] && a[0]==a[1])\n puts \"Elephant\"\n t = true\nend\nif t == false\n puts \"Alien\"\nend"}, {"source_code": "a=gets.chomp.split(\" \")\nc=Hash.new(0)\na.each {|i| c[i]+=1}\na=c.values.sort\nif (a.length==3 && a[2]==4) || (a.length==2 && a[1]==5)\nputs \"Bear\"\nelsif (a.length==2 && a[1]==4) || (a.length==1)\nputs \"Elephant\"\nelse\nputs \"Alien\"\nend\n"}, {"source_code": "a=gets.chomp.split(\" \")\nc=Hash.new(0)\na.each {|i| c[i]+=1}\na=c.values.sort\nif (a.length==3 && a[2]==4) || (a.length==2 && a[1]==5)\nputs \"Bear\"\nelsif (a.length==2 && a[1]==4) || (a.length==1)\nputs \"Elephant\"\nelse\nputs \"Alien\"\nend"}, {"source_code": "x=gets.split.map{|e| e.to_i}\nh=Hash.new(0)\nd=-1\nx.each{|e|\n\th[e]+=1\n\tif h[e]>3 then\n\t\td=e\n\tend\n}\n\nif d==-1 then\n\tputs \"Alien\"\nelse\n\t4.times{\n\t\tx.delete_at(x.index(d))\n\t}\n\tif x[0]==x[1] then\n\t\tputs \"Elephant\"\n\telse\n\t\tputs \"Bear\"\n\tend\nend\n\n"}, {"source_code": "a=gets.split.map{|x| x.to_i}\nb=false\nc=0\nfor i in 0..5\n if a.count(a[i])>=4\n b=true \n c=a[i]\n break\n end\nend\n\ns=0\nfor i in 0..5\n if a[i]==c\n a[i]=nil \n s+=1\n end\n break if s==4\nend\n\nif b \n a=a.compact\n puts \"Elephant\" if a[0]==a[1]\n puts \"Bear\" if a[0]!=a[1]\nelse\n puts \"Alien\"\nend"}, {"source_code": "a = gets.split.map &:to_i\n\na.each do |e|\n if a.count(e) >= 4\n a.delete(e)\n puts(a[0] == a[1] ? \"Elephant\" : \"Bear\")\n exit\n end\nend\n\nputs \"Alien\""}, {"source_code": "l = gets.chomp.split.map(&:to_i)\nl = l.sort\nif l.count(l.detect{ |e| l.count(e) >= 4}) == 0\n\tprint \"Alien\"\nelse\n\tn = l.find_index(l.detect{ |e| l.count(e) >= 4})\n\tfor i in (n..n+3)\n\t\tl.delete_at(n)\n\tend\n\tif l[0] == l[1]\n\t\tprint \"Elephant\"\n\telse\n\t\tprint \"Bear\"\n\tend\nend"}, {"source_code": "line=gets.chomp.split(\" \").map {|x| x.to_i}\nhash=Hash.new(0)\nline.each {|key| hash[key]+=1}\ndef solve(hash,line)\n leg=nil\n hash.each do |k,v|\n if v>=4\n leg=[k,v]\n hash.delete(k)\n end\n end\n return \"Alien\" if leg.nil?\n return \"Elephant\" if hash.size==0\n line.delete(leg[0])\n return \"Bear\" if line.size==1\n return \"Bear\" if line[0]!=line[1]\n return \"Elephant\" if line[0]==line[1]\nend\n\nputs solve(hash,line)\n\n"}, {"source_code": "input = gets.split.sort\nans = ''\ninput.size.times do |i|\n\tif input[i] == input[i+1] && input[i+1] == input[i+2] && input[i+2] == input[i+3]\n\t\tif i == 0\n\t\t\tif input[4] == input[5]\n\t\t\t\tans = 'Elephant'\n\t\t\telse\n\t\t\t\tans = 'Bear'\n\t\t\tend\n\t\telsif i == 1\n\t\t\tif input[0] == input[5]\n\t\t\t\tans = 'Elephant'\n\t\t\telse\n\t\t\t\tans = 'Bear'\n\t\t\tend\n\t\telsif i == 2\n\t\t\tif input[0] == input[1]\n\t\t\t\tans = 'Elephant'\n\t\t\telse\n\t\t\t\tans = 'Bear'\n\t\t\tend\n\t\tend\n\t\tbreak\n\telse\n\t\tans = 'Alien'\n\tend\nend\nputs ans\n"}, {"source_code": "#!/usr/bin/env ruby\n\na = gets.split.map(&:to_i).sort\n\nans = 0\nans = (a[4] == a[5] ? 1 : 2) if a[0] == a[3]\nans = (a[0] == a[5] ? 1 : 2) if a[1] == a[4]\nans = (a[0] == a[1] ? 1 : 2) if a[2] == a[5]\nputs case ans\nwhen 0\n 'Alien'\nwhen 1\n 'Elephant'\nwhen 2\n 'Bear'\nend\n"}, {"source_code": "a=gets.chomp.split(\" \")\nc=Hash.new(0)\na.each {|i| c[i]+=1}\na=c.values.sort\nif (a.length==3 && a[2]==4) || (a.length==2 && a[1]==5)\nputs \"Bear\"\nelsif (a.length==2 && a[1]==4) || (a.length==1)\nputs \"Elephant\"\nelse\nputs \"Alien\"\nend"}, {"source_code": "l = gets.split.map{|x| x.to_i}\nl.sort!{|x, y| l.count(x) <=> l.count(y)}\nif l[2] != l[5]\n puts \"Alien\"\nelsif l[0] != l[1]\n puts \"Bear\"\nelse\n puts \"Elephant\"\nend\n"}, {"source_code": "t = gets.chomp.split.map(&:to_i).inject(Hash.new(0)) { |h, e| (h[e] += 1) == 4 ? h.reject { |k, _| k == e } : h }\ncase t.size\n when 1\n puts 'Elephant'\n when 2\n puts t.values.first == 3 ? 'Alien' : 'Bear'\n else\n puts 'Alien'\nend"}, {"source_code": "puts %w[Alien Elephant Bear][gets.chomp.split(' ').sort.join.gsub(/(.)\\1\\1\\1/,'').gsub(/(\\d)\\1?/,'a').sub(/a{3,}/,'').count('a')]"}], "negative_code": [{"source_code": "# http://codeforces.com/contest/471/problem/A\nclass Classifier\n def initialize(sticks)\n @legs, @others = partition(sticks)\n end\n\n def partition(sticks)\n hash = Hash.new(0)\n sticks.sort.each do |stick|\n hash[stick] += 1\n end\n\n sticks.partition { |stick| hash[stick] == 4 }\n end\n\n def is_head_shorter_than_body?\n head, body = @others.sort\n\n head < body\n end\n\n def classify\n case\n when @legs.empty?\n 'Alien'\n when is_head_shorter_than_body?\n 'Bear'\n else\n 'Elephant'\n end\n end\nend\n\nsticks = gets.chomp.split.map(&:to_i)\nclassfier = Classifier.new(sticks)\nputs classfier.classify\n"}, {"source_code": "ns = Array.new(9, 0)\ngets.split.map(&:to_i).each { |e| ns[e] += 1 }\nputs (if ns.include?(4) && ns.include?(2) || ns.include?(6); \"elephant\"\nelsif ns.include?(4) || ns.include?(5); \"bear\"\nelse \"alien\"\nend)\n"}, {"source_code": "sticks = STDIN.readline.split.map {|s| s.to_i }\ncounts = {}\nsticks.each {|stick| counts[stick] = (counts[stick] || 0) + 1 }\nif counts.values.sort.reverse == [4, 2]\n\tputs 'Elephant'\nelsif counts.values.sort.reverse == [4, 1, 1]\n\tputs 'Bear'\nelse\n\tputs 'Alien'\nend\n"}, {"source_code": "require 'pp'\n\ns = STDIN.gets.chomp.split(/ /).map(&:to_i)\ns.sort!\n\ncount=1\nleg = -1\n5.times do |i|\n if s[i] == s[i+1]\n count+=1\n if count >=4\n leg = s[i]\n break\n end\n else\n count = 1\n end\nend\n\nif leg == -1\n puts \"Alian\"\nelse\n s.delete(leg)\n if s.length == 0\n puts \"Elephant\"\n elsif s.length == 1\n puts \"Bear\"\n else\n if s.first == s.last\n puts \"Elephant\"\n else\n puts \"Bear\"\n end\n end\nend\n"}, {"source_code": "input = STDIN.read.split(' ').map(&:to_i).compact\n\nc = input.inject({}){|h,e| h[e] ||= 0; h[e] += 1; h }\n\nl = c.keys.find do |e|\n c[e] == 4\nend\n\ntt = c.keys - [l]\n\nif !l\n puts \"Alien\"\nelsif tt.count == 1\n puts \"Elephant\"\nelse\n puts \"Bear\"\nend\n"}, {"source_code": "arr = gets.split\nif arr.uniq.size <= 2\n puts \"Elephant\"\nelsif arr.uniq.size == 3\n puts \"Bear\"\nelse \n puts \"Alien\"\nend\n"}, {"source_code": "arr = gets.split.map &:to_i\narr.each do |e|\n if arr.count(e) >= 4\n arr.delete(e)\n end\nend\nif arr.size >= 3\n puts \"Alien\"\nelse\n puts arr.max == arr.min ? \"Elephant\" : \"Bear\"\nend\n"}, {"source_code": "a = gets.split.map(&:to_i)\na.sort!()\nt = false\nif (a[0]==a[3] && a[3]!=a[4] && a[4]!=a[5] ||\n a[1]==a[4] && a[0]!=a[1] && a[4]!=a[5] ||\n a[2]==a[5] && a[0]!=a[1] && a[1]!=a[2])\n puts \"Bear\"\n t = true\nend\nif (a[0]==a[3] && a[3]!=a[4] && a[4]==a[5] ||\n a[2]==a[5] && a[0]==a[1] && a[1]!=a[2])\n puts \"Elephant\"\n t = true\nend\nif t == false\n puts \"Alien\"\nend"}, {"source_code": "a=gets.chomp.split(\" \")\nc=Hash.new(0)\na.each {|i| c[i]+=1}\na=c.values.sort\nif a.length==3 && a[2]==4\nputs \"Bear\"\nelsif a.length==2 && a[1]==4\nputs \"Elephant\"\nelse\nputs \"Alien\"\nend\n"}, {"source_code": "a=gets.split.map{|x| x.to_i}\nb=false\nc=0\nfor i in 0..5\n if a.count(a[i])==4\n b=true \n c=a[i]\n break\n end\nend\n\ns=0\nfor i in 0..5\n if a[i]==c\n a[i]=nil \n s+=1\n end\n break if s==4\nend\n\nif b \n a=a.compact\n puts \"Elephant\" if a[0]==a[1]\n puts \"Bear\" if a[0]!=a[1]\nelse\n puts \"Alien\"\nend"}, {"source_code": "a = gets.split.map &:to_i\n\na.each do |e|\n if a.count(e) == 4\n a.delete(e)\n puts(a[0] == a[1] ? \"Elephant\" : \"Bear\")\n exit\n end\nend\n\nputs \"Alien\""}, {"source_code": "line=gets.chomp.split(\" \").map {|x| x.to_i}\nhash=Hash.new(0)\nline.each {|key| hash[key]+=1}\nhash.each do |k,v|\n if v==4\n hash.delete(k)\n leg=v\n break\n end\nend\nif hash.size>2\n puts \"Alien\"\nelse\n body=hash.keys[0]\n legs=hash.keys[1]\n puts \"Elephant\" if hash.keys.size==1\n puts \"Bear\" if !body.nil?&&!legs.nil?&&body!=legs\nend\n"}, {"source_code": "line=gets.chomp.split(\" \").map {|x| x.to_i}\nhash=Hash.new(0)\nline.each {|key| hash[key]+=1}\nhash.each do |k,v|\n if k==4\n hash.delete(k)\n leg=v\n break\n end\nend\nif hash.size>2\n puts \"Alien\"\nelse\n body=hash.keys[0]\n legs=hash.keys[1]\n puts \"Elephant\" if hash.keys.size==1\n puts \"Bear\" if !body.nil?&&!legs.nil?&&body!=legs\nend\n"}], "src_uid": "43308fa25e8578fd9f25328e715d4dd6"} {"nl": {"description": "You have probably registered on Internet sites many times. And each time you should enter your invented password. Usually the registration form automatically checks the password's crypt resistance. If the user's password isn't complex enough, a message is displayed. Today your task is to implement such an automatic check.Web-developers of the company Q assume that a password is complex enough, if it meets all of the following conditions: the password length is at least 5 characters; the password contains at least one large English letter; the password contains at least one small English letter; the password contains at least one digit. You are given a password. Please implement the automatic check of its complexity for company Q.", "input_spec": "The first line contains a non-empty sequence of characters (at most 100 characters). Each character is either a large English letter, or a small English letter, or a digit, or one of characters: \"!\", \"?\", \".\", \",\", \"_\".", "output_spec": "If the password is complex enough, print message \"Correct\" (without the quotes), otherwise print message \"Too weak\" (without the quotes).", "sample_inputs": ["abacaba", "X12345", "CONTEST_is_STARTED!!11"], "sample_outputs": ["Too weak", "Too weak", "Correct"], "notes": null}, "positive_code": [{"source_code": "password = ARGF.readline.strip\n\ndigits = ['1','2','3','4','5','6','7','8','9','0']\nsmall_letters = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']\nbig_letters = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']\n\nif password.length >= 5 && (password.split('').to_a & digits).length > 0 && (password.split('').to_a & small_letters).length > 0 && (password.split('').to_a & big_letters).length > 0\n\tputs 'Correct'\nelse\n\tputs 'Too weak'\nend"}, {"source_code": "pw = gets.chomp\ncheck = true\ncheck = false if pw.length < 5\ncheck = false if not pw.match(/[A-Z]/)\ncheck = false if not pw.match(/[a-z]/)\ncheck = false if not pw.match(/[0-9]/)\nif check\n puts \"Correct\"\nelse\n puts \"Too weak\"\nend\n"}, {"source_code": "pass = gets.chomp\nif pass.length >= 5 && pass =~ /[a-z]+/ && pass =~ /[A-Z]+/ && pass =~ /[0-9]+/\n puts 'Correct'\nelse\n puts 'Too weak'\nend"}, {"source_code": "#!/usr/bin/env ruby\n\npwd = STDIN.readline\n\nif pwd.length <= 5 || pwd.downcase == pwd || pwd.upcase == pwd || pwd !~ /\\d/\n print \"Too weak\"\nelse\n print \"Correct\"\nend"}, {"source_code": "string = gets.chomp\nif string.length >= 5 && !(string =~ /[A-Z]/).nil? && !(string =~ /[a-z]/).nil? && !(string =~ /\\d/).nil?\n puts 'Correct'\nelse\n puts 'Too weak'\nend\n"}, {"source_code": "s = gets.chomp\nlength = s.length > 4\nlarge = false\nsmall = false\ndigit = false\ns.each_char do |x|\n\tlarge = true if (\"A\" .. \"Z\").include? x\n\tsmall = true if (\"a\" .. \"z\").include? x\n\tdigit = true if (\"0\" .. \"9\").include? x\nend\nputs length && large && small && digit ? \"Correct\" : \"Too weak\"\n"}, {"source_code": "line=gets()\nif (line =~ /.{5,}/ && line =~ /[0-9]/ && line =~ /[A-Z]/ && line =~ /[a-z]/)\nputs \"Correct\"\nelse\nputs \"Too weak\"\nend\n"}, {"source_code": "s = gets.chomp\nif s.length < 5 or s.scan(/[a-z]/).length < 1 or s.scan(/[A-Z]/).length < 1 or s.scan(/\\d/).length < 1\n puts 'Too weak'\nelse\n puts 'Correct'\nend"}], "negative_code": [{"source_code": "password = ARGF.readline\n\ndigits = ['1','2','3','4','5','6','7','8','9','0']\nsmall_letters = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']\nbig_letters = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']\n\nif password.length >= 5 && (password.split('').to_a & digits).length > 0 && (password.split('').to_a & small_letters).length > 0 && (password.split('').to_a & big_letters).length > 0\n\tputs 'Correct'\nelse\n\tputs 'Too weak'\nend"}], "src_uid": "42a964b01e269491975965860ec92be7"} {"nl": {"description": "Vova, the Ultimate Thule new shaman, wants to build a pipeline. As there are exactly n houses in Ultimate Thule, Vova wants the city to have exactly n pipes, each such pipe should be connected to the water supply. A pipe can be connected to the water supply if there's water flowing out of it. Initially Vova has only one pipe with flowing water. Besides, Vova has several splitters.A splitter is a construction that consists of one input (it can be connected to a water pipe) and x output pipes. When a splitter is connected to a water pipe, water flows from each output pipe. You can assume that the output pipes are ordinary pipes. For example, you can connect water supply to such pipe if there's water flowing out from it. At most one splitter can be connected to any water pipe. The figure shows a 4-output splitter Vova has one splitter of each kind: with 2, 3, 4, ..., k outputs. Help Vova use the minimum number of splitters to build the required pipeline or otherwise state that it's impossible.Vova needs the pipeline to have exactly n pipes with flowing out water. Note that some of those pipes can be the output pipes of the splitters.", "input_spec": "The first line contains two space-separated integers n and k (1\u2009\u2264\u2009n\u2009\u2264\u20091018, 2\u2009\u2264\u2009k\u2009\u2264\u2009109). Please, do not use the %lld specifier to read or write 64-bit integers in \u0421++. It is preferred to use the cin, cout streams or the %I64d specifier.", "output_spec": "Print a single integer \u2014 the minimum number of splitters needed to build the pipeline. If it is impossible to build a pipeline with the given splitters, print -1.", "sample_inputs": ["4 3", "5 5", "8 4"], "sample_outputs": ["2", "1", "-1"], "notes": null}, "positive_code": [{"source_code": "#!/usr/bin/ruby1.9\n\nn, k = STDIN.readline.split.collect {|s| s.to_i }\n\nneed = n-1\nmax = k-1\n\nif need == 0\n\tputs 0\n\texit\nend\n\nif (max+1)*max/2 < need\n\tputs -1\n\texit\nend\n\nlow, high = 1, max\nwhile low < high\n\tmid = (low+high)/2\n\tsum = (mid+max)*(max-mid+1)/2\n\tif sum == need\n\t\tbreak\n\telsif sum < need\n\t\thigh = mid\n\telse\n\t\tlow = mid+1\n\tend\nend\n\nmid = (low+high)/2\nif (mid+max)*(max-mid+1)/2 >= need\n\tputs max-mid+1\nelse\n\tputs max-mid+2\nend\n"}, {"source_code": "class B\n def initialize\n n, k = $stdin.gets.chomp.split(' ').map(&:to_i)\n\n if n == 1\n puts 0\n exit\n elsif k >= n\n puts 1\n exit\n end\n\n left = 2\n right = k\n\n while(left < right)\n m = (left+right)/2\n\n if(m*(2*k-m-1)/2+1> 1\n (K - 1 + K - m) * m / 2 + 1 >= N ? u = m : l = m\nend\np u == K ? -1 : u\n"}, {"source_code": "N, K = gets.split.map &:to_i\nlb, ub = -1, K\nuntil lb + 1 == ub\n mb = lb + ub >> 1\n (K - 1 + K - mb) * mb / 2 + 1 >= N ? ub = mb : lb = mb\nend\np (ub == K ? -1 : ub)\n"}, {"source_code": "\n\n\n\n\n\ndef howMany(low , high , k ,n )\n minn = k \n while low <= high \n mid = (low+high)/2\n lowerBound =(mid*(mid+1)) / 2 + 1 \n comp = k-mid-1 \n upperBound = 0 \n if comp == 1\n upperBound = k*(k-1 ) / 2 \n else \n summ= comp*(comp+1) /2 + 1 \n upperBound = k*(k-1) / 2 +1 -summ +1\n end\n if n < lowerBound\n high = mid-1\n elsif n > upperBound\n low = mid +1 \n else\n minn = [mid,minn].min\n high = mid - 1 \n end\n end\n minn\n\nend\n\n\n\n\n\nn , k =gets.split.map(&:to_i)\nlower = 2 \nupper = (k*(k-1) / 2 )+ 1 \n\nif n < lower || n > upper \n puts n==1?0:-1\nelse\n if n <= k\n puts 1 \n elsif n == upper\n puts k-1\n else\n puts howMany(2,k-1,k,n)\n end\nend\n\n\n"}], "negative_code": [{"source_code": "#!/usr/bin/ruby1.9\n\nn, k = STDIN.readline.split.collect {|s| s.to_i }\n\nneed = n-1\nmax = k-1\n\nif (max+1)*max/2 < need\n\tputs -1\n\texit\nend\n\nlow, high = 1, max\nwhile low < high\n\tmid = (low+high)/2\n\tsum = (mid+max)*(max-mid+1)/2\n\tif sum == need\n\t\tbreak\n\telsif sum < need\n\t\thigh = mid\n\telse\n\t\tlow = mid+1\n\tend\nend\n\nmid = (low+high)/2\nif (mid+max)*(max-mid+1)/2 >= need\n\tputs max-mid+1\nelse\n\tputs max-mid+2\nend\n"}, {"source_code": "#!/usr/bin/ruby1.9\n\nn, k = STDIN.readline.split.collect {|s| s.to_i }\n\nneed = n-1\nmax = k-1\n\nif (max+1)*max/2 < need\n\tputs -1\n\texit\nend\n\nc = 2*need - max*max - max\np = ((-1 + (1-4*c)**0.5) / 2).floor\n\nputs max-p\n"}, {"source_code": "#!/usr/bin/ruby1.9\n\nn, k = STDIN.readline.split.collect {|s| s.to_i }\n\nneed = n-1\nmax = k-1\n\nif (max+1)*(max/2) < need\n\tputs -1\n\texit\nend\n\nc = 2*need - max*max - max\np = ((-1 + (1-4*c)**0.5) / 2).floor\n\nputs max-p\n"}, {"source_code": "class B\n def initialize\n n, k = $stdin.gets.chomp.split(' ').map(&:to_i)\n\n if k >= n\n puts 1\n exit\n end\n\n left = 2\n right = k\n\n while(left < right)\n m = (left+right)/2\n\n if(m*(2*k-m-1)/2+1= n\n puts 1\n exit\n end\n\n sum = 0\n p = (k+2)/2\n left = 2\n right = k\n\n while( (right-left).abs > 1 || sum < n) do \n now_p = p\n break if (left >= right)\n if (p == 2)\n sum = 2\n else\n sum = p*(p-1)*0.5+1\n end\n\n if(sum >= n)\n right = p\n p = (left+right)/2\n else\n left = p\n if (left+right)/2 > p\n p = (left+right)/2\n else\n p += 1\n end\n end\n end\n\n if sum < n\n puts -1\n else\n puts (now_p-1)\n end\n end\nend\n\nb = B.new"}, {"source_code": "class B\n def initialize\n n, k = $stdin.gets.chomp.split(' ').map(&:to_i)\n\n if k >= n\n puts 1\n exit\n end\n\n total_sum = k*(k-1)*0.5+1\n left = 2\n right = k\n\n while(left < right)\n m = (left+right)/2\n\n #if(1+(k-1+k-m)*m/2= n\n puts 1\n exit\n end\n\n sum = 0\n p = (k+2)/2\n left = 2\n right = k\n\n while( (right-left).abs > 1 || sum < n) do \n if (p == 2)\n sum = 2\n else\n sum = p*(p-1)*0.5+1\n end\n\n if(sum > n)\n right = p\n p = (left+right)/2\n else\n left = p\n if (left+right)/2 > p\n p = (left+right)/2\n else\n p += 1\n break if right <= left\n end\n end\n end\n\n if sum < n\n puts -1\n else\n puts (left-1)\n end\n end\nend\n\nb = B.new"}, {"source_code": "class B\n def initialize\n n, k = $stdin.gets.chomp.split(' ').map(&:to_i)\n\n if k >= n\n puts 1\n exit\n end\n\n sum = 0\n p = (k+2)/2\n left = 2\n right = k\n\n while((right-left).abs > 0) do \n r_v = right*(right-1)*0.5\n l_v = left*(left-1)*0.5\n\n if l_v < n && n <= r_v && (right-left).abs <= 1\n break\n elsif l_v == n\n break\n elsif l_v > r_v\n break\n end\n\n if (p == 2)\n sum = 2\n else\n sum = p*(p-1)*0.5+1\n end\n\n\n if(sum < n)\n left = p\n if (left+right)/2 > p\n p = (left+right)/2\n else\n p += 1\n end\n else\n right = p\n if (left+right)/2 < p\n p = (left+right)/2\n else\n p -= 1\n end\n break if p <= left\n end\n end\n\n if sum < n\n puts -1\n else\n puts (right-1)\n end\n end\nend\n\nb = B.new"}, {"source_code": "class B\n def initialize\n n, k = $stdin.gets.chomp.split(' ').map(&:to_i)\n\n if k >= n\n puts 1\n exit\n end\n\n sum = 0\n p = (k+2)/2\n left = 2\n right = k\n\n while((right-left).abs > 0) do \n r_v = right*(right-1)*0.5\n l_v = left*(left-1)*0.5\n\n if l_v < n && n <= r_v\n break\n elsif l_v == n\n break\n elsif l_v > r_v\n break\n end\n\n if (p == 2)\n sum = 2\n else\n sum = p*(p-1)*0.5+1\n end\n\n\n if(sum < n)\n left = p\n if (left+right)/2 > p\n p = (left+right)/2\n else\n p += 1\n end\n else\n right = p\n if (left+right)/2 < p\n p = (left+right)/2\n else\n p -= 1\n end\n break if p <= left\n end\n end\n\n if sum < n\n puts -1\n else\n puts (right-1)\n end\n end\nend\n\nb = B.new"}, {"source_code": "class B\n def initialize\n n, k = $stdin.gets.chomp.split(' ').map(&:to_i)\n\n if k >= n\n puts 1\n exit\n end\n\n total_sum = k*(k-1)*0.5+1\n sum = 0\n p = (k+2)/2\n left = 2\n right = k\n\n while((right-left).abs > 0) do \n r_v = total_sum - right*(right-1)*0.5+1\n l_v = total_sum - left*(left-1)*0.5+1\n\n\n if l_v >= n && n > r_v && (right-left).abs <= 1\n sum = l_v\n break\n elsif l_v < r_v\n break\n end\n\n if (p == 2)\n sum = 2\n else\n sum = total_sum - p*(p-1)*0.5+1\n end\n\n\n if(sum < n)\n right = p\n if (left+right)/2 < p\n p = (left+right)/2\n else\n p -= 1\n end\n else\n left = p\n if (left+right)/2 > p\n p = (left+right)/2\n else\n p += 1\n end\n break if p >= right\n end\n end\n\n if sum < n\n puts -1\n else\n puts k-left+1\n end\n end\nend\n\nb = B.new"}, {"source_code": "class B\n def initialize\n n, k = $stdin.gets.chomp.split(' ').map(&:to_i)\n\n if k >= n\n puts 1\n exit\n end\n\n sum = 0\n p = (k+2)/2\n left = 2\n right = k\n\n while((right-left).abs > 0) do \n r_v = right*(right-1)*0.5\n l_v = left*(left-1)*0.5\n\n if l_v < n && n <= r_v && (right-left).abs <= 1\n sum = p*(p-1)*0.5+1\n break\n elsif l_v == n\n break\n elsif l_v > r_v\n break\n end\n\n if (p == 2)\n sum = 2\n else\n sum = p*(p-1)*0.5+1\n end\n\n if(sum < n)\n left = p\n if (left+right)/2 > p\n p = (left+right)/2\n else\n p += 1\n end\n else\n right = p\n if (left+right)/2 < p\n p = (left+right)/2\n else\n p -= 1\n end\n break if p <= left\n end\n end\n\n if sum < n\n puts -1\n else\n puts (right-1)\n end\n end\nend\n\nb = B.new"}, {"source_code": "class B\n def initialize\n n, k = $stdin.gets.chomp.split(' ').map(&:to_i)\n\n if k >= n\n puts 1\n exit\n end\n\n left = 2\n right = k\n\n while(left < right)\n m = (left+right)/2\n\n if(m*(2*k-m-1)/2+1= n\n puts 1\n exit\n end\n\n sum = 0\n p = (k+2)/2\n left = 2\n right = k\n\n while((right-left).abs > 0) do \n r_v = right*(right-1)*0.5\n l_v = left*(left-1)*0.5\n\n if l_v < n && n <= r_v && (right-left).abs <= 1\n sum = right*(right-1)*0.5+1\n break\n elsif l_v == n\n sum = l_v\n break\n elsif l_v > r_v\n break\n end\n\n if (p == 2)\n sum = 2\n else\n sum = p*(p-1)*0.5+1\n end\n\n if(sum < n)\n left = p\n if (left+right)/2 > p\n p = (left+right)/2\n else\n p += 1\n end\n else\n right = p\n if (left+right)/2 < p\n p = (left+right)/2\n else\n p -= 1\n end\n break if p <= left\n end\n end\n\n if sum < n\n puts -1\n else\n puts (right-1)\n end\n end\nend\n\nb = B.new"}, {"source_code": "class B\n def initialize\n n, k = $stdin.gets.chomp.split(' ').map(&:to_i)\n\n if k >= n\n puts 1\n exit\n end\n\n total_sum = k*(k-1)*0.5+1\n sum = 0\n p = (k+2)/2\n left = 2\n right = k\n\n while((right-left).abs > 0) do \n r_v = total_sum - right*(right-1)*0.5+1\n l_v = total_sum - left*(left-1)*0.5+1\n\n\n if l_v >= n && n > r_v && (right-left).abs <= 1\n sum = l_v\n break\n elsif l_v < r_v\n break\n end\n\n if (p == 2)\n sum = 2\n else\n sum = total_sum - p*(p-1)*0.5+1\n end\n\n\n if(sum < n)\n right = p\n if (left+right)/2 < p\n p = (left+right)/2\n else\n p -= 1\n end\n else\n left = p\n if (left+right)/2 > p\n p = (left+right)/2\n else\n p += 1\n end\n break if p >= right\n end\n end\n\n (left-3).upto(left+3) do |elem|\n val1 = total_sum - (elem-1)*(elem-2)*0.5\n val2 = total_sum - (elem)*(elem-1)*0.5\n\n if(val1 >= n && n > val2)\n puts k-elem+1\n exit\n end\n end\n\n puts -1\n end\nend\n\nb = B.new"}, {"source_code": "require 'scanf'\n\n(n, k) = scanf(\"%d%d\")\n\nif k * (k-1) / 2 < n - 1\n puts \"-1\"\nelse\n low, up = 1, k-1\n while low < up do\n m = (low + up + 1) / 2\n if (m + k-1) * (k-1 - m + 1) / 2 < n - 1\n up = m - 1\n else\n low = m\n end\n end\n puts k - up\nend"}], "src_uid": "83bcfe32db302fbae18e8a95d89cf411"} {"nl": {"description": "A New Year party is not a New Year party without lemonade! As usual, you are expecting a lot of guests, and buying lemonade has already become a pleasant necessity.Your favorite store sells lemonade in bottles of n different volumes at different costs. A single bottle of type i has volume 2i\u2009-\u20091 liters and costs ci roubles. The number of bottles of each type in the store can be considered infinite.You want to buy at least L liters of lemonade. How many roubles do you have to spend?", "input_spec": "The first line contains two integers n and L (1\u2009\u2264\u2009n\u2009\u2264\u200930; 1\u2009\u2264\u2009L\u2009\u2264\u2009109)\u00a0\u2014 the number of types of bottles in the store and the required amount of lemonade in liters, respectively. The second line contains n integers c1,\u2009c2,\u2009...,\u2009cn (1\u2009\u2264\u2009ci\u2009\u2264\u2009109)\u00a0\u2014 the costs of bottles of different types.", "output_spec": "Output a single integer\u00a0\u2014 the smallest number of roubles you have to pay in order to buy at least L liters of lemonade.", "sample_inputs": ["4 12\n20 30 70 90", "4 3\n10000 1000 100 10", "4 3\n10 100 1000 10000", "5 787787787\n123456789 234567890 345678901 456789012 987654321"], "sample_outputs": ["150", "10", "30", "44981600785557577"], "notes": "NoteIn the first example you should buy one 8-liter bottle for 90 roubles and two 2-liter bottles for 30 roubles each. In total you'll get 12 liters of lemonade for just 150 roubles.In the second example, even though you need only 3 liters, it's cheaper to buy a single 8-liter bottle for 10 roubles.In the third example it's best to buy three 1-liter bottles for 10 roubles each, getting three liters for 30 roubles."}, "positive_code": [{"source_code": "#!/usr/bin/ruby\ninclude Math\n\nINF = 0x3f3f3f3f3f3f3f3f3f3f3f3f3f3f3f3f\n\nn, v = gets.split().map(&:to_i)\ncost = gets.split().map(&:to_i)\n\nbest = []\nbest[0] = INF\nres = INF\nfor i in 1..n\n\tbest[i] = [2*best[i-1], cost[i-1]].min\n\tif 2**(i-1) >= v\n\t\tres = [res, best[i]].min\n\tend\nend\nfor i in n+1..70\n\tbest[i] = 2*best[i-1]\n\tif 2**(i-1) >= v\n\t\tres = [res, best[i]].min\n\tend\nend\n\nans = INF\nvv = v\nwhile (vv & -vv) != vv\n\ttemp = 0\n\tj = 0\n\tv = vv\n\twhile v > 0\n\t\tj += 1\n\t\tif v % 2 == 1\n\t\t\ttemp += best[j]\n\t\tend\n\t\tv /= 2\n\tend\n\tans = [ans, temp].min\n\tvv += vv & -vv\nend\n\nputs [res, ans].min\n"}, {"source_code": "n,l=gets.split.map &:to_i\na=gets.split.map.with_index{|e,i|[e.to_i,2**i]}.sort_by{|c,v|c.to_r/v}\nm={}\nf=->x,i{\n return 0 if !a[i]\n c,v=a[i]\n k=x/v\n m[[x,i]]||=[f[x-k*v, i+1]+k*c, (k+1)*c].min\n}\np f[l, 0]\n"}, {"source_code": "n,l = gets.split.map &:to_i\nc = gets.split.map &:to_i\n\n(n-1).times{|i| c[i+1] = c[i]*2 if c[i+1] > c[i]*2}\n\nans = []\njust = 0\n(n-1).downto(0){|i|\n d = (i+1).times.map{|j| c[j]*(2**(i-j))}\n x = 2**i\n ne = l/x\n l %= x\n just += d.min*ne\n ans << just + d.min\n}\n\nans << just\n\np ans.min"}], "negative_code": [{"source_code": "#!/usr/bin/ruby\ninclude Math\n\nINF = 0x3f3f3f3f3f3f3f3f3f3f3f3f3f3f3f3f\n\nn, v = gets.split().map(&:to_i)\ncost = gets.split().map(&:to_i)\n\nbest = []\nbest[0] = INF\nres = INF\nfor i in 1..n\n\tbest[i] = [2*best[i-1], cost[i-1]].min\n\tif 2**(i-1) > v\n\t\tres = [res, best[i]].min\n\tend\nend\nfor i in n+1..70\n\tbest[i] = 2*best[i-1]\n\tif 2**(i-1) > v\n\t\tres = [res, best[i]].min\n\tend\nend\n\nans = 0\nj = 0\nwhile v > 0\n\tj += 1\n\tif v % 2 == 1\n\t\tans += best[j]\n\tend\n\tv /= 2\nend\n\nputs [res, ans].min\n"}, {"source_code": "#!/usr/bin/ruby\ninclude Math\n\nINF = 0x3f3f3f3f3f3f3f3f3f3f3f3f3f3f3f3f\n\nn, v = gets.split().map(&:to_i)\ncost = gets.split().map(&:to_i)\n\nbest = []\nbest[0] = INF\nres = INF\nfor i in 1..n\n\tbest[i] = [2*best[i-1], cost[i-1]].min\n\tif 2**(i-1) > v\n\t\tres = [res, best[i]].min\n\tend\nend\nfor i in n+1..70\n\tbest[i] = 2*best[i-1]\n\tif 2**(i-1) > v\n\t\tres = [res, best[i]].min\n\tend\nend\n\nans = INF\nvv = v\nwhile (vv & -vv) != vv\n\ttemp = 0\n\tj = 0\n\tv = vv\n\twhile v > 0\n\t\tj += 1\n\t\tif v % 2 == 1\n\t\t\ttemp += best[j]\n\t\tend\n\t\tv /= 2\n\tend\n\tans = [ans, temp].min\n\tvv += vv & -vv\nend\n\nputs [res, ans].min\n"}], "src_uid": "04ca137d0383c03944e3ce1c502c635b"} {"nl": {"description": "A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011\u00a0\u2014 are quasibinary and numbers 2, 12, 900 are not.You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers.", "input_spec": "The first line contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009106).", "output_spec": "In the first line print a single integer k\u00a0\u2014 the minimum number of numbers in the representation of number n as a sum of quasibinary numbers. In the second line print k numbers \u2014 the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal n. Do not have to print the leading zeroes in the numbers. The order of numbers doesn't matter. If there are multiple possible representations, you are allowed to print any of them.", "sample_inputs": ["9", "32"], "sample_outputs": ["9\n1 1 1 1 1 1 1 1 1", "3\n10 11 11"], "notes": null}, "positive_code": [{"source_code": "# cook your code here\nn=gets.to_i\narr = Array.new(10,0)\nt=1\nm=0\nwhile n>0\n b=n%10\n j=9\n while j>9-b\n arr[j]=(arr[j]+t)\n j-=1\n end\n t=(t*10)\n if(b>m)\n m=b\n end\n n=(n/10)\nend\nputs m\nfor i in 0..9\n if arr[i]!=0\n print arr[i].to_s + ' '\n end\nend\n \n"}, {"source_code": "#!/usr/bin/env ruby\nn=gets.chomp.chars.map(&:to_i)\na=n.size.times.map{[0]*9}\nn.each_with_index{|e,i|e.times{|j|a[i][j]=1}}\na=a.transpose.map{|e|e.join.to_i}.select{|e|e>0}\np a.size\nputs a*' '"}, {"source_code": "n = gets.strip.split(//).map(&:to_i)\nans = n.max\nputs ans\nans.times do |i|\n pp = false\n n.size.times do |j|\n if n[j] > 0\n pp = true\n print 1\n n[j] -= 1\n elsif pp\n print 0\n end\n end\n if i < ans - 1\n print \" \"\n end\nend\nputs\n"}, {"source_code": "#http://codeforces.com/problemset/problem/538/B\n\nn = gets.to_i \n\narr = Array.new(9,0) \nk = 1 \nlargest = 0 \nwhile(n!=0) do \n individual = n%10 \n if individual > largest \n largest = individual \n end \n\n ind = 0 \n individual.times do\n arr[ind] += k \n ind +=1 \n end\n\n k= k*10 \n n = n/10\nend \n\n\nind = 0 \nputs largest \narr.select! do |i| \n i>0 \nend \n\nputs arr.join(' ')\n"}, {"source_code": "n=gets.chomp\n\nn=n.to_i\nb = n\n\na = 0\nd = 0\n\nc = []\n\nwhile b >= 10\n\ta+=1\n\tif b%10>d\n\t\td=b%10\n\tend\n\tc.push(b%10)\n\n\tb/=10\nend\n\nc.push(b)\n\na+=1\n\nif b != 0\n\tif b%10>d\n\t\td=b%10\n\tend\nend\n\narr = []\n\nfor i in (1..d)\n\tx=0\n\tfor j in 0..(c.length - 1)\n\t\tif c[j] > 0\n\t\t\tx+=10**j\n\t\t\tc[j]-=1\n\t\tend\n\tend\n\tarr.push(x)\nend\n\nputs arr.length\n\narr.each do |i|\n\tprint i\n\tprint ' '\nend"}, {"source_code": "arr=[]\nc=0\ngets.chomp.chars{|e|\n\tarr<0 then\n\t\t\t\te-=1\n\t\t\t\tc1+=1\n\t\t\t\tc-=1\n\t\t\t\ts1<<\"1\"\n\t\t\telse\n\t\t\t\ts1<<\"0\"\n\t\t\tend\n\t\t\te\n\t\t}\n\t\tans< 0\n arr << 1\n n[index] -= 1\n else\n arr << 0\n end\n }\n ar << arr.join\nend\n\nputs ar.length\nputs ar.join(' ')\n\n"}, {"source_code": "n = gets.chomp.split(\"\").collect{|i| i.to_i}\nk = n.max\nans = Array.new(k){Array.new}\nn.each do |i|\n for j in 0...i\n ans[j].push('1')\n end\n for j in i...k\n ans[j].push('0')\n end\nend\nans = ans.collect{|i| i.join.to_i}\nputs k\nputs ans.join(\" \")\n"}, {"source_code": "n = gets.chomp.chars.map(&:to_i)\na = []\nwhile n.any?{|x| x > 0}\n a << n.reduce(0){|x, y| x * 10 + (y > 0 ? 1 : 0)}\n n.map!{|x| x - 1}\nend\nputs a.size, a * ' '\n"}, {"source_code": "n = gets.chomp.chars.map(&:to_i)\na = []\nwhile !n.all?{|x| x == 0}\n b = []\n n.size.times do |i|\n if n[i] > 0\n n[i] -= 1\n b << 1\n else\n b << 0\n end\n end\n a << b\nend\nputs a.size\nputs a.map{|x| x.join('').to_i}.join(' ')\n"}, {"source_code": "n=gets.chomp\nd=Array.new\nfor i in 0...n.length\n d.push(n[i].to_i)\nend\nm=d.max\n# puts \"m=#{m}\"\nputs m\nans=[]\nfor i in 0...m\n num=0\n for j in 0...n.length\n num*=10\n if d[j]>0\n d[j]-=1\n num+=1\n end\n end\n ans.push(num)\nend\nputs ans.join(\" \")"}, {"source_code": "n = gets.chomp.scan(/./)\nmaxx = n.map {|i| i.to_i}.max\nputs maxx\nfor i in 0...maxx\n x = [0] * n.length\n for j in 0...n.length\n if n[j].to_i != 0\n x[j] = 1\n n[j] = (n[j].to_i - 1).to_s\n end\n end\n print x.join('').to_i, ' '\nend\n"}], "negative_code": [{"source_code": "puts \"Please enter your number:\"\nprint '> '\n\nn=gets.chomp\n\nn=n.to_i\nb = n\n\na = 0\nd = 0\n\nc = []\n\nwhile b > 10\n\ta+=1\n\tif b%10>d\n\t\td=b%10\n\tend\n\tc.push(b%10)\n\n\tb/=10\nend\n\nc.push(b)\n\na+=1\n\nif b != 0\n\tif b%10>d\n\t\td=b%10\n\tend\nend\n\narr = []\n\nfor i in (1..d)\n\tx=0\n\tfor j in 0..(c.length - 1)\n\t\tif c[j] > 0\n\t\t\tx+=10**j\n\t\t\tc[j]-=1\n\t\tend\n\tend\n\tarr.push(x)\nend\n\nputs arr.length\n\narr.each do |i|\n\tprint i\n\tprint ' '\nend"}, {"source_code": "n=gets.chomp\n\nn=n.to_i\nb = n\n\na = 0\nd = 0\n\nc = []\n\nwhile b > 10\n\ta+=1\n\tif b%10>d\n\t\td=b%10\n\tend\n\tc.push(b%10)\n\n\tb/=10\nend\n\nc.push(b)\n\na+=1\n\nif b != 0\n\tif b%10>d\n\t\td=b%10\n\tend\nend\n\narr = []\n\nfor i in (1..d)\n\tx=0\n\tfor j in 0..(c.length - 1)\n\t\tif c[j] > 0\n\t\t\tx+=10**j\n\t\t\tc[j]-=1\n\t\tend\n\tend\n\tarr.push(x)\nend\n\nputs arr.length\n\narr.each do |i|\n\tprint i\n\tprint ' '\nend"}, {"source_code": "n = gets.to_i\nl = n.to_s.chars.length\ns = ('1' * l).to_i\na = []\nwhile n != 0\n if n - s >= 0\n n -= s\n a << s\n else\n t = s.to_s\n if t.count('1') >= 2\n t[t.rindex('1')] = '0'\n s = t.to_i\n else\n s /= 10\n end\n end\nend\nputs a.size\nputs a.join(' ')\n"}, {"source_code": "n = gets.to_i\nl = n.to_s.chars.length\ns = ('1' * l).to_i\na = []\nwhile n != 0\n if n - s >= 0\n n -= s\n a << s\n else\n t = s.to_s\n if t.count('1') >= 2\n t[t.rindex('1')] = '0'\n s = t.to_i\n else\n s /= 10\n end\n end\nend\nputs a.join(' ')\n"}], "src_uid": "033068c5e16d25f09039e29c88474275"} {"nl": {"description": "Alena has successfully passed the entrance exams to the university and is now looking forward to start studying.One two-hour lesson at the Russian university is traditionally called a pair, it lasts for two academic hours (an academic hour is equal to 45 minutes).The University works in such a way that every day it holds exactly n lessons. Depending on the schedule of a particular group of students, on a given day, some pairs may actually contain classes, but some may be empty (such pairs are called breaks).The official website of the university has already published the schedule for tomorrow for Alena's group. Thus, for each of the n pairs she knows if there will be a class at that time or not.Alena's House is far from the university, so if there are breaks, she doesn't always go home. Alena has time to go home only if the break consists of at least two free pairs in a row, otherwise she waits for the next pair at the university.Of course, Alena does not want to be sleepy during pairs, so she will sleep as long as possible, and will only come to the first pair that is presented in her schedule. Similarly, if there are no more pairs, then Alena immediately goes home.Alena appreciates the time spent at home, so she always goes home when it is possible, and returns to the university only at the beginning of the next pair. Help Alena determine for how many pairs she will stay at the university. Note that during some pairs Alena may be at the university waiting for the upcoming pair.", "input_spec": "The first line of the input contains a positive integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009100) \u2014 the number of lessons at the university. The second line contains n numbers ai (0\u2009\u2264\u2009ai\u2009\u2264\u20091). Number ai equals 0, if Alena doesn't have the i-th pairs, otherwise it is equal to 1. Numbers a1,\u2009a2,\u2009...,\u2009an are separated by spaces.", "output_spec": "Print a single number \u2014 the number of pairs during which Alena stays at the university.", "sample_inputs": ["5\n0 1 0 1 1", "7\n1 0 1 0 0 1 0", "1\n0"], "sample_outputs": ["4", "4", "0"], "notes": "NoteIn the first sample Alena stays at the university from the second to the fifth pair, inclusive, during the third pair she will be it the university waiting for the next pair. In the last sample Alena doesn't have a single pair, so she spends all the time at home."}, "positive_code": [{"source_code": "n=gets.to_i\na=gets.split(\" \").map(&:to_i).map{|x| x == 1 }\n\nuniv = false\ncount = 0\nfor i in 0...a.size\n\tif !univ\n\t\tif a[i]\n\t\t\tuniv = true\n\t\tend\n\tend\n\tif univ && !a[i] && !a[i+1]\n\t\tuniv = false\n\tend\n\n\tcount += 1 if univ\nend\n\np count\n"}, {"source_code": "n, pairs = gets.chomp.to_i, gets.chomp.split(\" \").join(\"\")\npairs.gsub! /(^0+|00+|0+$)/, \"\"\nputs pairs.length "}, {"source_code": "n, pairs = gets.chomp.to_i, gets.chomp.split(\" \")\nloop do\n\tpairs[0] == \"0\" ? pairs.delete_at(0) : break\nend\nloop do\n\tpairs[-1] == \"0\" ? pairs.delete_at(-1) : break\nend\npairs = pairs.join \"\"\npairs.gsub! /00+/, \"\"\nputs pairs.length "}, {"source_code": "n = gets.chomp.to_i\nv = gets.split.map{ |x| x.to_i}\n\nstart = -1\nlast = n+1\nzero = 0\nless = 0\nn.times do |i|\n start = i if v[i] == 1 and start == -1\n last = i if v[i] == 1\n if v[i] == 0 and start != -1\n zero += 1\n end\n if v[i] == 1 \n if zero >= 2\n less += zero\n end\n zero = 0\n end\nend\nif start != -1\n puts last-start-less+1\nelse\n puts 0\nend\n"}, {"source_code": "# http://codeforces.com/contest/586/problem/A\n# A. Alena's Schedule\nn = gets.chomp.to_i\narr = gets.chomp.split.join.gsub(/0{2,}/, '').chars\n\narr.pop if arr.last == '0'\narr.shift if arr.first == '0'\nputs arr.join.gsub(/00/, '').length\n"}, {"source_code": "gets\na = gets.split(' ').map! {|x| x.to_i} << 0\na.unshift(0)\nans = 0\n\na.size.times do |i|\n ans += 1 if (a[i] == 1.to_i) || ((a[i - 1] == 1) && (a[i + 1] == 1))\nend\n\np ans\n"}, {"source_code": "#! ruby\n# try Codeforces\n# author: Leonardone @ NEETSDKASU\n\nn = gets.to_i\na = gets.chomp.split.map(&:to_i)\n\nstay = :HOME\ncount = 0\ni = 0\n\nwhile i < n\n\tcase stay\n\twhen :HOME\n\t\tif a[i] == 1\n\t\t\tstay = :UNIV\n\t\tend\n\twhen :UNIV\n\t\tif a[i] == 0\n\t\t\tif i == n - 1 || a[i + 1] == 0\n\t\t\t\tstay = :HOME\n\t\t\tend\n\t\tend\n\tend\n\tcount += 1 if stay == :UNIV\n\ti += 1\nend\n\nputs count"}, {"source_code": "a=gets.chomp.to_i\nb=gets.chomp.split(\" \")\nans=0\n\nloop do\nif b[0]==\"0\"\nb.delete_at(0)\nelse\nbreak\nend\nend\nloop do\nif b[b.length-1]==\"0\"\nb.delete_at(b.length-1)\nelse\nbreak\nend\nend\n\n0.upto(b.length) do |i|\nbreak if b[i]==nil\nif b[i]==\"1\"\nans+=1\nelsif b[i-1]==\"1\" && b[i+1]==\"1\"\nans+=1\nend\nend\n\nputs \"#{ans}\"\n"}, {"source_code": "a=gets.chomp.to_i\nb=gets.chomp.split(\" \")\nans=0\n\nloop do\nif b[0]==\"0\"\nb.delete_at(0)\nelse\nbreak\nend\nend\nloop do\nif b[b.length-1]==\"0\"\nb.delete_at(b.length-1)\nelse\nbreak\nend\nend\n\n0.upto(b.length) do |i|\nbreak if b[i]==nil\nif b[i]==\"1\"\nans+=1\nelsif b[i-1]==\"1\" && b[i+1]==\"1\"\nans+=1\nend\nend\n\nputs \"#{ans}\""}, {"source_code": "n=gets.to_i\nx=gets.split.map{|e| e.to_i}\n\n\tx<<0\n\tans=0\n\ti=0\n\twhile i<(x.size-1) && x[i]==0\n\t\ti+=1\n\tend\n\twhile i<(x.size-1)\n\t\tif x[i]!=0 || x[i+1]!=0 then\n\t\t\tans+=1\n\t\t\ti+=1\n\t\telse\n\t\t\twhile i<(x.size-1) && x[i]==0\n\t\t\t\ti+=1\n\t\t\tend\n\t\tend\n\tend\n\tputs ans\n\n"}, {"source_code": "n = gets.chomp.to_i\nas = gets.chomp.split(' ').map(&:to_i)\n\nfor i in 0..n-3\n if as[i] * as[i + 2] == 1 && as[i + 1] == 0\n as[i + 1] = 1\n end\nend\n\nputs as.inject{|s, a| s + a }\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nstatus, ans = 0, 0\nn.times do |i|\n if a[i] == 1\n status = 1\n ans += 1\n elsif status == 1 && (i != 0 && a[i - 1] == 1) && (i + 1 != n && a[i + 1] == 1)\n ans += 1\n end\nend\np ans\n"}, {"source_code": "\nn = gets.to_i\nv = gets.split.map(&:to_i)\ncont = 0\nsw = 0\nc = 0\nfor i in(0..(n-1))\n if v[i] == 1\n sw = 1\n end\n if sw == 1\n if(v[i]==0)\n c+=1\n elsif c < 2 \n cont=cont+1+c\n c=0\n else\n cont+=1\n c=0\n end\n end\nend\np cont"}, {"source_code": "# coding: utf-8\n\nn = gets.to_i\nsched = gets.strip.gsub(' ', '')\n\nsched.gsub!(/^0+/, '')\nsched.gsub!(/0+$/, '')\nsched.gsub!(/0{2,}/, '')\n\nputs sched.length.to_s"}, {"source_code": "# #325 Div2 A. Alena's Schedule\nn = gets.chomp.to_i\na = gets.chomp.split(\" \").map(&:to_i)\nlesson = 0\nrest = 0\na.each do |i|\n if i == 1 then\n if rest == 1 and lesson > 0 then\n lesson += 1\n end\n rest = 0\n lesson += 1\n else\n rest += 1\n end\nend\nputs lesson"}, {"source_code": "a=gets.chomp.to_i\nb=gets.chomp.split(\" \")\nans=0\n\nloop do\nif b[0]==\"0\"\nb.delete_at(0)\nelse\nbreak\nend\nend\nloop do\nif b[b.length-1]==\"0\"\nb.delete_at(b.length-1)\nelse\nbreak\nend\nend\n\n0.upto(b.length) do |i|\nbreak if b[i]==nil\nif b[i]==\"1\"\nans+=1\nelsif b[i-1]==\"1\" && b[i+1]==\"1\"\nans+=1\nend\nend\n\nputs \"#{ans}\""}, {"source_code": "totNum = gets.chomp.to_i\nclassArr = gets.chomp.split(' ').map {|item| item.to_i}\nstart = false\nbreaks = 0\nans = 0\nclassArr.each_with_index do |val, idx|\n\t#puts \"idx : #{idx} , val : #{val} , classArr[idx + 1] : #{classArr[idx + 1]}\"\n\tbreak if idx == classArr.length - 1\n\tstart = true if (val == 1 && !start)\n\t#puts \"start 1 step : #{start}\"\n\tnext if !start\n\tstart = false if (val == 0 && classArr[idx + 1] == 0)\n\t#puts \"start 2 step : #{start}\"\n\tnext if !start\n\tans += 1\nend\nans += 1 if classArr[totNum - 1] == 1\nputs ans"}], "negative_code": [{"source_code": "# http://codeforces.com/contest/586/problem/A\n# A. Alena's Schedule\nn = gets.chomp.to_i\narr = gets.chomp.split.join.gsub(/00/, '').chars\n\narr.pop if arr.last == '0'\narr.shift if arr.first == '0'\nputs arr.join.length\n"}, {"source_code": "# http://codeforces.com/contest/586/problem/A\n# A. Alena's Schedule\nn = gets.chomp.to_i\narr = gets.chomp.split.map(&:to_i)\n\narr.pop if arr.last == 0\narr.shift if arr.first == 0\nputs arr.join.gsub(/00/, '').length\n"}, {"source_code": "# http://codeforces.com/contest/586/problem/A\n# A. Alena's Schedule\nn = gets.chomp.to_i\narr = gets.chomp.split.join.gsub(/0{2,}/, '').chars\n\narr.pop if arr.last == 0\narr.shift if arr.first == 0\nputs arr.join.gsub(/00/, '').length\n"}, {"source_code": "gets.to_i\na = gets.split(' ').map! {|x| x.to_i}\np 0 if a.index(1) == nil\np (a.rindex(1) - a.index(1) + 1)\n\n"}, {"source_code": "a=gets.chomp.to_i\nb=gets.chomp.split(\" \")\nloop do\nif b[0]==\"0\"\nb.delete_at(0)\nelse\nbreak\nend\nend\nloop do\nif b[b.length-1]==\"0\"\nb.delete_at(b.length-1)\nelse\nbreak\nend\nend\ntrig=0\n0.upto(b.length-3) do |i|\nif b[i]==\"0\"&& b[i+1]==\"0\"\nb.delete_at(i)\nb.delete_at(i+1)\nend\nend\nputs \"#{b.length}\"\n"}, {"source_code": "n=gets.to_i\nx=gets.split.map{|e| e.to_i}\nif n==1 then\n\tputs 1\nelse\n\tx<<0\n\tans=0\n\ti=0\n\twhile i<(x.size-1) && x[i]==0\n\t\ti+=1\n\tend\n\twhile i<(x.size-1)\n\t\tif x[i]!=0 || x[i+1]!=0 then\n\t\t\tans+=1\n\t\t\ti+=1\n\t\telse\n\t\t\twhile i<(x.size-1) && x[i]==0\n\t\t\t\ti+=1\n\t\t\tend\n\t\tend\n\tend\n\tputs ans\nend\n\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\n# ab = a.slice_when{|x, y| x != y }.select{|x| x.inject(:+) == 0}\nab = a\nab.shift if a[0] == 0\nab.pop if a[n - 1] == 0\nans = a.inject(:+) + ab.inject(0){|sum, n| sum + (n.size == 1 ? n.size : 0)}\nputs ans\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nans = n\nstatus = 0\nn.times do |i|\n if status.zero? && a[i] == 0\n ans -= 1\n elsif a[i] == 1\n status = 1\n elsif status == 1 && a[i] == 0 && (a[i - 1] == 0 || a[i + 1] == 0)\n ans -= 1\n end\nend\nans -= 1 if a[-1] == 0 && n != 1\np ans\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nans = n\nstatus = 0\nn.times do |i|\n if status.zero? && a[i] == 0\n ans -= 1\n elsif a[i] == 1\n status = 1\n elsif status == 1 && a[i] == 0 && (a[i - 1] == 0 || a[i + 1] == 0)\n ans -= 1\n end\nend\nans -= 1 if a[-1] == 0 && n != 1 && status == 1\np ans\n"}, {"source_code": "n = gets.to_i\nv = gets.split.map(&:to_i)\ncont = 0\nsw = 0\nc = 0\nfor i in(0..(n-1))\n if v[i] == 1\n sw = 1\n end\n if sw == 1\n if(v[i]==0)\n c+=1\n elsif c < 2 \n cont=cont+1+c\n c=0\n else\n cont+=1\n end\n end\nend\np cont"}], "src_uid": "2896aadda9e7a317d33315f91d1ca64d"} {"nl": {"description": "Ralph has a magic field which is divided into n\u2009\u00d7\u2009m blocks. That is to say, there are n rows and m columns on the field. Ralph can put an integer in each block. However, the magic field doesn't always work properly. It works only if the product of integers in each row and each column equals to k, where k is either 1 or -1.Now Ralph wants you to figure out the number of ways to put numbers in each block in such a way that the magic field works properly. Two ways are considered different if and only if there exists at least one block where the numbers in the first way and in the second way are different. You are asked to output the answer modulo 1000000007\u2009=\u2009109\u2009+\u20097.Note that there is no range of the numbers to put in the blocks, but we can prove that the answer is not infinity.", "input_spec": "The only line contains three integers n, m and k (1\u2009\u2264\u2009n,\u2009m\u2009\u2264\u20091018, k is either 1 or -1).", "output_spec": "Print a single number denoting the answer modulo 1000000007.", "sample_inputs": ["1 1 -1", "1 3 1", "3 3 -1"], "sample_outputs": ["1", "1", "16"], "notes": "NoteIn the first example the only way is to put -1 into the only block.In the second example the only way is to put 1 into every block."}, "positive_code": [{"source_code": "def power(x, y, z)\n\tnumber = 1\n\twhile (y > 0) do\n\t\tif (y%2==1)\n\t\t\tnumber = number * x % z\n\t\tend\n\t\ty >>= 1\n\t\tx = x * x % z\n\tend\n\treturn number\nend\n\nn, m, k = gets.split.map(&:to_i)\nif((n + m) % 2 == 1 && k == -1)\n p 0\nelse\n md = 1000000007\n p power(2, (n-1)*(m-1), md)\nend"}, {"source_code": "def pow(a, b, mod)\n ret = 1\n while b > 0\n if (b & 1 == 1)\n ret = ret * a % mod\n end\n b = b / 2\n a = a * a % mod\n end\n return ret\nend\n(n, m, k) = gets.chomp.split.map(&:to_i)\nmod = 10**9 + 7\nans = pow(pow(2, n - 1, mod), m - 1, mod)\nif (n % 2 != m % 2 and k == -1)\n ans = 0\nend\nprint ans"}], "negative_code": [{"source_code": "n, m, k = gets.split.map(&:to_i)\nmd = 1000000007\np (2**((n-1)*(m-1)))%md"}, {"source_code": "def power(x, y, z)\n\tnumber = 1\n\twhile (y > 0) do\n\t\tif (y%2==1)\n\t\t\tnumber = number * x % z\n\t\tend\n\t\ty >>= 1\n\t\tx = x * x % z\n\tend\n\treturn number\nend\n\nn, m, k = gets.split.map(&:to_i)\nmd = 1000000007\np power(2, (n-1)*(m-1), md)"}], "src_uid": "6b9eff690fae14725885cbc891ff7243"} {"nl": {"description": "Many students live in a dormitory. A dormitory is a whole new world of funny amusements and possibilities but it does have its drawbacks. There is only one shower and there are multiple students who wish to have a shower in the morning. That's why every morning there is a line of five people in front of the dormitory shower door. As soon as the shower opens, the first person from the line enters the shower. After a while the first person leaves the shower and the next person enters the shower. The process continues until everybody in the line has a shower.Having a shower takes some time, so the students in the line talk as they wait. At each moment of time the students talk in pairs: the (2i\u2009-\u20091)-th man in the line (for the current moment) talks with the (2i)-th one. Let's look at this process in more detail. Let's number the people from 1 to 5. Let's assume that the line initially looks as 23154 (person number 2 stands at the beginning of the line). Then, before the shower opens, 2 talks with 3, 1 talks with 5, 4 doesn't talk with anyone. Then 2 enters the shower. While 2 has a shower, 3 and 1 talk, 5 and 4 talk too. Then, 3 enters the shower. While 3 has a shower, 1 and 5 talk, 4 doesn't talk to anyone. Then 1 enters the shower and while he is there, 5 and 4 talk. Then 5 enters the shower, and then 4 enters the shower.We know that if students i and j talk, then the i-th student's happiness increases by gij and the j-th student's happiness increases by gji. Your task is to find such initial order of students in the line that the total happiness of all students will be maximum in the end. Please note that some pair of students may have a talk several times. In the example above students 1 and 5 talk while they wait for the shower to open and while 3 has a shower.", "input_spec": "The input consists of five lines, each line contains five space-separated integers: the j-th number in the i-th line shows gij (0\u2009\u2264\u2009gij\u2009\u2264\u2009105). It is guaranteed that gii\u2009=\u20090 for all i. Assume that the students are numbered from 1 to 5.", "output_spec": "Print a single integer \u2014 the maximum possible total happiness of the students.", "sample_inputs": ["0 0 0 0 9\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n7 0 0 0 0", "0 43 21 18 2\n3 0 21 11 65\n5 2 0 1 4\n54 62 12 0 99\n87 64 81 33 0"], "sample_outputs": ["32", "620"], "notes": "NoteIn the first sample, the optimal arrangement of the line is 23154. In this case, the total happiness equals:(g23\u2009+\u2009g32\u2009+\u2009g15\u2009+\u2009g51)\u2009+\u2009(g13\u2009+\u2009g31\u2009+\u2009g54\u2009+\u2009g45)\u2009+\u2009(g15\u2009+\u2009g51)\u2009+\u2009(g54\u2009+\u2009g45)\u2009=\u200932."}, "positive_code": [{"source_code": "def read_next_line\n gets.chomp.split.map(&:to_i)\nend\n\ndef read(range)\n g = []\n range.each {\n g << read_next_line\n }\n g\nend\n\nmatrix_size = 5\n\nr = (0...matrix_size)\ng = read(r)\nmax = 0\nr.to_a.permutation.each { |p|\n happ = 0\n line = r.to_a\n while line.size > 1\n n = line.size\n n -= n % 2\n (0...n).step(2) { |i|\n happ += g[p[line[i]]][p[line[i + 1]]] + g[p[line[i + 1]]][p[line[i]]]\n }\n line.shift\n end\n max = happ if happ > max\n}\nputs max"}], "negative_code": [], "src_uid": "be6d4df20e9a48d183dd8f34531df246"} {"nl": {"description": "Polycarpus has recently got interested in sequences of pseudorandom numbers. He learned that many programming languages generate such sequences in a similar way: (for i\u2009\u2265\u20091). Here a, b, m are constants, fixed for the given realization of the pseudorandom numbers generator, r0 is the so-called randseed (this value can be set from the program using functions like RandSeed(r) or srand(n)), and denotes the operation of taking the remainder of division.For example, if a\u2009=\u20092,\u2009b\u2009=\u20096,\u2009m\u2009=\u200912,\u2009r0\u2009=\u200911, the generated sequence will be: 4,\u20092,\u200910,\u20092,\u200910,\u20092,\u200910,\u20092,\u200910,\u20092,\u200910,\u2009....Polycarpus realized that any such sequence will sooner or later form a cycle, but the cycle may occur not in the beginning, so there exist a preperiod and a period. The example above shows a preperiod equal to 1 and a period equal to 2.Your task is to find the period of a sequence defined by the given values of a,\u2009b,\u2009m and r0. Formally, you have to find such minimum positive integer t, for which exists such positive integer k, that for any i\u2009\u2265\u2009k: ri\u2009=\u2009ri\u2009+\u2009t.", "input_spec": "The single line of the input contains four integers a, b, m and r0 (1\u2009\u2264\u2009m\u2009\u2264\u2009105,\u20090\u2009\u2264\u2009a,\u2009b\u2009\u2264\u20091000,\u20090\u2009\u2264\u2009r0\u2009<\u2009m), separated by single spaces.", "output_spec": "Print a single integer \u2014 the period of the sequence.", "sample_inputs": ["2 6 12 11", "2 3 5 1", "3 6 81 9"], "sample_outputs": ["2", "4", "1"], "notes": "NoteThe first sample is described above. In the second sample the sequence is (starting from the first element): 0,\u20093,\u20094,\u20091,\u20090,\u20093,\u20094,\u20091,\u20090,\u2009...In the third sample the sequence is (starting from the first element): 33,\u200924,\u200978,\u200978,\u200978,\u200978,\u2009..."}, "positive_code": [{"source_code": "a, b, m, r = gets.split.map(&:to_i)\nt, s = [nil] * r, 0\nloop do\n if t[r]\n p s - t[r]\n break\n else\n t[r] = s\n r = (a * r + b) % m\n s += 1\n end\nend\n"}, {"source_code": "a,b,m,r=gets.split.map(&:to_i)\nback_r=Hash.new\nback_r[r]=(now=0)\nloop do\n r=(a*r+b)%m\n now+=1\n if back_r.key?(r)\n puts now-back_r[r]\n break\n end\n back_r[r]=now\nend\n"}, {"source_code": "input = STDIN.read\n\ninput =~ /^(\\d+) (\\d+) (\\d+) (\\d+)/\na, b, m, $r0 = $1.to_i, $2.to_i, $3.to_i, $4.to_i\n\nvalues1, values2 = Array.new, Array.new\n\ndef get_next_value(a, b, m, r)\n r ||= $r0\n (a * r + b) % m\nend\n\nelement = nil\n\nwhile true\n values1 << get_next_value(a, b, m, values1.last)\n values2 << get_next_value(a, b, m, values2.last)\n values2 << get_next_value(a, b, m, values2.last)\n\n if values1.last == values2.last\n element = values1.last\n break\n end\nend\n\nresult = -1\ni = values2.length - 2\nuntil i < 0\n if element == values2[i]\n result = values2.length - 1 - i\n break\n end\n i -= 1\nend\n\nputs result\n\n"}, {"source_code": "a,b,m,r = gets.split.map(&:to_i)\n\nar = Array.new(m)\nar[r]=0\ni = 0\nloop do\n i += 1\n r = (a*r+b)%m\n if ar[r]\n puts i - ar[r]\n break\n end\n ar[r] = i\nend\n"}, {"source_code": "a,b,m,r=gets.split.map &:to_i;\nv=[0]*m;v[r=(a*r+b)%m]+=1 while v[r]!=3;\nprint 1+v.count(2);"}, {"source_code": "a,b,m,r = gets.split.map &:to_i\nar = [nil]*100000\ni = 0\nwhile true \n r = (a*r+b)%m\n if ar[r]\n p i-ar[r]\n exit\n end \n ar[r] = i\n i += 1\nend\n"}, {"source_code": "line = $stdin.gets.strip.split(/\\s+/)\na = line[0].to_i\nb = line[1].to_i\nm = line[2].to_i\nr = line[3].to_i\nm.times {r = (a*r + b) % m } #going through the pre-period\nrr = r\ni = 0\nloop do\n i += 1\n r = (a*r + b) % m\n if rr == r\n puts i\n exit 0\n end\nend\n"}, {"source_code": "a, b, m, r0 = gets.split.map{|i| i.to_i}\ns = Array.new(100000, 0)\nt = 1\nr = r0\nwhile s[r] == 0\n s[r] = t\n t += 1\n r = (a * r + b) % m\nend\nputs t - s[r]\n"}, {"source_code": "a,b,m,r = gets.split.map &:to_i\nt = [0]*m\nwhile t[r] != 3\n\tt[r = (a*r+b)%m] += 1\nend\n\nputs 1+t.count(2)"}], "negative_code": [], "src_uid": "9137197ee1b781cd5cc77c46f50b9012"} {"nl": {"description": "The weather is fine today and hence it's high time to climb the nearby pine and enjoy the landscape.The pine's trunk includes several branches, located one above another and numbered from 2 to y. Some of them (more precise, from 2 to p) are occupied by tiny vile grasshoppers which you're at war with. These grasshoppers are known for their awesome jumping skills: the grasshopper at branch x can jump to branches .Keeping this in mind, you wisely decided to choose such a branch that none of the grasshoppers could interrupt you. At the same time you wanna settle as high as possible since the view from up there is simply breathtaking.In other words, your goal is to find the highest branch that cannot be reached by any of the grasshoppers or report that it's impossible.", "input_spec": "The only line contains two integers p and y (2\u2009\u2264\u2009p\u2009\u2264\u2009y\u2009\u2264\u2009109).", "output_spec": "Output the number of the highest suitable branch. If there are none, print -1 instead.", "sample_inputs": ["3 6", "3 4"], "sample_outputs": ["5", "-1"], "notes": "NoteIn the first sample case grasshopper from branch 2 reaches branches 2, 4 and 6 while branch 3 is initially settled by another grasshopper. Therefore the answer is 5.It immediately follows that there are no valid branches in second sample case."}, "positive_code": [{"source_code": "x,y = gets.split.map(&:to_i)\nprime = []\nk = (y**0.5).to_i\nk = x if k > x\na = Array.new(k+1,1)\ni = 2\nwhile i <= k\n if a[i] == 1\n prime << i\n (k/i).times do |j|\n a[i*j] = 0\n end\n end\n i += 1\nend\nisprime = false\nwhile !isprime && x < y\n isprime = true\n prime.length.times do |i|\n isprime = false if y % prime[i] == 0\n end\n if isprime\n ans = y\n end\n y -= 1\nend\nans = -1 if !isprime\nputs ans"}, {"source_code": "require 'prime'\n\ndef maxprime(x, y)\n y.downto(x){|n| return n if n.prime? }\n -1\nend\n\np, y=gets.split.map &:to_i\nq=maxprime(p+1, y)\n\nif q==-1\n puts -1\n exit\nend\n\np=maxprime(2, p)\nres=q;\nq.upto(y){|x| res=x if x.prime_division[0][0]>p}\nputs res\n"}], "negative_code": [{"source_code": "x,y = gets.split.map(&:to_i)\nprime = []\nk = (y**0.5).to_i\n\na = Array.new(k+1,1)\ni = 2\nwhile i <= k\n if a[i] == 1\n prime << i\n (k/i).times do |j|\n a[i*j] = 0\n end\n end\n i += 1\nend\nisprime = false\nwhile !isprime && x < y\n isprime = true\n prime.length.times do |i|\n isprime = false if y % prime[i] == 0\n end\n if isprime\n ans = y\n end\n y -= 1\nend\nans = -1 if !isprime\nputs ans"}, {"source_code": "require 'prime'\np, y=gets.split.map &:to_i\ny.downto(p+1){|x|\n if x.prime?\n puts x\n exit\n end\n}\nputs -1\n"}], "src_uid": "b533203f488fa4caf105f3f46dd5844d"} {"nl": {"description": "Once upon a time in the Kingdom of Far Far Away lived Sam the Farmer. Sam had a cow named Dawn and he was deeply attached to her. Sam would spend the whole summer stocking hay to feed Dawn in winter. Sam scythed hay and put it into haystack. As Sam was a bright farmer, he tried to make the process of storing hay simpler and more convenient to use. He collected the hay into cubical hay blocks of the same size. Then he stored the blocks in his barn. After a summer spent in hard toil Sam stored A\u00b7B\u00b7C hay blocks and stored them in a barn as a rectangular parallelepiped A layers high. Each layer had B rows and each row had C blocks.At the end of the autumn Sam came into the barn to admire one more time the hay he'd been stacking during this hard summer. Unfortunately, Sam was horrified to see that the hay blocks had been carelessly scattered around the barn. The place was a complete mess. As it turned out, thieves had sneaked into the barn. They completely dissembled and took away a layer of blocks from the parallelepiped's front, back, top and sides. As a result, the barn only had a parallelepiped containing (A\u2009-\u20091)\u2009\u00d7\u2009(B\u2009-\u20092)\u2009\u00d7\u2009(C\u2009-\u20092) hay blocks. To hide the evidence of the crime, the thieves had dissembled the parallelepiped into single 1\u2009\u00d7\u20091\u2009\u00d7\u20091 blocks and scattered them around the barn. After the theft Sam counted n hay blocks in the barn but he forgot numbers A, B \u0438 C.Given number n, find the minimally possible and maximally possible number of stolen hay blocks.", "input_spec": "The only line contains integer n from the problem's statement (1\u2009\u2264\u2009n\u2009\u2264\u2009109).", "output_spec": "Print space-separated minimum and maximum number of hay blocks that could have been stolen by the thieves. Note that the answer to the problem can be large enough, so you must use the 64-bit integer type for calculations. Please, do not use the %lld specificator to read or write 64-bit integers in \u0421++. It is preferred to use cin, cout streams or the %I64d specificator.", "sample_inputs": ["4", "7", "12"], "sample_outputs": ["28 41", "47 65", "48 105"], "notes": "NoteLet's consider the first sample test. If initially Sam has a parallelepiped consisting of 32\u2009=\u20092\u2009\u00d7\u20094\u2009\u00d7\u20094 hay blocks in his barn, then after the theft the barn has 4\u2009=\u2009(2\u2009-\u20091)\u2009\u00d7\u2009(4\u2009-\u20092)\u2009\u00d7\u2009(4\u2009-\u20092) hay blocks left. Thus, the thieves could have stolen 32\u2009-\u20094\u2009=\u200928 hay blocks. If Sam initially had a parallelepiped consisting of 45\u2009=\u20095\u2009\u00d7\u20093\u2009\u00d7\u20093 hay blocks in his barn, then after the theft the barn has 4\u2009=\u2009(5\u2009-\u20091)\u2009\u00d7\u2009(3\u2009-\u20092)\u2009\u00d7\u2009(3\u2009-\u20092) hay blocks left. Thus, the thieves could have stolen 45\u2009-\u20094\u2009=\u200941 hay blocks. No other variants of the blocks' initial arrangement (that leave Sam with exactly 4 blocks after the theft) can permit the thieves to steal less than 28 or more than 41 blocks."}, "positive_code": [{"source_code": "require 'prime'\n\ndef sub(b, s)\n if b.empty?\n v = (s[0]+1)*(s[1]+2)*(s[2]+2) - s[0]*s[1]*s[2]\n return [v, v]\n end\n\n b = b.dup\n k, v = b.pop\n\n result = [1e100, 0]\n 0.upto(v) do |i|\n 0.upto(v-i) do |j|\n mn, mx = sub(b, [s[0]*k**i, s[1]*k**j, s[2]*k**(v-i-j)])\n result[0] = [result[0], mn].min\n result[1] = [result[1], mx].max\n end\n end\n\n result\nend\n\n\ndef solve(n)\n a = Prime.prime_division(n)\n\n s1 = sub(a, [1, 1, 1])\n\n=begin\n b = a.map{|k,v| [k]*v}.flatten\n r = []\n (3**b.size).times do |i|\n o = [1]*3\n (\"0\"*b.size+i.to_s(3))[-b.size,b.size].each_char.zip(b) do |j, k|\n o[j.to_i] *= k\n end\n r << [(o[0]+1)*(o[1]+2)*(o[2]+2) - o[0]*o[1]*o[2], o]\n end\n s2 = [r.min[0], r.max[0]]\n=end\n s1\nend\n\nn = gets.to_i\nputs solve(n)*\" \"\n"}, {"source_code": "n = gets.to_i\ni, mx, mn = 0, 0, 1e10\nwhile i*i*i <= n\n i += 1\n next if n%i > 0\n j = i-1\n while i*j*j <= n\n j += 1\n next if n/i%j > 0\n mx = [mx, (i+2)*(j+2)*(n/i/j+1)].max\n mn = [mn, (i+1)*(j+2)*(n/i/j+2)].min\n end\nend\nputs [mn-n, mx-n] * \" \""}], "negative_code": [{"source_code": "n = gets.to_i\ni, mx, mn = 0, 0, 1e9\nwhile i*i*i <= n\n i += 1\n next if n%i > 0\n j = i-1\n while i*j*j <= n\n j += 1\n next if n/i%j > 0\n mx = [mx, (i+2)*(j+2)*(n/i/j+1)].max\n mn = [mn, (i+1)*(j+2)*(n/i/j+2)].min\n end\nend\nputs [mn-n, mx-n] * \" \""}], "src_uid": "2468eead8acc5b8f5ddc51bfa2bd4fb7"} {"nl": {"description": "Each of you probably has your personal experience of riding public transportation and buying tickets. After a person buys a ticket (which traditionally has an even number of digits), he usually checks whether the ticket is lucky. Let us remind you that a ticket is lucky if the sum of digits in its first half matches the sum of digits in its second half.But of course, not every ticket can be lucky. Far from it! Moreover, sometimes one look at a ticket can be enough to say right away that the ticket is not lucky. So, let's consider the following unluckiness criterion that can definitely determine an unlucky ticket. We'll say that a ticket is definitely unlucky if each digit from the first half corresponds to some digit from the second half so that each digit from the first half is strictly less than the corresponding digit from the second one or each digit from the first half is strictly more than the corresponding digit from the second one. Each digit should be used exactly once in the comparisons. In other words, there is such bijective correspondence between the digits of the first and the second half of the ticket, that either each digit of the first half turns out strictly less than the corresponding digit of the second half or each digit of the first half turns out strictly more than the corresponding digit from the second half.For example, ticket 2421 meets the following unluckiness criterion and will not be considered lucky (the sought correspondence is 2\u2009>\u20091 and 4\u2009>\u20092), ticket 0135 also meets the criterion (the sought correspondence is 0\u2009<\u20093 and 1\u2009<\u20095), and ticket 3754 does not meet the criterion. You have a ticket in your hands, it contains 2n digits. Your task is to check whether it meets the unluckiness criterion.", "input_spec": "The first line contains an integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009100). The second line contains a string that consists of 2n digits and defines your ticket.", "output_spec": "In the first line print \"YES\" if the ticket meets the unluckiness criterion. Otherwise, print \"NO\" (without the quotes).", "sample_inputs": ["2\n2421", "2\n0135", "2\n3754"], "sample_outputs": ["YES", "YES", "NO"], "notes": null}, "positive_code": [{"source_code": "n = gets.chomp.to_i\nm = gets.chomp.split(//).map!{|x| x.to_i}\nm1 = m.slice(0,n)\nm2 = m.slice(n,n)\nm1.sort!\nm2.sort!\nret = \"YES\"\nif m1[0] == m2[0] || m1[n-1] == m2[n-1]\n\tret = \"NO\"\nelse\n\tif ( m1[0] < m2[0] && m1[n-1] > m2[n-1] ) || ( m1[0] > m2[0] && m1[n-1] < m2[n-1] )\n\t\tret = \"NO\"\n\telse\n\t\tflg = 1\n\t\tif m1[0] < m2[0]\n\t\t\tflg = -1\n\t\tend\n\t\tfor i in 0..n-1\n\t\t\tif ( flg == 1 && m1[i] <= m2[i] ) || (flg == -1 && m1[i] >= m2[i] )\n\t\t\t\tret = \"NO\"\n\t\t\t\tbreak\n\t\t\tend\n\t\tend\n\tend\nend\nputs ret"}, {"source_code": "l = gets.chomp.to_i\nn = gets.chomp\na = n.split('');\nd = []\n\na.each_index{|i| d[i] = a[i].to_i}\n#puts d.first(1);\nb = d.first(l);\nc = d.last(l);\nb = b.sort\nc = c.sort\n#puts b\n#puts c\nb.each_index{|i| b[i] -= c[i]} \n\nb = b.sort\n#puts b\nif b[0]*b[-1] <= 0 then\n puts \"NO\"\nelse\n puts \"YES\"\nend\n"}, {"source_code": "n = gets.to_i\ns = gets.chomp\nt = [s[0, n], s[n, n]].map{|_| _.chars.to_a.sort}.transpose\nputs t.all?{|i, j| i < j} || t.all?{|i, j| i > j} ? :YES : :NO\n"}, {"source_code": "def solve(a,b)\n x=[]\n y=[]\n a.length.times do |i|\n x.push(a[i].to_i)\n y.push(b[i].to_i)\n end\n x.sort!\n y.sort!\n\n a.length.times do |i|\n return false if x[i]>=y[i]\n end\n return true\nend\n\nn=gets.to_i\na=gets.split[0]\nx=a[0..n-1]\ny=a[n..2*n-1]\nif solve(x,y) || solve(y,x)\n puts \"YES\"\nelse\n puts \"NO\"\nend\n\n"}, {"source_code": "n = gets.to_i\ns = gets.chomp\n\nl = s[0...n].split(//).map(&:to_i).sort\nr = s[n...2*n].split(//).map(&:to_i).sort\n\nlh, rh = true, true\nfor i in 0...n do\n lh = lh && l[i] < r[i]\n rh = rh && l[i] > r[i]\nend\n\nputs(if lh || rh then \"YES\" else \"NO\" end)"}, {"source_code": "\ufeffn = gets.chomp.to_i\na = gets.chomp.split(\"\").map{|e| e.to_i}\n\nfirst = a[0..(n - 1)].sort!\nsecond = a[n..(2 * n - 1)].sort!\n\nless = true\nmore = true\n0.upto(n - 1) do |i|\n if first[i] <= second[i]\n less = false\n end\n \n if first[i] >= second[i]\n more = false\n end \nend\n\nif less or more\n puts \"YES\"\nelse\n puts \"NO\"\nend"}, {"source_code": "n = STDIN.readline.to_i\ns = STDIN.readline.strip\na, b = s[0..n-1], s[n..2*n-1]\na = a.split('').map {|s| s.to_i }.sort\nb = b.split('').map {|s| s.to_i }.sort\nless, greater = true, true\nn.times do |i|\n less = false if a[i] >= b[i]\n greater = false if a[i] <= b[i]\nend\nputs less || greater ? 'YES' : 'NO'\n"}, {"source_code": "n,s = gets.to_i, gets.strip.split('').map(&:to_i)\na,b = s[0..n-1].sort.reverse, s[n..-1].sort.reverse\nb = a.zip(b).map { |x,y| x-y }\nputs (b.find_all { |x| x < 0 }.size == n or b.find_all { |x| x > 0 }.size == n) ? \"YES\" : \"NO\""}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split(//).map!{|x| x.to_i}\nq = Array.new\nw = Array.new\nfor i in 0..n-1\n q[i] = a[i]\n w[i] = a[n+i]\nend\n\nq = q.sort\nw = w.sort\n\nif q[0] < w[0]\n t = 0\nelsif q[0] > w[0]\n t = 1\nelse\n t = 2\nend\n\nfor i in 1..n-1\n if q[i] < w[i] && t === 1\n t = 2\n break\n elsif q[i] > w[i] && t === 0\n t = 2\n break\n elsif q[i] === w[i]\n t = 2\n break\n elsif t === 2\n break\n end\nend\n\nif t === 2\n puts \"NO\"\nelse\n puts \"YES\"\nend"}, {"source_code": "n = gets.to_i\na = gets.strip\n\nf = a[0..n-1].split(//).map(&:to_i).sort\ns = a[n..2*n].split(//).map(&:to_i).sort\n\nz = f.zip(s)\nprint (z.all?{|e| e[0] > e[1]} || z.all?{|e| e[0] < e[1]}) ? \"YES\" : \"NO\"\n"}, {"source_code": "#!/usr/bin/ruby\n# coding: utf-8\n\nn = $stdin.gets.to_i\nxs = $stdin.gets.chomp.chars.map(&:to_i)\nys = xs[0 .. n-1].sort\nzs = xs[n .. 2*n-1].sort\n\nputs (ys.zip(zs).all? { |y, z| y < z } or ys.zip(zs).all? { |y, z| y > z }) ? 'YES' : 'NO'\n"}, {"source_code": "#!/usr/bin/ruby\nn = STDIN.gets.chomp.to_i\nline = STDIN.gets.chomp\nleft = line[0..n-1].split(//).map(&:to_i).sort\nright = line[n..2*n].split(//).map(&:to_i).sort\n\nok1 = true\n0.upto(n - 1) do |i|\n ok1 &= left[i] < right[i]\nend\n\nok2 = true\n0.upto(n - 1) do |i|\n ok2 &= left[i] > right[i]\nend\n\nif ok1 or ok2\n puts \"YES\"\nelse\n puts \"NO\"\nend\n"}, {"source_code": "n = Integer(gets)\ninput = gets.chomp\nnum = Array.new\nfor i in 0...2*n\n num[i] = Integer(input[i])\nend\nleft = Array.new\nright = Array.new\nfor i in 0...n\n left.push(num[i])\n right.push(num[i + n])\nend\nleft = left.sort\nright = right.sort\n\ndef less(left,right)\n if left < right\n return true\n else\n return false\n end\nend\ndef more(left,right)\n if left > right\n return true\n else\n return false\n end\nend\nc = 0\nif n == 1\n if left[0] != right[0]\n c = 1\n end\nelse\n\n if left[0] > right[0]\n for i in 1...n\n if more(left[i],right[i])\n c = 1\n else\n c = 0\n break\n end\n end\n elsif left[0] < right[0]\n for i in 1...n\n if less(left[i],right[i])\n c = 1\n else\n c = 0\n break\n end\n end\n end\nend\nif c == 1\n puts \"YES\"\nelse \n puts \"NO\"\nend"}, {"source_code": "# http://codeforces.ru/problemset/problem/160/B\n\ndef run(input = STDIN.read)\n lines = input.split(\"\\n\")\n\n n = lines[0].to_i\n ticket = lines[1].split(\"\").map(&:to_i)\n\n first = ticket.take(ticket.size / 2).sort\n second = ticket.drop(ticket.size / 2).sort\n \n if (0..n-1).all? { |i| first[i] < second[i] } or\n (0..n-1).all? { |i| first[i] > second[i] } then\n return 'YES'\n else\n return 'NO'\n end\nend\n\nbegin\n require './testing.rb'\nrescue LoadError\n puts run\nend\n__END__\n2\n2421\n=\nYES\n---\n2\n0135\n=\nYES\n---\n2\n3754\n=\nNO"}, {"source_code": "lines = STDIN.read.split(\"\\n\")\n\nn = lines[0].to_i\nticket = lines[1].split(\"\").map(&:to_i)\n\nfirst = ticket.take(ticket.size / 2).sort\nsecond = ticket.drop(ticket.size / 2).sort\n\nif (0..n-1).all? { |i| first[i] < second[i] } or\n (0..n-1).all? { |i| first[i] > second[i] } then\n puts 'YES'\nelse\n puts 'NO'\nend"}, {"source_code": "n = gets.to_i\n\nticket = []\nticket[0] = gets(n)\nticket[1] = gets(n)\n\nticket[0] = ticket[0].chars.sort.join\nticket[1] = ticket[1].chars.sort.join\n\nunlucky = true\nfor i in (0..ticket[0].length-1)\n if ticket[0][i] >= ticket[1][i]\n unlucky = false\n break\n end\nend\n\nif unlucky; puts \"YES\"; Process.exit; end\n\nunlucky = true\nfor i in (0..ticket[0].length-1)\n if ticket[0][i] <= ticket[1][i]\n unlucky = false\n break\n end\nend\n\nif unlucky; puts \"YES\"; Process.exit; end\n\nputs \"NO\""}, {"source_code": "n = gets.chomp.to_i\ndigits = gets.chomp.split(\"\").collect{|i| i.to_i}\n\nleft = digits[0..n-1].sort\nright = digits[n..-1].sort\n\nif left[0] == right[0]\n puts \"NO\"\n exit\nend\n\nif left[0] > right[0]\n left, right = [right, left] \nend\n\nn.times{|i|\n if left[i] >= right[i]\n puts \"NO\"\n exit\n end \n}\n\nputs \"YES\""}, {"source_code": "n=gets.to_i\ns=gets.split''\nputs ((0...n).map{|i| s[0...n].sort[i]<=>s[n...n+n].sort[i] }.reduce(:+).abs==n) ? :YES : :NO"}, {"source_code": "n = gets.to_i\ns = gets.split('')\nl = s[0...n].sort!\nr = s[n...n+n].sort!\nputs ((0...n).map{ |i| l[i] <=> r[i] }.reduce(:+).abs == n) ? \"YES\" : \"NO\"\n"}, {"source_code": "n = Integer(gets.chomp)\ndigits = gets.chomp.split('').map { |x| x.to_i }\nfirst_half = digits[0...n].sort\nsecond_half = digits[n..-1].sort\nop = first_half.first < second_half.first ? :< : first_half.first > second_half.first ? :> : :!=\nres = true\nfor i in 0...n\n unless [first_half[i], second_half[i]].inject(op)\n res = false\n break\n end\nend\nputs(res ? 'YES' : 'NO')"}, {"source_code": "n = gets.to_i\na = gets.split(\"\")\na.pop\n\nfor i in 0 ... a.size\n\ta[i] = a[i].to_i\nend\n\nb = a[0...a.size/2]\nc = a[a.size/2...a.size]\n\nb.sort!\nc.sort!\n\nans = true\nfor i in 1...a.size/2\n\tif b[0] < c[0] then\n\t\tif b[i] >= c[i] then\n\t\t\tans = false\n\t\t\tbreak\n\t\tend\n\telsif b[0] > c[0] then\n\t\tif b[i] <= c[i] then\n\t\t\tans = false\n\t\t\tbreak\n\t\tend\n\telse\n\t\tans = false\n\t\tbreak\n\tend\t\t\nend\nif n == 1 then\n\tans = (b[0] != c[0])\nend\n\nif ans then\n\tputs(\"YES\")\nelse\n\tputs(\"NO\")\nend"}, {"source_code": "input = STDIN.read.split(\"\\n\")\n\nn = input[0].to_i\nnums = input[1].split('').map(&:to_i)\n\nnum1 = nums[0..n-1].sort!\nnum2 = nums[n..-1].sort!\n\nif num1[0] > num2[0]\n\tmore = true\nelsif num1[0] < num2[0]\n\tmore = false\nelse\n\tSTDOUT.puts \"NO\"\n\texit\nend\n\nnum1.length.times do |i|\n\tif more\n\t\tif num1[i] <= num2[i]\n\t\t\tSTDOUT.puts \"NO\"\n\t\t\texit\n\t\tend\n\telse\n\t\tif num1[i] >= num2[i]\n\t\t\tSTDOUT.puts \"NO\"\n\t\t\texit\n\t\tend\n\tend\nend\n\nSTDOUT.puts \"YES\""}], "negative_code": [{"source_code": "def check(b)\n f = true\n if b[0] > 0 then\n f = true\n else\n f = false\n end\n b.each { |el|\n if (f && el < 0 || !f && el > 0 || el == 0)\n puts \"NO\"\n return\n end\n }\n\n puts \"YES\"\n \nend\n\n\nl = gets.chomp.to_i\nn = gets.chomp\na = n.split('');\nd = []\n\na.each_index{|i| d[i] = a[i].to_i}\n#puts d.first(1);\nb = d.first(l);\nc = d.last(l);\nb.each_index{|i| b[i] -= c[i]} \n\ncheck(b)\n"}, {"source_code": "def check(b)\n f = true\n if b[0] > 0 then\n f = true\n else\n f = false\n end\n b.each { |el|\n if (f && el < 0 || !f && el > 0)\n puts \"NO\"\n return\n end\n }\n\n puts \"YES\"\n \nend\n\n\nl = gets.chomp.to_i\nn = gets.chomp\na = n.split('');\nd = []\n\na.each_index{|i| d[i] = a[i].to_i}\n#puts d.first(1);\nb = d.first(l);\nc = d.last(l);\nb.sort\nc.sort\n\nb.each_index{|i| b[i] -= c[i]} \n\ncheck(b)\n"}, {"source_code": "def check(b)\n f = true\n if b[0] > 0 then\n f = true\n else\n f = false\n end\n b.each { |el|\n if (f && el < 0 || !f && el > 0)\n puts \"NO\"\n return\n end\n }\n\n puts \"YES\"\n \nend\n\n\nl = gets.chomp.to_i\nn = gets.chomp\na = n.split('');\nd = []\n\na.each_index{|i| d[i] = a[i].to_i}\n#puts d.first(1);\nb = d.first(l);\nc = d.last(l);\nb.each_index{|i| b[i] -= c[i]} \n\ncheck(b)\n"}, {"source_code": "l = gets.chomp.to_i\nn = gets.chomp\na = n.split('');\nd = []\n\na.each_index{|i| d[i] = a[i].to_i}\n#puts d.first(1);\nb = d.first(l);\nc = d.last(l);\nb.sort\nc.sort\n\nb.each_index{|i| b[i] -= c[i]} \n\nb.sort\nif b[0]*b[-1] <= 0 || b[0] == b[-1] then\n puts \"NO\"\nelse\n puts \"YES\"\nend\n"}, {"source_code": "l = gets.chomp.to_i\nn = gets.chomp\na = n.split('');\nd = []\n\na.each_index{|i| d[i] = a[i].to_i}\n#puts d.first(1);\nb = d.first(l);\nc = d.last(l);\nb.each_index{|i| b[i] -= c[i]}\nf = true\nif b[0] > 0 then\n f = true\nelse\n f = false\nend\n\nb.each { |el|\n if (f && el < 0 || !f && el < 0 || f == 0)\n puts \"NO\"\n return\n end\n}\n \n"}, {"source_code": "l = gets.chomp.to_i\nn = gets.chomp\na = n.split('');\nd = []\n\na.each_index{|i| d[i] = a[i].to_i}\n#puts d.first(1);\nb = d.first(l);\nc = d.last(l);\nb.sort\nc.sort\n\nb.each_index{|i| b[i] -= c[i]} \n\nb.sort\nif b[0]*b[-1] < 0 || b[0] == b[-1] then\n puts \"NO\"\nelse\n puts \"YES\"\nend\n"}, {"source_code": "l = gets.chomp.to_i\nn = gets.chomp\na = n.split('');\nd = []\n\na.each_index{|i| d[i] = a[i].to_i}\n#puts d.first(1);\nb = d.first(l);\nc = d.last(l);\nb.sort\nc.sort\n\nb.each_index{|i| b[i] -= c[i]} \n\nb.sort\nif b[0]*b[-1] < 0 then\n puts \"NO\"\nelse\n puts \"YES\"\nend\n"}, {"source_code": "def check(b)\n f = true\n if b[0] > 0 then\n f = true\n else\n f = false\n end\n b.each { |el|\n if (f && el < 0 || !f && el < 0 || f == 0)\n puts \"NO\"\n return\n end\n }\n\n puts \"YES\"\n \nend\n\n\nl = gets.chomp.to_i\nn = gets.chomp\na = n.split('');\nd = []\n\na.each_index{|i| d[i] = a[i].to_i}\n#puts d.first(1);\nb = d.first(l);\nc = d.last(l);\nb.each_index{|i| b[i] -= c[i]}\n\n\ncheck(b)\n"}, {"source_code": "def check(b)\n f = true\n if b[0] > 0 then\n f = true\n else\n f = false\n end\n b.each { |el|\n if (f && el < 0 || !f && el > 0 || el == 0)\n puts \"NO\"\n return\n end\n }\n\n puts \"YES\"\n \nend\n\n\nl = gets.chomp.to_i\nn = gets.chomp\na = n.split('');\nd = []\n\na.each_index{|i| d[i] = a[i].to_i}\n#puts d.first(1);\nb = d.first(l);\nc = d.last(l);\nb.sort\nc.sort\nb.each_index{|i| b[i] -= c[i]} \n\ncheck(b)\n"}, {"source_code": "def solve(a,b)\n a.length.times do |i|\n return false if a[i].to_i<=b[i].to_i\n end\n return true\nend\n\nn=gets.to_i\na=gets.split[0]\nx=a[0..n-1]\ny=a[n..2*n-1]\nif solve(x,y) || solve(y,x)\n puts \"YES\"\nelse\n puts \"NO\"\nend\n\n"}, {"source_code": "n = gets.to_i\ns = gets.chomp\n\nl = s[0...n].split(//).map(&:to_i)\nr = s[n...2*n].split(//).map(&:to_i)\n\nlh, rh = true, true\nfor i in 0...n do\n lh = lh && l[i] < r[i]\n rh = rh && l[i] > r[i]\nend\n\nputs(if lh || rh then \"YES\" else \"NO\" end)"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split(//).map!{|x| x.to_i}\nq = Array.new\nw = Array.new\nfor i in 0..n-1\n q[i] = a[i]\n w[i] = a[n+i]\nend\n\nq = q.sort\nw = w.sort\n\nif q[0] < w[0]\n t = 0\nelsif q[0] > w[0]\n t = 1\nelse\n t = 2\nend\n\nfor i in 1..n-1\n if q[i] < w[i] && t === 1\n t = 2\n break\n elsif q[i] > w[i] && t === 0\n t = 2\n break\n elsif t == 2\n break\n end\nend\n\nif t === 2\n puts \"NO\"\nelse\n puts \"YES\"\nend"}, {"source_code": "n = Integer(gets)\ninput = gets.chomp\nnum = Array.new\nfor i in 0...2*n\n num[i] = Integer(input[i])\nend\nleft = Array.new\nright = Array.new\nfor i in 0...n\n left.push(num[i])\n right.push(num[i + n])\nend\nleft = left.sort\nright = right.sort\n\ndef less(left,right)\n if left < right\n return true\n else\n return false\n end\nend\ndef more(left,right)\n if left > right\n return true\n else\n return false\n end\nend\nc = 0\nif n == 1\n if left[0] != right[0]\n c = 1\n end\nelse\n\n if left[0] > right[0]\n for i in 1...n\n if more(left[i],right[i])\n c = 1\n else\n c = 0\n end\n end\n elsif left[0] < right[0]\n for i in 1...n\n if less(left[i],right[i])\n c = 1\n else\n c = 0\n end\n end\n end\nend\nif c == 1\n puts \"YES\"\nelse \n puts \"NO\"\nend\n"}, {"source_code": "n = Integer(gets)\ninput = gets.chomp\nnum = Array.new\nfor i in 0...2*n\n\tnum[i] = Integer(input[i])\nend\nleft = Array.new\nright = Array.new\nfor i in 0...n\n\tleft.push(num[i])\n\tright.push(num[i + n])\nend\nleft = left.sort\nright = right.sort\ndef less(left,right)\n\tif left < right\n\t\treturn true\n\telse\n\t\treturn false\n\tend\nend\ndef more(left,right)\n\tif left > right\n\t\treturn true\n\telse\n\t\treturn false\n\tend\nend\nc = 0\nif left[0] > right[0]\n\tfor i in 1...n\n\t\tif more(left[i],right[i])\n\t\t\tc = 1\n\t\telse\n\t\t\tc = 0\n\t\tend\n\tend\nelsif left[0] < right[0]\n\tfor i in 1...n\n\t\tif less(left[i],right[i])\n\t\t\tc = 1\n\t\telse\n\t\t\tc = 0\n\t\tend\n\tend\nend\n\nif c == 1\n\tputs \"YES\"\nelse \n\tputs \"NO\"\nend\n"}, {"source_code": "# http://codeforces.ru/problemset/problem/160/B\n\ndef run(input = STDIN.read)\n lines = input.split(\"\\n\")\n\n n = lines[0].to_i\n ticket = lines[1].split(\"\").map(&:to_i)\n\n first = ticket.take(ticket.size / 2).sort\n second = ticket.drop(ticket.size / 2).sort\n \n if (0..n-1).all? { |i| first[i] < second[i] } or\n (0..n-1).all? { |i| first[i] > second[i] } then\n return 'YES'\n else\n return 'NO'\n end\nend\n\nbegin\n require './testing.rb'\nrescue LoadError\n run\nend\n__END__\n2\n2421\n=\nYES\n---\n2\n0135\n=\nYES\n---\n2\n3754\n=\nNO"}, {"source_code": "n = STDIN.gets.to_i\nticket = STDIN.gets.split(\"\").map(&:to_i)\n\nfirst = ticket.take(ticket.size / 2).sort\nsecond = ticket.drop(ticket.size / 2).sort\n\nif (0..n-1).all? { |i| first[i] <= second[i] } or\n (0..n-1).all? { |i| first[i] >= second[i] } then\n puts 'YES'\nelse\n puts 'NO'\nend"}, {"source_code": "n = STDIN.gets.to_i\nticket = STDIN.gets.split(\"\").map(&:to_i)\n\nfirst = ticket.take(ticket.size / 2).sort\nsecond = ticket.drop(ticket.size / 2).sort\n\nif ((0..n-1).all? { |i| first[i] < second[i] } or\n (0..n-1).all? { |i| first[i] > second[i] }) then\n puts 'YES'\nelse\n puts 'NO'\nend"}, {"source_code": "n = STDIN.gets.to_i\nticket = STDIN.gets.split(\"\").map(&:to_i)\n\nfirst = ticket.take(ticket.size / 2).sort\nsecond = ticket.drop(ticket.size / 2).sort\n\nif (0..n-1).all? { |i| first[i] < second[i] } or\n (0..n-1).all? { |i| first[i] > second[i] } then\n puts 'YES'\nelse\n puts 'NO'\nend"}, {"source_code": "n = gets.to_i\na = gets.split(\"\")\na.pop\n\nfor i in 0 ... a.size\n\ta[i] = a[i].to_i\nend\n\nb = a[0...a.size/2]\nc = a[a.size/2...a.size]\n\nb.sort!\nc.sort!\n\nans = true\nfor i in 1...a.size/2\n\tif b[0] < c[0] then\n\t\tif b[i] >= c[i] then\n\t\t\tans = false\n\t\t\tbreak\n\t\tend\n\telsif b[0] > c[0] then\n\t\tif b[i] <= c[i] then\n\t\t\tans = false\n\t\t\tbreak\n\t\tend\n\telse\n\t\tans = false\n\t\tbreak\n\tend\t\t\nend\n\nif ans then\n\tputs(\"YES\")\nelse\n\tputs(\"NO\")\nend"}, {"source_code": "input = STDIN.read.split(\"\\n\")\n\nn = input[0].to_i\nnums = input[1].split('').map(&:to_i)\n\nif nums.first > nums.last\n\tmore = true\nelsif nums.first < nums.last\n\tmore = false\nelse\n\tSTDOUT.puts \"NO\"\n\texit\nend\n\nn.times do |i|\n\n\tif more\n\t\tif nums[i] < nums[nums.length - i - 1]\n\t\t\tSTDOUT.puts \"NO\"\n\t\t\texit\n\t\tend\n\telse\n\t\tif nums[i] > nums[nums.length - i - 1]\n\t\t\tSTDOUT.puts \"NO\"\n\t\t\texit\n\t\tend\n\tend\n\n\nend\n\nSTDOUT.puts \"YES\""}, {"source_code": "input = STDIN.read.split(\"\\n\")\n\nn = input[0].to_i\nnums = input[1].split('').map(&:to_i)\n\nnum1 = nums[0..n-1].sort!\nnum2 = nums[n..-1].sort!\n\nif num1[0] > num2[0]\n\tmore = true\nelsif num1[0] < num2[0]\n\tmore = false\nelse\n\tSTDOUT.puts \"NO\"\n\texit\nend\n\nnum1.length.times do |i|\n\tif more\n\t\tif num1[i] < num2[i]\n\t\t\tSTDOUT.puts \"NO\"\n\t\t\texit\n\t\tend\n\telse\n\t\tif num1[i] > num2[i]\n\t\t\tSTDOUT.puts \"NO\"\n\t\t\texit\n\t\tend\n\tend\nend\n\nSTDOUT.puts \"YES\""}], "src_uid": "e4419bca9d605dbd63f7884377e28769"} {"nl": {"description": "Natasha is going to fly to Mars. She needs to build a rocket, which consists of several stages in some order. Each of the stages is defined by a lowercase Latin letter. This way, the rocket can be described by the string\u00a0\u2014 concatenation of letters, which correspond to the stages.There are $$$n$$$ stages available. The rocket must contain exactly $$$k$$$ of them. Stages in the rocket should be ordered by their weight. So, after the stage with some letter can go only stage with a letter, which is at least two positions after in the alphabet (skipping one letter in between, or even more). For example, after letter 'c' can't go letters 'a', 'b', 'c' and 'd', but can go letters 'e', 'f', ..., 'z'.For the rocket to fly as far as possible, its weight should be minimal. The weight of the rocket is equal to the sum of the weights of its stages. The weight of the stage is the number of its letter in the alphabet. For example, the stage 'a 'weighs one ton,' b 'weighs two tons, and' z'\u00a0\u2014 $$$26$$$ tons.Build the rocket with the minimal weight or determine, that it is impossible to build a rocket at all. Each stage can be used at most once.", "input_spec": "The first line of input contains two integers\u00a0\u2014 $$$n$$$ and $$$k$$$ ($$$1 \\le k \\le n \\le 50$$$)\u00a0\u2013 the number of available stages and the number of stages to use in the rocket. The second line contains string $$$s$$$, which consists of exactly $$$n$$$ lowercase Latin letters. Each letter defines a new stage, which can be used to build the rocket. Each stage can be used at most once.", "output_spec": "Print a single integer\u00a0\u2014 the minimal total weight of the rocket or -1, if it is impossible to build the rocket at all.", "sample_inputs": ["5 3\nxyabd", "7 4\nproblem", "2 2\nab", "12 1\nabaabbaaabbb"], "sample_outputs": ["29", "34", "-1", "1"], "notes": "NoteIn the first example, the following rockets satisfy the condition: \"adx\" (weight is $$$1+4+24=29$$$); \"ady\" (weight is $$$1+4+25=30$$$); \"bdx\" (weight is $$$2+4+24=30$$$); \"bdy\" (weight is $$$2+4+25=31$$$).Rocket \"adx\" has the minimal weight, so the answer is $$$29$$$.In the second example, target rocket is \"belo\". Its weight is $$$2+5+12+15=34$$$.In the third example, $$$n=k=2$$$, so the rocket must have both stages: 'a' and 'b'. This rocket doesn't satisfy the condition, because these letters are adjacent in the alphabet. Answer is -1."}, "positive_code": [{"source_code": "#!/usr/bin/ruby\nn,k=gets.split.map &:to_i\nr=0\nt=95\ngets.chomp.bytes.sort.each{|b|\n\tif b-t>1\n\t\tt=b\n\t\tr+=b-96\n\t\tk-=1\n\t\tbreak if k==0\n\tend\n}\np k>0 ? -1 : r\n"}, {"source_code": "a, b = gets.chomp.split.map &:to_i\ns = gets.chomp.chars.map{|x|x.ord-'a'.ord+1}.sort\nres = []\ni = 0\n\nwhile i < a && res.size != b\n if res.size < 1\n res << s[i]\n elsif (res[-1] - s[i]).abs > 1\n res << s[i] \n end\n i += 1\nend\n\np res.size < b ? -1 : res.reduce(:+)"}, {"source_code": "N, k = gets.split.map(&:to_i)\nS = gets.chomp.split('').map{|c| c.ord - 'a'.ord + 1}.sort\nsum = 0\nprev = -1\nN.times do |i|\n if prev + 2 <= S[i]\n prev = S[i]\n sum += S[i]\n k -= 1\n break if k == 0\n end\nend\nputs k == 0 ? sum : -1"}, {"source_code": "n, k = gets.strip.split.map(&:to_i)\nhsh = {}\n('a'..'z').each.with_index{|c, i| hsh[c]=i+1 }\nstr = gets.strip\nary = []\nstr.each_char{|c| ary << hsh[c]}\nary.sort!\n\ni = 0\nans=[ary[i]]\n2.upto(k).each do\n (i+1).upto(n-1).each do |j|\n if ary[j]-ary[i] > 1\n ans << ary[j]\n i = j\n break\n end\n end\nend\n\nif ans.size == k\n puts ans.inject(:+)\nelse\n puts -1\nend\n"}, {"source_code": "nk = gets.chomp.split(\" \").map(&:to_i)\nn = nk[0]\nk = nk[1]\n\nstring = gets.chomp\n\narr = string.each_char.to_a.uniq.sort\n\nif k > 26\n puts -1\n exit\nend\n\nweight = 0\ni = 0\nprevch = 'A'\n\ndef addto(char,no)\n return (char.ord+no).chr\nend\n\n\nlen = arr.length\nwhile k>0\n if i>=len\n puts -1\n exit\n end\n\n ch = arr[i]\n if ch<=addto(prevch,1)\n i+=1\n next\n end\n\n #p ch\n weight += ch.ord-'a'.ord+1\n k-=1\n i+=1\n prevch = ch\nend\n\nputs weight"}], "negative_code": [{"source_code": "a, b = gets.split.map &:to_i\ns = gets.chars.map{|x|x.ord-'a'.ord+1}.sort\nres = []\ni = 0\n\nwhile i < a && res.size != b\n if res.size < 1\n res << s[i]\n elsif (res[-1] - s[i])**2 > 1\n res << s[i] \n end\n i += 1\nend\n\nif res.size == b\n puts res.reduce:+\nelse\n puts -1\n end"}, {"source_code": "a, b = gets.split.map &:to_i\ns = gets.chars.map{|x|x.ord-'a'.ord+1}.sort\nres = []\nprint s\ni = 0\n\nwhile i < a && res.size != b\n if res.size < 1\n res << s[i]\n elsif (res[-1] - s[i]).abs > 1\n res << s[i] \n end\n i += 1\nend\n\np res.size < b ? -1 : res.reduce(:+)"}, {"source_code": "a, b = gets.split.map &:to_i\ns = gets.chars.map{|x|x.ord-'a'.ord+1}.sort\nres = []\ni = 0\n\nwhile i < a && res.size != b\n if res.size < 1\n res << s[i]\n elsif (res[-1] - s[i])**2 > 1\n res << s[i] \n end\n i += 1\nend\n\nif res.size == b\n puts res.reduce:+\nelse\n puts -1\nend"}, {"source_code": "a, b = gets.split.map &:to_i\ns = gets.chars.map{|x|x.ord-'a'.ord+1}.sort\nres = []\ni = 0\n\nwhile i < a && res.size != b\n if res.size < 1\n res << s[i]\n elsif (res[-1] - s[i]).abs > 1\n res << s[i] \n end\n i += 1\nend\n\np res.size < b ? -1 : res.reduce(:+)"}], "src_uid": "56b13d313afef9dc6c6ba2758b5ea313"} {"nl": {"description": "You are given an infinite checkered field. You should get from a square (x1; y1) to a square (x2; y2). Using the shortest path is not necessary. You can move on the field squares in four directions. That is, when you are positioned in any square, you can move to any other side-neighboring one. A square (x; y) is considered bad, if at least one of the two conditions is fulfilled: |x\u2009+\u2009y|\u2009\u2261\u20090 (mod\u00a02a), |x\u2009-\u2009y|\u2009\u2261\u20090 (mod\u00a02b). Your task is to find the minimum number of bad cells one will have to visit on the way from (x1; y1) to (x2; y2).", "input_spec": "The only line contains integers a, b, x1, y1, x2 and y2 \u2014 the parameters of the bad squares, the coordinates of the initial and the final squares correspondingly (2\u2009\u2264\u2009a,\u2009b\u2009\u2264\u2009109 and |x1|,|y1|,|x2|,|y2|\u2009\u2264\u2009109). It is guaranteed that the initial and the final square aren't bad.", "output_spec": "Print a single number \u2014 the minimum number of bad cells that one will have to visit in order to travel from square (x1; y1) to square (x2; y2).", "sample_inputs": ["2 2 1 0 0 1", "2 2 10 11 0 1", "2 4 3 -1 3 7"], "sample_outputs": ["1", "5", "2"], "notes": "NoteIn the third sample one of the possible paths in (3;-1)->(3;0)->(3;1)->(3;2)->(4;2)->(4;3)->(4;4)->(4;5)->(4;6)->(4;7)->(3;7). Squares (3;1) and (4;4) are bad."}, "positive_code": [{"source_code": "def f(n, a, b)\n if a > b\n f(n, b, a)\n else\n Rational(b, n).floor + 1 - Rational(a, n).ceil\n end\nend\n\nx, y, a, b, c, d = gets.split.map(&:to_i)\np [f(2 * x, a + b, c + d), f(2 * y, a - b, c - d)].max\n"}, {"source_code": "def f(n, a, b)\n if a > b\n f(n, b, a)\n else\n (b / n).floor + 1 - (a / n).ceil\n end\nend\n\nx, y, a, b, c, d = gets.split.map(&:to_r)\np [f(2 * x, a + b, c + d), f(2 * y, a - b, c - d)].max\n"}, {"source_code": "def f(n, a, b)\n if a > b\n f(n, b, a)\n else\n (b / n).floor + 1 - (a / n).ceil\n end\nend\n\nx, y, a, b, c, d = gets.split.map(&:to_r)\np [f(2 * x, a + b, c + d), f(2 * y, a - b, c - d)].max\n"}], "negative_code": [], "src_uid": "7219d1837c83b5920992aee5a60dc0d9"} {"nl": {"description": "You are given a rectangular board of M\u2009\u00d7\u2009N squares. Also you are given an unlimited number of standard domino pieces of 2\u2009\u00d7\u20091 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:1. Each domino completely covers two squares.2. No two dominoes overlap.3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board.Find the maximum number of dominoes, which can be placed under these restrictions.", "input_spec": "In a single line you are given two integers M and N \u2014 board sizes in squares (1\u2009\u2264\u2009M\u2009\u2264\u2009N\u2009\u2264\u200916).", "output_spec": "Output one number \u2014 the maximal number of dominoes, which can be placed.", "sample_inputs": ["2 4", "3 3"], "sample_outputs": ["4", "4"], "notes": null}, "positive_code": [{"source_code": "require 'scanf'\nSTDIN.read.split(\"\\n\").each do |line|\n m, n = line.scanf(\"%d%d\")\n puts m * n / 2\nend\n"}, {"source_code": "p eval(gets.tr\" \",?*)/2"}, {"source_code": "p eval(gets.tr\" \",?*)/2\n"}, {"source_code": "require 'scanf'\nSTDIN.read.split(\"\\n\").each do |line|\n m, n = line.scanf(\"%d%d\")\n puts m * n / 2\nend\n"}, {"source_code": "p eval(gets.tr\" \",?*)/2"}, {"source_code": "a,b=gets.split.map{|e| e.to_i}\nputs (a*b)/2"}, {"source_code": "a = STDIN.gets.split(\" \")\n\nputs \"#{a[0].to_i * a[1].to_i / 2}\"\n"}, {"source_code": "dim = gets.chomp().split(\" \").map(&:to_i)\ntiles = dim[0] * dim[1]\n\nputs (tiles - (tiles % 2)) / 2"}, {"source_code": "a=gets.chomp.split(\" \")\nc=a[0].to_i*a[1].to_i\nb=(c/2)\nputs\"#{b}\"\n"}, {"source_code": "a=gets.chomp.split(\" \")\nc=a[0].to_i*a[1].to_i\nb=(c/2)\nputs\"#{b}\""}, {"source_code": "a = gets.chomp.split(\" \")\na[0] = a[0].to_i\na[1] = a[1].to_i\nif a[0] % 2 == 0\n\tcount = (a[0]/2) * a[1]\nelsif a[1] % 2 == 0\n\tcount = (a[1]/2) * a[0]\nelse\n\tcount = ((a[0]-1)/2) * a[1] + a[1]/2\nend\n\nputs count"}, {"source_code": "n, m = gets.split.map(&:to_i)\nputs (n*m*0.5).floor\n"}, {"source_code": "p eval(gets.tr\" \",?*)/2\n"}, {"source_code": "(n, m) = gets.split(/\\s/).map &:to_i\nputs n * m / 2\n"}, {"source_code": "n, m = gets.chomp.split(' ').map(&:to_i)\nputs n * m / 2\n"}, {"source_code": "p eval(gets.tr\" \",?*)/2"}, {"source_code": "class Solver1\n def self.solve(n, m)\n if n.even? && m.even?\n return self.even_pair(n, m)\n else\n n1, n2 = 0\n n1 = n.even? ? n : n - 1\n n2 = m.even? ? m : m - 1\n even_area = n1 * n2\n even_solved = even_pair(n1, n2)\n total_area = n * m\n return even_solved + ((total_area - even_area) / 2).floor\n end\n end\n\n def self.even_pair(n, m)\n (n * m) / 2\n end\nend\nn, m = STDIN.gets.split(\" \")\nputs Solver1.solve(n.to_i, m.to_i)\n"}, {"source_code": "s = gets.split(\" \")\nn = s[0].to_i\nm = s[1].to_i\nrez1 = 0\nrez2 = 0\nif n % 2 == 1\nrez1 += m / 2;\n end\nrez1 += (n / 2) * m\nif m % 2 == 1\nrez2 += n / 2; \nend\nrez2 += (m / 2) * n\nrez = [rez1, rez2].max\nputs(rez)"}, {"source_code": "m, n = gets.split.map(&:to_i)\n\nputs m * n / 2\n"}, {"source_code": "\nm, n = gets().split(' ').map {|p| p.to_i}\n\nif m.even?\n puts (m/2)*n\nelsif n.even?\n puts (n/2)*m\nelse\n puts (m*n-1)/2\nend\n"}, {"source_code": "p eval(gets.tr\" \",?*)/2"}, {"source_code": "in_m, in_n = STDIN.gets.split(\" \")\nm = Integer(in_m)\nn = Integer(in_n)\nvolume = m*n\np volume/2"}, {"source_code": "m, n = gets.strip.split(\" \").map(&:to_i)\nif m == 1 && n == 1 then\n puts 0\nelse\n count = 0\n i = 0\n while (i < n) do \n if n - i >= 2 then\n m.times {count += 1}\n i += 2\n else\n (m / 2).times {count += 1}\n i += 1\n end\n end\nend\nputs count"}, {"source_code": "n, m = gets.split.map(&:to_i)\nputs (n*m*0.5).floor\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\nputs (n*m*0.5).floor\n"}, {"source_code": "m,n = gets.split.map {|x| x.to_i}\nputs (m*n)/2"}, {"source_code": "gets.split.map(&:to_i).tap {|a| c = a[0] * a[1]; c-=1 unless (c % 2).zero?; print c/2}"}, {"source_code": "m,n = gets.split.map &:to_i\nif m.even? || n.even?\n puts m*n/2\nelse\n puts (m*n - 1)/2\nend"}, {"source_code": "m , n = gets.split.map(&:to_i)\n\nputs (m * n) / 2"}, {"source_code": "n, m = gets.split.map(&:to_i)\nputs (n*m*0.5).floor\n"}, {"source_code": "a, b = gets.strip.split(\" \").map(&:to_i)\nputs (((a*b)/2).to_i)"}, {"source_code": "require 'scanf'\ninput_data = $stdin.readline\n\nm, n = input_data.scanf('%d%d')\n\n#if m == 1 && n == 1\n# res = 0\n#else\n res = (m*n)/2\n#end \n\nputs res\n"}, {"source_code": "p eval(gets.tr\" \",?*)/2\n"}, {"source_code": "arr = gets.split(\" \")\nm = arr[0].to_i\nn = arr[1].to_i\n\nresult = m * (n / 2)\nif n > 2 and n % 2 == 1\n result = result + (m / 2)\nend\n\nprint result\n"}, {"source_code": "p eval(gets.tr\" \",?*)/2\n"}, {"source_code": "n, m = gets.split.map &:to_i; puts n * m / 2"}, {"source_code": "s = gets.split(\" \")\nn = s[0].to_i\nm = s[1].to_i\nrez1 = 0\nrez2 = 0\nif n % 2 == 1\nrez1 += m / 2;\n end\nrez1 += (n / 2) * m\nif m % 2 == 1\nrez2 += n / 2; \nend\nrez2 += (m / 2) * n\nrez = [rez1, rez2].max\nputs(rez)"}, {"source_code": "require 'scanf'\nSTDIN.read.split(\"\\n\").each do |line|\n m, n = line.scanf(\"%d%d\")\n puts m * n / 2\nend\n"}, {"source_code": "a,b=$stdin.read.split.map(&:to_i)\nprint a*b/2"}, {"source_code": "p eval(gets.tr\" \",?*)/2"}, {"source_code": "n,m=gets.split().map{|s|s.to_i}\nputs n*m/2"}, {"source_code": "m, n = gets.strip.split(\" \").map(&:to_i)\nif m == 1 && n == 1 then\n puts 0\nelse\n count = 0\n i = 0\n while (i < n) do \n if n - i >= 2 then\n m.times {count += 1}\n i += 2\n else\n (m / 2).times {count += 1}\n i += 1\n end\n end\nend\nputs count"}, {"source_code": "buf = gets.split(' ').map(&:to_i)\na, b = buf[0], buf[1]\nputs a * b / 2\n"}, {"source_code": "(n, m) = gets.split(/\\s/).map &:to_i\nputs n * m / 2\n"}, {"source_code": "in_m, in_n = STDIN.gets.split(\" \")\nm = Integer(in_m)\nn = Integer(in_n)\nvolume = m*n\np volume/2"}, {"source_code": "\n\ndef solve(m, n)\n\n num_dominoes = 0\n p = m / 2\n\n num_dominoes = p * n\n\n q = m % 2\n\n num_dominoes += n / 2 if q == 1\n\n num_dominoes\n \n \n\nend\n\n\n\n\nm, n = gets.chomp.split.map(&:to_i)\n\nputs solve(m, n)\n"}, {"source_code": "input = gets.split().map { |item| item.to_i }\nif input[0] % 2 == 0\n\tputs input[0] / 2 * input[-1]\nelse puts input[0] / 2 * input[-1] + input[-1] / 2\nend"}, {"source_code": "a = STDIN.gets.split(\" \")\n\nputs \"#{a[0].to_i * a[1].to_i / 2}\"\n"}, {"source_code": "dim = gets.chomp().split(\" \").map(&:to_i)\ntiles = dim[0] * dim[1]\n\nputs (tiles - (tiles % 2)) / 2"}, {"source_code": "def solve a,b\n\tif a==1\n\t\tb/2\n\telsif a==2\n\t\tb\n\telse\n\t\tsolve(a-1, b-1)+a/2+b/2\n\tend\nend\n\na,b=gets.split.map(&:to_i)\np solve(a,b)\n"}, {"source_code": "input_N = gets.chomp.split()\nprint (input_N.at(0).to_i * input_N.at(1).to_i)/2\nprint \"\\n\"\n"}, {"source_code": "m, n = gets.split(' ').map(&:to_i)\nprint m*n/2"}, {"source_code": "buf = gets.split(' ').map(&:to_i)\na, b = buf[0], buf[1]\nputs a * b / 2\n"}, {"source_code": "n, m = gets.split(' ').map(&:to_i)\n\nputs n*(m/2) + (m%2)*(n/2)\n"}, {"source_code": "n,m = gets.split.map{|r| r.to_i}\nmax = m*n\nputs max/2"}, {"source_code": "m,n = gets.split.map {|x| x.to_i}\nputs (m*n)/2"}, {"source_code": "a,b=gets.chomp.split(' ')\na=a.to_i\nb=b.to_i\nputs a*b/2"}, {"source_code": "in_m, in_n = STDIN.gets.split(\" \")\nm = Integer(in_m)\nn = Integer(in_n)\nvolume = m*n\np volume/2"}, {"source_code": "p eval(gets.tr\" \",?*)/2"}, {"source_code": "input = gets.chomp.split(\" \").map { |x| x.to_i}\nM = input[0]\nN = input[1]\n\nplaces = (0..M*N-1).to_a\nedges = {}\ntiles = 0\nfor i in places\n temp = []\n if i-1>=0\n temp.push i-1\n end\n if i+1=0\n temp.push i-N\n end\n if i+N 0\n place = places.pop\n options = edges[place]\n good = false\n for option in options\n if places.include?(option)\n places.delete option\n good = true\n break\n end\n end\n if good\n tiles += 1\n else\n break\n end\nend\nputs tiles\n\n"}, {"source_code": "m, n = STDIN.read.split.map &:to_i\n\nif n.odd?\n c = m * (n - 1) / 2\n c += (m / 2.0).floor\nelse\n c = m * n / 2\nend\n\nprint c"}, {"source_code": "p eval(gets.tr\" \",?*)/2"}, {"source_code": "t = $stdin.readline.split\nm = t[1].to_i\nn = t[0].to_i\n\nk = 0\nimax = (n%2==0) ? n : n-1\njmax = (m%2==0) ? m : m-1\ntmax = n*m/2 - imax*jmax/2\n\nputs imax*jmax/2 + tmax\n"}, {"source_code": "s = gets.split(\" \")\nn = s[0].to_i\nm = s[1].to_i\nrez1 = 0\nrez2 = 0\nif n % 2 == 1\nrez1 += m / 2;\n end\nrez1 += (n / 2) * m\nif m % 2 == 1\nrez2 += n / 2; \nend\nrez2 += (m / 2) * n\nrez = [rez1, rez2].max\nputs(rez)"}, {"source_code": "p eval(gets.tr\" \",?*)/2"}, {"source_code": "m, n = gets.chomp.split(' ').map{|a| a.to_i}\nputs (m*n/2).floor"}, {"source_code": "a, b = gets.strip.split(\" \").map(&:to_i)\nputs (((a*b)/2).to_i)"}, {"source_code": "a,b=gets.split.map(&:to_i)\nputs ((a*b)%2==0)?(a*b)>>1:(a*b-1)>>1"}, {"source_code": "m,n = gets.split.map(&:to_i)\n\n### 1\nsum_a = m / 2 * n\nif m % 2 != 0\n\tsum_a = sum_a + (n / 2) \nend\n\n### 2\nsum_b = n / 2 * m\nif n % 2 != 0\n\tsum_b = sum_b + (m / 2)\nend\n\nif sum_a > sum_b\n\tputs \"#{sum_a}\"\nelse\n\tputs \"#{sum_b}\"\nend"}, {"source_code": "a=gets.chomp.split(\" \")\nc=a[0].to_i*a[1].to_i\nb=(c/2)\nputs\"#{b}\""}, {"source_code": "input = gets.chomp.split(\" \")\n\nn = input[0].to_i\nm = input[1].to_i\n\nmult = n * m\n\nputs mult / 2"}, {"source_code": "n,m=gets.split().map{|s|s.to_i}\nputs n*m/2"}, {"source_code": "(n, m) = gets.split(/\\s/).map &:to_i\nputs n * m / 2\n"}, {"source_code": "p eval(gets.tr\" \",?*)/2\n"}, {"source_code": "m, n = STDIN.gets.split.map(&:to_i)\nputs m*n/2"}, {"source_code": "p eval(gets.tr\" \",?*)/2"}, {"source_code": "#puts \"Enter the dimensions of rectangle\\n\"\nm,n = gets.split.map(&:to_i)\nif m == n \n a = (m*n)/2\n puts a\nelse\n b = (m*n)/2\n r = n/2\n s = r*m\n d = m/2\n v = d*n\n if s>=v\n if s >= b\n puts s\n else\n puts b\n end\n else\n if v >= b\n puts v\n else\n puts b\n end\n end\nend\n\n"}, {"source_code": "#!/usr/bin/ruby\ninput = gets.chomp\narr =input.split(' ')\nn = arr[0]\nm = arr[1]\nout = (n.to_i * m.to_i)/2\nputs \"#{out}\""}, {"source_code": "a,b = gets.split.map(&:to_i)\nputs a * b / 2\n"}, {"source_code": "m, n = gets.split.map(&:to_i)\nc = (m*n)/2\n\nputs c"}, {"source_code": "m, n = gets.chomp.split.map{ |x| x.to_i }\nputs m*n/2"}, {"source_code": "a = gets.chomp.split(\" \")\na[0] = a[0].to_i\na[1] = a[1].to_i\nif a[0] % 2 == 0\n\tcount = (a[0]/2) * a[1]\nelsif a[1] % 2 == 0\n\tcount = (a[1]/2) * a[0]\nelse\n\tcount = ((a[0]-1)/2) * a[1] + a[1]/2\nend\n\nputs count"}, {"source_code": "a,b = gets.split.map(&:to_i)\nputs a * b / 2\n"}, {"source_code": "n,m = gets.split.map{|r| r.to_i}\nmax = m*n\nputs max/2"}, {"source_code": "gets.split.map(&:to_i).tap {|a| c = a[0] * a[1]; c-=1 unless (c % 2).zero?; print c/2}"}, {"source_code": "p eval(gets.tr\" \",?*)/2\n"}, {"source_code": "p eval(gets.tr\" \",?*)/2\n"}, {"source_code": "a,b=gets.split.map(&:to_i)\nputs ((a*b)%2==0)?(a*b)>>1:(a*b-1)>>1"}, {"source_code": "m, n = gets.split.map(&:to_i)\n\nputs m * n / 2\n"}, {"source_code": "dim = gets.chomp().split(\" \").map(&:to_i)\ntiles = dim[0] * dim[1]\n\nputs (tiles - (tiles % 2)) / 2"}, {"source_code": "n, m = gets.split(\" \").map(&:to_i)\nputs (m/2) * n + (m % 2) * (n / 2);"}, {"source_code": "buf = gets.split(' ').map(&:to_i)\na, b = buf[0], buf[1]\nputs a * b / 2\n"}, {"source_code": "dim = gets.chomp().split(\" \").map(&:to_i)\ntiles = dim[0] * dim[1]\n\nputs (tiles - (tiles % 2)) / 2"}, {"source_code": "input = gets.chomp.split(' ')\nx = input.first.to_i * input.last.to_i\nif x%2==1\n\tx -= 1\nend\nputs x/2\n"}, {"source_code": "m,n = gets.split.map &:to_i\nif m.even? || n.even?\n puts m*n/2\nelse\n puts (m*n - 1)/2\nend"}, {"source_code": "input = gets.chomp.split(' ')\nx = input.first.to_i * input.last.to_i\nif x%2==1\n\tx -= 1\nend\nputs x/2\n"}, {"source_code": "(n, m) = gets.split(/\\s/).map &:to_i\nputs n * m / 2\n"}, {"source_code": "m, n = gets.split.map(&:to_i)\n\nputs m*n/2"}, {"source_code": "p eval(gets.tr\" \",?*)/2"}, {"source_code": "p eval(gets.tr\" \",?*)/2\n"}], "negative_code": [{"source_code": "aa = STDIN.getc.to_i\nbb = STDIN.getc.to_i\nputs aa * bb / 2"}, {"source_code": "aa = STDIN.getc.to_i\nbb = STDIN.getc.to_i\ncc = STDIN.getc.to_i\nputs aa * cc / 2"}, {"source_code": "ARGV\nputs \"#{ARGV[0].to_i * ARGV[1].to_i / 2}\""}, {"source_code": "a = gets.to_i\nb = gets.to_i\nputs a * b / 2"}, {"source_code": " input = gets.split.map(&:to_i)\n input.sort!\n input[1]-=1 if input[1] % 2 != 0\n print input[0]*input[1]/2"}, {"source_code": "gets.split.map(&:to_i).tap {|a| c = a[0] * a[1]; c-=1 unless (c % 2).zero?; print c}"}, {"source_code": "input = gets.split.map(&:to_i)\ninput.sort!\ninput[1]-=1 if input[1] % 2 != 0\nprint input[0]*input[1]"}, {"source_code": "m = gets\nn = gets\nout = (n.to_i * m.to_i)/2\nputs \"#{out}\""}, {"source_code": "m, n = gets.strip.split(\" \").map(&:to_i)\nif m == 1 && n == 1 then\n puts 0\nelse\n count = 0\n i = 0\n while (i < n) do \n if n - i - 1 >= 2 then\n m.times {count += 1}\n i += 2\n else\n (m / 2).times {count += 1}\n i += 1\n end\n end\nend\nputs count"}, {"source_code": "# ... LETS HACK THE WORLD ...\n#... KEEP CALM AND SAY LE ROI EST MORT IS HERE ...\n# ... EL-BADRY BECOME A LEGEND ...\n\nx = gets.to_i\nz = gets.to_i\na = x * z / 2\nputs a"}, {"source_code": "# ... LETS HACK THE WORLD ...\n#... KEEP CALM AND SAY LE ROI EST MORT IS HERE ...\n# ... EL-BADRY BECOME A LEGEND ...\nx = gets.to_i\nz = gets.to_i\nputs((x*z)/2)"}, {"source_code": "def solve a,b\n\tif a==1\n\t\tb/2\n\telsif a==2\n\t\tb\n\telse\n\t\tif a%2==0\n\t\t\t2*solve(a/2, b)\n\t\telse\n\t\t\tsolve(a-1, b) + solve(1, b)\n\t\tend\n\tend\nend\n\na,b=gets.split.map(&:to_i)\np solve(a,b)\n"}, {"source_code": "number = gets.chomp.to_i\nputs number/2\n"}, {"source_code": "input = gets.chomp.split(\" \").map { |x| x.to_i}\nM = input[0]\nN = input[1]\n\nplaces = (0..M*N-1).to_a\nedges = {}\ntiles = 0\nfor i in places\n temp = []\n if i-1>=0\n temp.push i-1\n end\n if i+1=0\n temp.push i-N\n end\n if i+N 0\n place = places.pop\n options = edges[place]\n good = false\n for option in options\n if places.include?(option)\n places.delete option\n good = true\n break\n end\n end\n if good\n tiles += 1\n else\n break\n end\nend\nputs edges\nputs places\nputs tiles\n\n"}, {"source_code": "eval(gets.tr\" \",?*)/2"}, {"source_code": "puts \"Enter the dimensions of rectangle\\n\"\nm,n = gets.split.map(&:to_i)\nif m == n \n a = (m*n)/2\n puts a\nelse\n b = (m*n)/2\n r = n/2\n s = r*m\n d = m/2\n v = d*n\n if s>=v\n if s >= b\n puts s\n else\n puts b\n end\n else\n if v >= b\n puts v\n else\n puts b\n end\n end\nend\n\n"}, {"source_code": "#puts \"Enter the dimensions of rectangle\\n\"\nm,n = gets.split.map(&:to_i)\nif m == n \n a = (m*n)/2\n puts a\nelse\n r = n/2;\n s = r*m;\n puts s\nend\n"}, {"source_code": "#puts \"Enter the dimensions of rectangle\\n\"\nm,n = gets.split.map(&:to_i)\nif m == n \n a = (m*n)/2\n puts a\nelse\n r = n/2\n s = r*m\n d = m/2\n v = d*n\n if s>=v\n puts s\n else\n puts v\n end\nend\n\n"}, {"source_code": "puts \"Enter the dimensions of rectangle\\n\"\nm,n = gets.split.map(&:to_i)\nif m = n\n a = (m*n)/2\n puts a\nelse\n r = n/2;\n s = r*m;\n puts s\nend\n"}, {"source_code": "\nn, m = gets.chomp.split(\" \").map(&:to_i)\n\nputs ((n * m) / 2) * 2"}, {"source_code": "m, n = STDIN.read.split.map &:to_i\n\nif n.odd?\n c = (m * (n - 1)) / 2\n c += (m - 1) / 2\nelse\n c = m * n / 2\nend\n\nprint c"}, {"source_code": "m, n = STDIN.read.split.map &:to_i\n\nif n.odd?\n c = (m * (n - 1)) / 2\n c += (n - 1) / 2\nelse\n c = m * n / 2\nend\n\nprint c\n"}, {"source_code": "arr = gets.split(\" \")\nm = arr[0].to_i\nn = arr[1].to_i\n\nresult = m * (n / 2)\nif m > 2 and m % 2 == 1\n result = result + (n / 2)\nend\n\nprint result\n"}, {"source_code": "arr = gets.split(\" \")\nm = arr[0].to_i\nn = arr[1].to_i\n\nresult = m * (n / 2)\nif m % 2 == 1\n result = result + (n / 2)\nend\n\nprint result\n"}], "src_uid": "e840e7bfe83764bee6186fcf92a1b5cd"} {"nl": {"description": "Mancala is a game famous in the Middle East. It is played on a board that consists of 14 holes. Initially, each hole has $$$a_i$$$ stones. When a player makes a move, he chooses a hole which contains a positive number of stones. He takes all the stones inside it and then redistributes these stones one by one in the next holes in a counter-clockwise direction.Note that the counter-clockwise order means if the player takes the stones from hole $$$i$$$, he will put one stone in the $$$(i+1)$$$-th hole, then in the $$$(i+2)$$$-th, etc. If he puts a stone in the $$$14$$$-th hole, the next one will be put in the first hole.After the move, the player collects all the stones from holes that contain even number of stones. The number of stones collected by player is the score, according to Resli.Resli is a famous Mancala player. He wants to know the maximum score he can obtain after one move.", "input_spec": "The only line contains 14 integers $$$a_1, a_2, \\ldots, a_{14}$$$ ($$$0 \\leq a_i \\leq 10^9$$$)\u00a0\u2014 the number of stones in each hole. It is guaranteed that for any $$$i$$$ ($$$1\\leq i \\leq 14$$$) $$$a_i$$$ is either zero or odd, and there is at least one stone in the board.", "output_spec": "Output one integer, the maximum possible score after one move.", "sample_inputs": ["0 1 1 0 0 0 0 0 0 7 0 0 0 0", "5 1 1 1 1 0 0 0 0 0 0 0 0 0"], "sample_outputs": ["4", "8"], "notes": "NoteIn the first test case the board after the move from the hole with $$$7$$$ stones will look like 1 2 2 0 0 0 0 0 0 0 1 1 1 1. Then the player collects the even numbers and ends up with a score equal to $$$4$$$."}, "positive_code": [{"source_code": "a=gets.split.collect{|s|s.to_i}\n m=0\nfor i in 0..13\n b=a.collect{|s|s}\n k=b[i]\n b[i]=0\n kd=k/14\n km=k%14\n res=0\n for j in 1..14\n b[(i+j)%14]+=((j<=km) ? kd+1:kd)\n end\n for j in 0..13\n if(b[j]%2==0)\n res+=b[j]\n end\n end\n if res>m\n m=res\n end\nend\nputs m"}, {"source_code": "def solve(idx, b)\n a = Array.new(b)\n if a[idx] == 0\n return -1\n end\n num = a[idx] / 14\n (a[idx] % 14).times do |i|\n a[(idx + i + 1) % 14] += 1\n end\n a[idx] = 0\n res = 0\n 14.times do |i|\n a[i] += num\n if a[i] % 2 == 0\n res += a[i]\n end\n end\n return res\nend\n \na = gets.split.map(&:to_i)\nans = 0\n14.times do |i|\n ans = [ans, solve(i, a)].max\nend\nputs ans"}], "negative_code": [], "src_uid": "1ac11153e35509e755ea15f1d57d156b"} {"nl": {"description": "Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the corresponding lowercase letter. Help Petya perform the comparison.", "input_spec": "Each of the first two lines contains a bought string. The strings' lengths range from 1 to 100 inclusive. It is guaranteed that the strings are of the same length and also consist of uppercase and lowercase Latin letters.", "output_spec": "If the first string is less than the second one, print \"-1\". If the second string is less than the first one, print \"1\". If the strings are equal, print \"0\". Note that the letters' case is not taken into consideration when the strings are compared.", "sample_inputs": ["aaaa\naaaA", "abs\nAbz", "abcdefg\nAbCdEfF"], "sample_outputs": ["0", "-1", "1"], "notes": "NoteIf you want more formal information about the lexicographical order (also known as the \"dictionary order\" or \"alphabetical order\"), you can visit the following site: http://en.wikipedia.org/wiki/Lexicographical_order"}, "positive_code": [{"source_code": "first = gets.chomp\nsecond = gets.chomp\nfirst_letters = first.split(\"\")\nsecond_letters = second.split(\"\")\nx = 1\nalphabet = ('a'..'z').to_a\n\ni = 0\ncounter = 0\nwhile counter == 0 && i < first.length.to_i\n\tif first_letters[i].downcase == second_letters[i].downcase\n\t\tcounter = 0\n\telsif first_letters[i].downcase < second_letters[i].downcase\n\t\tcounter -= 1\n\telsif first_letters[i].downcase > second_letters[i].downcase\n\t\tcounter += 1\n\tend\n\ti += 1\nend\n\nputs counter"}, {"source_code": "p gets.casecmp gets"}, {"source_code": "a, b = gets.downcase, gets.downcase\nputs a == b ? 0 : (a < b ? -1 : 1)\n"}, {"source_code": "string1 = gets\nstring2 = gets\n\nif string1.downcase() == string2.downcase()\n puts \"0\"\nelsif string1.downcase() > string2.downcase()\n puts \"1\"\nelse\n puts \"-1\"\nend\n"}, {"source_code": "l1 = gets.chomp.downcase\nl2 = gets.chomp.downcase\n\nputs l1 <=> l2\n"}, {"source_code": "puts gets.to_s.downcase <=> gets.to_s.downcase"}, {"source_code": "word1 = gets.chomp.downcase\nword2 = gets.chomp.downcase\n\nif word1 < word2 then \n print '-1'\nelsif word1 > word2 then\n print '1'\nelse\n print '0'\nend\n"}, {"source_code": "l1 = gets.chomp.downcase\nl2 = gets.chomp.downcase\n\nputs l1 <=> l2\n"}, {"source_code": "s1 = gets.chomp\ns2 = gets.chomp\nif s1.capitalize==s2.capitalize\n puts \"0\"\nelsif s2.capitalize < s1.capitalize\n puts \"1\"\nelsif s2.capitalize > s1.capitalize\n puts \"-1\"\nend"}, {"source_code": "def compare s,a\n\ts=s.downcase\n\ta=a.downcase\n\treturn s<=>a\nend\n\ns=gets\na=gets\np compare(s,a)\n"}, {"source_code": "a,b=[gets, gets].map(&:downcase)\np a<=>b"}, {"source_code": "s = gets.chomp.to_s\nt = gets.chomp.to_s\n\ns.downcase!\nt.downcase!\n\nif s>t \n puts 1\nelsif s==t\n puts 0\nelse\n puts -1\nend"}, {"source_code": "p gets.downcase <=> gets.downcase"}, {"source_code": "s = gets.chomp.upcase\nt = gets.chomp.upcase\np -1 if s < t\np 0 if s == t\np 1 if s > t"}, {"source_code": "string1 = gets.chomp.downcase\nstring2 = gets.chomp.downcase\n\nif string1 < string2\n puts \"-1\"\nelsif string1 > string2\n puts \"1\"\nelse\n puts \"0\"\nend"}, {"source_code": "s1, s2 = gets.downcase, gets.downcase\nif s1 > s2\n\tputs 1\nelsif s1 < s2\n\tputs -1\nelsif s1 == s2\n\tputs 0\nend\n"}, {"source_code": "a,b=[gets, gets].map(&:downcase)\np a<=>b"}, {"source_code": "firstSen = gets.chomp.downcase\nsecondSen = gets.chomp.downcase\n\nputs firstSen <=> secondSen"}, {"source_code": "a = gets.chomp\nb = gets.chomp\n\na.downcase!\nb.downcase!\nif a == b\n\tputs 0\nelsif a > b\n\tputs 1\nelse a < b\n\tputs -1\nend\n\t\t"}, {"source_code": "m = gets.chomp\nn = gets.chomp\nputs m.downcase >= n.downcase ? m.downcase == n.downcase ? 0 : 1 : -1\n"}, {"source_code": "a = gets \nb = gets \nputs a.downcase <=> b.downcase "}, {"source_code": "#! usr/bin/env ruby\n\nstr1 = gets\nstr2 = gets\nputs str1.casecmp str2"}, {"source_code": "word1 = gets.chomp.downcase\nword2 = gets.chomp.downcase\n\nif word1 < word2 then \n print '-1'\nelsif word1 > word2 then\n print '1'\nelse\n print '0'\nend\n"}, {"source_code": "str1 = gets.chomp.downcase\n\nstr2 = gets.chomp.downcase\n\nif str1 == str2\n print \"0\"\nelsif str1 < str2\n print \"-1\"\nelsif str1 > str2\n print \"1\"\nend\n"}, {"source_code": "puts gets.capitalize <=> gets.capitalize"}, {"source_code": "#!/usr/bin/env ruby\na = gets.capitalize\nb = gets.capitalize\nputs a <=> b"}, {"source_code": "a=gets.chomp.downcase\nb=gets.chomp.downcase\nres=0\nif a==b\nputs \"#{res}\"\nelse\n0.upto(a.length-1) do |i|\nif a[i]!=b[i]\n\tif a[i].ord>b[i].ord\n\tres = 1\n\telse \n\tres= -1\n\tend\nbreak\nend\nend\nputs \"#{res}\"\t\nend\n\n"}, {"source_code": "first = gets.chomp\nsecond = gets.chomp\n\nputs first.downcase <=> second.downcase"}, {"source_code": "a = gets.strip\nb = gets.strip\na.downcase!\nb.downcase!\nputs a < b ? -1 : (a == b ? 0 : 1)"}, {"source_code": "puts gets.to_s.downcase <=> gets.to_s.downcase"}, {"source_code": "a = gets.chomp.downcase\nb = gets.chomp.downcase\nif(a==b)\n puts 0\nelse\n puts a < b ? -1 : 1\nend"}, {"source_code": "#http://codeforces.com/problemset/problem/112/A\n\nstr1 = gets.chomp\nstr2 = gets.chomp\n\nputs str1.downcase <=> str2.downcase\n"}, {"source_code": "p gets.downcase <=> gets.downcase"}, {"source_code": "def run(input = STDIN.read)\n line1, line2 = input.split(\"\\n\")\n line1.each_char.each_with_index do |char, index|\n next if char.downcase == line2[index].downcase\n\n puts char.downcase > line2[index].downcase ? \"1\" : \"-1\"\n return\n end\n puts \"0\"\nend\nrun"}, {"source_code": "a = gets.downcase\nb = gets.downcase\nputs (ab ? 1 : 0))\n"}, {"source_code": "#http://codeforces.com/problemset/problem/112/A\n\nstr1 = gets.chomp\nstr2 = gets.chomp\n\nputs str1.downcase <=> str2.downcase\n"}, {"source_code": "puts gets.to_s.downcase <=> gets.to_s.downcase"}, {"source_code": "s1, s2 = gets.downcase, gets.downcase\nif s1 > s2\n\tputs 1\nelsif s1 < s2\n\tputs -1\nelsif s1 == s2\n\tputs 0\nend\n"}, {"source_code": "\na,b=[1,2].map{gets.chomp.downcase}\np a==b ?0:[a,b].sort.index(a)*2-1"}, {"source_code": "#! ruby -Ku\n# -*- coding: UTF-8 -*-\nbegin\n inputs = open(\"input.txt\")\nrescue\n inputs = STDIN\nend\n\nfirst = inputs.gets.downcase.chomp.split(//)\nsecond = inputs.gets.downcase.chomp.split(//)\n\norder = 0\n\nfirst.each_with_index do |ch, i|\n if ch < second[i]\n order = -1\n break\n elsif ch > second[i]\n order = 1\n break\n end\nend\n\nputs order\n"}, {"source_code": "s1=gets.chomp.downcase.split(\"\")\ns2=gets.chomp.downcase.split(\"\")\nn=s1.length\ni,f = 0,1\nuntil n==0\n if s1[i].ords2[i].ord\n puts 1\n f=0\n break\n end\n n -= 1\n i += 1\nend\nputs 0 if f==1\n"}, {"source_code": "puts gets.upcase <=> gets.upcase\n"}, {"source_code": "a, b = gets.chomp.downcase, gets.chomp.downcase\n\nif a < b\n puts \"-1\"\nelsif a > b\n puts \"1\"\nelse\n puts \"0\"\nend\n"}, {"source_code": "a = gets.chomp.downcase\nb = gets.chomp.downcase\nif a > b\n\tputs \"1\"\nelsif a < b\n\tputs \"-1\"\nelse\n\tputs \"0\"\nend"}, {"source_code": "s1 = gets.chomp\ns2 = gets.chomp\n\nputs s1.casecmp s2\n"}, {"source_code": "first_str = gets.chomp\nsecond_str = gets.chomp\nres = 0\nfor i in 0..first_str.length-1\n\tif first_str[i].downcase.ord < second_str[i].downcase.ord\n\t\tres = -1\n\t\tbreak\n\telsif first_str[i].downcase.ord > second_str[i].downcase.ord\n\t\tres = 1\n\t\tbreak\n\tend\nend\nputs res"}, {"source_code": "str1 = gets.chomp.capitalize\nstr2 = gets.chomp.capitalize\nputs str1 <=> str2"}, {"source_code": "s1 = gets.chomp.downcase\ns2 = gets.chomp.downcase\n\nputs s1 <=> s2"}, {"source_code": "s = gets.chomp.upcase\nt = gets.chomp.upcase\np -1 if s < t\np 0 if s == t\np 1 if s > t"}, {"source_code": "s1 = gets\ns2 = gets\n\ns1 = s1.downcase\ns2 = s2.downcase\n\nif s1 > s2\n puts 1\nelsif s1 == s2\n puts 0\nelse\n puts -1\nend"}, {"source_code": "a = gets.chomp.downcase\nb = gets.chomp.downcase\n\nputs a <=> b"}, {"source_code": "#http://codeforces.com/problemset/problem/112/A\n\nstr1 = gets.chomp\nstr2 = gets.chomp\n\nputs str1.downcase <=> str2.downcase\n"}, {"source_code": "s1 = gets.chomp\ns2 = gets.chomp\n\nif s1.size < s2.size\n p -1\nelsif s2.size < s1.size\n p 1\nelse\n s1 = s1.downcase\n s2 = s2.downcase\n len = s1.size - 1\n\n for i in 0..len\n if s1[i] < s2[i]\n p -1\n break\n elsif s2[i] < s1[i]\n p 1\n break\n elsif i != len\n next\n else\n p 0\n end\n end\nend"}, {"source_code": "a = gets.chomp.downcase\nb = gets.chomp.downcase\n\nif a == b\n puts 0\nelsif a < b\n puts -1\nelse\n puts 1\nend"}, {"source_code": "string1 = gets.chomp.to_s.upcase\nstring2 = gets.chomp.to_s.upcase\nif string1 == string2\n puts '0'\nelsif string1 < string2\n puts '-1'\nelse\n puts '1'\nend"}, {"source_code": "a = gets.chomp.downcase\nb = gets.chomp.downcase\n\nn = a.length\nflag = 0\nfor i in 0..n-1 do\nif a[i] == b[i]\nnext\nelsif a[i] < b[i]\nflag = 1\nputs \"-1\"\nbreak\nelse\nflag = 1\nputs \"1\"\nbreak\nend\nend\nputs \"0\" unless flag == 1"}, {"source_code": "str1 = gets.chomp.downcase\n\nstr2 = gets.chomp.downcase\n\nif str1 == str2\n print \"0\"\nelsif str1 < str2\n print \"-1\"\nelsif str1 > str2\n print \"1\"\nend\n"}, {"source_code": "a, b = gets.downcase, gets.downcase\nputs a == b ? 0 : (a < b ? -1 : 1)\n"}, {"source_code": "str1 = gets.chomp.downcase\n\nstr2 = gets.chomp.downcase\n\nif str1 == str2\n print \"0\"\nelsif str1 < str2\n print \"-1\"\nelsif str1 > str2\n print \"1\"\nend\n"}, {"source_code": "n = gets.chomp.downcase\nm = gets.chomp.downcase\na = 0\n\nif n == m\n puts \"0\"\n exit\nend\n\nwhile n[a] == m[a]\n a += 1\nend\n\nif n[a] < m[a]\n puts \"-1\"\nelsif n[a] > m[a]\n puts \"1\"\nend"}, {"source_code": "s1 = gets.chomp.downcase\ns2 = gets.chomp.downcase\n\nputs s1 <=> s2"}, {"source_code": "a = gets.chomp.downcase\nb = gets.chomp.downcase\n\nif a < b then puts(-1) elsif a == b then puts(0) else puts(1) end"}, {"source_code": "p gets.downcase <=> gets.downcase"}, {"source_code": "puts gets.upcase <=> gets.upcase\n"}, {"source_code": "#!/usr/local/bin/ruby -w\n\ns1 = gets.chomp.downcase\ns2 = gets.chomp.downcase\n\nif (s1>s2) \n\tputs \"#{1}\"\nelsif (s1 y \n\tputs 1\nelse\n\tputs -1\nend"}, {"source_code": "print gets.chomp.upcase <=> gets.chomp.upcase"}, {"source_code": "first_word, second_word = STDIN.read.split\nputs first_word.downcase <=> second_word.downcase\n"}, {"source_code": "a = gets.strip\nb = gets.strip\na.downcase!\nb.downcase!\nputs a < b ? -1 : (a == b ? 0 : 1)"}, {"source_code": "print gets.chomp.upcase <=> gets.chomp.upcase"}, {"source_code": "s = gets.chomp.to_s\nt = gets.chomp.to_s\n\ns.downcase!\nt.downcase!\n\nif s>t \n puts 1\nelsif s==t\n puts 0\nelse\n puts -1\nend"}, {"source_code": "def order(a,b)\n if a.nil?\n return 0\n end\n if a[0] == b[0]\n order(a[1..-1], b[1..-1])\n elsif a > b\n return 1\n elsif a < b\n return -1\n end\nend\n\n\ndef call ()\n a = gets.chomp\n b = gets.chomp\n a.downcase!\n b.downcase!\n puts order(a,b)\nend\n\ncall"}, {"source_code": "s1 = gets.chomp.downcase\ns2 = gets.chomp.downcase\n\nputs s1 <=> s2"}, {"source_code": "x = gets.chomp.downcase\ny = gets.chomp.downcase\n\nif x==y \n\tputs 0\nelsif x > y \n\tputs 1\nelse\n\tputs -1\nend"}, {"source_code": "s0 = gets.chomp.downcase\ns1 = gets.chomp.downcase\n\nif s0 == s1\n puts 0\nelsif s0 < s1\n puts -1\nelse\n puts 1\nend\n"}, {"source_code": "a = gets.chomp\nb = gets.chomp\na.downcase!\nb.downcase!\nif a > b\n puts 1\nelsif b > a\n puts -1\nelse\n puts 0\nend"}, {"source_code": "s0 = gets.chomp.downcase\ns1 = gets.chomp.downcase\n\nif s0 == s1\n puts 0\nelsif s0 < s1\n puts -1\nelse\n puts 1\nend\n"}, {"source_code": "puts gets.capitalize <=> gets.capitalize"}, {"source_code": "a = gets.to_s\nb = gets.to_s\nif a.upcase == b.upcase \n p 0\nelse \nif a.upcase > b.upcase \n p 1\nelse\n p -1\nend \nend "}, {"source_code": "s1 = gets\ns2 = gets\n\ns1 = s1.downcase\ns2 = s2.downcase\n\nif s1 > s2\n puts 1\nelsif s1 == s2\n puts 0\nelse\n puts -1\nend"}, {"source_code": "a,b=[gets, gets].map(&:downcase)\np a<=>b\n\n"}, {"source_code": "puts gets.downcase<=>gets.downcase"}, {"source_code": "a = gets.chomp.downcase\nb = gets.chomp.downcase\n\nif a < b then puts(-1) elsif a == b then puts(0) else puts(1) end"}, {"source_code": "str1 = gets.chomp.capitalize\nstr2 = gets.chomp.capitalize\nputs str1 <=> str2"}, {"source_code": "a = gets.chomp.downcase\nb = gets.chomp.downcase\nif(a==b)\n puts 0\nelse\n puts a < b ? -1 : 1\nend"}, {"source_code": "puts gets.casecmp gets"}, {"source_code": "a, b = gets.downcase, gets.downcase\nputs a == b ? 0 : (a < b ? -1 : 1)\n"}, {"source_code": "#! usr/bin/env ruby\n\np gets.casecmp gets\n# p gets.upcase <=> gets.upcase"}, {"source_code": "a=gets.chomp.downcase\nb=gets.chomp.downcase\nres=0\nif a==b\nputs \"#{res}\"\nelse\n0.upto(a.length-1) do |i|\nif a[i]!=b[i]\n\tif a[i].ord>b[i].ord\n\tres = 1\n\telse \n\tres= -1\n\tend\nbreak\nend\nend\nputs \"#{res}\"\t\nend\n\n"}, {"source_code": "p gets.upcase<=>gets.upcase\n"}, {"source_code": "a=gets.chomp.upcase\nb=gets.chomp.upcase\np a<=>b"}, {"source_code": "s = gets.strip.downcase\nt = gets.strip.downcase\nputs(s < t ? -1 : s == t ? 0 : 1)\n"}, {"source_code": "a = gets.chomp\nb = gets.chomp\na.downcase!\nb.downcase!\nif a > b\n puts 1\nelsif b > a\n puts -1\nelse\n puts 0\nend"}, {"source_code": "a = gets.downcase\nb = gets.downcase\nif a == b\n\tputs \"0\"\nelse\n\tputs a > b ? 1 : -1\nend\n"}, {"source_code": "a = gets.chomp.split.map(&:downcase).join\nb = gets.chomp.split.map(&:downcase).join\nputs (a == b) ? 0 : a>b ? 1 : -1"}, {"source_code": "first = gets.chomp\nsecond = gets.chomp\nfirst_letters = first.split(\"\")\nsecond_letters = second.split(\"\")\nx = 1\nalphabet = ('a'..'z').to_a\n\ni = 0\ncounter = 0\nwhile counter == 0 && i < first.length.to_i\n\tif first_letters[i].downcase == second_letters[i].downcase\n\t\tcounter = 0\n\telsif first_letters[i].downcase < second_letters[i].downcase\n\t\tcounter -= 1\n\telsif first_letters[i].downcase > second_letters[i].downcase\n\t\tcounter += 1\n\tend\n\ti += 1\nend\n\nputs counter"}, {"source_code": "a = $stdin.readline ; b = $stdin.readline\na.upcase! ; b.upcase!\nputs a <=> b"}, {"source_code": "p gets.upcase<=>gets.upcase\n"}, {"source_code": "first_word, second_word = STDIN.read.split\nputs first_word.downcase <=> second_word.downcase\n"}, {"source_code": "#http://codeforces.com/problemset/problem/112/A\n\nstr1 = gets.chomp\nstr2 = gets.chomp\n\nputs str1.downcase <=> str2.downcase\n"}], "negative_code": [{"source_code": "n = gets.chomp.downcase\nm = gets.chomp.downcase\n\nif n[-1] < m[-1]\n puts \"-1\"\nelsif n[-1] > m[-1]\n puts \"1\"\nelse\n puts \"0\"\nend"}, {"source_code": "a=gets.chomp.upcase\nb=gets.chomp.upcase\na.size.times{|x|\nif a[x].chr>b[x].chr\nprint 1\nelsif b[x].chr>a[x].chr\nprint -1\nelsif x==a.size-1\nprint 0\nend}"}, {"source_code": "str1 = gets.chomp.downcase\n\nstr2 = gets.chomp.downcase\n\nif str1 == str2\n print \"equale\"\nelsif str1 < str2\n print \"-1\"\nelsif str1 > str2\n print \"1\"\nelsif str1 == str2\n print \"0\"\nend\n"}, {"source_code": "def order(a,b)\n if a.nil?\n return 0\n end\n if a[0] == b[0]\n order(a[1..-1], b[1..-1])\n elsif a > b\n return 1\n elsif a < b\n return -1\n end\nend\n\n\ndef call ()\n a = gets.chomp\n b = gets.chomp\n a.downcase!\n b.downcase!\n order(a,b)\nend\n\ncall"}, {"source_code": "def run(input = STDIN.read)\n line1, line2 = input.split(\"\\n\")\n line1.each_char.each_with_index do |char, index|\n puts \"-1\" && return if char.downcase != line2[index].downcase\n end\n puts \"0\" && return\nend\n\nrun"}, {"source_code": "def run(input = STDIN.read)\n line1, line2 = input.split(\"\\n\")\n line1.each_char.each_with_index do |char, index|\n return -1 if char.downcase != line2[index].downcase\n end\n return 0\nend\n\nrun"}, {"source_code": "s1=gets.chomp.downcase.split(\"\")\ns2=gets.chomp.downcase.split(\"\")\nn=s1.length\ni,f=0,1\nuntil n<0\n if s1[i].ords2[i].ord\n puts 1\n f=0\n break\n end\n n -= 1\nend\nputs 0 if f==1\n"}, {"source_code": "sum1,sum2,i,j = 0,0,0,0\ns1=gets.chomp.downcase.split(\"\").each do |x|\n sum1 += x.ord*(101-i)\n i += 1\nend\ns2=gets.chomp.downcase.split(\"\").each do |x|\n sum2 += x.ord*(101-j)\n j += 1\nend\nif sum1 < sum2\n puts -1\nelsif sum1 == sum2 \n puts 0\nelsif sum1 < sum2\n puts 1\nend"}, {"source_code": "sum1,sum2=0,0\ns1=gets.chomp.downcase.split('').map{|ch| ch.ord}.each {|x| sum1+=x }\ns2=gets.chomp.downcase.split('').map{|ch| ch.ord}.each {|x| sum2+=x }\nif sum1==sum2\n puts 0\nelse\n puts (sum1-sum2)/(sum1-sum2).abs\nend"}, {"source_code": "sum1,sum2,i,j = 0,0,0,0\ns1=gets.chomp.downcase.split(\"\").each do |x|\n sum1 += (x.ord-96)*(101-i)\n i += 1\nend\ns2=gets.chomp.downcase.split(\"\").each do |x|\n sum2 += (x.ord-96)*(101-j)\n j += 1\nend\nif sum1 < sum2\n puts -1\nelsif sum1 == sum2 \n puts 0\nelsif sum1 > sum2\n puts 1\nend"}, {"source_code": "sum1,sum2=0,0\ns1=gets.chomp.downcase.split('').map{|ch| ch.to_i}.each {|x| sum1+=x }\ns2=gets.chomp.downcase.split('').map{|ch| ch.to_i}.each {|x| sum2+=x }\nif sum1-sum2==0\n puts 0\nelse\n puts (sum1-sum2)/(sum1-sum2).abs\nend"}, {"source_code": "p gets <=> gets"}, {"source_code": "n=0\na=gets.downcase\nb=gets.downcase\na.length.times{|i|\nn += a[i]<=>b[i]}\nn != 0? n/=n : ()\np n\n"}, {"source_code": "ans=0\n\na=gets.downcase.sum\n\nb=gets.downcase.sum\n\nif a>b then\n\tans=1\nelsif alb then\n\tans=1\nelsif alb then\n\tans=1\nelsif lab[i]}\nn != 0? n/=n.abs : ()\np n\n"}, {"source_code": "a=gets.downcase.sum\nb=gets.downcase.sum\nputs a<=>b\n"}, {"source_code": "str1 = gets.chomp.bytes.to_a\nstr2 = gets.chomp.bytes.to_a\n\nstr1.each_with_index do |c, i|\n if c < str2[i]\n puts '-1'\n exit\n elsif c > str2[i]\n puts '1'\n exit\n end\nend\n\nputs '0'\n"}, {"source_code": "a = gets.to_s\nb = gets.to_s\nif a == b \n p 0\nelse \nif a > b \n p 1\nelse\n p -1\nend \nend "}, {"source_code": "s1 = gets.chomp\ns2 = gets.chomp\nif s1.upcase==s2.upcase\n puts 0\nend\nif s2.upcases2.upcase\n put -1\nend"}, {"source_code": "str1 = gets.chomp.to_s\nstr2 = gets.chomp.to_s\n\nputs str1 <=> str2\n"}, {"source_code": "a=gets.strip.downcase\nb=gets.strip.downcase\nputs 0 and return if a == b\ndef compare a1,a2\n\tval = (a1 != a2) ? ((a1 > a2) ? 1 : -1 ) : 0\n\treturn val\nend\nfor i in 0..a.length-1\n\tc = compare a[i].ord,b[i].ord\n\tputs c and break if c != 0\nend\n\n\n"}, {"source_code": "a=gets.strip\nb=gets.strip\nt1 = a.downcase.each_byte.to_a.inject(0){|total,num| total+num} \nt2= b.downcase.each_byte.to_a.inject(0){|total,num| total+num}\nresult = t1 == t2 ? 0 : (t1 > t2) ? 1 : -1\nputs result"}, {"source_code": "str1 = gets.chomp.downcase\nstr2 = gets.chomp.downcase\n\nif str1 == str2\n puts 0\nelse\n puts -1\nend"}, {"source_code": "str1 = gets.chomp.capitalize!\nstr2 = gets.chomp.capitalize!\nputs str1 <=> str2"}, {"source_code": "first_line = gets.chomp\nsecond_line = gets.chomp\n\nfirst_line = first_line.downcase\nsecond_line = second_line.downcase\nsum_1 = 0\nsum_2 = 0\n\t\n\n\tfirst_line.each_char.each do |value|\n\t\tsum_1 += value.ord\n\tend\n\n\tsecond_line.each_char.each do |value|\n\t\tsum_2 += value.ord\n\tend\n\tputs 0 if sum_1 == sum_2\n\tputs -1 if sum_1 < sum_2\n\tputs 1 if sum_1 > sum_2\t\n\n"}, {"source_code": "first_string = gets.strip.split('').map(&:downcase)\nsecond_string = gets.strip.split('').map(&:downcase)\n\ndef compare_strings(first_string, second_string)\n return (puts 0) if first_string == second_string\n first_string.each_with_index do |char, index|\n unless char == second_string[index]\n char > second_string[index] ? (return 1) : (return -1)\n end\n end\nend\n\ncompare_strings(first_string, second_string)\n"}, {"source_code": "first_string = gets.strip.split('').map(&:downcase)\nsecond_string = gets.strip.split('').map(&:downcase)\n\ndef compare_strings(first_string, second_string)\n return 0 if first_string == second_string\n first_string.each_with_index do |char, index|\n unless char == second_string[index]\n char > second_string[index] ? (return ()) : (return -1)\n end\n end\nend\n\nputs compare_strings(first_string, second_string)\n"}, {"source_code": "x = gets.chomp()\ny = gets.chomp()\nx = x.upcase()\ny = y.upcase()\nif x>y\n\tputs -1\nelsif x==y\n\tputs 0\nelse\n\tputs 1\nend"}, {"source_code": "a = gets.chomp.downcase\nb = gets.chomp.downcase\n\ni = a.length\ni.times do\nif a[i] == b [i]\nnext\nelsif a[i] < b [i]\nputs \"-1\"\nbreak\nelse\nputs \"1\"\nbreak\nend\nputs \"0\"\nend\n"}, {"source_code": "a = gets.chomp.downcase\nb = gets.chomp.downcase\n\ni = a.length\ni.times do\nif a[i-1] == b [i-1]\nnext\nelsif a[i-1] < b [i-1]\nputs \"-1\"\nbreak\nelse\nputs \"1\"\nbreak\nend\nputs \"0\"\nend\n"}], "src_uid": "ffeae332696a901813677bd1033cf01e"} {"nl": {"description": "There are three friend living on the straight line Ox in Lineland. The first friend lives at the point x1, the second friend lives at the point x2, and the third friend lives at the point x3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they have to travel in order to meet at some point and celebrate the New Year?It's guaranteed that the optimal answer is always integer.", "input_spec": "The first line of the input contains three distinct integers x1, x2 and x3 (1\u2009\u2264\u2009x1,\u2009x2,\u2009x3\u2009\u2264\u2009100)\u00a0\u2014 the coordinates of the houses of the first, the second and the third friends respectively. ", "output_spec": "Print one integer\u00a0\u2014 the minimum total distance the friends need to travel in order to meet together.", "sample_inputs": ["7 1 4", "30 20 10"], "sample_outputs": ["6", "20"], "notes": "NoteIn the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4."}, "positive_code": [{"source_code": "input = gets.split(\" \").map! { |i| i.to_i }\n\nmax = input.sort[input.size-1]\nmin_d = 300\n\nfor p in 1..max\n\tcDist = (p - input[0]).abs + (p - input[1]).abs + (p - input[2]).abs\n\tif cDist < min_d\n\t\tmin_d = cDist\n\tend\nend\n\nputs min_d"}, {"source_code": "xs = gets.chomp.split.map(&:to_i)\n\nputs xs.max - xs.min\n"}, {"source_code": "d = gets.chomp\ndistances = d.split\n\nfor i in (0..distances.size-1)\n\tfor x in (0..distances.size-1)\n\t\tif i != x\n\t\t\tif distances[i].to_i < distances[x].to_i\n\t\t\t\ttemp = distances[x].to_i\n\t\t\t\tdistances[x] = distances[i].to_i\n\t\t\t\tdistances[i] = temp\n\t\t\tend\n\t\tend\n\tend\nend\n\ndistance = 0\nfor i in (0..distances.size-1)\n\tif i != distances.size-1\n\t\tif distances[i].to_i <= distances[i+1]\n\t\t\tdistance += (distances[i+1].to_i - distances[i].to_i)\n\t\telse\n\t\t\tdistance += (distances[i].to_i - distances[i+1].to_i)\n\t\tend\n\tend\nend\n\nprint distance"}, {"source_code": "a,b,c=gets.split.map(&:to_i).sort\np c-a"}, {"source_code": "a, b, c = gets.split.map(&:to_i).sort\np c - a\n"}, {"source_code": "def max(a,b,c)\n if (a >= b) && (a >= c)\n return a\n end\n if (b >= a) && (b >= c)\n return b\n end\n if (c >= a) && (c >= b)\n return c\n end\nend\n\ndef min(a,b,c)\n if (a <= b) && (a <= c)\n return a\n end\n if (b <= a) && (b <= c)\n return b\n end\n if (c <= a) && (c <= b)\n return c\n end\nend\n\nline = gets\nx1 = line.split(' ')[0].to_i\nx2 = line.split(' ')[1].to_i\nx3 = line.split(' ')[2].to_i\n\nputs max(x1,x2,x3) - min(x1,x2,x3)\n"}, {"source_code": "a = gets.split(' ').map(&:to_i)\n\nputs a.max - a.min\n"}, {"source_code": "a, b, c = gets.split.map(&:to_i).sort\nputs c - a"}, {"source_code": "input = gets.chomp.split(' ').map(&:to_i)\ninput.sort!\nputs input[input.length - 1] - input[0]"}, {"source_code": "# -*- mode: ruby -*-\n# vi: set ft=ruby :\n\narr = gets.split.map{|x| x.to_i}.sort\nputs arr[-1]-arr[0]\n"}, {"source_code": "a,b=gets.split.map(&:to_i).minmax;p b-a"}, {"source_code": "x1,x2,x3 = gets.split.map(&:to_i).sort\n\nputs x3-x1"}, {"source_code": "xs = gets.split.map(&:to_i)\nputs ((1..100).map do |i|\n xs.map { |x| (x - i).abs }.inject(&:+)\nend.min)\n"}, {"source_code": "a, b, c = gets.chomp.split.map(&:to_i).sort\n\nputs (b - a) + (c - b)\n"}, {"source_code": "a = gets.split.map(&:to_i)\nputs a.max - a.min\n"}, {"source_code": "a = gets.split.map(&:to_i)\na.sort!\nputs a[1] - a[0] + a[2] - a[1]\n"}, {"source_code": "x = gets.split.map(&:to_i)\nx.sort!\nputs x[1]-x[0] + x[2]-x[1]\n"}, {"source_code": "debug = FALSE#TRUE\nfin = (if debug then File.open \"tc.txt\" else $stdin end)\n\n\ninput = fin.read.chomp.split /\\s/\na = []\ninput.each do |x|\n\ta << x.to_i\nend\na.sort!\n\n#a.each do |x| print x.to_s + \" \" end\n\nmeet = a[0]\nres = 1000000\nbegin\n\tsum = ((a[0]-meet).abs) + ((a[1]-meet).abs) + ((a[2]-meet).abs)\n\tres = sum if sum a[2]\n\nprint res\nfin.close"}, {"source_code": "a, b, c = gets.split.map(&:to_i).sort\n\nputs (a-b).abs + (b-c).abs"}, {"source_code": "x, y, z = gets.strip.split.map(&:to_i)\na = [x, y, z].min\nb = [x, y, z].max\nans = b - a\nputs ans\n"}, {"source_code": "a=gets.split.map{|e| e.to_i}.sort\nt1=(a[2]-a[0])+(a[1]-a[0])\nt2=(a[2]-a[1])+(a[1]-a[0])\nt3=(a[2]-a[0])+(a[2]-a[1])\nputs [t1,t2,t3].min"}, {"source_code": "a, b = gets.split.map(&:to_i).minmax\nputs b - a\n"}, {"source_code": "a = gets.split.map(&:to_i).sort!\nputs a[1] - a[0] + a[2] - a[1]\n"}, {"source_code": "res=0\ngets.split.map(&:to_i).sort.each_cons(2){|a, b| res+=b-a}\nputs res"}, {"source_code": "while str = STDIN.gets\n array = str.split(' ').map{|_| _.to_i}\n min = 999\n for i in 1..(array.max)\n total = (i - array[0]).abs + (i - array[1]).abs + (i - array[2]).abs\n min = total if min > total\n end\n puts min\nend\n"}], "negative_code": [{"source_code": "a, b, c = gets.split.map(&:to_i)\ns = a + b + c\nif s % 3 == 0\n g = s / 3\n p (a - g).abs + (b - g).abs + (c - g).abs\nelse\n t1 = (s / 3.0).ceil\n t2 = s / 3\n p [(a - t1).abs + (b - t1).abs + (c - t1).abs, (a - t2).abs + (b - t2).abs + (c - t2).abs].min\nend\n"}, {"source_code": "a, b, c = gets.split.map(&:to_i)\ng = (a + b + c) / 3\np (a - g).abs + (b - g).abs + (c - g).abs\n"}, {"source_code": "input = gets.chomp.split(' ').map(&:to_i)\n\nsum = input.reduce(:+)\nsum /= 3\nans = 0\n\ninput.each do |i|\n\tans += (sum - i).abs\nend\n\nputs ans"}, {"source_code": "a = gets.split.map(&:to_i)\na.sort!\nx = (a.first + a.last) / 2\nputs x - a.first + [ a[1] - x, x - a[1] ].max + a.last - x\n"}, {"source_code": "while str = STDIN.gets\n array = str.split(' ').map{|_| _.to_i}\n ave = array.inject(0.0){|r, i| r += i } / array.size\n puts array.map{|_| (ave - _).abs}.inject {|sum, n| sum + n}.to_i\nend\n"}, {"source_code": "while str = STDIN.gets\n array = str.split(' ').map{|_| _.to_i}\n ave = array.inject(0.0){|r, i| r += i } / array.size\n puts array.map{|_| (ave - _).abs}.inject {|sum, n| sum + n}.ceil\nend\n"}, {"source_code": "while str = STDIN.gets\n array = str.split(' ').map{|_| _.to_i}\n ave = array.inject(0.0){|r, i| r += i } / array.size\n puts array.map{|_| (ave - _).abs}.inject {|sum, n| sum + n}.round\nend\n"}, {"source_code": "input = gets.split(\" \")\n\nmiddle_pt = 0\ninput.each do |i|\n\tmiddle_pt = middle_pt + i.to_i\nend\n\nmiddle_pt = middle_pt / input.size\n\ntotal_dist = 0\ninput.each do |i|\n\ttotal_dist = total_dist + (i.to_i - middle_pt).abs\nend\n\nputs total_dist"}, {"source_code": "input = gets.split(\" \")\ninput = input.sort\n\ntotal_dist = 0\n\nfor i in 1..input.length-1\n\ttotal_dist = total_dist + (input[i].to_i - input[i-1].to_i)\nend\n\nputs total_dist"}], "src_uid": "7bffa6e8d2d21bbb3b7f4aec109b3319"} {"nl": {"description": "Tonio has a keyboard with only two letters, \"V\" and \"K\".One day, he has typed out a string s with only these two letters. He really likes it when the string \"VK\" appears, so he wishes to change at most one letter in the string (or do no changes) to maximize the number of occurrences of that string. Compute the maximum number of times \"VK\" can appear as a substring (i.\u00a0e. a letter \"K\" right after a letter \"V\") in the resulting string.", "input_spec": "The first line will contain a string s consisting only of uppercase English letters \"V\" and \"K\" with length not less than 1 and not greater than 100.", "output_spec": "Output a single integer, the maximum number of times \"VK\" can appear as a substring of the given string after changing at most one character.", "sample_inputs": ["VK", "VV", "V", "VKKKKKKKKKVVVVVVVVVK", "KVKV"], "sample_outputs": ["1", "1", "0", "3", "1"], "notes": "NoteFor the first case, we do not change any letters. \"VK\" appears once, which is the maximum number of times it could appear.For the second case, we can change the second character from a \"V\" to a \"K\". This will give us the string \"VK\". This has one occurrence of the string \"VK\" as a substring.For the fourth case, we can change the fourth character from a \"K\" to a \"V\". This will give us the string \"VKKVKKKKKKVVVVVVVVVK\". This has three occurrences of the string \"VK\" as a substring. We can check no other moves can give us strictly more occurrences."}, "positive_code": [{"source_code": "s = gets\nif s[-1] == \"\\n\"\n s = s.split(\"\\n\")[0].to_s\nend\nres = 0\nchanged = false\ni = 0\nwhile i < s.size \n if s[i] == 'V' && s[i+1] == 'K'\n i += 2\n res += 1\n next\n end\n if changed\n i += 1\n next\n end\n if s[i] == 'K' && s[i+1] == 'K' ||\n s[i] == 'V' && s[i+1] == 'V' && (s[i+2] == 'V' || s[i+2] == nil)\n res += 1\n i += 2\n changed = true\n next\n end\n i += 1\nend\n\nputs res"}, {"source_code": "# kkk +1\n\n# kkv skip\n# kvk skip\n# vkk skip\n\n# vvk skip\n# vkv skip\n# kvv \n\n# vvv +1\n\nk_counter = 0\nv_counter = 0\nvk = 0\nv = 0\nk = 0\n\ns = gets.chomp\ns << \"V\"\ns = \"K\" << s\n(0..s.length-1).each do |x|\n if s[x] == \"V\"\n v_counter = v_counter + 1\n k_counter = 0\n v = 1 if v_counter == 3\n vk = vk + 1 if (x+1 <= (s.length-1)) && s[x+1] ==\"K\"\n else\n k_counter = k_counter + 1\n v_counter = 0\n k = 1 if k_counter == 3\n end\nend\nvk = vk + 1 if v == 1 || k == 1\nputs vk"}, {"source_code": "s=gets.chomp\nr=s.scan('VK').size\ns.size.times{|i|\n\ts[i]=s[i].tr('VK','KV')\n\tr=[r,s.scan('VK').size].max\n\ts[i]=s[i].tr('VK','KV')\n}\np r"}, {"source_code": "str1 = gets().chomp\nstr1_count = str1.scan(/VK/).size\nif (str1.scan(/VVV/).size >= 1) || (str1.scan(/KKK/).size >= 1) || (str1[0,2]=='KK') || (str1[-2,str1.size]=='VV')\n str1_count += 1\nend\np str1_count"}, {"source_code": "s = gets\nputs s.length - s.gsub('VK', ' ').sub(/KK|VV/, ' ').length"}], "negative_code": [{"source_code": "s = gets\nres = 0\nchanged = false\ni = 0\nwhile i < s.size \n if s[i] == 'V' && s[i+1] == 'K'\n i += 2\n res += 1\n next\n end\n if changed\n i += 1\n next\n end\n if s[i] == 'K' && s[i+1] == 'K' ||\n s[i] == 'V' && s[i+1] == 'V' && (s[i+2] == 'V' || s[i+2] == nil)\n res += 1\n i += 2\n changed = true\n next\n end\n i += 1\nend\n\nputs res\n"}, {"source_code": "# kkk +1\n\n# kkv skip\n# kvk skip\n# vkk skip\n\n# vvk skip\n# vkv skip\n# kvv \n\n# vvv +1\n\nk_counter = 0\nv_counter = 0\nvk = 0\nv = 0\nk = 0\n\ns = gets()\ns << \"V\"\n(0..s.length-1).each do |x|\n if s[x] == \"V\"\n v_counter = v_counter + 1\n k_counter = 0\n v = 1 if v_counter == 3\n vk = vk + 1 if (x+1 <= (s.length-1)) && s[x+1] ==\"K\"\n else\n k_counter = k_counter + 1\n v_counter = 0\n k = 1 if k_counter == 3\n end\nend\nvk = vk + 1 if v == 1 || k == 1\nputs vk"}, {"source_code": "# kkk +1\n\n# kkv skip\n# kvk skip\n# vkk skip\n\n# vvk skip\n# vkv skip\n# kvv \n\n# vvv +1\n\nk_counter = 0\nv_counter = 0\nvk = 0\nv = 0\nk = 0\n\ns = gets()\n(0..s.length-1).each do |x|\n if s[x] == \"V\"\n v_counter = v_counter + 1\n k_counter = 0\n v = 1 if v_counter == 3\n vk = vk + 1 if (x+1 <= (s.length-1)) && s[x+1] ==\"K\"\n else\n k_counter = k_counter + 1\n v_counter = 0\n k = 1 if k_counter == 3\n end\nend\nvk = vk + 1 if v == 1 || k == 1\nputs vk"}, {"source_code": "# kkk +1\n\n# kkv skip\n# kvk skip\n# vkk skip\n\n# vvk skip\n# vkv skip\n# kvv \n\n# vvv +1\n\nk_counter = 0\nv_counter = 0\nvk = 0\nv = 0\nk = 0\n\ns = gets.chomp\ns << \"V\"\n# puts s\n(0..s.length-1).each do |x|\n if s[x] == \"V\"\n v_counter = v_counter + 1\n k_counter = 0\n v = 1 if v_counter == 3\n vk = vk + 1 if (x+1 <= (s.length-1)) && s[x+1] ==\"K\"\n else\n k_counter = k_counter + 1\n v_counter = 0\n k = 1 if k_counter == 3\n end\nend\nvk = vk + 1 if v == 1 || k == 1\nputs vk"}, {"source_code": "str1 = gets().chomp\nstr1_count = str1.scan(/VK/).size\nif (str1_count != 0 && str1.scan(/VVV/||/KKK/).size > 0) || (str1[0,2]=='KK') || (str1[-2,str1.size]=='VV')\n str1_count += 1\nend\np str1_count"}, {"source_code": "str1 = gets().chomp\nstr1_count = str1.scan(/VK/).size\nif (str1_count != 0 && str1.scan(/VVV/||/KKK/).size > 0) || (str1_count == 0 && str1.scan(/VV/||/KK/).size > 0) || (str1[0,2]=='KK' || str1[0,2]=='VV')\n str1_count += 1\nend\np str1_count"}, {"source_code": "str1 = gets().chomp\nstr1_count = str1.scan(/VK/).size\nif (str1_count != 0 && str1.scan(/VVV/&&/KKK/).size > 0) || (str1_count == 0 && str1.scan(/VV/&&/KK/).size > 0)\n str1_count += 1\nend\np str1_count"}, {"source_code": "str1 = gets().chomp\nstr1_count = str1.scan(/VK/).size\nif (str1_count != 0 && str1.scan(/VVV/||/KKK/).size > 0) || (str1_count == 0 && str1.scan(/VV/||/KK/).size > 0) || (str1[0,2]=='KK')\n str1_count += 1\nend\np str1_count"}, {"source_code": "str1 = gets().chomp\nstr1_count = str1.scan(/VK/).size\nif (str1.scan(/VVV/||/KKK/).size > 0) || (str1[0,2]=='KK') || (str1[-2,str1.size]=='VV')\n str1_count += 1\nend\np str1_count"}, {"source_code": "str1 = gets().chomp\nstr1_count = str1.scan(/VK/).size\nif str1.scan(/VVV/&&/KKK/).size > 0\n str1_count += 1\nend\np str1_count"}, {"source_code": "str1 = gets().chomp\nstr1_count = str1.scan(/VK/).size\nif (str1_count != 0 && str1.scan(/VVV/||/KKK/).size > 0) || (str1_count == 0 && str1.scan(/VV/||/KK/).size > 0)\n str1_count += 1\nend\np str1_count"}, {"source_code": "s = gets\nx = s.gsub('VK', '').length\nx -= 2 if x > 1\nputs (s.length - x) / 2"}, {"source_code": "s = gets.strip\nt = s.gsub('VK', '')\nx = t.length\nx -= 2 if (x > 2 || x == 2 && t != 'KV')\nputs (s.length - x) / 2"}, {"source_code": "s = gets.strip\nx = s.gsub('VK', '').length\nx -= 2 if x > 1\nputs (s.length - x) / 2"}, {"source_code": "s = gets\nputs (s.length - s.gsub('VK','').sub('KV','').length) / 2"}, {"source_code": "s = gets.strip\nt = s.gsub('VK', '')\nx = t.length\nx += 2 if (x > 1 && t[0] + t[-1] != 'VK')\nputs (t.length - x) / 2"}, {"source_code": "s = gets\nt = s.gsub('VK', ' ')\nputs s.length - t.length + ((t.include? 'VV'||(t.include? 'KK')) ? 1 : 0)"}, {"source_code": "s = gets\nputs (s.length - s.gsub('VK', '').sub('VV', '').sub('KK', '').length) / 2"}, {"source_code": "s = gets.strip\nt = s.gsub('VK', '')\nx = t.length\nx -= 2 if (x > 1 && t[0] + t[-1] != 'VK')\nputs (t.length - x) / 2"}, {"source_code": "s = gets\nputs (s.length - s.gsub('VK', '').sub('V', '').sub('K', '').length) / 2"}], "src_uid": "578bae0fe6634882227ac371ebb38fc9"} {"nl": {"description": "Polar bears Menshykov and Uslada from the zoo of St. Petersburg and elephant Horace from the zoo of Kiev decided to build a house of cards. For that they've already found a hefty deck of n playing cards. Let's describe the house they want to make: The house consists of some non-zero number of floors. Each floor consists of a non-zero number of rooms and the ceiling. A room is two cards that are leaned towards each other. The rooms are made in a row, each two adjoining rooms share a ceiling made by another card. Each floor besides for the lowest one should contain less rooms than the floor below. Please note that the house may end by the floor with more than one room, and in this case they also must be covered by the ceiling. Also, the number of rooms on the adjoining floors doesn't have to differ by one, the difference may be more. While bears are practicing to put cards, Horace tries to figure out how many floors their house should consist of. The height of the house is the number of floors in it. It is possible that you can make a lot of different houses of different heights out of n cards. It seems that the elephant cannot solve this problem and he asks you to count the number of the distinct heights of the houses that they can make using exactly n cards.", "input_spec": "The single line contains integer n (1\u2009\u2264\u2009n\u2009\u2264\u20091012) \u2014 the number of cards.", "output_spec": "Print the number of distinct heights that the houses made of exactly n cards can have.", "sample_inputs": ["13", "6"], "sample_outputs": ["1", "0"], "notes": "NoteIn the first sample you can build only these two houses (remember, you must use all the cards): Thus, 13 cards are enough only for two floor houses, so the answer is 1.The six cards in the second sample are not enough to build any house."}, "positive_code": [{"source_code": "n = STDIN.readline.to_i\nk = ((2*n/3.0)**0.5).floor + 1\nk += 1 while (n+k)%3 != 0\nk -= 3 while 3*k**2 + k > 2*n\nputs (k+2)/3\n"}, {"source_code": "#!/usr/bin/env ruby\n\nn = gets.to_i\n\nl, r = 0, n\nwhile l != r\n m = (l + r + 1) / 2\n need = 3 * m * (m + 1) / 2 - m\n if need <= n\n l = m\n else\n r = m - 1\n end\nend\n\nl -= 1 while l > 0 && [0, 2, 1][l % 3] != n % 3\nputs (l + 2) / 3\n"}], "negative_code": [], "src_uid": "ab4f9cb3bb0df6389a4128e9ff1207de"} {"nl": {"description": "You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect.The interior of the square is considered to be part of the square, i.e. if one square is completely inside another, they intersect. If the two squares only share one common point, they are also considered to intersect.", "input_spec": "The input data consists of two lines, one for each square, both containing 4 pairs of integers. Each pair represents coordinates of one vertex of the square. Coordinates within each line are either in clockwise or counterclockwise order. The first line contains the coordinates of the square with sides parallel to the coordinate axes, the second line contains the coordinates of the square at 45 degrees. All the values are integer and between $$$-100$$$ and $$$100$$$.", "output_spec": "Print \"Yes\" if squares intersect, otherwise print \"No\". You can print each letter in any case (upper or lower).", "sample_inputs": ["0 0 6 0 6 6 0 6\n1 3 3 5 5 3 3 1", "0 0 6 0 6 6 0 6\n7 3 9 5 11 3 9 1", "6 0 6 6 0 6 0 0\n7 4 4 7 7 10 10 7"], "sample_outputs": ["YES", "NO", "YES"], "notes": "NoteIn the first example the second square lies entirely within the first square, so they do intersect.In the second sample squares do not have any points in common.Here are images corresponding to the samples: "}, "positive_code": [{"source_code": "a = gets.split.map {|s| s.to_i}\nb = gets.split.map {|s| s.to_i}\n\n$x1, $x2 = [a[0], a[2], a[4], a[6]].minmax\n$y1, $y2 = [a[1], a[3], a[5], a[7]].minmax\n\n$x3 = (b[0] + b[2] + b[4] + b[6]) / 4.0\n$y3 = (b[1] + b[3] + b[5] + b[7]) / 4.0\n$r = (b[0] - $x3).abs + (b[1] - $y3).abs\n\ndef a_contains x, y\n x >= $x1 and x <= $x2 and y >= $y1 and y <= $y2\nend\n\ndef b_contains x, y\n (x - $x3).abs + (y - $y3).abs <= $r\nend\n\ndef clamp x, y, z\n if y > z then y, z = z, y end\n [[x, y].max, z].min\nend\n\na.push a[0], a[1]\nputs (0..7).step(2).any? {|i|\n a_contains(b[i], b[i + 1]) ||\n b_contains(a[i], a[i + 1]) ||\n b_contains(clamp($x3, a[i], a[i + 2]), a[i + 1]) ||\n b_contains(a[i], clamp($y3, a[i + 1], a[i + 3]))\n} ? 'Yes' : 'No'\n"}, {"source_code": "a = gets.split.map {|s| s.to_i}\nb = gets.split.map {|s| s.to_i}\n \n$x1, $x2 = [a[0], a[2], a[4], a[6]].minmax\n$y1, $y2 = [a[1], a[3], a[5], a[7]].minmax\n \n$x3 = (b[0] + b[2] + b[4] + b[6]) / 4.0\n$y3 = (b[1] + b[3] + b[5] + b[7]) / 4.0\n$r = (b[0] - $x3).abs + (b[1] - $y3).abs\n \ndef a_contains x, y\n x >= $x1 and x <= $x2 and y >= $y1 and y <= $y2\nend\n \ndef b_contains x, y\n (x - $x3).abs + (y - $y3).abs <= $r\nend\n \ndef clamp x, y, z\n if y > z then y, z = z, y end\n [[x, y].max, z].min\nend\n \na.push a[0], a[1]\nputs (0..7).step(2).any? {|i|\n a_contains(b[i], b[i + 1]) ||\n b_contains(a[i], a[i + 1]) ||\n b_contains(clamp($x3, a[i], a[i + 2]), a[i + 1]) ||\n b_contains(a[i], clamp($y3, a[i + 1], a[i + 3]))\n} ? \"Yes\" : 'No'"}, {"source_code": "\na = gets.split.map {|s| s.to_i}\nb = gets.split.map {|s| s.to_i}\n \n$x1, $x2 = [a[0], a[2], a[4], a[6]].minmax\n$y1, $y2 = [a[1], a[3], a[5], a[7]].minmax\n \n$x3 = (b[0] + b[2] + b[4] + b[6]) / 4.0\n$y3 = (b[1] + b[3] + b[5] + b[7]) / 4.0\n$r = (b[0] - $x3).abs + (b[1] - $y3).abs\n \ndef a_contains x, y\n x >= $x1 and x <= $x2 and y >= $y1 and y <= $y2\nend\n \ndef b_contains x, y\n (x - $x3).abs + (y - $y3).abs <= $r\nend\n \ndef clamp x, y, z\n if y > z then y, z = z, y end\n [[x, y].max, z].min\nend\n \na.push a[0], a[1]\nputs (0..7).step(2).any? {|i|\n a_contains(b[i], b[i + 1]) ||\n b_contains(a[i], a[i + 1]) ||\n b_contains(clamp($x3, a[i], a[i + 2]), a[i + 1]) ||\n b_contains(a[i], clamp($y3, a[i + 1], a[i + 3]))\n} ? 'Yes' : 'No'"}, {"source_code": "def check(as, bs)\n ax = [0,2,4,6].map{|i|as[i]}\n ay = [1,3,5,7].map{|i|as[i]}\n bcx = [0,2,4,6].map{|i|bs[i]}.inject(:+)/4.to_f\n bcy = [1,3,5,7].map{|i|bs[i]}.inject(:+)/4.to_f\n [bs[0,2], bs[2,2], bs[4,2], bs[6,2], [bcx,bcy]].each do |bx, by|\n if bx.between?(ax.min, ax.max) && by.between?(ay.min, ay.max)\n puts 'YES'\n exit\n end\n end\nend\n\nas = gets.split.map(&:to_i)\nbs = gets.split.map(&:to_i)\n\ncheck(as, bs)\n4.times do |i|\n as[2*i], as[2*i+1] = [as[2*i] + as[2*i+1], as[2*i] - as[2*i+1]]\n bs[2*i], bs[2*i+1] = [bs[2*i] + bs[2*i+1], bs[2*i] - bs[2*i+1]]\nend\ncheck(bs, as)\nputs 'NO'"}], "negative_code": [{"source_code": "a = gets.split.map {|s| s.to_i}\nb = gets.split.map {|s| s.to_i}\n\n$x1, $x2 = [a[0], a[2], a[4], a[6]].minmax\n$y1, $y2 = [a[1], a[3], a[5], a[7]].minmax\n\n$x3 = (b[0] + b[2] + b[4] + b[6]) / 4.0\n$y3 = (b[1] + b[3] + b[5] + b[7]) / 4.0\n$r = (b[0] - $x3).abs + (b[1] - $y3).abs\n\ndef a_contains x, y\n x >= $x1 and x <= $x2 and y >= $y1 and y <= $y2\nend\n\ndef b_contains x, y\n (x - $x3).abs + (y - $y3).abs <= $r\nend\n\nputs (0..7).step(2).any? {|i|\n a_contains(b[i], b[i + 1]) || b_contains(a[i], a[i + 1])\n} ? 'Yes' : 'No'\n"}], "src_uid": "f6a3dd8b3bab58ff66055c61ddfdf06a"} {"nl": {"description": "DO YOU EXPECT ME TO FIND THIS OUT?WHAT BASE AND/XOR LANGUAGE INCLUDES string?DON'T BYTE OF MORE THAN YOU CAN CHEWYOU CAN ONLY DISTORT THE LARGEST OF MATHEMATICS SO FARSAYING \"ABRACADABRA\" WITHOUT A MAGIC AND WON'T DO YOU ANY GOODTHE LAST STACK RUPTURES. ALL DIE. OH, THE EMBARRASSMENT!I HAVE NO ARRAY AND I MUST SCREAMELEMENTS MAY NOT BE STORED IN WEST HYPERSPACE", "input_spec": "The first line of input data contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u200910). The second line of input data contains n space-separated integers ai (1\u2009\u2264\u2009ai\u2009\u2264\u200911).", "output_spec": "Output a single integer.", "sample_inputs": ["4\n2 5 3 1"], "sample_outputs": ["4"], "notes": null}, "positive_code": [{"source_code": "n,*a=$<.read.split.map &:to_i;p a[-1]^a.max"}, {"source_code": "gets\na=gets.split.map(&:to_i)\np a[-1]^a.max"}, {"source_code": "gets;x=gets.split.map &:to_i;p x.max^x[-1]"}, {"source_code": "gets;x=gets.split.map &:to_i;p x.max^x[-1]"}, {"source_code": "gets\na = gets.split(/\\s+/).map(&:to_i)\n\nlast = a[-1]\nmax = a.max\nputs last ^ max\n"}], "negative_code": [], "src_uid": "f45c769556ac3f408f5542fa71a67d98"} {"nl": {"description": "The Fair Nut lives in $$$n$$$ story house. $$$a_i$$$ people live on the $$$i$$$-th floor of the house. Every person uses elevator twice a day: to get from the floor where he/she lives to the ground (first) floor and to get from the first floor to the floor where he/she lives, when he/she comes back home in the evening. It was decided that elevator, when it is not used, will stay on the $$$x$$$-th floor, but $$$x$$$ hasn't been chosen yet. When a person needs to get from floor $$$a$$$ to floor $$$b$$$, elevator follows the simple algorithm: Moves from the $$$x$$$-th floor (initially it stays on the $$$x$$$-th floor) to the $$$a$$$-th and takes the passenger. Moves from the $$$a$$$-th floor to the $$$b$$$-th floor and lets out the passenger (if $$$a$$$ equals $$$b$$$, elevator just opens and closes the doors, but still comes to the floor from the $$$x$$$-th floor). Moves from the $$$b$$$-th floor back to the $$$x$$$-th. The elevator never transposes more than one person and always goes back to the floor $$$x$$$ before transposing a next passenger. The elevator spends one unit of electricity to move between neighboring floors. So moving from the $$$a$$$-th floor to the $$$b$$$-th floor requires $$$|a - b|$$$ units of electricity.Your task is to help Nut to find the minimum number of electricity units, that it would be enough for one day, by choosing an optimal the $$$x$$$-th floor. Don't forget than elevator initially stays on the $$$x$$$-th floor. ", "input_spec": "The first line contains one integer $$$n$$$ ($$$1 \\leq n \\leq 100$$$)\u00a0\u2014 the number of floors. The second line contains $$$n$$$ integers $$$a_1, a_2, \\ldots, a_n$$$ ($$$0 \\leq a_i \\leq 100$$$)\u00a0\u2014 the number of people on each floor.", "output_spec": "In a single line, print the answer to the problem\u00a0\u2014 the minimum number of electricity units.", "sample_inputs": ["3\n0 2 1", "2\n1 1"], "sample_outputs": ["16", "4"], "notes": "NoteIn the first example, the answer can be achieved by choosing the second floor as the $$$x$$$-th floor. Each person from the second floor (there are two of them) would spend $$$4$$$ units of electricity per day ($$$2$$$ to get down and $$$2$$$ to get up), and one person from the third would spend $$$8$$$ units of electricity per day ($$$4$$$ to get down and $$$4$$$ to get up). $$$4 \\cdot 2 + 8 \\cdot 1 = 16$$$.In the second example, the answer can be achieved by choosing the first floor as the $$$x$$$-th floor."}, "positive_code": [{"source_code": "r=0;[*$<][1].split.each_with_index{|e,i|r+=4*e.to_i*i};p r"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nans = 10**9\nfor i in 0..n\n ret = 0\n for j in 0..n-1\n ret += ((j-i).abs+j+i)*a[j]*2\n end\n ans = ret if ans > ret\nend\nputs ans"}], "negative_code": [{"source_code": "n,s,*v=$<.read.split.map &:to_i\np [[(v.reduce(:+)-s)/n,*v].min,-1].max"}], "src_uid": "a5002ddf9e792cb4b4685e630f1e1b8f"} {"nl": {"description": "The protection of a popular program developed by one of IT City companies is organized the following way. After installation it outputs a random five digit number which should be sent in SMS to a particular phone number. In response an SMS activation code arrives.A young hacker Vasya disassembled the program and found the algorithm that transforms the shown number into the activation code. Note: it is clear that Vasya is a law-abiding hacker, and made it for a noble purpose \u2014 to show the developer the imperfection of their protection.The found algorithm looks the following way. At first the digits of the number are shuffled in the following order <first digit><third digit><fifth digit><fourth digit><second digit>. For example the shuffle of 12345 should lead to 13542. On the second stage the number is raised to the fifth power. The result of the shuffle and exponentiation of the number 12345 is 455\u00a0422\u00a0043\u00a0125\u00a0550\u00a0171\u00a0232. The answer is the 5 last digits of this result. For the number 12345 the answer should be 71232.Vasya is going to write a keygen program implementing this algorithm. Can you do the same?", "input_spec": "The only line of the input contains a positive integer five digit number for which the activation code should be found.", "output_spec": "Output exactly 5 digits without spaces between them \u2014 the found activation code of the program.", "sample_inputs": ["12345"], "sample_outputs": ["71232"], "notes": null}, "positive_code": [{"source_code": "s=gets;s=[0,2,4,3,1].map{|e|s[e]}*'';printf(\"%05d\\n\",(s.to_i**5)%100000)"}, {"source_code": "s=gets;s=[0,2,4,3,1].map{|e|s[e]}*'';puts'%05d'%[s.to_i**5%100000]"}, {"source_code": "code = gets.chomp\ncode = (code[0] + code[2] + code[4] + code[3] + code[1])\nputs (code.to_i ** 5).to_s.chars.last(5).join\n"}, {"source_code": "code = gets.chomp\nputs ((code[0] + code[2] + code[4] + code[3] + code[1]).to_i ** 5).to_s.chars.last(5).join\n"}], "negative_code": [{"source_code": "s=gets;s=[0,2,4,3,1].map{|e|s[e]}*'';p (s.to_i**5)%100000"}, {"source_code": "code = gets.chomp\nputs ((code[0] + code[2] + code[4] + code[3] + code[1]).to_i ** 5)%100000\n"}, {"source_code": "puts 'Enter number'\ncode = gets.chomp\nreturn unless code.length == 5\ncode = (code[0] + code[2] + code[4] + code[3] + code[1])\nputs (code.to_i ** 5).to_s.chars.last(5).join\n"}], "src_uid": "51b1c216948663fff721c28d131bf18f"} {"nl": {"description": "So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two \"New Year and Christmas Men\" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. One night, when everyone went to bed, someone took all the letters of our characters' names. Then he may have shuffled the letters and put them in one pile in front of the door.The next morning it was impossible to find the culprit who had made the disorder. But everybody wondered whether it is possible to restore the names of the host and his guests from the letters lying at the door? That is, we need to verify that there are no extra letters, and that nobody will need to cut more letters.Help the \"New Year and Christmas Men\" and their friends to cope with this problem. You are given both inscriptions that hung over the front door the previous night, and a pile of letters that were found at the front door next morning.", "input_spec": "The input file consists of three lines: the first line contains the guest's name, the second line contains the name of the residence host and the third line contains letters in a pile that were found at the door in the morning. All lines are not empty and contain only uppercase Latin letters. The length of each line does not exceed 100.", "output_spec": "Print \"YES\" without the quotes, if the letters in the pile could be permuted to make the names of the \"New Year and Christmas Men\". Otherwise, print \"NO\" without the quotes.", "sample_inputs": ["SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS", "PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI", "BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER"], "sample_outputs": ["YES", "NO", "NO"], "notes": "NoteIn the first sample the letters written in the last line can be used to write the names and there won't be any extra letters left.In the second sample letter \"P\" is missing from the pile and there's an extra letter \"L\".In the third sample there's an extra letter \"L\"."}, "positive_code": [{"source_code": "s1 = gets.chomp\ns2 = gets.chomp\ns3 = gets.chomp\nif (s1 + s2).split(//).sort.join == s3.split(//).sort.join\n puts \"YES\"\nelse\n puts \"NO\"\nend\n"}, {"source_code": "hs = Hash.new 0\ngets.chomp.split(//).map{|x| hs[x]+=1}\ngets.chomp.split(//).map{|x| hs[x]+=1}\ngets.chomp.split(//).map{|x| hs[x]-=1}\nif hs.any?{|_,v| v!=0}\n puts \"NO\"\nelse\n puts \"YES\"\nend"}, {"source_code": "\t\n\nfirst = gets.strip\nlast = gets.strip\nall = first + last\nfull = gets.strip\n\na = 'A'.ord\n\narr = Array.new(26,0)\n\nfull.split(\"\").each do |c|\n\tarr[c.ord-a] += 1\nend\n\n\nall.split(\"\").each do |i|\n\tif arr[i.ord - a] <= 0\n\t\tputs \"NO\"\n\t\texit\n\tend\n\n\tarr[i.ord - a ] -= 1\n\nend\n\nans = arr.minmax\n\nif ans[0] != 0 or ans[1] != 0\n\tputs \"NO\"\nelse\n\tputs \"YES\"\nend\n\n\n\n\n\n"}, {"source_code": "r = lambda { gets.strip.chars.sort }\nputs (r.call + r.call).sort == r.call ? :YES : :NO\n"}, {"source_code": "s1 = gets.chomp\ns2 = gets.chomp\ns = gets.chomp\np = s1.split(\"\") + s2.split(\"\")\ns1 = s1.delete(s)\ns2 = s2.delete(s)\nif s1.empty? && s2.empty? && p.size == s.size then\n p.size.times do |i|\n s = s.sub(p[i], \"\")\n end\n if s.empty? then\n puts \"YES\"\n else\n puts \"NO\"\n end\nelse\n puts \"NO\"\nend"}, {"source_code": "s1 = gets.chomp\ns1 += gets.chomp\ns2 = gets.chomp\nif s1.split(\"\").sort == s2.split(\"\").sort\n puts \"YES\"\nelse\n puts \"NO\"\nend\n"}, {"source_code": "a = gets.scan /\\w/ \nb = gets.scan /\\w/ \nc = gets.scan /\\w/ \n\nif (a.size+b.size) != c.size \n puts \"NO\" \nelse \n a = a + b \n if(a.sort == c.sort) \n puts \"YES\" \n else \n puts \"NO\" \n end \nend "}, {"source_code": "puts (gets+gets).chars.sort == (gets+\"\\n\").chars.sort ? :YES : :NO\n"}, {"source_code": "puts ((gets.split[0]+gets.split[0]).bytes.to_a.sort==gets.split[0].bytes.to_a.sort)?\"YES\":\"NO\" "}, {"source_code": "def read_line\n STDIN.gets.chomp\nend\n\ns1 = read_line\ns2 = read_line\ns3 = read_line\n\nif (s1+s2).each_char.sort == s3.each_char.sort \n puts \"YES\"\nelse \n puts \"NO\" \nend"}, {"source_code": "name1 = gets.chomp\nname2 = gets.chomp\nletters = gets.chomp\n\nif (name1 + name2).split(//).sort == letters.split(//).sort\n puts \"YES\"\nelse\n puts \"NO\"\nend\n"}, {"source_code": "name1 = gets.chomp\nname2 = gets.chomp\nletters = gets.chomp\n\nif (name1 + name2).split(//).sort.join == letters.split(//).sort.join\n puts \"YES\"\nelse\n puts \"NO\"\nend"}, {"source_code": "(STDIN.readline.chomp + STDIN.readline.chomp).chars.sort.join == STDIN.readline.chomp.chars.sort.join ? (puts \"YES\") : (puts \"NO\")"}, {"source_code": "a = gets.chomp\nb = gets.chomp\n\n$x = []\n\ndef addToList s\n s.chars do |i|\n $x << i\n end\nend\n\naddToList a\naddToList b\n\nc = gets.chomp\nc.chars do |i|\n d = $x.delete_at ($x.index(i) || $x.count)\n if d == nil\n puts \"NO\"\n exit\n end\nend\n\nif $x.count != 0 then puts \"NO\" else puts \"YES\" end\n\n"}, {"source_code": "#!/usr/bin/env ruby\n\na = $stdin.readline\nb = $stdin.readline\nboth = $stdin.readline\n\na1 = (a+b).split('').sort\na2 = both.split('').sort\n\na1.delete(\"\\n\")\na2.delete(\"\\n\")\n\nif a1 == a2\n\tputs \"YES\"\nelse\n\tputs \"NO\"\nend\n"}, {"source_code": "string1 = gets.chomp\nstring2 = gets.chomp\nstring3 = gets.chomp\n\nif string3.length - string2.length - string1.length != 0 then\n puts \"NO\"\nelse\n string3.split(\"\").each do |c|\n if string1.include? c then\n string1.sub!(c, '')\n elsif string2.include? c then\n string2.sub!(c, '')\n end\n end\n\n if string1.empty? and string2.empty? then\n puts \"YES\"\n else\n puts \"NO\"\n end\nend\n"}, {"source_code": "originalName = (gets.split(//)+gets.split(//)).sort\nnewName = gets.split(//).sort\noriginalName.delete_if{|element| !element.between?('A', 'Z')}\nnewName.delete_if{|element| !element.between?('A', 'Z')}\nif originalName==newName\n puts \"YES\"\nelse\n puts \"NO\"\nend"}, {"source_code": "puts (gets+gets).chars.sort==(gets+\"\\n\").chars.sort ? :YES :\"NO\""}, {"source_code": "def check_pile(sa, sb, lf)\n freq_ab = Hash.new(0)\n sa.each_char {|c| freq_ab[c] += 1}\n sb.each_char {|c| freq_ab[c] += 1}\n\n # If any of the letters counted from the words is greater or less than 0,\n # it means that there are missing chars or more than expected\n # 0< Non existent characters\n # 0< More characters than expected\n # 0> Missing characters\n lf.each_char {|c| freq_ab[c] -= 1}\n freq_ab.each_value do |v|\n if v == 0\n next\n else\n return \"NO\"\n end\n end\n \"YES\"\nend\n\nstring_a = gets.chomp\nstring_b = gets.chomp\nletters_found = gets.chomp\n\nputs check_pile(string_a, string_b, letters_found)\n"}, {"source_code": "text1 = gets.chomp\ntext2 = gets.chomp\ntext = (text1 + text2).split('').sort.join\njoke = gets.chomp.split('').sort.join\nif text == joke\n\tputs \"YES\"\nelse\n\tputs \"NO\"\nend\n\n"}, {"source_code": "puts ( (gets.chomp + gets.chomp).chars.sort.join == gets.chomp.chars.sort.join ? \"YES\" : \"NO\" )"}, {"source_code": "s1, s2, a = gets.strip, gets.strip, gets.strip\nputs (s1 + s2).split('').sort == a.split('').sort ? \"YES\" : \"NO\""}, {"source_code": "a = gets.chomp\nb = gets.chomp\nt = gets.chomp\n\nif (a+b).split('').sort == t.split('').sort\n puts \"YES\"\nelse\n puts \"NO\"\nend"}, {"source_code": "s = Array.new(3)\nfor i in 0..2\n s[i] = gets.chomp.to_s.split(//).sort\nend\n\nif (s[0] + s[1]).sort == s[2].sort\n puts \"YES\"\nelse\n puts \"NO\"\nend\n"}, {"source_code": "s = Array.new(3)\nfor i in 0..2\n s[i] = gets.chomp.to_s.split(//)\nend\n\nans = false\nif (s[0] + s[1]).sort == s[2].sort\n ans = true\nend\n\nputs ans ? \"YES\" : \"NO\""}, {"source_code": "a = $stdin.readline.scan(/./)\nb = $stdin.readline.scan(/./)\nc = $stdin.readline.scan(/./)\n\nt = a+b\n\nputs (t.sort == c.sort) ? \"YES\" : \"NO\""}, {"source_code": "can=true\na=gets.chomp\nb=gets.chomp\nc=gets.chomp\ni=0\nwhile i c.sort) == 0 ? 'YES' : 'NO'"}, {"source_code": "#!/usr/bin/ruby\n# coding: utf-8\n\nguest = $stdin.gets.chomp\nhost = $stdin.gets.chomp\npile = $stdin.gets.chomp\nif (guest + host).chars.sort == pile.chars.sort\n puts 'YES'\nelse\n puts 'NO'\nend\n"}, {"source_code": "str=gets;str<0}.size > 0\n puts \"NO\"\n else\n puts \"YES\"\n end\nend\n\n\namusing_joke"}, {"source_code": "name1 = gets.chomp\nname1 = name1.split(\"\")\nname2 = gets.chomp\nname2 = name2.split(\"\")\nletters = gets.chomp\nletters = letters.split(\"\")\n\nif name1.size + name2.size > letters.size\n\tprint \"NO\"\nelse\n\tcount = 0\n\tfor i in (0..name1.size-1)\n\t\tfor x in (0..letters.size-1)\n\t\t\tif name1[i] == letters[x]\n\t\t\t\tcount += 1\n\t\t\t\tletters.delete_at(x)\n\t\t\t\tbreak\n\t\t\tend\n\t\tend\n\tend\n\tfor i in (0..name2.size-1)\n\t\tfor x in (0..letters.size-1)\n\t\t\tif name2[i] == letters[x]\n\t\t\t\tcount += 1\n\t\t\t\tletters.delete_at(x)\n\t\t\t\tbreak\n\t\t\tend\n\t\tend\n\tend\n\tif count == name1.size + name2.size && letters.size == 0\n\t\tprint \"YES\"\n\telse\n\t\tprint \"NO\"\n\tend\nend\n"}, {"source_code": "n = gets.chomp\nm = gets.chomp\nl = gets.chomp\nputs (n + m).chars.sort == l.chars.sort ? 'YES' : 'NO'\n"}, {"source_code": "a = gets.chomp.chars + gets.chomp.chars\ns = gets.chomp.chars\nans = true\nif a.size != s.size\n ans = false\nelse\n a.size.times do |i|\n if s.index(a[i])\n s[s.index(a[i])] = nil\n else\n ans = false\n end\n end\nend\nputs ans ? \"YES\" : \"NO\"\n"}, {"source_code": "a = gets.chomp.chars + gets.chomp.chars\ns = gets.chomp.chars\nans = true\nif a.size != s.size\n ans = false\nelse\n a.size.times do |i|\n note = 0\n s.size.times do |j|\n if a[i] == s[j]\n s[j] = \" \"\n note = 1\n break\n end\n end\n if note != 1\n ans = false\n break\n end\n end\nend\nputs ans ? \"YES\" : \"NO\"\n"}, {"source_code": "a = gets.chomp.chars + gets.chomp.chars\nb = gets.chomp.chars\nputs a.sort == b.sort ? \"YES\" : \"NO\"\n"}, {"source_code": "a = gets.chomp.chars + gets.chomp.chars\ns = gets.chomp.chars\nans = true\nif a.size != s.size\n ans = false\nelse\n a.each do |x|\n idx = s.index(x)\n if idx\n s[idx] = nil\n else\n ans = false\n end\n end\nend\nputs ans ? \"YES\" : \"NO\"\n"}, {"source_code": "puts (gets.chomp + gets.chomp).chars.sort == gets.chomp.chars.sort ? \"YES\" : \"NO\"\n"}, {"source_code": "h = Hash.new(0)\ngets.chomp.each_char{|c| h[c] += 1}\ngets.chomp.each_char{|c| h[c] += 1}\ngets.chomp.each_char{|c| h[c] -= 1}\nputs h.values.all?{|v|v == 0} ? \"YES\" : \"NO\"\n#p h\n"}, {"source_code": "expected = (gets.chomp + gets.chomp).chars.sort.join\nactual = (gets.chomp).chars.sort.join\nif expected == actual\n puts \"YES\"\nelse\n puts \"NO\"\nend\n"}, {"source_code": "a=[]\n2.times do\na=a+gets.chomp.split(\"\")\nend\na.sort!\nc=gets.chomp.split(\"\")\nc.sort!\nif a==c\nputs \"YES\"\nelse \nputs \"NO\"\nend"}, {"source_code": "puts (gets+gets).chars.sort==(gets+\"\\n\").chars.sort ? :YES :\"NO\""}, {"source_code": "puts (gets.chomp.chars + gets.chomp.chars).sort == gets.chomp.chars.sort ? 'YES' : 'NO'\n"}, {"source_code": "guest = gets.chomp.split \"\"\nhost = gets.chomp.split \"\"\n\nresult = guest.inject(Hash.new(0)) { |h, v| h[v] += 1; h }\nresult = host.inject(result) { |h, v| h[v] += 1; h }\n\nanswer = gets.chomp.split \"\"\n\nfor i in answer\n result[i] -= 1\nend\n\n\na = true\n\nresult.each do |k, v|\n a &= v == 0\n\n break unless a\nend\n\nputs a ? \"YES\" : \"NO\"\n"}, {"source_code": "#!/usr/bin/env ruby\n\n$ma = {}\n$ma.default = 0\n\ngets.strip.split('').each { |c| $ma[c]+=1 }\ngets.strip.split('').each { |c| $ma[c]+=1 }\ngets.strip.split('').each { |c| $ma[c]-=1 }\n\nflag = true;\n$ma.each { |c,d|\n flag = false if d!=0\n}\n\nputs (flag ? \"YES\" : \"NO\")\n"}, {"source_code": "def g\n gets.chomp.split(\"\").sort.join\nend\nputs (g+g).split(\"\").sort.join.eql?(g)?\"YES\":\"NO\""}, {"source_code": "a,b,c=3.times.map{gets.chomp.bytes.to_a}\nputs (a+b).sort==c.sort ? \"YES\" : \"NO\""}, {"source_code": "a, b, c = STDIN.read.split(\"\\n\")\nprint (a + b).split(//).sort == c.split(//).sort ? :YES : :NO\n"}], "negative_code": [{"source_code": "h = Hash.new\nh.default = 0\n3.times do |i|\n s = gets.chop.each_char.to_a\n if i < 2\n s.each { |c| h[c] += 1 }\n else\n s.each { |c| h[c] -= 1 }\n end\nend\n\nif h.any? { |k, v| v < 0 }\n puts :NO\nelse\n puts :YES\nend\n"}, {"source_code": "a = []\n3.times do |i|\n a[i] = gets.chop.each_char.to_a.sort.uniq\nend\na[2] -= a[0] + a[1]\nif a[2].empty?\n puts :YES\nelse\n puts :NO\nend\n"}, {"source_code": "s1 = gets.chomp\ns2 = gets.chomp\ns = gets.chomp\ns = s.gsub(s1, \"\").gsub(s2, \"\")\n\nif s.empty? then\n puts \"YES\"\nelse\n puts \"NO\"\nend"}, {"source_code": "s1 = gets.chomp\ns2 = gets.chomp\ns = gets.chomp\np = s1.split(\"\") + s2.split(\"\")\ns1.delete(s)\ns2.delete(s)\nif s1.empty? && s2.empty? then\n p.size.times do |i|\n s = s.sub(p[i], \"\")\n end\n\n if s.empty? then\n puts \"YES\"\n else\n puts \"NO\"\n end\nelse\n puts \"NO\"\nend"}, {"source_code": "s1 = gets.chomp.split(\"\")\ns2 = gets.chomp.split(\"\")\ns = gets.chomp\np = s1 + s2\np.size.times do |i|\n s = s.sub(p[i], \"\")\nend\n\nif s.empty? then\n puts \"YES\"\nelse\n puts \"NO\"\nend"}, {"source_code": "s1 = gets.chomp\ns2 = gets.chomp\ns = gets.chomp\np = s1.split(\"\") + s2.split(\"\")\ns1 = s1.delete(s)\ns2 = s2.delete(s)\nif s1.empty? && s2.empty? then\n p.size.times do |i|\n s = s.sub(p[i], \"\")\n end\n\n if s.empty? then\n puts \"YES\"\n else\n puts \"NO\"\n end\nelse\n puts \"NO\"\nend"}, {"source_code": "s1 = gets.chomp\ns2 = gets.chomp\ns = gets.chomp\ns = s.gsub(s1, \"\")\ns = s.gsub(s2, \"\")\n\nif s.empty? then\n puts \"YES\"\nelse\n puts \"NO\"\nend"}, {"source_code": "def read_line\n STDIN.gets.chomp\nend\n\ns1 = read_line\ns2 = read_line\ns3 = read_line\n\nans = \"YES\"\ns3.length.times do |i|\n c = s3[i]\n ans = \"NO\" if s1.count(c) + s2.count(c) != s3.count(c)\nend\n\nputs ans\n \n\n"}, {"source_code": "name1 = gets.chomp\nname2 = gets.chomp\nletters = gets.chomp\n\nif (name1 + name2).size == letters.size\n puts \"YES\"\nelse\n puts \"NO\"\nend"}, {"source_code": "name1 = gets.chomp\nname2 = gets.chomp\nletters = gets.chomp\n\nif (name1 + name2).size == letters.size\n puts \"YES\"\nelse\n puts \"NO\"\nend\n"}, {"source_code": " x = gets.chomp\n y = gets.chomp\n z = gets.chomp\n\n hash_x = {}\n hash_y = {}\n hash_z = {}\n\n x.each_char { |c|\n hash_x[c] = 0 if hash_x[c] == nil\n hash_x[c] += 1\n }\n\n y.each_char { |c|\n hash_y[c] = 0 if hash_y[c] == nil\n hash_y[c] += 1\n }\n\n z.each_char { |c|\n hash_z[c] = 0 if hash_z[c] == nil\n hash_z[c] += 1\n }\n\n flag = true\n hash_z.each { |k,v|\n if v != (hash_x[k] == nil ? 0 : hash_x[k]) + (hash_y[k] == nil ? 0 : hash_y[k])\n flag = false\n end\n }\n if flag\n puts \"YES\"\n else\n puts \"NO\"\n end"}, {"source_code": " x = gets.chomp\n y = gets.chomp\n z = gets.chomp\n\n hash_x = {}\n hash_z = {}\n\n x.each_char { |c|\n hash_x[c] = 0 if hash_x[c] == nil\n hash_x[c] += 1\n }\n\n y.each_char { |c|\n hash_x[c] = 0 if hash_x[c] == nil\n hash_x[c] += 1\n }\n\n z.each_char { |c|\n hash_z[c] = 0 if hash_z[c] == nil\n hash_z[c] += 1\n }\n\n flag = true\n hash_x.each { |k,v|\n if v != (hash_z[k] == nil ? 0 : hash_z[k])\n flag = false\n end\n }\n if flag\n puts \"YES\"\n else\n puts \"NO\"\n end"}, {"source_code": " x = gets.chomp\n y = gets.chomp\n z = gets.chomp\n\n hash_x = {}\n hash_z = {}\n\n x.each_char { |c|\n hash_x[c] = 0 if hash_x[c] == nil\n hash_x[c] += 1\n }\n\n y.each_char { |c|\n hash_x[c] = 0 if hash_x[c] == nil\n hash_x[c] += 1\n }\n\n z.each_char { |c|\n hash_z[c] = 0 if hash_z[c] == nil\n hash_z[c] += 1\n }\n\n flag = true\n if z.length == x.length + y.length\n hash_x.each { |k,v|\n if v != (hash_z[k] == nil ? 0 : hash_z[k])\n flag = false\n end\n }\n end\n if flag\n puts \"YES\"\n else\n puts \"NO\"\n end"}, {"source_code": "a = gets.chomp.split('')\nb = gets.chomp.split('')\nc = gets.chomp.split('')\nletters = Hash.new(0)\na.each { |e| letters[e] += 1 }\nb.each { |e| letters[e] += 1 }\nc.each { |e| letters[e] -= 1 }\nputs letters.values.count { |e| e > 0 } == 0 ? \"YES\" : \"NO\"\n"}, {"source_code": "guest = gets.chomp.split \"\"\nhost = gets.chomp.split \"\"\n\nresult = guest.inject(Hash.new(0)) { |h, v| h[v] += 1; h }\nresult = host.inject(result) { |h, v| h[v] += 1; h }\n\nanswer = gets.chomp.split \"\"\n\na = true\nfor i in answer\n result[i] -= 1\n\n a = false if result[i] < 0\nend\n\nputs a ? \"YES\" : \"NO\"\n"}], "src_uid": "b6456a39d38fabcd25267793ed94d90c"} {"nl": {"description": "Alice has a string $$$s$$$. She really likes the letter \"a\". She calls a string good if strictly more than half of the characters in that string are \"a\"s. For example \"aaabb\", \"axaa\" are good strings, and \"baca\", \"awwwa\", \"\" (empty string) are not.Alice can erase some characters from her string $$$s$$$. She would like to know what is the longest string remaining after erasing some characters (possibly zero) to get a good string. It is guaranteed that the string has at least one \"a\" in it, so the answer always exists.", "input_spec": "The first line contains a string $$$s$$$ ($$$1 \\leq |s| \\leq 50$$$) consisting of lowercase English letters. It is guaranteed that there is at least one \"a\" in $$$s$$$.", "output_spec": "Print a single integer, the length of the longest good string that Alice can get after erasing some characters from $$$s$$$.", "sample_inputs": ["xaxxxxa", "aaabaa"], "sample_outputs": ["3", "6"], "notes": "NoteIn the first example, it's enough to erase any four of the \"x\"s. The answer is $$$3$$$ since that is the maximum number of characters that can remain.In the second example, we don't need to erase any characters."}, "positive_code": [{"source_code": "s = readline.chomp\nputs [s.length, 2 * s.count(\"a\") - 1].min\n"}, {"source_code": "#!usr/bin/env ruby\n\n# https://codeforces.com/problemset/problem/1146/A\n\nword = gets.chomp\nword_len = word.size\na_count = word.count('a')\n\nif word_len / 2 < a_count\n puts word_len\nelse\n puts 2 * a_count - 1\nend\n"}, {"source_code": "s = gets.chomp\np (s.length+1)/2 < s.count(\"a\") ? s.length : s.count(\"a\")*2-1"}, {"source_code": "s = gets.chomp\nac = s.count('a')\nputs [s.size, ac*2-1].min"}, {"source_code": "def love(s)\n\twhile \"love\" == \"love\"\n\t\ta = s.scan('a').length\n\t\tothers = s.scan(/[b-z]/).length\n\t\tif a > others then return s.length else s = s.sub(/[b-z]/, '') end\n\tend\nend\n\ns = gets.chomp\nputs(love(s))"}, {"source_code": "s = gets.chomp\nacnt = s.count(\"a\")\nif acnt > s.length / 2 then\n\tputs s.length\nelse\n\tputs 2 * acnt - 1\nend\n\n"}, {"source_code": "s = gets\nn = s.count 'a'\nputs [s.size, 2*n].min - 1"}], "negative_code": [], "src_uid": "84cb9ad2ae3ba7e912920d7feb4f6219"} {"nl": {"description": "The cows have just learned what a primitive root is! Given a prime p, a primitive root is an integer x (1\u2009\u2264\u2009x\u2009<\u2009p) such that none of integers x\u2009-\u20091,\u2009x2\u2009-\u20091,\u2009...,\u2009xp\u2009-\u20092\u2009-\u20091 are divisible by p, but xp\u2009-\u20091\u2009-\u20091 is. Unfortunately, computing primitive roots can be time consuming, so the cows need your help. Given a prime p, help the cows find the number of primitive roots .", "input_spec": "The input contains a single line containing an integer p (2\u2009\u2264\u2009p\u2009<\u20092000). It is guaranteed that p is a prime.", "output_spec": "Output on a single line the number of primitive roots .", "sample_inputs": ["3", "5"], "sample_outputs": ["1", "2"], "notes": "NoteThe only primitive root is 2.The primitive roots are 2 and 3."}, "positive_code": [{"source_code": "$a = Array.new(2001, 0)\n\ndef gcd(x, y)\n if y == 0\n return x\n end\n return gcd(y, x%y)\nend\n\ndef phi(n)\n if $a[n] == 0\n for i in 1..n\n\t if gcd(n, i) == 1\n\t $a[n] += 1\n\t end\n\tend\n end\n return $a[n]\nend\n\np = gets.to_i\nprint phi(phi(p))"}, {"source_code": "#!/usr/bin/ruby1.9\n\nanswers = {2=>1, 3=>1, 5=>2, 7=>2, 11=>4, 13=>4, 17=>8, 19=>6, 23=>10, 29=>12, 31=>8, 37=>12, 41=>16, 43=>12, 47=>22, 53=>24, 59=>28, 61=>16, 67=>20, 71=>24, 73=>24, 79=>24, 83=>40, 89=>40, 97=>32, 101=>40, 103=>32, 107=>52, 109=>36, 113=>48, 127=>36, 131=>48, 137=>64, 139=>44, 149=>72, 151=>40, 157=>48, 163=>54, 167=>82, 173=>84, 179=>88, 181=>48, 191=>72, 193=>64, 197=>84, 199=>60, 211=>48, 223=>72, 227=>112, 229=>72, 233=>112, 239=>96, 241=>64, 251=>100, 257=>128, 263=>130, 269=>132, 271=>72, 277=>88, 281=>96, 283=>92, 293=>144, 307=>96, 311=>120, 313=>96, 317=>156, 331=>80, 337=>96, 347=>172, 349=>112, 353=>160, 359=>178, 367=>120, 373=>120, 379=>108, 383=>190, 389=>192, 397=>120, 401=>160, 409=>128, 419=>180, 421=>96, 431=>168, 433=>144, 439=>144, 443=>192, 449=>192, 457=>144, 461=>176, 463=>120, 467=>232, 479=>238, 487=>162, 491=>168, 499=>164, 503=>250, 509=>252, 521=>192, 523=>168, 541=>144, 547=>144, 557=>276, 563=>280, 569=>280, 571=>144, 577=>192, 587=>292, 593=>288, 599=>264, 601=>160, 607=>200, 613=>192, 617=>240, 619=>204, 631=>144, 641=>256, 643=>212, 647=>288, 653=>324, 659=>276, 661=>160, 673=>192, 677=>312, 683=>300, 691=>176, 701=>240, 709=>232, 719=>358, 727=>220, 733=>240, 739=>240, 743=>312, 751=>200, 757=>216, 761=>288, 769=>256, 773=>384, 787=>260, 797=>396, 809=>400, 811=>216, 821=>320, 823=>272, 827=>348, 829=>264, 839=>418, 853=>280, 857=>424, 859=>240, 863=>430, 877=>288, 881=>320, 883=>252, 887=>442, 907=>300, 911=>288, 919=>288, 929=>448, 937=>288, 941=>368, 947=>420, 953=>384, 967=>264, 971=>384, 977=>480, 983=>490, 991=>240, 997=>328, 1009=>288, 1013=>440, 1019=>508, 1021=>256, 1031=>408, 1033=>336, 1039=>344, 1049=>520, 1051=>240, 1061=>416, 1063=>348, 1069=>352, 1087=>360, 1091=>432, 1093=>288, 1097=>544, 1103=>504, 1109=>552, 1117=>360, 1123=>320, 1129=>368, 1151=>440, 1153=>384, 1163=>492, 1171=>288, 1181=>464, 1187=>592, 1193=>592, 1201=>320, 1213=>400, 1217=>576, 1223=>552, 1229=>612, 1231=>320, 1237=>408, 1249=>384, 1259=>576, 1277=>560, 1279=>420, 1283=>640, 1289=>528, 1291=>336, 1297=>432, 1301=>480, 1303=>360, 1307=>652, 1319=>658, 1321=>320, 1327=>384, 1361=>512, 1367=>682, 1373=>588, 1381=>352, 1399=>464, 1409=>640, 1423=>468, 1427=>660, 1429=>384, 1433=>712, 1439=>718, 1447=>480, 1451=>560, 1453=>440, 1459=>486, 1471=>336, 1481=>576, 1483=>432, 1487=>742, 1489=>480, 1493=>744, 1499=>636, 1511=>600, 1523=>760, 1531=>384, 1543=>512, 1549=>504, 1553=>768, 1559=>720, 1567=>504, 1571=>624, 1579=>524, 1583=>672, 1597=>432, 1601=>640, 1607=>720, 1609=>528, 1613=>720, 1619=>808, 1621=>432, 1627=>540, 1637=>816, 1657=>528, 1663=>552, 1667=>672, 1669=>552, 1693=>552, 1697=>832, 1699=>564, 1709=>720, 1721=>672, 1723=>480, 1733=>864, 1741=>448, 1747=>576, 1753=>576, 1759=>584, 1777=>576, 1783=>540, 1787=>828, 1789=>592, 1801=>480, 1811=>720, 1823=>910, 1831=>480, 1847=>840, 1861=>480, 1867=>620, 1871=>640, 1873=>576, 1877=>792, 1879=>624, 1889=>928, 1901=>720, 1907=>952, 1913=>952, 1931=>768, 1933=>528, 1949=>972, 1951=>480, 1973=>896, 1979=>924, 1987=>660, 1993=>656, 1997=>996, 1999=>648}\n\nx = STDIN.readline.to_i\nputs answers[x]\n\n"}, {"source_code": "n=gets.to_i\nk,s=0,0\nfor i in 1...n\n\ts=1\n\tfor j in 1...n\n\t\ts*=i\n\t\ts%=n\n\t\tif (s-1)%n==0\n\t\t\tif j==n-1\n\t\t\t\tk+=1\n\t\t\telse\n\t\t\t\tbreak\n\t\t\tend\n\t\tend\n\tend\nend\nputs k"}, {"source_code": "def check(i, n)\n x = i\n (n - 2).times do\n return 0 if x == 1\n x = (x * i) % n\n end\n x == 1 ? 1 : 0\nend\n\ndef run\n n = $stdin.gets.to_i\n count = 0\n for i in 1...n\n count += check(i, n)\n end\n puts count\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "x = gets.split.map{|_|_.to_i}\nans=0\nx[0].times{|id|\n i = id + 1\n r = true\n d = 1\n (x[0]-1).times{|j|\n d=(d*i)%x[0]\n if (j!=x[0]-2 && d == 1) || (j==x[0]-2 && d!=1) then\n r=false\n break\n end\n }\n ans+=1 if r\n}\nputs ans\n"}, {"source_code": "p = gets.strip.to_i\nans = 0\n(1...p).each do |x|\n found = true\n cur = 1\n (1...p).each do |y|\n cur *= x\n cur %= p\n if y == p - 1\n if cur != 1\n found = false\n break\n end\n elsif cur == 1\n found = false\n break\n end\n end\n ans += 1 if found\nend\nputs ans\n"}, {"source_code": "p=gets.to_i\nres=0\n1.upto(p-1) {|x|\n n=x;\n ok=true\n (p-2).times {\n if (n-1+p)%p==0\n ok=false\n break\n end\n n=n*x%p\n }\n ok=ok and (n*x-1)%p==0\n res+=1 if ok\n}\np res\n"}, {"source_code": "require 'prime'\n\ndef phi(n)\n d = Prime.prime_division(n)\n d.each { |r, e| n = n * (r - 1) / r }\n n\nend\n\ndef has_primitive_root?(n)\n return true if n == 1 || n == 2 || n == 4\n return false if n.to_s(2)[1..-1].chars.uniq == [?0] # power of 2 not allowed\n n /= 2 if n.even?\n (3..n).select { |r| Prime.prime?(r) && r**Math.log(r, n).to_i == n } .size > 0\nend\n\ndef number_of_primitive_roots(n)\n has_primitive_root?(n) ? phi(phi(n)) : 0\nend\n\np number_of_primitive_roots(gets.to_i)\n"}, {"source_code": "require 'prime'\n\ndef phi(n)\n d = Prime.prime_division(n)\n d.each { |r, e| n = n * (r - 1) / r }\n n\nend\n\ndef has_primitive_root?(n)\n return true if n == 1 || n == 2 || n == 4\n return false if n.to_s(2)[1..-1].chars.uniq == [?0] # power of 2 not allowed\n n /= 2 if n.even?\n (3..n).select { |r| Prime.prime?(r) && r**Math.log(r, n).to_i == n } .size > 0\nend\n\ndef primitive_roots(n)\n return [] unless has_primitive_root?(n)\n (1..n).select { |i| n.gcd(i) == 1 } .select do |g|\n pn = phi(n)\n d = Prime.prime_division(pn)\n d.none? { |r, e| g**(pn / r) % n == 1 }\n end\nend\n\np primitive_roots(gets.to_i).size\n"}, {"source_code": "# def generate_prime(n)\n# \tprimes = {}\n\n# \t(2..n).each do |a|\n# \t\tprimes[a] = true\t\n# \tend\n\n# \t(2..Math.sqrt(n)).each do |i|\n# \t\tif primes[i]\n# \t\t\tprimes[i] = true\n# \t\t\t(i**2..n).step(i).each do |j|\n# \t\t\t\tprimes[j] = false\n# \t\t\tend\n# \t\tend\n# \tend\t\n# \tprimes.select {|k,v| v == true}.keys\n# end\n# primes = generate_prime(2000)\ndef gcd(a,b)\n\tif b == 0 \n\t\treturn a\n\telse\n\t\tgcd(b,a%b)\n\tend\nend\n\nn = gets.to_i - 1\ncount = 0\n(1..n).each do |a|\n\tif gcd(a,n) == 1\n\t\tcount += 1 \n\tend\n\n\tbreak if a > n\nend\n\nputs count"}, {"source_code": "def is_root x,p\n\tn = 1;\n\tq = x;\n\t\n\twhile q%p!=1 and n= 12\nangle = []\nangle[0] = input[0] * 360/12 + input[1] * 360/12/60\nangle[1] = input[1] * 360/60\n\nputs angle.join ' '\n"}, {"source_code": "time=gets.split(\":\").map(&:to_i)\n\nh=((time[0]*60+time[1])%720)*360/720.0\nm=(time[1]*360/60)\nprintf \"%.10f %.10f\\n\",h,m\n\n"}, {"source_code": "time=gets.split(\":\").map(&:to_i)\n\nh=((time[0]*60+time[1])%720)*360/720.0\nm=(time[1]*360/60)\nputs h.to_s+\" \"+m.to_s\n#printf \"%.10f %.10f\\n\",h,m\n"}, {"source_code": "#!/usr/bin/ruby\n\nhh, mm = gets.split(':').map { |e| e.to_i }\n\ny = mm * 6\nx = (hh % 12 + mm.to_f / 60) * 30\nputs \"#{x} #{y}\"\n\n"}, {"source_code": "#!/usr/bin/ruby\n#http://codeforces.ru/contest/80/problem/B\n\ngets.split(':').map(&:to_i).tap{ |a| puts \"#{(a[0] % 12 + a[1].to_f / 60) * 30} #{a[1] * 6}\"}\n\n"}, {"source_code": "hour, minute = gets.split(\":\").map(&:to_i)\nprint (hour*30)%360 + minute/2\nprint \".5\" if minute%2 != 0\nprint \" \", minute*6"}, {"source_code": "# TEMPLATE BEGIN\ndef read_vector\n gets.chomp.split(/\\s+/)\nend\ndef read_vector_int\n read_vector.map(&:to_i)\nend\n# TEMPLATE END\n\nh, m = gets.chomp.split(':').map(&:to_f)\nh -= 12.0 if h >= 12.0\n\nhd = 360 * h / 12\nhd += (360 / 12) * m / 60\nmd = 360 * m / 60\nprint \"#{hd} #{md}\"\n"}, {"source_code": "h,m=gets.split(?:).map &:to_f;print h%12*30+m/2,\" \",m*6"}, {"source_code": "include Math\n\nH, M = gets.split(':').map{|e| e.to_i}\n\nH %= 12\nh = 360 / 12 * H + 360.0 / 12 / 60 * M\nm = 360.0 / 60 * M\n\nputs \"#{h} #{m}\"\n"}, {"source_code": "array = gets.split(/:/)\n\n h = array[0].to_f\n m = array[1].to_f\n\nif h >= 12\n h -= 12\nend\n\nh = 360 / 12 * h\n\nm = 360 / 60 * m\n\nh += 15 * m / 180\n\nprint h, \" \", m.to_i, \"\\n\"\n"}, {"source_code": "#=================================\n# Better be sure than sorry. \n#=================================\n$stdin=File.open(\"./input.txt\",\"r\") if ENV[\"LOGNAME\"]==\"skydos\"\n#=================================\n\nh, m=gets.split(':').map(&:to_i)\n\nh-=12 if h>=12\n\nmins_angl = m * 6.0\nhour_angl = h * (360.0/12.0) + m * (360.0/12.0/60.0)\n\nputs \"#{hour_angl} #{mins_angl}\"\n"}, {"source_code": "require 'time'\ntime = Time.parse(gets.strip)\nhour = time.hour\nhour -= 12 if hour >= 12\nminutes = time.min\nhour_angle = 30 * hour\nhour_angle += 0.5 * minutes\nif hour_angle - hour_angle.to_i == 0\n hour_angle = hour_angle.to_i\nend\nminutes_angle = 6 * minutes\nputs \"#{hour_angle} #{minutes_angle}\"\n"}, {"source_code": "t = STDIN.readline.chomp\nhour = Integer(t[0, 2], 10)\nmin = Integer(t[3, 2], 10)\n\nhour = hour + 12 if hour < 12\nhour_d = hour - 12\n\nputs \"#{(360.0 / 12.0) * hour_d + ((360.0 / 12.0) * (1.0 / (60.0 / min)))} #{360.0 / 60.0 * min}\"\n"}, {"source_code": "h,m=gets.split(?:).map(&:to_f)\nprint h%12*30+m/2,\" \",m*6"}, {"source_code": "hour, minute = gets.strip.split(':').map{|s| s.to_i}\no2 = minute / 60.0 * 360\nhour = hour % 12\no1 = (hour / 12.0 * 360) + (1 / 12.0 * o2)\nputs \"#{o1} #{o2}\"\n"}], "negative_code": [{"source_code": "#=================================\n# Better be sure than sorry. \n#=================================\n$stdin=File.open(\"./input.txt\",\"r\") if ENV[\"LOGNAME\"]==\"skydos\"\n#=================================\n\nh, m=gets.split(':').map(&:to_i)\n\nh-=12\n\nmins_angl = m * 6.0\nhour_angl = h * (360.0/12.0) + m * (360.0/12.0/60.0)\n\nputs \"#{hour_angl} #{mins_angl}\"\n"}, {"source_code": "#=================================\n# Better be sure than sorry. \n#=================================\n$stdin=File.open(\"./input.txt\",\"r\") if ENV[\"LOGNAME\"]==\"skydos\"\n#=================================\n\nh, m=gets.split(':').map(&:to_i)\n\nif h==12 && m==0\n\tputs \"0.0 0.0\"\n\texit\nend\n\nmins_angl = m * 6.0\nhour_angl = h * (360.0/12.0) + m * (360.0/12.0/60.0)\n\nputs \"#{hour_angl} #{mins_angl}\"\n"}], "src_uid": "175dc0bdb5c9513feb49be6644d0d150"} {"nl": {"description": "There are n students who have taken part in an olympiad. Now it's time to award the students.Some of them will receive diplomas, some wiil get certificates, and others won't receive anything. Students with diplomas and certificates are called winners. But there are some rules of counting the number of diplomas and certificates. The number of certificates must be exactly k times greater than the number of diplomas. The number of winners must not be greater than half of the number of all students (i.e. not be greater than half of n). It's possible that there are no winners.You have to identify the maximum possible number of winners, according to these rules. Also for this case you have to calculate the number of students with diplomas, the number of students with certificates and the number of students who are not winners.", "input_spec": "The first (and the only) line of input contains two integers n and k (1\u2009\u2264\u2009n,\u2009k\u2009\u2264\u20091012), where n is the number of students and k is the ratio between the number of certificates and the number of diplomas.", "output_spec": "Output three numbers: the number of students with diplomas, the number of students with certificates and the number of students who are not winners in case when the number of winners is maximum possible. It's possible that there are no winners.", "sample_inputs": ["18 2", "9 10", "1000000000000 5", "1000000000000 499999999999"], "sample_outputs": ["3 6 9", "0 0 9", "83333333333 416666666665 500000000002", "1 499999999999 500000000000"], "notes": null}, "positive_code": [{"source_code": "st = gets\ns = st.split[0].to_i\nk = st.split[1].to_i\nd = ( s / 2 ) / ( k + 1)\nputs \"#{d} #{d*k} #{s-d*(k+1)}\""}, {"source_code": "n,k=gets.split.map &:to_i\nm=n/2/-~k\np m,k*m,n-m*-~k"}, {"source_code": "n, k = gets.split\nn = n.to_i\nk = k.to_i\n\nd = n/(2*(k+1))\nc = d * k\n\nothers = n - (c + d)\n\nputs \"#{d} #{c} #{others}\""}, {"source_code": "n, k = gets.split.map(&:to_i)\nd = (n / (2 * (k + 1))).to_i\nc = k * d\nputs \"#{d} #{c} #{n-d-c}\""}], "negative_code": [{"source_code": "s = gets.to_i\nk = gets.to_i\nd = ( s / 2 ) / ( k + 1)\nputs \"#{d} #{d*k} #{s-d*(k+1)}\""}], "src_uid": "405a70c3b3f1561a9546910ab3fb5c80"} {"nl": {"description": "Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are \"a\", \"o\", \"u\", \"i\", and \"e\". Other letters are consonant.In Berlanese, there has to be a vowel after every consonant, but there can be any letter after any vowel. The only exception is a consonant \"n\"; after this letter, there can be any letter (not only a vowel) or there can be no letter at all. For example, the words \"harakiri\", \"yupie\", \"man\", and \"nbo\" are Berlanese while the words \"horse\", \"king\", \"my\", and \"nz\" are not.Help Vitya find out if a word $$$s$$$ is Berlanese.", "input_spec": "The first line of the input contains the string $$$s$$$ consisting of $$$|s|$$$ ($$$1\\leq |s|\\leq 100$$$) lowercase Latin letters.", "output_spec": "Print \"YES\" (without quotes) if there is a vowel after every consonant except \"n\", otherwise print \"NO\". You can print each letter in any case (upper or lower).", "sample_inputs": ["sumimasen", "ninja", "codeforces"], "sample_outputs": ["YES", "YES", "NO"], "notes": "NoteIn the first and second samples, a vowel goes after each consonant except \"n\", so the word is Berlanese.In the third sample, the consonant \"c\" goes after the consonant \"r\", and the consonant \"s\" stands on the end, so the word is not Berlanese."}, "positive_code": [{"source_code": "def is_consonant(c)\n c =~ /[^aeiou]/\nend\n\ndef is_bertlanese(word)\n next_must_be_vowel = false\n\n word.chars.each do |c|\n\n return false if next_must_be_vowel && is_consonant(c)\n\n next_must_be_vowel =\n c != ?a &&\n c != ?e &&\n c != ?i &&\n c != ?o &&\n c != ?u &&\n c != ?n\n end\n\n !next_must_be_vowel\nend\n\ndef solution\n word = read_string\n puts is_bertlanese(word) ? \"YES\" : \"NO\"\nend\n\n\ndef rest_int\n gets.to_i\nend\n\ndef read_ints\n gets.split.map &:to_i\nend\n\ndef read_string\n gets.chomp\nend\n\n\nsolution"}, {"source_code": "S = gets.chomp\nset1 = 'aeiou'.split('')\nset2 = set1 + ['n']\nS.length.times do |i|\n if !set2.include?(S[i]) && !set1.include?(S[i+1])\n puts 'No'\n exit\n end\nend\nputs 'Yes'"}, {"source_code": "str = gets.strip\n\nvowels = ['a','e','i','o','u']\n\nn = str.size\n\nvalid = true\n0.upto(n-2).each do |i|\n break if valid == false\n if vowels.include?(str[i])\n else\n if str[i]!='n' && vowels.include?(str[i+1]) == false\n valid = false\n end\n end\nend\n\nvalid = false if vowels.include?(str[n-1]) == false && str[n-1]!='n'\n\nputs (valid ? \"YES\" : \"NO\")"}, {"source_code": "s = gets.chomp.downcase\nputs (s =~ /[^aeioun][^aeiou]/ || s=~ /[^aeioun]$/) ? \"NO\" : \"YES\""}, {"source_code": " #!/usr/bin/ruby\n\n\ndef isvowel(x)\n if x == 'a'||x=='e'||x=='i'||x=='o'||x=='u'\n return true\n end\n\nend\nname = gets().chomp()\nflag = 0\nfor i in 0...name.length\n\n #puts(name[i])\n\n if(i == name.length-1)\n\n if(name[i] == 'n')\n flag = 0\n elsif (isvowel(name[i]))\n flag = 0\n else\n flag = 1\n break\n end\n\n\n\n elsif(!isvowel(name[i]))\n\n if(name[i] == 'n')\n flag = 0\n\n else\n if(!isvowel(name[i+1]))\n flag = 1\n break\n end\n\n end\n\n end\n\nend\n\nif(flag == 0)\n puts(\"YES\")\nelse\n puts(\"NO\")\nend"}, {"source_code": "s = gets.chomp\nn = s.size\na = [\"a\", \"i\", \"u\", \"e\", \"o\"]\ni = 0\nflag = true\nwhile i < n\n if a.include?(s[i])\n i += 1\n elsif s[i] == ?n\n i += 1\n else\n if i + 1 == n\n flag = false\n break\n else\n i += 1\n if !a.include?(s[i])\n flag = false\n break\n end\n i += 1\n end\n end\nend\nputs flag ? \"YES\" : \"NO\"\n"}, {"source_code": "s = gets\n(0...s.size-1).each do |i|\n next if s[i] =~ /[aouien]/\n if i == s.size - 1 || s[i + 1] !~ /[aouie]/\n puts 'NO'\n exit\n end\nend\nputs 'YES'\n"}], "negative_code": [{"source_code": "s = gets.chomp.downcase\nputs (s =~ /[^aeioun][^aeiou]/ || s =~ /^[aeiou]/ || s=~ /[^aeioun]$/) ? \"NO\" : \"YES\""}, {"source_code": "s = gets.chomp.downcase\nx = s =~ /[^aeioun][^aeiou]|/\nputs (x == nil || /[aeiou]/.match(s[0])) ? \"NO\" : \"YES\""}, {"source_code": "s = gets.chomp.downcase\nx = s =~ /[^aeiou]{2,} | n[aeiou] | ^[aeiou]/\nputs x ? \"NO\" : \"YES\""}, {"source_code": "s = gets.chomp.downcase\nx = s =~ /[^aeiou]{2,} | n[aeiou] | ^[aeiou]/\nputs x == nil ? \"NO\" : \"YES\""}, {"source_code": "#!/usr/bin/ruby\n\n\ndef isvowel(x)\n if x == 'a'||x=='e'||x=='i'||x=='o'||x=='u'\n return true\n end\n\nend\nname = gets().chomp()\nflag = 0\nfor i in 0...name.length\n\n #puts(name[i])\n\n if(i == name.length-1)\n\n if(name[i] == 'n')\n flag = 0\n elsif (isvowel(name[i]))\n flag = 0\n else\n flag = 1\n break\n end\n\n\n\n elsif(!isvowel(i))\n\n if(name[i] == 'n')\n flag = 0\n\n else\n if(!isvowel(name[i+1]))\n flag = 1\n break\n end\n\n end\n\n end\n\nend\n\nif(flag == 0)\n puts(\"YES\")\nelse\n puts(\"NO\")\nend"}, {"source_code": "#!/usr/bin/ruby\n\n\ndef isvowel(x)\n if x == 'a'||x=='e'||x=='i'||x=='o'||x=='u'\n return true\n end\n\nend\nname = gets().chomp()\nflag = 0\nfor i in 0...name.length\n\n #puts(name[i])\n\n if(i == name.length-1)\n\n if(name[i] == 'n')\n flag = 0\n elsif (isvowel(name[i]))\n flag = 0\n else\n flag = 1\n end\n\n\n\n elsif(!isvowel(i))\n\n if(name[i] == 'n')\n flag = 0\n\n else\n if(!isvowel(name[i+1]))\n flag = 1\n end\n\n end\n\n end\n\nend\n\nif(flag == 0)\n puts(\"YES\")\nelse\n puts(\"NO\")\nend"}], "src_uid": "a83144ba7d4906b7692456f27b0ef7d4"} {"nl": {"description": "There are n stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them.", "input_spec": "The first line contains integer n (1\u2009\u2264\u2009n\u2009\u2264\u200950) \u2014 the number of stones on the table. The next line contains string s, which represents the colors of the stones. We'll consider the stones in the row numbered from 1 to n from left to right. Then the i-th character s equals \"R\", if the i-th stone is red, \"G\", if it's green and \"B\", if it's blue.", "output_spec": "Print a single integer \u2014 the answer to the problem.", "sample_inputs": ["3\nRRG", "5\nRRRRR", "4\nBRBG"], "sample_outputs": ["1", "4", "0"], "notes": null}, "positive_code": [{"source_code": "n = gets.chomp.to_i\n\ns = gets.chomp\nlen = s.size - 1\n\nans = 0\n\nfor i in 0..len do\n if s[i] == s[i + 1]\n ans += 1\n i += 1\n else\n i += 1\n end\nend\n \np ans"}, {"source_code": "puts gets.chomp.to_i - gets.chomp.gsub(/(.)\\1+/,'\\1').length"}, {"source_code": "p gets.to_i - gets.scan(/(.)\\1*/).size"}, {"source_code": "i = 0\nn = gets.chomp.to_i\narr = gets.chomp.scan(/((.)\\2*)/).map(&:first).each{|x| i += x.length - 1}\nputs i\n"}, {"source_code": "def all_equal(array)\n\treturn array.max == array.min \nend\nx = gets.to_i\ninstone = gets.chomp().split(\"\")\ncount =0\ni = 0 \nwhile i 1 && index + 1 != input.length\n if input[index] == input[index + 1]\n input.slice!(index + 1)\n else\n index += 1\n end\nend\n\nputs input_copy.length - input.length"}, {"source_code": "n = gets.to_i\ns = gets.chomp\n\n\ncount = 0\nsaveColor =\"Z\"\ns.chars do |color|\n if saveColor != color\n saveColor = color\n else\n count += 1\n end\nend\n\nputs count"}, {"source_code": "def solve(sc, n)\n i = 0\n stones_removed = 0\n while i < sc.size\n # Compare only if the are more than one stone present\n if sc.size > 1\n if i >= 1 && sc.size >=3\n # Comparing if it is a middle position\n if sc[i-1] == sc[i] || sc[i] == sc[i+1]\n sc.delete_at(i)\n stones_removed += 1\n else\n i += 1\n end\n else\n # Comparing if it is the starting position\n if i == 0 && sc[i] == sc[i+1]\n sc.delete_at(i)\n stones_removed += 1\n else\n # Comparing if it is the last position\n if i != 0 && sc[i-1] == sc[i]\n sc.delete_at(i)\n stones_removed += 1\n else\n i += 1\n end\n end\n end\n else\n break\n end\n end\n stones_removed\nend\nn = gets.to_i\nstones_colors = gets.chomp.split(//)\nputs solve(stones_colors, n)"}, {"source_code": "def answers ()\n useless = gets.chomp\n str = gets.chomp\n count = 0\n for i in 1...str.length\n if str[i] == str[i-1]\n count+=1\n end\n end\n print count\nend\n\nanswers"}, {"source_code": "p gets(p).scan(/(.)(?=\\1)/).size"}, {"source_code": "n = gets.to_i\ns = gets.chomp\ncount = 0\nfor i in 1...n\n if s[i] == s[i-1]\n count+=1\n end\nend \nputs count"}, {"source_code": "#!/usr/bin/ruby1.9\n\nn = STDIN.readline.to_i\nline = STDIN.readline.strip\ncount = 0\n(1..line.length-1).each do |i|\n\tcount += 1 if line[i] == line[i-1]\nend\nputs count\n\n"}, {"source_code": "n = gets.to_i\ns = gets.chomp\nc = 0\n(1...s.length).each { |i| c += 1 if s[i] == s[i - 1] }\nputs c\n"}, {"source_code": "n = gets.chomp.to_i\nstr = gets.chomp\nres = 0\ni = 0\n\n(n-1).times do\nif (str[i] == str[i+1])\n res+=1\nend\ni = i + 1\nend\n\nputs res"}, {"source_code": "gets\nstr = gets.chomp\nprev = nil\ncnt = 0\nstr.split(\"\").each do |rock|\n\tif rock == prev\n\t\tcnt += 1\n\telse\n\t\tprev = rock\n\tend\nend\nputs cnt"}, {"source_code": "n = gets.to_i\ns = gets\ni=0\nr=0\nwhile(i0 && s[i] == s[i-1] then\n\t\tr=r+1\n\tend\n\ti=i+1\nend\nputs r\n"}, {"source_code": "n=gets.chomp.to_i\ns=gets.chomp.strip.split('')\nctr=0\ni=0\nwhile i0\n b = tt.shift\n ttt << b if a != b\n a = b\nend\n\nputs n - ttt.size"}, {"source_code": "n = gets;\na = gets.chomp;\nres = 0;\nfor i in 1...a.size\n if(a[i] == a[i - 1])\n res += 1;\n end\nend\nputs res;"}, {"source_code": "n = gets.to_i\ns = gets\nc = 0\nfor i in 0...s.size - 1\n c += 1 if s[i] == s[i+1]\nend\nputs c"}, {"source_code": "def run\n n = ARGF.readline.chomp\n s = ARGF.readline.chomp\n\n if s.length == 1\n puts \"0\"\n return\n end\n\n cnt = 0\n flag = false\n while !flag and s.length >= 1\n flag = true\n (s.length - 1).times do |i|\n if s[i] == s[i + 1]\n flag = false\n s[i] = ''\n break\n end\n end\n\n cnt += 1 unless flag\n end\n\n puts cnt\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "gets\nto_remove = 0\nline = gets.chomp.scan(/R{2,}|G{2,}|B{2,}/) { |match| to_remove += match.length - 1 }\nputs to_remove\n"}, {"source_code": "gets\ns = gets\nn = 0\ns.chars.each_with_index do |c, i|\n n +=1 if c == s[i-1]\nend\nputs n"}, {"source_code": "require 'pp'\n\ngets\nstr = gets.chomp\n\ncounter = 0\nstr.scan(/(RR+|GG+|BB+)/).each do |comb| \n counter += comb[0].length - 1\nend\nputs counter\n"}, {"source_code": "n = gets.to_i\ns = gets\n\n$res = 0\nc = '.'\n\ns.split(\"\").each do |i| \n if c == i\n $res += 1\n else\n c = i\n end\nend\n\nputs $res\n"}, {"source_code": "n=Integer(gets.chomp)\ns=gets.chomp.split(\"\")\nans=0\nuntil n==0\n if s[n]==s[n-1]\n ans+=1\n end\n n-=1\nend\nputs ans"}, {"source_code": "n = gets.to_i\ns = gets.chomp\n\nans = 0\ni = 0\nj = 1\nwhile i < n && s[i+j] do\n e = s[i]\n if e == s[i+j]\n ans += 1\n j += 1\n else\n i += j\n j = 1\n end\nend\nputs ans"}, {"source_code": "n = gets.strip.to_i\ntable = gets.strip\ni = 1\ncount = 0\nwhile i < n\n count += 1 if table[i - 1] == table[i]\n i += 1\nend\nputs count\n"}, {"source_code": "a=gets.chomp.to_i\nb=gets.chomp\nres=0\n0.upto(a-2) do|i|\nif b[i]==b[i+1]\nres+=1\nend\nend\n\nputs \"#{res}\""}, {"source_code": "p gets(p).size-$_.bytes.chunk{|i|i}.to_a.size"}, {"source_code": "n = gets.to_i\ns = gets\nx = 0\nn.times do |i|\n x += 1 if s[i] == s[i + 1]\nend\nprint x\n"}, {"source_code": "$stdin = File.open(\"./input.txt\", \"r\") if ENV[\"USER\"] == \"new\"\n# ====================================\n\ngets\nstones = gets.strip.split //\n\ncount = 0\nfor i in 0...stones.count-1\n a = stones[i]\n b = stones[i+1]\n \n count+=1 if a==b\nend\n\nputs count"}, {"source_code": "n = gets.to_i\nq = gets.chomp.split(//)\n\nfor i in 0...n-1\n if q[i] == q[i+1]\n q[i] = nil\n end\nend\n\nq.keep_if { |x| x.nil?}\n\nputs q.size"}, {"source_code": "n = gets.to_i\ns = gets.chomp.split('')\n\nr = [s.pop]\n\n(n-1).times do\n t = s.pop\n if t == r[-1]\n else\n r.push(t)\n end\nend\n# puts r[0]\nputs n - r.length\n"}, {"source_code": "i = gets.chomp.to_i\nstr = gets.chomp.split(//)\nx = -1\ncount = 0\nstr.each do |c|\n if c == x\n count += 1\n end\n x = c\nend\nputs count"}, {"source_code": "n=gets.chomp\nstone=gets.chomp\na=[]\nstone.split(\"\").each do |i|\n a< 1\n\t\t\tcolors.delete_at(i+1)\n\t\tend\n\tend\nend\n\nprint stones - colors.size"}, {"source_code": "number = gets.to_i\nlist = gets.split(//)\n\nlast = nil\ncount = 0\n(number-1).times do |i|\n count += 1 if list[i]==list[i+1]\nend\n\np count\n"}, {"source_code": "n=gets.to_i\ns=gets.split('')\n\nx = 0\n\nn.times do |i|\t\t\n\tx +=1 if s[i] == s[i+1]\nend\n\nputs x\n"}, {"source_code": "n, s = gets.to_i, gets\nputs n.times.count{|i| s[i] == s[i+1]}"}, {"source_code": "#puts \"Enter the number of stones\\n\"\nn = gets.to_i\n#puts \"Enter the arrangement\\n\"\ns = gets.to_s\nkey = 0\na = n-2\nfor j in 0..a do\n if s[j] == s[j+1]\n key += 1\n end\nend\nputs key"}, {"source_code": "n = gets.chomp.to_i\nstr = gets.chomp\n\nansg = ansr = ansb = 0\n\nn.times do |i|\n if str[i] == 'R'\n ansr, ansg, ansb = [ansr + 1, ansg, ansb].min, ansg + 1, ansb + 1\n elsif str[i] == 'G'\n ansr, ansg, ansb = ansr + 1, [ansr, ansg + 1, ansb].min, ansb + 1\n else\n ansr, ansg, ansb = ansr + 1, ansg + 1, [ansr, ansg, ansb + 1].min\n end\nend\n\nputs [ansg, ansr, ansb].min\n"}, {"source_code": "n = gets.to_i\nputs gets.split(//).each_cons(2).select{|x| x[0]==x[1]}.count"}, {"source_code": "gets\nputs gets.split(//).each_cons(2).select{|x| x[0]==x[1]}.count\n"}, {"source_code": "c,n=0,gets.to_i;a=gets.split('').to_a;1.upto(n){|x|a[x]==a[x-1] ?(c+=1):(0)};puts c\n"}, {"source_code": "# http://codeforces.com/problemset/problem/266/A\n\nn = gets.chomp\nstones = gets.chomp\n\neq = 0\n\nfor i in 1..(stones.length-1)\n if stones[i] == stones[i-1]\n eq = eq + 1\n end\nend\n\np eq\n"}, {"source_code": "p gets(p).scan(/(.)(?=\\1)/).size\n"}, {"source_code": "gets\ns = gets\nc = 0\n(1...s.size).each{ |i| s[i] == s[i - 1] ? c += 1 : 0 }\nputs c"}, {"source_code": "n = gets.to_i\ncolors = gets\nresult = 0\ncolors_array = colors.split('')\ncolors_array.each_with_index do |letter, idx|\n if idx != 0\n previous_letter = colors_array[idx - 1]\n if previous_letter == letter\n result = result + 1\n end\n end\nend\nputs result\n"}, {"source_code": "n = gets.chomp.to_i\ns = gets.chomp\nans = 0\nfor i in (1...n)\n ans += (s[i] == s[i - 1]) ? 1 : 0\nend\nputs ans"}, {"source_code": "stn_num = gets.chomp.to_i\nstn_color = gets.chomp\ncnt = 0\n\nfor num in 0..stn_num do \n\n if stn_color.split(\"\")[num] == stn_color.split(\"\")[num +1] then\n cnt+=1\n end\n\nend\np cnt-1\n"}, {"source_code": "n = gets.chomp.to_i\nline = gets.chomp.split(\"\")\np = 0\n(1..(n-1)).each { |k|\n\tif line[k]==line[k-1]\n\t\tp += 1\n\tend\n}\n\nputs p"}, {"source_code": "n=gets.to_i; last=\"\"; count=0\ngets.strip.chars.to_a.each{|x| (count+=1 if(last==x)); last=x}\np count"}, {"source_code": "n = gets.to_i\ncount = 0\narray = gets.split(\"\")\nfor i in 0...n\n\tif array[i] == array[i+1]\n\t\tcount += 1\n\tend\nend\nputs count\n"}, {"source_code": "n = gets.chomp.to_i\nx= gets.chomp\naux = 0\ni = 0\na,b = \"\"\nwhile(i < n - 1)\n\ta = x[i].chr\n\tb = x[i+1].chr\n\tif(a == b)\n\t\taux = aux + 1\n\tend\n\ti = i + 1\nend\nputs aux.to_s"}, {"source_code": "n, s = gets.to_i, gets\nputs n.times.count{|i| s[i] == s[i+1]}\n"}, {"source_code": "n = gets.to_i\nword = gets\n\ntotal = 0\n\nword.chars.each_with_index do |c, i|\n\ttotal += 1 if c == word[i-1]\nend\nputs total"}, {"source_code": "a=gets.chomp.to_i\nb=gets.chomp\nres=0\n0.upto(a-2) do|i|\nif b[i]==b[i+1]\nres+=1\nend\nend\n\nputs \"#{res}\"\n\n\n"}, {"source_code": "n = gets.to_i\nq = gets.chomp\nm = []\nm = q.split(\"\")\ni = 0\nj = 0\nwhile i < n do\n if m[i] == m[i+1]\n j = j+1\n end\n i = i+1\nend\nputs j"}, {"source_code": "n=gets.to_i-1\ns=gets.chomp\nfor i in 1..s.length-1\nif s[i]!=s[i-1]\nn-=1\nend\nend\np n"}, {"source_code": "n = gets.to_i\ns = gets.strip.split(//)\nans = 0\n0.upto(n-2) do |i|\n if s[i] == s[i+1]\n ans+=1\n end\nend\nputs ans"}, {"source_code": "p gets(p).scan(/(.)(?=\\1)/).size"}, {"source_code": "n = gets.to_i\na = gets.split('')\n\nd = 0\n\n(0..n-1).each do |i| \n\tif ( a[i] == a[i+1] )\n\t\td += 1\n\tend\nend\n\nputs d"}, {"source_code": "gets.chomp\narr = gets.chomp.scan(/((\\w)\\2*)/).map(&:first)\nputs arr.map(&:size).reduce(:+) - arr.size"}, {"source_code": "#!/usr/bin/env ruby\n\nn = gets.to_i\ns = gets\ntot = 0\n0.upto(n-2) { |i| tot += 1 if s[i] == s[i+1] }\t\nputs tot\n"}, {"source_code": "n = gets.to_i\na = gets.split('')\nm = 0\n(1..n-1).each do |t|\n m += 1 if a[t] == a[t-1]\nend\nputs m"}, {"source_code": "_n = gets.chomp.to_i\nstr = gets.chomp\nprev = ''\ncount = 0\nstr.split(//).each do |chr|\n chr == prev ? count += 1 : prev = chr\nend\nputs count\n"}, {"source_code": "number = gets.strip.to_i\nsequence = gets.strip\n\nnew_string = sequence[0]\nsequence[0] = ''\n\nsequence.each_char.with_index do |char, index|\n new_string << char if new_string[-1] != char\nend\n\nputs number - new_string.length\n"}, {"source_code": "BEGIN{\n\tdef gint()\n\t\treturn gets.split.map(&:to_i)\n\tend\n\tdef main()\n\t\tn = gint\n\t\ts = gets.to_s\n\t\tsum = 0\n\t\tfor i in 0..s.length - 2 do\n\t\t\tc = s[i]\n\t\t\tif c == s[i + 1] then\n\t\t\t\tsum += 1\n\t\t\tend\n\t\tend\n\t\tputs sum\n\tend\n\tTest_case = 1\n\tTest_case.times do\n\t\tmain()\n\tend\n}\n"}, {"source_code": "n = gets.to_i\ns = gets.chomp\nd = 0\nfor i in 1 ... s.size\n if s[i] == s[i-1]\n d += 1\n end\nend\n\np d\n"}, {"source_code": "n = gets.to_i\nputs gets.split(//).each_cons(2).select{|x| x[0]==x[1]}.count"}, {"source_code": "n = gets\ns = gets\np s.length - s.squeeze.length"}, {"source_code": "n=gets.chomp.to_i\n\n\nstr=gets.chomp\ncur=0\nfor i in 1..n \n\tif str[i]==str[i-1]\n\t\tcur+=1\n\n\tend\nend\nputs(cur)\n\n"}, {"source_code": "n = gets\nprevious = ''\ncounter = 0\ngets.chomp.split('').each do |letter|\n counter += 1 if previous == letter\n previous = letter\nend\nputs counter\n"}, {"source_code": "@numBall = STDIN.gets\n@input = STDIN.gets\n@check = true\n@count = 0\ndef removeNearby\n @check = false\n str_temp = @input\n str_length = str_temp.length - 1\n while (str_length > 1)\n if(str_temp[str_length - 1] == str_temp[str_length - 2])\n @check = true\n @count += 1\n str_temp.slice!(str_length - 1)\n else\n str_length -= 1\n end\n end\n @input = str_temp\n\nend\n\nwhile (@check)\n removeNearby\nend\n\nputs @count"}, {"source_code": "n = gets.to_i\ns = gets.chomp\n\nresult = 0\ni = 1\nwhile i < n do\n if s[i] == s[i-1] then\n result += 1\n end\n i += 1\nend\n\nputs result"}], "negative_code": [{"source_code": "p gets.to_i - gets.squeeze.size"}, {"source_code": "n = gets.chomp.to_i\ns = gets.chomp.split(\"\")\nx = 0\n0.upto n-1 do |i|\n\tnext if i == 0\n\tif s[i] == s[i-1]\n\t\ts.delete_at(i-1)\n\t\tx += 1\n\tend\nend\nputs x"}, {"source_code": "puts \"Number of stones n=\"\nn = gets.to_i\nputs \"Colors of stones s=\"\ns = gets(n)\ni = 0\nstones = 0\n# \u0438\u0434\u0435\u043c \u043f\u043e \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u0441\u0438\u043c\u0432\u043e\u043b\u0443 \u0432 \u0441\u0442\u0440\u043e\u043a\u0435\nwhile i < n\n # \u0435\u0441\u043b\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0441\u0438\u043c\u0432\u043e\u043b \u0432 \u0441\u0442\u0440\u043e\u043a\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c\u0443\n if s[i] == s[i+1]\n stones += 1\n end\n i += 1\nend\n\nputs stones"}, {"source_code": "def solve(sc, n)\n i = 0\n stones_removed = 0\n while i < sc.size\n # Compare only if the are more than one stone present\n if sc.size > 1\n if i >= 1 && sc.size >=3\n # Comparing if it is a middle position\n if sc[i-1] == sc[i] || sc[i] == sc[i+1]\n sc.delete_at(i)\n stones_removed += 1\n else\n i += 1\n end\n else\n # Comparing if it is the starting position\n if i == 0 && sc[i] == sc[i+1]\n sc.delete_at(i)\n stones_removed += 1\n else\n # Comparing if it is the last position\n if sc[i-1] == sc[i]\n sc.delete_at(i)\n stones_removed += 1\n else\n i += 1\n end\n end\n end\n else\n break\n end\n end\n stones_removed\nend\nn = gets.to_i\nstones_colors = gets.chomp.split(//)\nputs solve(stones_colors, n)"}, {"source_code": "n = gets.to_i\na = Array.new(n)\n\nfor i in 0..n-1\n a[i] = gets.to_s\nend\n\ncounter = 0\nfor i in 0..n-1 \n if a[i] == a[i+1]\n counter+=1\n end\nend\np counter"}, {"source_code": "n = gets.to_i\na = Array.new(n)\n\nfor i in 0..n-1\n a[i] = gets.to_s\nend\n\ncounter = 0\nfor i in 0..n-1 \n if a[i] == a[i+1]\n counter+=1\n end\nend\nputs counter"}, {"source_code": "n = gets.to_i\ns = gets.chomp.split(//)\n\ncounter = 0\nfor i in 0..s.length-1\n if s[i] != s[i+1]\n counter+=1\n end\nend\nputs counter"}, {"source_code": "n = gets.to_i\na = Array.new(n)\n\nfor i in 0..n-1\n a[i] = gets.to_s\nend\n\ncounter = 0\nfor i in 0..n-1 \n if a[i] == a[i+1]\n counter+=1\n end\nend\ncounter"}, {"source_code": "def run\n n = ARGF.readline.chomp\n s = ARGF.readline.chomp\n\n return 0 if s.length == 1\n\n cnt = 0\n flag = false\n while !flag and s.length >= 1\n flag = true\n (s.length - 1).times do |i|\n if s[i] == s[i + 1]\n flag = false\n s[i] = ''\n break\n end\n end\n\n cnt += 1 unless flag\n end\n\n puts cnt\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "n = gets.to_i\ns = gets.chomp\n\nans = 0\ni = 0\nj = 1\nwhile i < n && i + j < n do\n e = s[i]\n if e == s[i+j]\n ans += 1\n j += 1\n else\n i += 1\n j = 1\n end\nend\nputs ans"}, {"source_code": "p gets(p).bytes.chunk{|i|i}.to_a.size-3"}, {"source_code": "puts gets.scan(/(.)(?=\\1)/).size"}, {"source_code": "n, s = gets.to_i, gets\nputs n-1.times.count{|i| s[i] == s[i+1]}"}, {"source_code": "puts \"Enter the number of stones\\n\"\nn = gets.to_i\nputs \"Enter the arrangement\\n\"\ns = gets.to_s\nkey = 0\na = n-2\nfor j in 0..a do\n if s[j] == s[j+1]\n key += 1\n end\nend\nputs key"}, {"source_code": "n = gets.chomp.to_i\nstr = gets.chomp\n\nansg = ansr = 0\n\nn.times do |i|\n if str[i] == 'R'\n ansr, ansg = [ansg, ansr + 1].min, ansg + 1\n else\n ansr, ansg = ansr + 1, [ansg + 1, ansr].min\n end\nend\n\nputs [ansg, ansr].min"}, {"source_code": "n = gets.chomp.to_i\nstr = gets.chomp\n\nansg = ansr = ansb = 0\n\nn.times do |i|\n if str[i] == 'R'\n ansr, ansg, ansb = [ansr + 1, ansg, ansb].min, ansg + 1, ansb + 1\n elsif str[i] == 'G'\n ansr, ansg, ansb = ansr + 1, [ansr, ansg + 1, ansb].min, ansb + 1\n else\n ansr, ansg, ansb = ansr + 1, ansg + 1, [ansr, ansg, ansb + 1].min\n end\nend\n\nputs [ansg, ansr].min\n"}, {"source_code": "s = gets\nc = 0\n(1...s.size).each{ |i| s[i] == s[i - 1] ? c += 1 : 0 }\nputs c"}, {"source_code": "n = gets.to_i\nq = gets.chomp\nm = []\nm = q.split(\"\")\ni = 0\nj = 0\nwhile i < n do\n i = i+1\n if m[i] == m[i+1]\n j = j+1\n end\nend\nputs j"}, {"source_code": "n=gets.to_i-1\ns=gets\nfor i in 1..s.length-1\nif s[i]!=s[i-1]\nn-=1\nend\nend\np n"}, {"source_code": "number = gets.strip.to_i\nsequence = gets.strip\n\nnew_string = sequence[0]\nsequence[0] = ''\n\nputs sequence\nsequence.each_char.with_index do |char, index|\n new_string << char if new_string[-1] != char\nend\n\nputs number - new_string.length\n"}, {"source_code": "n=gets.chomp.to_i\n\n\nstr=gets.chomp\nbest=0\ncur=0\nfor i in 1..n \n\tif str[i]==str[i-1]\n\t\tcur+=1\n\telse\n\t\tcur=0\n\tend\n\tbest=[best,cur].max\nend\nputs(best)\n\n"}], "src_uid": "d561436e2ddc9074b98ebbe49b9e27b8"} {"nl": {"description": "\"QAQ\" is a word to denote an expression of crying. Imagine \"Q\" as eyes with tears and \"A\" as a mouth.Now Diamond has given Bort a string consisting of only uppercase English letters of length n. There is a great number of \"QAQ\" in the string (Diamond is so cute!). illustration by \u732b\u5c4b https://twitter.com/nekoyaliu Bort wants to know how many subsequences \"QAQ\" are in the string Diamond has given. Note that the letters \"QAQ\" don't have to be consecutive, but the order of letters should be exact.", "input_spec": "The only line contains a string of length n (1\u2009\u2264\u2009n\u2009\u2264\u2009100). It's guaranteed that the string only contains uppercase English letters.", "output_spec": "Print a single integer\u00a0\u2014 the number of subsequences \"QAQ\" in the string.", "sample_inputs": ["QAQAQYSYIOIWIN", "QAQQQZZYNOIWIN"], "sample_outputs": ["4", "3"], "notes": "NoteIn the first example there are 4 subsequences \"QAQ\": \"QAQAQYSYIOIWIN\", \"QAQAQYSYIOIWIN\", \"QAQAQYSYIOIWIN\", \"QAQAQYSYIOIWIN\"."}, "positive_code": [{"source_code": "r=0\ns=gets.chomp\ns.size.times{|i|if s[i]=='Q'\n(i+2...s.size).each{|j|if s[j]=='Q'\nr+=(i+1...j).count{|k|s[k]=='A'}\nend}\nend}\np r"}, {"source_code": "str_arr = gets.chomp\nl, m, r = 0, 1, 2\nresult = 0\n\nwhile l <= str_arr.length - 3\n while str_arr[l] != 'Q' and l < str_arr.length - 3\n l += 1\n end\n m = l + 1\n r = m + 1\n while m <= str_arr.length - 2\n while str_arr[m] != 'A' and m < str_arr.length - 2\n m += 1\n end\n r = m + 1\n while r <= str_arr.length - 1\n while str_arr[r] != 'Q' and r < str_arr.length - 1\n r += 1\n end\n if str_arr[l] + str_arr[m] + str_arr[r] == \"QAQ\"\n result += 1\n end\n r += 1\n end\n m += 1\n end\n l += 1 \n \nend\n\nprint result\n\n\n"}, {"source_code": "input = gets.chomp\nr = 0\nfor i in 0...input.size\n\tif input[i] == \"Q\"\n\t\tfor j in (i + 2)...input.size\n\t\t\tif input[j] == \"Q\"\n\t\t\t\tr += ((i + 1)...j).count {|x| input[x] == \"A\"}\n\t\t\tend\n\t\tend\n\tend\nend\nputs r"}, {"source_code": "\n na=gets.chomp\n i1=na.index(\"Q\")\n if(i1!=nil)\n i2=na.index(\"A\",i1+1)\n end\n if(i2!=nil&&i1!=nil)\n i3=na.index(\"Q\",i2+1)\n end\n num=0\n while i1!=nil\n while i2!=nil\n while i3!=nil&&i20\n\t\tif e==c\n\t\t\tcount0+=count1\n\t\t\tdp2[i]=count0\n\t\tend\n\t\ti=i+1\n\t}\n\treturn dp2\nend\n\ns=\" \"+gets.chomp\nans=0\ndp=[1]*s.size\n\"QAQ\".chars.each{|e|\n\tdp=f(s,e,dp)\n}\nputs dp.max\n"}, {"source_code": "p gets.chars.combination(3).to_a.count(['Q','A','Q'])"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\nQ = 'Q'\nA = 'A'\nqi = []\nai = []\n\ngets.chomp.split(//).each_with_index { |elem, index| \n if elem == Q\n qi << index\n elsif elem == A\n ai << index\n else\n next\n end\n}\n\nseqs = 0\nqi.each { |i|\n ai.each { |j|\n if i < j\n count = 0\n qi.each { |sub_i|\n count += 1 if sub_i > j\n }\n seqs += count\n end\n }\n}\n\nputs seqs\n"}, {"source_code": "class QAQCounter\n def count(input)\n a_array = Array.new(input.size)\n\n leading_count = 0\n input.each_char.with_index do |c, i|\n if c == 'Q'\n leading_count += 1\n elsif c == 'A'\n a_array[i] = [leading_count, nil]\n end\n end\n\n following_count = 0\n input.reverse.each_char.with_index do |c, i|\n if c == 'Q'\n following_count += 1\n elsif c == 'A'\n a_array[input.size-i-1][1] = following_count\n end\n end\n\n a_array.inject(0) { |sum, x| sum + (x.nil? ? 0 : x[0] * x[1]) }\n end\nend\n\ninput = ARGF.readline\nputs QAQCounter.new.count(input)\n"}, {"source_code": "def solution(string)\n q, a, qa, count = 0, 0, 0, 0\n for i in 0...string.size do\n if string[i] == \"Q\"\n q += 1\n count += qa\n end \n if string[i] == \"A\"\n a += 1 \n qa += q\n end\n end\n count\nend\n\nputs solution(gets.strip)\n"}, {"source_code": "def solution(string)\n left_q = string.each_char.inject([0]) { |memo, chr| memo + [memo.last + (chr == \"Q\" ? 1 : 0)] }.tap { |o| o.shift }\n right_q = string.reverse.each_char.inject([0]) { |memo, chr| memo + [memo.last + (chr == \"Q\" ? 1 : 0)] }.tap { |o| o.shift }.reverse\n\n count = 0\n for i in 1...string.size-1 do\n if string[i] == \"A\"\n count += left_q[i]*right_q[i]\n end \n end\n count\nend\n \nputs solution(gets.strip)\n"}, {"source_code": "c = gets.chomp.chars.combination(3).to_a.count(['Q','A','Q'])\nprint c\n"}, {"source_code": "a = gets.chomp\nn = a.size\nans = 0\nn.times do |i|\n if a[i] == ?A\n ans += a[0...i].count(?Q) * a[i..-1].count(?Q)\n end\nend\nputs ans"}, {"source_code": "S = gets\n\nQ = ?Q\nA = ?A\n\nq = qa = qaq = 0\n\nS.each_char do |c|\n \n if c == Q\n \n q += 1\n qaq += qa\n \n elsif c == A\n \n qa += q\n \n end\n \nend\n\nputs qaq"}, {"source_code": "s = gets\ni = 1\nl, r = [0], [nil]*(s.size - 1) + [0]\nwhile i < s.size\n l[i] = l[i - 1] + (s[i - 1] == 'Q' ? 1 : 0)\n r[-i - 1] = r[-i] + (s[-i] == 'Q' ? 1 : 0)\n i += 1\nend\ni = 1\nans = 0\nwhile i < s.size - 1\n ans += l[i]*r[i] if s[i] == 'A'\n i += 1\nend\nputs ans\n"}, {"source_code": "s = gets.chomp\n\nresult = 0\n\ns.chars.each_with_index { |c, i| result += (s[0..i] || '').count('Q') * (s[i..-1] || '').count('Q') if c == 'A' }\n\nputs result\n"}], "negative_code": [{"source_code": "str_arr = gets.chomp\nl, m, r = 0, 1, 2\nresult = 0\n\nwhile l <= str_arr.length - 3\n while str_arr[l] != 'Q' and l < str_arr.length - 3\n l += 1\n end\n\n while m <= str_arr.length - 2\n while str_arr[m] != 'A' and m < str_arr.length - 2\n m += 1\n end\n\n while r <= str_arr.length - 1\n while str_arr[r] != 'Q' and r < str_arr.length - 1\n r += 1\n end\n if str_arr[l] + str_arr[m] + str_arr[r] == \"QAQ\"\n result += 1\n end\n r += 1\n end\n m += 1\n r = m + 1\n end\n l += 1 \n m = l + 1\n r = m + 1\nend\n\nprint result\n\n\n"}, {"source_code": " na=gets.chomp\n i1=na.index(\"Q\")\n i2=na.index(\"A\",i1+1)\n i3=na.index(\"Q\",i1+1)\n num=0\n while i1!=nil\n while i2!=nil\n while i3!=nil\n num+=1\n \n i3=na.index(\"Q\",i3+1)\n end\n i2=na.index(\"A\",i2+1)\n if(i2!=nil)\n i3=na.index(\"Q\",i2+1)\nend\n end\n i1=na.index(\"Q\",i1+1)\n if(i1!=nil)\n i2=na.index(\"A\",i1+1)\nend\n if(i2!=nil)\n i3=na.index(\"Q\",i2+1)\nend\n end\n if num == 379\n puts 378\n else\n \n puts num\n end"}, {"source_code": " na=gets.chomp\n i1=na.index(\"Q\")\n i2=na.index(\"A\",i1+1)\n i3=na.index(\"Q\",i1+1)\n num=0\n while i1!=nil\n while i2!=nil\n while i3!=nil\n num+=1\n \n i3=na.index(\"Q\",i3+1)\n end\n i2=na.index(\"A\",i2+1)\n if(i2!=nil)\n i3=na.index(\"Q\",i2+1)\nend\n end\n i1=na.index(\"Q\",i1+1)\n if(i1!=nil)\n i2=na.index(\"A\",i1+1)\nend\n if(i2!=nil)\n i3=na.index(\"Q\",i2+1)\nend\n end\n if num == 379\n puts 378\n else\n puts num\n end"}, {"source_code": " \n na=gets.chomp\n i1=na.index(\"Q\")\n i2=na.index(\"A\",i1+1)\n i3=na.index(\"Q\",i1+1)\n num=0\n while i1!=nil\n while i2!=nil\n while i3!=nil\n num+=1\n \n i3=na.index(\"Q\",i3+1)\n end\n i2=na.index(\"A\",i2+1)\n if(i2!=nil)\n i3=na.index(\"Q\",i2+1)\nend\n end\n i1=na.index(\"Q\",i1+1)\n if(i1!=nil)\n i2=na.index(\"A\",i1+1)\nend\n if(i2!=nil)\n i3=na.index(\"Q\",i2+1)\nend\n end\n if num > 378\n puts num-1\n else\n puts num\n end"}, {"source_code": "\n na=gets.chomp\n i1=na.index(\"Q\")\n i2=na.index(\"A\",i1+1)\n i3=na.index(\"Q\",i1+1)\n num=0\n while i1!=nil\n while i2!=nil\n while i3!=nil\n num+=1\n \n i3=na.index(\"Q\",i3+1)\n end\n i2=na.index(\"A\",i2+1)\n if(i2!=nil)\n i3=na.index(\"Q\",i2+1)\nend\n end\n i1=na.index(\"Q\",i1+1)\n if(i1!=nil)\n i2=na.index(\"A\",i1+1)\nend\n if(i2!=nil)\n i3=na.index(\"Q\",i2+1)\nend\n end\n puts num"}, {"source_code": "str = gets\nprint str.scan(/(?=QAQ)/).count\n"}], "src_uid": "8aef4947322438664bd8610632fe0947"} {"nl": {"description": "It is known that fleas in Berland can jump only vertically and horizontally, and the length of the jump is always equal to s centimeters. A flea has found herself at the center of some cell of the checked board of the size n\u2009\u00d7\u2009m centimeters (each cell is 1\u2009\u00d7\u20091 centimeters). She can jump as she wishes for an arbitrary number of times, she can even visit a cell more than once. The only restriction is that she cannot jump out of the board.The flea can count the amount of cells that she can reach from the starting position (x,\u2009y). Let's denote this amount by dx,\u2009y. Your task is to find the number of such starting positions (x,\u2009y), which have the maximum possible value of dx,\u2009y.", "input_spec": "The first line contains three integers n, m, s (1\u2009\u2264\u2009n,\u2009m,\u2009s\u2009\u2264\u2009106) \u2014 length of the board, width of the board and length of the flea's jump.", "output_spec": "Output the only integer \u2014 the number of the required starting positions of the flea.", "sample_inputs": ["2 3 1000000", "3 3 2"], "sample_outputs": ["6", "4"], "notes": null}, "positive_code": [{"source_code": "def calc(n,m,d)\n\tk = (n - 1) / d + 1\n t = (m - 1) / d + 1\n i = (n - 1) % d + 1\n j = (m - 1) % d + 1\n return k * t * i * j\nend\n\ndef countone(x, d)\n\tdd = ((x-1)/d)+1\n\treturn (((x-1) % d)+1)*dd\nend\n\ns = gets.chomp\nns,ms,ds = s.split(/ /)\nn = ns.to_i\nm = ms.to_i\nd = ds.to_i\nret = n*m\nif (n > d) || (m > d) \n\tif (n <= d)\n\t\tni = n\n\telse\n\t\tni = countone(n,d)\n\tend\n\tif (m <= d)\n\t\tmi = m\n\telse\n\t\tmi = countone(m,d)\n\tend\n\tret = ni*mi\nend\nputs ret\n"}, {"source_code": "def F(x,s);x-(-x%s*(x/s));end;n,m,s=gets.split.map &:to_i;p F(n,s)*F(m,s)\n"}, {"source_code": "def F(x,s);x-(-x%s*(x/s));end;n,m,s=gets.split.map &:to_i;p F(n,s)*F(m,s)\n"}, {"source_code": "def F(x,s);x-(-x%s*(x/s));end;n,m,s=gets.split.map &:to_i;p F(n,s)*F(m,s)\n"}, {"source_code": "def F(x,s);x-(-x%s*(x/s));end;n,m,s=gets.split.map &:to_i;p F(n,s)*F(m,s)\n"}, {"source_code": "def F(x,s);x-(-x%s*(x/s));end;n,m,s=gets.split.map &:to_i;p F(n,s)*F(m,s)"}, {"source_code": "def F(x,s);x-(-x%s*(x/s));end;n,m,s=gets.split.map &:to_i;p F(n,s)*F(m,s)"}, {"source_code": "def F(x,s);x-(-x%s*(x/s));end;n,m,s=gets.split.map &:to_i;p F(n,s)*F(m,s)\n"}, {"source_code": "def F(x,s);x-(-x%s*(x/s));end;n,m,s=gets.split.map &:to_i;p F(n,s)*F(m,s)\n"}, {"source_code": "def F(x,s);x-(-x%s*(x/s));end;n,m,s=gets.split.map &:to_i;p F(n,s)*F(m,s)\n"}, {"source_code": "def F(x,s);x-(-x%s*(x/s));end;n,m,s=gets.split.map &:to_i;p F(n,s)*F(m,s)\n"}, {"source_code": "def F(x,s);x-(-x%s*(x/s));end;n,m,s=gets.split.map &:to_i;p F(n,s)*F(m,s)\n"}], "negative_code": [{"source_code": "def calc(n,m,d)\n\tk = (n - 1) / d + 1\n t = (m - 1) / d + 1\n i = (n - 1) % d + 1\n j = (m - 1) % d + 1\n return k * t * i * j\nend\n\ndef countone(x, d)\n\tdd = ((x-1)/d)+1\n\treturn (((x-1) % d)+1)*dd\nend\n\ns = gets.chomp\nns,ms,ds = s.split(/ /)\nn = ns.to_i\nm = ms.to_i\nd = ds.to_i\nret = n*m\nif (n > d) || (m > d) \n\tif (n <= d)\n\t\tni = 2\n\telse\n\t\tni = countone(n,d)\n\tend\n\tif (m <= d)\n\t\tmi = 2\n\telse\n\t\tmi = countone(m,d)\n\tend\n\tret = ni*mi\nend\nputs ret\n"}, {"source_code": "def countone(x, d)\n\tdd = ((x-1)/d)+1\n\treturn (((x-1) % d)+1)*dd\nend\n\ns = gets.chomp\nns,ms,ds = s.split(/ /)\nn = ns.to_i\nm = ms.to_i\nd = ds.to_i\nret = n*m\nif (n > d) || (m > d) \n\tif (n <= d)\n\t\tni = 1\n\telse\n\t\tni = countone(n,d)\n\tend\n\tif (m <= d)\n\t\tmi = 1\n\telse\n\t\tmi = countone(m,d)\n\tend\n\tret = ni*mi\nend\nputs ret"}], "src_uid": "e853733fb2ed87c56623ff9a5ac09c36"} {"nl": {"description": "Today on Informatics class Nastya learned about GCD and LCM (see links below). Nastya is very intelligent, so she solved all the tasks momentarily and now suggests you to solve one of them as well.We define a pair of integers (a,\u2009b) good, if GCD(a,\u2009b)\u2009=\u2009x and LCM(a,\u2009b)\u2009=\u2009y, where GCD(a,\u2009b) denotes the greatest common divisor of a and b, and LCM(a,\u2009b) denotes the least common multiple of a and b.You are given two integers x and y. You are to find the number of good pairs of integers (a,\u2009b) such that l\u2009\u2264\u2009a,\u2009b\u2009\u2264\u2009r. Note that pairs (a,\u2009b) and (b,\u2009a) are considered different if a\u2009\u2260\u2009b.", "input_spec": "The only line contains four integers l,\u2009r,\u2009x,\u2009y (1\u2009\u2264\u2009l\u2009\u2264\u2009r\u2009\u2264\u2009109, 1\u2009\u2264\u2009x\u2009\u2264\u2009y\u2009\u2264\u2009109).", "output_spec": "In the only line print the only integer\u00a0\u2014 the answer for the problem.", "sample_inputs": ["1 2 1 2", "1 12 1 12", "50 100 3 30"], "sample_outputs": ["2", "4", "0"], "notes": "NoteIn the first example there are two suitable good pairs of integers (a,\u2009b): (1,\u20092) and (2,\u20091).In the second example there are four suitable good pairs of integers (a,\u2009b): (1,\u200912), (12,\u20091), (3,\u20094) and (4,\u20093).In the third example there are good pairs of integers, for example, (3,\u200930), but none of them fits the condition l\u2009\u2264\u2009a,\u2009b\u2009\u2264\u2009r."}, "positive_code": [{"source_code": "L, R, X, Y = gets.split.map(&:to_i)\nif Y % X != 0\n puts 0\n exit\nend\n\ndiv = Y/X\nsq = Math.sqrt(div).ceil\nans = 0\n(1..sq).each do |i|\n next if div%i != 0\n j = div/i\n next if i > j\n next if i.gcd(j) != 1\n if (i*X).between?(L, R) && (j*X).between?(L, R)\n ans += i==j ? 1 : 2\n end\nend\nputs ans"}, {"source_code": "require 'prime'\n\nl, r, x, y = gets.strip.split.map(&:to_i)\n\nx_factors = Prime.prime_division(x)\ny_factors = Prime.prime_division(y)\nall_factors = {}\nx_factors.each do |fp|\n all_factors[fp[0]] = [fp[1]]\nend\ny_factors.each do |fp|\n if all_factors[fp[0]]\n all_factors[fp[0]] << fp[1]\n else\n all_factors[fp[0]] = [0, fp[1]]\n end\nend\n\nif all_factors.values.map(&:size).uniq != [2]\n puts 0\n exit\nend\n\nall_factors_ary = all_factors.keys.sort\nbl = all_factors_ary.size\nn = 1< 0\n b *= (f ** all_factors[f][1])\n a *= (f ** all_factors[f][0])\n else\n a *= (f ** all_factors[f][1])\n b *= (f ** all_factors[f][0])\n end\n end\n # puts \"(#{a},#{b})\"\n if l<=a && a<=r && l<=b && b<=r\n pairs << [a,b]\n end\nend\nputs pairs.uniq.size\n\n"}], "negative_code": [], "src_uid": "d37dde5841116352c9b37538631d0b15"} {"nl": {"description": "Special Agent Smart Beaver works in a secret research department of ABBYY. He's been working there for a long time and is satisfied with his job, as it allows him to eat out in the best restaurants and order the most expensive and exotic wood types there. The content special agent has got an important task: to get the latest research by British scientists on the English Language. These developments are encoded and stored in a large safe. The Beaver's teeth are strong enough, so the authorities assured that upon arriving at the place the beaver won't have any problems with opening the safe.And he finishes his aspen sprig and leaves for this important task. Of course, the Beaver arrived at the location without any problems, but alas. He can't open the safe with his strong and big teeth. At this point, the Smart Beaver get a call from the headquarters and learns that opening the safe with the teeth is not necessary, as a reliable source has sent the following information: the safe code consists of digits and has no leading zeroes. There also is a special hint, which can be used to open the safe. The hint is string s with the following structure: if si = \"?\", then the digit that goes i-th in the safe code can be anything (between 0 to 9, inclusively); if si is a digit (between 0 to 9, inclusively), then it means that there is digit si on position i in code; if the string contains letters from \"A\" to \"J\", then all positions with the same letters must contain the same digits and the positions with distinct letters must contain distinct digits. The length of the safe code coincides with the length of the hint. For example, hint \"?JGJ9\" has such matching safe code variants: \"51919\", \"55959\", \"12329\", \"93539\" and so on, and has wrong variants such as: \"56669\", \"00111\", \"03539\" and \"13666\".After receiving such information, the authorities change the plan and ask the special agents to work quietly and gently and not to try to open the safe by mechanical means, and try to find the password using the given hint.At a special agent school the Smart Beaver was the fastest in his platoon finding codes for such safes, but now he is not in that shape: the years take their toll ... Help him to determine the number of possible variants of the code to the safe, matching the given hint. After receiving this information, and knowing his own speed of entering codes, the Smart Beaver will be able to determine whether he will have time for tonight's show \"Beavers are on the trail\" on his favorite TV channel, or he should work for a sleepless night...", "input_spec": "The first line contains string s \u2014 the hint to the safe code. String s consists of the following characters: ?, 0-9, A-J. It is guaranteed that the first character of string s doesn't equal to character 0. The input limits for scoring 30 points are (subproblem A1): 1\u2009\u2264\u2009|s|\u2009\u2264\u20095. The input limits for scoring 100 points are (subproblems A1+A2): 1\u2009\u2264\u2009|s|\u2009\u2264\u2009105. Here |s| means the length of string s.", "output_spec": "Print the number of codes that match the given hint.", "sample_inputs": ["AJ", "1?AA"], "sample_outputs": ["81", "100"], "notes": null}, "positive_code": [{"source_code": "#!/usr/bin/ruby\nh={}\nf=10\nx=1\ngets.chomp.each_char.with_index{|c,i|\n\tif i==0&&!('0'..'9').include?(c)\n\t\tf=9\n\tend\n\tif c=='?'\n\t\tx*=10\n\telsif ('A'..'J').include?(c)\n\t\th[c]=1\n\tend\n}\np x*(11-h.size..10).reduce(1,:*)*f/10"}, {"source_code": "hint = gets\ntemp = hint\narr = Array.new()\nnum = 10\nres = 1\nif hint[0] == '?'\n res *= 9\nelsif hint[0] > '9'\n res *= 9\n hint = hint[0] + temp.gsub(hint[0],'')\n num = num - 1\nend\nhint[0] = ''\nhint.each_char {|c|\n if c == '?'\n res *= 10\n elsif c > '9' && !(arr.include?(c))\n res *= num\n arr << c \n num = num - 1\n end \n}\n\nputs res\n"}, {"source_code": "s = gets\nret = 1\nhash = {}\nfor i in 0...s.size\n adjust = i == 0 ? 1 : 0\n ret *= 10 - adjust if s[i] == '?'\n if s[i] >= 'A' && s[i] <= 'J'\n ret *= 10 - hash.size - adjust unless hash[s[i]]\n hash[s[i]] = true\n end\nend\nputs ret\n"}, {"source_code": "t = STDIN.gets\ndef ppp(start,lcounter)\n return start if lcounter == 1\n return 1 if lcounter < 1\n start*ppp(start-1, lcounter -1)\nend\nh = []\nk = []\nqcounter = 0\n\nt.size.times do |i|\n if t[i] =~ /[A-J]/\n h << t[i] if not h.include? t[i]\n end\n if '0123456789'.include? t[i]\n k << t[i] if not k.include? t[i]\n end\n qcounter = qcounter + 1 if t[i] == '?'\nend \n\np = h.count\np = 0 if p < 0\npp = 10 \n\n\nres = ((t[0] =~ /[A-J]/) ? ppp(pp-1, p-1)*(pp-1) : ppp(pp, p))* ((t[0] == '?') ? (10)**(qcounter - 1)*9 : (10)**qcounter) \nputs res"}, {"source_code": "#!/usr/bin/ruby\nh={}\nf=10\nx=0\ngets.chomp.each_char.with_index{|c,i|\n\tif i==0&&!('0'..'9').include?(c)\n\t\tf=9\n\tend\n\tif c=='?'\n\t\tx+=1\n\telsif ('A'..'J').include?(c)\n\t\th[c]=1\n\tend\n}\nr=(11-h.size..10).reduce(1,:*)\nif x>0\n\tr*=10\n\tx-=1\nend\nr=r*f/10\nputs r.to_s+'0'*x"}, {"source_code": "def f(n)\n return 1 if n == 1\n return n * f(n-1)\nend\ns = gets\nret = 1\nq = s.count('?')\nc = 10\nfor i in 'A'..'J'\n if s.index(i)\n ret *= c\n c -= 1\n end\nend\nret *= (10 ** q)\nif s[0] == '?' || (s[0] >= 'A' && s[0] <= 'J')\n ret = ret / 10 * 9\nend\nputs ret"}, {"source_code": "t = STDIN.gets\ndef ppp(start,lcounter)\n return start if lcounter == 1\n return 1 if lcounter < 1\n start*ppp(start-1, lcounter -1)\nend\nh = []\nk = []\nqcounter = 0\n\nt.size.times do |i|\n if t[i] =~ /[A-J]/\n h << t[i] if not h.include? t[i]\n end\n if '0123456789'.include? t[i]\n k << t[i] if not k.include? t[i]\n end\n qcounter = qcounter + 1 if t[i] == '?'\nend \n\np = h.count\np = 0 if p < 0\npp = 10 \n\n\nres = ((t[0] =~ /[A-J]/) ? ppp(pp-1, p-1)*(pp-1) : ppp(pp, p))* ((t[0] == '?') ? (10)**(qcounter - 1)*9 : (10)**qcounter) \nputs res"}], "negative_code": [{"source_code": "#!/usr/bin/ruby\nh={}\nf=10\nx=1\ngets.chomp.each_char.with_index{|c,i|\n\tif i==0&&!('0'..'9').include?(c)\n\t\tf=9\n\tend\n\tif c=='?'\n\t\tx*=10\n\telsif ('A'..'J').include?(c)\n\t\th[c]=1\n\tend\n}\np x*(11-h.size..10).reduce(1,:*)/10*f"}], "src_uid": "d3c10d1b1a17ad018359e2dab80d2b82"} {"nl": {"description": "Let's consider equation:x2\u2009+\u2009s(x)\u00b7x\u2009-\u2009n\u2009=\u20090,\u2009 where x,\u2009n are positive integers, s(x) is the function, equal to the sum of digits of number x in the decimal number system.You are given an integer n, find the smallest positive integer root of equation x, or else determine that there are no such roots.", "input_spec": "A single line contains integer n (1\u2009\u2264\u2009n\u2009\u2264\u20091018) \u2014 the equation parameter. Please, do not use the %lld specifier to read or write 64-bit integers in \u0421++. It is preferred to use cin, cout streams or the %I64d specifier. ", "output_spec": "Print -1, if the equation doesn't have integer positive roots. Otherwise print such smallest integer x (x\u2009>\u20090), that the equation given in the statement holds.", "sample_inputs": ["2", "110", "4"], "sample_outputs": ["1", "10", "-1"], "notes": "NoteIn the first test case x\u2009=\u20091 is the minimum root. As s(1)\u2009=\u20091 and 12\u2009+\u20091\u00b71\u2009-\u20092\u2009=\u20090.In the second test case x\u2009=\u200910 is the minimum root. As s(10)\u2009=\u20091\u2009+\u20090\u2009=\u20091 and 102\u2009+\u20091\u00b710\u2009-\u2009110\u2009=\u20090.In the third test case the equation has no roots."}, "positive_code": [{"source_code": "n=gets.to_i\nx=Math.sqrt(n).round-200\nfor y in 1..400 do\n\tsum=0\n\tstr=x.to_s\n\tfor i in 0..str.size do\n\t\tsum+=str[i].to_i end;\n\tif x*(x+sum)==n and x>0\n\t\tputs x\n\t\tbreak\n\tend\n\tx+=1\n\tprint -1 if y==400\n\tend\n"}, {"source_code": "def s(x)\n res = 0\n until x == 0\n res += x%10\n x /= 10\n end\n return res\nend\n\nn = gets.to_i\nx = Math.sqrt(n).floor\nnotfound = true\nfor i in [x-100000, 1].max..x\n if i**2 + s(i)*i - n == 0\n print i\n notfound = false\n break\n end\nend\n\nprint -1 if notfound"}, {"source_code": "#!/usr/bin/ruby2.0\n\nn = STDIN.readline.to_i\n\ncandidates = []\n\n(1..162).each do |b|\n\tx = (-b + (b*b + 4*n)**0.5) / 2\n\tx = x.round\n\tnext if x*x + b*x != n\n\tt, sum = x, 0\n\twhile t != 0\n\t\tsum += t%10\n\t\tt /= 10\n\tend\n\tnext if sum != b\n\tcandidates.push(x)\nend\n\nif candidates.length == 0\n\tputs -1\nelse\n\tputs candidates.sort[0]\nend\n"}, {"source_code": "#!/usr/bin/ruby2.0\n\nn = STDIN.readline.to_i\n\ncandidates = []\n\n(1..162).each do |c|\n\tlow, high = 1, n\n\twhile high-low > 1e-6\n\t\tmid = (low+high)/2.0\n\t\tif n/mid - mid > c\n\t\t\tlow = mid\n\t\telse\n\t\t\thigh = mid\n\t\tend\n\tend\n\tx = mid.round\n\tnext if n != c*x + x*x\n\tt = x\n\ttotal = 0\n\twhile t != 0\n\t\ttotal += t%10\n\t\tt /= 10\n\tend\n\tif total == c\n\t\tcandidates.push(x)\n\tend\nend\n\nif candidates.length == 0\n\tputs -1\nelse\n\tputs candidates.sort[0]\nend\n"}, {"source_code": "n=gets.chomp.to_i\nx=Math.sqrt(n).round\nx-=200\nfor y in 1..400 do\n\tsum=0\n\tstr=x.to_s\n\tfor i in 0..str.size do\n\t\tsum+=str[i].to_i end;\n\tif x>0 and x*(x+sum)==n\n\t\tputs x\n\t\tbreak\n\tend\n\tx+=1\n\tprint -1 if y==400\nend"}, {"source_code": "n = gets.to_i\nx = Math.sqrt(n).round - 200\n0.upto(400) do\n sum = 0\n str = x.to_s\n 0.upto(str.size) do |i|\n sum += str[i].to_i\n end\n if x * (x + sum) == n and x > 0\n puts str\n exit\n end\n x += 1\nend\nputs -1"}, {"source_code": "n = gets.to_i\n\ndef s(x)\n sum = 0\n x.to_s.each_byte { |c| sum += c - 48 }\n sum\nend\n\ndef sqrt(y)\n lo, hi = 1, y\n while lo <= hi do\n mid = (lo + hi) / 2\n return mid if mid * mid == y\n lo = mid + 1 if mid * mid < y\n hi = mid - 1 if mid * mid > y\n end\n return -1\nend\n\nans = []\n\nfor i in 1..81 do\n t = sqrt(i * i + 4 * n) \n if t != -1 then\n if t - i > 0 && (t - i) % 2 == 0 then\n ans << (t - i) / 2 if s((t - i) / 2) == i\n end\n end \nend\n\nif ans.size == 0 then\n puts \"-1\"\nelse\n puts ans.min\nend\n"}, {"source_code": "n = gets.to_i\n\n# while l <= r\n# \tx = l + (r-l)/2\n# \ts = x.to_s.split(\"\").map(&:to_i).inject(0,:+)\n# \tputs x\n# \tif ((x * x) + (s * x) - n) == 0 \n# \t\tans = x\n# \t\tbreak\n# \telse\n# \t\tr = x - 1\n# \tend\n# end\n\n# puts x\nans = false\nmin = n\n(1..90).each do |s|\n\ta = 1\n\tb = s\n\tc = -n\n\td = (b ** 2) - (4 * a * c)\n\tif d >=0\n\t\tr1 = (-b + Math.sqrt(d))/(2 * a)\n\t\tr2 = (-b - Math.sqrt(d))/(2 * a)\n\telsif d == 0\n\t\tr1 = r2 = (-b)/(2 * a)\n\tend\n\t# puts \"sum #{s} roots #{r1} #{r2}\"\n\tif r1 && r2\n\t\tarr = []\n\t\tsum = r1.to_i.to_s.split(\"\").map(&:to_i).inject(0,:+)\n\t\tarr << r1 if r1 % 1 == 0 && r1 > 0 && s == sum\n\t\tsum = r2.to_i.to_s.split(\"\").map(&:to_i).inject(0,:+)\n\t\tarr << r2 if r2 % 1 == 0 && r2 > 0 && s == sum\n\t\tunless arr.empty?\n\t\t# puts \"s #{s} ar #{r1} #{r2}\"\n\t\t\tval = arr.min \n\t\t\tmin = val if val && val < min\n\t\t\t# puts \"#{val}\"\n\t\t\tans = true\n\t\tend\n\tend\nend\nif ans\n\tif min == 999959999\n\t\tputs -1\n\telse\n\tputs min.to_i\n\tend\nelse\n\tputs \"-1\"\nend"}, {"source_code": "def s(x)\n sum = 0\n while x>0\n sum+= x%10\n x /= 10\n end\n sum\nend\n\nn = gets.to_i\nx = Math.sqrt(n).round - 160;\n\n321.times do |i|\n if x*(x+s(x))==n && x > 0\n puts x\n exit\n end\n x+=1\nend\nputs -1\n"}, {"source_code": "EPS=1e-9\ndef s(x)\n\tret=0\n\twhile x>0\n\t\tret+=x%10\n\t\tx/=10\n\tend\n\tret\nend\n\ndef is_int?(_x)\n\tx=_x.round\n\t(x-EPS<=_x)&&(_x<=x+EPS)\nend\n\nn=gets.to_i\nans=100.times.map{|s|\n\t_x=(-s+(s*s+4*n)**0.5)/2.0\n\tif is_int?(_x)\n\t\tx=_x.round\n\t\tif x*x+s(x)*x-n==0\n\t\t\tx\n\t\telse\n\t\t\tnil\n\t\tend\n\telse\n\t\tnil\n\tend\n}\n\np ans.any? ? ans.compact.min : -1"}], "negative_code": [{"source_code": "n=gets.to_i\nx=n**0.5.round-200\nfor y in 1..400 do\n\tsum=0\n\tstr=x.to_s\n\tfor i in 0..str.size do\n\t\tsum+=str[i].to_i end;\n\tif x*(x+sum)==n\n\t\tputs x\n\t\tbreak\n\tend\n\tx+=1\n\tprint -1 if y==400\n\tend\n"}, {"source_code": "#!/usr/bin/ruby2.0\n\nn = STDIN.readline.to_i\n\ncandidates = []\n\n(1..162).each do |c|\n\tlow, high = 1, n\n\twhile high-low > 1e-6\n\t\tmid = (low+high)/2.0\n\t\tif n/mid - mid > c\n\t\t\tlow = mid\n\t\telse\n\t\t\thigh = mid\n\t\tend\n\tend\n\tx = mid.round\n\tt = x\n\ttotal = 0\n\twhile t != 0\n\t\ttotal += t%10\n\t\tt /= 10\n\tend\n\tif total == c\n\t\tcandidates.push(x)\n\tend\nend\n\nif candidates.length == 0\n\tputs -1\nelse\n\tputs candidates.sort[0]\nend\n"}, {"source_code": "n = gets.to_i\n\n# while l <= r\n# \tx = l + (r-l)/2\n# \ts = x.to_s.split(\"\").map(&:to_i).inject(0,:+)\n# \tputs x\n# \tif ((x * x) + (s * x) - n) == 0 \n# \t\tans = x\n# \t\tbreak\n# \telse\n# \t\tr = x - 1\n# \tend\n# end\n\n# puts x\nans = false\nmin = n\n(1..90).each do |s|\n\ta = 1\n\tb = s\n\tc = -n\n\td = (b ** 2) - (4 * a * c)\n\tif d >=0\n\t\tr1 = (-b + Math.sqrt(d))/(2 * a)\n\t\tr2 = (-b - Math.sqrt(d))/(2 * a)\n\telsif d == 0\n\t\tr1 = r2 = (-b)/(2 * a)\n\tend\n\t# puts \"sum #{s} roots #{r1} #{r2}\"\n\tif r1 && r2\n\t\tarr = []\n\t\tsum = r1.to_i.to_s.split(\"\").map(&:to_i).inject(0,:+)\n\t\tarr << r1 if r1 % 1 == 0 && s == sum\n\t\tsum = r2.to_i.to_s.split(\"\").map(&:to_i).inject(0,:+)\n\t\tarr << r2 if r2 % 1 == 0 && s == sum\n\t\t# puts \"sum #{s} #{arr}\"\n\t\tval = arr.min \n\t\tmin = val if val && val > 0 && val < min\n\t\tans = true\n\tend\nend\nif ans\nputs min.to_i\nelse\n\tputs \"-1\"\nend"}, {"source_code": "n = gets.to_i\n\n# while l <= r\n# \tx = l + (r-l)/2\n# \ts = x.to_s.split(\"\").map(&:to_i).inject(0,:+)\n# \tputs x\n# \tif ((x * x) + (s * x) - n) == 0 \n# \t\tans = x\n# \t\tbreak\n# \telse\n# \t\tr = x - 1\n# \tend\n# end\n\n# puts x\nans = false\nmin = n\n(1..90).each do |s|\n\ta = 1\n\tb = s\n\tc = -n\n\td = (b ** 2) - (4 * a * c)\n\tif d >=0\n\t\tr1 = (-b + Math.sqrt(d))/(2 * a)\n\t\tr2 = (-b - Math.sqrt(d))/(2 * a)\n\telsif d == 0\n\t\tr1 = r2 = (-b)/(2 * a)\n\tend\n\t# puts \"sum #{s} roots #{r1} #{r2}\"\n\tif r1 && r2\n\t\tarr = []\n\t\tsum = r1.to_i.to_s.split(\"\").map(&:to_i).inject(0,:+)\n\t\tarr << r1 if r1 % 1 == 0 && r1 > 0 && s == sum\n\t\tsum = r2.to_i.to_s.split(\"\").map(&:to_i).inject(0,:+)\n\t\tarr << r2 if r2 % 1 == 0 && r2 > 0 && s == sum\n\t\tunless arr.empty?\n\t\t# puts \"ar #{arr}\"\n\t\t\tval = arr.min \n\t\t\tmin = val if val && val < min\n\t\t\t# puts \"#{val}\"\n\t\t\tans = true\n\t\tend\n\tend\nend\nif ans\n\tputs min.to_i\nelse\n\tputs \"-1\"\nend"}, {"source_code": "n = gets.to_i\n\n# while l <= r\n# \tx = l + (r-l)/2\n# \ts = x.to_s.split(\"\").map(&:to_i).inject(0,:+)\n# \tputs x\n# \tif ((x * x) + (s * x) - n) == 0 \n# \t\tans = x\n# \t\tbreak\n# \telse\n# \t\tr = x - 1\n# \tend\n# end\n\n# puts x\nans = false\nmin = n\n(1..90).each do |s|\n\ta = 1\n\tb = s\n\tc = -n\n\td = (b ** 2) - (4 * a * c)\n\tif d >=0\n\t\tr1 = (-b + Math.sqrt(d))/(2 * a)\n\t\tr2 = (-b - Math.sqrt(d))/(2 * a)\n\telsif d == 0\n\t\tr1 = r2 = (-b)/(2 * a)\n\tend\n\t# puts \"sum #{s} roots #{r1} #{r2}\"\n\tif r1 && r2\n\t\tarr = []\n\t\tsum = r1.to_i.to_s.split(\"\").map(&:to_i).inject(0,:+)\n\t\tarr << r1 if r1 % 1 == 0 && s == sum\n\t\tsum = r2.to_i.to_s.split(\"\").map(&:to_i).inject(0,:+)\n\t\tarr << r2 if r2 % 1 == 0 && s == sum\n\t\tunless arr.empty?\n\t\t\tval = arr.min \n\t\t\tmin = val if val && val > 0 && val < min\n\t\t\tans = true\n\t\tend\n\tend\nend\nif ans\n\tputs min.to_i\nelse\n\tputs \"-1\"\nend"}, {"source_code": "n = gets.to_i\n\n# while l <= r\n# \tx = l + (r-l)/2\n# \ts = x.to_s.split(\"\").map(&:to_i).inject(0,:+)\n# \tputs x\n# \tif ((x * x) + (s * x) - n) == 0 \n# \t\tans = x\n# \t\tbreak\n# \telse\n# \t\tr = x - 1\n# \tend\n# end\n\n# puts x\nans = false\nmin = n\n(1..90).each do |s|\n\ta = 1\n\tb = s\n\tc = -n\n\td = (b ** 2) - (4 * a * c)\n\tif d >=0\n\t\tr1 = (-b + Math.sqrt(d))/(2 * a)\n\t\tr2 = (-b - Math.sqrt(d))/(2 * a)\n\telsif d == 0\n\t\tr1 = r2 = (-b)/(2 * a)\n\tend\n\t# puts \"sum #{s} roots #{r1} #{r2}\"\n\tif r1 && r2\n\t\tarr = []\n\t\tsum = r1.to_i.to_s.split(\"\").map(&:to_i).inject(0,:+)\n\t\tarr << r1 if r1 % 1 == 0 && r1 > 0 && s == sum\n\t\tsum = r2.to_i.to_s.split(\"\").map(&:to_i).inject(0,:+)\n\t\tarr << r2 if r2 % 1 == 0 && r2 > 0 && s == sum\n\t\tunless arr.empty?\n\t\tputs \"s #{s} ar #{r1} #{r2}\"\n\t\t\tval = arr.min \n\t\t\tmin = val if val && val < min\n\t\t\t# puts \"#{val}\"\n\t\t\tans = true\n\t\tend\n\tend\nend\nif ans\n\tif min == 999959999\n\t\tputs -1\n\telse\n\tputs min.to_i\n\tend\nelse\n\tputs \"-1\"\nend"}, {"source_code": "def s(x)\n sum = 0\n while x>0\n sum+= x%10\n x /= 10\n end\n sum\nend\n\nn = gets.to_i\nx = Math.sqrt(n).round-1\nwhile x*x <= n\n if x*(x+s(x))==n\n puts x\n exit\n end\n x+=1\nend\nputs -1\n"}, {"source_code": "def s(x)\n sum = 0\n while x>0\n sum+= x%10\n x /= 10\n end\n sum\nend\n\nn = gets.to_i\nx = Math.sqrt(n).round - 160;\n\n321.times do |i|\n if x*(x+s(x))==n\n puts x\n exit\n end\n x+=1\nend\nputs -1\n"}, {"source_code": "def s(x)\n sum = 0\n while x>0\n sum+= x%10\n x /= 10\n end\n sum\nend\n\nn = gets.to_i\nx = Math.sqrt(n).round-s(Math.sqrt(n).round)-1\nwhile x*x <= n+s(x)\n if x*(x+s(x))==n\n puts x\n exit\n end\n x+=1\nend\nputs -1\n"}, {"source_code": "def s(x)\n sum = 0\n while x>0\n sum+= x%10\n x /= 10\n end\n sum\nend\n\nn = gets.to_i\nx = Math.sqrt(n).round\n\nwhile x*x <= n\n if x*(x+s(x))==n\n puts x\n exit\n end\n x+=1\nend\nputs -1\n"}, {"source_code": "def s(x)\n\tret=0\n\twhile x>0\n\t\tret+=x%10\n\t\tx/=10\n\tend\n\tret\nend\n\ndef is_int?(_x)\n\tx=_x.round\n\t(x-1e-9<_x)&&(_x0\n\t\tret+=x%10\n\t\tx/=10\n\tend\n\tret\nend\n\ndef is_int?(_x)\n\tx=_x.round\n\t(x-1e-9<_x)&&(_x0\n\t\tret+=x%10\n\t\tx/=10\n\tend\n\tret\nend\n\ndef is_int?(_x)\n\tx=_x.round\n\t(x-1e-19<_x)&&(_x 2\n\tputs \"-1\"\nelse\n\tputs ctr\nend"}, {"source_code": "/(?[\\d]+) (?[\\d]+)/ =~ gets.chomp\na = a.to_i\nb = b.to_i\n\ndef bite(size, mults=[2, 3, 5])\t# => [b*2, b*3, b*5, leftovers || 1]\n\tbitesizes = []\n\tmults.each do |mult|\n\t\tbite = 0\n\t\tbite, size = (bite+1), (size/mult) while (size%mult)==0\n\t\tbitesizes << bite\n\tend\n\tbitesizes << size\n\treturn bitesizes\nend\n\n*bitesA, leftA = bite(a)\n*bitesB, leftB = bite(b)\n\nif (leftA != leftB)\n\tputs -1\nelse\n\tp (bitesA.zip(bitesB).map{ |bA, bB|\n\t\t(bA-bB).abs\n\t}.reduce(&:+))\nend\n"}], "negative_code": [], "src_uid": "75a97f4d85d50ea0e1af0d46f7565b49"} {"nl": {"description": "A necklace can be described as a string of links ('-') and pearls ('o'), with the last link or pearl connected to the first one. You can remove a link or a pearl and insert it between two other existing links or pearls (or between a link and a pearl) on the necklace. This process can be repeated as many times as you like, but you can't throw away any parts.Can you make the number of links between every two adjacent pearls equal? Two pearls are considered to be adjacent if there is no other pearl between them.Note that the final necklace should remain as one circular part of the same length as the initial necklace.", "input_spec": "The only line of input contains a string $$$s$$$ ($$$3 \\leq |s| \\leq 100$$$), representing the necklace, where a dash '-' represents a link and the lowercase English letter 'o' represents a pearl.", "output_spec": "Print \"YES\" if the links and pearls can be rejoined such that the number of links between adjacent pearls is equal. Otherwise print \"NO\". You can print each letter in any case (upper or lower).", "sample_inputs": ["-o-o--", "-o---", "-o---o-", "ooo"], "sample_outputs": ["YES", "YES", "NO", "YES"], "notes": null}, "positive_code": [{"source_code": "s=gets.chomp\nc=s.count(?o)\nputs c>0&&s.size%c>0?:No: :Yes"}, {"source_code": "s=gets.chomp\n\nli=s.count('-')\npe=s.count('o')\n\nif pe==0\n puts 'YES'\nelse\n if li%pe==0\n puts 'YES'\n else\n puts 'NO'\n end\nend"}, {"source_code": "PEARL = 'o'\nLINK = '-'\n\nnecklace = STDIN.gets.chomp\n\ndef adjustable?(necklace)\n pearl_count = necklace.count(PEARL)\n return true if pearl_count == 0\n link_count = necklace.count(LINK)\n\n link_count % pearl_count == 0\nend\n\nif adjustable?(necklace)\n puts 'YES'\nelse\n puts 'NO'\nend\n"}], "negative_code": [{"source_code": "s=gets.chomp\nc=s.count(?o)\nputs c==0||s.size%c>0?:No: :Yes"}, {"source_code": "s=gets.chomp\nc=s.count(?o)\nputs c>0||s.size%c>0?:No: :Yes"}, {"source_code": "PEARL = 'o'\nLINK = '-'\n\nnecklace = STDIN.gets.chomp\n\ndef adjustable?(necklace)\n pearl_count = necklace.count(PEARL)\n if pearl_count == 1\n true\n else\n link_count = necklace.count(LINK)\n link_count % (pearl_count - 1) == 0\n end\nend\n\nif adjustable?(necklace)\n puts 'YES'\nelse\n puts 'NO'\nend\n"}], "src_uid": "6e006ae3df3bcd24755358a5f584ec03"} {"nl": {"description": "Nicholas has an array a that contains n distinct integers from 1 to n. In other words, Nicholas has a permutation of size n.Nicholas want the minimum element (integer 1) and the maximum element (integer n) to be as far as possible from each other. He wants to perform exactly one swap in order to maximize the distance between the minimum and the maximum elements. The distance between two elements is considered to be equal to the absolute difference between their positions.", "input_spec": "The first line of the input contains a single integer n (2\u2009\u2264\u2009n\u2009\u2264\u2009100)\u00a0\u2014 the size of the permutation. The second line of the input contains n distinct integers a1,\u2009a2,\u2009...,\u2009an (1\u2009\u2264\u2009ai\u2009\u2264\u2009n), where ai is equal to the element at the i-th position.", "output_spec": "Print a single integer\u00a0\u2014 the maximum possible distance between the minimum and the maximum elements Nicholas can achieve by performing exactly one swap.", "sample_inputs": ["5\n4 5 1 3 2", "7\n1 6 5 3 4 7 2", "6\n6 5 4 3 2 1"], "sample_outputs": ["3", "6", "5"], "notes": "NoteIn the first sample, one may obtain the optimal answer by swapping elements 1 and 2.In the second sample, the minimum and the maximum elements will be located in the opposite ends of the array if we swap 7 and 2.In the third sample, the distance between the minimum and the maximum elements is already maximum possible, so we just perform some unnecessary swap, for example, one can swap 5 and 2."}, "positive_code": [{"source_code": "n = gets.chomp.to_i\narr = gets.split.map(&:to_i)\n\nfirst = arr.index(1)\nlast = arr.index(n)\nif first == 0 and last == n - 1\n p (n - 1)\nelse\n p [first, last, n - 1 - first, n - 1 - last].max\nend"}, {"source_code": "n=gets.to_i\na,b=gets.split.map(&:to_i).each_with_index.select{|e,i|e==1||e==n}.map(&:last)\np [n-1-a,n-1-b,a,b].map(&:abs).max"}, {"source_code": "n=gets.to_i\na,b=gets.split.map(&:to_i).each_with_index.select{|e,i|e==1||e==n}.map(&:last)\np [n-1-a,n-1-b,a,b].max"}, {"source_code": "def checks(n, arrays)\n arrays = arrays.split.map(&:to_i)\n n = n.to_i\n\n for i in (0..n - 1)\n if arrays[i] == 1\n pos1 = i\n end\n\n if arrays[i] == n\n posn = i\n end\n end\n\n puts [posn, n - 1 - posn, pos1, n - 1 - pos1].max\nend\n\nchecks(gets, gets)"}, {"source_code": "def max (a,b)\n a > b ? a : b \nend\n\nn = gets.to_i\narr = gets.strip.split(' ').map(&:to_i)\n\npos = []\narr.each_with_index do |value, index|\n if 1 == value\n pos.push index\n elsif n == value\n pos.push index\n end\nend\n\nputs max(pos[1], n - pos[0] - 1)\n"}, {"source_code": "n = gets.to_i\narr = gets.strip.split(' ').map(&:to_i)\n\npos = []\narr.each_with_index do |value, index|\n if 1 == value\n pos.push index\n elsif n == value\n pos.push index\n end\nend\n\np [pos[1], n - pos[0] - 1].max\n"}, {"source_code": "class Array\n def swap(a, b)\n clone = self.dup\n clone[a], clone[b] = clone[b], clone[a]\n \n clone\n end\n def max_distance\n (self.index(self.min) - self.index(self.max)).abs\n end\nend\n\nn = gets.chomp.to_i\narr = gets.chomp.split.map(&:to_i)\nresults = []\n\n(0...n).each do |i|\n (0...n).each do |j|\n next if i == j\n results << arr.swap(i, j).max_distance\n end\nend\nputs results.max\n"}, {"source_code": "n = readline.to_i\narr = readline.split(' ').collect(&:to_i)\ni, j = arr.index(1), arr.index(n)\nputs [[i, n - i - 1].max, [j, n - j - 1].max].max\n"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split(/ /).map(&:to_i)\nmin_element = a.min\nmax_element = a.max\npos_min = a.index min_element\npos_max = a.index max_element\nstart_min_dist = pos_min\nstart_max_dist = pos_max\nend_min_dist = n - pos_min - 1\nend_max_dist = n - pos_max - 1\nputs [start_min_dist, start_max_dist, end_min_dist, end_max_dist].max\n"}, {"source_code": "n=gets.to_i\na=gets.split.map{|e| e.to_i}\nb=a.index(1)\nc=a.index(n)\nb1=[b,c].min\nc1=[b,c].max\nn-=1\nif b1==0 || c1==n then\n\tputs n\nelse\n\tputs [c1,n-b1].max\nend\n\n"}, {"source_code": "n = gets.to_i\n\nnumbers = gets\n\nres = numbers.split(' ')\n\np_max = -1\np_min = -1\n\nres.each_with_index do |r,i|\n if (r.to_i == 1) \n p_min = i + 1\n end\n if (r.to_i == n)\n p_max = i + 1\n end\nend\n\nif (p_max < p_min)\n t = p_max\n p_max = p_min\n p_min = t\nend\nputs (n-p_min>p_max-1)? n-p_min : p_max - 1\n"}, {"source_code": "gets;a=gets.split.map(&:to_i);puts [[a.find_index(a.max), (a.size-a.find_index(a.max)-1).abs].max, [a.find_index(a.min), (a.size-a.find_index(a.min)-1).abs].max].max"}, {"source_code": "n=gets.to_i;a=gets.split.map(&:to_i);(amax,amin)=[a.find_index(a.max),a.find_index(a.min)];puts [amax, n-amax-1, amin, n-amin-1].max"}, {"source_code": "n=gets.to_i;a=gets.split.map(&:to_i);puts [a.index(n), n-a.index(n)-1, a.index(1), n-a.index(1)-1].max"}, {"source_code": "n = gets.chomp.to_i\nas = gets.chomp.split.map(&:to_i)\n\nif n <= 3\n puts n - 1\nelse\n i = as.index(1)\n j = as.index(n)\n ans = (i - j).abs\n ans = [ans, n - 1 - [i, j].min].max\n ans = [ans, [i, j].max].max\n puts ans\nend\n"}, {"source_code": "n = gets.chomp.to_i\nnums = gets.split.map(&:to_i)\n\nfor i in 0...n\n\tbiggest = i + 1 if n == nums[i]\n\tsmallest = i + 1 if 1 == nums[i]\nend\n\nputs [n - [smallest, biggest].min, [smallest, biggest].max - 1].max\n\n=begin\n7\n1 \n6 \n5 \n3 \n4 \n7 \n2\n\n6\n6 \n5 \n4 \n3 \n2 \n1\n\n3\n2 3 1\n\n\n=end"}, {"source_code": "n = 0\nnums = Array.new\n\n\n\nbiggest = 0\nsmallest = 100\n\nn = gets.chomp.to_i\nnums = gets.split.map(&:to_i)\n\n#p nums\n#puts n\n#puts nums.last\n\nfor i in 0..n\n\t#nums.push($stdin.read.chomp.to_i) \n\t#thing = gets.chomp.split('|')[1].scan(/\\d+/).map{|n| n.to_i}\n\tif n == nums[i]\n\t\tbiggest = i + 1\n\tend\n\tif 1 == nums[i]\n\t\tsmallest = i + 1\n\tend\nend\n\n#puts \"Biggest: #{biggest}, smallest: #{smallest}\\n\\n\"\n\nputs [n - [smallest, biggest].min, [smallest, biggest].max - 1].max\n\n=begin\n7\n1 \n6 \n5 \n3 \n4 \n7 \n2\n\n6\n6 \n5 \n4 \n3 \n2 \n1\n\n3\n2 3 1\n\n\n=end"}, {"source_code": "n = gets.to_i\nd = gets.split.map(&:to_i)\n\np (d.index(1)-d.index(n)).abs + [[d.index(1),d.index(n)].min,n-1-[d.index(1),d.index(n)].max].max"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nb = [a.index(1), a.index(n)].sort\nputs [n - 1 - b[0], b[1]].max\n"}, {"source_code": "size_of_permutation = gets.chomp.to_i\nintegers_array = gets.chomp.split.map(&:to_i)\n\ndef max_distance(size, list)\n min_index = nil\n max_index = nil\n\n for i in 0..(list.length - 1)\n min_index = i if list[i] == 1\n max_index = i if list[i] == size\n\n if min_index && max_index\n break\n end\n end\n\n potential_distance = [min_index, max_index, size - 1 - min_index, size - 1 - max_index]\n max_distance = potential_distance[0]\n for i in potential_distance\n if i > max_distance\n max_distance = i\n end\n end\n max_distance\nend\n\nputs max_distance(size_of_permutation, integers_array)\n"}, {"source_code": "size_of_permutation = gets.chomp.to_i\nintegers_array = gets.chomp.split.map(&:to_i)\n\ndef max_distance(size, list)\n min, max = list[0], list[0]\n min_index = 0\n max_index = 0\n\n for i in 0..(list.length - 1)\n if list[i] < min\n min = list[i]\n min_index = i\n end\n\n if list[i] > max\n max = list[i]\n max_index = i\n end\n end\n\n potential_distance = [min_index, max_index, size - 1 - min_index, size - 1 - max_index]\n max_distance = potential_distance[0]\n for i in potential_distance\n if i > max_distance\n max_distance = i\n end\n end\n max_distance\nend\n\nputs max_distance(size_of_permutation, integers_array)\n"}, {"source_code": "arrLen = gets.chomp.to_i\narr = gets.chomp.split(' ').map { |i| i.to_i }\n\nminIdx = arr.index { |i| i == arr.min}\nmaxIdx = arr.index { |i| i == arr.max}\n\nbiggerIdx = minIdx > maxIdx ? minIdx : maxIdx\nnonBiggerIdx = minIdx < maxIdx ? minIdx : maxIdx\n\ncandidate_1 = (arrLen - 1) - nonBiggerIdx\ncandidate_2 = (arrLen - 1) - biggerIdx\ncandidate_3 = nonBiggerIdx - 0\ncandidate_4 = biggerIdx - 0\n\nans = Array.new\nans << candidate_1\nans << candidate_2\nans << candidate_3\nans << candidate_4\n\nputs ans.max"}], "negative_code": [{"source_code": "n = gets.chomp.to_i\narr = gets.split.map(&:to_i)\n\nfirst = arr.index(1)\np first\nlast = arr.index(n)\nif first == 0 and last == n - 1\n p (n - 1)\nelse\n p [first, last, n - 1 - first, n - 1 - last].max\nend"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split(/ /).map(&:to_i)\nmin_element = a.min\nmax_element = a.max\npos_min = a.index min_element\npos_max = a.index max_element\nif pos_min > pos_max\n pos_min = n - 1\nelsif pos_max > pos_min\n pos_max = n - 1\nend\ndist = (pos_min - pos_max).abs\nputs dist\n"}, {"source_code": "n = gets.to_i\n\nnumbers = gets\n\nres = numbers.split(' ')\n\np_max = -1\np_min = -1\n\nres.each_with_index do |r,i|\n if (r.to_i == 1) \n p_min = i + 1\n end\n if (r.to_i == n)\n p_max = i + 1\n end\nend\n\nif (p_max < p_min)\n t = p_max\n p_max = p_min\n p_min = t\nend\nputs (n-p_min>p_max)? n-p_min : p_max\n"}, {"source_code": "n = 0\nnums = Array.new\n\n\n\nbiggest = 0\nsmallest = 100\n\nn = gets.chomp.to_i\nnums = gets.split.map(&:to_i)\n\n#p nums\n#puts n\n#puts nums.last\n\nfor i in 0..n\n\t#nums.push($stdin.read.chomp.to_i) \n\t#thing = gets.chomp.split('|')[1].scan(/\\d+/).map{|n| n.to_i}\n\tif n == nums[i]\n\t\tbiggest = i + 1\n\tend\n\tif 1 == nums[i]\n\t\tsmallest = i + 1\n\tend\nend\n\n#puts \"Biggest: #{biggest}, smallest: #{smallest}\\n\\n\"\n\nputs [n - [smallest, biggest].min, [smallest, biggest].min - 1].max\n\n=begin\n7\n1 \n6 \n5 \n3 \n4 \n7 \n2\n\n6\n6 \n5 \n4 \n3 \n2 \n1\n\n=end"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nb = [a.index(1), a.index(n)].sort\nputs [n - b[0], b[1]].max - 1\n"}, {"source_code": "size_of_permutation = gets.chomp.to_i\nintegers_array = gets.chomp.split.map(&:to_i)\n\ndef max_distance(size, list)\n min, max = list[0], list[0]\n min_index = 0\n max_index = 0\n\n for i in 0..(list.length - 1)\n if list[i] < min\n min = list[i]\n min_index = i\n end\n\n if list[i] > max\n max = list[i]\n max_index = i\n end\n end\n\n if min_index == 0 || max_index == 0 || min_index == size - 1 || max_index == size - 1\n return size - 1\n end\n\n min_index < max_index ? size - 1 - min_index : size - 1 - max_index\nend\n\nputs max_distance(size_of_permutation, integers_array)\n"}, {"source_code": "size_of_permutation = gets.chomp.to_i\nintegers_array = gets.chomp.split.map(&:to_i)\n\ndef max_distance(size, list)\n min, max = list[0], list[0]\n min_index = 0\n max_index = 0\n\n for i in 0..(list.length - 1)\n if list[i] < min\n min = list[i]\n min_index = i\n end\n\n if list[i] > max\n max = list[i]\n max_index = i\n end\n end\n\n max_distance = min_index < max_index ? size - 1 - min_index : size - 1 - max_index\nend\n\nputs max_distance(size_of_permutation, integers_array)\n"}, {"source_code": "arrLen = gets.chomp.to_i\narr = gets.chomp.split(' ').map { |i| i.to_i }\n\nminIdx = arr.index { |i| i == arr.min}\nmaxIdx = arr.index { |i| i == arr.max}\n\nbiggerIdx = minIdx > maxIdx ? minIdx : maxIdx\nnonBiggerIdx = minIdx < maxIdx ? minIdx : maxIdx\n\nans = if (arrLen - biggerIdx) > (nonBiggerIdx - 0)\n\tarrLen - nonBiggerIdx\nelse\n\tbiggerIdx - 0\nend\n\nputs ans - 1"}], "src_uid": "1d2b81ce842f8c97656d96bddff4e8b4"} {"nl": {"description": "Jabber ID on the national Berland service \u00abBabber\u00bb has a form <username>@<hostname>[/resource], where <username> \u2014 is a sequence of Latin letters (lowercase or uppercase), digits or underscores characters \u00ab_\u00bb, the length of <username> is between 1 and 16, inclusive. <hostname> \u2014 is a sequence of word separated by periods (characters \u00ab.\u00bb), where each word should contain only characters allowed for <username>, the length of each word is between 1 and 16, inclusive. The length of <hostname> is between 1 and 32, inclusive. <resource> \u2014 is a sequence of Latin letters (lowercase or uppercase), digits or underscores characters \u00ab_\u00bb, the length of <resource> is between 1 and 16, inclusive. The content of square brackets is optional \u2014 it can be present or can be absent.There are the samples of correct Jabber IDs: mike@codeforces.com, 007@en.codeforces.com/contest.Your task is to write program which checks if given string is a correct Jabber ID.", "input_spec": "The input contains of a single line. The line has the length between 1 and 100 characters, inclusive. Each characters has ASCII-code between 33 and 127, inclusive.", "output_spec": "Print YES or NO.", "sample_inputs": ["mike@codeforces.com", "john.smith@codeforces.ru/contest.icpc/12"], "sample_outputs": ["YES", "NO"], "notes": null}, "positive_code": [{"source_code": "a=\"YES\"\ns=gets.chomp\nunless s=~/^(\\w{1,16})@([\\w\\.]{1,32})\\/(\\w{1,16})$/ || s=~/^(\\w{1,16})@([\\w\\.]{1,32})$/ then a=\"NO\"\nelse $2.split(\".\",-1).each{|s|if s.length==0||s.length>16 then a=\"NO\" end}\nend\nputs a"}, {"source_code": "puts gets=~/^\\w{1,16}@\\w{1,16}(\\.\\w{1,16})*(\\/\\w{1,16})?\\n$/?\"YES\":\"NO\""}, {"source_code": "puts gets =~ /^[\\w_]{1,16}@[\\w_.]{1,32}(\\/[\\w_]{1,16})?$/ && $_ !~ /[@.]\\.|\\.\\/|\\.$/ ? :YES : :NO\n"}, {"source_code": "r = /[\\w_]{1,16}/\nputs gets =~ /^#{r}@(#{r}(\\.#{r})*)(\\/#{r})?$/ && $1.size <= 32 ? :YES : :NO\n"}, {"source_code": "str = gets.strip!\nre_pattern = /^\\w{1,16}@(\\w{1,16}(\\.\\w{1,16})*)(\\/\\w{1,16})?$/\nif str.match(re_pattern) && $1.size <= 32\n\tputs 'YES'\nelse\n\tputs 'NO'\nend"}, {"source_code": "str = gets.strip!\nre_pattern = /^\\w{1,16}@\\w{1,16}(\\.\\w{1,16})*(\\/\\w{1,16})?$/\nif str.match(re_pattern)\n\tputs 'YES'\nelse\n\tputs 'NO'\nend"}, {"source_code": "puts gets=~/^\\w{1,16}@\\w{1,16}(\\.\\w{1,16})*(\\/\\w{1,16})?\\n$/?\"YES\":\"NO\"\n"}, {"source_code": "puts gets=~/^\\w{1,16}@\\w{1,16}(\\.\\w{1,16})*(\\/\\w{1,16})?\\n$/?\"YES\":\"NO\"\n"}, {"source_code": "puts gets=~/^\\w{1,16}@\\w{1,16}(\\.\\w{1,16})*(\\/\\w{1,16})?\\n$/?\"YES\":\"NO\""}, {"source_code": "puts gets=~/^\\w{1,16}@\\w{1,16}(\\.\\w{1,16})*(\\/\\w{1,16})?\\n$/?\"YES\":\"NO\""}, {"source_code": "puts gets=~/^\\w{1,16}@\\w{1,16}(\\.\\w{1,16})*(\\/\\w{1,16})?\\n$/?\"YES\":\"NO\"\n"}, {"source_code": "puts gets=~/^\\w{1,16}@\\w{1,16}(\\.\\w{1,16})*(\\/\\w{1,16})?\\n$/?\"YES\":\"NO\"\n"}, {"source_code": "puts gets=~/^\\w{1,16}@\\w{1,16}(\\.\\w{1,16})*(\\/\\w{1,16})?\\n$/?\"YES\":\"NO\""}, {"source_code": "puts gets=~/^\\w{1,16}@\\w{1,16}(\\.\\w{1,16})*(\\/\\w{1,16})?\\n$/?\"YES\":\"NO\""}, {"source_code": "def valid_word?(s)\n s =~ /^[_a-zA-Z0-9_]{1,16}$/\nend\n\ndef solve(s)\n \n words = (s + '.a').split(/[.@\\/]/)\n words.pop\n return false unless words.all? { |w| valid_word? w }\n\n wr = '[_a-zA-Z0-9_]{1,16}' # word regex\n rr = '[_a-zA-Z0-9_.]{1,32}' # resource regex\n \n return s =~ Regexp.new(\"^#{wr}@#{wr}(\\\\.#{wr})*(\\\\/#{wr})?\") &&\n s =~ Regexp.new(\"^#{wr}@#{rr}(\\\\/#{wr})?\")\n\nend\n\ns = gets.chomp\n#s = 'mike@codeforces.com'\n#s = 'john.smith@codeforces.ru/contest.icpc/12'\n#s = '007@en.codeforces.com/contest'\nputs solve(s) ? 'YES' : 'NO'"}, {"source_code": "puts gets=~/^\\w{1,16}@\\w{1,16}(\\.\\w{1,16})*(\\/\\w{1,16})?\\n$/?\"YES\":\"NO\"\n"}, {"source_code": "puts gets =~ /^\\w{1,16}@\\w{1,16}(\\.\\w{1,16})*(\\/\\w{1,16})*$/ ? \"YES\" : \"NO\"\n"}, {"source_code": "puts (gets =~ /^\\w{1,16}@(\\w{1,16}(\\.\\w{1,16})*)(\\/\\w{1,16})*$/ && $1.size <= 32) ? \"YES\" : \"NO\"\n\n"}, {"source_code": "if gets.strip =~ %r{^([0-9a-zA-Z_]{1,16})@([0-9a-zA-Z_]{1,16}(\\.[0-9a-zA-Z_]{1,16})*)((/[0-9a-zA-Z_]{1,16})?)$} && $2.length >= 1 && $2.length <= 32 \n puts \"YES\"\nelse\n puts \"NO\"\nend"}, {"source_code": "s = gets.strip\nunless s =~ %r{^([0-9a-zA-Z_]{1,16})@([0-9a-zA-Z_]{1,16}(\\.[0-9a-zA-Z_]{1,16})*)((/[0-9a-zA-Z_]{1,16})?)$}\n puts \"NO\"\n exit 0\nend\n#puts $1, $2, $3, $4\nusername, hostname, resource = $1, $2, $4\n\nif hostname.length >= 1 && hostname.length <= 32\n puts \"YES\"\nelse\n puts \"NO\"\nend\n"}, {"source_code": "puts(if gets.strip =~ %r{^([0-9a-zA-Z_]{1,16})@([0-9a-zA-Z_]{1,16}(\\.[0-9a-zA-Z_]{1,16})*)((/[0-9a-zA-Z_]{1,16})?)$} && $2.length <= 32\n\"YES\" else \"NO\" end)"}, {"source_code": "def user_ok(s)\n s.length >= 1 && s.length <= 16 && s =~ /^[0-9a-zA-Z_]*$/\nend\n\ndef host_ok(s)\n# puts s\n if s.length < 1 || s.length > 32\n return false\n end \n if s[0] == \".\" || s[-1] == \".\"\n return false\n end\n for st in s.split(\".\") do\n# puts st\n unless user_ok(st)\n return false\n end\n end\n true\nend\n\ns = gets.strip\nok = true\nunless s =~ %r{^([^@]+)@([^/]+)((/[0-9a-zA-Z_]*)?)$}\n puts \"NO\"\n exit 0\nend\nusername, hostname, resource = $1, $2, $3\nunless user_ok(username) && host_ok(hostname)\n ok = false\nend\n\nif resource.length == 1 || resource.length > 17\n ok = false\nend\n\nif ok\n puts \"YES\"\nelse\n puts \"NO\"\nend\n"}, {"source_code": "puts gets=~/^\\w{1,16}@\\w{1,16}(\\.\\w{1,16})*(\\/\\w{1,16})?\\n$/?\"YES\":\"NO\"\n"}, {"source_code": "puts gets=~/^\\w{1,16}@\\w{1,16}(\\.\\w{1,16})*(\\/\\w{1,16})?\\n$/?\"YES\":\"NO\""}, {"source_code": "puts gets=~/^\\w{1,16}@\\w{1,16}(\\.\\w{1,16})*(\\/\\w{1,16})?\\n$/?\"YES\":\"NO\"\n"}, {"source_code": "puts gets=~/^\\w{1,16}@\\w{1,16}(\\.\\w{1,16})*(\\/\\w{1,16})?\\n$/?\"YES\":\"NO\"\n"}, {"source_code": "s = gets.strip\nif !s.include?( '/' )\n\ts += \"/a\"\nend\nputs /^\\w{1,16}@\\w{1,16}(\\.\\w{1,16})*\\/\\w{1,16}$/ =~ s && s.index( \"/\" ) - s.index( \"@\" ) - 1 <= 32 ? \"YES\" : \"NO\"\n"}, {"source_code": "def del(s)\n return s.delete(\"abcdefghijklmnopqrstuvwxyz_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ\")\nend\n\ns = gets.chomp\nresult = \"YES\"\nif (k = s.index(\"@\")) then\n if s[0...k].size < 1 then\n result = \"NO\"\n end\n user = del(s[0...k])\n if user.size > 0 then\n result = \"NO\"\n end\n if (n = s.index(\"/\")) then\n host = s[k+1...n]\n resource = s[n+1..-1]\n else\n host = s[k+1..-1]\n resource = nil\n end\n if host.size < 1 then\n result = \"NO\"\n end\n k = -1\n while (m = host.index(\".\", k+1)) do\n if m-k > 17 || m-k < 2 then\n result = \"NO\"\n end\n k = m\n end\n host = del(host).delete(\".\")\n if host.size > 0 then\n result = \"NO\"\n end\n\n if resource then\n if s[n-1] == \".\" then\n result = \"NO\"\n end\n if resource.size > 16 || resource.size < 1 then \n result = \"NO\"\n else\n resource = del(resource)\n if resource.size > 0 then\n result = \"NO\"\n end\n end\n else\n if s[-1] == \".\" then\n result = \"NO\"\n end\n end\nelse\n result = \"NO\"\nend\n\nputs result"}], "negative_code": [{"source_code": "def del(s)\n return s.delete(\"abcdefghijklmnopqrstuvwxyz_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ\")\nend\n\ns = gets.chomp\nresult = \"YES\"\nif (k = s.index(\"@\")) then\n if s[0...k].size < 1 then\n result = \"NO\"\n end\n user = del(s[0...k])\n if user.size > 0 then\n result = \"NO\"\n end\n if (n = s.index(\"/\")) then\n host = s[k+1...n]\n resource = s[n+1..-1]\n else\n host = s[k+1..-1]\n resource = nil\n end\n if host.size < 1 then\n result = \"NO\"\n end\n k = -1\n while (m = host.index(\".\", k+1)) do\n if m-k > 16 then\n result = \"NO\"\n end\n k = m\n end\n host = del(host).delete(\".\")\n if host.size > 0 then\n result = \"NO\"\n end\n\n if resource then\n if s[n] == \".\" then\n result = \"NO\"\n end\n if resource.size > 16 then \n result = \"NO\"\n else\n resource = del(resource)\n if resource.size > 0 then\n result = \"NO\"\n end\n end\n else\n if s[-1] == \".\" then\n result = \"NO\"\n end\n end\nelse\n result = \"NO\"\nend\n\nputs result"}, {"source_code": "def del(s)\n return s.delete(\"abcdefghijklmnopqrstuvwxyz_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ\")\nend\n\ns = gets.chomp\nresult = \"YES\"\nif (k = s.index(\"@\")) then\n if s[0...k].size < 1 then\n result = \"NO\"\n end\n user = del(s[0...k])\n if user.size > 0 then\n result = \"NO\"\n end\n if (n = s.index(\"/\")) then\n host = s[k+1...n]\n resource = s[n+1..-1]\n else\n host = s[k+1..-1]\n resource = nil\n end\n if host.size < 1 then\n result = \"NO\"\n end\n k = -1\n while (m = host.index(\".\", k+1)) do\n if m-k > 16 then\n result = \"NO\"\n end\n k = m\n end\n host = del(host).delete(\".\")\n if host.size > 0 then\n result = \"NO\"\n end\n\n if resource then\n if resource.size > 16 then \n result = \"NO\"\n else\n resource = del(resource)\n if resource.size > 0 then\n result = \"NO\"\n end\n end\n end\nelse\n result = \"NO\"\nend\n\nputs result"}, {"source_code": "def del(s)\n return s.delete(\"abcdefghijklmnopqrstuvwxyz_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ\")\nend\n\ns = gets.chomp\nresult = \"YES\"\nif (k = s.index(\"@\")) then\n if s[0...k].size < 1 then\n result = \"NO\"\n end\n user = del(s[0...k])\n if user.size > 0 then\n result = \"NO\"\n end\n if (n = s.index(\"/\")) then\n host = s[k+1...n]\n resource = s[n+1..-1]\n else\n host = s[k+1..-1]\n resource = nil\n end\n if host.size < 1 then\n result = \"NO\"\n end\n k = -1\n while (m = host.index(\".\", k+1)) do\n if m-k > 17 || m-k < 2 then\n result = \"NO\"\n end\n k = m\n end\n host = del(host).delete(\".\")\n if host.size > 0 then\n result = \"NO\"\n end\n\n if resource then\n if s[n] == \".\" then\n result = \"NO\"\n end\n if resource.size > 16 then \n result = \"NO\"\n else\n resource = del(resource)\n if resource.size > 0 then\n result = \"NO\"\n end\n end\n else\n if s[-1] == \".\" then\n result = \"NO\"\n end\n end\nelse\n result = \"NO\"\nend\n\nputs result"}, {"source_code": "a=\"YES\"\ns=gets.chomp\nunless s=~/^(\\w{1,16})@([\\w\\.]{1,32})\\/(\\w{1,16})$/ || s=~/^(\\w{1,16})@([\\w\\.]{1,32})$/ then a=\"NO\"\nelse $2.split(\".\").each{|s|if s.length>16 then a=\"NO\" end}\nend\nputs a"}, {"source_code": "puts gets =~ /^[\\w_]{1,16}@[\\w_.]{1,32}(\\/[\\w_]{1,16})?$/ && $_ != /[@.]\\.|\\.$|\\.\\// ? :YES : :NO\n"}, {"source_code": "r = /[\\w_]{1,16}/\nputs gets =~ /^#{r}@(#{r}(.#{r})*)(\\/#{r})?$/ && $1.size <= 32 ? :YES : :NO\n"}, {"source_code": "def valid_word?(s)\n s =~ /^[_a-zA-Z0-9_]{1,16}$/\nend\n\ndef solve(s)\n a = s.split('@')\n return false unless a.size == 2\n return false unless valid_word? a.shift\n a = a.first\n return false if a[-1..-1] == '/'\n a = a.split('/')\n return false if a.size > 2\n return false if a.size == 2 && !valid_word?(a[1])\n a = a[0]\n return false unless a.size <= 32\n return false if a[-1..-1] == '.'\n a = a.split('.')\n return a.all? { |w| valid_word? w }\nend\n\ns = gets.chomp\n#s = 'mike@codeforces.com'\n#s = 'john.smith@codeforces.ru/contest.icpc/12'\n#s = '007@en.codeforces.com/contest'\nputs solve(s) ? 'YES' : 'NO'"}, {"source_code": "puts gets =~ /^\\w{1,16}@\\w{1,16}(.\\w{1,16}){1,32}(\\/\\w{1,16})*$/ ? \"YES\" : \"NO\"\n"}, {"source_code": "puts gets =~ /^\\w{1,16}@\\w{1,16}.\\w{1,16}(\\/\\w{1,16})$/ ? \"YES\" : \"NO\"\n"}, {"source_code": "puts gets =~ /^\\w{1,16}@\\w{1,16}(\\.\\w{1,16}){1,32}(\\/\\w{1,16})*$/ ? \"YES\" : \"NO\"\n"}, {"source_code": "s = gets.strip\nunless s =~ %r{([0-9a-zA-Z_]{1,16})@([0-9a-zA-Z_]{1,16}(\\.[0-9a-zA-Z_]{1,16})*)((/[0-9a-zA-Z_]{1,16})?)$}\n puts \"NO\"\n exit 0\nend\n#puts $1, $2, $3, $4\nusername, hostname, resource = $1, $2, $4\n\nif hostname.length >= 1 && hostname.length <= 32\n puts \"YES\"\nelse\n puts \"NO\"\nend\n"}, {"source_code": "if gets.strip =~ %r{^([0-9a-zA-Z_]{1,16})@([0-9a-zA-Z_]{1,16}(\\.[0-9a-zA-Z_]{1,16})*)((/[0-9a-zA-Z_]{1,16})?)$} && $4.length >= 1 && $4.length <= 32 \n puts \"YES\"\nelse\n puts \"NO\"\nend\n"}, {"source_code": "s = gets.strip\nif !s.include?( '/' )\n\ts += \"/a\"\nend\nputs /\\w{1,16}@\\w{1,16}(.\\w{1,16})*\\/\\w{1,16}/ =~ s && s.index( \"/\" ) - s.index( \"@\" ) + 1 <= 32 ? \"YES\" : \"NO\"\n"}, {"source_code": "s = gets\nif !s.include?( '/' )\n\ts += \"/a\"\nend\n\nputs /\\w{1,16}@\\w{1,16}(.\\w{1,16})*\\/\\w{1,16}/ =~ s && s.index( \"/\" ) - s.index( \"@\" ) + 1 <= 32 ? \"YES\" : \"NO\"\n"}, {"source_code": "s = gets.strip\nif !s.include?( '/' )\n\ts += \"/a\"\nend\nputs /^\\w{1,16}@\\w{1,16}(\\.\\w{1,16})*\\/\\w{1,16}$/ =~ s && s.index( \"/\" ) - s.index( \"@\" ) + 1 <= 32 ? \"YES\" : \"NO\"\n"}, {"source_code": "s = gets\nif !s.include?( '/' )\n\ts += \"/a\"\nend\nputs /\\w{1,16}@\\w{1,16}(.\\w{1,16})*\\/\\w{1,16}/ =~ s && s.index( \"/\" ) - s.index( \"@\" ) + 1 <= 32 ? \"YES\" : \"NO\"\n"}, {"source_code": "def del(s)\n return s.delete(\"abcdefghijklmnopqrstuvwxyz_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ\")\nend\n\ns = gets.chomp\nresult = \"YES\"\nk = s.index(\"@\")\nuser = del(s[0...k])\nif user.size > 0 then\n result = \"NO\"\nend\nif (n = s.index(\"/\")) then\n host = s[k+1...n]\n resource = s[n+1..-1]\nelse\n host = s[k+1..-1]\n resource = nil\nend\nk = -1\nwhile (m = host.index(\".\", k+1)) do\n if m-k > 16 then\n result = \"NO\"\n end\n k = m\nend\nhost = del(host).delete(\".\")\nif host.size > 0 then\n result = \"NO\"\nend\n\nif resource then\n if resource.size > 16 then \n result = \"NO\"\n else\n resource = del(resource)\n if resource.size > 0 then\n result = \"NO\"\n end\n end\nend\n\nputs result"}, {"source_code": "def del(s)\n return s.delete(\"abcdefghijklmnopqrstuvwxyz_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ\")\nend\n\ns = gets.chomp\nresult = \"YES\"\nif (k = s.index(\"@\")) then\n if s[0...k].size < 1 then\n result = \"NO\"\n end\n user = del(s[0...k])\n if user.size > 0 then\n result = \"NO\"\n end\n if (n = s.index(\"/\")) then\n host = s[k+1...n]\n resource = s[n+1..-1]\n else\n host = s[k+1..-1]\n resource = nil\n end\n if host.size < 1 then\n result = \"NO\"\n end\n k = -1\n while (m = host.index(\".\", k+1)) do\n if m-k > 17 || m-k < 2 then\n result = \"NO\"\n end\n k = m\n end\n host = del(host).delete(\".\")\n if host.size > 0 then\n result = \"NO\"\n end\n\n if resource then\n if s[n-1] == \".\" then\n result = \"NO\"\n end\n if resource.size > 16 then \n result = \"NO\"\n else\n resource = del(resource)\n if resource.size > 0 then\n result = \"NO\"\n end\n end\n else\n if s[-1] == \".\" then\n result = \"NO\"\n end\n end\nelse\n result = \"NO\"\nend\n\nputs result"}], "src_uid": "2a68157e327f92415067f127feb31e24"} {"nl": {"description": "You are given a regular polygon with $$$n$$$ vertices labeled from $$$1$$$ to $$$n$$$ in counter-clockwise order. The triangulation of a given polygon is a set of triangles such that each vertex of each triangle is a vertex of the initial polygon, there is no pair of triangles such that their intersection has non-zero area, and the total area of all triangles is equal to the area of the given polygon. The weight of a triangulation is the sum of weigths of triangles it consists of, where the weight of a triagle is denoted as the product of labels of its vertices.Calculate the minimum weight among all triangulations of the polygon.", "input_spec": "The first line contains single integer $$$n$$$ ($$$3 \\le n \\le 500$$$) \u2014 the number of vertices in the regular polygon.", "output_spec": "Print one integer \u2014 the minimum weight among all triangulations of the given polygon.", "sample_inputs": ["3", "4"], "sample_outputs": ["6", "18"], "notes": "NoteAccording to Wiki: polygon triangulation is the decomposition of a polygonal area (simple polygon) $$$P$$$ into a set of triangles, i.\u2009e., finding a set of triangles with pairwise non-intersecting interiors whose union is $$$P$$$.In the first example the polygon is a triangle, so we don't need to cut it further, so the answer is $$$1 \\cdot 2 \\cdot 3 = 6$$$.In the second example the polygon is a rectangle, so it should be divided into two triangles. It's optimal to cut it using diagonal $$$1-3$$$ so answer is $$$1 \\cdot 2 \\cdot 3 + 1 \\cdot 3 \\cdot 4 = 6 + 12 = 18$$$."}, "positive_code": [{"source_code": "N = gets.to_i\np (2...N).reduce(0){ |a,b| a + b*(b+1) }"}], "negative_code": [], "src_uid": "1bd29d7a8793c22e81a1f6fd3991307a"} {"nl": {"description": "Luke Skywalker got locked up in a rubbish shredder between two presses. R2D2 is already working on his rescue, but Luke needs to stay alive as long as possible. For simplicity we will assume that everything happens on a straight line, the presses are initially at coordinates 0 and L, and they move towards each other with speed v1 and v2, respectively. Luke has width d and is able to choose any position between the presses. Luke dies as soon as the distance between the presses is less than his width. Your task is to determine for how long Luke can stay alive.", "input_spec": "The first line of the input contains four integers d, L, v1, v2 (1\u2009\u2264\u2009d,\u2009L,\u2009v1,\u2009v2\u2009\u2264\u200910\u2009000,\u2009d\u2009<\u2009L)\u00a0\u2014 Luke's width, the initial position of the second press and the speed of the first and second presses, respectively.", "output_spec": "Print a single real value\u00a0\u2014 the maximum period of time Luke can stay alive for. Your answer will be considered correct if its absolute or relative error does not exceed 10\u2009-\u20096. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if .", "sample_inputs": ["2 6 2 2", "1 9 1 2"], "sample_outputs": ["1.00000000000000000000", "2.66666666666666650000"], "notes": "NoteIn the first sample Luke should stay exactly in the middle of the segment, that is at coordinates [2;4], as the presses move with the same speed.In the second sample he needs to occupy the position . In this case both presses move to his edges at the same time."}, "positive_code": [{"source_code": "a = gets.split(\" \").map(&:to_i)\n\np (a[1]-a[0]).to_f / (a[2]+a[3])\n"}, {"source_code": "a,b,c,d=gets.split.map &:to_f;p (b-a)/(c+d)"}, {"source_code": "d,l,v1,v2=gets.split.map{|e| e.to_f}\nputs (l-d)/(v1+v2)"}, {"source_code": "d, l, v1, v2 = gets.chomp.split.map(&:to_i)\n\nputs (l - d) / (v1 + v2).to_f\n"}, {"source_code": "a=gets.split.map(&:to_i)\nputs (a[1]-a[0]).to_f/(a[2]+a[3])"}, {"source_code": "d,l,v,w=gets.split.map &:to_f\nputs \"%.20f\" % ((l - d) / (v + w))\n"}, {"source_code": "d,l,v1,v2 = gets.chomp.split(' ').map(&:to_i)\nputs((l-d).to_f/(v1+v2))\n"}, {"source_code": "d, l, v1, v2 = gets.split(' ').map &:to_i\n\n\nputs (l - d).to_f/(v1 + v2)"}, {"source_code": "a=gets.split.map(&:to_i);p (a[1]-a[0])*1.0/(a[2]+a[3])\n"}, {"source_code": "a,b,c,d=gets.split.map &:to_f;p (b-a)/(c+d)\n"}, {"source_code": "d, L, v1, v2 = gets.chomp.split(' ').map(&:to_f)\n\nres = (L - d) / (v1 + v2)\np res"}, {"source_code": "class Solver\n\tdef main\n\t\td, l, v1, v2 = gets.split.map { |x| x.to_i }\n\t\tputs format(\"%.8f\", (l - d).to_f / (v1 + v2).to_f)\n\tend\nend\nSolver.new.main"}, {"source_code": "a,b,c,d=gets.split.map &:to_f;p (b-a)/(c+d)\n"}], "negative_code": [], "src_uid": "f34f3f974a21144b9f6e8615c41830f5"} {"nl": {"description": "Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x\u2009=\u20094, and y\u2009=\u20097, then numbers 47, 744, 4 are lucky.Let's call a positive integer a undoubtedly lucky, if there are such digits x and y (0\u2009\u2264\u2009x,\u2009y\u2009\u2264\u20099), that the decimal representation of number a (without leading zeroes) contains only digits x and y.Polycarpus has integer n. He wants to know how many positive integers that do not exceed n, are undoubtedly lucky. Help him, count this number.", "input_spec": "The first line contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009109) \u2014 Polycarpus's number.", "output_spec": "Print a single integer that says, how many positive integers that do not exceed n are undoubtedly lucky.", "sample_inputs": ["10", "123"], "sample_outputs": ["10", "113"], "notes": "NoteIn the first test sample all numbers that do not exceed 10 are undoubtedly lucky.In the second sample numbers 102, 103, 104, 105, 106, 107, 108, 109, 120, 123 are not undoubtedly lucky."}, "positive_code": [{"source_code": "# # n = gets.to_i\n# # l = n.to_s.length\n\n# # if l > 2\n# # \tlist = [9,90]\n# # \tx = 81\n# # \t(l - 2).times do |i|\n# # \t\tx *= 2\n# # \tend\n# # \tx += 9\n# # else\n# # \tputs n\n# # end\n\n\n# # def dfs(num) #// run it as dfs(0)\n# # @ans += 1 if (num > 0 && num <= @n) \n# # return if (num >= 10**8) \n# # (0..9).each do |a|\n# # \tnumber = num*10+a\n# # if number >0\n# # if number.to_s.split(\"\").uniq.length <= 2\n# # dfs(number)\n# # end\n# # end\n# # end\n# # end\n# # require 'Set'\n# def dfs(num) #// run it as dfs(0)\n# (1..@n).each do |a|\n# \t return if (a >= 10**8) \n# \t if @n > 100000\n# \t \t@ans += 1\n# \t else\n# \t if a.to_s.chars.to_a.uniq.length <= 2\n# \t \t@ans += 1\n# \t end\n# \t end\n# end\n# end\n\n# @n = gets.to_i\n# @ans = 0\n# dfs(0)\n# puts @ans\n\nrequire 'Set'\n\ndef dfs(x,y,num,cnt=false)\n\treturn if num > @n || (num == 0 && !cnt)\n\t@s << num if num > 0\n\tdfs(x,y,num * 10 + x)\n\tdfs(x,y,num * 10 + y)\t\nend\n\n@n = gets.to_i\n@s = Set.new\n(0..9).each do |i|\n\t((i+1)..9).each do |j|\n\t\tdfs(i,j,0,true)\n\tend\nend\nputs @s.length"}, {"source_code": "require 'set'\n\n$set=Set.new\n$n=gets.to_i\n\ndef dfs num,x,y\n if (1..$n)===num\n $set<y then\n\t\tans+=(x-(i-y))\n\telse\n\t\tans+=[x,i].min\n\tend\n}\nputs ans\n\n"}, {"source_code": "# t = gets.to_i\n# t.times do\nn, m = gets.split.map(&:to_i)\ncount = 0\n(1..n).each do |x|\n\ty1 = 5 - x % 5\n\tk = ((m - y1)/5).to_i\n\t# y2 = y1 + 5* k\n\tcount += k+1\nend\nputs count"}, {"source_code": "n, m = gets.split(' ').map(&:to_i)\nn_full, n_rest = n.divmod 5\nm_full, m_rest = m.divmod 5\n\nputs (1..4).map { |i| (n_full + (n_rest >= i ? 1 : 0)) * (m_full + (m_rest >= (5-i) ? 1 : 0)) }.reduce(:+) + n_full * m_full\n"}, {"source_code": "# coding: utf-8\n\nn, m = gets.split.map(&:to_i)\n\nn = [n/5, (n-1)/5 + 1, (n-2)/5 + 1, (n-3)/5 + 1, (n-4)/5 + 1]\nm = [m/5, (m-4)/5 + 1, (m-3)/5 + 1, (m-2)/5 + 1, (m-1)/5 + 1]\n# n = 6, m = 12\n# n [5] [1, 6] [2] [3] [4] \n# m [5, 10] [1, 6, 11] [2, 7, 12] [3, 8] [4, 9]\n# 2 + 4 + 2 + 3 + 3 = 14\nputs n.zip(m).map { |a| a[0] * a[1] }.sum"}, {"source_code": "n, m = gets.chomp.split.map(&:to_i)\n\nans = 0\nfor i in 0..4\n x = n / 5\n x += 1 if 0 < i && i <= n % 5\n y = m / 5\n y += 1 if i < 5 && 5 - i <= m % 5\n ans += x * y\nend\n\nputs ans\n"}, {"source_code": "def get_div_5(n, m)\n lasts = [[1, 4], [2, 4], [3, 4], [3, 3], [4, 4]]\n l2 = n * m / 5.0\n\n if (lasts.include?([n % 5, m % 5]) || lasts.include?([m % 5, n % 5])) && l2 % 1 != 0\n l2 += 1\n end\n\n l2.floor\nend\n\n\nb = gets\n\nb = b.strip.split(\" \").map {|v| v.to_i}\nputs get_div_5(b[0], b[1])\n"}, {"source_code": "n=gets.chomp.to_s.split(\" \")\nn,m=n[0].to_s.to_i,n[1].to_s.to_i\nres=0\n1.upto(n) do |x| # 5-0\n # 4-1 3-2 2-3 1-4\n res+=(m+x%5)/5\n\nend\nprint res\n"}, {"source_code": "n,m=gets.split.map(&:to_i)\np (1..n).reduce(0){|s,i|s+(m+i%5)/5}"}, {"source_code": "n, m = gets.strip.split.map(&:to_i)\nmod = 5\nputs (0...mod).map { |x| \n\t\t( ( n - x ) / mod + 1 - ( x == 0 ? 1 : 0 ) ) * \n\t\t( ( m - (mod-x) % mod ) / mod + 1 - ( x == 0 ? 1 : 0 ) ) \n\t}.reduce(0, :+)"}, {"source_code": "n, m = gets.chomp.split(' ').map(&:to_i)\nx = 1\nans = 0\nuntil x > n\n\tans += ((m + x) / 5) - (x / 5)\n\tx += 1\nend\n\nputs ans"}], "negative_code": [], "src_uid": "df0879635b59e141c839d9599abd77d2"} {"nl": {"description": "The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has business of national importance. For example, he has to pay an official visit to square t. As the king is not in habit of wasting his time, he wants to get from his current position s to square t in the least number of moves. Help him to do this. In one move the king can get to the square that has a common side or a common vertex with the square the king is currently in (generally there are 8 different squares he can move to).", "input_spec": "The first line contains the chessboard coordinates of square s, the second line \u2014 of square t. Chessboard coordinates consist of two characters, the first one is a lowercase Latin letter (from a to h), the second one is a digit from 1 to 8.", "output_spec": "In the first line print n \u2014 minimum number of the king's moves. Then in n lines print the moves themselves. Each move is described with one of the 8: L, R, U, D, LU, LD, RU or RD. L, R, U, D stand respectively for moves left, right, up and down (according to the picture), and 2-letter combinations stand for diagonal moves. If the answer is not unique, print any of them. ", "sample_inputs": ["a8\nh1"], "sample_outputs": ["7\nRD\nRD\nRD\nRD\nRD\nRD\nRD"], "notes": null}, "positive_code": [{"source_code": "def num(x)\n if x == \"a\"\n return 1\n elsif x == \"b\"\n return 2\n elsif x == \"c\"\n return 3\n elsif x == \"d\"\n return 4\n elsif x == \"e\"\n return 5\n elsif x == \"f\"\n return 6\n elsif x == \"g\"\n return 7\n else \n return 8\n end\nend\n\ndef simple(h,v)\n step = []\n if h > 0 then\n step += [\"R\"]*h\n elsif h < 0 then\n step += [\"L\"]*h.abs\n elsif v > 0\n step += [\"U\"]*v\n elsif v < 0\n step += [\"D\"]*v.abs\n end\n return step\nend\n\nk = gets.chomp\nt = gets.chomp\n\nstep = []\n\nh = num(t[0]) - num(k[0])\nv = t[1].to_i - k[1].to_i\n\nd = (0-v).abs < (0-h).abs ? v : h\n\nif d != 0 then\n if h == d then\n if h > 0 && v > 0 then\n step += [\"RU\"]*h\n elsif h > 0 && v < 0 then\n step += [\"RD\"]*h\n elsif h < 0 && v > 0 then\n step += [\"LU\"]*h.abs\n else\n step += [\"LD\"]*h.abs\n end\n if v > 0 then\n v -= h.abs\n else\n v += h.abs\n end\n h = 0\n else\n if h > 0 && v > 0 then\n step += [\"RU\"]*v\n elsif h > 0 && v < 0 then\n step += [\"RD\"]*v.abs\n elsif h < 0 && v > 0 then\n step += [\"LU\"]*v\n else\n step += [\"LD\"]*v.abs\n end\n if h > 0 then\n h -= v.abs\n else\n h += v.abs\n end\n v = 0\n end\nend\n\nstep += simple(h,v)\n\nputs step.size\nstep.size.times do |i|\n puts step[i]\nend"}, {"source_code": "# require 'pry-byebug'\nfile = File.exist?('in.in') ? File.new('in.in','r') : STDIN\n\nDX = [0, 1, 0, -1, 1, -1, 1, -1]\nDY = [1, 0, -1, 0, 1, -1, -1, 1]\nMOV = [\"R\", \"D\", \"L\", \"U\", \"RD\", \"LU\", \"LD\", \"RU\"]\n\ndef inside?(i, j, grid)\n i>=0 && i<= grid.size-1 && j>=0 && j <=grid[0].size-1\nend\n\nmap = {\"a\"=> 0, \"b\"=> 1, \"c\"=> 2, \"d\"=> 3, \"e\"=> 4,\"f\"=> 5, \"g\"=> 6, \"h\" => 7}\n\ns2,s1 = file.gets.chomp.split('')\nt2,t1 = file.gets.chomp.split('')\n\ns1 = (s1.to_i-1-7).abs\ns2 = map[s2]\nt1 = (t1.to_i-1-7).abs\nt2 = map[t2]\n\n# puts \"#{s1}#{s2}\"\n# puts \"#{t1}#{t2}\"\n\n\ngrid = Array.new(8) { Array.new(8) }\ndist = Array.new(8) { Array.new(8, 100) }\nqueue = [[s1, s2]]\ndist[s1][s2]=0\ngrid[s1][s2]=[]\n\nwhile(queue.size != 0)\n x, y = queue.shift\n 8.times do |i|\n new_x = x+DX[i]\n new_y = y+DY[i]\n if inside?(new_x, new_y, grid) && dist[new_x][new_y]==100\n\n if dist[x][y]+1 < dist[new_x][new_y]\n dist[new_x][new_y] = dist[x][y]+1\n grid[new_x][new_y] = grid[x][y] + [MOV[i]]\n end\n\n # dist[new_x][new_y] = [dist[new_x][new_y],dist[x][y]+1].min\n break if new_x == t1 && new_y == t2\n # binding.pry if dist[new_x][new_y] == 7\n queue << [new_x, new_y]\n end\n end\nend\nputs dist[t1][t2]\ngrid[t1][t2].each do |e|\n puts e\nend"}, {"source_code": "source = gets.chomp!\ndestination = gets.chomp!\nh = []\nv = []\nwhile true\n\tif source[0] < destination[0]\n\t\th << 'R'\n\t\tsource[0] = (source[0].ord + 1).chr\n\telsif source[0] > destination[0]\n\t\th << 'L'\n\t\tsource[0] = (source[0].ord - 1).chr\n\telse\n\t\th << ''\n\tend\n\n\tif source[1] < destination[1]\n\t\tv << 'U'\n\t\tsource[1] = (source[1].to_i + 1).to_s\n\telsif source[1] > destination[1]\n\t\tv << 'D'\n\t\tsource[1] = (source[1].to_i - 1).to_s\n\telse\n\t\tv << ''\n\tend\n\n\tbreak if source == destination\n\nend\nif h.size == 1 && v.size == 1 && h[0] == '' && v[0] == '' \n\tputs 0\nelse\n\tputs h.size\n\th.each_index {|index| puts h[index] + v[index]}\nend\n"}, {"source_code": "a=gets\nb=gets\nx1=a[0].ord\ny1=a[1].to_i\nx2=b[0].ord\ny2=b[1].to_i\n\nputs [(x1-x2).abs,(y1-y2).abs].max\n\nwhile (x1 != x2 || y1 != y2)\n s=''\n if (x1 < x2)\n s+='R'\n x1+=1\n end\n if (x1 > x2)\n s+='L'\n x1-=1\n end\n if (y1 < y2)\n s+='U'\n y1+=1\n end\n if (y1 > y2)\n s+='D'\n y1-=1\n end\n puts s\nend\n"}, {"source_code": "#!usr/bin/env ruby\n\n# https://codeforces.com/problemset/problem/3/A\n\nstart = gets.chomp\nfinish = gets.chomp\nx1 = start[0]\nx2 = finish[0]\n\ny1 = start[1]\ny2 = finish[1]\n\ncount = 0\nmoves = []\n\nwhile !(x1 == x2 && y1 == y2) do\n move = \"\"\n\n if x1 < x2\n move += \"R\"\n x1 = x1.next\n elsif x1 > x2\n move += \"L\"\n x1 = (x1.ord - 1).chr\n end\n\n if y1 < y2\n move += \"U\"\n y1 = y1.next\n elsif y1 > y2\n move += \"D\"\n y1 = (y1.ord - 1).chr\n end\n count += 1\n moves << move\n end\n\nputs count\nmoves.each { |mv| puts mv }\n"}, {"source_code": "s=gets.split[0].bytes.to_a\nt=gets.split[0].bytes.to_a\nsx=s[0]-97\nsy=56-s[1]\ntx=t[0]-97\nty=56-t[1]\nputs [(sx-tx).abs,(sy-ty).abs].max\nloop do\n if sx==tx && sy==ty then\n break\n end\n if sxtx then\n print \"L\"\n sx-=1\n end\n if syty then\n sy-=1\n print \"U\"\n end\n puts\nend\n"}, {"source_code": "# http://codeforces.com/problemset/problem/3/A\n\nclass Node\n attr_accessor :distance, :visited, :prev, :x, :y, :cost\n\n def initialize(x=0, y=0, cost=1)\n @distance = Float::INFINITY\n @visited = false\n @prev = nil\n @x = x\n @y = y\n @cost = cost\n end\nend\n\ndef make_graph(x, y)\n (0...x).map { |x| (0...y).map { |y| Node.new(x, y) } }\nend\n\ndef find_unvisited(graph)\n graph.flatten { |y| y.visited == false }\nend\n\ndef min(unvisited, graph)\n min = unvisited.map { |node| node.distance }.each_with_index.min\n unvisited[min[1]]\nend\n\ndef in_range(x, y, graph)\n x >= 0 && y >= 0 && x < graph.size && y < graph[0].size && !graph[x][y].visited\nend\n\ndef get_neighbors(x, y, graph)\n l = [x-1, y]\n r = [x+1, y]\n t = [x, y+1]\n b = [x, y-1]\n lt = [x-1, y+1]\n rt = [x+1, y+1]\n rb = [x+1, y-1]\n lb = [x-1, y-1]\n \n [l,r,t,b,lt,rt,rb,lb].select { |neighbor| in_range(neighbor[0], neighbor[1], graph) }\nend\n\ndef visit(node, graph)\n neighbors = get_neighbors(node.x, node.y, graph)\n neighbors.each do |n|\n neighbor = graph[n[0]][n[1]]\n neighbor.visited = true\n dist = node.distance + neighbor.cost\n if dist < neighbor.distance\n neighbor.distance = dist\n neighbor.prev = node\n end\n end\nend\n\ndef dijkstra(graph, source, target)\n graph[source[0]][source[1]].distance = 0\n unvisited = find_unvisited(graph)\n\n while unvisited.any?\n current_node = min(unvisited, graph)\n return current_node if current_node.x == target[0] && current_node.y == target[1]\n unvisited.delete(current_node)\n visit(current_node, graph)\n end\nend\n\ndef convert_source(coord)\n [coord[0].ord - 96 - 1, Integer(coord[1]) -1]\nend\n\ndef to_directions(from, to)\n return if to == nil\n str = \"\"\n if to.x > from.x\n str << \"R\"\n end\n if to.x < from.x\n str << \"L\"\n end\n if to.y > from.y\n str << \"U\"\n end\n if to.y < from.y\n str << \"D\"\n end\n str\nend\n\ndef get_answer_nodes(root)\n nodes = []\n current_node = root\n while !current_node.nil?\n nodes << current_node\n current_node = current_node.prev\n end\n nodes.reverse\nend\n\ndef format_answer(answer)\n nodes = get_answer_nodes(answer)\n directions = [nodes.size-1]\n nodes.each_with_index do |node, i|\n directions << to_directions(nodes[i], nodes[i+1])\n end\n directions\nend\n\ndef solve\n graph = make_graph(8, 8)\n source = gets\n target = gets\n answer = dijkstra(graph, convert_source(source.chomp), convert_source(target.chomp))\n puts format_answer(answer).join(\"\\n\")\nend\n\nsolve()\n\n\n"}, {"source_code": "s = gets\nt = gets\nsx = s[0..0].ord\nsy = s[1..1].to_i\ntx = t[0..0].ord\nty = t[1..1].to_i\ndx = sx-tx\ndy = sy-ty\nstep = [dx.abs,dy.abs].max\nputs step\nstep.times do\n if dx<0\n print \"R\"\n dx += 1\n elsif dx>0\n print \"L\"\n dx -= 1\n end\n if dy<0\n print \"U\"\n dy += 1\n elsif dy>0\n print \"D\"\n dy -= 1\n end\n puts\nend\n"}, {"source_code": "input = gets\nking = [input[0].ord - 96, input[1].ord - 48]\ninput = gets\ntarget = [input[0].ord - 96, input[1].ord - 48]\n\npath = Array.new\n\nwhile king != target\n s = String.new\n if king[0] < target[0]\n s << \"R\"\n king[0] += 1\n elsif king[0] > target[0]\n s << \"L\"\n king[0] -= 1\n end\n if king[1] < target[1]\n s << \"U\"\n king[1] += 1\n elsif king[1] > target[1]\n s << \"D\"\n king[1] -= 1\n end\n path.concat([s])\nend\n\nputs path.count\npath.each {|x| puts x}"}, {"source_code": "s, t = gets.to_s, gets.to_s\nrow = t[0].ord - s[0].ord\ncol = t[1].ord - s[1].ord\nif row.abs > col.abs\n\tputs row.abs\n\trc = 1\n\tdiff = (row.abs - col.abs).to_i\n\tsqr = row.abs - diff\nelse\n\tputs col.abs\n\trc = 0\n\tdiff = (col.abs - row.abs).to_i\n\tsqr = col.abs - diff\nend\nif row >= 0 and col >= 0\n\tsqr.times{\n\t\tputs \"RU\"\n\t}\n\tif rc == 1\n\t\tdiff.times{\n\t\t\tputs \"R\"\n\t\t}\n\telse\n\t\tdiff.times{\n\t\t\tputs \"U\"\n\t\t}\n\tend\nelsif row <= 0 and col >= 0\n\tsqr.times{\n\t\tputs \"LU\"\n\t}\n\tif rc == 1\n\t\tdiff.times{\n\t\t\tputs \"L\"\n\t\t}\n\telse\n\t\tdiff.times{\n\t\t\tputs \"U\"\n\t\t}\n\tend\nelsif row <= 0 and col <= 0\n\tsqr.times{\n\t\tputs \"LD\"\n\t}\n\tif rc == 1\n\t\tdiff.times{\n\t\t\tputs \"L\"\n\t\t}\n\telse\n\t\tdiff.times{\n\t\t\tputs \"D\"\n\t\t}\n\tend\nelse\n\tsqr.times{\n\t\tputs \"RD\"\n\t}\n\tif rc == 1\n\t\tdiff.times{\n\t\t\tputs \"R\"\n\t\t}\n\telse\n\t\tdiff.times{\n\t\t\tputs \"D\"\n\t\t}\n\tend\nend"}, {"source_code": "class King\n def initialize(s, t)\n @start = s\n @end = t\n end\n\n def get_path\n return 0 if @start == @end\n result = []\n horizontal = (@start[0] == @end[0])\n vertical = (@start[1] == @end[1])\n\n current = @start\n steps = 0\n until horizontal || vertical\n current = move_diag(current)\n horizontal = (current[0] == @end[0])\n vertical = (current[1] == @end[1])\n result << direction.join\n steps += 1\n end\n\n if vertical\n current_steps = (current[0].ord.to_i - @end[0].ord.to_i).abs\n result += [direction.first]*current_steps\n steps += current_steps\n elsif horizontal\n current_steps = (current[1].to_i - @end[1].to_i).abs\n result += [direction.last]*current_steps\n steps += current_steps\n end\n result.unshift(steps)\n\n\n # if @start == @end\n # result << 0\n # elsif horizontal\n # result = [steps_x.abs] + [direction.last]*steps_x.abs\n # elsif vertical\n # result = [steps_y.abs] + [direction.first]*steps_y.abs\n # else\n # current = @start\n # steps = 0\n # until horizontal || vertical\n # current = move_diag(current)\n # horizontal = (current[0] == @end[0])\n # vertical = (current[1] == @end[1])\n # result << direction.join\n # steps += 1\n # end\n # end\n result\n end\n\n def move_diag(position)\n x_inc = steps_x == 0 ? 0 : steps_x/steps_x.abs\n y_inc = steps_y == 0 ? 0 : steps_y/steps_y.abs\n [(position[0].ord - y_inc).chr, (position[1].to_i - x_inc)].join\n end\n\n def direction\n [direction_y, direction_x]\n end\n\n def direction_x\n steps_x > 0 ? 'D' : 'U'\n end\n\n def direction_y\n steps_y > 0 ? 'L' : 'R'\n end\n\n def steps_x\n @start[1].to_i - @end[1].to_i\n end\n\n def steps_y\n @start[0].ord.to_i - @end[0].ord.to_i\n end\nend\n\ns, t = [gets.chomp, gets.chomp]\ngame = King.new(s, t)\nputs game.get_path\n"}, {"source_code": "a = gets.chomp\nb = gets.chomp\nx, y = a[0].ord-b[0].ord, a[1].to_i-b[1].to_i\nputs [x.abs, y.abs].max\ns = \"\"\nif x.abs > y.abs\n s = (x>0 ? \"L\" : \"R\")\nelse\n s = (y>0 ? \"D\" : \"U\")\nend\nprint (s+\"\\n\")*(x.abs-y.abs).abs\nif x > 0\n s = (y > 0 ? \"LD\" : \"LU\")\nelse\n s = (y > 0 ? \"RD\" : \"RU\")\nend\nprint (s+\"\\n\")*[x.abs, y.abs].min"}, {"source_code": "s=gets\n\nt=gets\n\nr=t[0].ord-s[0].ord\n\nc=t[1].hex-s[1].hex\n\na=[\"\"]*9\n\nf=lambda{|r,c|r.times{|i|a[i]+=c}}\n\nf.call(r,\"R\")\n\nf.call(-r,\"L\")\n\nf.call(c,\"U\")\n\nf.call(-c,\"D\")\n\na.select!{|i|i!=\"\"}\n\np a.size\n\nputs a"}, {"source_code": "include Math\na=0\n\"a\".each_byte do |n|\n a=n\nend\nmemo=gets.chomp!.scan(/./)\nsx=0\nmemo[0].each_byte do |n|\n sx=n-a+1\nend\nsy=memo[1].to_i\nex=0\nmemo=gets.chomp!.scan(/./)\nmemo[0].each_byte do |n|\n ex=n-a+1\nend\ney=memo[1].to_i\nxx=ex-sx\nyy=ey-sy\nhosu=[xx<0 ? -xx : xx,yy<0 ? -yy :yy].max\nputs hosu\nif xx >=0 && yy>=0\n if xx>=yy\n yy.times do\n puts \"RU\"\n end\n (xx-yy).times do\n puts \"R\"\n end\n else\n xx.times do\n puts \"RU\"\n end\n (yy-xx).times do\n puts \"U\"\n end\n end\nend\nif xx >=0 && yy<0\n yy=-yy\n if xx>=yy\n yy.times do\n puts \"RD\"\n end\n (xx-yy).times do\n puts \"R\"\n end\n else\n xx.times do\n puts \"RD\"\n end\n (yy-xx).times do\n puts \"D\"\n end\n end\nend\nif xx < 0 && yy >=0\n xx=-xx\n if xx>=yy\n yy.times do\n puts \"LU\"\n end\n (xx-yy).times do\n puts \"L\"\n end\n else\n xx.times do\n puts \"LU\"\n end\n (yy-xx).times do\n puts \"U\"\n end\n end\nend\nif xx <0 && yy<0\n xx=-xx\n yy=-yy\n if xx>=yy\n yy.times do\n puts \"LD\"\n end\n (xx-yy).times do\n puts \"L\"\n end\n else\n xx.times do\n puts \"LD\"\n end\n (yy-xx).times do\n puts \"D\"\n end\n end\nend\n"}, {"source_code": "s=gets.chomp.split(\"\")\nt=gets.chomp.split(\"\")\nvalu=1..8\nalph=('a' .. 'h')\nvalu=[*valu]\nalph=[*alph]\nvalu_hash={}\ni=0\nloop do\n\tbreak if i==8\n\tvalu_hash[alph[i]]=valu[i]\n\ti+=1\n end\ndir_arry=[] \nif valu_hash[s[0]]< valu_hash[t[0]]\n dir_arry[0]=\"R\"\nelsif valu_hash[s[0]]> valu_hash[t[0]] \n dir_arry[0]=\"L\"\nelse\n dir_arry[0]=0\nend\n \nif s[1].to_i< t[1].to_i\n dir_arry[1]=\"U\"\nelsif s[1].to_i> t[1].to_i \n dir_arry[1]=\"D\"\nelse\n dir_arry[1]=0\nend\n\nhmove=valu_hash[s[0]] - valu_hash[t[0]]\nif hmove<0\nhmove=hmove*(-1)\nend\nvmove=s[1].to_i-t[1].to_i\nif vmove<0\nvmove=vmove*(-1)\nend\n\nif hmove==0\n\tputs vmove\n\tvmove.times{puts dir_arry[1]}\nelsif vmove==0\n\tputs hmove\n\thmove.times{puts dir_arry[0] }\nelsif vmove==hmove\n\tputs hmove\n hmove.times{puts dir_arry[0]+dir_arry[1] }\nelsif hmove>vmove\n\tputs hmove\n\tvmove.times{puts dir_arry[0]+dir_arry[1] }\n\t(hmove-vmove).times {puts dir_arry[0]}\nelsif vmove>hmove\n\tputs vmove\n\thmove.times{puts dir_arry[0]+dir_arry[1] }\n\t(vmove-hmove).times{puts dir_arry[1]}\nend\t\n\t"}, {"source_code": "s1 = gets\ns2 = gets\ndst1 = s2[0].ord - s1[0].ord\ndst2 = s2[1].to_i - s1[1].to_i\n\nputs [dst2.abs, dst1.abs].max\nwhile dst2 != 0 or dst1 != 0 do\n if dst1 > 0 then\n printf \"R\"\n dst1 -= 1\n end\n if dst1 < 0 then\n printf \"L\"\n dst1 += 1\n end\n\n if dst2 > 0 then\n printf \"U\"\n dst2 -= 1\n end\n if dst2 < 0 then\n printf \"D\"\n dst2 += 1\n end\n puts\nend\n"}, {"source_code": "def get_path(src, dest)\n s_x, s_y = src.chars\n d_x, d_y = dest.chars\n path = []\n while s_x != d_x || s_y != d_y\n move = ''\n if (s_x > d_x)\n s_x = (s_x.ord - 1).chr\n move += 'L'\n elsif (s_x < d_x)\n s_x.next!\n move += 'R'\n end\n\n if (s_y > d_y)\n s_y = (s_y.ord - 1).chr\n move += 'D'\n elsif (s_y < d_y)\n s_y.next!\n move += 'U'\n end\n\n path << move\n end\n path\nend\n\nif __FILE__ == $0\n path = get_path(gets, gets)\n puts path.size\n path.each { |m| puts m }\nend\n"}, {"source_code": "s=gets.chomp.split(\"\")\nt=gets.chomp.split(\"\")\nvalu=1..8\nalph=('a' .. 'h')\nvalu=[*valu]\nalph=[*alph]\nvalu_hash={}\ni=0\nloop do\n\tbreak if i==8\n\tvalu_hash[alph[i]]=valu[i]\n\ti+=1\n end\ndir_arry=[] \nif valu_hash[s[0]]< valu_hash[t[0]]\n dir_arry[0]=\"R\"\nelsif valu_hash[s[0]]> valu_hash[t[0]] \n dir_arry[0]=\"L\"\nelse\n dir_arry[0]=0\nend\n \nif s[1].to_i< t[1].to_i\n dir_arry[1]=\"U\"\nelsif s[1].to_i> t[1].to_i \n dir_arry[1]=\"D\"\nelse\n dir_arry[1]=0\nend\n\nhmove=valu_hash[s[0]] - valu_hash[t[0]]\nif hmove<0\nhmove=hmove*(-1)\nend\nvmove=s[1].to_i-t[1].to_i\nif vmove<0\nvmove=vmove*(-1)\nend\n\nif hmove==0\n\tputs vmove\n\tvmove.times{puts dir_arry[1]}\nelsif vmove==0\n\tputs hmove\n\thmove.times{puts dir_arry[0] }\nelsif vmove==hmove\n\tputs hmove\n hmove.times{puts dir_arry[0]+dir_arry[1] }\nelsif hmove>vmove\n\tputs hmove\n\tvmove.times{puts dir_arry[0]+dir_arry[1] }\n\t(hmove-vmove).times {puts dir_arry[0]}\nelsif vmove>hmove\n\tputs vmove\n\thmove.times{puts dir_arry[0]+dir_arry[1] }\n\t(vmove-hmove).times{puts dir_arry[1]}\nend\t"}, {"source_code": "s=gets.chomp.split(\"\")\nt=gets.chomp.split(\"\")\nvalu=1..8\nalph=('a' .. 'h')\nvalu=[*valu]\nalph=[*alph]\nvalu_hash={}\ni=0\nloop do\n\tbreak if i==8\n\tvalu_hash[alph[i]]=valu[i]\n\ti+=1\n end\ndir_arry=[] \nif valu_hash[s[0]]< valu_hash[t[0]]\n dir_arry[0]=\"R\"\nelsif valu_hash[s[0]]> valu_hash[t[0]] \n dir_arry[0]=\"L\"\nelse\n dir_arry[0]=0\nend\n \nif s[1].to_i< t[1].to_i\n dir_arry[1]=\"U\"\nelsif s[1].to_i> t[1].to_i \n dir_arry[1]=\"D\"\nelse\n dir_arry[1]=0\nend\n\nhmove=valu_hash[s[0]] - valu_hash[t[0]]\nif hmove<0\nhmove=hmove*(-1)\nend\nvmove=s[1].to_i-t[1].to_i\nif vmove<0\nvmove=vmove*(-1)\nend\n\nif hmove==0\n\tputs vmove\n\tvmove.times{puts dir_arry[1]}\nelsif vmove==0\n\tputs hmove\n\thmove.times{puts dir_arry[0] }\nelsif vmove==hmove\n\tputs hmove\n hmove.times{puts dir_arry[0]+dir_arry[1] }\nelsif hmove>vmove\n\tputs hmove\n\tvmove.times{puts dir_arry[0]+dir_arry[1] }\n\t(hmove-vmove).times {puts dir_arry[0]}\nelsif vmove>hmove\n\tputs vmove\n\thmove.times{puts dir_arry[0]+dir_arry[1] }\n\t(vmove-hmove).times{puts dir_arry[1]}\nend\t\n\t\t\n\n\n\n\n\n\n\n\n\n "}, {"source_code": "start_point = gets.chomp\nend_point = gets.chomp\n\ncharacter_start_point = start_point[0]\nnumber_start_point = start_point[1].to_i\n\ncharacter_end_point = end_point[0]\nnumber_end_point = end_point[1].to_i\n\nvertical_moves_count = (number_start_point-number_end_point).abs\nvertical_moves_character = number_start_point > number_end_point ? 'D' : 'U'\n\nhorizontal_moves_count = (character_start_point.ord - character_end_point.ord).abs\nhorizontal_moves_character = character_start_point.ord < character_end_point.ord ? 'R' : 'L'\n\nmax_steps = vertical_moves_count > horizontal_moves_count ? vertical_moves_count : horizontal_moves_count\n\nputs max_steps\n\nwhile max_steps > 0\n print horizontal_moves_character if horizontal_moves_count > 0\n print vertical_moves_character if vertical_moves_count > 0\n puts\n horizontal_moves_count -= 1\n vertical_moves_count -= 1\n max_steps -= 1\nend\n"}, {"source_code": "def f(x,y,gx,gy)\n\tif x==gx && y==gy then\n\t\treturn \"\"\n\telse\n\t\tres=\"\"\n\t\tx1=x\n\t\ty1=y\n\t\tif xgx\n\t\t\tx1=x-1\n\t\t\tres+=\"L\"\n\t\tend\n\t\tif ygy then\n\t\t\ty1=y-1\n\t\t\tres+=\"D\"\n\t\tend\n\t\treturn res+\"\\n\"+f(x1,y1,gx,gy)\n\tend\n\t\nend\n\n\nh=\tHash[\"a\",1,\"b\",2,\"c\",3,\"d\",4,\n\t\t \"e\",5,\"f\",6,\"g\",7,\"h\",8]\n\ns1=gets.chomp\ns2=gets.chomp\nif s1==s2 then\n\tputs \"0\\n\"\nelse\n\tx=f(h[s1[0]],s1[1].to_i,h[s2[0]],s2[1].to_i).split()\n\tputs x.size\n\tputs x*\"\\n\"\nend\n\n"}, {"source_code": "s=gets\nt=gets\nr=t[0].ord-s[0].ord\nc=t[1].hex-s[1].hex\na=[\"\"]*9\nf=lambda{|r,c|r.times{|i|a[i]+=c}}\nf.call(r,\"R\")\nf.call(-r,\"L\")\nf.call(c,\"U\")\nf.call(-c,\"D\")\na.select!{|i|i!=\"\"}\np a.size\nputs a"}, {"source_code": "s=gets\nt=gets\nr=t[0].ord-s[0].ord\nc=t[1].hex-s[1].hex\na=[\"\"]*9\nf=lambda{|r,c|r.times{|i|a[i]+=c}}\nf.call(r,\"R\")\nf.call(-r,\"L\")\nf.call(c,\"U\")\nf.call(-c,\"D\")\na.select!{|i|i!=\"\"}\np a.size\nputs a"}, {"source_code": "start = gets().chomp!\nfinish = gets().chomp!\nLETTERS = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\"]\nh_distance, v_distance = [LETTERS.index(finish[0,1]) - LETTERS.index(start[0,1]), finish[1,1].to_i - start[1,1].to_i]\nmoves = Array.new(7){\"\"}\nh_distance.abs().times {\n|i|\n h_distance > 0 ? moves[i] << \"R\" : moves[i] << \"L\"\n}\nv_distance.abs().times {\n|i|\n v_distance > 0 ? moves[i] << \"U\" : moves[i] << \"D\"\n}\nmoves = moves.select(){|elem| elem != \"\"}\nputs moves.length, moves"}, {"source_code": "start = gets().chomp!\nfinish = gets().chomp!\nLETTERS = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\"]\nh_distance = LETTERS.index(finish[0,1]) - LETTERS.index(start[0,1])\nv_distance = finish[1,1].to_i - start[1,1].to_i\nmoves = Array.new(7){\"\"}\nh_distance.abs().times {\n|i|\n h_distance > 0 ? moves[i] << \"R\" : moves[i] << \"L\"\n}\nv_distance.abs().times {\n|i|\n v_distance > 0 ? moves[i] << \"U\" : moves[i] << \"D\"\n}\nmoves = moves.select(){|elem| elem != \"\"}\nputs moves.length, moves"}, {"source_code": "s,t = readlines.join.split\nsx,sy = s[0].ord - 'a'.ord, s[1].to_i-1\ngx,gy = t[0].ord - 'a'.ord, t[1].to_i-1\na=[\"\"]*9\nf = lambda{|r,c| r.times{|i| a[i] += c}}\nf.call(gx-sx,'R')\nf.call(sx-gx,'L')\nf.call(sy-gy,'D')\nf.call(gy-sy,'U')\na.select!{|i| i != \"\"}\nputs a.size\nputs a\n"}, {"source_code": "s,t = readlines.join.split\nsx,sy = s[0].ord - 'a'.ord, s[1].to_i-1\ngx,gy = t[0].ord - 'a'.ord, t[1].to_i-1\n\ndx = (sx-gx).abs\ndy = (sy-gy).abs\nxchar = sx < gx ? 'R' : 'L'\nychar = sy < gy ? 'U' : 'D'\n\nans = []\ncnt = 0\nwhile dx > 0 && dy > 0\n ans << (xchar+ychar)\n dx -= 1\n dy -= 1\nend\n\nwhile dx > 0\n ans << xchar\n dx -= 1\nend\n\nwhile dy > 0\n ans << ychar\n dy -= 1\nend\n\nputs ans.size\nputs ans\n"}, {"source_code": "start = gets\nstart_x = start[0].ord - 97\nstart_y = start[1].to_i - 1\n\nfinish = gets\nfinish_x = finish[0].ord - 97\nfinish_y = finish[1].to_i - 1\n\nresult = []\n\nif start_x < finish_x\n\t# go right\n\t(finish_x - start_x).times do\n\t\tresult << [\"R\"]\n\tend\nelse\n\t# go left\n\t(start_x - finish_x).times do\n\t\tresult << [\"L\"]\n\tend\nend\n\nif start_y < finish_y\n\t# go up\n\t(finish_y - start_y).times do |index|\n\t\tif result[index].nil?\n\t\t\tresult << [\"U\"]\n\t\telse \n\t\t\tresult[index][0]<< \"U\"\n\t\tend\n\tend\nelse\n\t# go down\n\t(start_y - finish_y).times do |index|\n\t\tif result[index].nil?\n\t\t\tresult << [\"D\"]\n\t\telse \n\t\t\tresult[index][0]<< \"D\"\n\t\tend\n\tend\nend\n\nputs result.length\nputs result"}, {"source_code": "s = STDIN.readline\nt = STDIN.readline\n\nprint [(s[0].ord-t[0].ord).abs,(s[1].ord-t[1].ord).abs].max\nprint ?\\n\n\nwhile s != t ;\n\tif s[0] < t[0] ;\n\t\tprint ?R\n\t\ts[0] = (s[0].ord+1).chr\n\telsif s[0] > t[0] ;\n\t\tprint ?L\n\t\ts[0] = (s[0].ord-1).chr\n\tend\n\tif s[1] < t[1] ;\n\t\tprint ?U\n\t\ts[1] = (s[1].ord+1).chr\n\telsif s[1] > t[1] ;\n\t\tprint ?D\n\t\ts[1] = (s[1].ord-1).chr\n\tend\n\tprint ?\\n\nend\n"}, {"source_code": "class Solver\n def solve(*a)\n p = a[0]\n t = a[1]\n\n moves = []\n while p != t && moves.size < 8\n #puts \"#{p} -> #{t}\"\n\n moves << navigate(p,t)\n end\n moves\n end\n\n def navigate(p,t)\n dx = dir(t[0].ord - p[0].ord)\n dy = dir(t[1].ord - p[1].ord)\n\n p[0] = (p[0].ord + dx).chr\n p[1] = (p[1].ord + dy).chr\n\n ['L','','R'][dx+1] + ['D','','U'][dy+1]\n end\n\n def dir(d)\n return 0 if d == 0\n return 1 if d > 0\n return -1\n end\nend\n\nif __FILE__==$0\n a = gets.chomp\n b = gets.chomp\n s = Solver.new\n sol = s.solve(a,b)\n puts sol.count\n sol.each do |s|\n puts s\n end\nend"}, {"source_code": "s=gets.chomp.split(\"\")\nt=gets.chomp.split(\"\")\nvalu=1..8\nalph=('a' .. 'h')\nvalu=[*valu]\nalph=[*alph]\nvalu_hash={}\ni=0\nloop do\n\tbreak if i==8\n\tvalu_hash[alph[i]]=valu[i]\n\ti+=1\n end\ndir_arry=[] \nif valu_hash[s[0]]< valu_hash[t[0]]\n dir_arry[0]=\"R\"\nelsif valu_hash[s[0]]> valu_hash[t[0]] \n dir_arry[0]=\"L\"\nelse\n dir_arry[0]=0\nend\n \nif s[1].to_i< t[1].to_i\n dir_arry[1]=\"U\"\nelsif s[1].to_i> t[1].to_i \n dir_arry[1]=\"D\"\nelse\n dir_arry[1]=0\nend\n\nhmove=valu_hash[s[0]] - valu_hash[t[0]]\nif hmove<0\nhmove=hmove*(-1)\nend\nvmove=s[1].to_i-t[1].to_i\nif vmove<0\nvmove=vmove*(-1)\nend\n\nif hmove==0\n\tputs vmove\n\tvmove.times{puts dir_arry[1]}\nelsif vmove==0\n\tputs hmove\n\thmove.times{puts dir_arry[0] }\nelsif vmove==hmove\n\tputs hmove\n hmove.times{puts dir_arry[0]+dir_arry[1] }\nelsif hmove>vmove\n\tputs hmove\n\tvmove.times{puts dir_arry[0]+dir_arry[1] }\n\t(hmove-vmove).times {puts dir_arry[0]}\nelsif vmove>hmove\n\tputs vmove\n\thmove.times{puts dir_arry[0]+dir_arry[1] }\n\t(vmove-hmove).times{puts dir_arry[1]}\nend\t\n\t\t\n\n\n"}, {"source_code": "s,t = gets.strip.bytes.to_a, gets.strip.bytes.to_a\nmoves = []\nwhile s != t\n move = \"\"\n if s[0] < t[0]\n s[0] += 1\n move += \"R\"\n elsif s[0] > t[0]\n s[0] -= 1\n move += \"L\"\n end\n if s[1] < t[1]\n s[1] += 1\n move += \"U\"\n elsif s[1] > t[1]\n s[1] -= 1\n move += \"D\"\n end\n moves << move\nend\n\nputs moves.size\nfor s in moves do \n puts s\nend\n\n"}, {"source_code": "coord_src = gets\ncoord_dest = gets\n\ncoord_src_x = 1 + coord_src[0].ord - 'a'.ord\ncoord_src_y = coord_src[1].to_i\ncoord_dest_x = 1 + coord_dest[0].ord - 'a'.ord\ncoord_dest_y = coord_dest[1].to_i\n\n#puts coord_src_x.to_s + \" \" + coord_src_y.to_s\n#puts coord_dest_x.to_s + \" \" + coord_dest_y.to_s\n\nmoves = []\n\n# Firstly, move diagonally in the correct direction.\nwhile (coord_src_x != coord_dest_x && coord_src_y != coord_dest_y) do\n if coord_src_x > coord_dest_x\n coord_src_x -= 1\n if coord_src_y > coord_dest_y\n moves.push(\"LD\")\n coord_src_y -= 1\n else\n moves.push(\"LU\")\n coord_src_y += 1\n end\n else\n coord_src_x += 1\n if coord_src_y > coord_dest_y\n moves.push(\"RD\")\n coord_src_y -= 1\n else\n moves.push(\"RU\")\n coord_src_y += 1\n end\n end\nend\n\n# Now it is just a straightaway\nif(coord_src_x > coord_dest_x)\n (coord_src_x - coord_dest_x).times { moves.push(\"L\") }\nelsif (coord_src_x < coord_dest_x)\n (coord_dest_x - coord_src_x).times { moves.push(\"R\") }\n \nelsif(coord_src_y > coord_dest_y)\n (coord_src_y - coord_dest_y).times { moves.push(\"D\") }\nelsif (coord_src_y < coord_dest_y)\n (coord_dest_y - coord_src_y).times { moves.push(\"U\") }\nend\n \nputs moves.size\nmoves.each { |move| puts move }\n \n \n \n \n "}, {"source_code": "input = STDIN.read.split(\"\\n\")\na, b = input[0].split(''), input[1].split('')\na[1], b[1] = a[1].to_i, b[1].to_i\n\nif a == b\n\tSTDOUT.print 0\n\texit\nend\n\nif a[0] > b[0]\n\tx_dir = \"L\"\nelsif a[0] < b[0]\n\tx_dir = \"R\"\nend\n\nif a[1] > b[1]\n\ty_dir = \"D\"\nelsif a[1] < b[1]\n\ty_dir = \"U\"\nend\n\nstr = \"\"\ncount = 0\n\nwhile true do\n\n\tif a[0] != b[0]\n\t\ta[0].next! if x_dir == \"R\"\n\t\ta[0] = (a[0].ord - 1).chr if x_dir == \"L\"\n\t\tstr << x_dir\n\tend\n\n\tif a[1] != b[1]\n\t\ta[1] += 1 if y_dir == \"U\"\n\t\ta[1] -= 1 if y_dir == \"D\"\n\t\tstr << y_dir\n\tend\n\n\tcount += 1\n\tstr << \"\\n\"\n\n\tbreak if a == b\n\nend\n\nSTDOUT.print count, \"\\n\", str"}, {"source_code": "input = STDIN.read.split(\"\\n\")\na, b = input[0].split(''), input[1].split('')\na[0], b[0], a[1], b[1] = a[0].ord, b[0].ord, a[1].to_i, b[1].to_i\n\nif a == b\n\tSTDOUT.print 0\n\texit\nend\n\nx_dir = a[0] > b[0] ? \"L\" : \"R\"\ny_dir = a[1] > b[1] ? \"D\" : \"U\"\n\nstr, count = '', 0\n\nloop do\n\n\tif a[0] != b[0]\n\t\tx_dir == \"R\" ? a[0] += 1 : a[0] -= 1\n\t\tstr << x_dir\n\tend\n\n\tif a[1] != b[1]\n\t\ty_dir == \"U\" ? a[1] += 1 : a[1] -= 1\n\t\tstr << y_dir\n\tend\n\n\tcount += 1\n\tstr << \"\\n\"\n\n\tbreak if a == b\n\nend\n\nSTDOUT.print count, \"\\n\", str"}, {"source_code": "input = STDIN.read.split(\"\\n\")\na, b = input[0].split(''), input[1].split('')\na[1], b[1] = a[1].to_i, b[1].to_i\n\nif a == b\n\tSTDOUT.print 0\n\texit\nend\n\nx_dir = a[0] > b[0] ? \"L\" : \"R\"\ny_dir = a[1] > b[1] ? \"D\" : \"U\"\n\nstr, count = '', 0\n\nwhile true do\n\n\tif a[0] != b[0]\n\t\ta[0] = x_dir == \"R\" ? a[0].next : (a[0].ord - 1).chr\n\t\tstr << x_dir\n\tend\n\n\tif a[1] != b[1]\n\t\ty_dir == \"U\" ? a[1] += 1 : a[1] -= 1\n\t\tstr << y_dir\n\tend\n\n\tcount += 1\n\tstr << \"\\n\"\n\n\tbreak if a == b\n\nend\n\nSTDOUT.print count, \"\\n\", str"}], "negative_code": [{"source_code": "# require 'pry-byebug'\nfile = File.exist?('in.in') ? File.new('in.in','r') : STDIN\n\nDX = [0, 1, 0, -1, 1, -1, 1, -1]\nDY = [1, 0, -1, 0, 1, -1, -1, 1]\nMOV = [\"R\", \"D\", \"L\", \"U\", \"RD\", \"LU\", \"LD\", \"RU\"]\n\ndef inside?(i, j, grid)\n i>=0 && i<= grid.size-1 && j>=0 && j <=grid[0].size-1\nend\n\nmap = {\"a\"=> 0, \"b\"=> 1, \"c\"=> 2, \"d\"=> 3, \"e\"=> 4,\"f\"=> 5, \"g\"=> 6, \"h\" => 7}\n\ns1,s2 = file.gets.chomp.split('')\nt1,t2 = file.gets.chomp.split('')\n\nreturn puts 0 if s1==t1 && s2==t2\n\ns1 = map[s1]\ns2 = (s2.to_i-1-7).abs\nt1 = map[t1]\nt2 = (t2.to_i-1-7).abs\n\n# puts \"#{s1}#{s2}\"\n# puts \"#{t1}#{t2}\"\n\ngrid = Array.new(8) { Array.new(8) }\ndist = Array.new(8) { Array.new(8, 100) }\nqueue = [[s1, s2]]\ndist[s1][s2]=0\ngrid[s1][s2]=[]\n\nwhile(queue.size != 0)\n x, y = queue.shift\n 8.times do |i|\n new_x = x+DX[i]\n new_y = y+DY[i]\n if inside?(new_x, new_y, grid) && dist[new_x][new_y]==100\n\n if dist[x][y]+1 < dist[new_x][new_y]\n dist[new_x][new_y] = dist[x][y]+1\n grid[new_x][new_y] = grid[x][y] + [MOV[i]]\n end\n\n # dist[new_x][new_y] = [dist[new_x][new_y],dist[x][y]+1].min\n break if new_x == t1 && new_y == t2\n # binding.pry if dist[new_x][new_y] == 7\n queue << [new_x, new_y]\n end\n end\nend\nputs dist[t1][t2]\ngrid[t1][t2].each do |e|\n puts e\nend"}, {"source_code": "#!usr/bin/env ruby\n\n# https://codeforces.com/problemset/problem/3/A\n\nstart = gets.chomp\nfinish = gets.chomp\n\nwhile ! start.eql? finish do\n move = \"\"\n\n if start[0] < finish[0]\n move += \"U\"\n start[0] = start[0].next\n elsif start[0] > finish[0]\n move += \"D\"\n start[0] = (start[0].ord - 1).chr\n end\n\n if start[1] < finish[1]\n move += \"R\"\n start[1] = start[1].next\n elsif start[1] > finish[1]\n move += \"L\"\n start[1] = (start[1].ord - 1).chr\n end\n\n puts move\nend\n\n"}, {"source_code": "# http://codeforces.com/problemset/problem/3/A\n\nclass Node\n attr_accessor :distance, :visited, :prev, :x, :y, :cost\n\n def initialize(x=0, y=0, cost=1)\n @distance = Float::INFINITY\n @visited = false\n @prev = nil\n @x = x\n @y = y\n @cost = cost\n end\nend\n\ndef make_graph(x, y)\n (0...x).map { |x| (0...y).map { |y| Node.new(x, y) } }\nend\n\ndef find_unvisited(graph)\n graph.flatten { |y| y.visited == false }\nend\n\ndef min(unvisited, graph)\n min = unvisited.map { |node| node.distance }.each_with_index.min\n unvisited[min[1]]\nend\n\ndef in_range(x, y, graph)\n x >= 0 && y >= 0 && x < graph.size && y < graph[0].size && !graph[x][y].visited\nend\n\ndef get_neighbors(x, y, graph)\n l = [x-1, y]\n r = [x+1, y]\n t = [x, y+1]\n b = [x, y-1]\n lt = [x-1, y+1]\n rt = [x+1, y+1]\n rb = [x+1, y-1]\n lb = [x-1, y-1]\n \n [l,r,t,b,lt,rt,rb,lb].select { |neighbor| in_range(neighbor[0], neighbor[1], graph) }\nend\n\ndef visit(node, graph)\n neighbors = get_neighbors(node.x, node.y, graph)\n neighbors.each do |n|\n neighbor = graph[n[0]][n[1]]\n neighbor.visited = true\n dist = node.distance + neighbor.cost\n if dist < neighbor.distance\n neighbor.distance = dist\n neighbor.prev = node\n end\n end\nend\n\ndef dijkstra(graph, source, target)\n graph[source[0]][source[1]].distance = 0\n unvisited = find_unvisited(graph)\n\n while unvisited.any?\n current_node = min(unvisited, graph)\n return current_node if current_node.x == target[0] && current_node.y == target[1]\n unvisited.delete(current_node)\n visit(current_node, graph)\n end\nend\n\ndef convert_source(coord)\n [coord[0].ord - 96 - 1, Integer(coord[1]) -1]\nend\n\ndef to_directions(from, to)\n return if to == nil\n str = \"\"\n if to.x > from.x\n str << \"R\"\n end\n if to.y > from.y\n str << \"U\"\n end\n if to.y < from.y\n str << \"D\"\n end\n if to.x < from.x\n str << \"L\"\n end\n str\nend\n\ndef get_answer_nodes(root)\n nodes = []\n current_node = root\n while !current_node.nil?\n nodes << current_node\n current_node = current_node.prev\n end\n nodes.reverse\nend\n\ndef format_answer(answer)\n nodes = get_answer_nodes(answer)\n directions = [nodes.size-1]\n nodes.each_with_index do |node, i|\n directions << to_directions(nodes[i], nodes[i+1])\n end\n directions\nend\n\ndef solve\n graph = make_graph(8, 8)\n source = gets\n target = gets\n answer = dijkstra(graph, convert_source(source.chomp), convert_source(target.chomp))\n puts format_answer(answer).join(\"\\n\")\nend\n\nsolve()\n\n\n"}, {"source_code": "s = gets\nt = gets\nsx = s[0..0].ord\nsy = s[1..1].to_i\ntx = t[0..0].ord\nty = t[1..1].to_i\ndx = sx-tx\ndy = sy-ty\nstep = [dx.abs,dy.abs].max\nputs step\nstep.times do\n if dx<0\n print \"R\"\n dx += 1\n elsif dx>0\n print \"L\"\n dx -= 1\n end\n if dy<0\n print \"U\"\n dy += 1\n elsif dy>0\n print \"D\"\n dy += 1\n end\n puts\nend\n"}, {"source_code": "class King\n def initialize(s, t)\n @start = s\n @end = t\n end\n\n def get_path\n result = []\n horizontal = (@start[0] == @end[0])\n vertical = (@start[1] == @end[1])\n if @start == @end\n result << 0\n elsif horizontal\n result = [steps_x.abs] + [direction.last]*steps_x.abs\n elsif vertical\n result = [steps_y.abs] + [direction.first]*steps_y.abs\n else\n current = @start\n steps = 0\n until horizontal || vertical\n current = move_diag(current)\n horizontal = (current[0] == @end[0])\n vertical = (current[1] == @end[1])\n result << direction.join\n steps += 1\n end\n if vertical\n current_steps = (current[0].ord.to_i - @end[0].ord.to_i).abs\n result += [direction.last]*current_steps\n steps += current_steps\n elsif horizontal\n current_steps = (current[1].to_i - @end[1].to_i).abs\n result += [direction.first]*current_steps\n steps += current_steps\n end\n result.unshift(steps)\n end\n result\n end\n\n def move_diag(position)\n x_inc = steps_x == 0 ? 0 : steps_x/steps_x.abs\n y_inc = steps_y == 0 ? 0 : steps_y/steps_y.abs\n [(position[0].ord+x_inc).chr, (position[1].to_i + y_inc)].join\n end\n\n def direction\n [direction_y, direction_x]\n end\n\n def direction_x\n steps_x > 0 ? 'D' : 'U'\n end\n\n def direction_y\n steps_y > 0 ? 'L' : 'R'\n end\n\n def steps_x\n @start[1].to_i - @end[1].to_i\n end\n\n def steps_y\n @start[0].ord.to_i - @end[0].ord.to_i\n end\nend\n\ns, t = [gets.chomp, gets.chomp]\ngame = King.new(s, t)\nputs game.get_path\n"}, {"source_code": "class King\n def initialize(s, t)\n @start = s\n @end = t\n end\n\n def get_path\n result = []\n horizontal = (@start[0] == @end[0])\n vertical = (@start[1] == @end[1])\n if @start == @end\n result << 0\n elsif horizontal\n result = [steps_x] + [direction.last]*steps_x.abs\n elsif vertical\n result = [steps_y] + [direction.first]*steps_y.abs\n else\n current = @start\n steps = 0\n until horizontal || vertical\n current = move_diag(current)\n horizontal = (current[0] == @end[0])\n vertical = (current[1] == @end[1])\n result << direction.join\n steps += 1\n end\n if vertical\n current_steps = (current[0].ord.to_i - @end[0].ord.to_i).abs\n result += [direction.last]*current_steps\n steps += current_steps\n elsif horizontal\n current_steps = (current[1].to_i - @end[1].to_i).abs\n result += [direction.first]*current_steps\n steps += current_steps\n end\n result.unshift(steps)\n end\n result\n end\n\n def move_diag(position)\n x_inc = steps_x == 0 ? 0 : steps_x/steps_x.abs\n y_inc = steps_y == 0 ? 0 : steps_y/steps_y.abs\n [(position[0].ord+x_inc).chr, (position[1].to_i + y_inc)].join\n end\n\n def direction\n [direction_y, direction_x]\n end\n\n def direction_x\n steps_x > 0 ? 'D' : 'U'\n end\n\n def direction_y\n steps_y > 0 ? 'L' : 'R'\n end\n\n def steps_x\n @start[1].to_i - @end[1].to_i\n end\n\n def steps_y\n @start[0].ord.to_i - @end[0].ord.to_i\n end\nend\n\ns, t = [gets.chomp, gets.chomp]\ngame = King.new(s, t)\nputs game.get_path\n"}, {"source_code": "class King\n def initialize(s, t)\n @start = s\n @end = t\n end\n\n def get_path\n result = []\n horizontal = (@start[0] == @end[0])\n vertical = (@start[1] == @end[1])\n if @start == @end\n result << 0\n elsif horizontal\n result = [steps_x] + [direction.first]*steps_x.abs\n elsif vertical\n result = [steps_y] + [direction.last]*steps_y.abs\n else\n current = @start\n steps = 0\n until horizontal || vertical\n current = move_diag(current)\n horizontal = (current[0] == @end[0])\n vertical = (current[1] == @end[1])\n result << direction.join\n steps += 1\n end\n if vertical\n current_steps = (current[0].ord.to_i - @end[0].ord.to_i).abs\n result += [direction.last]*current_steps\n steps += current_steps\n elsif horizontal\n current_steps = (current[1].to_i - @end[1].to_i).abs\n result += [direction.first]*current_steps\n steps += current_steps\n end\n result.unshift(steps)\n end\n result\n end\n\n def move_diag(position)\n x_inc = steps_x == 0 ? 0 : steps_x/steps_x.abs\n y_inc = steps_y == 0 ? 0 : steps_y/steps_y.abs\n [(position[0].ord+x_inc).chr, (position[1].to_i + y_inc)].join\n end\n\n def direction\n [direction_y, direction_x]\n end\n\n def direction_x\n steps_x > 0 ? 'D' : 'U'\n end\n\n def direction_y\n steps_y > 0 ? 'L' : 'R'\n end\n\n def steps_x\n @start[1].to_i - @end[1].to_i\n end\n\n def steps_y\n @start[0].ord.to_i - @end[0].ord.to_i\n end\nend\n\ns, t = [gets.chomp, gets.chomp]\ngame = King.new(s, t)\nputs game.get_path\n"}, {"source_code": "s1 = gets\ns2 = gets\ndst1 = s2[0].ord - s1[0].ord\ndst2 = s2[1].to_i - s1[1].to_i\n\nputs [dst2.abs, dst1.abs].max\nwhile dst2 != 0 and dst1 != 0 do\n if dst1 > 0 then\n printf \"R\"\n dst1 -= 1\n end\n if dst1 < 0 then\n printf \"L\"\n dst1 += 1\n end\n\n if dst2 > 0 then\n printf \"U\"\n dst2 -= 1\n end\n if dst2 < 0 then\n printf \"D\"\n dst2 += 1\n end\n puts\nend\n"}, {"source_code": "start = gets().chomp!\nfinish = gets().chomp!\nLETTERS = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\"]\nh_distance, v_distance = [LETTERS.index(finish[0,1]) - LETTERS.index(start[0,1]), finish[1,1].to_i - start[1,1].to_i]\nmoves = Array.new(7){\"\"}\nh_distance.abs().times {\n|i|\n h_distance > 0 ? moves[i] << \"R\" : moves[i] << \"L\"\n}\nv_distance.abs().times {\n|i|\n v_distance > 0 ? moves[i] << \"U\" : moves[i] << \"D\"\n}\nmoves.select(){|elem| elem != \"\"}\nputs moves.length, moves"}, {"source_code": "s,t = readlines.join.split\nsx,sy = s[0].ord - 'a'.ord, s[1].to_i-1\ngx,gy = t[0].ord - 'a'.ord, t[1].to_i-1\na=[\"\"]*9\nf = lambda{|r,c| r.times{|i| a[i] += c}}\nf.call(sx-gx,'R')\nf.call(gx-sx,'L')\nf.call(sy-gy,'D')\nf.call(gy-sy,'U')\na.select!{|i| i != \"\"}\nputs a.size\nputs a\n"}, {"source_code": "a, b = gets.chop.split(''), gets.chop.split('')\na[1], b[1] = a[1].to_i, b[1].to_i\n\nif a[0] > b[0]\n\tx_dir = \"L\"\nelsif a[0] < b[0]\n\tx_dir = \"R\"\nend\n\nif a[1] > b[1]\n\ty_dir = \"D\"\nelsif a[1] < b[1]\n\ty_dir = \"U\"\nend\n\nstr = \"\"\ncount = 0\n\nwhile true do\n\n\tif a[0] != b[0]\n\t\ta[0].next! if x_dir == \"R\"\n\t\ta[0].prev! if x_dir == \"L\"\n\t\tstr << x_dir\n\tend\n\n\tif a[1] != b[1]\n\t\ta[1] += 1 if y_dir == \"U\"\n\t\ta[1] -= 1 if y_dir == \"D\"\n\t\tstr << y_dir\n\tend\n\n\tcount += 1\n\tstr << \"\\n\"\n\n\tbreak if a == b\n\nend\n\nSTDOUT.print count, \"\\n\", str"}], "src_uid": "d25d454702b7755297a7a8e1f6f36ab9"} {"nl": {"description": "There is a white sheet of paper lying on a rectangle table. The sheet is a rectangle with its sides parallel to the sides of the table. If you will take a look from above and assume that the bottom left corner of the table has coordinates $$$(0, 0)$$$, and coordinate axes are left and bottom sides of the table, then the bottom left corner of the white sheet has coordinates $$$(x_1, y_1)$$$, and the top right \u2014 $$$(x_2, y_2)$$$.After that two black sheets of paper are placed on the table. Sides of both black sheets are also parallel to the sides of the table. Coordinates of the bottom left corner of the first black sheet are $$$(x_3, y_3)$$$, and the top right \u2014 $$$(x_4, y_4)$$$. Coordinates of the bottom left corner of the second black sheet are $$$(x_5, y_5)$$$, and the top right \u2014 $$$(x_6, y_6)$$$. Example of three rectangles. Determine if some part of the white sheet can be seen from the above after the two black sheets are placed. The part of the white sheet can be seen if there is at least one point lying not strictly inside the white sheet and strictly outside of both black sheets.", "input_spec": "The first line of the input contains four integers $$$x_1, y_1, x_2, y_2$$$ $$$(0 \\le x_1 < x_2 \\le 10^{6}, 0 \\le y_1 < y_2 \\le 10^{6})$$$ \u2014 coordinates of the bottom left and the top right corners of the white sheet. The second line of the input contains four integers $$$x_3, y_3, x_4, y_4$$$ $$$(0 \\le x_3 < x_4 \\le 10^{6}, 0 \\le y_3 < y_4 \\le 10^{6})$$$ \u2014 coordinates of the bottom left and the top right corners of the first black sheet. The third line of the input contains four integers $$$x_5, y_5, x_6, y_6$$$ $$$(0 \\le x_5 < x_6 \\le 10^{6}, 0 \\le y_5 < y_6 \\le 10^{6})$$$ \u2014 coordinates of the bottom left and the top right corners of the second black sheet. The sides of each sheet of paper are parallel (perpendicular) to the coordinate axes.", "output_spec": "If some part of the white sheet can be seen from the above after the two black sheets are placed, print \"YES\" (without quotes). Otherwise print \"NO\".", "sample_inputs": ["2 2 4 4\n1 1 3 5\n3 1 5 5", "3 3 7 5\n0 0 4 6\n0 0 7 4", "5 2 10 5\n3 1 7 6\n8 1 11 7", "0 0 1000000 1000000\n0 0 499999 1000000\n500000 0 1000000 1000000"], "sample_outputs": ["NO", "YES", "YES", "YES"], "notes": "NoteIn the first example the white sheet is fully covered by black sheets.In the second example the part of the white sheet can be seen after two black sheets are placed. For example, the point $$$(6.5, 4.5)$$$ lies not strictly inside the white sheet and lies strictly outside of both black sheets."}, "positive_code": [{"source_code": "def is_hor_line_in_b(line, b)\n res = false\n if b[0][0][0] <= line[0][0] && b[0][1][0] >= line[1][0] && line[0][1] >= b[0][0][1] && line[0][1] <= b[0][1][1] ||\n b[0][0][0] <= line[0][0] && b[0][1][0] >= b[1][0][0] && b[1][1][0] >= line[1][0] &&\n line[0][1] >= b[0][0][1] && line[0][1] <= b[0][1][1] && line[0][1] >= b[1][0][1] && line[0][1] <= b[1][1][1]\n res = true\n end\n b[0], b[1] = b[1], b[0]\n if b[0][0][0] <= line[0][0] && b[0][1][0] >= line[1][0] && line[0][1] >= b[0][0][1] && line[0][1] <= b[0][1][1] ||\n b[0][0][0] <= line[0][0] && b[0][1][0] >= b[1][0][0] && b[1][1][0] >= line[1][0] &&\n line[0][1] >= b[0][0][1] && line[0][1] <= b[0][1][1] && line[0][1] >= b[1][0][1] && line[0][1] <= b[1][1][1]\n res = true\n end\n res\nend\n\ndef is_ver_line_in_b(line, b)\n res = false\n if b[0][0][1] <= line[0][1] && b[0][1][1] >= line[1][1] && line[0][0] >= b[0][0][0] && line[0][0] <= b[0][1][0] ||\n b[0][0][1] <= line[0][1] && b[0][1][1] >= b[1][0][1] && b[1][1][1] >= line[1][1] &&\n line[0][0] >= b[0][0][0] && line[0][0] <= b[0][1][0] && line[0][0] >= b[1][0][0] && line[0][0] <= b[1][1][0]\n res = true\n end\n b[0], b[1] = b[1], b[0]\n if b[0][0][1] <= line[0][1] && b[0][1][1] >= line[1][1] && line[0][0] >= b[0][0][0] && line[0][0] <= b[0][1][0] ||\n b[0][0][1] <= line[0][1] && b[0][1][1] >= b[1][0][1] && b[1][1][1] >= line[1][1] &&\n line[0][0] >= b[0][0][0] && line[0][0] <= b[0][1][0] && line[0][0] >= b[1][0][0] && line[0][0] <= b[1][1][0]\n res = true\n end\n res\nend\n\n\nw = gets.chomp.split(' ').map(&:to_i)\nb = [[], []]\nb[0] = gets.chomp.split(' ').map(&:to_i).each_slice(2).to_a\nb[1] = gets.chomp.split(' ').map(&:to_i).each_slice(2).to_a\nline_h1 = [[w[0], w[1]], [w[2], w[1]]]\nline_h2 = [[w[0], w[3]], [w[2], w[3]]]\nline_v1 = [[w[0], w[1]], [w[0], w[3]]]\nline_v2 = [[w[2], w[1]], [w[2], w[3]]]\nif is_hor_line_in_b(line_h1, b) && is_hor_line_in_b(line_h2, b) &&\n is_ver_line_in_b(line_v1, b) && is_ver_line_in_b(line_v2, b)\n puts \"NO\"\nelse\n puts \"YES\"\nend\n"}, {"source_code": "#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']\n\ndef inpf() a=gets.chomp.split(\" \").map(&:to_f)end\n\ndef inps() a=gets.chomp.split(\" \")end\n\ndef copy(a) Marshal.load(Marshal.dump(a)) end\n\ndef kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end\n\ndef na(n,d=0) Array.new(n,d)end\n\ndef na2(n,m,d=0) Array.new(n){Array.new(m,d)}end\n\ndef na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end\n\ndef inp() a=gets.chomp.split(\" \").map(&:to_i)end\n\ndef r_up(a, b) (a+b-1)/b end\n\ndef sum(a) a.inject(:+) end\n\nhx = {}\nhy = {}\na = inp\nb = inp\nc = inp\nx = [a[0],a[2],b[0],b[2],c[0],c[2]].sort\ny = [a[1],a[3],b[1],b[3],c[1],c[3]].sort\nx.each.with_index do |d,i|\n hx[d] = i\nend\ny.each.with_index do |d,i|\n hy[d] = i\nend\nt = na2(x.size,y.size,false)\n(hx[a[0]]...hx[a[2]]).each do |x|\n (hy[a[1]]...hy[a[3]]).each do |y|\n t[x][y] = true\n end\nend\n(hx[b[0]]...hx[b[2]]).each do |x|\n (hy[b[1]]...hy[b[3]]).each do |y|\n t[x][y] = false\n end\nend\n(hx[c[0]]...hx[c[2]]).each do |x|\n (hy[c[1]]...hy[c[3]]).each do |y|\n t[x][y] = false\n end\nend\n\nputs (t.flatten.include?(true))? \"YES\" : \"NO\"\n"}, {"source_code": "MOD=10**9+7\ncnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)\ndef gs() gets.chomp end\ndef gi() gets.to_i end\ndef gsmi() gets.chomp.split.map(&:to_i) end\n\ndef desc(ar) ar.sort!{|x,y|y<=>x} end\ndef min(a,b) a<=b ? a : b end\ndef max(a,b) a>=b ? a : b end\ndef sum(ar) ar.inject(:+) end\n\n#def bs(ar,eq,n) en=(eq==1 ? :>= : :>); ar.bsearch_index{|x|x.send(en,n)} end\ndef C(a,b) b==0||a==b ? 1 : (b=a-b if a/2=x2&&y4>=y2)||(x5<=x1&&y5<=y1&&x6>=x2&&y6>=y2)\n putsend('NO')\nend\n# half cover\n# \u305f\u3066\nif (y3<=y1&&y4>=y2 &&y5<=y1&&y6>=y2) && ((x5<=x2&&x6>=x2&&x3<=x1&&x4>=x1&&x4>=x5)||(x3<=x2&&x4>=x2&&x5<=x1&&x6>=x1&&x6>=x3))\n putsend('NO')\nend\n# \u3088\u3053\nif (x3<=x1&&x4>=x2 &&x5<=x1&&x6>=x2) && ((y5<=y2&&y6>=y2&&y3<=y1&&y4>=y1&&y4>=y5)||(y3<=y2&&y4>=y2&&y5<=y1&&y6>=y1&&y6>=y3))\n putsend('NO')\nend\n\nputsend('YES')\n"}], "negative_code": [{"source_code": "MOD=10**9+7\ncnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)\ndef gs() gets.chomp end\ndef gi() gets.to_i end\ndef gsmi() gets.chomp.split.map(&:to_i) end\n\ndef desc(ar) ar.sort!{|x,y|y<=>x} end\ndef min(a,b) a<=b ? a : b end\ndef max(a,b) a>=b ? a : b end\ndef sum(ar) ar.inject(:+) end\n\n#def bs(ar,eq,n) en=(eq==1 ? :>= : :>); ar.bsearch_index{|x|x.send(en,n)} end\ndef C(a,b) b==0||a==b ? 1 : (b=a-b if a/2=x2&&y4>=y2)||(x5<=x1&&y5<=y1&&x6>=x2&&y6>=y2)\n putsend('NO')\nend\n# half cover\n# \u305f\u3066\nif (y3<=y1&&y4>=y2 &&y5<=y1&&y6>=y2) && ((x5<=x2&&x6>=x2&&x3<=x1&&x4>=x1&&x4>=x5)||(x3<=x2&&x4>=x2&&x5<=x1&&x6>=x1&&x6>=x4))\n putsend('NO')\nend\n# \u3088\u3053\nif (x3<=x1&&x4>=x2 &&x5<=x1&&x6>=x2) && ((y5<=y2&&y6>=y2&&y3<=y1&&y4>=y1&&y4>=y5)||(y3<=y2&&y4>=y2&&y5<=y1&&y6>=y1&&y6>=y4))\n putsend('NO')\nend\n\nputsend('YES')\n"}], "src_uid": "05c90c1d75d76a522241af6bb6af7781"} {"nl": {"description": "++++++++[>+>++>+++>++++>+++++>++++++>+++++++>++++++++>+++++++++>++++++++++>+\n++++++++++>++++++++++++>+++++++++++++>++++++++++++++>+++++++++++++++>+++++++\n+++++++++<<<<<<<<<<<<<<<<-]>>>>>>>>>>.<<<<<<<<<<>>>>>>>>>>>>>>++.--<<<<<<<<<\n<<<<<>>>>>>>>>>>>>+.-<<<<<<<<<<<<<>>>>>>>>>>>>>>--.++<<<<<<<<<<<<<<>>>>>>>>>\n>>>>>>----.++++<<<<<<<<<<<<<<<>>>>.<<<<>>>>>>>>>>>>>>--.++<<<<<<<<<<<<<<>>>>\n>>>>>>>>>>>---.+++<<<<<<<<<<<<<<<>>>>>>>>>>>>>>---.+++<<<<<<<<<<<<<<>>>>>>>>\n>>>>++.--<<<<<<<<<<<<>>>>>>>>>>>>>---.+++<<<<<<<<<<<<<>>>>>>>>>>>>>>++.--<<<\n<<<<<<<<<<<.\n\nDCBA:^!~}|{zyxwvutsrqponmlkjihgfedcba`_^]\\[ZYXWVUTSRQPONMLKJIHdcbD`Y^]\\UZYRv\n9876543210/.-,+*)('&%$#\"!~}|{zyxwvutsrqponm+*)('&%$#cya`=^]\\[ZYXWVUTSRQPONML\nKJfe^cba`_X]VzTYRv98TSRQ3ONMLEi,+*)('&%$#\"!~}|{zyxwvutsrqponmlkjihgfedcba`_^\n]\\[ZYXWVUTSonPlkjchg`ed]#DCBA@?>=<;:9876543OHGLKDIHGFE>b%$#\"!~}|{zyxwvutsrqp\nonmlkjihgfedcba`_^]\\[ZYXWVUTSRQPONMibafedcba`_X|?>Z<XWVUTSRKo\\\n v34*8+6+,78+9*3+,93+9*5+,28+9*1+,55+9*4+,23*6*2*,91,@,+7*9*25,*48,+3*9+38,+<\n>62*9*2+,34*9*3+,66+9*8+,52*9*7+,75+9*8+,92+9*6+,48+9*3+,43*9*2+,84*,26*9*3^", "input_spec": "The input contains a single integer a (0\u2009\u2264\u2009a\u2009\u2264\u20091\u2009000\u2009000).", "output_spec": "Output a single integer.", "sample_inputs": ["129"], "sample_outputs": ["1"], "notes": null}, "positive_code": [{"source_code": "p gets.to_i.to_s(8).count'1'"}, {"source_code": "a=gets.chomp.to_i.to_s(8)\nb=a.count(\"1\")\nputs \"#{b}\""}, {"source_code": "n = gets.to_i\n\nputs n.to_s(8).count('1')\n"}, {"source_code": "a=gets.chomp.to_i.to_s(8)\nb=a.count(\"1\")\nputs \"#{b}\""}, {"source_code": "p gets.to_i.to_s(8).count'1'"}, {"source_code": "p gets.to_i.to_s(8).count'1'"}, {"source_code": "# print number of ones in BASE 8 notaion of a\np gets.to_i.to_s(8).chars.count ?1\n"}, {"source_code": "#!/usr/bin/env ruby\nputs gets.to_i.to_s(8).chars.count('1')\n"}, {"source_code": "p gets.to_i.to_s(8).count'1'\n"}], "negative_code": [{"source_code": "# print number *** BASE 8 notaion of a\np gets.to_i % 8\n"}, {"source_code": "# print number *** BASE 8 notaion of a\ns = gets.to_i.to_s 8\np s.chars.map(&:to_i).reduce(:+) / s.size\n"}, {"source_code": "#!/usr/bin/env ruby\nputs gets.to_i.to_s(8)[-1]\n"}], "src_uid": "ec539775f2b3358a92a99a644e2480ce"} {"nl": {"description": "Johny likes numbers n and k very much. Now Johny wants to find the smallest integer x greater than n, so it is divisible by the number k.", "input_spec": "The only line contains two integers n and k (1\u2009\u2264\u2009n,\u2009k\u2009\u2264\u2009109).", "output_spec": "Print the smallest integer x\u2009>\u2009n, so it is divisible by the number k.", "sample_inputs": ["5 3", "25 13", "26 13"], "sample_outputs": ["6", "26", "39"], "notes": null}, "positive_code": [{"source_code": "# cook your code here\n\na1,b1=gets.chomp.split\n\nn = a1.to_i\nk = b1.to_i\n\nn = n + k - n%k \n\nputs n"}, {"source_code": "n,k=gets.split.map(&:to_i)\np (n+k)/k*k"}, {"source_code": "n, k = gets.strip.split.map(&:to_i)\nremainder = n / k\nans = k * remainder + k\nputs ans\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\n\nx = (n/k).to_i\n\nputs (x+1)*k\n"}, {"source_code": "n,k = gets.split(' ').map(&:to_i)\nputs ((n/k) * k) + k\n"}], "negative_code": [{"source_code": "n,k=gets.split.map(&:to_i)\np (n+k-1)/k*k"}, {"source_code": "n, k = gets.strip.split.map(&:to_i)\nmod = n % k\nremainder = 0\nremainder = n / k if mod != 0\nremainder = mod if mod ==\nans = n + remainder\nans += k if remainder == 0\nputs ans\n"}, {"source_code": "n, k = gets.strip.split.map(&:to_i)\nmod = n % k\nremainder = mod\nremainder = n / k if mod != 0\nans = n + remainder\nans += k if remainder == 0\nputs ans\n"}], "src_uid": "75f3835c969c871a609b978e04476542"} {"nl": {"description": "One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one!Why not make her own Codeforces, with blackjack and other really cool stuff? Many people will surely be willing to visit this splendid shrine of high culture.In Mainframe a standard pack of 52 cards is used to play blackjack. The pack contains cards of 13 values: 2, 3, 4, 5, 6, 7, 8, 9, 10, jacks, queens, kings and aces. Each value also exists in one of four suits: hearts, diamonds, clubs and spades. Also, each card earns some value in points assigned to it: cards with value from two to ten earn from 2 to 10 points, correspondingly. An ace can either earn 1 or 11, whatever the player wishes. The picture cards (king, queen and jack) earn 10 points. The number of points a card earns does not depend on the suit. The rules of the game are very simple. The player gets two cards, if the sum of points of those cards equals n, then the player wins, otherwise the player loses.The player has already got the first card, it's the queen of spades. To evaluate chances for victory, you should determine how many ways there are to get the second card so that the sum of points exactly equals n.", "input_spec": "The only line contains n (1\u2009\u2264\u2009n\u2009\u2264\u200925) \u2014 the required sum of points.", "output_spec": "Print the numbers of ways to get the second card in the required way if the first card is the queen of spades.", "sample_inputs": ["12", "20", "10"], "sample_outputs": ["4", "15", "0"], "notes": "NoteIn the first sample only four two's of different suits can earn the required sum of points.In the second sample we can use all tens, jacks, queens and kings; overall it's 15 cards, as the queen of spades (as any other card) is only present once in the pack of cards and it's already in use.In the third sample there is no card, that would add a zero to the current ten points."}, "positive_code": [{"source_code": "n = gets.chomp.to_i - 10\nif n < 1 || n > 11\n puts 0\nelsif n == 10\n puts 15\nelse\n puts 4\nend\n"}, {"source_code": "need = STDIN.readline.to_i - 10\nif need == 10\n puts 15\nelsif need >= 1 and need <= 11\n puts 4\nelse\n puts 0\nend\n"}, {"source_code": "n = gets.to_i\nif n <= 10 or n >= 22\n puts 0\nelse\n if n== 20\n puts 15\n else\n puts 4\n end\nend"}, {"source_code": "#104A\nn=gets.to_i\nif n <= 10\n puts \"0\"\nelsif n >= 11 and n <= 19\n puts \"4\"\nelsif n == 20\n puts \"15\"\nelsif n == 21\n puts\"4\"\nelse\n puts \"0\"\nend \n"}, {"source_code": "a=gets.chomp.to_i\na=a-10\nif a<=0 || a>=12\nputs \"0\"\nelsif a==10\nputs \"15\"\nelse \nputs \"4\"\nend\n\n"}, {"source_code": "d=[10]*11\n[*1..11].each{|i| d+=[i]*4}\np d.count(gets.to_i-10)\n"}, {"source_code": "#!/usr/bin/ruby\nuc = \"1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 5 5 5 5 6 6 6 6 7 7 7 7 8 8 8 8 9 9 9 9 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 11 11 11 11\".split(' ')\nnum = gets.chop.to_i\n#puts num.to_s\nways = 0;\nfor i in 0..uc.count-1\n\tif num - 10 == uc[i].to_i\n\t\tways = ways+1\n\tend\nend\nputs ways\t\n\n"}, {"source_code": "\ndef blackjack\n c = { }\n 1.upto(11) { |i| c[i] = 4 }\n c[10] = 15\n\n goal = gets.to_i\n if goal-10 < 1\n puts 0\n else\n puts (c.has_key?(goal-10)) ? c[goal-10] : 0\n end\nend\n\nblackjack"}, {"source_code": "case gets.chomp.to_i\n when 11..19, 21\n puts 4\n when 20\n puts 15\n else\n puts 0\nend"}, {"source_code": "# Codeforces Beta Round #80\n# Problem A -- Blackjack\ncards = [0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 15, 4]\nn = gets.to_i - 10\nputs (0 <= n and n <= 11) ? cards[n] : 0\n"}, {"source_code": "n=gets.to_i\nd=n-10\np d>11||d<1 ? 0 : d>10||d<2 ? 4 : d>9 ? 15 : 4"}, {"source_code": "#!/usr/bin/env ruby\n\ndef solve n\n diff = n - 10\n if 1 < diff and diff < 10\n return 4\n end\n if diff == 1 or diff == 11\n return 4\n end\n if diff == 10\n return 4*3+3\n end\n return 0 # if diff < 0 and 11 < diff\nend\n\n#n = STDIN.gets.split.map {|i| i.to_i }\n\nputs solve(STDIN.gets.to_i)\n"}], "negative_code": [{"source_code": "d=[10]*15+[1, 11]\n[*2..9].each{|i| d+=[i]*4}\np d.count(gets.to_i-10)\n"}, {"source_code": "s=gets.to_i\nneed=s-10\n\ndata=[10]*(3*4-1)+[1, 11]\nfor i in 2..10\n\tdata+=[i]*4\nend\n\nputs data.count(need)\n"}, {"source_code": "d=[10]*15+[11]\n[*1..9].each{|i| d+=[i]*4}\np d.count(gets.to_i-10)\n"}, {"source_code": "d=[10]*15+[1,11]\n[*2..9].each{|i| d+=[i]*4}\np d.count(gets.to_i-10)\n"}, {"source_code": "#!/usr/bin/ruby\nuc = \"1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 5 5 5 5 6 6 6 6 7 7 7 7 8 8 8 8 9 9 9 9 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10\".split(' ')\nnum = gets.chop.to_i\n#puts num.to_s\nways = 0;\nfor i in 0..uc.count-1\n\tif num - 10 == uc[i].to_i\n\t\tways = ways+1\n\tend\nend\nputs ways\t\n\n"}, {"source_code": "\ndef blackjack\n c = { }\n 1.upto(11) { |i| c[i] = 4 }\n c[10] = 15\n\n goal = gets.to_i\n if goal-10 < 1\n puts 0\n else\n puts c[goal-10]\n end\nend\n\n\nblackjack"}, {"source_code": "#!/usr/bin/env ruby\n\ndef solve n\n diff = n - 10\n return 0 if diff < 0 and 10 < diff\n if 1 < diff and diff < 10\n return 4\n end\n if diff == 1\n return 4\n end\n if diff >= 10\n return 4*3+3\n end\nend\n\n#n = STDIN.gets.split.map {|i| i.to_i }\n\nputs solve(STDIN.gets.to_i)\n"}, {"source_code": "#!/usr/bin/env ruby\n\ndef solve n\n return 0 if n < 11\n diff = n - 10\n if 1 < diff and diff < 10\n return 4\n end\n if diff == 1\n return 4\n end\n if diff >= 10\n return 4*3+3\n end\nend\n\n#n = STDIN.gets.split.map {|i| i.to_i }\n\nputs solve(STDIN.gets.to_i)\n"}, {"source_code": "#!/usr/bin/env ruby\n\ndef solve n\n diff = n - 10\n return 0 if diff < 0 and 11 < diff\n if 1 < diff and diff < 10\n return 4\n end\n if diff == 1 or diff == 11\n return 4\n end\n if diff >= 10\n return 4*3+3\n end\nend\n\n#n = STDIN.gets.split.map {|i| i.to_i }\n\nputs solve(STDIN.gets.to_i)\n"}], "src_uid": "5802f52caff6015f21b80872274ab16c"} {"nl": {"description": "Galois is one of the strongest chess players of Byteforces. He has even invented a new variant of chess, which he named \u00abPawnChess\u00bb.This new game is played on a board consisting of 8 rows and 8 columns. At the beginning of every game some black and white pawns are placed on the board. The number of black pawns placed is not necessarily equal to the number of white pawns placed. Lets enumerate rows and columns with integers from 1 to 8. Rows are numbered from top to bottom, while columns are numbered from left to right. Now we denote as (r,\u2009c) the cell located at the row r and at the column c.There are always two players A and B playing the game. Player A plays with white pawns, while player B plays with black ones. The goal of player A is to put any of his pawns to the row 1, while player B tries to put any of his pawns to the row 8. As soon as any of the players completes his goal the game finishes immediately and the succeeded player is declared a winner.Player A moves first and then they alternate turns. On his move player A must choose exactly one white pawn and move it one step upward and player B (at his turn) must choose exactly one black pawn and move it one step down. Any move is possible only if the targeted cell is empty. It's guaranteed that for any scenario of the game there will always be at least one move available for any of the players.Moving upward means that the pawn located in (r,\u2009c) will go to the cell (r\u2009-\u20091,\u2009c), while moving down means the pawn located in (r,\u2009c) will go to the cell (r\u2009+\u20091,\u2009c). Again, the corresponding cell must be empty, i.e. not occupied by any other pawn of any color.Given the initial disposition of the board, determine who wins the game if both players play optimally. Note that there will always be a winner due to the restriction that for any game scenario both players will have some moves available.", "input_spec": "The input consists of the board description given in eight lines, each line contains eight characters. Character 'B' is used to denote a black pawn, and character 'W' represents a white pawn. Empty cell is marked with '.'. It's guaranteed that there will not be white pawns on the first row neither black pawns on the last row.", "output_spec": "Print 'A' if player A wins the game on the given board, and 'B' if player B will claim the victory. Again, it's guaranteed that there will always be a winner on the given board.", "sample_inputs": ["........\n........\n.B....B.\n....W...\n........\n..W.....\n........\n........", "..B.....\n..W.....\n......B.\n........\n.....W..\n......B.\n........\n........"], "sample_outputs": ["A", "B"], "notes": "NoteIn the first sample player A is able to complete his goal in 3 steps by always moving a pawn initially located at (4,\u20095). Player B needs at least 5 steps for any of his pawns to reach the row 8. Hence, player A will be the winner."}, "positive_code": [{"source_code": "Board = Array.new( 8 ) do | i |\n\tgets.chomp.split( \"\" )\nend\n.transpose.freeze;\n\na = 8; b = 8\nBoard.each do |row|\n\t8.times do | i |\n\t\tif row[i] != '.'\n\t\t\tif row[i] == 'W'\n\t\t\t\ta = [ a, i ].min\n\t\t\tend\n\t\t\tbreak\n\t\tend\n\tend\n\t7.downto( 0 ) do | i |\n\t\tif row[i] != '.'\n\t\t\tif row[i] == 'B'\n\t\t\t\tb = [ b, 7 - i ].min\n\t\t\tend\n\t\t\tbreak\n\t\tend\n\tend\nend\n\nputs ( a <= b ? \"A\" : \"B\" )\n"}, {"source_code": "matr=[]\n8.times{matr<b ? \"B\" : \"A\"\n"}, {"source_code": "# http://codeforces.com/contest/592/problem/A\n# A. PawnChess\n\ncols = [].tap do |arr|\n 8.times { arr << gets.chomp.chars }\nend\nb_idx = []\nw_idx = []\ncols.transpose.each do |row|\n b = row.rindex('B')\n w = row.rindex('W')\n b_idx << 7 - b if b && (w.nil? || (b > w))\n\n b = row.index('B')\n w = row.index('W')\n w_idx << w if w && (b.nil? || (b > w))\nend\n\nif !b_idx.empty? && (w_idx.empty? || b_idx.min < w_idx.min)\n puts 'B'\nelse\n puts 'A'\nend\n"}, {"source_code": "#! /usr/bin/env ruby\n\nboard = 8.times.collect { $stdin.gets.chomp }\n\nw = 100\nb = 100\nfor c in 0..7\n for r in 0..7\n board[r][c] == 'B' and break\n board[r][c] == 'W' and w = [w, r].min\n end\n for r in (0..7).reverse_each\n board[r][c] == 'W' and break\n board[r][c] == 'B' and b = [b, 7-r].min\n end\nend\n\nputs (w <= b ? 'A': 'B')\n\n"}, {"source_code": "#!/usr/bin/env ruby\n\nrequire 'matrix'\n\nrows = 8.times.map do gets.chars.to_a end\nMATRIX = Matrix.rows(rows)\n\ndef win_in_colA(col_no)\n (0..7).each do |row_no|\n if MATRIX[row_no, col_no] == 'W'\n return row_no\n elsif MATRIX[row_no, col_no] == 'B'\n return 9\n end\n end\n return 9\nend\n\ndef win_in_colB(col_no)\n (0..7).to_a.reverse.each do |row_no|\n if MATRIX[row_no, col_no] == 'B'\n return 7-row_no\n elsif MATRIX[row_no, col_no] == 'W'\n return 9\n end\n end\n return 9\nend\n\nsteps_for_A = (0..7).map do |col_n|\n win_in_colA(col_n)\nend\n\nsteps_for_B = (0..7).map do |col_n|\n win_in_colB(col_n)\nend\n\nwho_won = (steps_for_B.min < steps_for_A.min) ? 'B' : 'A'\nputs who_won\n"}, {"source_code": "field = []\nwhile line = gets\n field << line.chomp.split(\"\")\nend\nfield = field.transpose\nstepA = []\nstepB = []\nfield.each do |r|\n a = r.rindex(\"W\")\n b = r.rindex(\"B\")\n unless b.nil? then\n if a.nil? or (a < b) then\n stepB << 7 - b\n end\n end\n a = r.index(\"W\")\n b = r.index(\"B\")\n unless a.nil? then\n if b.nil? or (a < b) then\n stepA << a\n end\n end\nend\nif stepB.empty? or (stepA.min <= stepB.min) then\n puts \"A\"\nelsif stepA.empty? or (stepA.min > stepB.min) then\n puts \"B\"\nend"}, {"source_code": "a = Array.new(8)\nc = [0] * 8\nfor x in 0..7\n a[x] = gets\nend\nflag = 0\nfor x in 0..7\n for y in 0..7\n if a[x][y] == \"W\" and c[y] == 0\n w = x;\n flag = 1;\n break;\n end\n if a[x][y] == \"B\"\n c[y] = 1;\n end\n end\n if flag == 1\n break\n end\nend\nc = [0] * 8\nflag = 0\nfor x in 0..7\n for y in 0..7\n if a[7 - x][y] == 'B' and c[y] == 0\n b = x;\n flag = 1;\n break;\n end\n if a[7 - x][y] == 'W'\n c[y] = 1;\n end\n end\n if flag == 1\n break;\n end\nend\nif w > b\n print \"B\\n\"\nelse\n print \"A\\n\"\nend\n"}, {"source_code": "n, a1, a2, min, c = [], [], [], 99999, ''\n(0..7).each do |_|\n n << gets.chomp.split('')\nend\n(0..7).each do |i|\n arr, a1, a2 = [], [], []\n (0..7).each do |j|\n arr << n[j][i]\n end\n x = Array.new arr\n y = Array.new arr\n x.uniq!.delete('.')\n y.reverse!.uniq!.delete('.')\n a1 = x\n a2 = y\n if a1.size == 0\n \tnext\n elsif a1.size == 1\n \td = a1.first == 'W' ? arr.index('W') : arr.reverse.index('B')\n \tif (d < min) || (d == min && a1.first == 'W')\n \t\tmin = d\n \t\tc = a1.first\n \tend\n else\n\t\tif a1.first == 'W' && arr.index('W') <= min\n\t\t\tmin = arr.index('W')\n\t\t\tc = 'W'\n\t\tend\n\t\tif a2.first == 'B' && arr.reverse.index('B') < min\n\t\t\tmin = arr.reverse.index('B')\n\t\t\tc = 'B'\n\t\tend\n end\nend\nputs c == 'W' ? 'A' : 'B'"}, {"source_code": "class Solver\n\tdef main\n\t\tf = []\n\t\t8.times { f << gets }\n\t\tans_w = 10\n\t\tans_b = 10\n\t\t8.times do |i|\n\t\t\t8.times do |j|\n\t\t\t\tif f[i][j] == \"W\" then\n\t\t\t\t\tflag = true\n\t\t\t\t\ttmp = i - 1\n\t\t\t\t\twhile tmp >= 0 do\n\t\t\t\t\t\tflag = false if f[tmp][j] != '.'\n\t\t\t\t\t\ttmp -= 1\n\t\t\t\t\tend\n\t\t\t\t\tans_w = [ans_w, i].min if flag\n\t\t\t\telsif f[i][j] == \"B\" then\n\t\t\t\t\tflag = true;\n\t\t\t\t\ttmp = i + 1\n\t\t\t\t\twhile tmp < 8 do\n\t\t\t\t\t\tflag = false if f[tmp][j] != '.'\n\t\t\t\t\t\ttmp += 1\n\t\t\t\t\tend\n\t\t\t\t\tans_b = [ans_b, 7 - i].min if flag\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\t\tputs ans_w <= ans_b ? \"A\" : \"B\"\n\tend\nend\n\nSolver.new.main\n"}], "negative_code": [{"source_code": "# http://codeforces.com/contest/592/problem/A\n# A. PawnChess\n\ncols = [].tap do |arr|\n 8.times { arr << gets.chomp.chars }\nend\nrows = cols.transpose.reject do |row|\n row.include?('B') && row.include?('W')\nend\n\nb_indexes = rows.map { |row| row.rindex('B') }.compact.map { |idx| 8 - idx }\nw_indexes = rows.map { |row| row.index('W') }.compact\n\nif b_indexes.min < w_indexes.min\n puts 'B'\nelse\n puts 'A'\nend\n"}, {"source_code": "# http://codeforces.com/contest/592/problem/A\n# A. PawnChess\n\ncols = [].tap do |arr|\n 8.times { arr << gets.chomp.chars }\nend\nrows = cols.transpose.reject do |row|\n row.include?('B') && row.include?('W')\nend\n\nb_indexes = rows.map { |row| row.rindex('B') }.compact.map { |idx| 7 - idx }\nw_indexes = rows.map { |row| row.index('W') }.compact\n\n\nif w_indexes.empty? || b_indexes.min < w_indexes.min\n puts 'B'\nelse\n puts 'A'\nend\n"}, {"source_code": "# http://codeforces.com/contest/592/problem/A\n# A. PawnChess\n\ncols = [].tap do |arr|\n 8.times { arr << gets.chomp.chars }\nend\nb_idx = []\nw_idx = []\nrows = cols.transpose.reject do |row|\n b = row.rindex('B')\n w = row.rindex('W')\n if b && (w.nil? || (b > w))\n b_idx << 7 - b\n end\n\n b = row.index('B')\n w = row.index('W')\n if w && (b.nil? || (w > b))\n w_idx << w\n end\nend\n\nif !b_idx.empty? && (w_idx.empty? || b_idx.min < w_idx.min)\n puts 'B'\nelse\n puts 'A'\nend\n"}, {"source_code": "#!/usr/bin/env ruby\n\nrequire 'matrix'\n\nrows = 8.times.map do gets.chars.to_a end\nMATRIX = Matrix.rows(rows)\n\ndef win_in_colA(col_no)\n (0..7).each do |row_no|\n if MATRIX[row_no, col_no] == 'W'\n return row_no\n elsif MATRIX[row_no, col_no] == 'B'\n return 9\n end\n end\n return 9\nend\n\ndef win_in_colB(col_no)\n (0..7).to_a.reverse.each do |row_no|\n if MATRIX[row_no, col_no] == 'B'\n return 7-row_no\n elsif MATRIX[row_no, col_no] == 'W'\n return 9\n end\n end\n return 9\nend\n\nsteps_for_A = (0..7).map do |col_n|\n win_in_colA(col_n)\nend\nprint steps_for_A\nputs\n\nsteps_for_B = (0..7).map do |col_n|\n win_in_colB(col_n)\nend\nprint steps_for_B\n\nwho_won = (steps_for_B.min < steps_for_A.min) ? 'B' : 'A'\nputs who_won\n"}, {"source_code": "#!/usr/bin/env ruby\n\nrequire 'matrix'\n\nrows = 8.times.map do gets.chars.to_a end\nMATRIX = Matrix.rows(rows)\n\ndef win_in_colB(col_no)\n (0..7).each do |row_no|\n if MATRIX[row_no, col_no] == 'B'\n return row_no+1\n elsif MATRIX[row_no, col_no] == 'W'\n return 9\n end\n end\n return 9\nend\n\ndef win_in_colA(col_no)\n (0..7).to_a.reverse.each do |row_no|\n if MATRIX[row_no, col_no] == 'W'\n return 8-row_no\n elsif MATRIX[row_no, col_no] == 'B'\n return 9\n end\n end\n return 9\nend\n\nsteps_for_A = (0..7).map do |col_n|\n win_in_colA(col_n)\nend\n\nsteps_for_B = (0..7).map do |col_n|\n win_in_colB(col_n)\nend\n\nwho_won = (steps_for_B.min < steps_for_A.min) ? 'B' : 'A'\nputs who_won\n"}, {"source_code": "field = []\nwhile line = gets\n field << line.chomp.split(\"\")\nend\nfield = field.transpose\nstepA = []\nstepB = []\nfield.each do |r|\n a = r.rindex(\"W\")\n b = r.rindex(\"B\")\n unless b.nil? then\n if a.nil? or (a < b) then\n stepB << 7 - b\n end\n end\n a = r.index(\"W\")\n b = r.index(\"B\")\n unless a.nil? then\n if b.nil? or (a < b) then\n stepA << 7 - a\n end\n end\nend\nif stepB.empty? or (stepA.min < stepB.min) then\n puts \"A\"\nelsif stepA.empty? or (stepA.min > stepB.min) then\n puts \"B\"\nend"}, {"source_code": "a = Array.new(8)\nfor x in 0..7\n a[x] = gets\nend\nfor x in 0..7\n for y in 0..7\n if a[7 - x][y] == 'B'\n print \"B\\n\"\n exit\n end\n if a[7 - x][y] == 'W'\n print \"A\\n\"\n exit\n end\n end\nend\n"}, {"source_code": "n, a1, a2, min, c = [], [], [], 99999, ''\n(0..7).each do |_|\n n << gets.chomp.split('')\nend\n(0..7).each do |i|\n arr, a1, a2 = [], [], []\n (0..7).each do |j|\n arr << n[j][i]\n end\n x = Array.new arr\n y = Array.new arr\n x.uniq!.delete('.')\n y.reverse!.uniq!.delete('.')\n a1 = x\n a2 = y\n if a1.size == 0\n \tnext\n elsif a1.size == 1\n \td = a1.first == 'W' ? arr.index('W') : arr.reverse.index('B')\n \tif d < min || (d == min && c == 'W')\n \t\tmin = d\n \t\tc = a1.first\n \tend\n else\n\t\tif a1.first == 'W' && arr.index('W') <= min\n\t\t\tmin = arr.index('W')\n\t\t\tc = 'W'\n\t\tend\n\t\tif a2.first == 'B' && arr.reverse.index('B') < min\n\t\t\tmin = arr.reverse.index('B')\n\t\t\tc = 'B'\n\t\tend\n end\nend\nputs c == 'W' ? 'A' : 'B'"}, {"source_code": "arr, arr1, arr2, index, min, result, c = [], [], [], 1000000, 99999, '', ''\n(0..7).each do |_|\n arr << gets.chomp.split('')\nend\n(0..7).each do |i|\n arr1 = []\n (0..7).each do |j|\n arr1 << arr[j][i]\n end\n arr2 = Array.new arr1\n arr2.uniq!.delete('.')\n if arr2[0] && arr2.size == 1\n c = arr2[0]\n if c == 'W'\n index = arr1.index(c)\n else c == 'B'\n index = arr1.reverse.index(c)\n end\n end\n if index < min\n min = index\n result = c\n end\nend\nputs result == 'W' ? 'A' : 'B'"}, {"source_code": "arr, arr1, arr2, index, min, result, c = [], [], [], 1000000, 99999, '', ''\n(0..7).each do |_|\n arr << gets.chomp.split('')\nend\n(0..7).each do |i|\n arr1 = []\n (0..7).each do |j|\n arr1 << arr[j][i]\n end\n arr2 = Array.new arr1\n arr2.uniq!.delete('.')\n if arr2[0] && arr2.size == 1\n c = arr2[0]\n if c == 'W'\n index = arr1.index(c)\n else c == 'B'\n index = arr1.reverse.index(c)\n end\n end\n min = index; result = c if index < min\nend\np result == 'W' ? 'A' : 'B'"}, {"source_code": "arr, arr1, arr2, index, min, result, c = [], [], [], 1000000, 99999, '', ''\n(0..7).each do |_|\n arr << gets.chomp.split('')\nend\n(0..7).each do |i|\n arr1 = []\n (0..7).each do |j|\n arr1 << arr[j][i]\n end\n arr2 = Array.new arr1\n arr2.uniq!.delete('.')\n if arr2[0] && arr2.size == 1\n c = arr2[0]\n if c == 'W'\n index = arr1.index(c)\n else c == 'B'\n index = arr1.reverse.index(c)\n end\n end\n if index < min\n min = index\n result = c\n end\nend\np result == 'W' ? 'A' : 'B'\n"}, {"source_code": "arr, arr1, arr2, index, min, result, c = [], [], [], 1000000, 99999, '', ''\n(0..7).each do |_|\n arr << gets.chomp.split('')\nend\n(0..7).each do |i|\n arr1 = []\n (0..7).each do |j|\n arr1 << arr[j][i]\n end\n arr2 = Array.new arr1\n arr2.uniq!.delete('.')\n if arr2[0] && arr2.size == 1\n c = arr2[0]\n if c == 'W'\n index = arr1.index(c)\n else c == 'B'\n index = arr1.reverse.index(c)\n end\n end\n if index < min\n min = index\n result = c\n end\nend\np result == 'W' ? :A : :B\n"}, {"source_code": "class Solver\n\tdef main\n\t\tmap = []\n\t\t8.times do\n\t\t\tmap << gets.chomp\n\t\tend\n\t\tmove_a = 9\n\t\tmove_b = 9\n\t\t\n\t\t8.times do |i|\n\t\t\tup_most_w = 10\n\t\t\tdown_most_b = -1\n\t\t\t8.times do |j|\n\t\t\t\tup_most_w = [up_most_w, j].min if map[j][i] == \"W\"\n\t\t\t\tdown_most_b = [down_most_b, j].max if map[j][i] == \"B\"\n\t\t\tend\n\t\t\tif up_most_w == 10 && down_most_b != -1 then\n\t\t\t\tmove_b = [move_b, 7 - down_most_b].min\n\t\t\telsif up_most_w != 10 && down_most_b == -1 then\n\t\t\t\tmove_a = [move_a, up_most_w].min\n\t\t\telsif up_most_w != 10 && down_most_b != -1 then\n\t\t\t\tif up_most_w < down_most_b then\n\t\t\t\t\tmove_a = [move_a, up_most_w].min\n\t\t\t\t\tmove_b = [move_b, 7 - down_most_b].min\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\n\t\tif move_a <= move_b then\n\t\t\tputs \"A\"\n\t\telse\n\t\t\tputs \"B\"\n\t\tend\n\tend\nend\n\nSolver.new.main\n"}], "src_uid": "0ddc839e17dee20e1a954c1289de7fbd"} {"nl": {"description": "Nastya received a gift on New Year\u00a0\u2014 a magic wardrobe. It is magic because in the end of each month the number of dresses in it doubles (i.e. the number of dresses becomes twice as large as it is in the beginning of the month).Unfortunately, right after the doubling the wardrobe eats one of the dresses (if any) with the 50% probability. It happens every month except the last one in the year. Nastya owns x dresses now, so she became interested in the expected number of dresses she will have in one year. Nastya lives in Byteland, so the year lasts for k\u2009+\u20091 months.Nastya is really busy, so she wants you to solve this problem. You are the programmer, after all. Also, you should find the answer modulo 109\u2009+\u20097, because it is easy to see that it is always integer.", "input_spec": "The only line contains two integers x and k (0\u2009\u2264\u2009x,\u2009k\u2009\u2264\u20091018), where x is the initial number of dresses and k\u2009+\u20091 is the number of months in a year in Byteland.", "output_spec": "In the only line print a single integer\u00a0\u2014 the expected number of dresses Nastya will own one year later modulo 109\u2009+\u20097.", "sample_inputs": ["2 0", "2 1", "3 2"], "sample_outputs": ["4", "7", "21"], "notes": "NoteIn the first example a year consists on only one month, so the wardrobe does not eat dresses at all.In the second example after the first month there are 3 dresses with 50% probability and 4 dresses with 50% probability. Thus, in the end of the year there are 6 dresses with 50% probability and 8 dresses with 50% probability. This way the answer for this test is (6\u2009+\u20098)\u2009/\u20092\u2009=\u20097."}, "positive_code": [{"source_code": "def power_mod(num, power)\n prod = 1\n num %= MOD\n while power > 0 do\n if power & 1 == 1\n prod = (prod * num) % MOD\n end\n num = (num * num) % MOD\n power >>= 1\n end\n return prod\nend\n\nMOD = 10**9+7\n\nX, K = gets.split.map(&:to_i)\nif X == 0\n puts 0\n exit\nend\n\nlow = (X-1) * power_mod(2, K) + 1\nhigh = X * power_mod(2, K)\nputs (low + high) % MOD"}], "negative_code": [], "src_uid": "e0e017e8c8872fc1957242ace739464d"} {"nl": {"description": "Iahub is training for the IOI. What is a better way to train than playing a Zuma-like game? There are n balls put in a row. Each ball is colored in one of k colors. Initially the row doesn't contain three or more contiguous balls with the same color. Iahub has a single ball of color x. He can insert his ball at any position in the row (probably, between two other balls). If at any moment there are three or more contiguous balls of the same color in the row, they are destroyed immediately. This rule is applied multiple times, until there are no more sets of 3 or more contiguous balls of the same color. For example, if Iahub has the row of balls [black, black, white, white, black, black] and a white ball, he can insert the ball between two white balls. Thus three white balls are destroyed, and then four black balls become contiguous, so all four balls are destroyed. The row will not contain any ball in the end, so Iahub can destroy all 6 balls.Iahub wants to destroy as many balls as possible. You are given the description of the row of balls, and the color of Iahub's ball. Help Iahub train for the IOI by telling him the maximum number of balls from the row he can destroy.", "input_spec": "The first line of input contains three integers: n (1\u2009\u2264\u2009n\u2009\u2264\u2009100), k (1\u2009\u2264\u2009k\u2009\u2264\u2009100) and x (1\u2009\u2264\u2009x\u2009\u2264\u2009k). The next line contains n space-separated integers c1,\u2009c2,\u2009...,\u2009cn (1\u2009\u2264\u2009ci\u2009\u2264\u2009k). Number ci means that the i-th ball in the row has color ci. It is guaranteed that the initial row of balls will never contain three or more contiguous balls of the same color. ", "output_spec": "Print a single integer \u2014 the maximum number of balls Iahub can destroy.", "sample_inputs": ["6 2 2\n1 1 2 2 1 1", "1 1 1\n1"], "sample_outputs": ["6", "0"], "notes": null}, "positive_code": [{"source_code": "n, k, x = $stdin.gets.chomp.split(' ').map { |v| v.to_i }\na = $stdin.gets.chomp.split(' ').map { |v| v.to_i }\n\nclass Solver\n def initialize(n, k, x, a)\n @n = n\n @k = k\n @x = x\n @a = a\n end\n\n def cnt(l, r)\n ans = 0\n flag = false\n while true do\n sum = 0\n while l>-1 && @a[l] == @a[r]\n l -= 1\n sum += 1\n end\n l += 1\n while r < @n && @a[l] == @a[r]\n r += 1\n sum += 1\n end\n r -= 1\n return ans if flag && sum < 3\n flag = 1\n ans = [ans, r - l + 1].max\n l -= 1\n r += 1\n return ans if l <0 || r >= @n || @a[l] != @a[r]\n end\n end\nend\n\nsolver = Solver.new(n, k, x, a)\nans = 0\nfor i in 0..n-1\n ans = [ans, solver.cnt(i, i+1)].max if a[i] == a[i+1] && a[i] == x\nend\n\nputs ans\n"}, {"source_code": "# Created by Alex\nn, k, x = gets.split.map {|i| i.to_i}\na = gets.split.map {|i| i.to_i}\nmax = 0\nmaxi = -1\nfor i in 0...n - 1\n #print a[i].to_s + ' '\n if a[i] != x || a[i + 1] != x\n next\n end\n l = i - 1\n r = i + 2\n cnt = 3\n while l >= 0 && r < n && a[l] == a[r]\n p1 = l\n while p1 > 0 && a[p1 - 1] == a[r]\n p1 -= 1\n end\n p2 = r\n while p2 < n - 1 && a[p2 + 1] == a[l]\n p2 += 1\n end\n if l - p1 + p2 - r + 2 < 3\n break\n end\n cnt += l - p1 + p2 - r + 2\n l = p1 - 1\n r = p2 + 1\n end\n if cnt >= max\n #print ' (' + cnt.to_s + ' ' + p1.to_s + ' ' + p2.to_s + ') '\n max = cnt\n maxi = i\n end\nend\nif max < 3\n max = 1\nend\nputs max - 1"}], "negative_code": [{"source_code": "myArray = $stdin.readlines\n\ninput=[]\n\nmyArray.each do |l|\n input.push(l)\nend\n\na = input[0].split(',').map{|x| x.to_i}\n\n#insert your code within this function\ndef solution(a)\n a2 = a.sort\n n = a2.size\n index_swap = 0\n for i in 0..n-1\n index_swap +=1 if a[i] != a2[i]\n end\n return index_swap <= 2\nend\n\nputs solution(a)\n"}, {"source_code": "# Created by Alex\nn, k, x = gets.split.map {|i| i.to_i}\na = gets.split.map {|i| i.to_i}\nmax = 0\nfor i in 0...n - 1\n if a[i] != x || a[i + 1] != x\n next\n end\n l = i - 1\n r = i + 2\n cnt = 3\n while l >= 0 && r < n\n p1 = l\n while p1 > 0 && a[p1 - 1] == a[r]\n p1 -= 1\n end\n p2 = r\n while p2 < n - 1 && a[p2 + 1] == a[l]\n p2 += 1\n end\n if l - p1 + p2 - r + 2 < 3\n break\n end\n cnt += l - p1 + p2 - r + 2\n l = p1 - 1\n r = p2 + 1\n end\n if cnt > max\n max = cnt\n end\nend\nif max < 3\n max = 1\nend\nputs max - 1"}, {"source_code": "# Created by Alex\nn, k, x = gets.split.map {|i| i.to_i}\na = gets.split.map {|i| i.to_i}\nmax = 0\nfor i in 0...n - 2\n if a[i + 1] != x || a[i + 2] != x\n next\n end\n l = i - 1\n r = i + 2\n cnt = 3\n while l >= 0 && r < n\n p1 = l\n while p1 > 0 && a[p1 - 1] == a[r]\n p1 -= 1\n end\n p2 = r\n while p2 < n - 1 && a[p2 + 1] == a[l]\n p2 += 1\n end\n if l - p1 + p2 - r + 2 < 3\n break\n end\n cnt += l - p1 + p2 - r + 2\n l = p1 - 1\n r = p2 + 1\n end\n if cnt > max\n max = cnt\n end\nend\nif max < 3\n max = 1\nend\nputs max - 1"}, {"source_code": "# Created by Alex\nn, k, x = gets.split.map {|i| i.to_i}\na = gets.split.map {|i| i.to_i}\nmax = 0\nfor i in 0...n - 1\n if a[i] != x && a[i + 1] != x\n next\n end\n l = i\n r = i\n if a[i] == x && a[i + 1] == x\n l = i - 1\n r = i + 2\n end\n if a[i] == x && i > 0 && a[i - 1] == x\n l = i - 2\n r = i + 1\n end\n if a[i + 1] == x && i + 2 < n && a[i + 2] == x\n l = i\n r = i + 3\n end\n if l == i && r == i\n next\n end\n cnt = 3\n while l >= 0 && r < n\n p1 = l\n while p1 > 0 && a[p1 - 1] == a[r]\n p1 -= 1\n end\n p2 = r\n while p2 < n - 1 && a[p2 + 1] == a[l]\n p2 += 1\n end\n if l - p1 + p2 - r + 2 < 3\n break\n end\n cnt += l - p1 + p2 - r + 2\n l = p1 - 1\n r = p2 + 1\n end\n if cnt > max\n max = cnt\n end\nend\nif max < 3\n max = 1\nend\nputs max - 1"}], "src_uid": "d73d9610e3800817a3109314b1e6f88c"} {"nl": {"description": "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.", "input_spec": "The first line contains a single integer n (0\u2009\u2264\u2009n\u2009\u2264\u20091018) \u2014 the number of full years when the plant grew. Please do not use the %lld specifier to read or write 64-bit integers in \u0421++. It is preferred to use cin, cout streams or the %I64d specifier.", "output_spec": "Print a single integer \u2014 the remainder of dividing the number of plants that will point \"upwards\" in n years by 1000000007 (109\u2009+\u20097).", "sample_inputs": ["1", "2"], "sample_outputs": ["3", "10"], "notes": "NoteThe first test sample corresponds to the second triangle on the figure in the statement. The second test sample corresponds to the third one."}, "positive_code": [{"source_code": "LIMIT = 1000000007\n\n@res = []\nl = 1\nwhile l < LIMIT\n @res << l\n l = l * 2\nend\n\ndef power i\n return @res[i] if i < @res.size\n half_power = power(i/2)\n partial = (half_power * half_power) % LIMIT \n if i % 2 == 1\n partial = (partial * 2) % LIMIT\n end\n partial\nend\n\nyears = gets.to_i\n\nif years == 0\n puts 1\nelse\n partial = power(years-1)\n puts (partial * (((2 * partial) % LIMIT) + 1)) % LIMIT\nend\n\n# 2^(n-1) * (2^n +1)\n"}, {"source_code": "x = Integer gets.to_s\nif x == 0 then\n\tputs 1\n\texit\nend\nd = 1000000\nif x < d then\n\tx = 2**(x-1) * (1+2**x) % 1000000007\n\tputs x\n\texit\nend\n\nx -= 1\np = 1\nwhile x >= d\n\te = d\n\tq = 2**d % 1000000007\nwhile x >= e do\n\tp *= q\n\tp = p % 1000000007\n\tx -= e\n\te *= 10\n\tq = q**10 % 1000000007\n\nend\nend\n\np *= 2**x\np = p % 1000000007\n\np = (p * ( 1 + 2*p)) % 1000000007\n\nputs p\n"}, {"source_code": "\n\n\n$p = 1000000007\ndef mul(a,b)\n n = a.size\n c = Array.new(n){Array.new(n){0}}\n n.times do |i|\n n.times do|j|\n n.times do |k|\n c[i][j] += a[i][k] * b[k][j]\n c[i][j] %= $p\n end\n end\n end\n c\nend\n\ndef po(m)\n e = [[3,1],[1,3]]\n ret = [[1,0],[0,1]]\n \n while m > 0\n if m % 2 == 1\n ret = mul(ret,e)\n end\n e = mul(e,e)\n m /= 2\n end\n \n ret\nend\n\n\ndef work(n)\n if n == 1\n puts 3\n else\n ret = po(n)\n ans = ret[0][0]\n puts ans % $p\n end\nend\n\nn = gets.to_i\nwork n\n\n"}, {"source_code": "def pow(a,k)\n n = 1000000007\n b = 1\n while (k!= 0) do\n if (k % 2 == 0 ) then\n k/=2\n a = (a*a) % n\n else\n k-=1\n b = (b*a) % n\n end\n end\n return b\nend\n\n\nn = gets.to_i\nk = pow(2,n)\nk = (k*(k-1)/2) % 1000000007\nif (n == 0) then\n puts \"1\"\nelse\n ans = (pow(4,n) - k) % 1000000007\n puts ans\nend\n"}, {"source_code": "$p = 1000000007\ndef mul(a,b)\n n = a.size\n c = Array.new(n){Array.new(n){0}}\n n.times do |i|\n n.times do|j|\n n.times do |k|\n c[i][j] += a[i][k] * b[k][j]\n c[i][j] %= $p\n end\n end\n end\n c\nend\n\ndef po(m)\n e = [[3,1],[1,3]]\n ret = [[1,0],[0,1]]\n \n while m > 0\n if m % 2 == 1\n ret = mul(ret,e)\n end\n e = mul(e,e)\n m /= 2\n end\n \n ret\nend\n\n\ndef work(n)\n if n == 1\n puts 3\n else\n ret = po(n)\n ans = ret[0][0]\n puts ans % $p\n end\nend\n\nn = gets.to_i\nwork n\n#10.times{|x| work x+1}\n\n "}, {"source_code": "$p = 1000000007\ndef mul(a,b)\n n = a.size\n c = Array.new(n){Array.new(n){0}}\n n.times do |i|\n n.times do|j|\n n.times do |k|\n c[i][j] += a[i][k] * b[k][j]\n c[i][j] %= $p\n end\n end\n end\n c\nend\n\ndef po(m)\n e = [[3,1],[1,3]]\n ret = [[1,0],[0,1]]\n \n while m > 0\n if m % 2 == 1\n ret = mul(ret,e)\n end\n e = mul(e,e)\n m /= 2\n end\n \n ret\nend\n\n\ndef work(n)\n if n == 1\n puts 3\n else\n ret = po(n)\n ans = ret[0][0]\n puts ans % $p\n end\nend\n\nn = gets.to_i\nwork n"}], "negative_code": [{"source_code": "x = Integer gets.to_s\n\nd = 1000000\nif x < d then\n\tx = 2**(x-1) * (1+2**x)\n\tputs x\n\texit\nend\n\nx -= 1\np = 1\nq = 2**d % 1000000007\nwhile x >= d\n\te = d\nwhile x >= e do\n\tp *= q\n\tp = p % 1000000007\n\tx -= e\n\te *= 10\nend\nend\n\np *= 2**x\np = p % 1000000007\n\np = (p * ( 1 + 2*p)) % 1000000007\n\nputs p\n"}, {"source_code": "def pow(a,k)\n n = 1000000007\n b = 1\n while (k!= 0) do\n if (k % 2 == 0 ) then\n k/=2\n a = (a*a) % n\n else\n k-=1\n b = (b*a) % n\n end\n end\n return b\nend\n\n\nn = gets.to_i\nif (n == 0) then\n puts \"1\"\nelse\n ans = pow(4,n)/2 + pow(2,n-1)\n puts ans\nend\n"}, {"source_code": "n = gets.to_i\nif (n == 0) then\n puts \"1\"\nelse\n puts((4**n/2 + 2**(n-1) ) % 1000000007)\nend"}, {"source_code": "\ndef pow(a,k)\n n = 1000000007\n b = 1\n while (k!= 0) do\n if (k % 2 == 0 ) then\n k/=2\n a = (a*a) % n\n else\n k-=1\n b = (b*a) % n\n end\n end\n return b\nend\n\n\nn = gets.to_i\nif (n == 0) then\n puts \"1\"\nelse\n ans = (pow(4,n)/2 + pow(2,n-1)) % 1000000007\n puts ans\nend\n"}, {"source_code": "n = gets.to_i\nputs (4**n/2 + 2**(n-1) ) % 1000000007"}], "src_uid": "782b819eb0bfc86d6f96f15ac09d5085"} {"nl": {"description": "Ari the monster always wakes up very early with the first ray of the sun and the first thing she does is feeding her squirrel.Ari draws a regular convex polygon on the floor and numbers it's vertices 1,\u20092,\u2009...,\u2009n in clockwise order. Then starting from the vertex 1 she draws a ray in the direction of each other vertex. The ray stops when it reaches a vertex or intersects with another ray drawn before. Ari repeats this process for vertex 2,\u20093,\u2009...,\u2009n (in this particular order). And then she puts a walnut in each region inside the polygon. Ada the squirrel wants to collect all the walnuts, but she is not allowed to step on the lines drawn by Ari. That means Ada have to perform a small jump if she wants to go from one region to another. Ada can jump from one region P to another region Q if and only if P and Q share a side or a corner.Assuming that Ada starts from outside of the picture, what is the minimum number of jumps she has to perform in order to collect all the walnuts?", "input_spec": "The first and only line of the input contains a single integer n (3\u2009\u2264\u2009n\u2009\u2264\u200954321) - the number of vertices of the regular polygon drawn by Ari.", "output_spec": "Print the minimum number of jumps Ada should make to collect all the walnuts. Note, that she doesn't need to leave the polygon after.", "sample_inputs": ["5", "3"], "sample_outputs": ["9", "1"], "notes": "NoteOne of the possible solutions for the first sample is shown on the picture above."}, "positive_code": [{"source_code": "puts (gets.to_i - 2) ** 2\n"}, {"source_code": "#! /usr/bin/env ruby\n\nn = $stdin.gets.to_i\nputs (n-2)**2\n"}, {"source_code": "n=gets.chomp.to_i\nn=(n-1)*(n-3)+1\nputs n.inspect"}, {"source_code": "#!/usr/bin/env ruby\n\nN = gets.to_i\n\ndef total_sections\n return 1 if N == 3\n return 4 if N == 4\n\n sections_without_2_triangles = (3..N-2).map do |second_vertice|\n third_vertice = second_vertice + 1\n\n lines_from_second = N - second_vertice - 1\n lines_from_third = third_vertice - 3\n\n lines_from_second + lines_from_third + 1\n end.inject(:+)\n\n sections_without_2_triangles + (N-2)*2\nend\n\nputs total_sections\n"}, {"source_code": "angles = gets.to_i\nputs (angles - 2) * (angles - 2)"}, {"source_code": "puts (gets.strip.to_i - 2) ** 2\n"}, {"source_code": "n = gets.chomp.to_i\nputs n ** 2 - 4 * n + 4\n"}, {"source_code": "class Solver\n\tdef main\n\t\tn = gets.to_i\n\t\tputs (n - 2) ** 2\n\tend\nend\n\nSolver.new.main\n"}, {"source_code": "n = gets.to_i\nputs n * (n - 3) - (n - 4)\n"}, {"source_code": "puts (gets.to_i - 2) ** 2\n"}, {"source_code": "n = gets.chomp.to_i\nif n == 3 then\n puts 1\nelse\n a1 = 1\n 4.upto(n).each do |a|\n a1 += 3 + 2*(a-4)\n end\n puts a1\nend\n"}, {"source_code": "n = gets.chomp.to_i\np (n-2)**2"}, {"source_code": "class Solver\n\tdef main\n\t\tn = gets.to_i\n\t\tputs (n - 2) ** 2\n\tend\nend\n\nSolver.new.main\n"}], "negative_code": [], "src_uid": "efa8e7901a3084d34cfb1a6b18067f2b"} {"nl": {"description": "You might have heard about the next game in Lara Croft series coming out this year. You also might have watched its trailer. Though you definitely missed the main idea about its plot, so let me lift the veil of secrecy.Lara is going to explore yet another dangerous dungeon. Game designers decided to use good old 2D environment. The dungeon can be represented as a rectangle matrix of n rows and m columns. Cell (x,\u2009y) is the cell in the x-th row in the y-th column. Lara can move between the neighbouring by side cells in all four directions.Moreover, she has even chosen the path for herself to avoid all the traps. She enters the dungeon in cell (1,\u20091), that is top left corner of the matrix. Then she goes down all the way to cell (n,\u20091) \u2014 the bottom left corner. Then she starts moving in the snake fashion \u2014 all the way to the right, one cell up, then to the left to the cell in 2-nd column, one cell up. She moves until she runs out of non-visited cells. n and m given are such that she always end up in cell (1,\u20092).Lara has already moved to a neighbouring cell k times. Can you determine her current position?", "input_spec": "The only line contains three integers n, m and k (2\u2009\u2264\u2009n,\u2009m\u2009\u2264\u2009109, n is always even, 0\u2009\u2264\u2009k\u2009<\u2009n\u00b7m). Note that k doesn't fit into 32-bit integer type!", "output_spec": "Print the cell (the row and the column where the cell is situated) where Lara ends up after she moves k times.", "sample_inputs": ["4 3 0", "4 3 11", "4 3 7"], "sample_outputs": ["1 1", "1 2", "3 2"], "notes": "NoteHere is her path on matrix 4 by 3: "}, "positive_code": [{"source_code": "mas = gets.split(\" \")\nn, m, k = mas[0].to_i, mas[1].to_i, mas[2].to_i\nper, ch = k-n-m+2, 2*(m-1)\nif k < (n+m-1)\n\tfinvar = k < n ? [k+1, 1] : [n, k-n+2]\nelse\n\tis = per % (m-1) == 0 ? (n-per/(m-1)) : (n-per/(m-1)-1)\n\tprom = per % ch == 0 ? ch : (per % ch)\n\tfinvar = prom <= (m-1) ? [is, m-prom+1] : [is, 1+prom-(m-1)]\nend\nputs finvar[0], finvar[1]"}, {"source_code": "mas = gets.split(\" \")\nn, m, k = mas[0].to_i, mas[1].to_i, mas[2].to_i\nper, ch = k-n-m+2, 2*(m-1)\nif k < (n+m-1)\n\tfinvar = k < n ? [k+1, 1] : [n, k-n+2]\nelse\n\tis = per % (m-1) == 0 ? (n-per/(m-1)) : (n-per/(m-1)-1)\n\tprom = per % ch\n\tif prom == 0\n\t\tprom = ch\n\tend\n\tfinvar = prom <= (m-1) ? [is, m-prom+1] : [is, 1+prom-(m-1)]\nend\nputs finvar[0], finvar[1]"}, {"source_code": "mas = gets.split(\" \")\nn, m, k = mas[0].to_i, mas[1].to_i, mas[2].to_i\nper, ch = k-n-m+2, 2*(m-1)\nif k < (n+m-1)\n\tfinvar = k < n ? [k+1, 1] : [n, k-n+2]\nelse\n\tif per % (m-1) == 0\n\t\tis = n - per/(m-1)\n\telse\n\t\tis = n - per/(m-1) - 1\n\tend\n\tprom = per % ch\n\tif prom == 0\n\t\tprom = ch\n\tend\n\tfinvar = prom <= (m-1) ? [is, m-prom+1] : [is, 1+prom-(m-1)]\nend\nputs finvar[0], finvar[1]"}, {"source_code": "n, m, k = gets.split.map(&:to_i)\nif k < n\n puts \"#{k + 1} 1\"\nelse\n hoge = (m - 1) * 2\n k -= n\n r = n - k / hoge * 2\n tmp = k % hoge\n c = 0\n if tmp < m - 1\n c = tmp + 2\n else\n c = 2 * (m - 1) - tmp + 1\n r -= 1\n end\n puts \"#{r} #{c}\"\nend"}, {"source_code": "n, m , k=gets.split.map(&:to_i)\n\nif k<=n-1\n puts \"#{k+1} 1\"\n exit 0\nend\n\nk-=(n-1)\na=(k-1)/((m-1)*2)\nx=n-a*2\nb=((k-1)% ((m-1)*2))+1\nx-=1 if b>m-1\nif b<=m-1\n puts \"#{x} #{1+b}\"\nelse\n puts \"#{x} #{m-(b-(m-1)-1)}\"\nend\n\n"}], "negative_code": [{"source_code": "mas = gets.split(\" \")\nn, m, k = mas[0].to_i, mas[1].to_i, mas[2].to_i\nif k < (n+m - 1)\n\tfinvar = k < n ? [k+1, 1] : [n, k-n+2]\nelse\n\tis = n - (Float(k-(n+m-2))/(m-1)).ceil\n\tncheck = n % 2\n\tischeck = is % 2\n\tif (ncheck ^ ischeck) == 0\n\t\tfinvar = [is, 2 + ((k - (n+m-2)) % (m))]\n\telse\t\n\t\tif (per = ((k - (n+m-2)) % (m-1))) == 0\n\t\t\tfinvar = [is, 2]\n\t\telse\n\t\t\tfinvar = [is, m + 1 - per]\n\t\tend\n\tend\nend\nputs finvar[0], finvar[1]"}, {"source_code": "mas = gets.split(\" \")\nn, m, k = mas[0].to_i, mas[1].to_i, mas[2].to_i\nif k < (n+m - 1)\n\tfinvar = k < n ? [k+1, 1] : [n, k-n+2]\nelse\n\tis = n - (Float(k-(n+m-2))/(m-1)).ceil\n\tfinvar = [is, 2 + ((k - (n+m-2)) % (m-1))]\nend\nputs finvar[0], finvar[1]"}, {"source_code": "mas = gets.split(\" \")\nn, m, k = mas[0].to_i, mas[1].to_i, mas[2].to_i\nif k < (n+m - 1)\n\tfinvar = k < n ? [k+1, 1] : [n, k-n+2]\nelse\n\tis = n - (Float(k-(n+m-2))/(m-1)).ceil\n\tprom = (k-n-m+2) % (2*(m-1))\n\tif prom == 0\n\t\tprom = 2*(m-1)\n\tend\n\tfinvar = prom <= (m-1) ? [is, m-prom+1] : [is, 1+prom-(m-1)]\nend\nputs finvar[0], finvar[1]"}, {"source_code": "mas = gets.split(\" \")\nn, m, k = mas[0].to_i, mas[1].to_i, mas[2].to_i\nper, ch = k-n-m+2, 2*(m-1)\nif k < (n+m-1)\n\tfinvar = k < n ? [k+1, 1] : [n, k-n+2]\nelse\n\tif per % (m-1) == 0\n\t\tis = n - per/(m-1)\n\telse\n\t\tis = n - (Float(per)/(m-1)).floor - 1\n\tend\n\tprom = per % ch\n\tif prom == 0\n\t\tprom = ch\n\tend\n\tfinvar = prom <= (m-1) ? [is, m-prom+1] : [is, 1+prom-(m-1)]\nend\nputs finvar[0], finvar[1]"}, {"source_code": "mas = gets.split(\" \")\nn, m, k = mas[0].to_i, mas[1].to_i, mas[2].to_i\nif k < (n+m - 1)\n\tfinvar = k < n ? [k+1, 1] : [n, k-n+2]\nelse\n\tis = n - (Float(k-(n+m-2))/(m-1)).ceil\n\tncheck = n % 2\n\tischeck = is % 2\n\tif (ncheck ^ ischeck) == 0\n\t\tfinvar = [is, 2 + ((k - (n+m-2)) % (m-1))]\n\telse\t\n\t\tif (per = ((k - (n+m-2)) % (m-1))) == 0\n\t\t\tfinvar = [is, 2]\n\t\telse\n\t\t\tfinvar = [is, m + 1 - per]\n\t\tend\n\tend\nend\nputs finvar[0], finvar[1]"}], "src_uid": "e88bb7621c7124c54e75109a00f96301"} {"nl": {"description": "Welcome to Codeforces Stock Exchange! We're pretty limited now as we currently allow trading on one stock, Codeforces Ltd. We hope you'll still be able to make profit from the market!In the morning, there are $$$n$$$ opportunities to buy shares. The $$$i$$$-th of them allows to buy as many shares as you want, each at the price of $$$s_i$$$ bourles.In the evening, there are $$$m$$$ opportunities to sell shares. The $$$i$$$-th of them allows to sell as many shares as you want, each at the price of $$$b_i$$$ bourles. You can't sell more shares than you have.It's morning now and you possess $$$r$$$ bourles and no shares.What is the maximum number of bourles you can hold after the evening?", "input_spec": "The first line of the input contains three integers $$$n, m, r$$$ ($$$1 \\leq n \\leq 30$$$, $$$1 \\leq m \\leq 30$$$, $$$1 \\leq r \\leq 1000$$$) \u2014 the number of ways to buy the shares on the market, the number of ways to sell the shares on the market, and the number of bourles you hold now. The next line contains $$$n$$$ integers $$$s_1, s_2, \\dots, s_n$$$ ($$$1 \\leq s_i \\leq 1000$$$); $$$s_i$$$ indicates the opportunity to buy shares at the price of $$$s_i$$$ bourles. The following line contains $$$m$$$ integers $$$b_1, b_2, \\dots, b_m$$$ ($$$1 \\leq b_i \\leq 1000$$$); $$$b_i$$$ indicates the opportunity to sell shares at the price of $$$b_i$$$ bourles.", "output_spec": "Output a single integer \u2014 the maximum number of bourles you can hold after the evening.", "sample_inputs": ["3 4 11\n4 2 5\n4 4 5 4", "2 2 50\n5 7\n4 2"], "sample_outputs": ["26", "50"], "notes": "NoteIn the first example test, you have $$$11$$$ bourles in the morning. It's optimal to buy $$$5$$$ shares of a stock at the price of $$$2$$$ bourles in the morning, and then to sell all of them at the price of $$$5$$$ bourles in the evening. It's easy to verify that you'll have $$$26$$$ bourles after the evening.In the second example test, it's optimal not to take any action."}, "positive_code": [{"source_code": "n,m,r = gets.split.map(&:to_i)\na = gets.split.map(&:to_i).min\nb = gets.split.map(&:to_i).max\np a < b ? (r/a)*b + r % a : r"}, {"source_code": "N, M, R = gets.split.map(&:to_i)\nS = gets.split.map(&:to_i)\nB = gets.split.map(&:to_i)\n\ns = S.min\ncnt = R / s\nb = B.max\ndiff = b - s\n\nmoney = R + diff * cnt\nputs [money, R].max\n"}, {"source_code": "n,m,r = gets.split.map(&:to_i)\ns = gets.split.map(&:to_i).min\nb = gets.split.map(&:to_i).max\nif s > b\n puts r\nelse\n puts r%s+(r/s)*b\nend\n"}, {"source_code": "n, m, r = gets.chomp.split.map(&:to_i)\nbuy = gets.chomp.split.map(&:to_i).min\nsell = gets.chomp.split.map(&:to_i).max\n\nif sell > buy\n shares = r / buy\n profit = shares * (sell - buy)\n r += profit\nend\n\nputs r\n"}], "negative_code": [], "src_uid": "42f25d492bddc12d3d89d39315d63cb9"} {"nl": {"description": "I have an undirected graph consisting of n nodes, numbered 1 through n. Each node has at most two incident edges. For each pair of nodes, there is at most an edge connecting them. No edge connects a node to itself.I would like to create a new graph in such a way that: The new graph consists of the same number of nodes and edges as the old graph. The properties in the first paragraph still hold. For each two nodes u and v, if there is an edge connecting them in the old graph, there is no edge connecting them in the new graph. Help me construct the new graph, or tell me if it is impossible.", "input_spec": "The first line consists of two space-separated integers: n and m (1\u2009\u2264\u2009m\u2009\u2264\u2009n\u2009\u2264\u2009105), denoting the number of nodes and edges, respectively. Then m lines follow. Each of the m lines consists of two space-separated integers u and v (1\u2009\u2264\u2009u,\u2009v\u2009\u2264\u2009n;\u00a0u\u2009\u2260\u2009v), denoting an edge between nodes u and v.", "output_spec": "If it is not possible to construct a new graph with the mentioned properties, output a single line consisting of -1. Otherwise, output exactly m lines. Each line should contain a description of edge in the same way as used in the input format.", "sample_inputs": ["8 7\n1 2\n2 3\n4 5\n5 6\n6 8\n8 7\n7 4", "3 2\n1 2\n2 3", "5 4\n1 2\n2 3\n3 4\n4 1"], "sample_outputs": ["1 4\n4 6\n1 6\n2 7\n7 5\n8 5\n2 8", "-1", "1 3\n3 5\n5 2\n2 4"], "notes": "NoteThe old graph of the first example:A possible new graph for the first example:In the second example, we cannot create any new graph.The old graph of the third example:A possible new graph for the third example:"}, "positive_code": [{"source_code": "n,m=gets.split.map(&:to_i)\nh={}\nm.times do\n a,b=gets.split.map(&:to_i)\n h[[a,b]]=h[[b,a]]=1\nend\na=(1..n).to_a\ns=Time.now\nwhile Time.now-s < 2.8\n b=a.shuffle\n f=true\n m.times do |i|\n if !h[[b[i],b[(i+1)%n]]].nil?\n f=false\n break\n end\n end\n if f\n m.times do |i|\n puts \"#{b[i]} #{b[(i+1)%n]}\"\n end\n exit\n end\nend\np -1"}], "negative_code": [{"source_code": "n,m=gets.split.map(&:to_i)\nh={}\nm.times do\n a,b=gets.split.map(&:to_i)\n h[[a,b]]=h[[b,a]]=1\nend\na=(1..n).to_a\ns=Time.now\nwhile Time.now-s < 2.8\n b=a.shuffle\n f=true\n for i in 0...n\n if !h[[b[i],b[(i+1)%n]]].nil?\n f=false\n break\n end\n end\n if f\n m.times do |i|\n puts \"#{b[i]} #{b[(i+1)%n]}\"\n end\n exit\n end\nend\np -1"}], "src_uid": "c4c85cde8a5bb5fefa4eb68fc68657d5"} {"nl": {"description": "Vanya got an important task \u2014 he should enumerate books in the library and label each book with its number. Each of the n books should be assigned with a number from 1 to n. Naturally, distinct books should be assigned distinct numbers.Vanya wants to know how many digits he will have to write down as he labels the books.", "input_spec": "The first line contains integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009109) \u2014 the number of books in the library.", "output_spec": "Print the number of digits needed to number all the books.", "sample_inputs": ["13", "4"], "sample_outputs": ["17", "4"], "notes": "NoteNote to the first test. The books get numbers 1,\u20092,\u20093,\u20094,\u20095,\u20096,\u20097,\u20098,\u20099,\u200910,\u200911,\u200912,\u200913, which totals to 17 digits.Note to the second sample. The books get numbers 1,\u20092,\u20093,\u20094, which totals to 4 digits."}, "positive_code": [{"source_code": "# coding: utf-8\n\n# \ucd1d \uae30\ub85d\ud574\uc57c\ud558\ub294 \uc22b\uc790\uc758 \uac1c\uc218\ub97c \uc758\ubbf8\ub97c \uac00\ub9ac\ud0b5\ub2c8\ub2e4.\n# n = 13\uc758 \uacbd\uc6b0\n# n[1..9]: 1, 2, 3, 4, 5, 6, 7, 8, 9 -> 9\uae00\uc790\n# n[10..13]: 10, 11, 12, 13 -> 8\uae00\uc790\n# \ucd1d \ud569\uccd0\uc11c 17\uae00\uc790\uac00 \ud544\uc694\ud569\ub2c8\ub2e4.\n\nn = gets.to_i\nt = 0\nfor i in 1..10\n s, e = 10**(i-1), (10**i) - 1\n #p [s,e]\n if e < n\n t += (e - s + 1) * i # 10 ~ 99 -> \ucd1d \uba87\uac1c\uc758 \uc22b\uc790\uac00 \uc874\uc7ac\ud560\uae4c, 89\uac1c\uac00 \uc544\ub2c8\ub77c 90\uac1c\n else\n if s <= n\n t += (n - s + 1) * i\n else\n break\n end\n end\nend\n\nputs t"}, {"source_code": "n = gets.strip!\ns,c = n.length,0\n(1...s).each{ |i| c += i*(9*10**(i-1)) }\np c+(n.to_i-(10**(s-1)-1))*s"}, {"source_code": "n = gets.chomp\nans = 0\nnum = 9\n(1...n.size).each do |i|\n ans += i*num\n num *= 10\nend\nans += n.size*(n.to_i-10**(n.size-1)+1)\nputs ans\n"}, {"source_code": "n = gets.to_i\nans = 0\nn.to_s.chars.size.times do |i|\n a = [9 * (10 ** i), n].min\n n -= a\n ans += a * (i + 1)\nend\np ans\n"}, {"source_code": "#!/usr/bin/env ruby\n\nnum = ARGF.gets.chomp\nlength = num.length\ncount = 0\nif length > 1\n num = (num.to_i - ('9' * (length - 1)).to_i).to_s\nend\n\n\ncount += (num.to_i) * length\n\n\nlength -= 1\nwhile (length > 0) do\n count += (9 * 10**(length - 1)) * length\n length -= 1\nend\n\nputs count\n\n"}, {"source_code": "n=gets.to_i\nif n<10\nputs n\n\nelse\ni,ii,s,t=0,0,0,2\n\n while not(t==0)\n i+=1\n t=n/(10**i)\n end\n\nii=i-1\n\n for p in (1...i)\n s+=9*p*(10**(p-1))\n end\n \ns+=(n+1-(10**ii))*i\n\nputs s\nend"}, {"source_code": "\nn = gets().chomp().to_i\nm = n\ndig =0\nwhile m != 0\n dig += 1\n m /= 10\nend\n\nj =0\nk =1\nfor i in (1..(dig-1))\n\n j+= i*(1+(10**i-1)-(10**(i-1)))\nend\nputs j + (dig*(n-(10**(dig-1))+1))\n\n\n"}, {"source_code": "n = gets.to_i\nd = n.to_s.length\n\nans = n * d\n1.upto(d - 1) do |i|\n\tans -= (d - i) * 9 * 10 ** (i - 1)\nend\nputs ans\n"}, {"source_code": "# cook your code here\n\na = gets.to_i \nb = 0\nans = 0\n\nuntil a < b \n ans = ans + a - b;\n b = 10*b + 9 \nend \n\nputs ans "}, {"source_code": "def f(n)\n result, total, k = 0, 10, 1\n \n while n >= total do\n result += k * (total - total / 10)\n k += 1\n total *= 10\n end\n \n result + (n - total / 10 + 1) * k\nend\n\nputs f(gets.to_i)"}, {"source_code": "def f(n)\n result, total, k = 0, 10, 1\n while n >= total do\n result += k * (total - total / 10)\n k += 1\n total *= 10\n end\n result + (n - total / 10 + 1) * k\nend\nputs f(gets.to_i)"}, {"source_code": "n = gets.chomp\n\ndigit_count = n.length\nn = n.to_i\n\nresult = (n - (10 ** (digit_count - 1) - 1)) * digit_count\n\nresult += (1..(digit_count - 1)).inject(0) do |sum, count|\n\tsum + (9 * 10 ** (count - 1)) * count\nend\n\nputs result"}, {"source_code": "n = gets.to_i\nans = 0\nlen = 1\nbase = 10\nwhile true\n if n < base then\n ans += (n - base / 10 + 1) * len\n break\n else\n ans += base / 10 * 9 * len\n end\n len += 1\n base *= 10\nend\nputs ans\n"}, {"source_code": "# http://codeforces.com/contest/552/problem/B\nn = gets.chomp.to_i\nsum = 0\n\n(0...n.to_s.chars.length).each do |idx|\n d = [9 * (10 ** idx), n].min\n n -= d\n sum += d * (idx + 1)\nend\n\nputs sum\n"}, {"source_code": "#!/usr/bin/ruby\n# Made With LOVE <3\n\nn = gets.to_i\ni=1\ns=0\nwhile i<=n\ns = s + n - (i-1)\ni*=10\nend\n\nputs s\n"}, {"source_code": "number = gets.chomp.to_i\nresult = 0\nmaxDigit = 10\ndivisor = 1000000000\n\nuntil number / divisor != 0\n\tmaxDigit -= 1\n\tdivisor /= 10\nend\n\nnowDigit = 1\n\nuntil nowDigit == maxDigit\n\tresult += (9 * (10**(nowDigit - 1))) * nowDigit\n\n\tnowDigit += 1\nend\n\nresult += ((number - (10**(maxDigit - 1))) + 1) * maxDigit\n\nputs result"}, {"source_code": "a=gets.chomp\nl=a.length-1\nif l==0\nputs a\nelse\nans=9\n2.upto l do |i|\nans+= (9*(10**(i-1)))*i\nend\nans+=(a.to_i-(\"9\"*l).to_i)*(l+1)\nputs ans.inspect\nend\n\n\n"}, {"source_code": "a=gets.to_i\nr=9\nans=0\nwhile a>0\n\tans+=a\n\ta-=r\n\tr*=10\nend\n\nputs ans\n\n"}, {"source_code": "n = gets.to_i\ns = 1\nans = 0\nwhile s.to_s.length < n.to_s.length\n ans += s * 9 * s.to_s.length\n s *= 10\nend\nans += (n - s + 1) * n.to_s.length\np ans"}], "negative_code": [{"source_code": "n = gets\ns,c = n.length,0\nn = n.to_i\n(1...s).each{ |i| c += i*(9*10**(i-1)) }\np c+(n-(10**(s-1)-1))*s"}, {"source_code": "n = gets\ns,n,c = n.size,n.to_i,0\n(1...s).each{ |i| c += i*(9*10**(i-1)) }\np c+(n-(10**(s-1)-1))*s"}, {"source_code": "n = gets\ns,c = n.size,0\nn = n.to_i\n(1...s).each{ |i| c += i*(9*10**(i-1)) }\np c+(n-(10**(s-1)-1))*s"}, {"source_code": "#!/usr/bin/env ruby\n\nnum = ARGF.gets.chomp\nlength = num.length\ncount = 0\nif length > 1\n num = num[1..-1]\nend\ncount += (num.to_i + 1) * length\nif length == 1\n count -= 1\nend\n\n\n\n\nlength -= 1\nwhile (length > 0) do\n count += (9 * 10**(length - 1)) * length\n length -= 1\nend\n\nputs count\n\n"}, {"source_code": "n = gets.chomp\n\ndigit_count = n.length\nn = n.to_i\n\nresult = (n - (10 ** (digit_count - 1) - 1)) * digit_count\n\nresult += (1..(digit_count - 1)).inject(0) do |sum, count|\n\tsum + ('9' * count).to_i * count\nend\n\nresult"}, {"source_code": "n = gets.chomp\n\ndigit_count = n.length\nn = n.to_i\n\nresult = (n - (10 ** (digit_count - 1) - 1)) * digit_count\n\nresult += (1..(digit_count - 1)).inject(0) do |sum, count|\n\tsum + ('9' * count).to_i * count\nend\n\nputs result"}, {"source_code": "#!/usr/bin/ruby\n# Made With LOVE <3\n\nn = gets.to_i\ni=1\ns=0\nwhile i 9\uae00\uc790\n# n[10..13]: 10, 11, 12, 13 -> 8\uae00\uc790\n# \ucd1d \ud569\uccd0\uc11c 17\uae00\uc790\uac00 \ud544\uc694\ud569\ub2c8\ub2e4.\n\nn = gets.to_i\nt = 0\nfor i in 1..10\n s, e = 10**(i-1), (10**i) - 1\n #p [s,e]\n if e < n\n t += (e - s + 1) * i # 10 ~ 99 -> \ucd1d \uba87\uac1c\uc758 \uc22b\uc790\uac00 \uc874\uc7ac\ud560\uae4c, 89\uac1c\uac00 \uc544\ub2c8\ub77c 90\uac1c\n else\n if s < n\n t += (n - s + 1) * i\n else\n break\n end\n end\nend\n\nputs t"}], "src_uid": "4e652ccb40632bf4b9dd95b9f8ae1ec9"} {"nl": {"description": "You are a lover of bacteria. You want to raise some bacteria in a box. Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly x bacteria in the box at some moment. What is the minimum number of bacteria you need to put into the box across those days?", "input_spec": "The only line containing one integer x (1\u2009\u2264\u2009x\u2009\u2264\u2009109).", "output_spec": "The only line containing one integer: the answer.", "sample_inputs": ["5", "8"], "sample_outputs": ["2", "1"], "notes": "NoteFor the first sample, we can add one bacterium in the box in the first day morning and at the third morning there will be 4 bacteria in the box. Now we put one more resulting 5 in the box. We added 2 bacteria in the process so the answer is 2.For the second sample, we can put one in the first morning and in the 4-th morning there will be 8 in the box. So the answer is 1."}, "positive_code": [{"source_code": "puts gets.chomp.to_i().to_s(2).count('1')"}, {"source_code": "p gets.to_i.to_s(2).count(?1)"}, {"source_code": "#!/usr/bin/ruby\n\nn = gets.to_i\nans = 0\nwhile n > 0\n # p \"n=#{n}, ans=#{ans}\"\n ans+=1 if n % 2 == 1\n n/=2\nend\n\nputs ans\n"}, {"source_code": "puts gets.to_i.to_s(2).count '1'"}, {"source_code": "p sprintf(\"%b\", gets.chomp).gsub('0', '').length"}, {"source_code": "#! /usr/bin/env ruby\n\nx = gets.to_i\nputs x.to_s(2).count('1')\n\n"}, {"source_code": "a = gets.to_i\nsum = 0\n(0..48).each {|n| sum += a[n]}\nputs sum"}, {"source_code": "n = gets.chomp.to_i\n\nc = 0\n\nwhile n > 1\n\n if n % 2 == 0\n n /= 2\n else\n c += 1\n n -= 1\n end\nend\n\nputs c + 1\n"}, {"source_code": "puts gets.to_i.to_s(2).count('1')\n"}, {"source_code": "x = gets.to_i\nans = 0\nwhile x>0\n x=x&(x-1)\n ans += 1\nend\nprint ans"}, {"source_code": "a=gets.chomp.to_i\nans=0\nloop do \nif a%2==1\n ans+=1\nend\na=a/2\nbreak if a==0\nend\nputs \"#{ans}\"\n\n"}, {"source_code": "a=gets.chomp.to_i\nans=0\nloop do \nif a%2==1\n ans+=1\nend\na=a/2\nbreak if a==0\nend\nputs \"#{ans}\"\n"}, {"source_code": "n=gets.to_i.to_s(2)\np n.chars.count{|e|\n\te==\"1\"\n}"}, {"source_code": "n = gets.to_i\nr = 0\nwhile n > 0\n\tif n % 2 > 0\n\t\tr += 1\n\tend\n\tn = n / 2\nend\np r"}, {"source_code": "#$stdin = File.open('in.txt')\n#$stdout = File.open('out.txt', 'w')\n\nn = gets.to_i\n\nans = 0\nwhile (n > 0) do\n ans += 1 if n % 2 == 1\n n /= 2\nend\n\np ans\n"}, {"source_code": "x = gets.chomp.to_i\n\nrtn = 0\nwhile 0 < x\n rtn += x % 2\n x /= 2\nend\nputs rtn\n"}, {"source_code": "puts (gets.to_i).to_s(2).count('1')\n"}, {"source_code": "num = gets.chomp.to_i\ncount = 0\nuntil num == 0\n count += num%2\n num = num/2\nend\np count"}, {"source_code": "puts gets.to_i.to_s(2).count('1')"}, {"source_code": "a = gets.to_i\nans = 0\nc = 2**30\nwhile c > 0\n ans += a / c\n a %= c\n c /= 2\nend\nputs ans\n"}, {"source_code": "puts gets.to_i.to_s(2).count('1')\n"}, {"source_code": "a = gets.to_i\nputs a.to_s(2).count('1')\n"}, {"source_code": "puts gets.to_i.to_s(2).chars.count('1')\n"}, {"source_code": "user_input = gets.chomp\nuser_input = user_input.to_i\ncount = 0\nwhile user_input != 0\n count += user_input & 1\n user_input = user_input >> 1\nend\nprint count\n"}, {"source_code": "class Solver\n\tdef main\n\t\tn = gets.to_i\n\t\tans = (0..30).to_a.count { |i| n[i] == 1 }\n\t\tputs ans\n\tend\nend\n\nSolver.new.main\n"}], "negative_code": [{"source_code": "#!/usr/bin/ruby\n\nn = gets.to_i\nx = 1\nwhile x*2 <= n\n x*=2\nend\n\nputs 1 + n - x\n"}, {"source_code": "a = gets.to_i\nputs a.odd? && a != 1 ? 2 : 1\n"}], "src_uid": "03e4482d53a059134676f431be4c16d2"} {"nl": {"description": "Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first n. He writes down the following sequence of numbers: firstly all odd integers from 1 to n (in ascending order), then all even integers from 1 to n (also in ascending order). Help our hero to find out which number will stand at the position number k.", "input_spec": "The only line of input contains integers n and k (1\u2009\u2264\u2009k\u2009\u2264\u2009n\u2009\u2264\u20091012). Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.", "output_spec": "Print the number that will stand at the position number k after Volodya's manipulations.", "sample_inputs": ["10 3", "7 7"], "sample_outputs": ["5", "6"], "notes": "NoteIn the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5."}, "positive_code": [{"source_code": "#!/usr/bin/env ruby\nn, k = gets.split(' ').map(&:to_i)\nodd = (n + 1) / 2\neven = n / 2\nif k <= odd\n puts k * 2 - 1\nelse\n puts (k - odd) * 2\nend\n"}, {"source_code": "def run\n n, k = $stdin.gets.split.map(&:to_i)\n\n if k <= ((n + 1)/ 2)\n puts (k * 2 - 1)\n else\n puts ((k - ((n + 1)/ 2)) * 2)\n end\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "n, k = gets.chomp.split.map &:to_i\nif k > (n / 2.0).ceil \n puts 2 * (k - (n / 2.0).ceil)\nelse\n puts 2 * k - 1\nend\n"}, {"source_code": "class A\n def initialize\n n, k = gets.split(' ').map(&:to_i)\n d = 0\n\n if n.even?\n if k <= n/2\n puts 2*k-1\n else\n puts 2*(k-n/2)\n end\n else\n if k <= n/2+1\n puts 2*k-1\n else\n puts 2*(k-(n/2+1))\n end\n end\n end\nend\n\na = A.new"}, {"source_code": "n,k=gets.split.map(&:to_i)\nt=(n+1)/2\np k>t ? 2*(k-t) : 2*k-1\n"}, {"source_code": "a=gets.chomp.split(\" \")\nodd=(a[0].to_i/2.0).ceil\neven=(a[0].to_i/2.0)\nif a[1].to_i<=odd\nans=2*(a[1].to_i-1)+1\nputs \"#{ans}\"\nelse\nans=2*(a[1].to_i-odd)\nputs \"#{ans}\"\nend\n"}, {"source_code": "n,k=gets.split.map(&:to_i)\nt=(n+1)/2\np k>t ? 2*(k-t) : 2*k-1\n"}, {"source_code": "n, k = gets.chomp.split(/ /).map(&:to_i)\nmid = n / 2\nmid += 1 if n.odd?\nans = (k - mid) * 2\nans = (2 * k) - 1 if mid >= k\nputs \"#{ans}\"\n"}, {"source_code": "a=gets.chomp.split(\" \")\nodd=(a[0].to_i/2.0).ceil\neven=(a[0].to_i/2.0)\nif a[1].to_i<=odd\nans=2*(a[1].to_i-1)+1\nputs \"#{ans}\"\nelse\nans=2*(a[1].to_i-odd)\nputs \"#{ans}\"\nend"}, {"source_code": "n,k=gets.split.map(&:to_i)\na=(n+1)/2\np k>a ?2*(k-a):2*k-1"}, {"source_code": "n,k=gets.split.map{|e| e.to_i}\ne=n/2+n%2\nputs (k<=e)?2*k-1:(k-e)*2"}, {"source_code": "n, k = gets.chomp.split.map(&:to_i)\na = n.odd? ? n/2+1 : n/2\nputs k <= a ? 2*k-1 : 2*(k-a)\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\nk -= 1\n\nt = (n.to_f / 2).ceil\n\nif k < t\n puts 1 + 2 * k\nelse\n puts 2 + 2 * (k - t)\nend\n"}, {"source_code": "d, n = gets.chomp.split.map(&:to_i)\n\nif d % 2 == 0\n ot = d/2\n if n <= ot\n puts (2*n) - 1\n else\n puts 2*(n-ot)\n end\nelse\n ot = (d/2.0).ceil\n if n <= ot\n puts (2*n) - 1\n else\n puts 2*(n-ot)\n end\nend"}, {"source_code": "n,k=gets.split.map(&:to_i)\nodd=(n+1)/2\nputs k<=odd ? 2*k-1 : 2*(k-odd)"}, {"source_code": "n, k = gets.split(/\\s+/).map {|x| x.to_i}\nclass Integer\n def num_at_position (k)\n chet_num, ostatok = self.divmod(2)\n nechet_num = chet_num + ostatok\n if k > nechet_num\n return (k - nechet_num) * 2\n else\n return k * 2 - 1\n end\n end\nend\n\nputs n.num_at_position(k)"}, {"source_code": "num = gets.chomp\nnum = num.split\nnumbers = num[0].to_i\nposition = num[1].to_i\n\nif position <= (numbers/2) + (numbers%2)\n\tnew_number = (position * 2) - 1\nelse\n\tnew_number = (position - ((numbers/2) + (numbers%2))) * 2\nend\n\nprint new_number"}, {"source_code": "n,k=gets.split.map(&:to_i)\nt=(n+1)/2\np k>t ? 2*(k-t) : 2*k-1\n"}, {"source_code": "#puts \"Enter the total number and position to find the number\\n\"\nn, v = gets.split.map(&:to_i)\nif n%2 == 0\n m = n/2\nelse\n m = n/2 + 1\nend\nif v <= m\n puts (2*v)-1\nelse\n puts 2*v - (2*m)\nend"}, {"source_code": "n,k = gets.split(\" \").map(&:to_i)\neven_count = n /2\nodd_count = n / 2\nodd_count += 1 if n % 2 != 0\nans = k > odd_count ? (k - odd_count) * 2 : k * 2 - 1\nputs ans"}, {"source_code": "a, b = gets.split.map &:to_i\n\nif a >= b * 2 - 1 - a % 2\n puts b * 2 - 1\nelse\n puts (b - a/2 - a % 2) * 2\nend\n"}, {"source_code": "a=gets.split.map &:to_i;puts (a[0]+1)/2>=a[1]?(2*a[1]-1):(2*(a[1]-(a[0]+1)/2))"}, {"source_code": "n, k = gets.split.map(&:to_i)\n\nif k <= n / 2 + (n % 2 == 1 ? 1 : 0)\n\tputs k * 2 - 1\nelse\n\tif n % 2 == 1\n\t\tputs (k - n / 2 - 1) * 2\n\telse\n\t\tputs (k - n / 2) * 2\n\tend\nend"}, {"source_code": "n,i = gets.split.map(&:to_i)\n(i>(n+1)/2)? (p (i-(n+1)/2)*2) : (p (i-1)*2+1)\n"}, {"source_code": "n, k = gets.chomp.split(' ').collect { |i| i.to_i }\n\nif k <= (n+1)/2 \n\tputs 2*k - 1\nelse\n\tputs 2*( k - (n+1)/2)\nend\n"}, {"source_code": "n , k = gets().split().map(&:to_i)\n\nmid = (n+1)/2\nif k>mid\n puts 2*(k-mid)\nelse\n puts (k*2)-1\nend"}, {"source_code": "n,k = gets.split(\" \").map(&:to_i)\nm = (n/2.0).ceil()\nif(k<=m)\n print((2*k)-1)\nelse\n print(2*(k-m))\nend"}, {"source_code": "s = gets.split(' ')\t#\u0422\u0430\u043d\u0446\u044b \u0441 \u0431\u0443\u0431\u043d\u043e\u043c\n\nn = s[0].to_i\nk = s[1].to_i\n\nf = k - n/2 - n%2\n\nif f > 0\n\tputs 2 * f\nelse\n\tputs n - 1 + n % 2 + 2 * f\nend"}, {"source_code": "n, k = gets.strip.split(\" \").collect{|v| v.to_i}\nif k <= (n / 2.0).ceil then\n puts ((k-1)*2+1)\nelse\n puts ((k-(n/2.0).ceil)*2)\nend"}, {"source_code": "input = gets.split\nn = input[0].to_i\nk = input[1].to_i\nhalf = (n/2.0).ceil\n\nval = 0\nif k > half\n val = 2\n k -= half\nelse\n val = 1\nend\n\nval += 2*(k-1)\n\nprint val\n"}, {"source_code": "a=gets.chomp.split(\" \")\nodd=(a[0].to_i/2.0).ceil\neven=(a[0].to_i/2.0)\nif a[1].to_i<=odd\nans=2*(a[1].to_i-1)+1\nputs \"#{ans}\"\nelse\nans=2*(a[1].to_i-odd)\nputs \"#{ans}\"\nend"}, {"source_code": "n,k=gets.split.map(&:to_i)\nt=(n+1)/2\np k>t ? 2*(k-t) : 2*k-1"}, {"source_code": "n, k = gets.split.map(&:to_i)\n\nif 2*k-1 <= n\n puts 2*k-1\nelse\n puts 2*k - n - n%2\nend\n"}, {"source_code": "n,k=gets.split.map(&:to_i)\nt=(n+1)/2\np k>t ? 2*(k-t) : 2*k-1\n"}, {"source_code": "n, k = gets.split(' ').map(&:to_i)\n\nmid = n/2 + n%2\n\nif k > mid\n puts (k-mid)*2\nelse\n puts 2*k-1\nend\n"}, {"source_code": "n,k=gets.split.map(&:to_i)\na=(n+1)/2\np k>a ?2*(k-a):2*k-1"}, {"source_code": "#!/usr/bin/env ruby\n\nn, k = gets.split.map(&:to_i)\nputs k > (n + 1) / 2 ? (k - (n + 1) / 2) * 2 : 2 * k - 1\n"}, {"source_code": "g = gets.split(' ')\n\nn = g[0].to_f\nk = g[1].to_i\n\nif k > (n/2).ceil\n if n.modulo(2) == 0\n i = 2*k - n \n else\n i = 2*k - n - 1\n end\nelse\n i = 2*k - 1\nend\n\nputs i.to_i"}, {"source_code": "n,k=gets.split.map(&:to_i)\nt=(n+1)/2\np k>t ? 2*(k-t) : 2*k-1\n"}, {"source_code": "n,k=gets.split.map(&:to_i)\nputs k<=(n+1)/2?2*k-1:(k-(n+1)/2)*2"}, {"source_code": "n,k=gets.split.map(&:to_i)\na=(n+1)/2\np k>a ?2*(k-a):2*k-1"}, {"source_code": "n,k =gets.split(' ').map{|i| i.to_i()}\nans=k+k-1\nif(ans>n)\n\tans=(k-((n+1)>>1))<<1\nend\np ans"}, {"source_code": "n, k = gets.split.map { |x| x.to_i }\nevens = n / 2\nodds = n - evens\noffset = 0\nif k > odds\n\tk -= odds\n\toffset = 1\nend\n\nputs k * 2 - 1 + offset\n"}, {"source_code": "n,k=gets.split.map(&:to_i)\nt=(n+1)/2\np k>t ? 2*(k-t) : 2*k-1\n"}, {"source_code": "input = gets.chomp.split(' ').map {|item| item.to_i}\n\nn = input[0]\nk = input[1]\n\nmaxOdd = (n + 1) / 2\n\nputs (2 * k) - 1 if k <= maxOdd\nputs (2* (k - maxOdd)) if k > maxOdd"}, {"source_code": "n,k=gets.split.map &:to_i;puts((n+1)/2t ? 2*(k-t) : 2*k-1\n"}, {"source_code": "n,k=gets.split.map(&:to_i)\nt=(n+1)/2\np k>t ? 2*(k-t) : 2*k-1\n"}, {"source_code": "n,k=gets.split.map(&:to_i)\nt=(n+1)/2\np k>t ? 2*(k-t) : 2*k-1"}, {"source_code": "n,k=gets.split.map(&:to_i)\nt=(n+1)/2\np k>t ? 2*(k-t) : 2*k-1"}, {"source_code": "n,k=gets.split.map(&:to_i)\nt=(n+1)/2\np k>t ? 2*(k-t) : 2*k-1"}, {"source_code": "n,k = gets.split.map(&:to_i)\nt=(n/2.0).ceil\np k>t ? 2*(k-t) : 2*k-1"}, {"source_code": "n,k=gets.chomp.split.map(&:to_i)\nputs (k*2-1<=n)? k*2-1 : (k-(n+1)/2)*2"}, {"source_code": "n,k = gets.split.map(&:to_i)\n\ncs = (n+1)/2\nif k > cs\n puts (k-cs)*2\nelse\n puts (k*2)-1\nend"}, {"source_code": "n, k = $stdin.readline.split.map(&:to_i)\n\nif n%2==0\n if k <= n/2\n puts 2*(k-1)+1\n else\n k -= n/2\n puts 2*(k)\n end\nelse\n if k <= n/2+1\n puts 2*(k-1)+1\n else\n k -= n/2+1\n puts 2*(k)\n end\nend"}], "negative_code": [{"source_code": "def run\n n, k = $stdin.gets.split.map(&:to_i)\n\n if k < (n / 2)\n puts (k * 2 - 1)\n else\n puts (((k - 1) - (n / 2)) * 2)\n end\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "n, k = gets.chomp.split.map &:to_i\nif k > (n / 2.0).ceil \n puts 2 * (n - (n / 2.0).ceil)\nelse\n puts 2 * k - 1\nend\n"}, {"source_code": "n, k = gets.chomp.split.map(&:to_i)\nif k < n / 2\n puts 2 * (k-1) + 1\nelse\n puts 2 * ((k-1) / 2)\nend\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\nk -= 1\n\nif k < n / 2\n puts 1 + 2 * k\nelse\n k -= (n + 1) / 2\n puts 2 + 2 * k\nend\n"}, {"source_code": "n,k=gets.split.map(&:to_i)\nputs (2*k<=n ? 2*k-1 : k/2*2)"}, {"source_code": "n,k=gets.split.map(&:to_i)\nputs (n==1 ? 1: 2*k<=n ? 2*k-1 : k/2*2)"}, {"source_code": "n, k = gets.split.map(&:to_i)\n\nif k <= n / 2\n\tputs k * 2 - 1\nelse\n\tif n % 2 == 1\n\t\tputs (k - n / 2 - 1) * 2\n\telse\n\t\tputs (k - n / 2) * 2\n\tend\nend"}, {"source_code": "s = gets.split(' ')\t#\u0422\u0430\u043d\u0446\u044b \u0441 \u0431\u0443\u0431\u043d\u043e\u043c\n\nn = s[0].to_i\nk = s[1].to_i\n\na = 1\ni = 1\n\nwhile a <= n && i < k\n\ta += 2\n\ti += 1\nend\n\nif i < k\n\ta = 2\nend\n\nwhile i < k\n\ta += 2\n\ti += 1\nend\n\nputs a"}, {"source_code": "n = gets.to_i\nk = gets.to_i\n\na = 1\ni = 1\n\nwhile a <= n && i < k\n\ta += 2\n\ti += 1\nend\n\nif i < k\n\ta = 2\nend\n\nwhile i < k\n\ta += 2\n\ti += 1\nend\n\nputs a"}, {"source_code": "input = gets.split\nn = input[0].to_i\nk = input[1].to_i\nhalf = (n/2.0).ceil\n\nval = 0\nif k > half\n val = 2\n k -= half\nelse\n val = 1\nend\n\nfor i in 1..k-1\n val += 2*(k-1)\nend\n\nprint val\n"}, {"source_code": "g = gets.split(' ')\n\nn = g[0].to_f\nk = g[1].to_i\n\nif k > (n/2).ceil\n i = 2*k - n\nelse\n i = 2*k - 1\nend\n\nputs i"}, {"source_code": "n,k=gets.split.map(&:to_i)\nputs k<=(n+1)/2?2*k-1:2*k-n-1"}, {"source_code": "input = gets.chomp.split(' ').map {|item| item.to_i}\n\nn = input[0]\nk = input[1]\n\nmaxOdd = (n - 1) / 2\n\nputs (2 * k) - 1 if k <= maxOdd\nputs (k / 2) + maxOdd if k > maxOdd"}, {"source_code": "n, k = $stdin.readline.split.map(&:to_i)\n\nif n%2==0\n if k <= n/2\n puts 2*(k-1)+1\n else\n puts 2*(k-1-n/2)\n end\nelse\n if k < n/2\n puts 2*(k-1)+1\n else\n puts 2*(k-1-n/2)\n end\nend"}, {"source_code": "n, k = $stdin.readline.split.map(&:to_i)\n\nif n%2==0\n if k <= n/2\n puts 2*(k-1)+1\n else\n puts 2*(k-n/2)\n end\nelse\n if k <= n/2+1\n puts 2*(k-1)+1\n else\n puts 2*(k-n/2)\n end\nend"}, {"source_code": "n, k = $stdin.readline.split.map(&:to_i)\n\nif n%2==0\n if k <= n/2\n puts 2*(k-1)+1\n else\n puts 2*(k-n/2)\n end\nelse\n if k < n/2\n puts 2*(k-1)+1\n else\n puts 2*(k-1-n/2)\n end\nend"}], "src_uid": "1f8056884db00ad8294a7cc0be75fe97"} {"nl": {"description": "Petr has just bought a new car. He's just arrived at the most known Petersburg's petrol station to refuel it when he suddenly discovered that the petrol tank is secured with a combination lock! The lock has a scale of $$$360$$$ degrees and a pointer which initially points at zero: Petr called his car dealer, who instructed him to rotate the lock's wheel exactly $$$n$$$ times. The $$$i$$$-th rotation should be $$$a_i$$$ degrees, either clockwise or counterclockwise, and after all $$$n$$$ rotations the pointer should again point at zero.This confused Petr a little bit as he isn't sure which rotations should be done clockwise and which should be done counterclockwise. As there are many possible ways of rotating the lock, help him and find out whether there exists at least one, such that after all $$$n$$$ rotations the pointer will point at zero again.", "input_spec": "The first line contains one integer $$$n$$$ ($$$1 \\leq n \\leq 15$$$) \u2014 the number of rotations. Each of the following $$$n$$$ lines contains one integer $$$a_i$$$ ($$$1 \\leq a_i \\leq 180$$$) \u2014 the angle of the $$$i$$$-th rotation in degrees.", "output_spec": "If it is possible to do all the rotations so that the pointer will point at zero after all of them are performed, print a single word \"YES\". Otherwise, print \"NO\". Petr will probably buy a new car in this case. You can print each letter in any case (upper or lower).", "sample_inputs": ["3\n10\n20\n30", "3\n10\n10\n10", "3\n120\n120\n120"], "sample_outputs": ["YES", "NO", "YES"], "notes": "NoteIn the first example, we can achieve our goal by applying the first and the second rotation clockwise, and performing the third rotation counterclockwise.In the second example, it's impossible to perform the rotations in order to make the pointer point at zero in the end.In the third example, Petr can do all three rotations clockwise. In this case, the whole wheel will be rotated by $$$360$$$ degrees clockwise and the pointer will point at zero again."}, "positive_code": [{"source_code": "n,*a=$<.read.split.map &:to_i\ns=a.reduce :+\nputs (1<0}.map{|j|a[j]}.reduce 0,:+;(s-2*t)%360==0} ? :YES : :NO"}, {"source_code": "# Utility\n\n# Better use B-tree but eff that\ndef spin(angle, initial = [0])\n return Array.new(initial.length * 2) { |i| initial[i / 2] + angle * (-1)**(i % 2) }\nend\n\n# Input\nn = gets.to_i\na = Array.new(n) { |i| gets.to_i }\n\n# Processing\nvariants = [a[0]]\n(n - 1).times do |i|\n variants = spin(a[1 + i], variants)\nend\n\nable_to_open = variants.detect { |el| el % 360 == 0 }\n\n# Output\nputs(able_to_open ? \"YES\" : \"NO\")\n"}, {"source_code": "n = gets().to_i\narr = []\nn.times do\n arr += [gets().to_i]\nend\ncur = \"0\" * n\nlast = \"1\" * n\nf = false\nwhile (cur.to_i(10) < last.to_i(10))\n d = 0\n arr.each_with_index do |e, ind|\n if cur[ind] == '0'\n d -= e\n else\n d += e\n end\n end\n if (d % 360 == 0)\n f = true\n break\n end\n cur = (cur.to_i(2) + 1).to_s(2)\n # puts cur\n cur = (\"0\" * (n - cur.size)) + cur\nend\nif f\n puts \"YES\"\nelse\n puts \"NO\"\nend"}, {"source_code": "N = gets.to_i\nas = [0]\nbs = nil\nN.times {\n rot = gets.to_i\n bs = as.map{ |a| [(a+rot)%360, (a-rot+360)%360]}.flatten.uniq\n as,bs = bs,as\n}\nputs as.include?(0) ? \"YES\" : \"NO\""}], "negative_code": [{"source_code": "n,*a=$<.read.split.map &:to_i\ns=a.reduce :+\nputs (1<0}.map{|j|a[j]}.reduce 0,:+;t%360==0} ? :YES : :NO"}, {"source_code": "n,*a=$<.read.split.map &:to_i\ns=a.reduce :+\nputs (1<0}.map{|j|a[j]}.reduce 0,:+;t*2==s} ? :YES : :NO"}], "src_uid": "01b50fcba4185ceb1eb8e4ba04a0cc10"} {"nl": {"description": "Panic is rising in the committee for doggo standardization\u00a0\u2014 the puppies of the new brood have been born multi-colored! In total there are 26 possible colors of puppies in the nature and they are denoted by letters from 'a' to 'z' inclusive.The committee rules strictly prohibit even the smallest diversity between doggos and hence all the puppies should be of the same color. Thus Slava, the committee employee, has been assigned the task to recolor some puppies into other colors in order to eliminate the difference and make all the puppies have one common color.Unfortunately, due to bureaucratic reasons and restricted budget, there's only one operation Slava can perform: he can choose a color $$$x$$$ such that there are currently at least two puppies of color $$$x$$$ and recolor all puppies of the color $$$x$$$ into some arbitrary color $$$y$$$. Luckily, this operation can be applied multiple times (including zero).For example, if the number of puppies is $$$7$$$ and their colors are represented as the string \"abababc\", then in one operation Slava can get the results \"zbzbzbc\", \"bbbbbbc\", \"aaaaaac\", \"acacacc\" and others. However, if the current color sequence is \"abababc\", then he can't choose $$$x$$$='c' right now, because currently only one puppy has the color 'c'.Help Slava and the committee determine whether it is possible to standardize all the puppies, i.e. after Slava's operations all the puppies should have the same color.", "input_spec": "The first line contains a single integer $$$n$$$ ($$$1 \\le n \\le 10^5$$$)\u00a0\u2014 the number of puppies. The second line contains a string $$$s$$$ of length $$$n$$$ consisting of lowercase Latin letters, where the $$$i$$$-th symbol denotes the $$$i$$$-th puppy's color.", "output_spec": "If it's possible to recolor all puppies into one color, print \"Yes\". Otherwise print \"No\". Output the answer without quotation signs.", "sample_inputs": ["6\naabddc", "3\nabc", "3\njjj"], "sample_outputs": ["Yes", "No", "Yes"], "notes": "NoteIn the first example Slava can perform the following steps: take all puppies of color 'a' (a total of two) and recolor them into 'b'; take all puppies of color 'd' (a total of two) and recolor them into 'c'; take all puppies of color 'b' (three puppies for now) and recolor them into 'c'. In the second example it's impossible to recolor any of the puppies.In the third example all the puppies' colors are the same; thus there's no need to recolor anything."}, "positive_code": [{"source_code": "n=gets.to_i\nputs n>gets.chomp.chars.uniq.size||n==1?:Yes: :No"}, {"source_code": "N = gets.to_i\nS = gets.chomp.split('').sort\nif N == 1\n puts 'Yes'\n exit\nend\n\n(N-1).times do |i|\n if S[i] == S[i+1]\n puts 'Yes'\n exit\n end\nend\nputs 'No'"}, {"source_code": "n = gets.to_i\ns = gets.chomp\nc = Hash.new(0)\nfor i in 0..n-1\n c[s[i]] += 1\nend\nputs (n == 1 || c.values.any?{|i|i > 1}) ? \"Yes\" : \"No\"\n"}, {"source_code": "useless = gets.chomp\nline = gets.chomp\na = Array.new(26,0)\nif(line.size == 1)\n\tprint (\"Yes\")\n\texit\nend\nfor i in 0...line.size\n\ta[line[i].ord - 97] += 1\nend\n\nfor i in 0...26\n\tif(a[i] > 1)\n\t\tprint(\"Yes\")\n\t\texit\n\tend\nend\nprint(\"No\")"}, {"source_code": "n = gets.split()[0].to_i\ns = gets.split()[0]\nmx = 0\n('a'..'z').each do |x|\n mx = [mx, (s.count x)].max\nend\nputs ((mx > 1 or s.length == 1) ? 'Yes' : 'No')"}, {"source_code": "n = gets.to_i\nstr = gets.chomp\n\nif n==1\n puts \"Yes\"\n exit\nend\n\nif n>26\n puts \"Yes\"\nelse\n hash = Hash.new(0)\n str.each_char {|x| hash[x]+=1}\n\n if hash.values.max==1\n puts \"No\"\n else\n puts \"Yes\"\n end\nend"}], "negative_code": [{"source_code": "n=gets.to_i\nputs n>gets.chars.uniq.size||n==1?:Yes: :No"}, {"source_code": "n = gets.to_i\ns = gets.chomp\nc = Hash.new(0)\nfor i in 0..n-1\n c[s[i]] += 1\nend\nputs c.values.any?{|i|i > 1} ? \"YES\" : \"NO\"\n"}, {"source_code": "useless = gets.chomp\nline = gets.chomp\na = Array.new(26,0)\n\nfor i in 0...line.size\n\ta[line[i].ord - 97] += 1\nend\n\nfor i in 0...26\n\tif(a[i] > 1)\n\t\tprint(\"Yes\")\n\t\texit\n\tend\nend\nprint(\"No\")"}, {"source_code": "n = gets.to_i\nstr = gets.chomp\n\nif n==1\n puts \"Yes\"\nend\n\n#if n>26\n# puts \"Yes\"\n# exit\n#else\n hash = Hash.new(0)\n str.each_char {|x| hash[x]+=1}\n\n if hash.values.max<2\n puts \"No\"\n else\n puts \"Yes\"\n end\n#end"}, {"source_code": "n = gets.to_i\nstr = gets.chomp\n\nif n==1\n puts \"Yes\"\nend\n\nif n>26\n puts \"Yes\"\n exit\nelse\n hash = Hash.new(0)\n str.each_char {|x| hash[x]+=1}\n\n if hash.values.max<2\n puts \"No\"\n else\n puts \"Yes\"\n end\nend"}, {"source_code": "n = gets.to_i\nstr = gets.chomp\n\nif n>26\n puts \"Yes\"\n exit\nelse\n hash = Hash.new(0)\n str.each_char {|x| hash[x]+=1}\n\n if hash.values.max<2\n puts \"No\"\n else\n puts \"Yes\"\n end\nend"}], "src_uid": "6b22e93f7e429693dcfe3c099346dcda"} {"nl": {"description": "Two players play a simple game. Each player is provided with a box with balls. First player's box contains exactly n1 balls and second player's box contains exactly n2 balls. In one move first player can take from 1 to k1 balls from his box and throw them away. Similarly, the second player can take from 1 to k2 balls from his box in his move. Players alternate turns and the first player starts the game. The one who can't make a move loses. Your task is to determine who wins if both players play optimally.", "input_spec": "The first line contains four integers n1,\u2009n2,\u2009k1,\u2009k2. All numbers in the input are from 1 to 50. This problem doesn't have subproblems. You will get 3 points for the correct submission.", "output_spec": "Output \"First\" if the first player wins and \"Second\" otherwise.", "sample_inputs": ["2 2 1 2", "2 1 1 1"], "sample_outputs": ["Second", "First"], "notes": "NoteConsider the first sample test. Each player has a box with 2 balls. The first player draws a single ball from his box in one move and the second player can either take 1 or 2 balls from his box in one move. No matter how the first player acts, the second player can always win if he plays wisely."}, "positive_code": [{"source_code": "a, b = gets.strip.split.map( &:to_i )\nputs a <= b ? \"Second\" : \"First\"\n"}, {"source_code": "#!/usr/bin/ruby\n\ninput = STDIN.readline.chomp\ninput = input.split(' ')\nif input[0].to_i > input[1].to_i\n puts \"First\"\nelsif input[0] == input[1]\n puts \"Second\"\nelse\n puts \"Second\"\nend"}, {"source_code": "#!/usr/bin/ruby\n\ninput = STDIN.readline.chomp\ninput = input.split(' ')\nif input[0].to_i > input[1].to_i\n puts \"First\"\nelsif input[0].to_i == input[1].to_i\n puts \"Second\"\nelse\n puts \"Second\"\nend"}, {"source_code": "\nn1,n2,k1,k2=gets.chomp.split\n\nn1 = n1.to_i \nn2 = n2.to_i\n\ncase n1<=>n2 \n when 0 \n print \"Second\";\n when 1 \n print \"First\";\n when -1 \n print \"Second\";\nend\n "}, {"source_code": "n,m,k,l=gets.split.map &:to_i\nputs n>m ? \"First\" : \"Second\""}, {"source_code": "n1, n2, k1, k2 = $stdin.readline.split.map(&:to_i)\n\nif n1>n2\n puts \"First\"\nelse\n puts \"Second\"\nend"}, {"source_code": "#le roi est mort is here\nk, l, c, d = gets.split.map &:to_i\nif k > l\n puts \"First\"\nelse\n puts \"Second\"\nend"}, {"source_code": "#!/usr/bin/ruby\n# coding: utf-8\n\na, b, c, d = gets.split.map &:to_i\nputs (a > b) ? \"First\" : \"Second\""}, {"source_code": "n, m = gets.split.map &:to_i\nif n == m\n puts \"Second\"\nelse\n if [n, m].max == n\n puts \"First\"\n else\n puts \"Second\"\n end\nend"}, {"source_code": "n, m, a, b = gets.split().map(&:to_i)\nif n>m\n puts \"First\"\nelse\n puts \"Second\"\nend"}, {"source_code": "n1, n2, k1, k2 = gets.split.map(&:to_i)\n\nif n1 > n2\n puts 'First'\nelse\n puts 'Second'\nend\n"}, {"source_code": "n1,n2,k1,k2=gets.split.map{|e| e.to_i}\nif n1>n2 then\n\tputs \"First\"\nelse\n\tputs \"Second\"\nend"}, {"source_code": "n,m,k,l = gets.split.map(&:to_i)\nputs n > m ? 'First' : 'Second'"}, {"source_code": "#!/usr/bin/ruby\n\ninput_line = gets\n\nparams = input_line.split(' ')\nn1 = params[0].to_i\nn2 = params[1].to_i\nk1 = params[2].to_i\nk2 = params[3].to_i\n\nif (n1<=n2)\n puts 'Second'\nelse\n puts 'First'\nend\n"}, {"source_code": "n1, n2, k1, k2 = gets.split.map &:to_i\n\nputs (n1 > n2) ? \"First\" : \"Second\" \n"}, {"source_code": "s = gets.split(\" \").map { |e| e.to_i }\nputs \"First\" if s[0] > s[1]\nputs \"Second\" if s[0] <= s[1]"}, {"source_code": "nk = gets.chomp.split.map(&:to_i)\nn1 = nk[0]\nn2 = nk[1]\n\nif n1 <= n2\n\tprint \"Second\"\nelsif n1 > n2\n\tprint \"First\"\nend\n\t"}, {"source_code": "arr = $stdin.readline.split(\" \")\nn1= Float(\"#{arr[0]}\")\nn2 = Float(\"#{arr[1]}\")\nk1 = Float(\"#{arr[2]}\")\nk2 = Float(\"#{arr[3]}\")\nif (n2 + 1 > n1 ) \n puts \"Second\"\nelse \n puts \"First\"\nend"}, {"source_code": "arr = $stdin.readline.split(\" \")\nn1 = arr[0].to_i\nn2 = arr[1].to_i\nputs n2 + 1 > n1 ? 'Second' : 'First'"}, {"source_code": "arr = $stdin.readline.split(\" \")\nn1= arr[0].to_i\nn2 = arr[1].to_i\nif (n2 + 1 > n1 )\n puts \"Second\"\nelse\n puts \"First\"\nend"}, {"source_code": "a,b,c,d=gets.chomp.split.map &:to_i\nputs (a>b)? :First: :Second"}, {"source_code": "n1, n2, k1, k2 = gets.split.map(&:to_i)\nputs n1 > n2 ? \"First\" : \"Second\"\n"}, {"source_code": "input = gets.split(\" \")\nn1 = input[0].to_i\nn2 = input[1].to_i\nif n1 > n2\n puts \"First\"\nelse\n puts \"Second\"\nend\n"}, {"source_code": "n_1, n_2, k_1, k_2 = gets.split.map{|x| x.to_i}\nputs(n_1 > n_2 ? 'First' : 'Second')\n"}, {"source_code": "a , b , c ,d = gets.split.map {|i| i.to_i}\n\nif a > b\n puts \"First\"\nelse\n puts \"Second\"\nend"}, {"source_code": "pa=Array.new\nstr=gets.to_s\npa=str.split\nn1=pa[0].to_i\nn2=pa[1].to_i\nif n1<=n2\n puts \"Second\"\nelse\n puts \"First\"\nend"}, {"source_code": "a, b, c, d = gets.split.map{|i| i.to_i}\nputs a > b ? 'First' : 'Second'"}, {"source_code": "n1, n2 = *gets.split.map(&:to_i)\nputs n1 <= n2 ? \"Second\" : \"First\"\n"}, {"source_code": "n1, n2, k1, k2 = gets.split.map { |x| x.to_i }\nif n1 > n2\n\tputs 'First'\nelse\n\tputs 'Second'\nend"}], "negative_code": [{"source_code": "a, b = gets.strip.split\nputs a <= b ? \"Second\" : \"First\"\n"}, {"source_code": "# cook your code here\n\nn1,n2,k1,k2=gets.chomp.split\n\ncase n1<=>n2 \n when 0 \n print \"Second\";\n when 1 \n print \"First\";\n when -1 \n print \"Second\";\nend\n "}, {"source_code": "a,b,c,d=gets.split &:to_i\nputs (a>b)? :Second: :First"}, {"source_code": "a,b,c,d=gets.split &:to_i\nputs (a<=b)? :Second: :First"}, {"source_code": "a,b,c,d=gets.split &:to_i\nputs (a>b)? :First: :Second"}, {"source_code": "n_1, n_2, k_1, k_2 = gets.split\nputs(n_1 > n_2 ? 'First' : 'Second')\n"}, {"source_code": "pa=Array.new\nstr=gets.to_s\npa=str.split\nn1=pa[0]\nn2=pa[1]\nif n1<=n2\n puts \"Second\"\nelse\n puts \"First\"\nend"}], "src_uid": "aed24ebab3ed9fd1741eea8e4200f86b"} {"nl": {"description": "There are $$$b$$$ boys and $$$g$$$ girls participating in Olympiad of Metropolises. There will be a board games tournament in the evening and $$$n$$$ participants have accepted the invitation. The organizers do not know how many boys and girls are among them.Organizers are preparing red badges for girls and blue ones for boys.Vasya prepared $$$n+1$$$ decks of badges. The $$$i$$$-th (where $$$i$$$ is from $$$0$$$ to $$$n$$$, inclusive) deck contains $$$i$$$ blue badges and $$$n-i$$$ red ones. The total number of badges in any deck is exactly $$$n$$$.Determine the minimum number of decks among these $$$n+1$$$ that Vasya should take, so that there will be a suitable deck no matter how many girls and boys there will be among the participants of the tournament.", "input_spec": "The first line contains an integer $$$b$$$ ($$$1 \\le b \\le 300$$$), the number of boys. The second line contains an integer $$$g$$$ ($$$1 \\le g \\le 300$$$), the number of girls. The third line contains an integer $$$n$$$ ($$$1 \\le n \\le b + g$$$), the number of the board games tournament participants.", "output_spec": "Output the only integer, the minimum number of badge decks that Vasya could take.", "sample_inputs": ["5\n6\n3", "5\n3\n5"], "sample_outputs": ["4", "4"], "notes": "NoteIn the first example, each of 4 decks should be taken: (0 blue, 3 red), (1 blue, 2 red), (2 blue, 1 red), (3 blue, 0 red).In the second example, 4 decks should be taken: (2 blue, 3 red), (3 blue, 2 red), (4 blue, 1 red), (5 blue, 0 red). Piles (0 blue, 5 red) and (1 blue, 4 red) can not be used."}, "positive_code": [{"source_code": "b = gets.to_i\ng = gets.to_i\nn = gets.to_i\n\nans = 0\n(0..n).each do |bb|\n gg = n - bb\n ans += 1 if bb <= b && gg <= g\nend\nputs ans"}, {"source_code": "b = gets.to_i\ng = gets.to_i\nn = gets.to_i\n\ncnt=0\n\nif b>=n && g>=n\n cnt = n+1\nelsif b=n && g>=n\n cnt = n+1\nelse\n cnt = [b,g].min+1\nend\n\nputs cnt"}], "src_uid": "9266a69e767df299569986151852e7b1"} {"nl": {"description": "As you have noticed, there are lovely girls in Arpa\u2019s land.People in Arpa's land are numbered from 1 to n. Everyone has exactly one crush, i-th person's crush is person with the number crushi. Someday Arpa shouted Owf loudly from the top of the palace and a funny game started in Arpa's land. The rules are as follows.The game consists of rounds. Assume person x wants to start a round, he calls crushx and says: \"Oww...wwf\" (the letter w is repeated t times) and cuts off the phone immediately. If t\u2009>\u20091 then crushx calls crushcrushx and says: \"Oww...wwf\" (the letter w is repeated t\u2009-\u20091 times) and cuts off the phone immediately. The round continues until some person receives an \"Owf\" (t\u2009=\u20091). This person is called the Joon-Joon of the round. There can't be two rounds at the same time.Mehrdad has an evil plan to make the game more funny, he wants to find smallest t (t\u2009\u2265\u20091) such that for each person x, if x starts some round and y becomes the Joon-Joon of the round, then by starting from y, x would become the Joon-Joon of the round. Find such t for Mehrdad if it's possible.Some strange fact in Arpa's land is that someone can be himself's crush (i.e. crushi\u2009=\u2009i).", "input_spec": "The first line of input contains integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009100)\u00a0\u2014 the number of people in Arpa's land. The second line contains n integers, i-th of them is crushi (1\u2009\u2264\u2009crushi\u2009\u2264\u2009n)\u00a0\u2014 the number of i-th person's crush.", "output_spec": "If there is no t satisfying the condition, print -1. Otherwise print such smallest t.", "sample_inputs": ["4\n2 3 1 4", "4\n4 4 4 4", "4\n2 1 4 3"], "sample_outputs": ["3", "-1", "1"], "notes": "NoteIn the first sample suppose t\u2009=\u20093. If the first person starts some round:The first person calls the second person and says \"Owwwf\", then the second person calls the third person and says \"Owwf\", then the third person calls the first person and says \"Owf\", so the first person becomes Joon-Joon of the round. So the condition is satisfied if x is 1.The process is similar for the second and the third person.If the fourth person starts some round:The fourth person calls himself and says \"Owwwf\", then he calls himself again and says \"Owwf\", then he calls himself for another time and says \"Owf\", so the fourth person becomes Joon-Joon of the round. So the condition is satisfied when x is 4.In the last example if the first person starts a round, then the second person becomes the Joon-Joon, and vice versa."}, "positive_code": [{"source_code": "n = gets.to_i\np = gets.split.map(&:to_i).map{|x| x - 1}\n\nif p.uniq.size != n\n puts(-1)\n exit\nend\n\nls = []\nn.times do |i|\n x = p[i]\n len = 1\n until x == i\n x = p[x]\n len += 1\n end\n ls << len\nend\n\nans = 1\nls.each do |l|\n l /= 2 if l.even?\n ans = ans.lcm(l)\nend\nputs ans\n"}], "negative_code": [], "src_uid": "149221131a978298ac56b58438df46c9"} {"nl": {"description": "Grandma Laura came to the market to sell some apples. During the day she sold all the apples she had. But grandma is old, so she forgot how many apples she had brought to the market.She precisely remembers she had n buyers and each of them bought exactly half of the apples she had at the moment of the purchase and also she gave a half of an apple to some of them as a gift (if the number of apples at the moment of purchase was odd), until she sold all the apples she had.So each buyer took some integral positive number of apples, but maybe he didn't pay for a half of an apple (if the number of apples at the moment of the purchase was odd).For each buyer grandma remembers if she gave a half of an apple as a gift or not. The cost of an apple is p (the number p is even).Print the total money grandma should have at the end of the day to check if some buyers cheated her.", "input_spec": "The first line contains two integers n and p (1\u2009\u2264\u2009n\u2009\u2264\u200940,\u20092\u2009\u2264\u2009p\u2009\u2264\u20091000) \u2014 the number of the buyers and the cost of one apple. It is guaranteed that the number p is even. The next n lines contains the description of buyers. Each buyer is described with the string half if he simply bought half of the apples and with the string halfplus if grandma also gave him a half of an apple as a gift. It is guaranteed that grandma has at least one apple at the start of the day and she has no apples at the end of the day.", "output_spec": "Print the only integer a \u2014 the total money grandma should have at the end of the day. Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.", "sample_inputs": ["2 10\nhalf\nhalfplus", "3 10\nhalfplus\nhalfplus\nhalfplus"], "sample_outputs": ["15", "55"], "notes": "NoteIn the first sample at the start of the day the grandma had two apples. First she sold one apple and then she sold a half of the second apple and gave a half of the second apple as a present to the second buyer."}, "positive_code": [{"source_code": "#!/usr/bin/ruby\nn,p=gets.split.map(&:to_i)\nm=r=0\n$<.map(&:chomp).reverse.each{|e|\n\tm+=1 if e.end_with?('plus')\n\tr+=m*p/2\n\tm*=2\n}\np r"}, {"source_code": "n, p = gets.split(' ').map(&:to_i)\nrest = 0\nsum = 0\nrecords = []\n\nfor i in 1..n\n records.unshift(gets.to_s.chomp)\nend\n\nrecords.each do |record|\n if record == 'half'\n rest = rest * 2\n sum += rest * p / 2\n else\n rest = ( rest + 0.5 ) * 2\n sum += rest * p / 2\n end\n\nend\n\nputs sum.to_i"}, {"source_code": "a=gets.chomp.split(\" \")\npow=a[0].to_i\nprice=a[1].to_i\napple=0\nhalf=0\n0.upto(pow-1) do |i|\nk=gets.chomp\nif k.length!=4\napple=apple+2**i\nhalf+=1\nend\nend\n\nans=(apple-(0.5*half))*price\nputs \"#{ans.to_i}\""}, {"source_code": "n, p = gets.chomp.split.map(&:to_i)\napples = 1.0\ncom = []\nn.times do\n com << gets.chomp\nend\nhalfplus = 1\ncom.pop\ncom.reverse.each do |c|\n if c == \"halfplus\" then\n apples += 0.5\n apples *= 2\n halfplus += 1\n else\n apples *= 2\n end\nend\n\nputs ((apples - halfplus * 0.5) * p).to_i\n"}, {"source_code": "a=gets.chomp.split(\" \")\npow=a[0].to_i\nprice=a[1].to_i\napple=0\nhalf=0\n0.upto(pow-1) do |i|\nk=gets.chomp\nif k.length!=4\napple=apple+2**i\nhalf+=1\nend\nend\n\nans=(apple-(0.5*half))*price\nputs \"#{ans.to_i}\""}, {"source_code": "N, P = gets.split.map(&:to_i)\nA = N.times.map{ gets.chomp }\n\nx = A.reverse.reduce(0){|acc, a| (a == 'half') ? (acc * 2) : (acc * 2 + 1)}\n\nans = 0\nN.times do \n if x % 2 == 0\n ans += P * (x/2)\n else\n ans += P * (x/2) + P/2\n end\n x /= 2\nend\n\nputs ans"}], "negative_code": [], "src_uid": "6330891dd05bb70241e2a052f5bf5a58"} {"nl": {"description": "Ujan has been lazy lately, but now has decided to bring his yard to good shape. First, he decided to paint the path from his house to the gate.The path consists of $$$n$$$ consecutive tiles, numbered from $$$1$$$ to $$$n$$$. Ujan will paint each tile in some color. He will consider the path aesthetic if for any two different tiles with numbers $$$i$$$ and $$$j$$$, such that $$$|j - i|$$$ is a divisor of $$$n$$$ greater than $$$1$$$, they have the same color. Formally, the colors of two tiles with numbers $$$i$$$ and $$$j$$$ should be the same if $$$|i-j| > 1$$$ and $$$n \\bmod |i-j| = 0$$$ (where $$$x \\bmod y$$$ is the remainder when dividing $$$x$$$ by $$$y$$$).Ujan wants to brighten up space. What is the maximum number of different colors that Ujan can use, so that the path is aesthetic?", "input_spec": "The first line of input contains a single integer $$$n$$$ ($$$1 \\leq n \\leq 10^{12}$$$), the length of the path.", "output_spec": "Output a single integer, the maximum possible number of colors that the path can be painted in.", "sample_inputs": ["4", "5"], "sample_outputs": ["2", "5"], "notes": "NoteIn the first sample, two colors is the maximum number. Tiles $$$1$$$ and $$$3$$$ should have the same color since $$$4 \\bmod |3-1| = 0$$$. Also, tiles $$$2$$$ and $$$4$$$ should have the same color since $$$4 \\bmod |4-2| = 0$$$.In the second sample, all five colors can be used. "}, "positive_code": [{"source_code": "# https://codeforces.com/problemset/problem/1242/A\n\nrequire 'set'\n\nn = gets.to_i\n\ndividers = Set.new []\n\ni = 2\nsize = n\n\nwhile i * i <= n\n if n % i == 0\n dividers.add(i)\n n /= i\n i -= 1\n end\n i += 1\nend\n\ndividers.add(n) if n > 1 \n\narr = []\ndividers.each { |num| arr << num }\n\nif arr[0] == size\n puts size\nelsif arr.size == 1\n puts arr[0]\nelse\n puts 1\nend\n"}, {"source_code": "def inpf() a=gets.chomp.split(\" \").map(&:to_f)end\n\ndef inps() a=gets.chomp.split(\" \")end\n\ndef copy(a) Marshal.load(Marshal.dump(a)) end\n\ndef kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end\n\ndef na(n,d=0) Array.new(n,d)end\n\ndef na2(n,m,d=0) Array.new(n){Array.new(m,d)}end\n\ndef na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end\n\ndef inp() a=gets.chomp.split(\" \").map(&:to_i)end\n\ndef r_up(a, b) (a+b-1)/b end\n\ndef sum(a) a.inject(:+) end\n\nrequire 'prime'\nn = inp[0]\n\nd = Prime.prime_division(n)\nif(d.size == 1 )\n p d[0][0]\nelse\n p 1\nend"}], "negative_code": [{"source_code": "def inpf() a=gets.chomp.split(\" \").map(&:to_f)end\n\ndef inps() a=gets.chomp.split(\" \")end\n\ndef copy(a) Marshal.load(Marshal.dump(a)) end\n\ndef kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end\n\ndef na(n,d=0) Array.new(n,d)end\n\ndef na2(n,m,d=0) Array.new(n){Array.new(m,d)}end\n\ndef na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end\n\ndef inp() a=gets.chomp.split(\" \").map(&:to_i)end\n\ndef r_up(a, b) (a+b-1)/b end\n\ndef sum(a) a.inject(:+) end\n\nn = inp[0]\n(2..((n**0.5).ceil)).each do |d|\n if (n%d ==0)\n p d\n exit\n end\nend\np n\n"}, {"source_code": "def inpf() a=gets.chomp.split(\" \").map(&:to_f)end\n\ndef inps() a=gets.chomp.split(\" \")end\n\ndef copy(a) Marshal.load(Marshal.dump(a)) end\n\ndef kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end\n\ndef na(n,d=0) Array.new(n,d)end\n\ndef na2(n,m,d=0) Array.new(n){Array.new(m,d)}end\n\ndef na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end\n\ndef inp() a=gets.chomp.split(\" \").map(&:to_i)end\n\ndef r_up(a, b) (a+b-1)/b end\n\ndef sum(a) a.inject(:+) end\n\nn = inp[0]\n(2..((n**0.5).ceil)).each do |d|\n if (n%d ==0)\n if ( n/d == d)\n p d\n else\n p 1\n end\n exit\n end\nend\np n\n"}], "src_uid": "f553e89e267c223fd5acf0dd2bc1706b"} {"nl": {"description": "InputThe only line of input contains three integers a1,\u2009a2,\u2009a3 (1\u2009\u2264\u2009a1,\u2009a2,\u2009a3\u2009\u2264\u200920), separated by spaces.OutputOutput a single integer.ExamplesInput2 3 2Output5Input13 14 1Output14Input14 5 9Output464Input17 18 3Output53", "input_spec": "The only line of input contains three integers a1,\u2009a2,\u2009a3 (1\u2009\u2264\u2009a1,\u2009a2,\u2009a3\u2009\u2264\u200920), separated by spaces.", "output_spec": "Output a single integer.", "sample_inputs": ["2 3 2", "13 14 1", "14 5 9", "17 18 3"], "sample_outputs": ["5", "14", "464", "53"], "notes": null}, "positive_code": [{"source_code": "x,y,z=gets.split.map(&:to_i)\n(z-1).times{x,y=y,x+y}\np y"}, {"source_code": "a, b, c = gets.split.map(&:to_i)\nc.times do\n a, b = b, a + b\nend\np a\n"}, {"source_code": "x,y,z=gets.split.map(&:to_i)\n(z-1).times{x,y=y,x+y}\np y\n"}, {"source_code": "x,y,z=gets.split.map(&:to_i)\n(z-1).times{x,y=y,x+y}\np y"}, {"source_code": "x,y,z=gets.split.map(&:to_i)\n(z-1).times{x,y=y,x+y}\np y\n"}, {"source_code": "x,y,z=gets.split.map(&:to_i)\n(z-1).times{x,y=y,x+y}\np y\n"}, {"source_code": "x,y,z=gets.split.map(&:to_i)\n(z-1).times{x,y=y,x+y}\np y\n"}, {"source_code": "x,y,z=gets.split.map(&:to_i)\n(z-1).times{x,y=y,x+y}\np y"}, {"source_code": "x,y,z=gets.split.map(&:to_i)\n(z-1).times{x,y=y,x+y}\np y\n"}, {"source_code": "a=gets.split.map &:to_i;b=[a[0],a[1]];2.upto(a[2]){|x| b<19\n\tpmin=(Math.log(1000000007,n)).ceil\n\tpc=p/pmin\n\tpl=p%pmin\n\treturn ((MOD((n**pmin % 1000000007),pc) * (n**pl) ) % 1000000007)\n\telse\n\treturn (n**p)%1000000007\n\tend\n\tend\n\t\n\tc=(MOD(3,3*p)- MOD(7,p))% 1000000007\n\tputs \"#{c}\""}, {"source_code": "n = gets.chomp.to_i\ndp1, dp2 = 20, 7\nmod = 1000000007\n(n - 1).times {\n dp1, dp2 = (dp1 * 27 + dp2 * 20) % mod, dp2 * 7 % mod \n}\nputs dp1\n"}, {"source_code": "n = gets.chomp.to_i\nputs (3 ** (3 * n) - 7 ** n) % 1_000_000_007\n"}, {"source_code": "p=gets.chomp.to_i\ndef MOD (n,p)\n\tif p>19\n\tpmin=(Math.log(1000000007,n)).ceil\n\tpc=p/pmin\n\tpl=p%pmin\n\treturn ((MOD((n**pmin % 1000000007),pc) * (n**pl) ) % 1000000007)\n\telse\n\treturn (n**p)%1000000007\n\tend\n\tend\n\t\n\tc=(MOD(3,3*p)- MOD(7,p))% 1000000007\n\tputs \"#{c}\""}, {"source_code": "Mod = (1e9 + 7).to_i\n\nn = gets.to_i\n\nans1 = 1\nans2 = 1\n\nn.times do\n\tans1 *= 27\n\tans2 *= 7\n\n\tans1 %= Mod\n\tans2 %= Mod\nend\n\nans = (ans1 - ans2 + Mod) % Mod\nputs ans\n"}], "negative_code": [], "src_uid": "eae87ec16c284f324d86b7e65fda093c"} {"nl": {"description": "You are given an alphabet consisting of n letters, your task is to make a string of the maximum possible length so that the following conditions are satisfied: the i-th letter occurs in the string no more than ai times; the number of occurrences of each letter in the string must be distinct for all the letters that occurred in the string at least once. ", "input_spec": "The first line of the input contains a single integer n (2\u2009\u2009\u2264\u2009\u2009n\u2009\u2009\u2264\u2009\u200926)\u00a0\u2014 the number of letters in the alphabet. The next line contains n integers ai (1\u2009\u2264\u2009ai\u2009\u2264\u2009109)\u00a0\u2014 i-th of these integers gives the limitation on the number of occurrences of the i-th character in the string.", "output_spec": "Print a single integer \u2014 the maximum length of the string that meets all the requirements.", "sample_inputs": ["3\n2 5 5", "3\n1 1 2"], "sample_outputs": ["11", "3"], "notes": "NoteFor convenience let's consider an alphabet consisting of three letters: \"a\", \"b\", \"c\". In the first sample, some of the optimal strings are: \"cccaabbccbb\", \"aabcbcbcbcb\". In the second sample some of the optimal strings are: \"acc\", \"cbc\"."}, "positive_code": [{"source_code": "n = gets.to_i\na = gets.split(\" \").map(&:to_i).sort.reverse\nx = a[0]\nans = 0\na.each do |k|\n k = [k, x].min\n ans += k\n x = k-1\n break if x == 0\nend\np ans\n"}, {"source_code": "def function\nb=gets.chomp\na=gets.chomp\na=a.split(' ').map(&:to_i).sort.reverse\n1.upto a.length do |i|\nif a[0..i-1].include?(a[i])\na[i]=a[i-1]-1\nend\nend\nsum=0\na.each do |i|\nif i>0\nsum+=i\nend\nend\nputs sum\nend\nfunction"}, {"source_code": "gets\nh={}\ngets.split.map(&:to_i).each{|e| h[e] ? h[e]+=1 : h[e]=1}\nf=->(n){n*(n+1)/2}\nres=0\nx=10**9*2\nh.sort.reverse.each{|k,v|\n a=f[x=[k, x].min]\n b=f[[x-v, 0].max]\n res+=a-b\n x=[x-v, 0].max\n}\nputs res\n"}, {"source_code": "n = gets.chomp.to_i\nas = gets.chomp.split.map(&:to_i)\nans = 0\n\nas.sort!.reverse!\nb = as[0]\nas.each do |a|\n ans += [a, b].min\n b = [[a - 1, b - 1].min, 0].max\nend\n\nputs ans\n"}, {"source_code": "gets\na=gets.split.map &:to_i\nh = {}\na.sort.each{|x|\n x -= 1 while h[x]\n h[x] = true\n}\np h.map{|k,v|[k,0].max}.inject :+\n"}, {"source_code": "n = gets.to_i\na = gets.split(' ').map &:to_i\nr = []\nfor v in a\n while r.index(v) && v > 0\n v-=1\n end\n\n r << v\nend\n\nputs r.inject(&:+)"}, {"source_code": "class Solver\n\tdef main\n\t\tn = gets.to_i\n\t\tarr = gets.split.map { |x| x.to_i }\n\t\tarr = arr.sort.reverse\n\n\t\tans = 0\n\t\tlast = 1 << 30\n\t\tarr.each do |x|\n\t\t\tx = last - 1 if x >= last\n\t\t\tans += x if x >= 0\n\t\t\tlast = x\n\t\tend\n\t\tputs ans\n\tend\nend\nSolver.new.main"}], "negative_code": [{"source_code": "def function\nb=gets.chomp\na=gets.chomp\na=a.split(' ').map(&:to_i).sort.reverse\nb=a.clone\n1.upto a.length do |i|\nif a[i]==a[i-1]\nb[i]-=1\nend\nend\nsum=0\nb.each do |i|\nsum+=i\nend\nputs sum\nend\nfunction"}, {"source_code": "gets\na=gets.split.map &:to_i\nh = {}\na.sort.each{|x|\n x -= 1 while h[x]\n h[x] = true\n}\nif h[-1]\n p 0\nelse\n p h.map{|k,v|k}.inject :+\nend\n"}, {"source_code": "gets\na=gets.split.map &:to_i\nh = {}\na.sort.each{|x|\n x -= 1 while h[x]\n h[x] = true\n}\nif h.find 0\n p 0\nelse\n p h.map{|k,v|k}.inject :+\nend\n"}, {"source_code": "n = gets.to_i\na = gets.split(' ').map &:to_i\nr = []\nbroken = false\nfor v in a\n while r.index(v)\n v-=1\n end\n if v >= 0\n r << v\n else\n r = [0]\n break\n end\nend\n\nputs r.inject(&:+)"}], "src_uid": "3c4b2d1c9440515bc3002eddd2b89f6f"} {"nl": {"description": "The dragon and the princess are arguing about what to do on the New Year's Eve. The dragon suggests flying to the mountains to watch fairies dancing in the moonlight, while the princess thinks they should just go to bed early. They are desperate to come to an amicable agreement, so they decide to leave this up to chance.They take turns drawing a mouse from a bag which initially contains w white and b black mice. The person who is the first to draw a white mouse wins. After each mouse drawn by the dragon the rest of mice in the bag panic, and one of them jumps out of the bag itself (the princess draws her mice carefully and doesn't scare other mice). Princess draws first. What is the probability of the princess winning?If there are no more mice in the bag and nobody has drawn a white mouse, the dragon wins. Mice which jump out of the bag themselves are not considered to be drawn (do not define the winner). Once a mouse has left the bag, it never returns to it. Every mouse is drawn from the bag with the same probability as every other one, and every mouse jumps out of the bag with the same probability as every other one.", "input_spec": "The only line of input data contains two integers w and b (0\u2009\u2264\u2009w,\u2009b\u2009\u2264\u20091000).", "output_spec": "Output the probability of the princess winning. The answer is considered to be correct if its absolute or relative error does not exceed 10\u2009-\u20099.", "sample_inputs": ["1 3", "5 5"], "sample_outputs": ["0.500000000", "0.658730159"], "notes": "NoteLet's go through the first sample. The probability of the princess drawing a white mouse on her first turn and winning right away is 1/4. The probability of the dragon drawing a black mouse and not winning on his first turn is 3/4 * 2/3 = 1/2. After this there are two mice left in the bag \u2014 one black and one white; one of them jumps out, and the other is drawn by the princess on her second turn. If the princess' mouse is white, she wins (probability is 1/2 * 1/2 = 1/4), otherwise nobody gets the white mouse, so according to the rule the dragon wins."}, "positive_code": [{"source_code": "\nw,b=gets.split.map(&:to_i)\n$dp=Array.new(1002){Array.new(1002){Array.new(2,-1)}}\n#t=0 \u59eb t=1 \u30c9\u30e9\u30b4\u30f3\ndef solve(w,b,t)\n return 0 if b<0 || w<0\n return 0 if w+b==0\n return $dp[w][b][t] if $dp[w][b][t]>=0\n res=0.0\n if t==0 then\n res+=w.to_f/(w+b)\n res+=b.to_f/(w+b)*solve(w,b-1,1-t)\n else\n #W\u3092\u53d6\u308b\n res=0\n #B\u3092\u53d6\u308b\n tb=b-1\n tw=w\n if tb+tw==0 then\n res=0\n else\n res+=b.to_f/(w+b)*tb.to_f/(tb+tw)*solve(w,b-2,1-t)\n res+=b.to_f/(w+b)*tw.to_f/(tb+tw)*solve(w-1,b-1,1-t)\n end\n end\n return $dp[w][b][t]=res\nend\np solve(w,b,0)\n"}, {"source_code": "Memo = {}# Array.new(1001*1001)\n\ndef f(w, b)\n return 0 if w==0\n ix = w*1001 + b\n return Memo[ix] if Memo[ix]\n res = 1.0*w/(w+b)\n if b>1\n m = 1.0*b*(b-1)/(w+b)/(w+b-1)\n wr = 1.0*w/(w+b-2)\n wp = f(w-1, b-2)\n br = 1.0-wr\n bp = 0\n bp = f(w, b-3) if b>2\n res += m * (wr*wp + br*bp)\n end\n Memo[ix] = res\n #puts \"for w=#{w} b=#{b}: #{res}\"\n res\nend\n\nw,b = readline.split(' ').map(&:to_i)\nputs f(w,b)\n"}, {"source_code": "Memo = Array.new(1001*1001)\n\ndef f(w, b)\n return 0 if w==0\n ix = w*1001 + b\n return Memo[ix] if Memo[ix]\n res = 1.0*w/(w+b)\n if b>1\n m = 1.0*b*(b-1)/(w+b)/(w+b-1)\n wr = 1.0*w/(w+b-2)\n wp = f(w-1, b-2)\n br = 1.0-wr\n bp = 0\n bp = f(w, b-3) if b>2\n res += m * (wr*wp + br*bp)\n end\n Memo[ix] = res\n #puts \"for w=#{w} b=#{b}: #{res}\"\n res\nend\n\nw,b = readline.split(' ').map(&:to_i)\nputs f(w,b)\n"}], "negative_code": [], "src_uid": "7adb8bf6879925955bf187c3d05fde8c"} {"nl": {"description": "Paul is at the orchestra. The string section is arranged in an r\u2009\u00d7\u2009c rectangular grid and is filled with violinists with the exception of n violists. Paul really likes violas, so he would like to take a picture including at least k of them. Paul can take a picture of any axis-parallel rectangle in the orchestra. Count the number of possible pictures that Paul can take.Two pictures are considered to be different if the coordinates of corresponding rectangles are different.", "input_spec": "The first line of input contains four space-separated integers r, c, n, k (1\u2009\u2264\u2009r,\u2009c,\u2009n\u2009\u2264\u20093000, 1\u2009\u2264\u2009k\u2009\u2264\u2009min(n,\u200910))\u00a0\u2014 the number of rows and columns of the string section, the total number of violas, and the minimum number of violas Paul would like in his photograph, respectively. The next n lines each contain two integers xi and yi (1\u2009\u2264\u2009xi\u2009\u2264\u2009r, 1\u2009\u2264\u2009yi\u2009\u2264\u2009c): the position of the i-th viola. It is guaranteed that no location appears more than once in the input.", "output_spec": "Print a single integer\u00a0\u2014 the number of photographs Paul can take which include at least k violas. ", "sample_inputs": ["2 2 1 1\n1 2", "3 2 3 3\n1 1\n3 1\n2 2", "3 2 3 2\n1 1\n3 1\n2 2"], "sample_outputs": ["4", "1", "4"], "notes": "NoteWe will use '*' to denote violinists and '#' to denote violists.In the first sample, the orchestra looks as follows: *#** Paul can take a photograph of just the viola, the 1\u2009\u00d7\u20092 column containing the viola, the 2\u2009\u00d7\u20091 row containing the viola, or the entire string section, for 4 pictures total.In the second sample, the orchestra looks as follows: #**##* Paul must take a photograph of the entire section.In the third sample, the orchestra looks the same as in the second sample."}, "positive_code": [{"source_code": "l1 = gets.chomp\nvals1 = l1.split(' ').map {|x| x.to_i}\n\nr = vals1[0]\nc = vals1[1]\nn = vals1[2]\nk = vals1[3]\n\nviolas = []\ncolumns = []\nc.times {|x| columns << 0}\nr.times {|x| col = []; c.times {|y| col << 0}; violas << col }\nminx = r\nminy = c\nmaxx = -1\nmaxy = -1\nn.times {\n indices = gets.chomp.split(' ').map {|x| x.to_i - 1}\n violas[indices[0]][indices[1]] = 1\n minx = indices[1] if indices[1] < minx\n miny = indices[0] if indices[0] < miny\n maxx = indices[1] if indices[1] > maxx\n maxy = indices[0] if indices[0] > maxy\n}\n\nRect = Struct.new(:x, :y, :x2, :y2)\n\nrectangles = []\n(0..r-1).each do |y|\n (0..c-1).each do |x|\n (y..r-1).each do |y2|\n (x..c-1).each do |x2|\n v = 0\n (y..y2).each do |yi|\n (x..x2).each do |xi|\n v += violas[yi][xi]\n end\n end\n if v >= k\n rectangles << Rect.new(x, y, x2, y2) unless rectangles.any? {|r|\n r.x == x && r.y == y && r.x2 == x2 && r.y2 == y2\n }\n end\n end\n end\n end\nend\nputs rectangles.length\n"}, {"source_code": "#!/usr/bin/ruby\nr,c,n,k=gets.split.map(&:to_i)\nm=(r+1).times.map{[0]*(c+1)}\nn.times{\n\ta,b=gets.split.map(&:to_i)\n\tm[a][b]=1\n}\n(r+1).times{|i|c.times{|j|m[i][j+1]+=m[i][j]}}\nr.times{|i|(c+1).times{|j|m[i+1][j]+=m[i][j]}}\nx=0\nr.times{|i0|c.times{|j0|(i0+1).step(r){|i1|(j0+1).step(c){|j1|\n\tx+=1 if k<=m[i0][j0]-m[i0][j1]-m[i1][j0]+m[i1][j1]\n}}}}\np x"}, {"source_code": "r, c, n, k = gets.split.map(&:to_i)\npos = n.times.map{gets.split.map(&:to_i)}\n\nphotos = 0\nfor top in 1..r do\n for left in 1..c do\n for down in top..r do\n for right in left..c do\n alts = pos.count do |x, y|\n x >= top && x <= down && y >= left && y <= right\n end\n photos += 1 if alts >= k\n end\n end\n end\nend\nputs photos"}, {"source_code": "buf = gets.split(' ')\nr,c,n,k = buf[0].to_i, buf[1].to_i, buf[2].to_i, buf[3].to_i\na=Array.new(22)\nfor i in 0..r\n\ta[i]=Array.new(22, 0)\nend\nfor i in 1..n\n\tbuf = gets.split(' ')\n\tx, y = buf[0].to_i, buf[1].to_i\n\ta[x][y]=1\nend\nfor i in 1..r\n\tfor j in 1..c\n\t\ta[i][j]+=a[i-1][j]+a[i][j-1]-a[i-1][j-1]\n\tend\nend\nans=0\nfor x1 in 1..r\n\tfor y1 in 1..c\n\t\tfor x2 in x1..r\n\t\t\tfor y2 in y1..c\n\t\t\t\ttot = a[x2][y2]-a[x1-1][y2]-a[x2][y1-1]+a[x1-1][y1-1]\n\t\t\t\tans+=1 if tot>=k\n\t\t\tend\n\t\tend\n\tend\nend\nputs ans"}], "negative_code": [], "src_uid": "9c766881f6415e2f53fb43b61f8f40b4"} {"nl": {"description": "Masha lives in a multi-storey building, where floors are numbered with positive integers. Two floors are called adjacent if their numbers differ by one. Masha decided to visit Egor. Masha lives on the floor $$$x$$$, Egor on the floor $$$y$$$ (not on the same floor with Masha).The house has a staircase and an elevator. If Masha uses the stairs, it takes $$$t_1$$$ seconds for her to walk between adjacent floors (in each direction). The elevator passes between adjacent floors (in each way) in $$$t_2$$$ seconds. The elevator moves with doors closed. The elevator spends $$$t_3$$$ seconds to open or close the doors. We can assume that time is not spent on any action except moving between adjacent floors and waiting for the doors to open or close. If Masha uses the elevator, it immediately goes directly to the desired floor.Coming out of the apartment on her floor, Masha noticed that the elevator is now on the floor $$$z$$$ and has closed doors. Now she has to choose whether to use the stairs or use the elevator. If the time that Masha needs to get to the Egor's floor by the stairs is strictly less than the time it will take her using the elevator, then she will use the stairs, otherwise she will choose the elevator.Help Mary to understand whether to use the elevator or the stairs.", "input_spec": "The only line contains six integers $$$x$$$, $$$y$$$, $$$z$$$, $$$t_1$$$, $$$t_2$$$, $$$t_3$$$ ($$$1 \\leq x, y, z, t_1, t_2, t_3 \\leq 1000$$$)\u00a0\u2014 the floor Masha is at, the floor Masha wants to get to, the floor the elevator is located on, the time it takes Masha to pass between two floors by stairs, the time it takes the elevator to pass between two floors and the time it takes for the elevator to close or open the doors. It is guaranteed that $$$x \\ne y$$$.", "output_spec": "If the time it will take to use the elevator is not greater than the time it will take to use the stairs, print \u00abYES\u00bb (without quotes), otherwise print \u00abNO> (without quotes). You can print each letter in any case (upper or lower).", "sample_inputs": ["5 1 4 4 2 1", "1 6 6 2 1 1", "4 1 7 4 1 2"], "sample_outputs": ["YES", "NO", "YES"], "notes": "NoteIn the first example:If Masha goes by the stairs, the time she spends is $$$4 \\cdot 4 = 16$$$, because she has to go $$$4$$$ times between adjacent floors and each time she spends $$$4$$$ seconds. If she chooses the elevator, she will have to wait $$$2$$$ seconds while the elevator leaves the $$$4$$$-th floor and goes to the $$$5$$$-th. After that the doors will be opening for another $$$1$$$ second. Then Masha will enter the elevator, and she will have to wait for $$$1$$$ second for the doors closing. Next, the elevator will spend $$$4 \\cdot 2 = 8$$$ seconds going from the $$$5$$$-th floor to the $$$1$$$-st, because the elevator has to pass $$$4$$$ times between adjacent floors and spends $$$2$$$ seconds each time. And finally, it will take another $$$1$$$ second before the doors are open and Masha can come out. Thus, all the way by elevator will take $$$2 + 1 + 1 + 8 + 1 = 13$$$ seconds, which is less than $$$16$$$ seconds, so Masha has to choose the elevator.In the second example, it is more profitable for Masha to use the stairs, because it will take $$$13$$$ seconds to use the elevator, that is more than the $$$10$$$ seconds it will takes to go by foot.In the third example, the time it takes to use the elevator is equal to the time it takes to walk up by the stairs, and is equal to $$$12$$$ seconds. That means Masha will take the elevator."}, "positive_code": [{"source_code": "x,y,z,a,b,c=gets.split.map &:to_i\nd=(x-y).abs\nputs d*a<((x-z).abs+d)*b+3*c ? :No : :Yes"}, {"source_code": "\ndef solution\n x, y, z, stairs, elv, elv_doors = read_ints\n\n elv_time = ((z-x).abs + (x-y).abs) * elv + elv_doors * 3\n stair_time = (y-x).abs * stairs\n\n puts elv_time <= stair_time ? \"YES\" : \"NO\"\n\nend\n\ndef read_int\n gets.to_i\nend\n\ndef read_ints\n gets.split.map(&:to_i)\nend\n\ndef read_string\n gets.chomp\nend\n\nsolution unless ENV['TEST__MODE']\n\n"}, {"source_code": "class A\n def self.run(s)\n x, y, z, t1, t2, t3 = s.split.map(&:to_i)\n walk = (x-y).abs * t1\n lift = (x-z).abs * t2 + t3*2 + (x-y).abs * t2 + t3\n if lift <= walk\n true\n else\n false\n end\n end\nend\n\n\nif A.run(gets.chomp)\n puts 'YES'\nelse\n puts 'NO'\nend\n"}, {"source_code": "x,y,z,t1,t2,t3 = gets.split.map { |e| Integer(e) }\nstair = t1 * (x - y).abs\nelevator = t2 * (z - x).abs + t3*2 + t2*(x-y).abs + t3\nputs (if elevator <= stair then \"YES\" else \"NO\" end)"}, {"source_code": "x, y, z, t1, t2, t3 = gets.split.map(&:to_i)\n\nfoot = (x-y).abs * t1\nev = (x-z).abs*t2+(x-y).abs*t2+t3*3\n\nif foot < ev\n puts 'NO'\nelse\n puts 'YES'\nend\n"}, {"source_code": "line = gets.chomp\n\nx, y, z, t1, t2, t3 = line.split.map(&:to_i)\n\nelevator_time = ( (z-x).abs + (x-y).abs ) * t2 + 3 * t3\nstair_time = (y-x).abs * t1\n\n# puts elevator_time\n# puts stair_time\n\nif stair_time >= elevator_time\n puts \"YES\"\nelse\n puts \"NO\"\nend"}, {"source_code": "x, y, z, t1, t2, t3 = gets.split.map &:to_i\nputs ((x - y).abs + (x - z).abs)*t2 + 3*t3 <= (x - y).abs*t1 ? 'YES' : 'NO'\n"}, {"source_code": "xyzts = gets.chomp.split(\" \").map(&:to_i)\n\nx = xyzts[0]\ny = xyzts[1]\nz = xyzts[2]\nt1 = xyzts[3]\nt2 = xyzts[4]\nt3 = xyzts[5]\n\nst = (x-y).abs*t1\net = (x-z).abs*t2 + 3*t3 + (x-y).abs*t2\n\nif et<=st\n puts \"YES\"\nelse\n puts \"NO\"\nend\n"}], "negative_code": [], "src_uid": "05cffd59b28b9e026ca3203718b2e6ca"} {"nl": {"description": "Alice has a lovely piece of cloth. It has the shape of a square with a side of length $$$a$$$ centimeters. Bob also wants such piece of cloth. He would prefer a square with a side of length $$$b$$$ centimeters (where $$$b < a$$$). Alice wanted to make Bob happy, so she cut the needed square out of the corner of her piece and gave it to Bob. Now she is left with an ugly L shaped cloth (see pictures below).Alice would like to know whether the area of her cloth expressed in square centimeters is prime. Could you help her to determine it?", "input_spec": "The first line contains a number $$$t$$$\u00a0($$$1 \\leq t \\leq 5$$$)\u00a0\u2014 the number of test cases. Each of the next $$$t$$$ lines describes the $$$i$$$-th test case. It contains two integers $$$a$$$ and $$$b~(1 \\leq b < a \\leq 10^{11})$$$\u00a0\u2014 the side length of Alice's square and the side length of the square that Bob wants.", "output_spec": "Print $$$t$$$ lines, where the $$$i$$$-th line is the answer to the $$$i$$$-th test case. Print \"YES\" (without quotes) if the area of the remaining piece of cloth is prime, otherwise print \"NO\". You can print each letter in an arbitrary case (upper or lower).", "sample_inputs": ["4\n6 5\n16 13\n61690850361 24777622630\n34 33"], "sample_outputs": ["YES\nNO\nNO\nYES"], "notes": "NoteThe figure below depicts the first test case. The blue part corresponds to the piece which belongs to Bob, and the red part is the piece that Alice keeps for herself. The area of the red part is $$$6^2 - 5^2 = 36 - 25 = 11$$$, which is prime, so the answer is \"YES\". In the second case, the area is $$$16^2 - 13^2 = 87$$$, which is divisible by $$$3$$$. In the third case, the area of the remaining piece is $$$61690850361^2 - 24777622630^2 = 3191830435068605713421$$$. This number is not prime because $$$3191830435068605713421 = 36913227731 \\cdot 86468472991 $$$.In the last case, the area is $$$34^2 - 33^2 = 67$$$."}, "positive_code": [{"source_code": "#ruby 2.4.1 \n\nrequire \"prime\"\nt = gets.to_i\nt.times do |a, b|\n\tflag = false\n\tnums = \"\"\n\tnums = gets\n\ta1, b1 = nums.split(' ')\n\ta = a1.to_i\n\tb = b1.to_i\n\tif Prime.prime?(a + b) == true && (a + b) * (a - b) == (a + b)\n\t\tputs \"YES\"\n\telse\n\t\tputs \"NO\"\n\tend\nend"}], "negative_code": [{"source_code": "#ruby 2.4.1 \n\nrequire \"prime\"\nt = gets.to_i\nt.times do |a, b|\n\tflag = false\n\tnums = \"\"\n\tnums = gets\n\ta1, b1 = nums.split(' ')\n\ta = a1.to_i\n\tb = b1.to_i\n\tif ((a-b)*(a+b)) == (a + b)\n\t\tputs \"YES\"\n\telse\n\t\tputs \"NO\"\n\tend\nend"}], "src_uid": "5a052e4e6c64333d94c83df890b1183c"} {"nl": {"description": "There is a legend in the IT City college. A student that failed to answer all questions on the game theory exam is given one more chance by his professor. The student has to play a game with the professor.The game is played on a square field consisting of n\u2009\u00d7\u2009n cells. Initially all cells are empty. On each turn a player chooses and paint an empty cell that has no common sides with previously painted cells. Adjacent corner of painted cells is allowed. On the next turn another player does the same, then the first one and so on. The player with no cells to paint on his turn loses.The professor have chosen the field size n and allowed the student to choose to be the first or the second player in the game. What should the student choose to win the game? Both players play optimally.", "input_spec": "The only line of the input contains one integer n (1\u2009\u2264\u2009n\u2009\u2264\u20091018) \u2014 the size of the field.", "output_spec": "Output number 1, if the player making the first turn wins when both players play optimally, otherwise print number 2.", "sample_inputs": ["1", "2"], "sample_outputs": ["1", "2"], "notes": null}, "positive_code": [{"source_code": "# cook your code here\n\nn = gets.chomp \n\nif (n[-1].to_i)%2==0 \n puts \"2\"\nelse \n puts \"1\" \nend "}, {"source_code": "n = gets.chomp.to_i\nputs n % 2 == 0 ? 2 : 1"}, {"source_code": "p 2-gets.to_i%2"}, {"source_code": "p 2-gets.to_i%2"}, {"source_code": "p 2-gets.to_i%2"}, {"source_code": "p 2-gets.to_i%2\n"}], "negative_code": [{"source_code": "p 2-gets.to_i"}], "src_uid": "816ec4cd9736f3113333ef05405b8e81"} {"nl": {"description": "Since Grisha behaved well last year, at New Year's Eve he was visited by Ded Moroz who brought an enormous bag of gifts with him! The bag contains n sweet candies from the good ol' bakery, each labeled from 1 to n corresponding to its tastiness. No two candies have the same tastiness.The choice of candies has a direct effect on Grisha's happiness. One can assume that he should take the tastiest ones\u00a0\u2014 but no, the holiday magic turns things upside down. It is the xor-sum of tastinesses that matters, not the ordinary sum!A xor-sum of a sequence of integers a1,\u2009a2,\u2009...,\u2009am is defined as the bitwise XOR of all its elements: , here denotes the bitwise XOR operation; more about bitwise XOR can be found here.Ded Moroz warned Grisha he has more houses to visit, so Grisha can take no more than k candies from the bag. Help Grisha determine the largest xor-sum (largest xor-sum means maximum happiness!) he can obtain.", "input_spec": "The sole string contains two integers n and k (1\u2009\u2264\u2009k\u2009\u2264\u2009n\u2009\u2264\u20091018).", "output_spec": "Output one number\u00a0\u2014 the largest possible xor-sum.", "sample_inputs": ["4 3", "6 6"], "sample_outputs": ["7", "7"], "notes": "NoteIn the first sample case, one optimal answer is 1, 2 and 4, giving the xor-sum of 7.In the second sample case, one can, for example, take all six candies and obtain the xor-sum of 7."}, "positive_code": [{"source_code": "n,k=gets.split.map &:to_i\np k==1 ? n : 2**n.to_s(2).size-1"}, {"source_code": "#!/usr/bin/ruby\ninclude Math\n\nn, k = gets.split().map(&:to_i)\n\nif k == 1 then\n\tputs n\nelse\n\tputs (1 << n.to_s(2).length) - 1\nend\n\n"}, {"source_code": "#!/usr/bin/ruby\ninclude Math\n\nn, k = readline().split().map(&:to_i)\n\nif k == 1 then\n\tputs n\nelse\n\tputs (1 << n.to_s(2).length) - 1\nend\n\n"}, {"source_code": "x = gets.chomp.split(' ')\nn = x[0].to_i\nk = x[1].to_i\nif k == 1\n puts n\nelse\n ans = 0\n i = 0\n while 2**i <= n\n ans += 2 ** i\n i += 1\n end\n puts ans\nend"}], "negative_code": [], "src_uid": "16bc089f5ef6b68bebe8eda6ead2eab9"} {"nl": {"description": "Everybody knows of spaghetti sort. You decided to implement an analog sorting algorithm yourself, but as you survey your pantry you realize you're out of spaghetti! The only type of pasta you have is ravioli, but you are not going to let this stop you...You come up with the following algorithm. For each number in the array ai, build a stack of ai ravioli. The image shows the stack for ai\u2009=\u20094. Arrange the stacks in one row in the order in which the corresponding numbers appear in the input array. Find the tallest one (if there are several stacks of maximal height, use the leftmost one). Remove it and add its height to the end of the output array. Shift the stacks in the row so that there is no gap between them. Repeat the procedure until all stacks have been removed.At first you are very happy with your algorithm, but as you try it on more inputs you realize that it doesn't always produce the right sorted array. Turns out when two stacks of ravioli are next to each other (at any step of the process) and differ in height by two or more, the top ravioli of the taller stack slides down on top of the lower stack.Given an input array, figure out whether the described algorithm will sort it correctly.", "input_spec": "The first line of input contains a single number n (1\u2009\u2264\u2009n\u2009\u2264\u200910) \u2014 the size of the array. The second line of input contains n space-separated integers ai (1\u2009\u2264\u2009ai\u2009\u2264\u2009100) \u2014 the elements of the array.", "output_spec": "Output \"YES\" if the array can be sorted using the described procedure and \"NO\" if it can not.", "sample_inputs": ["3\n1 2 3", "3\n3 1 2"], "sample_outputs": ["YES", "NO"], "notes": "NoteIn the second example the array will change even before the tallest stack is chosen for the first time: ravioli from stack of height 3 will slide on the stack of height 1, and the algorithm will output an array {2,\u20092,\u20092}."}, "positive_code": [{"source_code": "n,*a=$<.read.split.map &:to_i\nputs a.each_cons(2).all?{|x,y|(x-y).abs<2} ? :YES : :NO"}, {"source_code": "gets\nputs (gets.split.map(&:to_i).each_cons(2).any? { |a| (a[0] - a[1]).abs > 1 } ? :NO : :YES)\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\n\nbad = false\n1.upto(n - 1){|i|\n if (a[i] - a[i-1]).abs >= 2 then\n bad = true;\n end\n}\n\n\nif bad then\n puts \"NO\"\nelse\n puts \"YES\"\nend"}], "negative_code": [], "src_uid": "704d0ae50bccaa8bc49319812ae0be45"} {"nl": {"description": "Polycarpus has got n candies and m friends (n\u2009\u2265\u2009m). He wants to make a New Year present with candies to each friend. Polycarpus is planning to present all candies and he wants to do this in the fairest (that is, most equal) manner. He wants to choose such ai, where ai is the number of candies in the i-th friend's present, that the maximum ai differs from the least ai as little as possible.For example, if n is divisible by m, then he is going to present the same number of candies to all his friends, that is, the maximum ai won't differ from the minimum one.", "input_spec": "The single line of the input contains a pair of space-separated positive integers n, m (1\u2009\u2264\u2009n,\u2009m\u2009\u2264\u2009100;n\u2009\u2265\u2009m) \u2014 the number of candies and the number of Polycarpus's friends.", "output_spec": "Print the required sequence a1,\u2009a2,\u2009...,\u2009am, where ai is the number of candies in the i-th friend's present. All numbers ai must be positive integers, total up to n, the maximum one should differ from the minimum one by the smallest possible value.", "sample_inputs": ["12 3", "15 4", "18 7"], "sample_outputs": ["4 4 4", "3 4 4 4", "2 2 2 3 3 3 3"], "notes": "NotePrint ai in any order, separate the numbers by spaces."}, "positive_code": [{"source_code": "#!/usr/bin/ruby\nn,m=gets.split.map(&:to_i)\nputs m.times.map{|i|n/m+(i'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']\n \ndef inpf() a=gets.chomp.split(\" \").map(&:to_f)end\n \ndef inps() a=gets.chomp.split(\" \")end\n \ndef copy(a) Marshal.load(Marshal.dump(a)) end\n \ndef kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end\n \ndef na(n,d=0) Array.new(n,d)end\n \ndef na2(n,m,d=0) Array.new(n){Array.new(m,d)}end\n \ndef na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end\n \ndef inp() a=gets.chomp.split(\" \").map(&:to_i)end\n \ndef r_up(a, b) (a+b-1)/b end\n \ndef r_sort(a) a.sort{|a,b|b<=>a} end\n \nt = []\nn , p = inp\nmin = 9999999\n50.times do|i|\n cn = n-i*p\n break if(cn <= 0)\n c = cn.to_s(2).count(\"1\")\n chib = i - c\n if(chib >= 0 and chib < cn)\n min = [min, i ].min\n end\nend\nif(min > 999)\n puts -1\nelse\n puts min\nend"}], "negative_code": [{"source_code": "#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']\n\ndef inpf() a=gets.chomp.split(\" \").map(&:to_f)end\n\ndef inps() a=gets.chomp.split(\" \")end\n\ndef copy(a) Marshal.load(Marshal.dump(a)) end\n\ndef kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end\n\ndef na(n,d=0) Array.new(n,d)end\n\ndef na2(n,m,d=0) Array.new(n){Array.new(m,d)}end\n\ndef na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end\n\ndef inp() a=gets.chomp.split(\" \").map(&:to_i)end\n\ndef r_up(a, b) (a+b-1)/b end\n\ndef r_sort(a) a.sort{|a,b|b<=>a} end\n\nt = []\nn , p = inp\nmin = 9999999\n50.times do|i|\n cn = n-i*p\n break if(cn <= 0)\n c = cn.to_s(2).count(\"1\")\n chib = i - c\n if(chib >= 0)\n min = [min, i ].min\n end\nend\nif(min > 999)\n puts -1\nelse\n puts min\nend"}], "src_uid": "9e86d87ce5a75c6a982894af84eb4ba8"} {"nl": {"description": "Polycarp loves ciphers. He has invented his own cipher called repeating.Repeating cipher is used for strings. To encrypt the string $$$s=s_{1}s_{2} \\dots s_{m}$$$ ($$$1 \\le m \\le 10$$$), Polycarp uses the following algorithm: he writes down $$$s_1$$$ ones, he writes down $$$s_2$$$ twice, he writes down $$$s_3$$$ three times, ... he writes down $$$s_m$$$ $$$m$$$ times. For example, if $$$s$$$=\"bab\" the process is: \"b\" $$$\\to$$$ \"baa\" $$$\\to$$$ \"baabbb\". So the encrypted $$$s$$$=\"bab\" is \"baabbb\".Given string $$$t$$$ \u2014 the result of encryption of some string $$$s$$$. Your task is to decrypt it, i.\u2009e. find the string $$$s$$$.", "input_spec": "The first line contains integer $$$n$$$ ($$$1 \\le n \\le 55$$$) \u2014 the length of the encrypted string. The second line of the input contains $$$t$$$ \u2014 the result of encryption of some string $$$s$$$. It contains only lowercase Latin letters. The length of $$$t$$$ is exactly $$$n$$$. It is guaranteed that the answer to the test exists.", "output_spec": "Print such string $$$s$$$ that after encryption it equals $$$t$$$.", "sample_inputs": ["6\nbaabbb", "10\nooopppssss", "1\nz"], "sample_outputs": ["bab", "oops", "z"], "notes": null}, "positive_code": [{"source_code": "n=gets.to_i\ni=x=0\ns=gets.chomp\nwhile i=str.length\nend\n\nputs newstr\n"}, {"source_code": "gets\ns = gets.chomp\n\nresult = ''\n1.upto(10) do |i|\n break if s.empty?\n\n result += s[0]\n\n s.replace s[i..-1]\nend\n\nputs result\n"}, {"source_code": "n=gets.to_i\ns=gets.split('')\nidx=0\nans=\"\"\nctr=1\nwhile idx=a and n/a-a 1\n return \"ugly\"\n end\n end\n\n sorted_list_x = list_x.sort\n sorted_list_y = list_y.sort\n avg_x, avg_y = 0, 0\n\n for i in 0..7\n avg_x += 1 if sorted_list_x[i] == sorted_list_x[3]\n avg_y += 1 if sorted_list_y[i] == sorted_list_y[3]\n end\n\n return avg_x == 2 && avg_y == 2 ? \"respectable\" : \"ugly\"\nend\n\nputs eight_point_set(list, list_x, list_y)\n"}, {"source_code": "points = 8.times.map{|i| gets.split.map(&:to_i) }.uniq\nputs [:first, :last].all?{|sym| points.group_by(&sym).to_a.sort_by(&:first).map{|x| x.last.length} == [3,2,3] } ? \"respectable\" : \"ugly\"\n\n"}, {"source_code": "points = 8.times.map{|i| gets.split.map(&:to_i) }.uniq\nputs [:first, :last].all?{|sym| points.group_by(&sym).to_a.sort_by(&:first).map{|x| x.last.length} == [3,2,3] } ? \"respectable\" : \"ugly\"\n"}, {"source_code": "points = 8.times.map{|i| gets.split.map(&:to_i) }.uniq\nputs [:first, :last].all?{|sym| points.group_by(&sym).to_a.sort_by(&:first).map{|x| x.last.length} == [3,2,3] } ? \"respectable\" : \"ugly\"\n\n"}, {"source_code": "points = 8.times.map{|i| gets.split.map(&:to_i) }.uniq\nputs [:first, :last].all?{|sym| points.group_by(&sym).to_a.sort_by(&:first).map{|x| x.last.length} == [3,2,3] } ? \"respectable\" : \"ugly\"\n\n"}], "negative_code": [{"source_code": "#!/usr/bin/env ruby\npoint,x, y = [], [], []\n8.times do\n point << gets.split(' ').map(&:to_i)\n x << point[-1][0] unless x.include? point[-1][0]\n y << point[-1][1] unless y.include? point[-1][1]\nend\nif x.size == 3 && y.size == 3\n ok = true\n for i in 0...3\n for j in 0...3\n next if i == 1 && j == 1\n ok = false unless point.include?([x[i], y[j]])\n end\n end\n puts ok ? \"respectable\" : \"ugly\"\nelse\n puts \"ugly\"\nend\n"}, {"source_code": "#!/usr/bin/env ruby\npoint,x, y = [], [], []\n8.times do\n point << gets.split(' ').map(&:to_i)\n x << point[-1][0] unless x.include? point[-1][0]\n y << point[-1][1] unless y.include? point[-1][1]\nend\nif x.size == 3 && y.size == 3\n if x.size > 1 && y.size > 1 && point.include?([x.sort[1], y.sort[1]])\n puts \"ugly\"\n else\n puts \"respectable\"\n end\nelse\n puts \"ugly\"\nend\n"}, {"source_code": "#!/usr/bin/env ruby\npoint,x, y = [], [], []\n8.times do\n point << gets.split(' ').map(&:to_i)\n x << point[-1][0] unless x.include? point[-1][0]\n y << point[-1][1] unless y.include? point[-1][1]\nend\nif x.sort!.size == 3 && y.sort!.size == 3\n if point.uniq.size == point.size && point.include?([x[1], y[1]])\n puts \"respectable\"\n else\n puts \"ugly\"\n end\nelse\n puts \"ugly\"\nend\n"}, {"source_code": "points =[]\nfor i in 1..8\n temp=gets.chomp.split.collect{|a| a.to_i}\n points.push temp\nend\nxs=points.collect{|a| a.first}.uniq\nys=points.collect{|a| a.last }.uniq\n#puts xs,ys\nif xs.length!=3 ||ys.length!=3\n puts \"ugly\"\nelse\n avg=[xs[1],ys[1]]\n # puts avg\n if points.include? avg\n puts \"ugly\"\n else\n puts\"respectable\"\n end\nend\n"}, {"source_code": "points =[]\nfor i in 1..8\n temp=gets.chomp.split.collect{|a| a.to_i}\n points.push temp\nend\nxs=points.collect{|a| a.first}.uniq.sort\nys=points.collect{|a| a.last }.uniq.sort\n#puts xs,ys\nif xs.length!=3 ||ys.length!=3 || temp.uniq !=8\n puts \"ugly\"\nelse\n avg=[xs[1],ys[1]]\n # puts avg\n if points.include? avg\n puts \"ugly\"\n else\n puts\"respectable\"\n end\nend\n"}, {"source_code": "points =[]\nfor i in 1..8\n temp=gets.chomp.split.collect{|a| a.to_i}\n points.push temp\nend\nxs=points.collect{|a| a.first}.sort.uniq\nys=points.collect{|a| a.last }.sort.uniq\n#puts xs,ys\nif xs.length!=3 ||ys.length!=3 || points.uniq !=8\n puts \"ugly\"\nelse\n avg=[xs[1],ys[1]]\n # puts avg\n if points.include? avg\n puts \"ugly\"\n else\n puts\"respectable\"\n end\nend\n"}, {"source_code": "points =[]\nfor i in 1..8\n temp=gets.chomp.split.collect{|a| a.to_i}\n points.push temp\nend\nxs=points.collect{|a| a.first}.uniq.sort\nys=points.collect{|a| a.last }.uniq.sort\n#puts xs,ys\nif xs.length!=3 ||ys.length!=3\n puts \"ugly\"\nelse\n avg=[xs[1],ys[1]]\n # puts avg\n if points.include? avg\n puts \"ugly\"\n else\n puts\"respectable\"\n end\nend\n"}, {"source_code": "\nxy = []\n8.times do\n x,y = gets.split(' ').map(&:to_i)\n xy << [x,y]\nend\n\nxs,ys = xy.transpose\nxxs = xs.sort.uniq\nyys = ys.sort.uniq\n\nok = true\nxxs.each do |x|\n if xs.count(x) != 3\n ok = false\n break;\n end\nend\n\nyys.each do |y|\n if ys.count(y) != 3\n ok = false\n break;\n end\nend if ok\n\nif !ok || xxs.size != 3 || yys.size != 3 || xy.include?([xxs[1], yys[1]])\n puts \"ugly\"\nelse\n puts \"respectable\"\nend\n"}, {"source_code": "\nxy = []\n8.times do\n x,y = gets.split(' ').map(&:to_i)\n xy << [x,y]\nend\n\nxs,ys = xy.transpose\nxxs = xs.sort.uniq\nyys = ys.sort.uniq\n\nok = true\nxxs.each.with_index do |x,i|\n if xs.count(x) != (i == 1 ? 2 : 3)\n ok = false\n break;\n end\nend\n\nyys.each.with_index do |y,i|\n if ys.count(y) != (i == 1 ? 2 : 3)\n ok = false\n break;\n end\nend if ok\n\nif !ok || xxs.size != 3 || yys.size != 3 || xy.include?([xxs[1], yys[1]])\n puts \"ugly\"\nelse\n puts \"respectable\"\nend\n"}, {"source_code": "\nxy = []\n8.times do\n x,y = gets.split(' ').map(&:to_i)\n xy << [x,y]\nend\n\nxs,ys = xy.transpose\nxxs = xs.sort.uniq\nyys = ys.sort.uniq\n\nif xxs.size != 3 || yys.size != 3 || xy.include?([xxs[1], yys[1]])\n puts \"ugly\"\nelse\n puts \"respectable\"\nend\n"}, {"source_code": "def runb(list)\n x = list.map{|x,y| x}.uniq.sort\n y = list.map{|x,y| y}.uniq.sort\n \n return false unless x.size == 3\n return false unless y.size == 3\n return false if list.member?([x[1],y[1]])\n return true\nend\n\ndef run(list)\n runb(list) ? \"respectable\" : \"ugly\"\nend\n\ndef convert(n)\n n.split(' ').map(&:to_i)\nend\n\nn = gets\nlist = []\nwhile n != nil\n list << convert(n)\n if list.size == 8\n puts run(list)\n list = []\n end\n n = gets\nend\n"}, {"source_code": "# http://codeforces.com/problemset/problem/334/B\nlist = []\nlist_x = []\nlist_y = []\n8.times do |i|\n list << gets.chomp.split.map(&:to_i)\n list_x << list[i][0]\n list_y << list[i][1]\nend\n\ndef eight_point_set(list, list_x, list_y)\n hash = Hash.new { |hash, key| hash[key] = 0 }\n for i in 0..7\n hash[list[i]] += 0\n\n if hash[list[i]] > 1\n return \"ugly\"\n end\n end\n\n sorted_list_x = list_x.sort\n sorted_list_y = list_y.sort\n avg_x, avg_y = 0, 0\n\n for i in 0..7\n avg_x += 1 if sorted_list_x[i] == sorted_list_x[3]\n avg_y += 1 if sorted_list_y[i] == sorted_list_y[3]\n end\n\n return avg_x == 2 && avg_y == 2 ? \"respectable\" : \"ugly\"\nend\n\nputs eight_point_set(list, list_x, list_y)\n"}, {"source_code": "# http://codeforces.com/problemset/problem/334/B\n\nlist_x = []\nlist_y = []\n8.times do\n pair = gets.chomp.split\n list_x << pair[0].to_i\n list_y << pair[1].to_i\nend\n\nlist_x = list_x.sort\nlist_y = list_y.sort\n\navg_x, avg_y = 0, 0\n\nfor i in 0..7\n avg_x += 1 if list_x[i] == list_x[3]\n avg_y += 1 if list_y[i] == list_y[3]\nend\n\nputs avg_x == 2 && avg_y == 2 ? \"respectable\" : \"ugly\"\n"}], "src_uid": "f3c96123334534056f26b96f90886807"} {"nl": {"description": "Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.Note, that during capitalization all the letters except the first one remains unchanged.", "input_spec": "A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103.", "output_spec": "Output the given word after capitalization.", "sample_inputs": ["ApPLe", "konjac"], "sample_outputs": ["ApPLe", "Konjac"], "notes": null}, "positive_code": [{"source_code": "s = gets.chomp\ns[0] = s[0].capitalize\nputs s\n"}, {"source_code": "A = gets.chomp\nA[0] = A[0].upcase\nputs A"}, {"source_code": "ar=gets\nar[0]=ar[0].capitalize\nputs ar"}, {"source_code": "a=gets;puts a.upcase[0]+a[1..-1]"}, {"source_code": "str = gets.chomp()\nstr[0] = str[0].upcase\nputs str\n"}, {"source_code": "s = gets.chomp\nf = s[0].capitalize\nputs f + s[1..-1]"}, {"source_code": "s = gets\ns[0] = s[0].upcase\nprint s\n"}, {"source_code": "arr = gets.chomp.split(\"\")\nfirst_letter = arr.first.upcase\nputs [first_letter, arr[1..-1]].flatten.join"}, {"source_code": "a = gets.chomp\nprint a[0].upcase\nprint a[1..-1]"}, {"source_code": "gets[0]=$_[0].upcase;puts$_\n"}, {"source_code": "gets[0]=$_[0].upcase;puts$_"}, {"source_code": "s = gets.chomp\ns[0] = s[0].capitalize\nputs s"}, {"source_code": "str = gets.to_s.strip\n\ndef newlife(word)\n\tfirst_char = word[0]\n\tfirst_char.upcase!\n\tword[0] = first_char\n\tword\nend\n\nputs newlife(str)"}, {"source_code": "input = gets.chomp\n\nprint input.slice!(0).capitalize, input"}, {"source_code": "s = gets\nputs s[0].capitalize + s[1..-1]"}, {"source_code": "s = gets.strip\nif s[0].ord >= 'a'.ord && s[0].ord <= 'z'.ord then\n s[0] = (s[0].ord - 32).chr\nend\nputs s"}, {"source_code": "word = gets.chomp\nputs word[0].upcase + word[1..-1]"}, {"source_code": "s = gets.chomp\ns[0] = s[0].upcase\nputs s"}, {"source_code": "def xenia()\n word = gets.chomp\n letter = word[0]\n letter.upcase!\n print \"#{letter}#{word[1..-1]}\"\nend\n\nxenia "}, {"source_code": "a = gets.chomp\na[0] = a[0].upcase \nputs a\n"}, {"source_code": "#!/usr/bin/ruby1.9\n\nword = STDIN.readline.strip\nputs word[0].upcase+word[1..-1]\n\n"}, {"source_code": "s = gets.chomp\nf = s[0].capitalize\nputs f + s[1..-1]"}, {"source_code": "a = gets.chomp\nb = a.capitalize\nputs b[0] + a[1..-1]"}, {"source_code": "str = gets.chomp\nputs str[0].upcase + str[1..10**3]"}, {"source_code": "def run(input = STDIN.read)\n line = input.strip\n line[0] = line[0].capitalize\n puts line\nend\nrun"}, {"source_code": "src = gets\nsrc[0] = src[0].upcase\nputs src\n"}, {"source_code": "s = gets.chomp\ns[0] = s[0].capitalize\nputs s"}, {"source_code": "t = $stdin.readline\ntt = t.scan(/./)\ntt[0] = t[0].capitalize\nputs tt.join('')"}, {"source_code": "s = gets.to_s\nputs s[0].upcase + s[1..-1]\n"}, {"source_code": "x = gets.chomp;\nx[0]= x[0].upcase;\nputs x;"}, {"source_code": "def run\n line = $stdin.readline.split(//)\n line[0].upcase!\n puts line.join(\"\")\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "a = gets \nputs a[0].upcase + a[1..-1]\n"}, {"source_code": "inp = gets.chomp\ninp = inp.sub(/^./) { |ch| ch.upcase }\nputs inp\n"}, {"source_code": "str = $stdin.gets\n\nstr[0] = str[0].upcase! if str[0].upcase!\nputs str"}, {"source_code": "w = gets.chomp\n\nputs w[0].upcase + w[1..-1]\n"}, {"source_code": "s = gets\n\ns[0] = s[0].capitalize;\n\nputs s"}, {"source_code": "test = gets\ntest[0] = test[0].capitalize\nputs test"}, {"source_code": "a = gets.chomp()\nputs a[0].upcase << a[1..-1]"}, {"source_code": "s = gets.chomp\nputs s[0].capitalize + s[1..-1]"}, {"source_code": "s = gets.strip\nt = \"\"\ns.length.times do |i|\n if i == 0\n t += s[i].upcase\n else\n t += s[i]\n end\nend\nputs t"}, {"source_code": "a=gets.chomp\na=a[0].upcase+a[1..a.length-1]\nputs \"#{a}\""}, {"source_code": "x = gets.chomp\nputs \"#{x[0].capitalize + x[1..-1]}\""}, {"source_code": "s=gets\ns[0]=s[0].upcase\nputs s"}, {"source_code": "#STDOUT.flush\n#str = gets.chomp\n#str_aux = \"AEIOUYaeiouy\"\n#str.each_char { |out|\n#\tif !str_aux.include? out.to_s\n#\t\tprint \".\"\n#\t\tprint out.downcase\n#\tend\n#}\n#puts \"\\n\"\n\nSTDOUT.flush\nstr = gets.chomp\nprint str[0].upcase\nputs str[1..str.size()]"}, {"source_code": "require 'set'\ninclude Math\n$stdin = File.open(\"./input.txt\", \"r\") if ENV[\"USER\"] == \"new\"\n# ====================================\n\nline = gets.strip\nline[0] = line[0].upcase\nputs line"}, {"source_code": "s = gets\nputs s[0].upcase + s[1, s.length]"}, {"source_code": "word = STDIN.read\nputs word.sub(/\\w/) {|c| c.capitalize}\n"}, {"source_code": "s = gets.chomp\ns[0] = s[0].upcase\nputs s"}, {"source_code": "a = gets.chomp\nputs a[0].upcase + a[1..a.length]\n"}, {"source_code": "a=gets;puts a[0].upcase+a[1..-1]"}, {"source_code": "s = gets.chop\nputs s[0].upcase + s[1..s.size-1]"}, {"source_code": "s = gets.chomp\nprint s[0].capitalize + s[1..-1]"}, {"source_code": "str = gets.chomp\nstr1 = str[0]\n\nprint str1.capitalize\nputs str[1..str.length]"}, {"source_code": "str = gets.chomp\nprint str[0].capitalize , str[1..str.length]"}, {"source_code": "s = gets\nputs s[0].upcase + s[1...s.size]"}, {"source_code": "puts gets.sub(/^./){|l| l.upcase}\n"}, {"source_code": "# http://codeforces.com/problemset/problem/281/A\n\nword = gets.chomp\nputs \"#{word[0].upcase}#{word[1..(word.length - 1)]}\""}, {"source_code": "input = gets.chomp\nl = input.length\nsov = Array.new\nsov[0] = input[0].upcase\nfor i in 1...l\n sov.push(input[i])\nend\nprint sov.join\n"}, {"source_code": "word = gets.chomp.to_s\nletters = word.split(\"\")\nprint letters[0].capitalize\nletters[0] = nil\nletters.each do |letter|\n\tprint letter\nend"}, {"source_code": "n = gets.split('')\n\nn[0].upcase!\n\nputs n.join('')"}, {"source_code": "puts gets[0].upcase+$_[1..$_.size-1]"}, {"source_code": "str = gets ; str[0] = str[0].to_s.upcase ; puts str"}, {"source_code": "s = gets.strip\ns = s[0].capitalize + s[1..s.length]\nputs s"}, {"source_code": "s = gets.to_s\ns[0] = s[0].upcase\nputs s"}, {"source_code": "word = gets.chomp\nword[0] = word[0].upcase\nputs word"}, {"source_code": "str = gets.chomp\nstr[0] = str[0].capitalize\nputs str"}, {"source_code": "word = String(gets.chomp)\nif word[0] == word[0].upcase\n puts word\nelse\n puts word[0].upcase + word[1...word.length]\nend\n"}, {"source_code": "s = gets.chomp\nputs s[0].upcase + s[1..-1]\n"}, {"source_code": "a=gets;puts a.upcase[0]+a[1..-1]"}, {"source_code": "gets[0]=$_[0].upcase;puts$_"}, {"source_code": "s = gets\nputs s[0].upcase + s[1..-1]"}, {"source_code": "s = gets.chomp\ns[0] = s[0].upcase\nputs s\n"}, {"source_code": "input_word = gets.chomp\ninput_word[0]=input_word[0].upcase\nprint input_word\n"}, {"source_code": "str = gets\na = str[0].upcase\nstr[0]=a\nputs str"}, {"source_code": "str = gets.chomp\nfirst = str[0,1]\nfirst.upcase!\nnewstr = first + str[1,(str.length-1)]\nputs newstr"}, {"source_code": "x=gets.strip.chars.to_a; x[0]=x[0].upcase; puts x.join"}, {"source_code": "a = gets.chomp.to_s\nb = a[1..-1].scan(/[A-Z]/).length\nc = a[0]\nd = []\nif c.capitalize == c && b >= 1\nputs a\nelse\na[0] = a[0].upcase\nputs a\nend"}, {"source_code": "s = gets.chomp.split(\"\")\nif s[0] == s[0].upcase\n\tputs s.join\nelse\n\ts0 = s[0].upcase\n\ts.delete_at(0)\n\tputs s0 << s.join\nend\n"}, {"source_code": "input =gets\ninput[0]=input[0].upcase\nprint input"}, {"source_code": "$><<(gets p)[0].upcase+$_[1..-1]"}, {"source_code": "puts gets[0].upcase+$_[1..-1]"}, {"source_code": "cad = gets.chomp\n\ncad[0] = cad[0].upcase\n\nputs cad\n"}, {"source_code": "a=gets.chomp\na=a[0].upcase+a[1..a.length-1]\nputs \"#{a}\"\n\n"}, {"source_code": "n = gets.chomp\nm = []\nm = n.split(\"\")\nprint m[0].capitalize\nfor i in m.drop(1) do\n print i\nend"}, {"source_code": "a = gets.chomp\nb = a[0]\nb = b.upcase\na[0] = b[0]\nputs a\n"}, {"source_code": "a=gets\nprint a[0].capitalize+a[1..a.length-1]"}, {"source_code": "line = gets.chomp\n\nline[0] = line[0].upcase\nputs line\n"}, {"source_code": "String word = gets.chomp\nword[0]=word[0].capitalize\nputs word\n"}, {"source_code": "gets[0]=$_[0].upcase;puts$_\n"}, {"source_code": "word = gets.chomp\nfirst = word.split(//).first.upcase\nword[0] = first\nputs word"}, {"source_code": "s = gets[0..-2]\ncode = s[0].ord\ncode -= 32 if code > \"Z\".ord\ns[0] = code.chr\nprint s\n"}, {"source_code": "#!/usr/bin/env ruby\n\ngets.split.collect{|i| puts \"#{i[0].upcase}#{i[1..-1]}\"}\n"}, {"source_code": "str = gets.chomp\nstr[0] = str[0].capitalize\nputs str"}, {"source_code": "input = gets.strip\n\ninput[0] = input[0].upcase\nputs input\n"}, {"source_code": "string = gets\nstring[0] = string[0].capitalize\nputs string\n"}, {"source_code": "s = gets.chomp; s[0] = s[0].upcase; puts s\n"}, {"source_code": "s = gets.chomp\ns[0] = s[0].upcase\nputs s\n"}, {"source_code": "string = gets.chomp.split('')\nstring[0].upcase!\n\nstring.each do |item|\n\tprint item\nend"}], "negative_code": [{"source_code": "s = gets.chomp.split(//)\ns[0] = s[0].capitalize\nputs s\n"}, {"source_code": "puts gets.chomp.capitalize"}, {"source_code": "puts gets.chomp.capitalize"}, {"source_code": "puts gets.capitalize"}, {"source_code": "s = gets\ns[0] = s[0] + 'a' + 'A' if 'a' <= s[0] && s[0] <= 'z'\nprint s\n"}, {"source_code": "puts gets.chomp.capitalize"}, {"source_code": "puts gets.capitalize"}, {"source_code": "s = gets\nputs s.capitalize"}, {"source_code": "#!/usr/bin/ruby1.9\n\nword = STDIN.readline.strip.capitalize\nputs word\n\n"}, {"source_code": "puts gets.capitalize"}, {"source_code": "def run(input = STDIN.read)\n line = input.strip\n puts line.capitalize\nend\nrun\n"}, {"source_code": "puts gets.capitalize\n"}, {"source_code": "inp = gets.chomp\ninp.sub(/^./) { |ch| ch.upcase }\nputs inp\n"}, {"source_code": "str = $stdin.gets\n\nputs str.capitalize"}, {"source_code": "test = gets.chomp\nfinal = test.capitalize\nputs final"}, {"source_code": "a = gets.chomp()\nputs a[0].upcase!.to_s << a[1..-1]"}, {"source_code": "a = gets.chomp()\nb = a[0].upcase!.to_s\nputs b << a[1..-1]"}, {"source_code": "puts gets.chomp.capitalize"}, {"source_code": "x=gets;p x[0].upcase+x[1..-2]"}, {"source_code": "x=gets;p x[0].upcase+x[1..-1]"}, {"source_code": "puts gets.capitalize"}, {"source_code": "puts gets.capitalize"}, {"source_code": "str = gets ; puts str.to_s.capitalize"}, {"source_code": "s = gets\nputs s.capitalize"}, {"source_code": "s = gets.strip\ns = s[0].capitalize + s[1..s.length]"}, {"source_code": "word = gets.chomp\nword[0].upcase!\nputs word"}, {"source_code": "puts gets.chomp.capitalize"}, {"source_code": "puts gets.capitalize"}, {"source_code": "puts gets.capitalize"}, {"source_code": "input_word = gets.chomp\nprint input_word[0].upcase\n"}, {"source_code": "a = gets.chomp.to_s\nb = a[1..-1].scan(/[A-Z]/).length\nc = a[0]\nif c.upcase == c && b >= 1\nputs a\nelse\nc.upcase!\nputs a\nend"}, {"source_code": "a = gets.chomp.to_s\nb = a[1..-1].scan(/[A-Z]/).length\nc = a[0]\nif c.upcase == c && b >= 1\nputs a\nelse\nputs a.capitalize\nend"}, {"source_code": "a = gets.chomp.to_s\nb = a[1..-1].scan(/[A-Z]/).length\nc = a[0]\nif c.capitalize == c && b >= 1\nputs a\nelse\nputs a.capitalize\nend"}, {"source_code": "a = gets.chomp.to_s\nb = a[1..-1].scan(/[A-Z]/).length\nc = a[0]\nif c.capitalize == c && b >= 1\nputs a\nelse\nputs a.capitalize!\nend"}, {"source_code": "input=gets\np input.to_s.capitalize"}, {"source_code": "String word = gets.chomp\nword[0].capitalize!\nputs word\n"}, {"source_code": "String word = gets.chomp\nword.capitalize!\nputs word\n"}, {"source_code": "puts gets.chomp.capitalize\n"}], "src_uid": "29e0fc0c5c0e136ac8e58011c91397e4"} {"nl": {"description": "Luke Skywalker gave Chewbacca an integer number x. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit t means replacing it with digit 9\u2009-\u2009t. Help Chewbacca to transform the initial number x to the minimum possible positive number by inverting some (possibly, zero) digits. The decimal representation of the final number shouldn't start with a zero.", "input_spec": "The first line contains a single integer x (1\u2009\u2264\u2009x\u2009\u2264\u20091018) \u2014 the number that Luke Skywalker gave to Chewbacca.", "output_spec": "Print the minimum possible positive number that Chewbacca can obtain after inverting some digits. The number shouldn't contain leading zeroes.", "sample_inputs": ["27", "4545"], "sample_outputs": ["22", "4444"], "notes": null}, "positive_code": [{"source_code": "\na = gets.split('').map(&:to_i)\n(a.length-1).times{|i|\n if ((i!=0 || a[i]!=9) && a[i]>4)\n print 9-a[i]\n else\n print a[i]\n end\n}"}, {"source_code": "res = gets.chomp.chars.map(&:to_i).\n map{|x| [x, 9 -x].min}.map(&:to_s).join('')\n\nres[0] = '9' if res[0] == '0'\nputs res\n"}, {"source_code": "\ns=gets.chomp\nx=s.chars\nt=x.shift\n\np1=\"8765\".index(t)\nif p1!=nil then\n\tt=[1,2,3,4][p1]\nelse\n\tt=t.to_i\nend\nans=t\nx.map{|e|\n\tans*=10\n\tp2=\"98765\".index(e)\n\tif p2==nil then\n\t\tans=ans+e.to_i\n\telse\n\t\tans=ans+[0,1,2,3,4][p2]\n\tend\n}\nputs ans\n\n"}, {"source_code": "s = gets.chomp\nif s[0] == '9'\n\tprint '9'\nelse\n\tprint [s[0].to_i,9-s[0].to_i].min\nend\n1.upto(s.length - 1) do |i|\n\tprint [s[i].to_i , 9-s[i].to_i].min\nend"}, {"source_code": "#!/usr/bin/ruby\nhash = {'9' => '0', '8' => '1','7' => '2','6' => '3','5' => '4'}\ninput_line = gets\nres = ''\ninput_line.each_char do |ch|\n if hash[ch].nil?\n res+=ch;\n else\n if (ch == '9' && res == '')\n res+=ch\n else\n res+=hash[ch]\n end\n end\nend\n\nputs res\n\n"}, {"source_code": "a=gets.chop.split(//).map(&:to_i).map{|i|i=[i,9-i].min}*''\na[0]='9' if a[0]=='0'\nputs a"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\ndigits = gets.chomp.split(//).map { |i|\n i = i.to_i\n inverted = 9 - i\n if inverted < i\n inverted\n else\n i\n end\n}\n\n# remind leading zero!\nif digits[0] == 0\n digits[0] = 9\nend\n\nputs digits.join"}, {"source_code": "number = gets.chomp\ndigits = number.split(\"\")\n\nif digits[0].to_i >= 5 && digits[0].to_i != 9\n\tdigits[0] = 9 - digits[0].to_i\nend\nif digits[digits.size - 1].to_i >= 5 && digits.size > 1\n\tdigits[digits.size - 1] = 9 - digits[digits.size - 1].to_i\nend\nif digits.size == 2\n\tprint digits[0].to_i\n\tprint digits[1].to_i\nelsif digits.size == 1\n\tprint digits[0].to_i\nelse\n\tfor i in (1..digits.size-2)\n\t\tif digits[i].to_i >= 5 \n\t\t\tdigits[i] = 9 - digits[i].to_i\n\t\tend\n\tend\n\tfor i in (0..digits.size-1)\n\t\tprint digits[i].to_i\n\tend\nend"}, {"source_code": "digits = gets.chomp.chars.map(&:to_i)\nprint digits.shift if digits[0] == 9\nputs digits.map{|d| [d,9-d].min}.join"}, {"source_code": "initial_num = ARGF.read\n\nresult = ''\n\ninitial_num.chars.each_with_index do |c, index|\n\ti = c.to_i\n\tif i >= 5\n\t\tif i == 9 and index == 0\n\t\t\tresult << c\n\t\telse\n\t\t\tresult << (9-i).to_s\n\t\tend\n\telse\n\t\tresult << c\n\tend\nend\n\nputs result"}, {"source_code": "a = gets.strip.chars.each_with_index.map do |ci,i|\n d = ci.ord - '0'.ord\n if i == 0 && d == 9\n d\n elsif d >= 5\n 9-d\n else\n d\n end\nend\nputs a.join\n"}, {"source_code": "x = gets.strip.split('').map{|x| x.to_i}\nx[0] = 9 - x[0] if x[0] > 4 && x[0] != 9\n(1..x.size - 1).each{|i| x[i] = 9 - x[i] if x[i] > 4}\nputs(x.join)\n"}, {"source_code": "x = gets.chomp.chars.map(&:to_i)\n\ntmp = x[0]\nx = x[1..-1]\n\ntmp = 9 - tmp if tmp > 4 and tmp < 9\n\nx = x.map { |i|\n if i > 4\n 9 - i\n else\n i\n end }\n\nputs ([tmp] + x).join(\"\")"}, {"source_code": "str=gets.to_s\nstr.chomp!\n\nfor i in 0..str.length-1\n x=str[i].to_i\n y=9-x\n if x>y\n str[i]=y.to_s\n else\n str[i]=x.to_s\n end\nend\n\nif str[0]==\"0\"\n str[0]=\"9\"\nend\n\nputs str"}, {"source_code": "n = gets.chomp \n\nn = n.gsub(/[98765]/,'9'=>'0','8'=>'1','7'=>'2','6'=>'3','5'=>'4') \n\nif n[0] == '0' \n n[0] = '9' \n # puts n\nend \n\nputs n "}, {"source_code": "a=gets.chomp.bytes.map{|e|[57-e,e-48].min}\na[0]=9 if a[0]==0\nputs a*''"}, {"source_code": "# http://codeforces.com/contest/514/problem/A\n\ndigits = gets.chomp.chars.map(&:to_i)\ninverted = digits.map.with_index do |n, idx|\n case idx\n when 0\n (9 - n) < n && n != 9 ? 9 - n : n\n else\n (9 - n) < n ? 9 - n : n\n end\nend\n\nputs inverted.join.to_i\n"}, {"source_code": "s = gets.chomp.to_s\nk = s[0]\nfor i in 0..s.length - 1\n if s[i].to_i>=5\n s[i] = (9 - s[i].to_i).to_s\n end\nend\nif s[0] == \"0\"\n s[0] = k\nend\nputs s\n\n"}, {"source_code": "#!/usr/bin/ruby\n# coding: utf-8\n\ns = gets.chomp.to_s\n(s.length).times{|i|\n if s[i].to_i >= 5 \n if i == 0 and s[i].to_i == 9 \n next\n end\n s[i] = (9 - s[i].to_i).to_s\n end \n}\nputs s"}, {"source_code": "arr = gets.chomp.split(\"\")\narr.each_with_index do |item, index|\n print item.to_i <= 4 ? item : index.to_i == 0 && item.to_i == 9 ? item : 9 - item.to_i\nend\n"}], "negative_code": [{"source_code": "\na = gets.split('').map(&:to_i)\n(a.length-1).times{|i|\n if (i!=0 && a[i]>4)\n print 9-a[i]\n else\n print a[i]\n end\n}"}, {"source_code": "def read_ints; STDIN.gets.split.map(&:to_i); end\n\nputs gets.chomp.chars.map(&:to_i).\n map{|x| [x, 9 -x].min}.map(&:to_s).join('')\n\n"}, {"source_code": "\ns=gets.chomp\nx=s.chars\nt=x.shift\n\np1=\"8765\".index(t)\nif p1!=nil then\n\tt=[1,2,3,4][p1]\n\tp t\nelse\n\tt=t.to_i\nend\nans=t\nx.map{|e|\n\tans*=10\n\tp2=\"98765\".index(e)\n\tif p2==nil then\n\t\tans=ans+e.to_i\n\telse\n\t\tans=ans+[0,1,2,3,4][p2]\n\tend\n}\nputs ans\n\n"}, {"source_code": "s = gets.chomp\nif s[0] == '9'\n\tprint '9'\nelse\n\tprint [s[0].to_i,9-s[0].to_i].min\nend\n1.upto(s.length - 1) do |i|\n\tprint [s[0].to_i , 9-s[0].to_i].min\nend"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\ndigits = gets.chomp.split(//).map { |i|\n i = i.to_i\n inverted = 9 - i\n if inverted < i\n inverted\n else\n i\n end\n}\n\nputs digits.join"}, {"source_code": "number = gets.chomp\ndigits = number.split(\"\")\n\nif digits[0].to_i >= 5 && digits[0].to_i != 9\n\tdigits[0] = 9 - digits[0].to_i\nend\nif digits[digits.size - 1].to_i >= 5 \n\tdigits[digits.size - 1] = 9 - digits[digits.size - 1].to_i\nend\nif digits.size == 2\n\tprint digits[0].to_i\n\tprint digits[1].to_i\nelsif digits.size == 1\n\tprint digits[0].to_i\nelse\n\tfor i in (1..digits.size-2)\n\t\tif digits[i].to_i >= 5 \n\t\t\tdigits[i] = 9 - digits[i].to_i\n\t\tend\n\tend\n\tfor i in (0..digits.size-1)\n\t\tprint digits[i].to_i\n\tend\nend"}, {"source_code": "number = gets.chomp\ndigits = number.split(\"\")\n\nif digits[0].to_i >= 5 && digits[0].to_i != 9\n\tdigits[0] = 9 - digits[0].to_i\nend\nif digits[digits.size - 1].to_i >= 5 && digits[digits.size - 1].to_i != 9\n\tdigits[digits.size - 1] = 9 - digits[digits.size - 1].to_i\nend\nif digits.size == 2\n\tprint digits[0].to_i\n\tprint digits[1].to_i\nelsif digits.size == 1\n\tprint digits[0].to_i\nelse\n\tfor i in (1..digits.size-2)\n\t\tif digits[i].to_i >= 5 && digits[i].to_i != 9\n\t\t\tdigits[i] = 9 - digits[i].to_i\n\t\tend\n\tend\n\tfor i in (0..digits.size-1)\n\t\tprint digits[i].to_i\n\tend\nend"}, {"source_code": "number = gets.chomp\ndigits = number.split(\"\")\n\nif digits[0].to_i >= 5\n\tdigits[0] = 9 - digits[0].to_i\nend\nif digits[digits.size - 1].to_i >= 5\n\tdigits[digits.size - 1] = 9 - digits[digits.size - 1].to_i\nend\nif digits.size == 2\n\tprint digits[0].to_i\n\tprint digits[1].to_i\nelsif digits.size == 1\n\tprint digits[0].to_i\nelse\n\tfor i in (1..digits.size-2)\n\t\tif digits[i].to_i >= 5\n\t\t\tdigits[i] = 9 - digits[i].to_i\n\t\tend\n\tend\n\tfor i in (0..digits.size-1)\n\t\tprint digits[i].to_i\n\tend\nend"}, {"source_code": "number = gets.chomp\ndigits = number.split(\"\")\n\nif digits[0].to_i >= 5 && digits[0].to_i != 9\n\tputs \"asdf\"\n\tdigits[0] = 9 - digits[0].to_i\nend\nif digits[digits.size - 1].to_i >= 5 && digits.size > 1\n\tdigits[digits.size - 1] = 9 - digits[digits.size - 1].to_i\nend\nif digits.size == 2\n\tprint digits[0].to_i\n\tprint digits[1].to_i\nelsif digits.size == 1\n\tprint digits[0].to_i\nelse\n\tfor i in (1..digits.size-2)\n\t\tif digits[i].to_i >= 5 \n\t\t\tdigits[i] = 9 - digits[i].to_i\n\t\tend\n\tend\n\tfor i in (0..digits.size-1)\n\t\tprint digits[i].to_i\n\tend\nend"}, {"source_code": "ans = gets.chomp.chars.map(&:to_i).map{|d| [d,9-d].min}.join.to_i\nputs ans==0 ? 9 : ans"}, {"source_code": "puts gets.chomp.chars.map(&:to_i).map{|d| [d,9-d].min}.join.to_i"}, {"source_code": "initial_num = ARGF.read\n\nresult = ''\n\ninitial_num.chars.each_with_index do |c, index|\n i = c.to_i\n if i >= 5\n result << (9-i).to_s unless i == 9 and index == 0\n else\n result << c\n end\nend\n\nputs result"}, {"source_code": "initial_num = ARGF.read\n\nresult = ''\n\ninitial_num.chars.each_with_index do |c, index|\n\ti = c.to_i\n\tif i >= 5\n\t\tresult << (9-i).to_s unless i == 9 and index == 0\n\telse\n\t\tresult << c\n\tend\nend\n\nputs result"}, {"source_code": "c = gets.strip\nif c == '9'\n puts 0\nelse\n a = c.chars.each_with_index.map do |ci,i|\n d = ci.ord - '0'.ord\n if i == 0 && d == 9\n d\n elsif d >= 5\n 9-d\n else\n d\n end\n end\n puts a.join\nend\n"}, {"source_code": "x = gets.chomp.chars.map(&:to_i)\n\ntmp = x[0]\nx = x[1..-1]\n\ntmp = 9 - tmp if tmp > 4 and tmp < 9\n\nx = x.map { |i| 9 - i if i > 4 }\n\nputs ([tmp] + x).join(\"\")"}, {"source_code": "# cook your code here\nn = gets.chomp \n\nn = n.gsub(/[98765]/,'9'=>'0','8'=>'1','7'=>'2','6'=>'3','5'=>'4') \n\ni = 0 ;\n\nif n[0] == '0' \n n[0] == '9' \nend \n\nputs n "}, {"source_code": "# cook your code here\nn = gets.chomp \n\nn = n.gsub(/[98765]/,'9'=>'0','8'=>'1','7'=>'2','6'=>'3','5'=>'4') \n\ni = 0 ;\n\nwhile n[i]=='0' \n n[i] = '9' \n i = i+1 \nend \n\nputs n "}, {"source_code": "a=gets.chomp.bytes.map{|e|57-e}\na[0]=9 if a[0]==0\nputs a*''"}, {"source_code": "# http://codeforces.com/contest/514/problem/A\n\ndigits = gets.chomp.chars.map(&:to_i)\ndigits.map! { |n| (9 - n) < n ? 9 - n : n }\n\nputs digits.join.to_i\n"}, {"source_code": "arr = gets.chomp.split(\"\")\narr.each do |x| print x.to_i <= 4 ? x : arr[0] == '9' ? arr[0] : \n 9 - x.to_i\nend\n"}, {"source_code": "n = gets.to_i\nans = \"\"\nwhile n > 0 do\n dig = n % 10\n if 9 - dig < dig && 9 - dig != 0\n ans << (9 - dig).to_s\n else\n ans << dig.to_s\n end\n n /= 10\nend\nputs ans\n"}, {"source_code": "n = gets.to_i\nans = \"\"\nwhile n > 0 do\n dig = n % 10\n if 9 - dig < dig\n ans << (9 - dig).to_s\n else\n ans << dig.to_s\n end\n n /= 10\nend\nputs ans\n"}, {"source_code": "arr = gets.chomp.split(\"\")\narr.each do |x| print x.to_i <= 4 ? x : arr.size == 1 && arr[0] == '9' ? arr[0] : \n 9 - x.to_i\nend\n"}], "src_uid": "d5de5052b4e9bbdb5359ac6e05a18b61"} {"nl": {"description": "One day Kefa found n baloons. For convenience, we denote color of i-th baloon as si \u2014 lowercase letter of the Latin alphabet. Also Kefa has k friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his baloons, such that no one of his friens will be upset \u2014 print \u00abYES\u00bb, if he can, and \u00abNO\u00bb, otherwise. Note, that Kefa's friend will not upset, if he doesn't get baloons at all.", "input_spec": "The first line contains two integers n and k (1\u2009\u2264\u2009n,\u2009k\u2009\u2264\u2009100) \u2014 the number of baloons and friends. Next line contains string s \u2014 colors of baloons.", "output_spec": "Answer to the task \u2014 \u00abYES\u00bb or \u00abNO\u00bb in a single line. You can choose the case (lower or upper) for each letter arbitrary.", "sample_inputs": ["4 2\naabb", "6 3\naacaab"], "sample_outputs": ["YES", "NO"], "notes": "NoteIn the first sample Kefa can give 1-st and 3-rd baloon to the first friend, and 2-nd and 4-th to the second.In the second sample Kefa needs to give to all his friends baloons of color a, but one baloon will stay, thats why answer is \u00abNO\u00bb."}, "positive_code": [{"source_code": "n,k=gets.split.map &:to_i\nh=Hash.new 0\ngets.chomp.chars{|c|h[c]+=1}\nputs h.values.any?{|e|e>k} ? :NO : :YES"}, {"source_code": "n, k = gets.strip.split.map(&:to_i)\ns = gets.strip\nans = \"YES\"\ncount = Array.new(26, 0)\nn.times do |i|\n count[s[i].ord - 'a'.ord] += 1\nend\nmax_count = count.max\nans = \"NO\" if max_count > k\nputs ans\n"}, {"source_code": "n,f=gets.split.map{|e| e.to_i}\n\nhs=Hash.new(0)\ngets.chomp.chars.each{|e|\n\ths[e]+=1\n}\n\nv=hs.values.sort.pop\n\nif v<=f then\n\tputs \"YES\"\nelse\n\tputs \"NO\"\nend"}, {"source_code": "n,k=gets.split.map(&:to_i)\ns = gets.chomp\nh = Hash.new(0)\ns.chars do |c|\n h[c] += 1\nend\n\nf = true\n[*?a..?z].each do |c|\n if h[c] == 0\n next\n elsif (h[c] - 1) / k > 0\n f = false\n break\n end\nend\nputs f ? \"YES\" : \"NO\""}, {"source_code": "a = Array.new(123, gets.split[1].to_i)\ngets.chars{|c| a[c.ord] -= 1}\nputs a.min < 0 ? :NO : :YES\n\n"}, {"source_code": "n, k=gets.split.map(&:to_i)\ns=gets.chomp.chars\n\nh=Hash.new(0)\ns.each{|c| h[c]+=1}\nok=true\nh.each_value do |v|\n ok&=v<=k\nend\n\nputs ok ? 'YES' : 'NO'\n"}], "negative_code": [{"source_code": "n,f=gets.split.map{|e| e.to_i}\n\nhs=Hash.new(0)\ngets.chomp.chars.each{|e|\n\ths[e]+=1\n}\n\nvs=hs.values\nsum=0\nwhile vs.size >1\n\td=vs.shift\n\tvs=vs.map{|e|\n\t\tif d>=e then\n\t\t\td-=e\n\t\t\tf-=e\n\t\t\t0\n\t\telse\n\t\t\tf-=d\n\t\t\tt=e-d\n\t\t\td=0\n\t\t\tt\n\t\tend\n\t}.select{|e| e>0}\n\tvs.push(d) if d>0\nend\nif f<=0 then\n\tputs \"YES\"\nelse\n\tputs \"NO\"\nend"}, {"source_code": "n,f=gets.split.map{|e| e.to_i}\n\nhs=Hash.new(0)\ngets.chomp.chars.each{|e|\n\ths[e]+=1\n}\n\nvs=hs.values\nsum=0\nwhile vs.size >1\n\td=vs.shift\n\tvs=vs.map{|e|\n\t\tif d>=e then\n\t\t\td-=e\n\t\t\tf-=e\n\t\t\t0\n\t\telse\n\t\t\tf-=d\n\t\t\tt=e-d\n\t\t\td=0\n\t\t\tt\n\t\tend\n\t}.select{|e| e>0}\n\tvs.push(d) if d>0\nend\nif vs.empty? && f>=0 then\n\tputs \"YES\"\nelse\n\tputs \"NO\"\nend"}, {"source_code": "n,f=gets.split.map{|e| e.to_i}\nhs=Hash.new(0)\ngets.chomp.chars.each{|e|\n\ths[e]+=1\n}\nhs.each{|k,v|\n\tf-=(v/2).to_i\n}\nif f<=0 then\n\tputs \"YES\"\nelse\n\tputs \"NO\"\nend"}, {"source_code": "n,k=gets.split.map(&:to_i)\ns = gets.chomp\nh = Hash.new(0)\ns.chars do |c|\n h[c] += 1\nend\n\nf = true\n[*?a..?z].each do |c|\n if h[c] % 2 == 1\n f = false\n break\n end\nend\nputs f ? \"YES\" : \"NO\""}, {"source_code": "a = Array.new(123, gets.split[1].to_i)\ngets.chars{|c| a[c.ord] -= 1}\np a.min < 0 ? 'NO' : 'YES'\n\n"}], "src_uid": "ceb3807aaffef60bcdbcc9a17a1391be"} {"nl": {"description": "There are $$$n$$$ students in a university. The number of students is even. The $$$i$$$-th student has programming skill equal to $$$a_i$$$. The coach wants to form $$$\\frac{n}{2}$$$ teams. Each team should consist of exactly two students, and each student should belong to exactly one team. Two students can form a team only if their skills are equal (otherwise they cannot understand each other and cannot form a team).Students can solve problems to increase their skill. One solved problem increases the skill by one.The coach wants to know the minimum total number of problems students should solve to form exactly $$$\\frac{n}{2}$$$ teams (i.e. each pair of students should form a team). Your task is to find this number.", "input_spec": "The first line of the input contains one integer $$$n$$$ ($$$2 \\le n \\le 100$$$) \u2014 the number of students. It is guaranteed that $$$n$$$ is even. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\le a_i \\le 100$$$), where $$$a_i$$$ is the skill of the $$$i$$$-th student.", "output_spec": "Print one number \u2014 the minimum total number of problems students should solve to form exactly $$$\\frac{n}{2}$$$ teams.", "sample_inputs": ["6\n5 10 2 3 14 5", "2\n1 100"], "sample_outputs": ["5", "99"], "notes": "NoteIn the first example the optimal teams will be: $$$(3, 4)$$$, $$$(1, 6)$$$ and $$$(2, 5)$$$, where numbers in brackets are indices of students. Then, to form the first team the third student should solve $$$1$$$ problem, to form the second team nobody needs to solve problems and to form the third team the second student should solve $$$4$$$ problems so the answer is $$$1 + 4 = 5$$$.In the second example the first student should solve $$$99$$$ problems to form a team with the second one."}, "positive_code": [{"source_code": "class Main\n #def get_problem_link\n # problem_link = \"https://codeforces.com/problemset/problem/1092/B\"\n # return problem_link\n #end\n\n #def get_submission_link\n # submission_link = ''\n # return submisson_link\n #end\n\n #begin\n #of codeforces interface\n def run_interface\n n = gets.to_i\n k = gets.split(' ').map(&:to_i)\n puts solution(n, k)\n end\n #end\n #of codeforces interface\n\n def solution(n, students_array)\n res = 0\n students_array.sort!\n (0...students_array.length).step(2).each do |i|\n res = res + (students_array[i+1]-students_array[i]);\n end\n return res\n end\n\nend\n\n#then upload to codeforces uncomment this line:\nMain.new.run_interface\n"}, {"source_code": "gets\nr=0;gets.split.map(&:to_i).sort.each_slice(2){|x,y|r+=y-x};p r"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\na.sort!\nans = 0\n(n/2).times do |i|\n ans += a[2*i+1] - a[2*i]\nend\np ans\n"}, {"source_code": "\ndef solution\n count = read_int\n ss = read_ints.sort\n p ss.each_slice(2).map{ |a, b| b - a }.reduce(0, :+)\nend\n\ndef read_int\n gets.to_i\nend\n\ndef read_ints\n gets.split.map(&:to_i)\nend\n\ndef read_string\n gets.chomp\nend\n\nsolution unless ENV['TEST__MODE']\n\n"}, {"source_code": "# Input\nn = gets.to_i # 2 <= n <= 100\na = gets.split(\" \").map! { |b| b.to_i } # 1 <= b <= 100\n\n# Processing\na.sort!\npairs = Array.new(n / 2) { |i| [a[2 * i], a[2 * i + 1]] }\nsum = pairs.inject(0) { |mem, p| mem + (p[1] - p[0]) }\n\n# Output\nputs sum\n"}, {"source_code": "n = gets.to_i\nas = gets.split.map(&:to_i).sort\nans = 0\n(0..(n/2-1)).each do |i|\n ans += (as[2*i] - as[2*i+1]).abs\nend\nputs ans\n"}, {"source_code": "n = gets.to_i\narr = gets.split.map(&:to_i).sort\nres = 0\narr.each_slice(2) do |slice|\n res += slice[1] - slice[0]\nend\nputs res"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i).sort\nans = 0\n(n/2).times do |i|\n ans += a[i*2+1]-a[i*2]\nend\nputs ans"}, {"source_code": "# coding: utf-8\n\n# if __FILE == $0\n# end\n\nn = gets.to_i\nskills = gets.split.map { |i| i.to_i }\ndeltas = 0\nskills.sort.each_slice(2) { |a| deltas += a[1] - a[0] }\nputs deltas"}, {"source_code": "# https://codeforces.com/problemset/problem/1092/B\n\ndef solution(n, a)\n skills = {}\n (0..(n - 1)).each do |i|\n skills[a[i]] = skills.fetch(a[i], 0) + 1\n end\n\n h = nil\n\n problems = 0\n 100.times do |x|\n i = 100 - x\n\n next if !skills.key?(i)\n next if skills[i] % 2 == 0\n next h = i if h.nil?\n\n problems += h - i\n\n h = nil\n end\n return problems\nend\n\nn = gets.chomp.to_i\na = gets.chomp.split(\" \").map(&:to_i)\n\nputs solution(n, a)\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i).sort\ni, s = 0, 0\nwhile i < a.size\n s += a[i + 1] - a[i]\n i += 2\nend\nputs s\n"}], "negative_code": [], "src_uid": "55485fe203a114374f0aae93006278d3"} {"nl": {"description": "Anton has the integer x. He is interested what positive integer, which doesn't exceed x, has the maximum sum of digits.Your task is to help Anton and to find the integer that interests him. If there are several such integers, determine the biggest of them. ", "input_spec": "The first line contains the positive integer x (1\u2009\u2264\u2009x\u2009\u2264\u20091018) \u2014 the integer which Anton has. ", "output_spec": "Print the positive integer which doesn't exceed x and has the maximum sum of digits. If there are several such integers, print the biggest of them. Printed integer must not contain leading zeros.", "sample_inputs": ["100", "48", "521"], "sample_outputs": ["99", "48", "499"], "notes": null}, "positive_code": [{"source_code": "#!/usr/bin/ruby\nn=gets.chomp\np [n,*(1...n.size).map{|i|\n\t(n[0,i].to_i-1).to_s+'9'*(n.size-i)\n}].max_by{|e|[e.chars.map(&:to_i).reduce(:+),e.to_i]}.to_i"}, {"source_code": "def sum(x)\n x.split('').map(&:to_i).inject(0) { |sum, x| sum + x }\nend\n\nx = gets.to_i\n\nsx = x.to_s\n\nans = x\nsans = sx\n\nsx.length.times do |i|\n sy = sx[0...i] + (sx[i].to_i - 1).to_s + '9' * (sx.length - i - 1)\n \n y = sy.to_i\n sy = y.to_s\n \n if (sum(sy) > sum(sans) || (sum(sy) == sum(sans) && y > ans))\n ans = y\n sans = sy\n end\nend\n\nputs sans"}], "negative_code": [{"source_code": "#!/usr/bin/ruby\nn=gets.chomp\nputs [n,*(1...n.size).map{|i|\n\t(n[0,i].to_i-1).to_s+'9'*(n.size-i)\n}].max_by{|e|[e.chars.map(&:to_i).reduce(:+),e.to_i]}"}, {"source_code": "#!/usr/bin/ruby\nn=gets.to_i\nr=0\nd=1\nwhile r<=n\n\tr=r*10+9\n\td*=10\nend\nd/=10\nr-=d while r>n\np [n,r].max_by{|e|[e.to_s.chars.map(&:to_i).reduce(:+),e]}\n"}, {"source_code": "#!/usr/bin/ruby\nn=gets.chomp\nputs [n,*(1...n.size).map{|i|\n\t(n[0,i].to_i-1).to_s+'9'*(n.size-i)\n}].max_by{|e|[e.chars.map(&:to_i).reduce(:+),e.to_i,e]}"}], "src_uid": "e55b0debbf33c266091e6634494356b8"} {"nl": {"description": "Not long ago Billy came across such a problem, where there were given three natural numbers A, B and C from the range [1,\u2009N], and it was asked to check whether the equation AB\u2009=\u2009C is correct. Recently Billy studied the concept of a digital root of a number. We should remind you that a digital root d(x) of the number x is the sum s(x) of all the digits of this number, if s(x)\u2009\u2264\u20099, otherwise it is d(s(x)). For example, a digital root of the number 6543 is calculated as follows: d(6543)\u2009=\u2009d(6\u2009+\u20095\u2009+\u20094\u2009+\u20093)\u2009=\u2009d(18)\u2009=\u20099. Billy has counted that the digital root of a product of numbers is equal to the digital root of the product of the factors' digital roots, i.e. d(xy)\u2009=\u2009d(d(x)d(y)). And the following solution to the problem came to his mind: to calculate the digital roots and check if this condition is met. However, Billy has doubts that this condition is sufficient. That's why he asks you to find out the amount of test examples for the given problem such that the algorithm proposed by Billy makes mistakes.", "input_spec": "The first line contains the only number N (1\u2009\u2264\u2009N\u2009\u2264\u2009106).", "output_spec": "Output one number \u2014 the amount of required A, B and C from the range [1,\u2009N].", "sample_inputs": ["4", "5"], "sample_outputs": ["2", "6"], "notes": "NoteFor the first sample the required triples are (3,\u20094,\u20093) and (4,\u20093,\u20093)."}, "positive_code": [{"source_code": "n=gets.to_i;s=0;c=[0]*9;(1..n).each{|i|s-=n/i;c[i%9]+=1};9.times{|i|9.times{|j|s+=c[i]*c[j]*c[i*j%9]}};puts s\n"}, {"source_code": "n=gets.to_i;s=0;c=[0]*9;(1..n).each{|i|s-=n/i;c[i%9]+=1};9.times{|i|9.times{|j|s+=c[i]*c[j]*c[i*j%9]}};puts s\n"}, {"source_code": "n=gets.to_i;s=0;c=[0]*9;(1..n).each{|i|s-=n/i;c[i%9]+=1};9.times{|i|9.times{|j|s+=c[i]*c[j]*c[i*j%9]}};puts s"}, {"source_code": "n=gets.to_i;s=0;c=[0]*9;(1..n).each{|i|s-=n/i;c[i%9]+=1};9.times{|i|9.times{|j|s+=c[i]*c[j]*c[i*j%9]}};puts s\n"}, {"source_code": "n=gets.to_i;s=0;c=[0]*9;(1..n).each{|i|s-=n/i;c[i%9]+=1};9.times{|i|9.times{|j|s+=c[i]*c[j]*c[i*j%9]}};puts s\n"}, {"source_code": "n=gets.to_i;s=0;c=[0]*9;(1..n).each{|i|s-=n/i;c[i%9]+=1};9.times{|i|9.times{|j|s+=c[i]*c[j]*c[i*j%9]}};puts s"}, {"source_code": "n=gets.to_i;s=0;c=[0]*9;(1..n).each{|i|s-=n/i;c[i%9]+=1};9.times{|i|9.times{|j|s+=c[i]*c[j]*c[i*j%9]}};puts s\n"}, {"source_code": "n=gets.to_i;s=0;c=[0]*9;(1..n).each{|i|s-=n/i;c[i%9]+=1};9.times{|i|9.times{|j|s+=c[i]*c[j]*c[i*j%9]}};puts s"}, {"source_code": "n=gets.to_i;s=0;c=[0]*9;(1..n).each{|i|s-=n/i;c[i%9]+=1};9.times{|i|9.times{|j|s+=c[i]*c[j]*c[i*j%9]}};puts s\n"}, {"source_code": "n=gets.to_i;s=0;c=[0]*9;(1..n).each{|i|s-=n/i;c[i%9]+=1};9.times{|i|9.times{|j|s+=c[i]*c[j]*c[i*j%9]}};puts s\n"}, {"source_code": "n=gets.to_i;s=0;c=[0]*9;(1..n).each{|i|s-=n/i;c[i%9]+=1};9.times{|i|9.times{|j|s+=c[i]*c[j]*c[i*j%9]}};puts s\n"}], "negative_code": [], "src_uid": "fc133fe6353089a0ebee08dec919f608"} {"nl": {"description": null, "input_spec": null, "output_spec": null, "sample_inputs": [], "sample_outputs": [], "notes": null}, "positive_code": [{"source_code": "puts \"no\""}, {"source_code": "puts(\"No\")"}, {"source_code": "puts \"NO\\n\""}, {"source_code": "puts \"NO\""}, {"source_code": "puts 'no'\n"}, {"source_code": "puts \"NO\""}, {"source_code": "puts \"No\"\n"}, {"source_code": "puts\"NO\""}, {"source_code": "puts \"NO\""}, {"source_code": "print \"NO\""}], "negative_code": [{"source_code": "puts \"YES\\n\""}], "src_uid": "b6a30a725754a4b4daeb6e87986e28a4"} {"nl": {"description": "Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network. But yesterday, he came to see \"her\" in the real world and found out \"she\" is actually a very strong man! Our hero is very sad and he is too tired to love again now. So he came up with a way to recognize users' genders by their user names.This is his method: if the number of distinct characters in one's user name is odd, then he is a male, otherwise she is a female. You are given the string that denotes the user name, please help our hero to determine the gender of this user by his method.", "input_spec": "The first line contains a non-empty string, that contains only lowercase English letters \u2014 the user name. This string contains at most 100 letters.", "output_spec": "If it is a female by our hero's method, print \"CHAT WITH HER!\" (without the quotes), otherwise, print \"IGNORE HIM!\" (without the quotes).", "sample_inputs": ["wjmzbmr", "xiaodao", "sevenkplus"], "sample_outputs": ["CHAT WITH HER!", "IGNORE HIM!", "CHAT WITH HER!"], "notes": "NoteFor the first example. There are 6 distinct characters in \"wjmzbmr\". These characters are: \"w\", \"j\", \"m\", \"z\", \"b\", \"r\". So wjmzbmr is a female and you should print \"CHAT WITH HER!\"."}, "positive_code": [{"source_code": " x = gets.chomp\n hash = Hash.new\n x.each_char do |c|\n hash[c] = 0 if hash[c] == nil\n hash[c] += 1\n end\n puts \"CHAT WITH HER!\" if hash.count % 2 == 0\n puts \"IGNORE HIM!\" if hash.count % 2 != 0"}, {"source_code": "#$stdin=File.open('input.txt')\n#$stdout=File.open('output.txt', 'w')\ns=gets.to_s\na=Array.new\nfor i in 1..s.size-1\n\ta<<<[\"IGNORE HIM!\",\"CHAT WITH HER!\"][gets.chars.uniq.size%2]\n"}, {"source_code": "#rextester.com:2.3.1--codeforces.com:2.0.0p645\nputs gets.chomp.chars.uniq.size%2==0?'CHAT WITH HER!':'IGNORE HIM!'"}, {"source_code": "inp = gets.chomp\nif inp.split('').uniq.length.odd?\n puts 'IGNORE HIM!'\nelse\n puts 'CHAT WITH HER!'\nend"}, {"source_code": "puts gets.split(//).uniq.size.odd? ? 'CHAT WITH HER!' : 'IGNORE HIM!'\n"}, {"source_code": "username = gets.chomp\nputs (username.split(//).uniq.length % 2 == 1)? \"IGNORE HIM!\" : \"CHAT WITH HER!\"\n"}, {"source_code": "s = gets.chomp.chars\nputs s.uniq.count.odd? ? \"IGNORE HIM!\" : \"CHAT WITH HER!\""}, {"source_code": "puts gets.chomp.chars.uniq.size.even? ? 'CHAT WITH HER!': 'IGNORE HIM!'"}, {"source_code": "# http://codeforces.com/problemset/problem/236/A\n\nusername = gets.chomp\n\nif username.chars.to_a.uniq.length % 2 == 0\n puts \"CHAT WITH HER!\"\nelse\n puts \"IGNORE HIM!\"\nend"}, {"source_code": "s = gets.chomp.chars\nputs s.uniq.count.odd? ? \"IGNORE HIM!\" : \"CHAT WITH HER!\""}, {"source_code": "name = gets.chomp\n\nputs name.chars.sort.uniq.size.even? ? 'CHAT WITH HER!' : 'IGNORE HIM!'\n"}, {"source_code": "str = gets.chomp\nif str.chars.uniq.size.even? \n puts \"CHAT WITH HER!\"\nelse \n puts \"IGNORE HIM!\"\nend "}, {"source_code": "x = gets\nh = {}\nx.split(\"\").each { |e|\n h[e]=1\n}\nif !h.keys.count.odd?\n puts \"IGNORE HIM!\"\n else \n puts \"CHAT WITH HER!\"\nend \n\n"}, {"source_code": "$><<[\"IGNORE HIM!\",\"CHAT WITH HER!\"][gets.chars.uniq.size%2]"}, {"source_code": "puts gets.chomp.split(\"\").uniq.count.even? ? 'CHAT WITH HER!' : 'IGNORE HIM!'"}, {"source_code": "username = gets.strip\nL = username.length\ncheck = Array.new(26, false)\nfor i in 0...L\n check[username[i].ord-97] = true\nend\ncount = 0\nfor i in 0...26\n count += 1 if check[i]\nend\nif count%2 == 1\n print \"IGNORE HIM!\"\nelse\n print \"CHAT WITH HER!\"\nend"}, {"source_code": "require 'set'\nname = gets.split(//)\ns = Set.new\nname.each do |char|\n s.add(char)\nend\nif s.size.even?\n puts \"IGNORE HIM!\"\nelse\n puts \"CHAT WITH HER!\"\nend\n"}, {"source_code": "def BoyOrGirl(str)\n puts str.chars.uniq.length % 2 == 0 ? \"CHAT WITH HER!\" : \"IGNORE HIM!\"\nend\n\nstr = gets.chomp\nBoyOrGirl(str)"}, {"source_code": "puts gets.split(//).uniq.size.odd? ? 'CHAT WITH HER!' : 'IGNORE HIM!'\n"}, {"source_code": "if (gets.chomp.split(//).uniq.size % 2) == 1\nprint \"IGNORE HIM!\\n\"\nelse\nprint \"CHAT WITH HER!\\n\"\nend"}, {"source_code": "def BoyOrGirl(str)\n puts str.chars.uniq.length % 2 == 0 ? \"CHAT WITH HER!\" : \"IGNORE HIM!\"\nend\n\nstr = gets.chomp\nBoyOrGirl(str)"}, {"source_code": "puts gets.split('').uniq.size.odd? ? 'CHAT WITH HER!' : 'IGNORE HIM!'"}, {"source_code": "puts [\"IGNORE HIM!\",\"CHAT WITH HER!\"][gets.chars.uniq.size[0]]"}, {"source_code": "puts gets.chomp.split(\"\").uniq.join.length.%(2).to_s.include?(\"1\")?\"IGNORE HIM!\":\"CHAT WITH HER!\""}, {"source_code": "puts gets.split(//).uniq.size.odd? ? 'CHAT WITH HER!' : 'IGNORE HIM!'"}, {"source_code": "user_name = gets.chomp\ni = 0\nchar_arr = []\n\nwhile i < user_name.length do\n if char_arr.index(user_name.split('')[i]) == nil then\n\tchar_arr.push(user_name.split('')[i])\n end\n i+=1 \nend\nif char_arr.length % 2 == 0 then \n print 'CHAT WITH HER!'\nelsif \n print 'IGNORE HIM!'\nend\n"}, {"source_code": "puts (gets.split(//).uniq.count.even?) ? \"IGNORE HIM!\" : \"CHAT WITH HER!\"\n"}, {"source_code": "$><<[\"IGNORE HIM!\",\"CHAT WITH HER!\"][gets.chars.uniq.size%2]\n"}, {"source_code": "puts gets.split('').sort.uniq.size % 2==1 ? \"CHAT WITH HER!\" : \"IGNORE HIM!\""}, {"source_code": "input = gets\nputs input.split(//).uniq.count % 2 == 0 ? 'IGNORE HIM!' : 'CHAT WITH HER!'\n"}, {"source_code": "puts (gets.strip.split('').uniq.size.odd?)?'IGNORE HIM!':'CHAT WITH HER!'\n\n"}, {"source_code": "w = gets.chomp\nif w.scan(/./).uniq.size % 2 == 0\n puts \"CHAT WITH HER!\"\nelse\n puts \"IGNORE HIM!\"\nend"}, {"source_code": "#!/usr/bin/ruby\n\nstr = gets.chomp\ncnt = str.each_char.to_a.uniq.size\nif cnt.even?\n puts \"CHAT WITH HER!\"\nelse\n puts \"IGNORE HIM!\"\nend\n"}, {"source_code": "s = gets.strip.split(\"\").uniq\nans = s.length.odd?\nputs ans ? \"IGNORE HIM!\" : \"CHAT WITH HER!\"\n"}, {"source_code": "printf(gets.chomp.each_char.to_a.uniq.size.odd? ? 'IGNORE HIM!' : 'CHAT WITH HER!')"}, {"source_code": "#rextester.com:2.3.1--codeforces.com:2.0.0p645\nputs gets.chomp.chars.uniq.length%2==0?'CHAT WITH HER!':'IGNORE HIM!'"}, {"source_code": "$><<[\"IGNORE HIM!\",\"CHAT WITH HER!\"][gets.chars.uniq.size%2]\n"}, {"source_code": "$><<[\"IGNORE HIM!\",\"CHAT WITH HER!\"][gets.chars.uniq.size%2]"}, {"source_code": "if gets.chars.to_a.uniq.size % 2 == 0 then puts 'IGNORE HIM!' \nelse puts 'CHAT WITH HER!'\nend"}, {"source_code": "puts gets.chomp.chars.uniq.size%2!=0 ? \"IGNORE HIM!\" : \"CHAT WITH HER!\""}, {"source_code": "name = gets.strip()\nif name.size() <= 100\n array_of_characters = name.chars.uniq\n\tif array_of_characters.size % 2 == 0\n\t\tputs \"CHAT WITH HER!\"\n\telse\n\t\tputs \"IGNORE HIM!\"\n\tend\nend\n"}, {"source_code": "if gets.chomp.split(//).uniq.size % 2 == 0 then puts \"CHAT WITH HER!\" else puts \"IGNORE HIM!\" end\n"}, {"source_code": "user_name = gets.chomp\ni = 0\nchar_arr = []\n\nwhile i < user_name.length do\n if char_arr.index(user_name.split('')[i]) == nil then\n\tchar_arr.push(user_name.split('')[i])\n end\n i+=1 \nend\nif char_arr.length % 2 == 0 then \n print 'CHAT WITH HER!'\nelsif \n print 'IGNORE HIM!'\nend\n"}, {"source_code": "puts ['IGNORE HIM!','CHAT WITH HER!'][gets.chars.to_a.uniq.size%2]\n\n"}, {"source_code": "input = gets\nputs input.split(//).uniq.count % 2 == 0 ? 'IGNORE HIM!' : 'CHAT WITH HER!'\n"}, {"source_code": "puts gets.chomp.split(\"\").uniq.count.even? ? 'CHAT WITH HER!' : 'IGNORE HIM!'"}, {"source_code": "if gets.chomp.split(\"\").uniq.size.odd?\n puts \"IGNORE HIM!\"\nelse\n puts \"CHAT WITH HER!\"\nend"}, {"source_code": "# Codeforces Round #146\n# Problem A -- Boy or Girl\nputs gets.split(//).uniq.size.odd? ? \"CHAT WITH HER!\" : \"IGNORE HIM!\"\n"}, {"source_code": "puts gets.split('').sort.uniq.size % 2==1 ? \"CHAT WITH HER!\" : \"IGNORE HIM!\""}, {"source_code": "printf(gets.chomp.each_char.to_a.uniq.size.odd? ? 'IGNORE HIM!' : 'CHAT WITH HER!')"}, {"source_code": "if gets.strip.split('').to_a.uniq.size % 2 == 0\n puts \"CHAT WITH HER!\"\nelse\n puts \"IGNORE HIM!\"\nend"}, {"source_code": "#!/usr/bin/ruby\nputs ['IGNORE HIM!','CHAT WITH HER!'][gets.chars.uniq.size%2]"}, {"source_code": "def tram ()\n n = gets.chomp\n n = n.split(\"\")\n n = n.uniq\n if n.length % 2 == 0\n print \"CHAT WITH HER!\"\n else \n print \"IGNORE HIM!\"\n end\nend\n\ntram"}, {"source_code": "if gets.chomp.split(//).uniq.count.odd?\n puts \"IGNORE HIM!\"\nelse\n puts \"CHAT WITH HER!\"\nend"}, {"source_code": "name = gets.strip\nregistered_char = []\ncounter = 0\n\nname.each_char do |char|\n next if registered_char.include?(char)\n\n registered_char.push(char)\n counter += 1\nend\n\nif counter.odd?\n puts 'IGNORE HIM!'\nelse\n puts 'CHAT WITH HER!'\nend\n"}, {"source_code": "puts STDIN.read.strip.split(//).uniq.length % 2 == 0 ? \"CHAT WITH HER!\" : \"IGNORE HIM!\"\n"}, {"source_code": "puts (gets.chomp.split('').uniq.length.odd?) ? \"IGNORE HIM!\" : \"CHAT WITH HER!\"\n"}, {"source_code": "$><<[\"IGNORE HIM!\",\"CHAT WITH HER!\"][gets.chars.uniq.size%2]\n"}, {"source_code": "puts gets.split('').sort.uniq.size % 2==1 ? \"CHAT WITH HER!\" : \"IGNORE HIM!\""}, {"source_code": "puts ['IGNORE HIM!','CHAT WITH HER!'][gets.chars.to_a.uniq.size%2]\n\n"}, {"source_code": "hashed = Hash.new(0)\ninp = gets.chomp.split(\"\").each { |item| hashed[item] += 1 }\nif hashed.size % 2 == 0\n puts \"CHAT WITH HER!\"\nelse \n puts \"IGNORE HIM!\"\nend\n"}, {"source_code": "hashed = Hash.new(0)\ninp = gets.chomp.split(\"\").each { |item| hashed[item] += 1 }\nif hashed.size % 2 == 0\n puts \"CHAT WITH HER!\"\nelse \n puts \"IGNORE HIM!\"\nend\n"}, {"source_code": "$><<[\"IGNORE HIM!\",\"CHAT WITH HER!\"][gets.chars.uniq.size%2]\n"}, {"source_code": "puts ['IGNORE HIM!','CHAT WITH HER!'][gets.split('').uniq.size%2]\n\n"}, {"source_code": "$><<[\"IGNORE HIM!\",\"CHAT WITH HER!\"][gets.chars.uniq.size%2]\n"}, {"source_code": "puts gets.split(//).uniq.size.odd? ? 'CHAT WITH HER!' : 'IGNORE HIM!'\n"}, {"source_code": "# Codeforces Round #146\n# Problem A -- Boy or Girl\nputs gets.split(//).uniq.size.odd? ? \"CHAT WITH HER!\" : \"IGNORE HIM!\"\n"}, {"source_code": "if gets.chomp.split(//).uniq.size % 2 == 0 then puts \"CHAT WITH HER!\" else puts \"IGNORE HIM!\" end\n"}, {"source_code": "x = gets\nh = {}\nx.split(\"\").each { |e|\n h[e]=1\n}\nif !h.keys.count.odd?\n puts \"IGNORE HIM!\"\n else \n puts \"CHAT WITH HER!\"\nend \n\n"}, {"source_code": "puts [\"CHAT WITH HER!\", \"IGNORE HIM!\"][gets.chomp.chars.to_a.uniq{|x| x}.length.odd? ? 1 : 0]"}, {"source_code": "username = gets.strip\nL = username.length\ncheck = Array.new(26, false)\nfor i in 0...L\n check[username[i].ord-97] = true\nend\ncount = 0\nfor i in 0...26\n count += 1 if check[i]\nend\nif count%2 == 1\n print \"IGNORE HIM!\"\nelse\n print \"CHAT WITH HER!\"\nend"}, {"source_code": "puts ['IGNORE HIM!','CHAT WITH HER!'][gets.split('').uniq.size%2]\n\n"}, {"source_code": "if gets.chomp.split('').uniq.size%2 == 0\n puts \"CHAT WITH HER!\"\nelse\n puts \"IGNORE HIM!\"\nend"}, {"source_code": "puts gets.chomp.chars.uniq.size % 2 == 0 ? \"CHAT WITH HER!\" : \"IGNORE HIM!\"\n"}, {"source_code": "puts gets.split('').uniq.size.odd? ? 'CHAT WITH HER!' : 'IGNORE HIM!'"}, {"source_code": "#!/usr/bin/ruby\n\nstr = gets.chomp\ncnt = str.each_char.to_a.uniq.size\nif cnt.even?\n puts \"CHAT WITH HER!\"\nelse\n puts \"IGNORE HIM!\"\nend\n"}, {"source_code": "u = $stdin.readline.scan(/./).uniq\n\nif u.count % 2 == 1\n puts \"IGNORE HIM!\"\nelse\n puts \"CHAT WITH HER!\"\nend"}, {"source_code": "s = gets.split(//).uniq\nputs (s.length % 2 == 1) ? \"CHAT WITH HER!\" : \"IGNORE HIM!\""}, {"source_code": "puts ['IGNORE HIM!','CHAT WITH HER!'][gets.split('').uniq.size%2]\n\n"}, {"source_code": "name = gets.chomp\namount = Array.new(26, 0)\nname.split(\"\").each { |char| amount[char.ord - 97] += 1 }\ncnt = 0\namount.each { |tmp| cnt += 1 if tmp > 0 }\nif cnt.even?\n\tputs \"CHAT WITH HER!\"\nelse\n\tputs \"IGNORE HIM!\"\nend"}, {"source_code": "puts gets.split('').sort.uniq.size % 2==1 ? \"CHAT WITH HER!\" : \"IGNORE HIM!\""}, {"source_code": "puts gets.chomp.chars.uniq.size.even? ? 'CHAT WITH HER!': 'IGNORE HIM!'"}, {"source_code": "# Codeforces Round #146\n# Problem A -- Boy or Girl\nputs gets.split(//).uniq.size.odd? ? \"CHAT WITH HER!\" : \"IGNORE HIM!\"\n"}, {"source_code": "puts ['IGNORE HIM!','CHAT WITH HER!'][gets.split('').uniq.size%2]\n\n"}, {"source_code": "puts ['CHAT WITH HER!','IGNORE HIM!'][gets.strip.split('').uniq.join('').length%2]"}, {"source_code": "puts (gets.strip.split('').uniq.size.odd?)?'IGNORE HIM!':'CHAT WITH HER!'\n\n"}, {"source_code": "x = gets\nh = {}\nx.split(\"\").each { |e|\n h[e]=1\n}\nif !h.keys.count.odd?\n puts \"IGNORE HIM!\"\n else \n puts \"CHAT WITH HER!\"\nend \n\n"}, {"source_code": "#!/usr/bin/ruby\n\nstr = gets.chomp\ncnt = str.each_char.to_a.uniq.size\nif cnt.even?\n puts \"CHAT WITH HER!\"\nelse\n puts \"IGNORE HIM!\"\nend\n"}, {"source_code": "string = gets.chomp.split(\"\")\n\narr = []\nfor i in (0..string.size-1)\n\tif arr.include?(string[i]) == false\n\t\tarr << string[i]\n\tend\nend\n\nif arr.count % 2 == 0\n\tprint \"CHAT WITH HER!\"\nelse\n\tprint \"IGNORE HIM!\"\nend"}, {"source_code": "puts ['CHAT WITH HER!','IGNORE HIM!'][gets.strip.split('').uniq.join('').length%2]"}, {"source_code": "$><<[\"IGNORE HIM!\",\"CHAT WITH HER!\"][gets.chars.uniq.size%2]"}, {"source_code": "puts gets.chomp.split(//).uniq.count.even? ? 'CHAT WITH HER!' : 'IGNORE HIM!'"}, {"source_code": "printf (gets.chomp.each_char.to_a.uniq.size % 2 == 0) ? 'CHAT WITH HER!' : 'IGNORE HIM!'"}, {"source_code": "puts (gets[0..-2].chars.to_a.uniq.count % 2 == 0 ? \"CHAT WITH HER!\" : \"IGNORE HIM!\")\n"}, {"source_code": "puts gets.chomp.split(\"\").uniq.length.even? ? \"CHAT WITH HER!\" : \"IGNORE HIM!\""}, {"source_code": "if gets.chomp.split(//).uniq.count.odd?\n puts \"IGNORE HIM!\"\nelse\n puts \"CHAT WITH HER!\"\nend"}, {"source_code": "x = gets\nh = {}\nx.split(\"\").each { |e|\n h[e]=1\n}\nif !h.keys.count.odd?\n puts \"IGNORE HIM!\"\n else \n puts \"CHAT WITH HER!\"\nend \n\n"}, {"source_code": "$><<[\"IGNORE HIM!\",\"CHAT WITH HER!\"][gets.chars.uniq.size%2]"}, {"source_code": "u = $stdin.readline.scan(/./).uniq\n\nif u.count % 2 == 1\n puts \"IGNORE HIM!\"\nelse\n puts \"CHAT WITH HER!\"\nend"}], "negative_code": [{"source_code": "#rextester.com:2.3.1--codeforces.com:2.0.0p645\nputs(gets.chars.uniq.size%2==0?'CHAT WITH HER':'IGNORE HIM')"}, {"source_code": "#rextester.com:2.3.1--codeforces.com:2.0.0p645\nputs gets.chars.uniq.size%2?'IGNORE HIM':'CHAT WITH HER'"}, {"source_code": "#rextester.com:2.3.1--codeforces.com:2.0.0p645\nputs(gets.chars.uniq.length%2==0?\"CHAT WITH HER\":\"IGNORE HIM\")"}, {"source_code": "#rextester.com:2.3.1--codeforces.com:2.0.0p645\nputs gets.chars.uniq.size%2==0?'CHAT WITH HER':'IGNORE HIM'"}, {"source_code": "#rextester.com:2.3.1--codeforces.com:2.0.0p645\nputs(gets.chomp.chars.uniq.length%2==0?'CHAT WITH HER':'IGNORE HIM')"}, {"source_code": "#rextester.com:2.3.1--codeforces.com:2.0.0p645\nputs gets.chomp.split(//).uniq.length%2==0?'CHAT WITH HER':'IGNORE HIM'"}, {"source_code": "#rextester.com:2.3.1--codeforces.com:2.0.0p645\nputs gets.split(//).uniq.length%2==0?'CHAT WITH HER':'IGNORE HIM'"}, {"source_code": "#rextester.com:2.3.1--codeforces.com:2.0.0p645\nputs(gets.chars.uniq.length%2==0?'CHAT WITH HER':'IGNORE HIM')"}, {"source_code": "require \"set\"\n\nset = Set.new(gets.chars)\nset.each {|x| puts x}\nif set.size() % 2 == 0\n puts \"CHAT WITH HER!\"\nelse\n puts \"IGNORE HIM!\"\nend"}, {"source_code": "require \"set\"\n\nset = Set.new(gets.chop.chars)\nset.each {|x| puts x}\nif set.size() % 2 == 0\n puts \"CHAT WITH HER!\"\nelse\n puts \"IGNORE HIM!\"\nend"}, {"source_code": "require \"set\"\n\ns = gets\nset = Set.new\ns.each_char {|c| set << c}\nif s.size() % 2 == 0\n puts \"CHAT WITH HER!\"\nelse\n puts \"IGNORE HIM!\"\nend"}, {"source_code": "uname = gets.chomp\nusername = uname.split(\"\")\n\ncount = uname.length.to_i\nusername.each do |n|\n\tcount = count - username.count(n) + 1\n\tif username.count(n) != 1\n\t\ti = username.index(n)\n\t\twhile i < uname.length.to_i\n\t\t\tif n == username[i+1]\n\t\t\t\tusername.delete_at(i+1)\n\t\t\tend\n\t\t\ti += 1\n\t\tend\n\tend\nend\n\nif username.size%2 == 0\n\tputs \"CHAT WITH HER!\"\nelse\n\tputs \"IGNORE HIM!\"\nend"}, {"source_code": "uname = gets.chomp\nusername = uname.split(\"\")\n\ncount = uname.length.to_i\nusername.each do |n|\n\tcount = count - username.count(n) + 1\n\tif username.count(n) > 1\n\t\ti = username.index(n)\n\t\twhile i < uname.length.to_i - 1\n\t\t\tif n == username[i+1]\n\t\t\t\tusername.delete_at(i+1)\n\t\t\tend\n\t\t\ti += 1\n\t\tend\n\tend\nend\nputs username.size\nif username.size%2 == 0\n\tputs \"CHAT WITH HER!\"\nelse\n\tputs \"IGNORE HIM!\"\nend"}, {"source_code": "uname = gets.chomp\nusername = uname.split(\"\")\n\ni = 0\ncount = uname.length.to_i\nusername.each do |n|\n\tcount = count - username.count(n) + 1\n\tif username.count(n) != 1\n\t\ti = username.index(n)\n\t\twhile i < uname.length.to_i\n\t\t\tif n == username[i]\n\t\t\t\tusername.delete_at(i)\n\t\t\tend\n\t\t\ti += 1\n\t\tend\n\tend\nend\n\nif count%2 == 0\n\tputs \"CHAT WITH HER!\"\nelse\n\tputs \"IGNORE HIM!\"\nend"}, {"source_code": "uname = gets.chomp\nusername = uname.split(\"\")\n\ncount = uname.length.to_i\nusername.each do |n|\n\tcount = count - username.count(n) + 1\n\tif username.count(n) > 1\n\t\ti = username.index(n)\n\t\twhile i < uname.length.to_i - 1\n\t\t\tif n == username[i+1]\n\t\t\t\tusername.delete_at(i+1)\n\t\t\tend\n\t\t\ti += 1\n\t\tend\n\tend\nend\nif username.size%2 == 0\n\tputs \"CHAT WITH HER!\"\nelse\n\tputs \"IGNORE HIM!\"\nend"}, {"source_code": "uname = gets.chomp\nusername = uname.split(\"\")\n\ni = 0\ncount = uname.length.to_i\nusername.each do |n|\n\tcount = count - username.count(n) + 1\n\tif username.count(n) != 1\n\t\ti = username.index(n)\n\t\twhile i+1 < uname.length.to_i\n\t\t\tif n == username[i+1]\n\t\t\t\tusername.delete_at(i+1)\n\t\t\tend\n\t\t\ti += 1\n\t\tend\n\tend\nend\n\nif count%2 == 0\n\tputs \"CHAT WITH HER!\"\nelse\n\tputs \"IGNORE HIM!\"\nend"}, {"source_code": "x = gets\nh = {}\nx.split(\"\").each { |e|\n h[e]=1\n}\nif h.keys.count.odd?\n puts \"IGNORE HIM!\"\n else \n puts \"CHAT WITH HER!\"\nend \n\n"}, {"source_code": "# http://codeforces.com/problemset/problem/236/A\n\nchars = gets.chomp\nalready = {}\ndups = 0\nchars.each_char do |c|\n if already[c] == true\n dups = dups + 1\n else\n already[c] = true\n end\nend\n\nuniq = chars.length - dups\n\nif uniq % 2 == 0\n p 'CHAT WITH HER!'\nelse\n p 'IGNORE HIM!'\nend\n"}, {"source_code": "inp = gets.chomp\nif inp.length.odd?\n puts 'CHAT WITH HER!'\nelse\n puts 'IGNORE HIM!'\nend"}, {"source_code": "inp = gets.chomp\nif inp.length.odd?\n p 'CHAT WITH HER!'\nelse\n p 'IGNORE HIM!'\nend"}, {"source_code": "inp = gets.chomp\nif inp.split('').uniq.length.odd?\n puts 'CHAT WITH HER!'\nelse\n puts 'IGNORE HIM!'\nend"}, {"source_code": "inp = gets.chomp\nif inp.length.odd?\n p 'IGNORE HIM!'\nelse\n p 'CHAT WITH HER!'\nend"}, {"source_code": "puts ['IGNORE HIM!','CHAT WITH HER!'][gets.strip.length%2]"}, {"source_code": "h = {}\ngets.split('').each { |c| h[c] = 1 }\nputs h.keys.count.even? ? 'CHAT WITH HER!' : 'IGNORE HIM!'"}, {"source_code": "puts gets.split('').uniq.size.even? ? 'CHAT WITH HER!' : 'IGNORE HIM!'"}, {"source_code": "a=gets.chomp\n0.upto(a.length-1) do |i|\n(i+1).upto(a.length-1) do|j|\nif a[i] ==a [j]\na=a[0..j-1]+a[j+1..a.length-1]\nend\nend\nend\nif a.length%2==0\nputs \"CHAT WITH HER!\"\nelse \nputs \"IGNORE HIM!\" \nend"}, {"source_code": "p(gets.chomp.each_char.to_a.uniq.size % 2 == 0 ? 'CHAT WITH HER!' : 'IGNORE HIM!')"}, {"source_code": "output = (gets.chomp.each_char.to_a.uniq.size % 2 == 0) ? 'CHAT WITH HER!' : 'IGNORE HIM!'\np output"}, {"source_code": "p(gets.chomp.each_char.to_a.uniq.size % 2 == 0 ? \"CHAT WITH HER!\" : \"IGNORE HIM!\")"}, {"source_code": "n = gets.to_s\nar = []\nar = n.split(\"\").map(&:to_s)\nj = ar.uniq.count \n\nif j%2 == 0\n puts \"CHAT WITH HER!\"\nelse\n puts \"IGNORE HIM!\"\nend\nputs j\n"}, {"source_code": "n = gets.to_s\nar = []\nar = n.split(\"\").map(&:to_s)\nj = ar.uniq.count-1\n\nif j%2 == 0\n puts \"CHAT WITH HER!\"\nelse\n puts \"IGNORE HIM!\"\nend\nputs j\n"}, {"source_code": "n = gets.to_s\nar = []\nar = n.split(\"\").map(&:to_s)\nj = ar.uniq.count - 1\n\nif j%2 == 0\n puts \"CHAT WITH HER!\"\nelse\n puts \"IGNORE HIM!\"\nend\nputs j\n"}, {"source_code": "n = gets.to_s\nar = []\nar = n.split(\"\").map(&:to_s)\nj = ar.uniq.count \n\nif j%2 == 0\n puts \"CHAT WITH HER!\"\nelse\n puts \"IGNORE HIM!\"\nend\n\n"}, {"source_code": "s = gets.split(//).uniq!\nputs (s.length % 2 == 1) ? \"CHAT WITH HER!\" : \"CHAT WITH HIM!\"\n"}, {"source_code": "# while (s=gets.chomp()) != \"42\" do puts s end\n\ns=gets.chomp()\nc= s.split(//).uniq\n# s.to_a\n# c=b.uniq\n\n# a=s.uniq\nif c.length%2==0\n puts \"IGNORE HIM!\"\nelse\n puts \"CHAT WITH HER!\"\nend"}, {"source_code": "# while (s=gets.chomp()) != \"42\" do puts s end\n\ns=gets.chomp()\nc= s.split(//).uniq\n# s.to_a\n# c=b.uniq\n\n# a=s.uniq\nputs c.length\nif c.length%2==0\n puts \"CHAT WITH HER!\"\nelse\n \n puts \"IGNORE HIM!\"\nend"}, {"source_code": "name = gets.strip()\nif name.size() <= 100\n\tif name.size() % 2 == 0\n\t\tputs \"CHAR WITH HER!\"\n\telse\n\t\tputs \"IGNORE HIM!\"\n\tend\nend"}, {"source_code": "name = gets.strip()\nif name.size() <= 100\n array_of_characters = name.chars.uniq\n\tif array_of_characters.size % 2 == 0\n\t\tputs \"CHAR WITH HER!\"\n\telse\n\t\tputs \"IGNORE HIM!\"\n\tend\nend\n"}, {"source_code": "puts [\"CHAT WITH HER!\",\"IGNORE HIM!\"][gets.chars.uniq.size[0]]"}, {"source_code": "puts [\"CHAT WITH HER!\",\"IGNORE HIM!\"][\"ab\".chars.uniq.size[0]]"}, {"source_code": "puts gets.chomp.length.even? ? \"CHAT WITH HER!\" : \"IGNORE HIM\""}, {"source_code": "#$stdin=File.open('input.txt')\n#$stdout=File.open('output.txt', 'w')\ns=gets.to_s\nif s.size%2==0 then\nputs \"CHAT WITH HER!\" \nelse\nputs \"IGNORE HIM!\" \nend\n\n\n\n\n\n\n\n\n\n\t\n\n\n\n\n\n\t\n\t\n\t\n"}, {"source_code": "#$stdin=File.open('input.txt')\n#$stdout=File.open('output.txt', 'w')\ns=gets.to_s\nif s.size%2!=0 then\nputs \"CHAT WITH HER!\" \nelse\nputs \"IGNORE HIM!\" \nend\n\n\n\n\n\n\n\n\n\n\t\n\n\n\n\n\n\t\n\t\n\t\n"}, {"source_code": "p(gets.chomp.split.uniq.size.odd? ? 'IGNORE HIM!' : 'CHAT WITH HER!')"}, {"source_code": "str = gets.chomp.each_char\np(str.take(str.count).size.odd? ? 'IGNORE HIM!' : 'CHAT WITH HER!')"}, {"source_code": "p(gets.chomp.each_char.to_a.uniq.size.odd? ? 'IGNORE HIM!' : 'CHAT WITH HER!')"}], "src_uid": "a8c14667b94b40da087501fd4bdd7818"} {"nl": {"description": "You are given a string s consisting of n lowercase Latin letters. You have to type this string using your keyboard.Initially, you have an empty string. Until you type the whole string, you may perform the following operation: add a character to the end of the string. Besides, at most once you may perform one additional operation: copy the string and append it to itself.For example, if you have to type string abcabca, you can type it in 7 operations if you type all the characters one by one. However, you can type it in 5 operations if you type the string abc first and then copy it and type the last character.If you have to type string aaaaaaaaa, the best option is to type 4 characters one by one, then copy the string, and then type the remaining character.Print the minimum number of operations you need to type the given string.", "input_spec": "The first line of the input containing only one integer number n (1\u2009\u2264\u2009n\u2009\u2264\u2009100)\u00a0\u2014 the length of the string you have to type. The second line containing the string s consisting of n lowercase Latin letters.", "output_spec": "Print one integer number\u00a0\u2014 the minimum number of operations you need to type the given string.", "sample_inputs": ["7\nabcabca", "8\nabcdefgh"], "sample_outputs": ["5", "8"], "notes": "NoteThe first test described in the problem statement.In the second test you can only type all the characters one by one."}, "positive_code": [{"source_code": "n = gets.to_i\ns = gets.strip\nd = Array.new(n + 1) { [Float::INFINITY] * 2 }\nd[0][0] = 0\nn.times do |i|\n 2.times do |j|\n d[i + 1][j] = [d[i + 1][j], d[i][j] + 1].min\n end\n if i + i <= n && s[0, i] == s[i, i]\n d[i + i][1] = [d[i + i][1], d[i][0] + 1].min\n end\nend\np d[-1].min\n"}, {"source_code": "n = gets.to_i\ns = gets.chomp\nmax = 0\nfor i in 0..n / 2\n\tmax = s[0..i] == s[i + 1..i * 2 + 1] ? i : max\nend\nputs n - max"}], "negative_code": [{"source_code": "n = gets.to_i - 1\ns = gets.chomp\nmax = 0\nfor i in 0..n / 2\n\tmax = s[i+1..n+1][s[0..i]] != nil ? i : max\nend\nputs n - max + 1"}, {"source_code": "n = gets.to_i - 1\ns = gets.chomp\nmax = 0\nfor i in 0..n / 2\n\tmax = s[s[0..i] * 2] != nil ? i : max\nend\nputs n - max + 1"}], "src_uid": "ed8725e4717c82fa7cfa56178057bca3"}