{"source_code": "s = gets.to_i\na = 1\nans = 0\nwhile a < s\n ans += 1\n a *= 100\nend\nputs ans", "src_uid": "d8ca1c83b431466eff6054d3b422ab47"} {"source_code": "n = gets.strip.to_i\nhome = gets.strip\ncount_home = count_away = 0\nn.times do\n departure, arrival = gets.strip.split(\"->\")\n count_home += 1 if departure == home\n count_away += 1 if arrival == home\nend\nat_home = count_home == count_away\nif at_home\n puts \"home\"\nelse\n puts \"contest\"\nend\n", "src_uid": "51d1c79a52d3d4f80c98052b6ec77222"} {"source_code": "x,y,z = gets.split.map(&:to_i)\na,b,c = gets.split.map(&:to_i)\n\ndef check_if_sufficiant(x,y,z,a,b,c)\n a = a-x\n return 'No' if (a < 0)\n return 'No' if (a+b < y)\n return 'No' if (a+b+c-y < z)\n return 'Yes'\nend\n\nputs check_if_sufficiant(x,y,z,a,b,c)", "src_uid": "d54201591f7284da5e9ce18984439f4e"} {"source_code": "def f(n)\n\tif n==1\n\t\treturn X\n\telsif n==2\n\t\treturn X+[X,Y].min\n\telsif n%2==0\n\t\treturn f(n/2)+[Y,X*(n-n/2)].min\n\telse\n\t\treturn X+[f(n+1),f(n-1)].min\n\tend\nend\nN,X,Y=gets.split.map(&:to_i)\np f(N)", "src_uid": "0f270af00be2a523515d5e7bd66800f6"} {"source_code": "nk = gets.chomp.split(\" \")\nn = nk[0].to_i\nk = nk[1].to_i\narr = gets.chomp.split(\" \").map(&:to_i)\n\nhash = Hash.new(0)\n\nuniqarr = arr.uniq\narr.each do |elem|\n hash[elem]+=1\nend\n\nmax = hash.values.max\ndishno = (max.to_f/k).ceil\n\ncount = 0\n\n#every set of utensils is the same\n\nhash.values.each do |z|\n count+= k*dishno-z\nend\n\nputs count\n\n", "src_uid": "c03ff0bc6a8c4ce5372194e8ea18527f"} {"source_code": "#!/usr/bin/ruby\n# coding: utf-8\nn, m = gets.split.map(&:to_i)\nputs [n, m, (n + m) / 3].min\n", "src_uid": "0718c6afe52cd232a5e942052527f31b"} {"source_code": "gets\nb=0\nc=0\ngets.split.map{|e| \n\te=e.to_i\n\te>0? b+=e : c+=e}\np b-c\n\n", "src_uid": "4b5d14833f9b51bfd336cc0e661243a5"} {"source_code": "n=gets.to_i;x,y=2,3;n.times{x,y=y,(x+y)%1000000007};p x-2\n", "src_uid": "5c4bd12df3915186a7b506c2060db125"} {"source_code": "c,r=$<.map{|x| x.size-3},[]\nc.each_with_index do |v,i|\n\tcc=c[i+1..-1]+(i>0?c[0..i-1]:[])\n\tr<<(i+'A'.ord).chr if c[i]>=2*cc.max || 2*c[i]<=cc.min\nend\nputs r.size!=1?'C':r[0]", "src_uid": "30725e340dc07f552f0cce359af226a4"} {"source_code": "require 'prime'\n\na,b = gets.split.map(&:to_i)\nif a != b\n g = (a-b).abs\nelse\n g = a\nend\nx = Prime.prime_division(g)\nm = a.lcm(b)\nans = 0\n\n$p = []\n\ndef div(c,d,i)\n if i == d.size\n $p << c\n else\n div(c,d,i+1)\n d[i][1].times do |j|\n div(c*(d[i][0]**(j+1)),d,i+1)\n end\n end\nend\n\ndiv(1,x,0)\n$p.sort!\n$p.each do |k|\n l = (k-a%k)%k\n if m > (a+l)*(b+l)/k\n m = (a+l)*(b+l)/k\n ans = l\n end\nend\nputs ans\n", "src_uid": "414149fadebe25ab6097fc67663177c3"} {"source_code": "n, k = gets.split.map(&:to_i)\nar = gets.split.map(&:to_i)\nun = ar.uniq\nif un.size < k\n puts \"NO\"\nelse\n puts\"YES\"\n un.map!{|i| ar.find_index(i)+1}\n puts un[0..(k-1)].join(\" \")\nend", "src_uid": "5de6574d57ab04ca195143e08d28d0ad"} {"source_code": "a, b, w, x, c = gets.split.map &:to_i\n\ngo = Array.new(w + 1, -1)\nval = []\n\nwhile go[b] == -1\n b = go[b] = if b >= x then val << 1; b - x else val << 0; b + w - x end\nend\n\nif c <= a\n puts 0\nelse\n x, y, z, ans = 0, 0, 0, 1e100\n val.each { |v| x += v }\n\n c -= a\n val.each { |v|\n y += v\n z += 1\n if (c - y) % x == 0\n tmp = (c - y) / x * val.size + z\n ans = tmp if tmp < ans\n end\n }\n puts ans\nend\n", "src_uid": "a1db3dd9f8d0f0cad7bdeb1780707143"} {"source_code": "n = gets.to_i\nk = gets.to_i\na = gets.to_i\nb = gets.to_i\n\ns=0\n\nunless k==1\n\n until n==0\n \n if n%k==0\n \n unless ((n-(n/k))*a) >= b\n s=s+(n-(n/k))*a\n n=n/k\n \n else\n s=s+b\n n=n/k\n end\n \n elsif n input_pluses || output_minuses > input_minuses then\n probability = 0\nelse\n diff_pluses = input_pluses - output_pluses\n diff_minuses = input_minuses - output_minuses\n combinations = factorial(output_questions)/(factorial(diff_pluses) * factorial(output_questions - diff_pluses))\n # puts combinations\n # puts 2**output_questions\n probability = combinations/2**output_questions.to_f\n\nend\nputs probability\n\n", "src_uid": "f7f68a15cfd33f641132fac265bc5299"} {"source_code": "n, k = gets.strip.split(' ').map(&:to_i);\na = gets.strip.split(' ').map(&:to_i);\nan = 0\nk -= 1\n(0...n).each { |e|\n ok1 = a[k + e] if k + e < n\n ok2 = a[k - e] if (k - e) >= 0\n if e == 0 && ok1 == 1\n an += 1\n next\n end\n next if ok1.nil? && ok2.nil?\n cnt = 0\n if !ok1.nil?\n next if ok1.zero?\n cnt += 1 if !ok1.zero?\n end\n if !ok2.nil?\n next if ok2.zero?\n cnt += 1 if !ok2.zero?\n end\n an += cnt\n}\nputs an", "src_uid": "4840d571d4ce6e1096bb678b6c100ae5"} {"source_code": "def almostP n\n res = 0\n primes = [2]\n for i in 3..(n/2)\n isP = true\n primes.each do |x|\n isP = false if i%x == 0\n end\n primes << i if isP\n end\n for i in 1..n\n np = 0\n primes.each do |x|\n np += 1 if i%x == 0\n end\n res += 1 if np == 2\n end\n return res\nend\nn = gets.to_i\nputs almostP(n)\n", "src_uid": "356666366625bc5358bc8b97c8d67bd5"} {"source_code": "interesting_min_numbers = gets.to_i\n\nincreasing_order = gets.strip.split(' ').map(&:to_i)\n\ndef watch_minutes(increasing_order)\n start_time = 0\n\n increasing_order.each do |order|\n is_boring = order - start_time > 15\n return start_time + 15 if is_boring\n start_time = order\n end\n\n [start_time + 15, 90].min\nend\n\nputs watch_minutes(increasing_order)\n", "src_uid": "5031b15e220f0ff6cc1dd3731ecdbf27"} {"source_code": "k = gets.to_i\ns = gets.chomp\nz = s.count(\"0\")\nif z != (k-z)\n p 1\n puts s\nelse\n p 2\n puts \"#{s[0]} #{s[1,k-1]}\"\nend\n", "src_uid": "4ebed264d40a449602a26ceef2e849d1"} {"source_code": "n=gets.to_i;z=9**9;1.upto(n){|i|x,y,o=n,i,0;(o+=x/y)&&(x,y=y,x%y)while y>0;x==1&&z>o&&z=o};p z-1", "src_uid": "75739f77378b21c331b46b1427226fa1"} {"source_code": "def solve(a)\n return a if a < 10\n l, r = a, a % 10\n while l >= 10\n l /= 10\n end\n ans = a / 10 + 9\n ans -= 1 if r < l\n return ans\nend\n\nl, r = gets.split.map { |i| i.to_i }\nputs solve(r) - solve(l - 1)", "src_uid": "9642368dc4ffe2fc6fe6438c7406c1bd"} {"source_code": "#!/usr/bin/env ruby\nclass Integer\n def cnt\n res = 0\n t = self\n while t != 0\n res += 1 if t.odd?\n t >>= 1\n end\n res\n end\nend\nMAP = {}\nMAP['R'] = 0; MAP['G'] = 1; MAP['B'] = 2; MAP['Y'] = 3; MAP['W'] = 4\n_ = gets.to_i\nall = gets.split.uniq.map { |x| MAP[x[0]] * 5 + x[1].to_i - 1 }\nans = 10\n(1 << 5).times do |i|\n (1 << 5).times do |j|\n flag = true\n all.each do |x|\n all.each do |y|\n next if x == y\n a, b = x.divmod(5)\n c, d = y.divmod(5)\n next if a != c && (i & (1 << a) > 0 || i & (1 << c) > 0)\n next if b != d && (j & (1 << b) > 0 || j & (1 << d) > 0)\n flag = false\n break\n end\n break unless flag\n end\n next unless flag\n now = i.cnt + j.cnt\n ans = now < ans ? now : ans\n end\nend\nputs ans\n", "src_uid": "3b12863997b377b47bae43566ec1a63b"} {"source_code": "n = gets.to_i\nx = gets.split.map &:to_i\ny = gets.split.map &:to_i\nputs x.inject(0) { |s, x| s + x } >= y.inject(0) { |s, x| s + x } ? 'Yes' : 'No'\n", "src_uid": "e0ddac5c6d3671070860dda10d50c28a"} {"source_code": "v = gets.split.map(&:to_i)\n\nputs ( v[1] * v[2] + (v[0]-1) * (v[1] + v[2]-1))", "src_uid": "8ab25ed4955d978fe20f6872cb94b0da"} {"source_code": "=begin\n , \\ / ,\n / \\ )\\__/( / \\\n / \\ (_\\ /_) / \\\n ____/_____\\__\\@ @/___/_____\\____\n | |\\../| |\n | \\VV/ |\n | ------hoi------- |\n |_________________________________|\n | /\\ / \\\\ \\ /\\ |\n | / V )) V \\ |\n |/ ` // ' \\|\n ` V '\n=end\n\na, b, m = gets.split.map{|e| e.to_f}\nvx, vy, vz = gets.split.map{|e| e.to_f}\nt = (m/vy).abs\ncz = vz*t\ncx = a/2+vx*t\nif cz.div(b).modulo(2)==0\n cz = cz.modulo(b)\nelse\n cz = b-cz.modulo(b)\nend\nif cx.div(a).modulo(2)==0\n cx = cx.modulo(a)\nelse\n cx = a-cx.modulo(a)\nend\nputs cx, cz", "src_uid": "84848b8bd92fd2834db1ee9cb0899cff"} {"source_code": "k = gets.to_i\n\nd = Array.new(10) { [0] * 11 }\nd[0][0] = 1\n(0..8).each do |i|\n (0..10).each do |j|\n (0..9).each do |k|\n d[i + 1][j + k] += d[i][j] if j + k < 11\n end\n end\nend\n\nans, s = 0, 10\n9.downto(1) do |i|\n ans *= 10\n (0..9).each do |j|\n if d[i - 1][s - j] < k\n k -= d[i - 1][s - j]\n else\n s -= j\n ans += j\n break\n end\n end\nend\n\np ans\n", "src_uid": "0a98a6a15e553ce11cb468d3330fc86a"} {"source_code": "def pow(x, y)\n md = 1000000007;\n if y == 0 \n 1\n else\n t = pow(x, y/2);\n t = (t * t) % md;\n if y % 2 == 1 then (x * t) % md else t end\n end\nend\n\nmd = 1000000007;\nn, k = gets.split.map(& :to_i)\n\n\nif k == 1 \n ans = pow(n - k, n- k)\nelse\n ans = ((pow(k, k - 2) * k)% md * pow(n - k, n - k)) % md\nend\n\np ans\n", "src_uid": "cc838bc14408f14f984a349fea9e9694"} {"source_code": "n, s, c = gets.split.map(&:to_i)\nd = gets =~ /tail/ ? 1 : -1\ngets.scan(/[01]/).each_with_index do |w, i|\n s = c if w == ?1\n d = 1 if c == 1\n d = -1 if c == n\n c += d\n s += d if s == c\n unless (1 .. n).include? s\n puts \"Controller #{i + 1}\"\n exit\n end\nend\nputs :Stowaway", "src_uid": "2222ce16926fdc697384add731819f75"} {"source_code": "require 'prime'\nn = gets.to_i\np n == 1 ? 1 : n.prime_division.map{|x| x[0]}.inject(:*)\n", "src_uid": "6d0da975fa0961acfdbe75f2f29aeb92"} {"source_code": "##$l = gets.to_i ##1 ##gets.strip() ## integer??\n##$r = gets.to_i ##2000000000 ## as above\n\n$l, $r = gets.split.map(&:to_i)\n\n$p1 = 0\n$count=0\n\nbegin\n $p2=0 \n \n begin\n if (3**$p1) * (2**$p2) >= $l\n if (3**$p1) * (2**$p2) <= $r\n $count+=1 \n ##puts 3**$p1 * 2**$p2\n end\n end\n \n $p2+=1\n end until 3**$p1 * 2**$p2 > $r\n \n ## puts 3**$p1\n \n $p1 +=1;\nend until 3**$p1 > $r\n\nputs $count", "src_uid": "05fac54ed2064b46338bb18f897a4411"} {"source_code": "w,m,k=gets.split.map(&:to_i)\na=Math.log10(m).to_i+1\nv=l=0\nwhile a*k*(c=(b=10**a-1)-m+1)+v <=w do\n v+=a*k*c\n l+=c\n m=b+1\n a+=1\nend\nl+=(w-v)/(a*k)\np l\n\n\n", "src_uid": "8ef8a09e33d38a2d7f023316bc38b6ea"} {"source_code": "n, cw, cb = gets.split(' ').map(&:to_i)\narr = gets.split(' ').map(&:to_i)\nanswer = 0\n\n1.upto(n) do |index|\n q = arr[index - 1]\n w = arr[n -index]\n \n if (q == 0 && w == 1) || (q == 1 && w == 0) \n answer = -1\n break\n end\n \n if q == 2 && w == 2\n \tanswer += [cw, cb].min\n elsif q != w && q == 2\n\tanswer += (w == 0 ? cw : cb)\n end\nend\n\n p answer", "src_uid": "af07223819aeb5bd6ded4340c472b2b6"} {"source_code": "a, b = gets.chomp.split(//)\nn = ('b'..'g').include? a\nm = ('2'..'7').include? b\nputs 8 if n && m\nputs 3 unless n || m\nputs 5 if (n || m) && !(n && m)", "src_uid": "6994331ca6282669cbb7138eb7e55e01"} {"source_code": "low=[]\nst=[]\ncur=1989\nstep=10\n(1..10).each{|i|\n\tlen=cur.to_s.length\n\tst< @min\n\t\t\t@wkhours -= 1\n\t\t\treturn true\n\t\tend\n\t\treturn false\n\tend\n\tattr_accessor :min, :max, :wkhours\nend\n\nns,sums = gets.chomp.split(/ /)\nn = ns.to_i\nsum = sums.to_i\n\nba = Array.new\nfor i in 0..n-1\n\tar = gets.chomp.split(/ /)\n\tar.map! {|x| x.to_i}\n\tba.push( Bdays.new(ar) )\nend\n\nmina = 0\nmaxa = 0\nsumwk = 0\nba.each {|b|\n\tmina += b.min\n\tmaxa += b.max\n\tsumwk += b.wkhours\n}\n\nif sum < mina || sum > maxa\n\tputs \"NO\"\nelse\n\tputs \"YES\"\n\tidx = 0\n\twhile (sumwk != sum)\n\t\tidx = 0 if idx >= n\n\t\tif sumwk < sum\n\t\t\tsumwk += 1 if ba[idx].wkinc\n\t\telse\n\t\t\tsumwk -= 1 if ba[idx].wkdec\n\t\tend\n\t\tidx += 1\n\tend\n\tba.each {|b| puts b.wkhours }\nend", "src_uid": "f48ff06e65b70f49eee3d7cba5a6aed0"} {"source_code": "n,*a=$<.read.split.map &:to_i\nb=[0];c=[0]\na.each{|e|b<= z\n\tputs (x+y+z)/3\nelse\n\ttail = z-x-y\n\tif tail <= x+y\n\t\tputs (x+y+z)/3\n\telse\n\t\tputs x+y\n\tend\nend\n", "src_uid": "bae7cbcde19114451b8712d6361d2b01"} {"source_code": "require 'Prime'\nt=gets.chomp.to_i\nans=1\nif(t==2 || Prime.instance.prime?(t))\nans=1\nelsif (t%2==0)\nans=2\nelsif (Prime.instance.prime?(t-2))\nans=2\nelse \nans=3\nend\nputs \"#{ans}\"", "src_uid": "684ce84149d6a5f4776ecd1ea6cb455b"} {"source_code": "dircount, width, start, stop = gets.split(/\\s+/)\nidircount = dircount.to_i\niwidth = width.to_i\nistart = start.to_i\nistop = stop.to_i\n\ndef solve(dircount, width, start, stop)\n dirsCount = stop - start + 1\n\n count = 0\n\n if (start % width != 1 || dirsCount == 1)\n count += 1\n #puts \"=1\"\n end\n\n stripStart = ((start-1)/width + 1)*width + 1\n stripStop = ((stop-1)/width - 1)*width + width\n\n #puts stripStart, stripStop\n \n stripBegin = false\n stripEnd = false\n if (stripStart < stripStop or (stripStart > stripStop and (stop%width == 0 or start%width == 1)))\n stripBegin = true if (start..stop).include?(stripStart)\n stripEnd = true if (start..stop).include?(stripStop)\n end\n if (stripEnd && stripBegin)\n count += 1\n if (((start-1)%width) - ((stop-1)%width) == 1)\n count -= 1\n elsif (width == 1)\n count -= 1\n end\n #puts \"=2\"\n end\n \n\n #height = (stop-1)/width - (start-1)/width\n #if (height > 2)\n # count += 1\n # #puts \"=2\"\n #else if (height == 1)\n # if (start % width == 1 or stop % width == 0)\n # count += 1\n # end\n #end\n #end\n #puts start/width, stop/width\n\n if ((start-1)/width < (stop-1)/width)\n #puts \"-pre3\"\n if (stop % width != 0)\n count += 1\n if (dircount == stop && stripEnd && stripBegin)\n count -= 1\n end\n #puts \"=3\"\n end\n elsif ((start-1)/width == (stop-1)/width)\n if (count == 0)\n count += 1\n end\n end\n\n count\nend\n\nputs solve(idircount, iwidth, istart, istop)", "src_uid": "f256235c0b2815aae85a6f9435c69dac"} {"source_code": "n, m = gets.split.map{|x| (x.to_i-1).to_s(7)}\nln, lm = [n, m].map(&:size)\nputs (0...7).to_a.permutation(ln + lm).lazy.map(&:join).select{|a| a[0...ln] <= n && a[ln..-1] <= m}.count", "src_uid": "0930c75f57dd88a858ba7bb0f11f1b1c"} {"source_code": "# Try Codeforces\n# author: Leonardone @ NEETSDKASU\n\nA = gets.to_i\n\nif A == 1\n puts \"1 1\"\n puts \"1\"\n exit\nend\n\nN = 7 * (A - 1)\n\nputs \"%d 2\" % [N]\nputs \"1 7\"\n ", "src_uid": "5c000b4c82a8ecef764f53fda8cee541"} {"source_code": "n = gets.to_i\ns = gets.chomp.chars\nans = 0\ns.each do |ss|\n if ss == \"-\"\n ans -= 1 if ans > 0\n else\n ans += 1\n end\nend\nputs ans\n", "src_uid": "a593016e4992f695be7c7cd3c920d1ed"} {"source_code": "def reflection(x)\n\tn = x.to_s.size\n\treturn 10 ** n - 1 - x\nend\n\nl, r = gets.split.map(&:to_i)\nn = r.to_s.size\na = [l, r]\n1.upto(n) do\n\tm = 10 ** n\n\ta << (m / 2 - 1)\n\ta << (m / 2)\n\ta << m / 10\nend\nputs a.select{|_| (l..r).include?(_)}.map{|_| _ * reflection(_)}.max\n", "src_uid": "2c4b2a162563242cb2f43f6209b59d5e"} {"source_code": "n,m=gets.split.map{|i| i.to_f}\nputs n+m==2 ? 1 : 1/n+(n-1)/n*(m-1)/(n*m-1)\n", "src_uid": "0b9ce20c36e53d4702869660cbb53317"} {"source_code": "gets\nputs gets.gsub(/o(go)+/,'***')", "src_uid": "619665bed79ecf77b083251fe6fe7eb3"} {"source_code": "N = 32768\n\nclass I\n\tdef initialize(n)\n\t\t@n = n % N\n\tend\n\n\tattr_reader :n\n\n\t'+-*/'.each_char do |c|\n\t\teval <(o)\n\t\treturn n <=> o.n\n\tend\n\n\tinclude Comparable\nend\n\ny = I.new(gets.to_i)\ns = (readlines * '')[/[^{]+(?=\\})/].scan(/[^;]+(?=;)/).map do |_|\n\t_ = \"if #{$1} then #{$2} end\" if _ =~ /if(.*)(return.*)/\n\t_.gsub(/\\d+/){\"I.new(#{$&})\"}\nend\n\n$f = Array.new(N)\neval < maxx\n maxy = y if y > maxy\nend\n\ndx = x\ndy = y\n\nstartx = a - maxx - 1\nstarty = b - maxy - 1\n\ninf = 10**9 + 10\niter = inf\niter = startx / dx if dx > 0\niter = [iter, starty / dy].min if dy > 0\n\niter = 0 if iter == inf or iter < 0\n\nx = iter * dx\ny = iter * dy\n\ns.size.times do\n s.each_char do |c|\n x, y = step x, y, c\n if x == a and y == b\n puts 'Yes'\n exit\n end\n end\nend\n\nputs 'No'\n\n\n", "src_uid": "5d6212e28c7942e9ff4d096938b782bf"} {"source_code": "q = Array.new(1000)\nipt = gets.split(' ')\na = ipt[0].to_i\nb = ipt[1].to_i\nc = 1\nwhile true\n\tq[c] = b\n\tif a == b\n\t\tbreak\n\tend\n\tc += 1\n\tif b % 2 == 0\n\t\tb /= 2\n\telsif b % 10 == 1\n\t\tb /= 10\n\telse\n\t\tputs \"NO\"\n\t\texit\n\tend\n\tif b < a\n\t\tputs \"NO\"\n\t\texit\n\tend\nend\nputs \"YES\", c\nfor i in (1...c)\n\tprint q[c - i + 1], \" \"\nend\nputs q[1]", "src_uid": "fc3adb1a9a7f1122b567b4d8afd7b3f3"} {"source_code": "n,m,k,*a=gets(p).split.map(&:to_i)\nm-=1\nans=0\n1.upto(n){|i|\n\tl=m-i\n\tr=m+i\n\tif (0...n)===l&&a[l]<=k&&a[l]!=0\n\t\tans=i\n\t\tbreak\n\tend\n\tif (0...n)===r&&a[r]<=k&&a[r]!=0\n\t\tans=i\n\t\tbreak\n\tend\n}\n\np ans*10", "src_uid": "57860e9a5342a29257ce506063d37624"} {"source_code": "n=gets.to_i\na=gets.split(\" \").map(&:to_i)\nif a[-1]==15\n\tputs \"DOWN\"\nelsif a[-1]==0\n\tputs \"UP\"\nelsif n==1\n\tputs \"-1\"\nelse\n\tputs a[-2]= 0) ? \"Yes\" : \"No\";\nend", "src_uid": "1527171297a0b9c5adf356a549f313b9"} {"source_code": "a = gets.to_i\nb = gets.to_i\ndiff = (a-b).abs\nm = diff/2\nans = 0\nm.times do |i|\n ans += (i+1)*2\nend\nans += diff/2 + 1 if diff % 2 == 1\nputs ans\n", "src_uid": "d3f2c6886ed104d7baba8dd7b70058da"} {"source_code": "p (gets.to_i+4)/10*10", "src_uid": "29c4d5fdf1328bbc943fa16d54d97aa9"} {"source_code": "n=gets.to_i\npos=0\nres=\"YES\"\nn.times do\n t, d=gets.split\n res=\"NO\" if pos==0 and d[0]!=?S\n res=\"NO\" if pos==20000 and d[0]!=?N\n if d[0]==?S\n res=\"NO\" if pos==20000\n pos+=t.to_i\n res=\"NO\" if pos>20000\n elsif d[0]==?N\n res=\"NO\" if pos==0\n pos-=t.to_i\n res=\"NO\" if pos<0\n end\nend\nres=\"NO\" if pos!=0\nputs res\n", "src_uid": "11ac96a9daa97ae1900f123be921e517"} {"source_code": "def minfactor(n)\n\tif n < 1 then\n\t\treturn 0\n\tend\n\t\n\tif n == 1 then\n\t\treturn 1\n\tend\n\t\n\tif n % 2 == 0 then\n\t\treturn 2\n\tend\n\t\n\tif n % 3 == 0 then\n\t\treturn 3\n\tend\n\t\n\tif n % 5 == 0 then\n\t\treturn 5\n\tend\n\t\n\tpj = [1, 7, 11, 13, 17, 19, 23, 29]\n\ti, j = 0, 0\n\t\n\twhile true do\n\t\tj += 1\n\t\tif j == 8 then\n\t\t\ti += 1\n\t\t\tj = 0\n\t\tend\n\t\tp = 30 * i + pj[j] \n\t\t\n\t\tif p * p > n then\n\t\t\treturn n\n\t\tend\n\t\t\n\t\tif n % p == 0 then\n\t\t\treturn p\n\t\tend\n\tend\nend\n\n\ndef isprime(n)\n\tif n <= 1 then\n\t\treturn false\n\tend\n\t\n\tif n == minfactor(n) then\n\t\treturn true\n\telse\n\t\treturn false\n\tend\nend\n\nnn = gets.chomp.to_i\nif nn == 1 then\n\tputs \"1\"\n\tputs \"0\"\n\texit\nend\n\nif nn == minfactor(nn) then\n\tputs \"1\"\n\tputs \"0\"\n\texit\nend\n\nnna = []\nwhile true do\n\tm = minfactor(nn)\n\t\n\tif m == 1 then\n\t\tbreak\n\tend\n\tnna << m\n\tbreak if nna.length >= 3\n\tnn /= m\nend\n\nrr = nna[0] * nna[1]\nif nna.length == 2\n\tputs \"2\"\nelse\n\tputs \"1\"\n\tputs rr\nend\n", "src_uid": "f0a138b9f6ad979c5ca32437e05d6f43"} {"source_code": "n = gets.to_i\na = gets.to_i\nb = gets.to_i\n\nx = [a, b].max\ny = [a, b].min\n\ni = 0\nwhile true do\n rem = n - (x * i)\n if rem % y == 0\n puts \"YES\"\n puts a == x ? \"#{i} #{(rem / y)}\" : \"#{(rem / y)} #{i}\"\n break\n end\n\n i += 1\n if (x * i) > n\n puts \"NO\"\n break\n end\nend\n", "src_uid": "b031daf3b980e03218167f40f39e7b01"} {"source_code": "s = gets.to_i.to_s(2)\na = []\ns.size.downto(1) do |i|\n a << i if s[s.size - i] == '1'\nend\nputs a.join(' ')\n", "src_uid": "757cd804aba01dc4bc108cb0722f68dc"} {"source_code": "p gets.chomp.chars.chunk{|c|c}.count{|e|e[1].size.even?}\n", "src_uid": "8b26ca1ca2b28166c3d25dceb1f3d49f"} {"source_code": "loop do\n n = gets.to_i\n\n i=1\n j=0\n loop do\n j += i\n n -= j\n break if n < 0\n i += 1\n end\n puts i-1\n break if $stdin.eof?\nend\n", "src_uid": "873a12edffc57a127fdfb1c65d43bdb0"} {"source_code": "#!/usr/bin/ruby1.9\n\nx, y, a, b = STDIN.readline.split.collect {|s| s.to_i }\n\ndef gcd(x, y)\n\treturn x if y == 0\n\treturn gcd(y, x%y)\nend\n\nc = x*y/gcd(x, y)\n\nlow = (a/c)*c\nif low < a\n\tlow += c\nend\n\nhigh = (b/c)*c\nif high > b\n\thigh -= c\nend\n\nif low <= high\n\tputs (high-low)/c + 1\nelse\n\tputs 0\nend\n\n", "src_uid": "c7aa8a95d5f8832015853cffa1374c48"} {"source_code": "sum = gets.to_i\ncx = [0] * 101\nans = 0\ngets.split.map(&:to_i).each { |x| cx[x] += 1 }\n\ndef check(len, cx)\n r = []\n dx = cx.clone\n (0...len).each do |i|\n ok = false\n (i..100).each do |j|\n next if dx[j].zero?\n dx[j] -= 1\n r << j\n ok = true\n break\n end\n return false unless ok\n end\n r\nend\n\nlen = 100\nwhile sum > 0\n break if len < 1\n r = check(len, cx)\n if r == false\n len -= 1\n else\n # p r\n sum -= r.size\n r.each { |x| cx[x] -= 1 }\n ans += 1\n end\nend\n\np ans\n", "src_uid": "7c710ae68f27f140e7e03564492f7214"} {"source_code": "# Try Codeforces\n# author: Leonardone @ NEETSDKASU\ndef xs()\n gets.strip.split.map &:to_i\nend\n\nl1, s1, r1, p1 = xs\nl2, s2, r2, p2 = xs\nl3, s3, r3, p3 = xs\nl4, s4, r4, p4 = xs\n\n\nf = p1 == 1 && l1+s1+r1+l2+s3+r4>0\nf |= p2 == 1 && l2+s2+r2+r1+l3+s4>0\nf |= p3 == 1 && l3+s3+r3+s1+r2+l4>0\nf |= p4 == 1 && l4+s4+r4+l1+s2+r3>0\n\nputs f ? :YES : :NO", "src_uid": "44fdf71d56bef949ec83f00d17c29127"} {"source_code": "w, h = gets.strip.split(' ').map(&:to_i)\n\nputs ( (2**w) * (2**h) ) % 998244353", "src_uid": "8b2a9ae21740c89079a6011a30cd6aee"} {"source_code": "x, y = gets.split.collect{|i| i.to_i}\nt = [x.abs, y.abs].max\nans = 4*t\nif x == t and y == -t+1\n ans -= 4\nelsif x == t and y > -t+1\n ans -= 3\nelsif x < t and y == t\n ans -= 2\nelsif x == -t and y < t\n ans -= 1\nelsif x > -t and y == -t\n ans -= 0\nend\nputs ans\n", "src_uid": "2fb2a129e01efc03cfc3ad91dac88382"} {"source_code": "N = gets.to_i\nas = gets.split.map(&:to_i)\ncnt = Array.new(6, 0)\nas.each do |a|\n cnt[a] += 1\nend\n\nborder = (N*9+1)/2\nshortage = border - as.inject(:+)\nans = 0\n(1..4).each do |i|\n break if shortage < 0\n num = [cnt[i], (shortage-1)/(5-i)+1].min\n ans += num\n shortage -= num * (5-i)\nend\nputs ans", "src_uid": "715608282b27a0a25b66f08574a6d5bd"} {"source_code": "puts gets.to_i==2?2:1", "src_uid": "c30b372a9cc0df4948dca48ef4c5d80d"} {"source_code": "n=gets.to_i\ns=gets.chomp\na, b, c=[], 0, -1\ns.chars do |e|\n if e.to_i==0\n if c==0\n a<< 0\n else\n a<< b\n b=0\n end\n else\n b+=1\n end\n c=e.to_i\nend\n\nputs (a< 1\n mid = (ok+ng)/2\n if (n-mid)*(n-mid+1)/2-mid < k\n ng = mid\n else\n ok = mid\n end\nend\nputs ok", "src_uid": "17b5ec1c6263ef63c668c2b903db1d77"} {"source_code": "a=gets.chomp.split(\" \")\nb=gets.chomp.split(\" \")\nsum=0\n0.upto(1) do |i|\na[i]=a[i].to_i\nend\n0.upto(a[0]-1) do |i|\nb[i]=b[i].to_i\nsum=sum+b[i]\nend\ntrig=1\n0.upto(a[0]-1) do |i|\nif sum-b[i]<=a[1]\n\tputs \"YES\"\n\ttrig=0\n\tbreak\nend\nend\nif trig==1\nputs \"NO\"\nend\n\t", "src_uid": "496baae594b32c5ffda35b896ebde629"} {"source_code": "MOD = 1000000007\n\ndef pow(x,n)\n if n == 0\n 1\n elsif n % 2 == 0\n pow(x*x%MOD, n/2) % MOD\n else\n x * pow(x, n-1) % MOD\n end\nend\n\nn = gets.to_i\nsum = 1\n1.upto(n) do |i|\n sum *= i\n sum %= MOD\nend\nminus = pow(2,n-1)\nsum -= minus\nsum %= MOD\nputs sum", "src_uid": "3dc1ee09016a25421ae371fa8005fce1"} {"source_code": "puts [*1..a=gets.to_i].any?{|n|-~n*n/2==a}?:YES:\"NO\"", "src_uid": "587d4775dbd6a41fc9e4b81f71da7301"} {"source_code": "#!/usr/bin/ruby1.9\n\nx = STDIN.readline.to_i\n\nif x >= 0\n\tputs x\n\texit\nend\n\nx = x.abs\n\nif x <= 10\n\tputs 0\n\texit\nend\n\na = x/10\n\nb = a - a%10 + x%10\n\nputs -([a, b].min)\n", "src_uid": "4b0a8798a6d53351226d4f06e3356b1e"} {"source_code": "n = gets.to_i\n\nk = Math.sqrt(n).to_i\n\nputs k * 4 + 2 * ((n - k**2 + k - 1) / k)", "src_uid": "414cc57550e31d98c1a6a56be6722a12"} {"source_code": "x,t,a,b,m,n=gets.split.map &:to_i\nr=[*0...t];puts r.product(r).flat_map{|i,j|[k=[a-i*m,0].max,l=[b-j*n,0].max,k+l,0]}.index(x)?:YES: :NO\n", "src_uid": "f98168cdd72369303b82b5a7ac45c3af"} {"source_code": "n = gets.to_i\ns = gets.chomp\nans = 0\n(0..n-3).each do |i|\n if s[i..(i+2)] == \"xxx\"\n ans += 1\n end\nend\nputs ans", "src_uid": "8de14db41d0acee116bd5d8079cb2b02"} {"source_code": "n = gets.to_i\ns = gets.chomp\ncnt = Hash.new(0)\n(n-1).times do |i|\n cnt[s[i, 2]] += 1\nend\n\nmaxv = 0\nans = \"\"\n\ncnt.each_key do |c|\n if cnt[c] > maxv\n ans = c\n maxv = cnt[c]\n end\nend\nputs ans", "src_uid": "e78005d4be93dbaa518f3b40cca84ab1"} {"source_code": "n,x,*a=$<.read.split.map &:to_i\nb=[*0...x]-a\np b.size+(a.include?(x)?1:0)", "src_uid": "21f579ba807face432a7664091581cd8"} {"source_code": "def is_able?(n)\n xc = n / $x\n yc = n / $y\n bc = n / $x.lcm($y)\n a_left = [$a - yc + bc, 0].max\n b_left = [$b - xc + bc, 0].max\n a_left + b_left <= n - xc - yc + bc\nend\n\ndef magic(l, r)\n return l if l == r\n m = (l + r) / 2\n is_able?(m) ? magic(l, m) : magic(m + 1, r)\nend\n\n$a, $b, $x, $y = gets.split.map(&:to_i)\np magic(0, 1e10.to_i)\n", "src_uid": "ff3c39b759a049580a6e96c66c904fdc"} {"source_code": "n = gets.to_i\nf = gets.split.map { |x| x.to_i }\n\nsum = 0\nflag = false\n\nf.each do |x|\n\tsum += x\n\tif x == 100 ;\n\t\tflag = true\n\tend\nend\n\nif sum % 200 == 100 ;\n\tprint \"NO\\n\"\nelsif sum % 400 == 200 && !flag ;\n\tprint \"NO\\n\"\nelse\n\tprint \"YES\\n\"\nend\n", "src_uid": "9679acef82356004e47b1118f8fc836a"} {"source_code": "a,b=gets.split(\" \").map(&:to_i)\np=1\nwhile a>=0 && b>=0\n\tif a>=2*p-1\n\t\ta-=2*p-1\n\telse\n\t\tputs \"Vladik\"\n\t\tbreak\n\tend\n\tif b>=2*p\n\t\tb-=2*p\n\telse\n\t\tputs \"Valera\"\n\t\tbreak\n\tend\n\tp+=1\nend\n\t\t", "src_uid": "87e37a82be7e39e433060fd8cdb03270"} {"source_code": "l, r, a = gets.split.map(&:to_i);\nx = [l, r].max;\ny = [l, r].min;\nif x-y >= a\n puts ((y+a)*2);\nelse\n a -= x-y;\n a = a/2 * 2;\n puts (x*2 + a);\nend", "src_uid": "e8148140e61baffd0878376ac5f3857c"} {"source_code": "require\"prime\"\nn = gets.to_i\n\nsum = c = n\n\nloop do\n pd = c.prime_division.sort\n c /= pd[0][0]\n sum += c\n break if pd.size == 1 && pd[0][1] == 1\nend\n\np sum\n", "src_uid": "821c0e3b5fad197a47878bba5e520b6e"} {"source_code": "n = gets.to_i\ncs = n.times.map{gets.split}\n\njudge = lambda{|x|\n cs.permutation.each{|cc|\n s = x.to_s.chars\n cube = 0\n flag = true\n \n until s.empty?\n c = s.first\n if cube>=n\n flag = false\n break\n end\n if cc[cube].include?(c)\n s.shift\n end\n cube += 1\n end\n \n if flag\n return true\n end\n }\n return false\n}\n\nresult = 0\n\n(1..999).each{|x|\n if judge.call(x)\n result = x\n else\n break\n end\n}\nputs result\n", "src_uid": "20aa53bffdfd47b4e853091ee6b11a4b"} {"source_code": "n=gets.to_i\np 1+3*n*-~n\n", "src_uid": "c046895a90f2e1381a7c1867020453bd"} {"source_code": "x = {'A' => 0, 'B' => 0, 'C' => 0}\ns = '___'\n3.times do\n\ta, o, b = gets.scan(/./)\n\to == '>' ? x[a] += 1 : x[b] += 1\nend\nx.each do |k, v|\n\ts[v] = k\nend\ns = 'Impossible' if s =~ /_/\nputs s\n", "src_uid": "97fd9123d0fb511da165b900afbde5dc"} {"source_code": "puts gets.chomp.scan(/C{1,5}|P{1,5}/).size", "src_uid": "5257f6b50f5a610a17c35a47b3a0da11"} {"source_code": "s = gets.strip\nx = s.index('+')\ny = s.index('=') - x - 1\nz = s.length - x - y - 2\n\nif x + y == z\n puts s\nelsif x > 1 && z + 1 == x + y - 1\n puts '|'*(x-1) + '+' + '|'*y + '=' + '|'*(z+1)\nelsif y > 1 && z + 1 == x + y - 1\n puts '|'*x + '+' + '|'*(y-1) + '=' + '|'*(z+1)\nelsif z > 1 && z - 1 == x + y + 1\n puts '|'*(x+1) + '+' + '|'*y + '=' + '|'*(z-1)\nelse\n puts \"Impossible\"\nend\n", "src_uid": "ee0aaa7acf127e9f3a9edafc58f4e2d6"} {"source_code": "n, m = gets.split.collect{|i| i.to_i}\nif n == 0 and m != 0\n puts \"Impossible\"\nelsif m == 0\n puts [n, n].join(\" \")\nelse\n puts [n+m-[n,m].min, n+m-1].join(\" \")\nend\n", "src_uid": "1e865eda33afe09302bda9077d613763"} {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\n# A: v1 per char, t1 network delay\n# B: v2 per char, t2 network delay\n# after t millisec, text is given\n# (they begin to type)\n\ns, v1, v2, t1, t2 = gets.split.map(&:to_i)\nfirst, second = (t1 + v1*s + t1), (t2 + v2*s + t2)\n# p \"#{first} #{second}\"\nif first < second\n puts \"First\"\nelsif first == second\n puts \"Friendship\"\nelse\n puts \"Second\"\nend\n", "src_uid": "10226b8efe9e3c473239d747b911a1ef"} {"source_code": "#!/usr/bin/env ruby\n\narr = gets.chomp.split(\" \").map(&:to_i)\nd = arr.pop\n\na = arr.sort\nright = a[2] - a[1] # 5 - 3 = 2\nleft = a[1] - a[0] # 3 - 1 = 2\ntime = 0\ntime += (d - right) if right < d\ntime += (d - left) if left < d\n\nputs time\n", "src_uid": "47c07e46517dbc937e2e779ec0d74eb3"} {"source_code": "s, k = gets.split.map(&:to_i)\n\nk = 50 if k > 50\n\nfib = Enumerator.new do |y|\n ar = Array.new(k,0)\n ar[k-1] = 1\n st = 0; sm = 1\n y << 1\n loop do\n y << sm\n aux = ar[st]\n ar[st] = sm\n st = (st + 1) % k\n sm += sm - aux\n end\nend\n\nlst = fib.take_while {|x| x <= s}\nps = lst.length - 1\n\nans = []\n\nwhile s > 0\n\twhile ps >= 0 and lst[ps] > s\n\t\tps -= 1\n\tend\n\tbreak if ps < 0\n\ts -= lst[ps]\n\tans.push lst[ps]\nend\n\nif ans.length == 1\n ans.push 0\nend\n\nputs \"#{ans.length}\"\nputs ans.map(&:to_s).join(' ')", "src_uid": "da793333b977ed179fdba900aa604b52"} {"source_code": "x, y, n = gets.split\nx = x.to_f\ny = y.to_f\nn = n.to_i\n\nval = x/y\n\nmin = (0x7FFFFFFF).to_f\na = 0\nb = 0\n\nfor i in 1..n\n k = val*i\n if (k - k.floor) > 0.5\n k = k.ceil.to_f\n else\n k = k.floor.to_f\n end\n s = (k/i - x/y).abs\n if s < min then\n min = s\n a = k.to_i\n b = i\n end\nend\n\nprint a, \"/\", b", "src_uid": "827bc6f120aff6a6f04271bc84e863ee"} {"source_code": "k = gets.to_i\nl = gets.to_i\ni = 0\nn = k\nwhile n < l\n n *= k\n i += 1\nend\nif n == l\n puts 'YES'\n puts i\nelse\n puts 'NO'\nend\n", "src_uid": "8ce89b754aa4080e7c3b2c3b10f4be46"} {"source_code": "gets\nans = 0.step(999, 8).find{|x| $_[/#{x.to_s.chars * '.*'}/]}\nputs ans ? \"YES\\n#{ans}\" : 'NO'\n\n", "src_uid": "0a2a5927d24c70aca24fc17aa686499e"} {"source_code": "n, k = gets.strip.split(' ').map(&:to_i)\ns = gets.strip\nj = -1\n0.upto(s.length - 1) do |i|\n if s[i] == 'G'\n j = i\n break\n end\nend\n\ni1 = j\ni2 = j\nfound = false\nwhile(1)\n i1 -= k\n i2 += k\n if i1 >= 0\n if s[i1] == 'T'\n found = true\n break\n elsif s[i1] == '#'\n i1 = -1\n end\n end\n if i2 < s.length\n if s[i2] == 'T'\n found = true\n break\n end\n if s[i2] == '#'\n i2 = s.length\n end\n end\n if i1 < 0 && i2 >= s.length\n break\n end\nend\n\nprintf(\"%s\\n\", found ? \"YES\" : \"NO\")\n", "src_uid": "189a9b5ce669bdb04b9d371d74a5dd41"} {"source_code": "#!/usr/bin/ruby\n\ninput_line = gets\n\nparams = input_line.split(' ')\nn = params[0].to_i\nm = params[1].to_i\n\nparr = (1..n).to_a.permutation.map(&:join)\n\ndef sum_arg param\n arr = param.to_s.chars.map{|x| x.to_i}\n res = 0\n i = 0;\n j = 0;\n while i < param.length do\n j = i\n while j < param.length do\n p = (arr.slice(i,j-i+1)).min\n res += p\n j = j + 1\n end\n i = i + 1\n end\n res\nend\n\nmax = 0\npermutations = []\n\nparr.each do |pp|\n current_sum = sum_arg(pp)\n if (current_sum > max)\n max = current_sum;\n permutations = []\n permutations << pp\n elsif (current_sum == max)\n permutations << pp\n end\n\nend\n\nres = permutations[m-1]\nsres = ''\nres.to_s.chars.each do |x|\n sres+= x + ' '\nend\nputs sres.strip\n", "src_uid": "a8da7cbd9ddaec8e0468c6cce884e7a2"} {"source_code": "m=gets.split[1].to_i;a=gets.split.map{|x|-x.to_i/m};p a.rindex(a.min)+1", "src_uid": "c0ef1e4d7df360c5c1e52bc6f16ca87c"} {"source_code": "n = gets.to_i\np gets.split.map(&:to_i).inject(:gcd) * n\n\n", "src_uid": "042cf938dc4a0f46ff33d47b97dc6ad4"} {"source_code": "n,k=gets.split.map &:to_i;p n.lcm 10**k", "src_uid": "73566d4d9f20f7bbf71bc06bc9a4e9f3"} {"source_code": "n,t,k,d=gets.split.map &:to_i\nt1=(n+k-1)/k*t\nt2=0\no1=0\no2=0\nwhile n>0\n t2+=1\n o1+=1\n if o1==t\n o1=0\n n-=k\n end\n if t2>d\n o2+=1\n if o2==t\n o2=0\n n-=k\n end\n end\nend\nputs (t2 maxa\n suma += ai\nend\n\nmink = [((suma + m).to_f / n).ceil, maxa].max\nmaxk = maxa + m\n\nputs \"#{mink} #{maxk}\"", "src_uid": "78f696bd954c9f0f9bb502e515d85a8d"} {"source_code": "def read_next_line\n gets.split.map { |x| x.to_i }\nend\n\ndef print_line(a)\n puts a * ' '\nend\n\n_, a1, a2 = read_next_line\nb0, _, b2 = read_next_line\nc0, c1, _ = read_next_line\ny = (2 * c0 + c1 - b2) / 2\nx = c0 + c1 - y\nz = b0 + c0 - y\nprint_line [x, a1, a2]\nprint_line [b0, y, b2]\nprint_line [c0, c1, z]", "src_uid": "0c42eafb73d1e30f168958a06a0f9bca"} {"source_code": "p [gets.to_i,gets.to_i/2,gets.to_i/4].min*7", "src_uid": "82a4a60eac90765fb62f2a77d2305c01"} {"source_code": "path = gets\nc, i, r = path.each_char.map.with_index{|c,i|\n [c, i, path.rindex(c)]\n}.max_by{|(c, i, r)| r - i}\nlpad = (r - i - 1)/2\npath = path.chomp * 2\nif r - i == 1\n puts \"Impossible\"\nelsif (r - i).even?\n top = path[i + 1 + lpad + 13 + 1, 13 - lpad - 1] + c + path[i + 1, lpad]\n bottom = path[i + 1 + lpad + lpad + 1 + 1, 13 - lpad - 1].reverse + path[i + 1 + lpad, lpad + 1].reverse\n puts top, bottom\nelse\n top = path[i + 1 + lpad + 13 + 1, 13 - lpad - 1] + c + path[i + 1, lpad]\n bottom = path[i + 1 + lpad + lpad + 1, 13 - lpad].reverse + path[i + 1 + lpad, lpad].reverse\n puts top, bottom\nend\n", "src_uid": "56c5ea443dec7a732802b16aed5b934d"} {"source_code": "a, b = gets.chomp.split(\" \").map(&:to_i)\n\nval = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6]\n\nnum = Hash.new(0)\n\n(a..b).each do |n|\n while n > 0 \n num[n%10] += 1\n n /= 10\n end\nend\n\nres = 0\n\nkey = (0..9).to_a\n\nkey.zip(val).each do |i, j|\n res += num[i] * j\nend\n\nputs res", "src_uid": "1193de6f80a9feee8522a404d16425b9"} {"source_code": "n = gets.to_i\nl = 0\nr = 10**14\nwhile l+1x} 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/20 do\n d = rui_cnt/10\n m = rui_cnt%10\n ans*=(base**m)\n ans%=MOD\n base = (base**10)%MOD\n rui_cnt=d\n end\n #ans*=(i**rui_cnt)\n # rui_cnt.times do |j|\n # ans *= i\n # ans %= MOD\n # end\n #ans%=MOD\nend\nputs ans % MOD\n", "src_uid": "04610fbaa746c083dda30e21fa6e1a0c"} {"source_code": "n = gets.to_i\nx,y = gets.split.map(&:to_i)\nif [x-1,y-1].max <= [n-x,n-y].max \n\tputs \"White\"\nelse\n\tputs \"Black\"\nend\n", "src_uid": "b8ece086b35a36ca873e2edecc674557"} {"source_code": "inp = gets.chomp.split(' ');\nx1 = inp[0].to_i\ny1 = inp[1].to_i\nx2 = inp[2].to_i\ny2 = inp[3].to_i\n\nd1 = (x2-x1)/2 + 1\nh1 = (y2-y1)/2 + 1\nd2 = (x2-x1 + 1)/2 \nh2 = (y2-y1+1)/2\n\nputs h1*d1 + h2*d2\n", "src_uid": "00cffd273df24d1676acbbfd9a39630d"} {"source_code": "a,b,c = gets.chomp.split(/ /).map!{|x| x.to_i}\nxyz = Math.sqrt(a*b*c)\nret = 4 * (xyz/b+xyz/c+xyz/a)\nputs ret.to_i", "src_uid": "c0a3290be3b87f3a232ec19d4639fefc"} {"source_code": "x1,y1,x2,y2,x3,y3=gets(p).split.map &:to_i\nputs [\"TOWARDS\",\"RIGHT\",\"LEFT\"][(x3-x1)*(y2-y1)-(x2-x1)*(y3-y1)<=>0]\n", "src_uid": "f6e132d1969863e9f28c87e5a44c2b69"} {"source_code": "input_size = gets.chomp.to_i\ninputs_string = gets.chomp\ninputs = inputs_string.split(' ')\n\nhard_problem = false\ninputs.each do |el|\n next if el.eql?('0')\n\n hard_problem = true\n break\nend\n\nif hard_problem.eql?(true)\n puts 'HARD'\nelse\n puts 'EASY'\nend\n", "src_uid": "060406cd57739d929f54b4518a7ba83e"} {"source_code": "arr=[\"\",\"\",\"\",\"\",\"\",\"\"]\nfor i in 0...6 do\n\tarr[i]=gets.chomp\nend\n\nansRow=-1\nansCol=-1\nansVal=-1\n\nvalue=[[3,3,3,4,4,3,3,3]\\\n\t,[3,3,3,4,4,3,3,3]\\\n\t,[2,2,2,3,3,2,2,2]\\\n\t,[2,2,2,3,3,2,2,2]\\\n\t,[1,1,1,2,2,1,1,1]\\\n\t,[1,1,1,2,2,1,1,1]]\n\nans=true\n#4の場所\nfor row in 0...6 do\n\tfor col in 0...8 do\n\t\tif arr[row][col]=='.' and value[row][col]>ansVal then\n\t\t\tansRow=row\n\t\t\tansCol=col\n\t\t\tansVal=value[row][col]\n\t\tend\n\tend\nend\narr[ansRow][ansCol]='P'\n# 出力\nfor row in 0...6 do\n\tprint(\"#{arr[row]}\\n\")\nend", "src_uid": "35503a2aeb18c8c1b3eda9de2c6ce33e"} {"source_code": "#!/usr/bin/env ruby\n\nn,m = gets.chomp.split(\" \").map(&:to_i)\n\nif m= 2 and y >= 2\n x -= 2\n y -= 2\n elsif x >= 1 and y >= 12\n x -= 1\n y -= 12\n elsif y >= 22\n y -= 22\n else\n puts \"Hanako\"\n exit\n end\n else\n if y >= 22\n y -= 22\n elsif y >= 12 and x >= 1\n y -= 12\n x -= 1\n elsif y >= 2 and x >= 2\n y -= 2\n x -= 2\n else\n puts \"Ciel\"\n exit\n end\n end\n}\n", "src_uid": "8ffee18bbc4bb281027f91193002b7f5"} {"source_code": "totalCard = gets.chomp.to_i\n\nfirstPerson = gets.chomp.split(' ').map {|item| item.to_i}\nsecondPerson = gets.chomp.split(' ').map {|item| item.to_i}\n\noriginalfPerson ||= []\noriginalsPerson ||= []\n\nfirstTurn = false\nturnNum = 0\n#####\n\nfirstPerson.each do |item|\n\toriginalfPerson << item\nend\n\nsecondPerson.each do |item|\n\toriginalsPerson << item\nend\n\nloop do\n\tif (originalfPerson <=> firstPerson) == 0 &&\n\t\t(originalsPerson <=> secondPerson) == 0 && firstTurn\n\n\t\tputs -1\n\t\tbreak\n\tend\n\n\tif turnNum > 1000\n\n\t\tputs -1\n\t\tbreak\n\tend\n\n\tif firstPerson.length == 1\n\t\tprint \"#{turnNum} 2\"\n\t\tbreak\n\tend\n\n\tif secondPerson.length == 1\n\t\tprint \"#{turnNum} 1\"\n\t\tbreak\n\tend\n\n\tif firstPerson[1] > secondPerson[1]\n\t\tfirstPerson << secondPerson[1]\n\t\tfirstPerson << firstPerson[1]\n\n\t\tfirstPerson.delete_at(1)\n\t\tsecondPerson.delete_at(1)\n\telse\n\t\tsecondPerson << firstPerson[1]\n\t\tsecondPerson << secondPerson[1]\n\n\t\tfirstPerson.delete_at(1)\n\t\tsecondPerson.delete_at(1)\n\tend\n\n\tturnNum += 1\n\tfirstTurn = true;\nend", "src_uid": "f587b1867754e6958c3d7e0fe368ec6e"} {"source_code": "s = gets.chomp\nn = gets.to_i\ni = 0\ncur = 0\nans = ''\nnn = s.tr('\\?|*', '').size\nwhile i < s.size\n if (s[i] != '?' && s[i] != '*')\n ans += s[i]\n cur += 1\n end\n if (s[i] == '?')\n if n < nn\n ans[-1] = ''\n nn -= 1\n cur -= 1\n end\n end\n if (s[i] == '*')\n if n < nn\n ans[-1] = ''\n nn -= 1\n cur -= 1\n else\n if n > nn\n ans += ans[-1] * (n - nn)\n nn += (n - nn)\n cur += (n - nn)\n end\n end\n end\n i += 1\nend\n# puts cur\n# puts ans.size\n# puts ans\nif (ans.size == n)\n puts ans\nelse\n puts \"Impossible\"\nend", "src_uid": "90ad5e6bb5839f9b99a125ccb118a276"} {"source_code": "class BinaryComparator\n\tdef initialize(n, string)\n\t\t@n = n.to_i\n\t\t@string = string\n\tend\n\n\tdef transform\n\t\tstring = @string.dup\n\t\tstring = sort(string)\n\t\tstring = squeeze(string)\n\t\tputs string\n\tend\n\n\tprivate\n\n\tdef sort(string)\n\t\tfor i in 0..@n-1\n\t\t\tfor j in 0..@n-i-1\n\t\t\t\tif string[j].to_i < string[j+1].to_i\n\t\t\t\t\ttemp = string[j]\n\t\t\t\t\tstring[j] = string[j+1]\n\t\t\t\t\tstring[j+1] = temp\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\t\tstring\n\tend\n\n\tdef squeeze(string)\n\t\tloop do\n\t\t\tif string.include? '11'\n\t\t\t\tstring.sub!('11', '1')\n\t\t\telse\n\t\t\t\tbreak\n\t\t\tend\n\t\tend\n\t\tstring\n\tend\nend\n\nN = gets.to_i\nSTRING = gets\n\ncomparator = BinaryComparator.new(N, STRING)\ncomparator.transform", "src_uid": "ac244791f8b648d672ed3de32ce0074d"} {"source_code": "buf=gets.split(' ')\na1,t1 = buf[0].to_i, buf[1].to_i\nbuf=gets.split(' ')\na2,t2 = buf[0].to_i, buf[1].to_i\nbuf=gets.split(':')\nst=buf[0].to_i*60+buf[1].to_i - 300\ned=st+t1\nx=ans=0\nwhile x<60*19\n\ty = x+t2\n\tif !(st>=y || ed<=x)\n\t\tans+=1\n\tend\n\tx+=a2\nend\nputs ans", "src_uid": "1c4cf1c3cb464a483511a8a61f8685a7"} {"source_code": "ss = gets.chomp.split\n\nx = ss[0].to_i\n\nif ss[2] == 'week'\n if x == 5 || x == 6\n cnt = 53\n else\n cnt = 52\n end\nelsif x <= 29\n cnt = 12\nelsif x == 30\n cnt = 11\nelsif x == 31\n cnt = 7\nend\n\nputs cnt\n", "src_uid": "9b8543c1ae3666e6c163d268fdbeef6b"} {"source_code": "s=gets.chomp\nn=s.size\nres=[0]*4\n\n\"RBYG\".chars.each_with_index{|c, i|\n k=s.index c\n j=k\n res[i]+=1 if s[j]==?! while 0<=j-=4\n j=k\n res[i]+=1 if s[j]==?! while n>j+=4\n}\n\nputs res*' '\n", "src_uid": "64fc6e9b458a9ece8ad70a8c72126b33"} {"source_code": "a = [2, 3, 5, 7, 13, 17, 19, 31, 61, 89, 107, 127, 521, 607, 1279, 2203, 2281, 3217, 4253, 4423, 9689, 9941, 11213, 19937, 21701, 23209, 44497, 86243, 110503, 132049, 216091, 756839, 859433, 1257787, 1398269, 2976221, 3021377, 6972593, 13466917, 20996011, 24036583]\n\ndef pow(x)\n return 1 if x == 0\n return 2 if x == 1\n t = pow(x / 2);\n t *= t\n t *= 2 if x % 2 == 1\n return t % 1000000007\nend\nn = gets.to_i - 1\np pow(a[n] - 1) - 1\n", "src_uid": "c2cbc35012c6ff7ab0d6899e6015e4e7"} {"source_code": "k,a,b=gets.split.map(&:to_i)\nif (a%k!=0&&b db\n [0, 0, 1]\n elsif da < db\n [1, 0, 0]\n else\n [0, 1, 0]\n end\n}.transpose.map{|r| r.reduce(&:+) }\n\nputs result.join ' '", "src_uid": "504b8aae3a3abedf873a3b8b127c5dd8"} {"source_code": "n,c = gets.split(\" \").map(&:to_i)\nrates = gets.split(\" \").map(&:to_i)\nmax_earn = 0\n(0..n-2).each do |i|\n val = rates[i] - rates[i+1] - c\n max_earn = val if val > max_earn\nend\nputs max_earn", "src_uid": "411539a86f2e94eb6386bb65c9eb9557"} {"source_code": "p1, p2, p3 = 3.times.map do \n gets.split.map &:to_i\nend\nans = []\n[p1, p2, p3].permutation(3).each do |a, b, c|\n ans << [c[0] + b[0] - a[0], c[1] + b[1] - a[1]]\nend\nans.uniq!\nputs ans.size\n$, = \" \"\nans.each do |i|\n puts i.join \" \"\nend", "src_uid": "7725f9906a1b87bf4e866df03112f1e0"} {"source_code": "s = gets.chomp\nn = s.size\na = -1\ncnt = 0\nn.times { |i|\n if s[i]=~/[a-z]/\n a = i\n cnt += 1\n end\n}\nif n == 1\n puts s.swapcase\nelsif cnt == 0 || cnt == n\n puts s.downcase\nelsif a == 0\n puts s.capitalize\nelse\n puts s\nend\n", "src_uid": "db0eb44d8cd8f293da407ba3adee10cf"} {"source_code": "n = gets.to_i\nstr = gets.to_s\n\nans = 0\n\nfor i in 0..(n-2) do\n x = 0\n y = 0\n for j in i..(n-1) do\n if str[j] == 'U'\n x = x + 1\n elsif str[j] == 'D' \n x = x - 1\n elsif str[j] == 'R' \n y = y + 1\n else \n y = y - 1\n end\n ans = ans + 1 if x == 0 and y == 0\n end\nend\n\nputs ans", "src_uid": "7bd5521531950e2de9a7b0904353184d"} {"source_code": "\nn = gets.strip.to_i\ns = gets.strip\n\ndef move(s)\n g = [\"A\", \"C\", \"T\", \"G\"]\n steps = 0\n 4.times do |i|\n distance = (s[i].ord - g[i].ord).abs\n steps += distance > 12 ? 26 - distance : distance\n end\n steps\nend\n\nstep_move = move(s[0..3])\n(4..n-1).each do |i|\n tmp = move(s[i-3..i]) \n step_move = tmp if step_move > tmp\nend\n\np step_move\n", "src_uid": "ee4f88abe4c9fa776abd15c5f3a94543"} {"source_code": "class Integer\n def divisers\n n=self\n res = []\n res << 1\n i=1\n while i*i <= n\n if n%i==0\n res << i\n res << n/i if i*i!=n\n end\n i+=1\n end\n res.sort!\n end\nend\n\ndef solve n,m,k\n ds = n.divisers\n if n-1+m-1 fs ? \"YES\" : \"NO\"", "src_uid": "ab8a2070ea758d118b3c09ee165d9517"} {"source_code": "def pred(x, n, m)\n (n-m+x*m)-((m+x)*(m+x+1)-m*(m+1))/2 <= 0;\nend\ninput = gets.chomp.split(' ').map(&:to_i)\nn = input[0];\nm = input[1];\nif m > n\n puts n;\nelse\n lo = 0\n hi = n;\n while lo < hi\n\tmid = lo+(hi-lo)/2;\n\tif pred(mid, n, m)\n\t hi = mid;\n\telse\n\t lo = mid+1\n\tend\n end\n puts m+hi;\nend", "src_uid": "3b585ea852ffc41034ef6804b6aebbd8"} {"source_code": "t = gets.to_s.to_i\n1.upto(t) do |casenum|\n n, k = gets.to_s.split.map {|x| x.to_i }\n res = 1\n p = 10 ** 9 + 7\n k.times { res = res * n % p }\n printf(\"%d\\n\", res)\nend\n", "src_uid": "2e7a9f3a97938e4a7e036520d812b97a"} {"source_code": "a,b,c = gets.split.map(&:to_i)\nans = c*2\nx = [a,b].min\nans += x*2\na -= x\nb -= x\nif b > 0\n ans += 1\n b -= 1\nend\nif a > 0\n ans += 1\nend\nputs ans", "src_uid": "609f131325c13213aedcf8d55fc3ed77"} {"source_code": "i = gets.to_i + 1\n\ndef distinct? i\n a = i.to_s.split('')\n if a[0] == a[1] || a[0] == a[2] || a[0] == a[3] || a[1] == a[2] || a[1] == a[3] || a[2] == a[3]\n return false\n else\n return true\n end\nend\n\nuntil distinct? i\n i +=1\nend\n\nputs i", "src_uid": "d62dabfbec52675b7ed7b582ad133acd"} {"source_code": "x=gets.to_i\nh,m=gets.split.map(&:to_i)\nm+=h*60\nc=0\nwhile !/7/.match(\"#{(m/60)%24}#{m%60}\")\n c+=1\n m-=x\nend\np c", "src_uid": "5ecd569e02e0164a5da9ff549fca3ceb"} {"source_code": "n, m = gets.split.map { |x| x.to_i }\n\ncb = n % m\ncs = m - cb\n\nmin = cs * (n / m - 1) * (n / m) / 2 + cb * (n / m) * (n / m + 1) / 2\nmax = (n - m) * (n - m + 1) / 2\n\nputs [min, max].join ' '", "src_uid": "a081d400a5ce22899b91df38ba98eecc"} {"source_code": "n= gets\nwhile(n.size > 1)\n n=n[1..-1] if n[0] == '0'\n break if n[0]== '1'\nend\nif n.count('0')>=6\n print('yes')\nelse\n\tprint('no')\nend\n", "src_uid": "88364b8d71f2ce2b90bdfaa729eb92ca"} {"source_code": "n = readline.to_i\na = readline.split.map(&:to_i)\n\nsum = 0\na.each_cons(2) do |x,y|\n if x+y == 5\n print \"Infinite\\n\"\n exit\n else\n sum += x+y\n end\nend\n\na.each_cons(3) { |x,_,z| if x==3 and z==2 then sum -= 1 end }\n\nprint \"Finite\\n#{sum}\"\n", "src_uid": "6c8f028f655cc77b05ed89a668273702"} {"source_code": "x, y, m = gets.split.map(&:to_i)\nans = 0\nloop do\n x, y = y, x if x > y\n if y >= m\n break\n elsif y <= 0\n ans = -1\n break\n elsif x + y <= [0, m].min\n z = ([0, m].min - x) / y\n x += y * z\n ans += z\n else\n x += y\n ans += 1\n end\nend\nputs ans\n", "src_uid": "82026a3c3d9a6bda2e2ac6e14979d821"} {"source_code": "n = gets.chomp.split(\"\")\nvowels = ['A','E','I','O','U','Y']\njump = []\n\ntemp = 0\ncount = 0\nfor i in (0..n.size-1)\n\tif vowels.include?(n[i])\n\t\tcount += 1\n\tend\nend\nif count == 0\n\tprint n.size + 1\nelse\n\tfor i in (-1..n.size-1)\n\t\tfor x in (i..n.size-1)\n\t\t\tif i != x\n\t\t\t\tif i == -1\n\t\t\t\t\tif vowels.include?(n[x])\n\t\t\t\t\t\tjump << x-i\n\t\t\t\t\t\ttemp = x\n\t\t\t\t\t\tbreak\n\t\t\t\t\tend\n\t\t\t\telsif i < n.size-1\n\t\t\t\t\tif vowels.include?(n[i]) && vowels.include?(n[x])\n\t\t\t\t\t\tjump << x-i\n\t\t\t\t\t\ttemp = x\n\t\t\t\t\t\tbreak\n\t\t\t\t\tend\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\tend\n\tjump << n.size - temp\n\tprint jump.max\nend", "src_uid": "1fc7e939cdeb015fe31f3cf1c0982fee"} {"source_code": "n,m,z=gets.split.map(&:to_i)\nputs(z/n.lcm(m))", "src_uid": "e7ad55ce26fc8610639323af1de36c2d"} {"source_code": "input = gets\noutput = \"\"\ne_index = input.index(\"e\")\nd_index = input.index(\".\")\nfactor = input[(e_index + 1)..-1].to_i\noutput = input[0..(e_index-1)]\noutput[d_index] = \"\"\nfactor.times do |i|\n unless output[d_index + i]\n output[d_index + i] = \"0\"\n end\nend\noutput.insert(d_index + factor, \".\") if (d_index + factor) < output.length\noutput[(d_index + factor)..-1] = \"\" if output[(d_index + factor + 1)..-1].to_i == 0\nputs output\n", "src_uid": "a79358099f08f3ec50c013d47d910eef"} {"source_code": "arow1 = gets.chomp\narow2 = gets.chomp\nbrow1 = gets.chomp\nbrow2 = gets.chomp\narow1.gsub!(\"X\", \"\")\narow2.gsub!(\"X\", \"\")\nbrow1.gsub!(\"X\", \"\")\nbrow2.gsub!(\"X\", \"\")\n\na = arow1 + arow2.reverse\nb = brow1 + brow2.reverse\n\nif (a * 2).index(b)\n puts \"YES\"\nelse\n puts \"NO\"\nend", "src_uid": "46f051f58d626587a5ec449c27407771"} {"source_code": "n,k = gets.chomp.split(\" \").map(&:to_i)\nans = 0\nif 2*n-1 >= k\n m = k-1 <= n ? 1 : k-n\n ans += k/2-m+1\n ans -= 1 if k.even?\nend\nputs ans\n", "src_uid": "98624ab2fcd2a50a75788a29e04999ad"} {"source_code": "# your code goes here\ndef f0(s)\n\treturn (s+s.reverse).to_i\nend\n\narr=[]\n(\"1\"..\"9\").each{|e1|\n\tarr<a[1].to_i\nputs \"-1\"\nelse\nans=(a[0].to_i-1)*2+(a[1].to_i-sum)/5\nputs \"#{ans}\"\nend", "src_uid": "b16f5f5c4eeed2a3700506003e8ea8ea"} {"source_code": "n,k=gets.split.map(&:to_i)\np (1..9).find{|i|n*i%10==k||n*i%10==0}", "src_uid": "18cd1cd809df4744bb7bcd7cad94e2d3"} {"source_code": "n,m,i,j,a,b=gets.chomp.split.map(&:to_i)\nc=[n,m].max\np,q=[1,1,n,n],[1,m,1,m]\n4.times do |x|\n\tdy,dx=(q[x]-j).abs,(p[x]-i).abs\n\tif dy%b==0 && dx%a==0 && dy/b %2 == dx/a %2\n\t\tbreak if (a > [i-1,n-i].max && dy > 0) || (b > [j-1,m-j].max and dx > 0)\n\t\tc=[c,[dy/b,dx/a].max].min\n\tend\nend\nputs (c<[n,m].max) ? \"#{c}\" : \"Poor Inna and pony!\"\n", "src_uid": "51155e9bfa90e0ff29d049cedc3e1862"} {"source_code": "puts gets=~/[AEIOUYaeiouy]\\W*\\?/?:YES:\"NO\"", "src_uid": "dea7eb04e086a4c1b3924eff255b9648"} {"source_code": "t=gets.chomp.to_i\r\nl=0\r\nt.times do\r\n n=gets.chomp.to_i\r\n puts 2**n-1\r\nend", "src_uid": "d5e66e34601cad6d78c3f02898fa09f4"} {"source_code": "class Team\n\tattr_accessor :atk, :def\n\tdef initialize(a, d)\n\t\t@atk, @def = a, d\n\tend\n\tdef beat(other)\n\t\t@atk > other.def && @def > other.atk\n\tend\nend\nclass Member\n\tattr_accessor :atk, :def\n\tdef initialize(a)\n\t\t@def, @atk = a[0], a[1]\n\tend\nend\nm = []\n4.times { m << Member.new(gets.split.map &:to_i) }\nteam1a = Team.new(m[0].atk,m[1].def)\nteam1b = Team.new(m[1].atk,m[0].def)\nteam2a = Team.new(m[2].atk,m[3].def)\nteam2b = Team.new(m[3].atk,m[2].def)\nif (team2a.beat(team1a) || team2b.beat(team1a)) && (team2a.beat(team1b) || team2b.beat(team1b))\n\tputs 'Team 2'\nelsif (team1a.beat(team2a) && team1a.beat(team2b)) || (team1b.beat(team2a) && team1b.beat(team2b))\n\tputs 'Team 1'\nelse\n\tputs 'Draw'\nend\n\n", "src_uid": "1a70ed6f58028a7c7a86e73c28ff245f"} {"source_code": "def calcs(x,y,ax,ay,bx,by) ((ax-x)*(by-y)-(bx-x)*(ay-y))/2.0 end\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 kaizyo(n)(n < 2)? 1 : (2..n).inject(:*) end\n\ndef scount(a) b=na(a.max+1);a.each{|n|b[n]+=1};return b end\n\ndef na(n=0,d=0) Array.new(n,d)end\n\ndef na2(n=0,m=0,d=0) Array.new(n){Array.new(m,d)}end\n\ndef na3(n=0,m=0,l=0,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end\n\ndef bit(n) n.to_s(2).split(\"\").map(&:to_i) end\n\ndef inp() a=gets.chomp.split(\" \").map(&:to_i)end\n\ndef k2(k,n,m)\n return 1 if k == 0\n return n if(k == 1)\n ans = 1\n if((k%2) == 0)\n ans *= k2(k/2,n,m)**2\n else\n ans *= k2(k-1,n,m)\n ans *= n\n end\n return ans % m\nend\nmod = 10**9+7\na,b = inp\np k2(a,k2(b,2,mod)-1,mod)", "src_uid": "71029e5bf085b0f5f39d1835eb801891"} {"source_code": "a,b = gets.split(/\\s+/).map(&:to_i)\nmod = 1000000007\n\n maxa = b - 1\n\nans = 0\n if maxa > 0\n x1 = (b+1 + a*b+1)*a / 2\n xn = maxa*(b+1 + a*b+1)*a / 2\n ans = (x1 + xn) * maxa / 2\n end\n\np ans % mod\n", "src_uid": "cd351d1190a92d094b2d929bf1e5c44f"} {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# END\n\nn = gets.to_i\n\n# 1 2 3, sum = 6 halfsum = 3, {1,2} {3} delta = 0\n# 1 2 3 4, sum = 10 halsfsum = 5 {1 4} {2 3} delta = 0\n# 1 2 3 4 5, sum = 15 halfsum = 7.5, {1,3,4} {2, 5} delta = 1\n# 1 2 3 4 5 6, sum = 21 halfsum = 10.5, {1,6,3} {2,4,5} delta = 1\n# 1 2 3 4 5 6 7, sum = 28 halfsum = 14, {1,6,7} {2,3,4,5} delta = 0\n\nsum = n * (n + 1) / 2\n\nif sum.odd?\n puts 1\nelse\n puts 0\nend\n", "src_uid": "fa163c5b619d3892e33e1fb9c22043a9"} {"source_code": "n = gets.to_i\nphone = gets.split('')\n\neight_num = 0\n\nfor digit in phone\n\teight_num += 1 if digit=='8'\nend\n\nputs [eight_num, n/11].min", "src_uid": "259d01b81bef5536b969247ff2c2d776"} {"source_code": "a = gets.chars.map(&:to_i)\nl, h = a.slice(0, 3), a.slice(3, 3)\nd = h.reduce(&:+) - l.reduce(&:+)\nl, h, d = h, l, -d if d < 0\na, i = (l.map {|x| 9 - x} + h).sort!, 0\nwhile d > 0\n d -= a.pop\n i += 1\nend\np i\n\n", "src_uid": "09601fd1742ffdc9f822950f1d3e8494"} {"source_code": "#!/usr/bin/env ruby\n#codeforces.com/problemset/problem/16/C\n\ninput = gets.chomp.split(\" \").map(&:to_i)\n\na = input[0]\nb = input[1]\nx = input[2]\ny = input[3]\n\n\ndef gcd(a1, b1)\n b1 == 0 ? a1 : gcd(b1, a1.modulo(b1))\nend\n\n\ngcdd = gcd(x,y)\nx = x/gcdd\ny = y/gcdd\n\n\nmultiply = [a/x, b/y].min\n\nputs (x*multiply).to_s + \" \" +(y*multiply).to_s\n\n\n", "src_uid": "97999cd7c6de79a4e39f56a41ff59e7a"} {"source_code": "n = gets.strip.to_i\n# n, k = gets.strip.split.map(&:to_i)\natleast_half = n/2\natleast_half += (n%2)\n\ndef get_eaten(n, k)\n eaten = 0\n rem = n\n # puts rem if @d1\n # puts \"---\" if @d1\n # puts eaten\n while rem > 0 do\n # puts rem if @dbg\n if rem >= k\n eaten += k\n rem -= k\n else\n eaten += rem\n rem = 0\n end\n # puts rem if @d1\n # rem -= (0.1 * rem).floor\n rem -= (rem/10)\n # puts rem if @d1\n # puts eaten if @d1\n # puts \"eod\" if @d1\n # puts eaten\n end\n eaten\nend\n\n# puts get_eaten(n, k)\n\n\n\nlo = 1\nhi = n\nk = (lo + hi)/2\nwhile lo+1 < hi do\n k = (lo + hi) >> 1\n # puts \"#{lo}:#{k}:#{hi}\"\n if get_eaten(n, k) >= atleast_half\n hi = k\n else\n lo = k\n end\nend\n# while lo <= hi do\n# k = (lo + hi)/2\n# # puts \"#{lo}:#{k}:#{hi}\"\n# if get_eaten(n, k) >= (n/2.0).ceil\n# hi = k-1\n# else\n# lo = k+1\n# end\n# end\n# puts k\n# puts \"...\"\nmk = [1, k-1000].max\n(mk).upto(k+1000).each do |ki|\n # puts ki\n # @dbg = true\n if get_eaten(n, ki) >= atleast_half\n # puts get_eaten(n, ki)\n puts ki\n break\n end\nend\n# puts k\n\n# # puts \"---\"\n# 1.upto(n).each do |ki|\n# if get_eaten(n, ki) >= (n/2.0).ceil\n# # @d1 = true\n# # puts get_eaten(n, ki)\n# puts ki\n# break\n# end\n# end\n", "src_uid": "db1a50da538fa82038f8db6104d2ab93"} {"source_code": "n, k = gets.split.map { |x| x.to_i }\na = gets.split.map { |x| x.to_i }\n\nans = 0\n0.upto(k) do |i|\n\tb = a.select.with_index { |x, j| j % k == i }\n\tans += [b.count(1), b.count(2)].min\nend\nputs ans\n", "src_uid": "5f94c2ecf1cf8fdbb6117cab801ed281"} {"source_code": "require'prime'\nn=gets.to_i\nz=[1]*n\nn=(n+1)*n/2\nif !Prime.prime?(n)\n\tif n.odd?&&!Prime.prime?(n-2)\n\t\tn-=3\n\t\tz[2]=3\n\tend\n\t2.upto(n){|i|\n\tif Prime.prime?(i)&&Prime.prime?(n-i)\n\t\tz[i-1]=2\n\t\tbreak\n\tend\n\t}\nend\nputs z*' '\n", "src_uid": "94ef0d901f21e1945849fd5bfc2d1449"} {"source_code": "p, d = gets.chomp.split(' ')\nd = d.to_i\npointer = p.length - 1\nans = p.to_i\n\nloop do\n alen = ans.to_s.length\n if (ans.to_s[pointer].to_i != 9)\n number_to_minus = (ans.to_s[pointer].to_i + 1) * (10 ** (alen - 1 - pointer))\n if (number_to_minus <= d)\n d -= number_to_minus\n ans -= number_to_minus\n else\n break\n end\n end\n pointer -= 1\n pointer -=1 if (alen != ans.to_s.length)\n break if (pointer <= 0)\nend\n\nputs ans\n", "src_uid": "c706cfcd4c37fbc1b1631aeeb2c02b6a"} {"source_code": "(n, d) = gets.chomp.split.map(&:to_i)\ns = gets.chomp\n\ndef solve(n, d, s)\n (pre, pos, cnt) = [-1, 0, 0]\n while (pos != n - 1 and pre != pos) do\n pre = pos\n (1..d).each do |i|\n if (pre + i < n and s[pre + i] == '1')\n pos = pre + i\n end\n end\n cnt += 1\n end\n return (pos == n - 1) ? cnt : -1\nend\n\nprint \"#{solve(n, d, s)}\"", "src_uid": "c08d2ecdfc66cd07fbbd461b1f069c9e"} {"source_code": "a,c=gets.split.map &:to_i;b=0;20.times{|i|b+=(c/3**i-a/3**i)%3*3**i};p b\n", "src_uid": "5fb635d52ddccf6a4d5103805da02a88"} {"source_code": "#!/usr/bin/ruby1.9\n\nn, t = STDIN.readline.split.collect {|s| s.to_i }\nline = STDIN.readline.strip\nchars = line.split('').reverse\nt.times do\n\tnew_chars = []\n\ti = 0\n\twhile i < n do\n\t\tif chars[i] == 'G' and i+1 < n and chars[i+1] == 'B'\n\t\t\tnew_chars.push('B')\n\t\t\tnew_chars.push('G')\n\t\t\ti += 2\n\t\telse\n\t\t\tnew_chars.push(chars[i])\n\t\t\ti += 1\n\t\tend\n\tend\n\tchars = new_chars\nend\nputs chars.reverse.join('')\n\n", "src_uid": "964ed316c6e6715120039b0219cc653a"} {"source_code": "l = gets.to_i\nl+=1\nputs [l/36, l/3%12]*\" \"\n", "src_uid": "5d4f38ffd1849862623325fdbe06cd00"} {"source_code": "b = [1]\n12.times { b << b.last * 9 }\n\nn = gets.chomp\na = n.split('').map(&:to_i)\n\nm = a.reduce(:*)\n\na.count.times do |i|\n r = a[0..i].join.to_i - 1\n r = 1 if r == 0\n\n r = r.to_s.split('').map(&:to_i).reduce(:*)\n rem_digits = a.count - i - 1\n r *= b[rem_digits]\n m = [r, m].max\nend\n\nputs m\n", "src_uid": "38690bd32e7d0b314f701f138ce19dfb"} {"source_code": "number = gets.chomp\nlucky_number = number.split(\"\")\ncheck = 0\n\nlucky_number.each do |n|\n\tif n.to_i != 4 && n.to_i != 7 \n\t\tcheck += 1 \n\telse\n\t\tcheck += 0\n\tend\nend\n\nif check >= 1 \n\tif number.to_i%4 == 0 || number.to_i%7 == 0 || number.to_i%47 == 0 || number.to_i%74 == 0 || number.to_i%444 == 0 || number.to_i%447 == 0 || number.to_i%474 == 0 || number.to_i%477 == 0\n\t\tputs \"YES\"\n\telse\n\t\tputs \"NO\"\n\tend\nelse\n\tputs \"YES\"\nend", "src_uid": "78cf8bc7660dbd0602bf6e499bc6bb0d"} {"source_code": "n = gets.to_i\nm = gets.to_i\np (0..40).map{ |i| 1 << i }.find_index{ |i| i >= m } < n ? m : m % (1 << n)", "src_uid": "c649052b549126e600691931b512022f"} {"source_code": "n, t = gets.split.map(&:to_i)\n$mas = []\n$res = 0\nfor i in 1..n+1 do \n $mas[i] = []\n for j in 1..n+1 do \n $mas[i][j] = 0\n end\nend\n\ndef children(lft, rgt)\n if( $mas[lft][rgt] >= 1)\n $res += 1\n $mas[lft + 1][rgt] += ($mas[lft][rgt] - 1) * 0.5\n $mas[lft + 1][rgt + 1] += ($mas[lft][rgt] - 1) * 0.5\n end\nend\n\n$mas[1][1] = t\nfor i in 1..n do\n for j in 1..i do\n children(i, j)\n end\nend\nputs $res", "src_uid": "b2b49b7f6e3279d435766085958fb69d"} {"source_code": "numbers = gets\nnum = numbers.split(\" \")\nx = num[0].to_i\ny = num[1].to_i\nn = gets.to_i\nresult = 0\n\ncase n%6\nwhen 1\n result = x\nwhen 2\n result = y\nwhen 3\n result = y-x\nwhen 4\n result = -x\nwhen 5\n result = -y\nwhen 0\n result = x-y\nend\nputs result%1000000007\n", "src_uid": "2ff85140e3f19c90e587ce459d64338b"} {"source_code": "N = 42\nd = Array.new(N)\nfor i in 0...d.length\n d[i] = Array.new(N, 0)\nend\n\nfor i in 0...N\n d[0][i] = 1\nend\n\nfor n in 1...N\n for depth in 1...N\n for k in 0...n\n d[n][depth] += d[k][depth - 1] * d[n - k - 1][depth - 1]\n end\n end\nend\n\nn, depth = gets.split(/\\s+/).map{|x| x.to_i}\np d[n][n] - d[n][depth - 1]", "src_uid": "faf12a603d0c27f8be6bf6b02531a931"} {"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\na, b = gis\nc, d = gis\n\nrick = [b]\nmonty = [d]\nt = 1\n1000.times do\n rick << rick[-1] + a\n monty << monty[-1] + c\nend\n\nwhile !rick.empty? && !monty.empty?\n case rick[0] <=> monty[0]\n when 0\n puts rick[0]\n exit\n when -1\n rick.shift\n when 1\n monty.shift\n end\nend\n\nputs -1\n\n\n", "src_uid": "158cb12d45f4ee3368b94b2b622693e7"} {"source_code": "input = STDIN.gets.chomp.split(\" \")\n\nx = input[0].to_i\ny = input[1].to_i\n\n\nif(y*Math.log10(x) == x*Math.log10(y))\n\tputs \"=\"\n\nelsif(y*Math.log10(x) < x*Math.log10(y))\n\tputs \"<\"\nelsif(y*Math.log10(x) > x*Math.log10(y))\n\tputs \">\"\nend\n\n", "src_uid": "ec1e44ff41941f0e6436831b5ae543c6"} {"source_code": "n, m = readline.split.map(&:to_i)\n\np(if m == 0; 1 else [m, n - m].min end)\n", "src_uid": "c05d0a9cabe04d8fb48c76d2ce033648"} {"source_code": "a=gets.chomp.split(\" \")\ns=a[1].to_i\nq=a[2].to_i\nt=a[0].to_f\nans=(Math.log(t/s,q)).ceil\nputs \"#{ans}\"", "src_uid": "0d01bf286fb2c7950ce5d5fa59a17dd9"} {"source_code": "puts gets.to_i * 3 / 2", "src_uid": "031e53952e76cff8fdc0988bb0d3239c"} {"source_code": "n = gets.to_i\ns = gets\nflag = 0\nfor dl in 1..n\n\tfor q in 0..n-1 do\n\t\tsov = 0; \n\t\twhile q < n and s[q]=='*'\n\t\t\tsov+=1\n\t\t\tq += dl\n\t\tend\n\t\tif sov == 5 then flag = 1 \n\t\tend\n\tend\n\nend\n\nif flag == 1 then puts\"yes\"\nelse\nputs\"no\"\n\nend", "src_uid": "12d451eb1b401a8f426287c4c6909e4b"} {"source_code": "n, m = gets.chomp.split(/ /).map(&:to_i)\nif ( [n, m].min.even? )\n puts \"Malvika\"\nelse\n puts \"Akshat\"\nend\n", "src_uid": "a4b9ce9c9f170a729a97af13e81b5fe4"} {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\nn = gets.to_i\n\n# 5 power of n, and last two digits\n# 5**1112212 = xxxxxxxxxxxxxxxxxxxxxxxxxx[][]\n# n >= 2\n# 5**2 = 25\n# 5**3 = 5**2 * 5 = 25 * 5 = 125\n# 5**4 = 5**3 * 5 = 125 * 5 = 625\n# 5**5 = 5**4 * 5 = 625 * 5 = 3125\n\nputs \"25\"", "src_uid": "dcaff75492eafaf61d598779d6202c9d"} {"source_code": "n=gets.to_i\nsum=gets.split.map(&:to_i).reduce(:+)\np (1..5).map{|i|((i+sum)% (n+1)==1)?0:1}.reduce(:+)\n", "src_uid": "ff6b3fd358c758324c19a26283ab96a4"} {"source_code": "def run\n chars = $stdin.gets.chomp.split(//)\n\n pos = 0\n cur = 0\n while cur < chars.length\n if pos == 0\n if chars[cur] == '1'\n pos += 1\n else\n break\n end\n elsif pos == 1\n if chars[cur] == '4'\n pos += 1\n else\n pos = 0\n cur -= 1\n end\n elsif pos == 2\n if chars[cur] == '4'\n pos = 0\n else\n pos = 0\n cur -= 1\n end\n end\n\n cur += 1\n end\n\n puts cur == chars.length ? \"YES\" : \"NO\"\nend\n\nrun if $0 == __FILE__\n", "src_uid": "3153cfddae27fbd817caaf2cb7a6a4b5"} {"source_code": "n,a,b = gets.split[0].to_i\n\nans = Array.new(n,2)\n\nt = gets.split.map { |x| x.to_i }\nt.each do |x|\n\tans[x-1] = 1\nend\n\nprint ans.join(' ')\n", "src_uid": "a35a27754c9c095c6f1b2d4adccbfe93"} {"source_code": "n,k=gets.split.map(&:to_i)\na=gets.split.map(&:to_i)\nhoge=n\nk.times do |i|\n tmp = a[i] / 4\n if hoge >= tmp\n hoge -= tmp\n a[i] %= 4\n else\n a[i] -= hoge * 4\n hoge = 0\n end\n if hoge == 0\n break\n end\nend\nlim = 2 * n + hoge\nlim2 = hoge\nk.times do |i|\n tmp = a[i] / 2\n if lim >= tmp\n lim -= tmp\n a[i] %= 2\n else\n a[i] -= 2 * lim\n lim2 -= a[i]\n a[i] = 0\n end \nend\nlim2 += lim\nk.times do |i|\n lim2 -= a[i]\nend\nputs lim2 >= 0 ? \"YES\" : \"NO\"", "src_uid": "d1f88a97714d6c13309c88fcf7d86821"} {"source_code": "#! /usr/bin/env ruby\n\nn, m = gets.split.map &:to_i\na = gets.split\nb = gets.split\nc = a & b\n\nif not c.empty?\n puts c.min\nelse\n puts [a.min, b.min].sort.join\nend\n", "src_uid": "3a0c1b6d710fd8f0b6daf420255d76ee"} {"source_code": "i=gets.chomp;n=i.scan(/[^0]/).sort;s=n.shift||'';s+=(n+i.scan('0')).sort.join;puts gets.chomp==s ?'OK':'WRONG_ANSWER'\n", "src_uid": "d1e381b72a6c09a0723cfe72c0917372"} {"source_code": "s=-1\na,b,_,c,d=gets(p).bytes.map{|e|e%48-1}\n8.times{|x|8.times{|y|5!=(x-a)**2+(y-b)**2&&5!=(x-c)**2+(y-d)**2&&a!=x&&b!=y&&s+=1}}\np s\n", "src_uid": "073023c6b72ce923df2afd6130719cfc"} {"source_code": "#!/usr/bin/ruby\nn=gets.to_i\np n%2>0 ? 0 : (n+3)/4-1", "src_uid": "32b59d23f71800bc29da74a3fe2e2b37"} {"source_code": "n,m = gets.split.map(&:to_i)\nc =0\nfor i in(1..n)\n if m%i==0 && m/i<=n\n c += 1\n end\nend\nputs c", "src_uid": "c4b139eadca94201596f1305b2f76496"} {"source_code": "n = gets.chomp.to_i\nans = Array.new(n + 1, 0)\nans[1] = 1\nans[2] = 2\n(3..n).each do |i|\n ans[i] = ans[i - 2] + i\nend\nprint ans[n]", "src_uid": "f8af5dfcf841a7f105ac4c144eb51319"} {"source_code": "#=================================\n# Better be sure than sorry. \n#=================================\n$stdin=File.open(\"./input.txt\",\"r\") if ENV[\"LOGNAME\"]==\"skydos\"\n#=================================\n\nn=gets.to_i\ncolors=[?R, ?O, ?Y, ?G, ?B, ?I, ?V]\n\na=\"\"\ni=0\nwhile a.length=6\n\t\tcols = a[0,3]+a[-3..-1]\n\telse\n\t\tcols = \"\"\n\tend\n\t\n\tif cols.length==0\n\t\ta+=colors[i%7]\n\t\ti+=1\n\telse\n\t\tcolors.each{|c|\n\t\t\tif cols.index(c).nil?\n\t\t\t\ta+=c\n\t\t\t\tbreak\n\t\t\tend\n\t\t}\n\tend\nend\n\nputs a\n", "src_uid": "dc3817c71b1fa5606f316e5e94732296"} {"source_code": "str = gets\na = str.split()[0].to_i\nb = str.split()[1].to_i\narr = Array.new\nstr2 = gets\ncanndy = 0\ndiff = 0\nres = -1\n(0..a-1).each do |counter|\n temp = str2.split()[counter].to_i\n if ((temp + diff) <= 8 )\n canndy += (temp + diff)\n diff = 0\n else\n canndy += 8\n diff = temp + diff - 8\n end\n\n if (canndy >= b)\n res = counter+1\n break\n end\n arr[counter] = temp\nend\n\nputs res", "src_uid": "24695b6a2aa573e90f0fe661b0c0bd3a"} {"source_code": "hash={\"0\"=>2,\"1\"=>7,\"2\"=>2,\"3\"=>3,\"4\"=>3,\"5\"=>4,\"6\"=>2,\"7\"=>5,\"8\"=>1,\"9\"=>2,}\na=gets.chomp.split(\"\")\nans=hash[a[0]]*hash[a[1]]\nputs \"#{ans}\"\n", "src_uid": "76c8bfa6789db8364a8ece0574cd31f5"} {"source_code": "def g a, b\n return [a, b] if a == 0 || b == 0\n if a >= 2 * b\n g a % (2 * b), b\n elsif b >= 2 * a\n g a, b % (2 * a)\n else\n [a, b]\n end\nend\n\nn, m = gets.split.map &:to_i\n\nputs g(n, m).join ' '\n", "src_uid": "1f505e430eb930ea2b495ab531274114"} {"source_code": "@es = [0]\n@os = [0]\n\ndef get_evens(i, j)\n @es[j+1] - @es[i]\nend\n\ndef get_odds(i, j)\n @os[j+1] - @os[i]\nend\n\ndef valid(ary, i, j)\n get_evens(i, j) == get_odds(i, j)\nend\n\ndef get_key(i, b)\n \"#{i},#{b}\"\nend\n\n@cache = {}\ndef solve(i, ary, b)\n unless @cache[get_key(i, b)]\n if valid(ary, 0, i)==false\n @cache[get_key(i, b)] = -1\n elsif i<1\n @cache[get_key(i, b)] = 0\n else\n ans = 0\n ni = i-2\n while ni > 0 do\n cost = (ary[ni] - ary[ni+1]).abs\n if cost <= b && valid(ary, ni+1, i)\n mc = solve(ni, ary, b-cost)\n if mc != -1\n ans = [ans, mc+1].max\n end\n end\n ni -= 2\n end\n # puts [i, b, ans].inspect\n @cache[get_key(i, b)] = ans\n end\n end\n @cache[get_key(i, b)]\nend\n\nn, b = gets.strip.split.map(&:to_i)\nary = gets.strip.split.map(&:to_i)\n0.upto(n-1).each do |i|\n if ary[i]%2 == 0\n @es << (@es[i] + 1)\n @os << (@os[i])\n else\n @es << (@es[i])\n @os << (@os[i] + 1)\n end\nend\n\nputs [solve(n-1, ary, b),0].max\n# puts @cache.inspect\n", "src_uid": "b3f8e769ee7719ea5c9f458428b16a4e"} {"source_code": "n = gets.chomp.to_i\n\ndef solve(n)\n monets = [1, 5, 10, 20, 100].reverse\n count = 0\n for monet in monets\n while n - monet >= 0\n n = n - monet\n count += 1\n end\n end\n return count\nend\n\nputs solve(n)", "src_uid": "8e81ad7110552c20297f08ad3e5f8ddc"} {"source_code": "ss = gets.split.map(&:to_i).sort\n\nputs [(ss.max + 1) - (ss[0] + ss[1]), 0].max", "src_uid": "3dc56bc08606a39dd9ca40a43c452f09"} {"source_code": "#!/usr/bin/ruby\n\nn = gets.chomp.to_i\na = gets.chomp.split\n\nper = 0\na.each { |i| per += i.to_i }\nper /= ( n / 2 )\n\n\nfor i in 0...n do\n next if a[i].to_i == 0\n for j in i+1...n do\n if a[j].to_i > 0 && a[i].to_i + a[j].to_i == per\n puts \"#{i+1} #{j+1}\"\n a[i] = a[j] = \"0\"\n break\n end\n end\nend\n", "src_uid": "6e5011801ceff9d76e33e0908b695132"} {"source_code": "s = gets.chomp.split(\"\")\na = ['a','e','i','o','u']\n\ncount = 0\nfor i in (0..s.size-1)\n\tif a.include?(s[i]) || s[i].to_i%2 != 0\n\t\tcount += 1\n\tend\nend\n\nprint count", "src_uid": "b4af2b8a7e9844bf58ad3410c2cb5223"} {"source_code": "def is_hour_palindromable(h)\n case h\n when 0..5\n return true\n when 10..15\n return true\n when 20..23\n return true\n else\n return false\n end\nend\n\ndef get_next_hour(h)\n nh = h < 23 ? h + 1 : 0\n is_hour_palindromable(nh) ? nh : get_next_hour(nh)\nend\n\nh, m = gets.split(':')#.map { |x| x.to_i }\nh = (get_next_hour h.to_i).to_s unless is_hour_palindromable(h.to_i) && m.to_i < h.reverse.to_i\nfh = \"%02d\" % h\nputs \"#{fh}:#{fh.reverse}\"", "src_uid": "158eae916daa3e0162d4eac0426fa87f"} {"source_code": "# -*- coding: utf-8 -*-\nclass Th < Struct.new(:a,:b,:c,:i)\nend\n\n$n,$m,$k=gets.split.map(&:to_i)\n$ths = []\n$m.times{|i|\n $ths << Th.new(*gets.split.map(&:to_i), i+1)\n}\n$ths.sort_by! {|th| th.c }\n\n# i 番目以降 で v の値を取って、残りr\n$h={}\ndef f(i,v,r)\n return [-1, nil] if r > $m-i\n key = [i,v,r]\n return $h[key] if $h.key? key\n\n cand = [[-1,nil]]\n th = $ths[i]\n if th.a <= v && v <= th.b\n if r==1\n cand << [v, [[th.i,v]]]\n else\n j = i+1\n j += 1 while j<$ths.size && th.c == $ths[j].c\n if j < $ths.size\n [f(j, v*$k, r-1), f(j, v+$k, r-1)].each {|sum, path|\n cand << [sum+v, [[th.i,v]] + path] if not path.nil?\n }\n end\n end\n end\n cand << f(i+1,v,r)\n cand.sort_by!(&:first)\n $h[key] = cand.last\nend\n\nvs = []\n$ths[0..$m-$n].each{|th| vs += (th.a..th.b).to_a }\nvs.sort!\nvs.uniq!\nmaxsum, maxpath = -1, nil\nvs.each{ |v|\n sum, path = f(0, v, $n)\n maxsum, maxpath = sum, path if sum > maxsum\n}\n\nif maxsum == -1\n puts 'NO'\nelse\n puts 'YES'\n maxpath.each{|i,v|\n puts \"#{i} #{v}\"\n }\nend", "src_uid": "c98fdad8e7ce09b8ac389108f72cecd9"} {"source_code": "def check? a1, a2, a3\n if !a1.nil? && !a2.nil? && !a3.nil?\n if (a1 == 'x' && a2 == 'x' && a3 == '.') \\\n || (a1 == 'x' && a2 == '.' && a3 == 'x') \\\n || (a1 == '.' && a2 == 'x' && a3 == 'x')\n return true\n end\n end\n false\nend\ngrid = Array.new(4)\n4.times do |i|\n grid[i] = gets.strip.split(\"\")\nend\nans = \"NO\"\n4.times do |i|\n 4.times do |j|\n a1 = grid[i][j]\n a2 = grid[i][j + 1] if j + 1 < 4\n a3 = grid[i][j + 2] if j + 2 < 4\n if check? a1, a2, a3\n ans = \"YES\"\n break\n end\n a2 = nil\n a3 = nil\n a2 = grid[i][j - 1] if j - 1 >= 0\n a3 = grid[i][j - 2] if j - 2 >= 0\n if check? a1, a2, a3\n ans = \"YES\"\n break\n end\n a2 = nil\n a3 = nil\n a2 = grid[i + 1][j] if i + 1 < 4\n a3 = grid[i + 2][j] if i + 2 < 4\n if check? a1, a2, a3\n ans = \"YES\"\n break\n end\n a2 = nil\n a3 = nil\n a2 = grid[i - 1][j] if i - 1 >= 0\n a3 = grid[i - 2][j] if i - 2 >= 0\n if check? a1, a2, a3\n ans = \"YES\"\n break\n end\n a2 = nil\n a3 = nil\n a2 = grid[i - 1][j - 1] if i - 1 >= 0 && j - 1 >= 0\n a3 = grid[i - 2][j - 2] if i - 2 >= 0 && j - 2 >= 0\n if check? a1, a2, a3\n ans = \"YES\"\n break\n end\n a2 = nil\n a3 = nil\n a2 = grid[i + 1][j - 1] if i + 1 < 4 && j - 1 >= 0\n a3 = grid[i + 2][j - 2] if i + 2 < 4 && j - 2 >= 0\n if check? a1, a2, a3\n ans = \"YES\"\n break\n end\n a2 = nil\n a3 = nil\n a2 = grid[i + 1][j + 1] if i + 1 < 4 && j + 1 < 4\n a3 = grid[i + 2][j + 2] if i + 2 < 4 && j + 2 < 4\n if check? a1, a2, a3\n ans = \"YES\"\n break\n end\n a2 = nil\n a3 = nil\n a2 = grid[i - 1][j + 1] if i - 1 >= 0 && j + 1 < 4\n a3 = grid[i - 2][j + 2] if i - 2 >= 0 && j + 2 < 4\n if check? a1, a2, a3\n ans = \"YES\"\n break\n end\n end\nend\nputs ans\n", "src_uid": "ca4a77fe9718b8bd0b3cc3d956e22917"} {"source_code": "# Codeforces Beat Round #75\n# Problem A -- Chips\nn, m = gets.split.map(&:to_i)\ni = 1\nwhile i <= m do \n m -= i\n i = 1 + i % n\nend\nputs m\n", "src_uid": "5dd5ee90606d37cae5926eb8b8d250bb"} {"source_code": "class A\n def self.run(w, h, k)\n r = 0\n k.times do |i|\n ww = w - 4*i\n hh = h - 4*i\n \n r += 2*ww + 2 * hh - 4\n end\n r\n end\nend\n\nw, h, k = gets.chomp.split.map(&:to_i)\nputs A.run(w, h, k)", "src_uid": "2c98d59917337cb321d76f72a1b3c057"} {"source_code": "n=gets.to_i\np (n-4..n).reduce(:*)**2/120", "src_uid": "92db14325cd8aee06b502c12d2e3dd81"} {"source_code": "#不是闰年,就是说:2月份是28天\nnumber=gets.chomp.split\nm=number[0].to_i\nd=number[1].to_i\nmonth=[0,31,28,31,30,31,30,31,31,30,31,30,31]\n#puts month[m]\ncolumn=(month[m]-(8-d))/7\nif (month[m]-(8-d))%7 > 0\n\tcolumn+=1\nend\nputs column+1\n", "src_uid": "5b969b6f564df6f71e23d4adfb2ded74"} {"source_code": "$a,$b,$n=gets.split.map(&:to_i)\n$m=10**9+7\nf=[1.0]\n1.upto($n){|i|f[i]=f[i-1]*i%$m}\nf.map!(&:to_i)\ndef g(x)while x>0;x,d=x.divmod 10;return 0 if d!=$a&&d!=$b end;1 end\ndef pow(x,p)p<1?1:pow(x,p/2)**2*x**(p%2)%$m end\nr=0\n($n+1).times{|i|r+=f[$n]*pow(f[$n-i]*f[i],$m-2) if g($a*i+($n-i)*$b)>0}\np r%$m", "src_uid": "d3e3da5b6ba37c8ac5f22b18c140ce81"} {"source_code": "p [3**~-gets.to_i%1000003,1].max\n", "src_uid": "1a335a9638523ca0315282a67e18eec7"} {"source_code": "s = ''\n8.times { s += gets }\n\nputs s =~ /(.)\\1/ ? 'NO' : 'YES'", "src_uid": "ca65e023be092b2ce25599f52acc1a67"} {"source_code": "n, h, m = gets.split.map(&:to_i)\nrest = Array.new(n, h)\nm.times do\n l, r, x = gets.split.map(&:to_i)\n (l..r).each do |pos|\n rest[pos-1] = [rest[pos-1], x].min\n end\nend\n\nans = 0\nrest.each do |r|\n ans += r ** 2\nend\nputs ans\n\n", "src_uid": "f22b6dab443f63fb8d2d288b702f20ad"} {"source_code": "\ndef fact(x)\n fact = 1\n x.times do |el|\n fact *= (el + 1)\n #fact %= (10**9 + 7)\n end\n fact\nend\n\n\ndef fact_mod(x)\n fact = 1\n x.times do |el|\n fact *= (el + 1)\n fact %= (10**9 + 7)\n end\n fact\nend\n\ndef fc(n, k)\n return 0 if k > n\n fact(n)/(fact(n - k)) # % (10**9 + 7)\nend\n\nn, x, pos = gets.chomp.split(' ').map(&:to_i)\nless = -1 \ngreater = 0\nleft = 0\nright = n\narr = (1..n).to_a\nwhile left < right\n middle = (left + right) / 2\n if arr[middle] <= pos + 1\n less += 1\n left = middle + 1\n else\n greater += 1\n right = middle\n end\nend\ngr_count = n - x\nls_count = n - gr_count - 1\nfixed = n - less - greater - 1\nputs (fact(fixed) * fc(gr_count, greater) * fc(ls_count, less)) % (10**9 + 7)\n", "src_uid": "24e2f10463f440affccc2755f4462d8a"} {"source_code": "a=gets.chomp.split(\" \")\n0.upto(2) {|i| a[i]=a[i].to_i }\nx=[a[0],a[1]].min\nif x>=2*a[2]\nputs \"First\"\nelse\nputs \"Second\"\nend\n\n", "src_uid": "90b9ef939a13cf29715bc5bce26c9896"} {"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\na = inp[0]\nb = inp[0]\nc = inp[0]\nd = inp[0]\ne = inp[0]\nmaxy = a*(c-1)+b*(d-1)\nmin = [e-maxy,0].max\nif(c > d)\n max = [e/d,b].min\n e -= max * d\n max += e/c\nelse\n max = [e/c,a].min\n e -= max * c\n max += e/d\nend\nputs \"#{min} #{max}\"", "src_uid": "2be8e0b8ad4d3de2930576c0209e8b91"} {"source_code": "a = gets.split.map(&:to_i)\nx = gets.split.map(&:to_i)\n\na = a.zip(x).map { |a,x|\n if a < x\n [0, x - a]\n else\n [(a - x)/2, 0]\n end\n}\n\na, x = a.transpose.map{|x| x.inject(&:+)}\n\nif a >= x\n puts \"Yes\"\nelse\n puts \"No\"\nend\n", "src_uid": "1db4ba9dc1000e26532bb73336cf12c3"} {"source_code": "def f(a,s)\n\tif a==[]\n\t\treturn \"YES\"\n\telse\n\t\tb=a.shift\n\t\tb=b.to_i\n\t\tif s.any?{|e| e==b}\n\t\t\ts=[1,2,3].select{|e|\n\t\t\t\te==b || s.all?{|e2| e2!=e}\n\t\t\t}\n\t\t\treturn f(a,s)\n\t\telse\n\t\t\treturn \"NO\"\n\t\tend\n\tend\nend\na=STDIN.each_line.to_a\na.shift\nputs f(a,[1,2])", "src_uid": "6c7ab07abdf157c24be92f49fd1d8d87"} {"source_code": "a = gets.to_i\nb = gets.to_i\nc = gets.to_i\n\nputs [a+b+c, (a+b)*c, a+(b*c), (a*b)+c, a*(b+c), a*b*c].max\n", "src_uid": "1cad9e4797ca2d80a12276b5a790ef27"} {"source_code": "n = gets.to_i\nputs [0, gets.split.map(&:to_i).max - n - (25 - n)].max\n", "src_uid": "ef657588b4f2fe8b2ff5f8edc0ab8afd"} {"source_code": "l,r,x,y,k=gets.split.map &:to_i\nputs ([(l+k-1)/k,x].max>[r/k,y].min)?'NO':'YES'", "src_uid": "1110d3671e9f77fd8d66dca6e74d2048"} {"source_code": "class BearBalls\n def consecutive_elements?(array)\n array.find.with_index do |_, i|\n array[i] + 2 == array[i + 2] \n end\n end\n\n def run(balls)\n balls_array = balls.split.map(&:to_i).sort.uniq\n puts consecutive_elements?(balls_array) ? \"YES\" : \"NO\"\n end\nend\n\nsize = gets.chomp\nballs = gets.chomp\nBearBalls.new.run(balls)\n", "src_uid": "d6c876a84c7b92141710be5d76536eab"} {"source_code": "n=gets.to_i\nwhile n!=1\n\tprint \"#{n} \"\n\tfor i in 2..n\n\t\tif n%i==0\n\t\t\tn/=i\n\t\t\tbreak\n\t\tend\n\tend\nend\nprint \"#{n}\"\nputs", "src_uid": "2fc946bb72f56b6d86eabfaf60f9fa63"} {"source_code": "n, m = gets.split.map(&:to_i)\nar1 = gets.split.map(&:to_i)\nar2 = gets.split.map(&:to_i)\nputs (ar1 & ar2).join(\" \")", "src_uid": "f9044a4b4c3a0c2751217d9b31cd0c72"} {"source_code": "require 'matrix'\n\na1, b1, c1 = gets.split.map { |v| Rational(v.to_i) }\na2, b2, c2 = gets.split.map { |v| Rational(v.to_i) }\na3, b3, c3 = [0, 0, 0].map { |v| Rational(v) }\n\nrank_a = Matrix[ [a1, b1], [a2, b2] ].rank\nrank_b = Matrix[ [a1, b1, c1], [a2, b2, c2], [a3, b3, c3] ].rank\n\nresult = 0\n\nif rank_a == rank_b\n result = rank_a == 2 ? 1 : -1;\nend\n\nputs result\n", "src_uid": "c8e869cb17550e888733551c749f2e1a"} {"source_code": "n=gets.chomp.to_i\na=Array.new(6,0)\nb=Array.new(6,0)\ninteger=gets.chomp.split(\" \")\ninteger.each do |integer|\n #puts \"a=#{integer}\"\n a[integer.to_i]+=1;\nend\ninteger=gets.chomp.split(\" \")\ninteger.each do |integer|\n #puts \"b=#{integer}\"\n b[integer.to_i]+=1;\nend\natob=0\nbtoa=0\ncan=1\n#for i in 1..5\n# puts \"#{i} #{a[i]} #{b[i]}\"\n#end\n\nfor i in 1..5\n if a[i] > b[i]\n if (a[i]-b[i])%2!=0\n can=0\n break\n end\n atob+=(a[i]-b[i])/2;\n elsif a[i] < b[i]\n if (b[i]-a[i])%2!=0\n can=0\n break\n end\n btoa+=(b[i]-a[i])/2;\n end\n\n #感觉只要处理一种情况就可以!\nend\nif can==1\n puts atob\nelse\n puts -1\nend\n", "src_uid": "47da1dd95cd015acb8c7fd6ae5ec22a3"} {"source_code": "#!/usr/bin/ruby\n\ndef readNextValues\n gets.split.map {|x| x.to_i}\nend\n\nline = gets.chomp\n\ntable = {\">\" => \"1000\", \"<\" => \"1001\", \"+\" => \"1010\", \"-\" => \"1011\", \".\" =>\"1100\", \",\"=>\"1101\", \"[\"=>\"1110\", \"]\"=>\"1111\"}\n\ncon = \"\"\nline.each_char do |a|\n con += table[a]\nend\nputs con.to_i(2) % 1000003\n", "src_uid": "04fc8dfb856056f35d296402ad1b2da1"} {"source_code": "nmk = gets.chomp.split(\" \").collect {|x| x.to_i}\nns = gets.chomp.split(\" \").collect {|x| (x.to_i - 1)}\nns.sort!\nsum = nmk[1]-nmk[2]\nrez = 0\np = 0\nwhile sum>0 and p0\n puts -1\n else\n puts p\n end", "src_uid": "b32ab27503ee3c4196d6f0d0f133d13c"} {"source_code": "k = gets.to_i\na = gets.split.map(&:to_i)\n0.upto(12) do |n|\n a.combination(n) do |b|\n if b.inject(0, &:+) >= k\n p n\n exit\n end\n end\nend\np -1\n", "src_uid": "59dfa7a4988375febc5dccc27aca90a8"} {"source_code": "def sorting(a,index)\n for i in 0...a.length\n for j in i+1...a.length\n if a[i]>a[j]\n a[i],a[j]=a[j],a[i]\n index[i],index[j]=index[j],index[i]\n end\n end\n end\nend\nn,k=gets.split().map{|i| Integer(i)}\na=gets.split().map{|i| Integer(i)}\nindex=Array.new\nfor i in 0...n\n index[i]=i+1\nend\nsorting(a,index)\ncount=0\nlist=Array.new\nfor i in a\n k-=i\n if k>=0\n count+=1\n end\nend \nputs count\nout=Array.new\nif count>0\n for i in 0...count\n out.push(index[i])\n end\nend\nout.sort!\nprint out*\" \"", "src_uid": "dbb164a8dd190e63cceba95a31690a7c"} {"source_code": "gets\nmas = gets.split(\" \").map(&:to_i)\nans = 0\nwhile mas.rindex(mas.max) != 0 do\n mas[mas.rindex(mas.max)] -= 1\n ans+=1\n mas[0]+=1\nend\n\n\nprint ans\n", "src_uid": "aa8fabf7c817dfd3d585b96a07bb7f58"} {"source_code": "gets;p *$<.map{|e|e.to_i/2}", "src_uid": "a661b6ce166fe4b2bbfd0ace56a7dc2c"} {"source_code": "r, g, b = gets.split.map(&:to_i).sort\n\ndef f (r, g, b)\n min = [r,g,b].min\n return -100 if min < 0\n r-=min\n g-=min\n b-=min\n min + r / 3 + g / 3 + b / 3\nend\n\nputs [f(r, g, b), f(r-1, g-3, b-3)+2].max\n\n\n", "src_uid": "acddc9b0db312b363910a84bd4f14d8e"} {"source_code": "a, b, c = gets.split.map{|x| x.to_i}\n\nx = (0..c/a).to_a.index{|w| ((c - (w * a)) % b).zero?}\n\nputs \"No\" if x.nil?\nputs \"Yes\" unless x.nil?", "src_uid": "e66ecb0021a34042885442b336f3d911"} {"source_code": "k, a, b, v = gets.split.collect{|i| i.to_i}\nans = 0\nif a <= b/(k-1)*k*v\n puts (a+k*v-1)/(k*v)\n exit\nelse\n ans += b/(k-1)\n a -= ans*k*v\nend\nif a <= (b%(k-1)+1)*v\n puts ans+1\n exit\nelse\n ans += 1\n a -= (b%(k-1)+1)*v\nend\nputs ans+(a+v-1)/v\n", "src_uid": "7cff20b1c63a694baca69bdf4bdb2652"} {"source_code": "#!/usr/bin/ruby\n\nwhile line = gets\n\tn, k = line.split.map(&:to_i)\n\tans = [ n * 3 - k, 0 ].max\n\tputs ans\nend\n", "src_uid": "5a5e46042c3f18529a03cb5c868df7e8"} {"source_code": "n=gets.to_i\nfor i in 1..n-1\n\tprint i\n\tfor j in 2..n-1\n\t\tprint (i*j).to_s(n).rjust(3, ' ')\n\tend\n\tputs\nend", "src_uid": "a705144ace798d6b41068aa284d99050"} {"source_code": "module Memoizer\n def memoize(methodname)\n raise ArgumentError, \"statefull method [#{methodname}]should not be memoized\" if methodname.match(/\\!\\z/)\n unbound_method = instance_method(methodname)\n raise ArgumentError, \"method [#{methodname}] with argument cannot be memoized\" if unbound_method.arity > 0\n memoized_object_name = \"@_memoized_#{methodname}\"\n define_method(methodname) do\n if(instance_variable_get(memoized_object_name).nil?)\n instance_variable_set(memoized_object_name, unbound_method.bind(self).call)\n end\n instance_variable_get(memoized_object_name)\n end\n end\nend\n\nclass Problem\n attr_reader(:e, :o)\n def initialize(e, o)\n @e = e\n @o = o\n end\n\n def ans\n return false if (e == 0 and o == 0)\n (e - o).abs <= 1\n end\n\n def out\n return \"YES\" if ans\n return \"NO\"\n end\nend\n\ne, o = gets.split(\" \").map(&:to_i)\nputs Problem.new(e, o).out\n", "src_uid": "ec5e3b3f5ee6a13eaf01b9a9a66ff037"} {"source_code": "ab = gets.chomp.split.map(&:to_i)\n\nn = 1\nfor i in (1..ab.min)\n\tn *= i\nend\n\nprint n", "src_uid": "7bf30ceb24b66d91382e97767f9feeb6"} {"source_code": "#!/usr/bin/ruby\na,b=gets.split.map(&:to_i)\np Enumerator.new{|y|\n\t(1..1/0.0).each{|i|\n\t\t1.upto(i){|j|\n\t\t\ty<<('1'*j+'0'+'1'*(i-j)).to_i(2)\n\t\t}\n\t}\n}.lazy.drop_while{|e|e 1}\nx, y = 0, 0\nbug = false\nvalue = 1\n\nroute.each_char do |direction|\n\tcase direction\n\twhen \"R\" then x += 1\n\twhen \"L\" then x -= 1\n\twhen \"U\" then y += 1\n\twhen \"D\" then y -= 1\n\tend\n\n\t(bug = true and break) if visited[[x, y]] && visited[[x, y]] > 0\n\t\n\tvalue += 1\n\t(-1..1).each do |i|\n\t\t(-1..1).each do |j|\n\t\t\tnext unless i ** 2 + j ** 2 == 1\n\t\t\tif visited[[x + i, y + j]] && visited[[x + i, y + j]] > 0\n\t\t\t\tbug = true if visited[[x + i, y + j]] != value - 1\n\t\t\tend\n\t\tend\n\tend\n\tvisited[[x, y]] = value\nend\n\nif bug then\n\tputs \"BUG\"\nelse\n\tputs \"OK\"\nend", "src_uid": "bb7805cc9d1cc907b64371b209c564b3"} {"source_code": "n = gets.to_i\nc = gets.strip\nd = {'R'=>0, 'G'=>0, 'B'=>0}\nfor i in c.split('')\n d[i]+=1\nend\n\nr = ''\nif c.size == 0\n puts ''\nelsif d['R'] > 0 && d['G'] > 0 && d['B'] > 0\n puts 'BGR'\nelse\n if d['R'] == 0 && d['G'] == 0\n puts 'B'\n elsif d['R'] == 0 && d['B'] == 0\n puts 'G'\n elsif d['G'] == 0 && d['B'] == 0\n puts 'R'\n elsif d['R'] == 0\n if d['G'] > 1 && d['B'] == 1\n puts 'BR'\n elsif d['B'] > 1 && d['G'] == 1\n puts 'GR'\n elsif d['B'] == 1 && d['G'] == 1\n puts 'R'\n else\n puts 'BGR'\n end\n elsif d['G'] == 0\n if d['R'] > 1 && d['B'] == 1\n puts 'BG'\n elsif d['B'] > 1 && d['R'] == 1\n puts 'GR'\n elsif d['B'] == 1 && d['R'] == 1\n puts 'G'\n else\n puts 'BGR'\n end\n elsif d['B'] == 0\n if d['R'] > 1 && d['G'] == 1\n puts 'BG'\n elsif d['G'] > 1 && d['R'] == 1\n puts 'BR'\n elsif d['G'] == 1 && d['R'] == 1\n puts 'B'\n else\n puts 'BGR'\n end\n end\nend\n", "src_uid": "4cedd3b70d793bc8ed4a93fc5a827f8f"} {"source_code": "a = gets.split(' ')\nk = a[0].to_i\nn = a[1].to_i\nw = a[2].to_i\nneed = k*(1+w)*w/2 - n\nif need < 0\n need = 0\nend\nputs need\n=begin\nstring = \"foobar\"\nputs \"The string '#{string}' is nonempty.\" unless string.empty?\n\nputs \"foo bar baz\".split\na = [42, 8, 17]\nputs '['+a.join(', ')+']'\nb = []\n(1..5).each do |i|\n b[i] = 2*i\nend\nputs b\n\n\nc = %w[a b c]\nputs '[\"'+c.join('\", \"')+'\"]'\n\nuser = { :name => \"Michael Hartl\", :email => \"michael@example.com\" }\nputs user[:name]\nputs user[:password]\n\ndef pow(x, y)\n p = 1\n y.times{p *= x}\n return p\nend\nz = pow(3,4)\nputs z\n=end", "src_uid": "e87d9798107734a885fd8263e1431347"} {"source_code": "def avg(x)\n x.inject(:+)/4.0\nend\n\ndef med(x)\n (x[1] + x[2])/2.0\nend\n\ndef ran(x)\n x[3] - x[0]\nend\n\ndef cond(x)\n # [avg(x), med(x), ran(x)] == [ran(x)] * 3\n avg(x) == ran(x) and ran(x) == med(x)\nend\n\nn = gets.chomp!.to_i\nx = []\nn.times do\n x << gets.chomp.to_i\nend\nx.sort!\n\ndef four(x)\n if cond(x)\n puts \"YES\"\n else\n puts \"NO\"\n end\nend\n\nMAX_B = 2000\ndef tree(x)\n 1.upto(MAX_B) do |i|\n tmp = x.clone\n tmp << i\n tmp.sort!\n break if (tmp[3] - tmp[0] > (tmp[1] + tmp[2])) and i > 2 * tmp[-1] #WTF?\n if cond(tmp)\n puts \"YES\"\n puts i\n return\n end\n end\n puts \"NO\"\nend\n\ndef two(x)\n tmp = x.clone\n if tmp[1] < 4 * tmp[0]\n puts \"YES\", [4 * tmp[0] - tmp[1], 3 * tmp[0]].minmax\n return\n end\n puts \"NO\"\nend\n\ndef one(x)\n puts \"YES\"\n puts x[0], x[0]*3, x[0]*3\nend\n\ndef zero\n puts \"YES\", [1, 1, 3, 3]\nend\n\n\none(x) if n == 1\ntwo(x) if n == 2\ntree(x) if n == 3\nfour(x) if n == 4\nzero if n == 0\n\n\n", "src_uid": "230e613abf0f6a768829cbc1f1a09219"} {"source_code": "def gcd (d1, d2)\n if d1 < d2\n tmp = d1\n d1 = d2\n d2 = tmp\n end\n rem = d1 % d2\n rem < Math::PI / 100 ? d2 : gcd(d2, rem)\nend\n\npoints = []\nARGF.each_line do |line|\n points.push({\n 'x' => line.split[0].to_f,\n 'y' => line.split[1].to_f\n })\nend\n\na = Math.sqrt((points[1]['x'] - points[0]['x']) ** 2 + (points[1]['y'] - points[0]['y']) ** 2)\nb = Math.sqrt((points[2]['x'] - points[1]['x']) ** 2 + (points[2]['y'] - points[1]['y']) ** 2)\nc = Math.sqrt((points[2]['x'] - points[0]['x']) ** 2 + (points[2]['y'] - points[0]['y']) ** 2)\n\nR = a*b*c / Math.sqrt((a+b+c)*(c+b-a)*(a-b+c)*(a+b-c))\n\nRpower2 = R ** 2\n\ndef getangle(side)\n d = 1 - side ** 2 / (2 * Rpower2)\n d < -1 ? -1 : d > 1? 1 : d\nend\n\nangA = Math.acos(getangle(a))\nangB = Math.acos(getangle(b))\nangC = Math.acos(getangle(c))\n\ngcd0 = gcd(2 * Math::PI, angA)\ngcd1 = gcd(angB, gcd0)\ngcd2 = gcd(angC, gcd1)\n\ncount = 2 * Math::PI / gcd2\n\nS = count / 2 * Rpower2 * Math.sin(2 * Math::PI / count)\n\nputs S\n", "src_uid": "980f4094b3cfc647d6f74e840b1bfb62"} {"source_code": "f, m, s = 3.times.map { gets.chomp }\n\nlabels = %w(F M S)\narr = [f, m, s]\nu = arr.uniq\n\nif u.size == 1 || u.size == 3\n puts \"?\"\nelse\n si = arr.index('scissors')\n ri = arr.index('rock')\n pi = arr.index('paper')\n\n res = arr.count{ |x| x == 'paper' } == 2 && si ? labels[si] : nil\n res = arr.count{ |x| x == 'rock' } == 2 && pi ? labels[pi] : nil unless res\n res = arr.count{ |x| x == 'scissors' } == 2 && ri ? labels[ri] : nil unless res\n\n puts res ? res : \"?\"\nend\n", "src_uid": "072c7d29a1b338609a72ab6b73988282"} {"source_code": "t=$<.read.chop;puts(t==t.reverse ? :YES:'NO')\n", "src_uid": "6a5fe5fac8a4e3993dc3423180cdd6a9"} {"source_code": "#!/usr/bin/ruby\n\nrequire 'prime'\n\nn = gets.to_i\nif Prime.prime?(n) then\n\tputs 1\n\tputs n\nelse\n\tn -= 3\n\tif Prime.prime?(n) then\n\t\tputs 2\n\t\tputs(\"3 #{n}\")\n\telse\n\t\tPrime.each(n) do |p|\n\t\t\tif Prime.prime?(n-p) then\n\t\t\t\tputs 3\n\t\t\t\tputs(\"3 #{p} #{n-p}\")\n\t\t\t\tbreak\n\t\t\tend\n\t\tend\n\tend\nend\n\n", "src_uid": "f2aaa149ce81bf332d0b5d80b2a13bc3"} {"source_code": "n, s = gets.chomp.split.map &:to_i\n\ndef differ(x)\n string = x.to_s\n for i in 0...string.length\n x -= string[i].to_i\n end\n return x\nend\n\nl = 1\nr = n\nm = -1\nwhile l <= r do\n m = (l + r) / 2\n if differ(m) < s\n l = m + 1\n else\n r = m - 1\n end\nend\nif differ(m) >= s\n amount = n - m + 1\nelse\n amount = n - m\nend\nputs amount", "src_uid": "9704e2ac6a158d5ced8fd1dc1edb356b"} {"source_code": "a,b=gets.split.map(&:to_i)\np (a*b-1)/(b-1)\n\n", "src_uid": "a349094584d3fdc6b61e39bffe96dece"} {"source_code": "def lucky(i, b)\n i.to_s.gsub(/[^47]/, '').to_i == b\nend\n\na, b = gets.split.map(&:to_i)\n\nret = 0\n(a + 1).upto((10 ** 5) + b) do |i|\n if lucky(i, b)\n ret = i\n break\n end\nend\n\nputs ret\n", "src_uid": "e5e4ea7a5bf785e059e10407b25d73fb"} {"source_code": "require 'set'\n\ndef readai\n\tgets.strip.split(/\\s+/).map! { |eac| eac.to_i }\nend\n\ndef readaf\n\tgets.strip.split(/\\s+/).map! { |eac| eac.to_f }\nend\n\ndef max a, b\n\tif a > b\n\t\ta\n\telse\n\t\tb\n\tend\nend\n\nn = readai\n\nstr = ((gets.strip.gsub /([\\(\\)])/, '#\\1#').gsub /_+/, '#_#').split '#'\n\ncnto, cnti, is_open = [0, 0, false]\n\n\nstr.each do |current|\n\tif current == '('\n\t\tis_open = true\n\telsif current == ')'\n\t\tis_open = false\n\telsif current != '_' and current != ''\n\t\tif is_open\n\t\t\tcnti += 1\n\t\telse\n\t\t\tcnto = max(cnto, current.length)\n\t\tend\n\tend\nend\n\nprint \"#{cnto} #{cnti}\"", "src_uid": "fc86df4931e787fa3a1a40e2aecf0b92"} {"source_code": "\ndef divisors(n)\n divisors1 = []\n divisors2 = []\n\n max = (n**(0.5)).floor\n (2..max).each do |d|\n if n % d < 1\n d2 = n/d\n divisors1 << d\n divisors2 << d2 if d2 > d\n end\n end\n\n [*divisors1, *divisors2.reverse]\nend\n\ndef solution\n gets\n s = gets.chomp.chars\n\n divs = divisors(s.size)\n\n divs.each do |d|\n a = s.shift d\n s = [*a.reverse, *s]\n end\n\n puts s.reverse.join\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", "src_uid": "1b0b2ee44c63cb0634cb63f2ad65cdd3"} {"source_code": "$n, q = gets.split.map(&:to_i)\na = q.times.map{gets.split}\n$h = Hash.new{Array.new()}\na.each{|x| $h[x[1]] += [x[0]]}\n \ndef magic(s)\n return 1 if s.size == $n\n array = $h[s[0]]\n return 0 if array.size.zero?\n b = array.map do |x|\n str = x + s[1..-1]\n magic(str)\n end\n b.inject(:+)\nend\n\np magic('a')\n", "src_uid": "c42abec29bfd17de3f43385fa6bea534"} {"source_code": "#!/usr/bin/ruby\nn,m=gets.split.map(&:to_i)\nr=0\nx=0\ngets.split.map(&:to_i).each{|e|\n\tif x 0\n w += i\n if i == d1\n w = [0, w - u1].max\n end\n if i == d2\n w = [0, w - u2].max\n end\n i -= 1\nend\nputs w", "src_uid": "084a12eb3a708b43b880734f3ee51374"} {"source_code": "a = STDIN.gets.split.map(&:to_i)\n\nputs [a[1]*a[2]/a[6], a[3]*a[4], a[5]/a[7]].min / a[0]\n", "src_uid": "67410b7d36b9d2e6a97ca5c7cff317c1"} {"source_code": "a=[\"Sheldon\", \"Leonard\", \"Penny\", \"Rajesh\", \"Howard\"]\nn=gets.chomp.to_i\nr = 1\nuntil r*5>n\n n -= r*5\n r *= 2\nend\nputs a[(n-1)/r]", "src_uid": "023b169765e81d896cdc1184e5a82b22"} {"source_code": "q,x,*y=[*$<].map{|i|i.scan(/./).permutation.map{|j|j.join.to_i}};p x.zip(*y).map{|l|l.max-l.min}.min\n", "src_uid": "08f85cd4ffbd135f0b630235209273a4"} {"source_code": "r1, r2 = gets.split.map(&:to_i)\nc1, c2 = gets.split.map(&:to_i)\nd1, d2 = gets.split.map(&:to_i)\n\n1.upto(9) do |a|\n b = r1 - a\n c = c1 - a\n d = d1 - a\n\n if [a,b,c,d].all?{|x|(1..9).include?(x)} && [a,b,c,d].uniq.size==4 && b+c == d2 && b+d == c2 && c+d == r2\n puts [a, b]*\" \"\n puts [c, d]*\" \"\n exit\n end\nend\nputs -1\n", "src_uid": "6821f502f5b6ec95c505e5dd8f3cd5d3"} {"source_code": "s = gets.chomp\nret = \"\"\nidx = 0\natend = false\nwhile idx < s.length\n\tif idx != 0 && idx != s.length-3 && s.slice(idx,3) == \"dot\"\n\t\tret += \".\"\n\t\tidx += 3\n\t\tnext\n\tend\n\tif atend == false && idx != 0 && idx != s.length-2 && s.slice(idx,2) == \"at\"\n\t\tret += \"@\"\n\t\tidx += 2\n\t\tatend = true\n\t\tnext\n\tend\n\tret += s[idx]\n\tidx += 1\nend\nputs ret\n", "src_uid": "a11c9679d8e2dca51be17d466202df6e"} {"source_code": "s=gets;a=%w(Danil Olya Slava Ann Nikita).select{|e|s.index e};puts a.size==1&&s.scan(a[0]).size==1?:YES: :NO", "src_uid": "db2dc7500ff4d84dcc1a37aebd2b3710"} {"source_code": "xs = STDIN.readline.split.map {|s| s.to_i }\nsum = xs.inject(:+)\nif sum != 0 and sum % xs.length == 0\n\tputs sum / xs.length\nelse\n\tputs -1\nend\n", "src_uid": "af1ec6a6fc1f2360506fc8a34e3dcd20"} {"source_code": "DBG = true\nn,l,r = gets.split.map{|z| z.to_i}\nt0 = Array.new(n)\nt1 = Array.new(n)\nt2 = Array.new(n)\n\nlm = l%3\nrm = r%3\nif lm == 0\n s0 = (r-l)/3 + 1\n s1 = (r-l)/3 + (rm!=0 ? 1 : 0)\n s2 = (r-l)/3 + (rm==2 ? 1 : 0)\nelsif lm == 1\n s0 = (r-l)/3 + (rm==0 ? 1 : 0)\n s1 = (r-l)/3 + 1\n s2 = (r-l)/3 + (rm!=1 ? 1 : 0)\nelse # if lm == 2\n s0 = (r-l)/3 + (rm!=2 ? 1 : 0)\n s1 = (r-l)/3 + (rm==1 ? 1 : 0)\n s2 = (r-l)/3 + 1\nend\n\n\nt0[0] = s0\nt1[0] = s1\nt2[0] = s2\nR = 1000000007\nfor i in 1...n\n t0[i] = (s0*t0[i-1] + s2*t1[i-1] + s1*t2[i-1]) % R\n t1[i] = (s1*t0[i-1] + s0*t1[i-1] + s2*t2[i-1]) % R\n t2[i] = (s2*t0[i-1] + s1*t1[i-1] + s0*t2[i-1]) % R\nend\nputs \"#{t0[n-1]}\"\n", "src_uid": "4c4852df62fccb0a19ad8bc41145de61"} {"source_code": "TEST_MODE = ARGV[0] == 't'\n\ndef evaluate(actual, expected); actual == expected ? \"OK\" : \"**NG**\"; end\ndef tests(); yield if TEST_MODE; end\ndef to_array(val); val.kind_of?(Array) ? val : [val]; end\ndef parse_int_array(str); str.split(\" \").collect{|s| s.to_i}; end\ndef p(*arg); puts \"DEBUG: \" + arg.to_s if TEST_MODE; end\n\ndef t(input, expected_output)\n input = to_array(input)\n expected_output = to_array(expected_output)\n output = []\n solve(input, output)\n puts \"#{evaluate(output, expected_output)} : input=#{input.to_s}, expected=#{expected_output.to_s}, actual=#{output.to_s}\"\nend\n\n# actual codes here\n\ndef diff(arr, l)\n (0..arr.size-2).collect do |i|\n arr[i+1] - arr[i]\n end + [l - arr[arr.size-1] + arr[0]]\nend\n\ndef eval(a, b)\n n = a.size()\n for delta in 0..n-1\n return true if (0..n-1).all? {|i|\n a[i] == b[(i+delta)%n]\n }\n end\n return false\nend\n\ndef solve(input, output)\n n, l = parse_int_array(input[0])\n a = diff(parse_int_array(input[1]), l)\n b = diff(parse_int_array(input[2]), l)\n p(a: a, b: b)\n output << (eval(a, b) ? \"YES\" : \"NO\")\nend\n\ntests do\n # test cases\n t([\"3 8\",\n\"2 4 6\",\n\"1 5 7\"], \"YES\")\n t([\"4 9\",\n\"2 3 5 8\",\n\"0 1 3 6\"], \"YES\")\n t([\"2 4\",\n\"1 3\",\n\"1 2\"], \"NO\")\nend\n\nputs solve(STDIN.read.split(\"\\n\"), []) unless TEST_MODE\n", "src_uid": "3d931684ca11fe6141c6461e85d91d63"} {"source_code": "#!/usr/bin/env ruby\nMOD = 1000000007\nm = gets.chomp\ncnt = Array.new(15, 0)\ndef cal(remain, lucky, amount, cnt)\n if remain == 0\n cnt[lucky] += amount\n return\n end\n cal(remain - 1, lucky, amount * 8, cnt)\n cal(remain - 1, lucky + 1, amount * 2, cnt)\nend\nt = 0\nfor i in 0...m.size\n for j in 0...m[i].to_i\n is_lucky = j == 4 || j == 7 ? 1 : 0\n cal(m.size - i - 1, t + is_lucky, 1, cnt)\n end\n t += 1 if m[i] == '4' || m[i] == '7'\nend\ncnt[t] += 1\ncnt[0] -= 1\ndef dfs(party_amount, lucky_amount, method_amount, cnt)\n return if lucky_amount > 9\n if party_amount == 6\n (lucky_amount + 1).upto(9) do |i|\n cnt[10] = (cnt[10] + method_amount * cnt[i]) % MOD\n end\n else\n for i in 0..9\n next unless cnt[i]\n cnt[i] -= 1\n dfs(party_amount + 1, lucky_amount + i, (method_amount * (cnt[i] + 1)) % MOD, cnt)\n cnt[i] += 1\n end\n end\nend\ndfs(0, 0, 1, cnt)\nputs cnt[10] % MOD", "src_uid": "656ed7b1b80de84d65a253e5d14d62a9"} {"source_code": "n = gets.strip.to_i\ncoins = gets.strip.split(\" \").map(&:to_i)\ncurrent_max_ones = 0\ni = 0 \ncurrent_flipped_ones = 0\nnumber_of_ones = coins.count(1)\ni0 = 0\nnumber_of_ones_before = 0\nnumber_of_ones_after = number_of_ones\nwhile i < n do\n if coins[i] == 0 then\n if current_flipped_ones == 0 then\n i0 = i\n number_of_ones_before = coins[0..i0].count(1)\n end\n current_flipped_ones += 1\n current_max_ones = current_max_ones >= number_of_ones_before + current_flipped_ones + number_of_ones_after ? \n current_max_ones : number_of_ones_before + current_flipped_ones + number_of_ones_after\n else\n if current_flipped_ones == 0 then\n number_of_ones_before += 1\n end\n number_of_ones_after -= 1\n current_max_ones = current_max_ones >= number_of_ones_before + current_flipped_ones + number_of_ones_after ? \n current_max_ones : number_of_ones_before + current_flipped_ones + number_of_ones_after\n if current_flipped_ones == i - i0 + 1 - current_flipped_ones then\n current_flipped_ones = 0\n end\n end\n i += 1\nend\nif coins.count(1) == coins.count then\n current_max_ones -= 1\nend\nputs current_max_ones", "src_uid": "9b543e07e805fe1dd8fa869d5d7c8b99"} {"source_code": "#!/usr/bin/ruby\n\nx, y, small_r, big_r = STDIN.readline.split.map {|s| s.to_i }\na, b = [x, y, big_r], [x, y, small_r]\nx, y, small_r, big_r = STDIN.readline.split.map {|s| s.to_i }\nc, d = [x, y, big_r], [x, y, small_r]\n\ndef intersects(a, b)\n\tx0, y0, r0 = a\n\tx1, y1, r1 = b\n\treturn false if includes(a, b) or includes(b, a)\n\tdd = (x1-x0)**2 + (y1-y0)**2\n\tdd < (r0 + r1)**2\nend\n\ndef includes(a, b)\n\tx0, y0, r0 = a\n\tx1, y1, r1 = b\n\treturn false if r1 >= r0\n\tdd = (x1-x0)**2 + (y1-y0)**2\n\tdd <= (r1 - r0)**2\nend\n\ncount = 0\n[ [a, c, d], [b, c, d], [c, a, b], [d, a, b] ].each do |x, a, b|\n\tnext if intersects(x, a) or intersects(x, b)\n\tnext if includes(a, x) and includes(x, b)\n\tif includes(a, x)\n\t\tnext if includes(x, b)\n\t\tnext if not includes(b, x)\n\tend\n\tcount += 1\nend\nputs count\n", "src_uid": "4c2865e4742a29460ca64860740b84f4"} {"source_code": "# cook your code here\n\nn,k = gets.chomp.split \n\nn = n.to_i \nk = k.to_i \n# ex = 1 \na = gets.chomp.split \n\nfor i in 0...n \n a[i] = a[i].to_i \nend \n\nputs a.count{ |x| x>=a[k-1] and x>0 } \n\n", "src_uid": "193ec1226ffe07522caf63e84a7d007f"} {"source_code": "a=gets.chomp.to_i\nb=gets.chomp\nif a==1\nputs \"YES\"\nputs \"#{b}\"\nelse\nbp=[]\ntemp=[b[0]]\n1.upto(b.length-1) do |i|\nif temp.count(b[i])==0\ntemp=temp+[b[i]]\nbp=bp+[i]\nend\nbreak if bp.length==a-1\nend\nif bp.length<(a-1)\nputs \"NO\"\nelse\nputs \"YES\"\nputs \"#{b[0..bp[0]-1]}\"\nif bp.length>1\n0.upto(a-3) do|i|\nputs \"#{b[bp[i]..bp[i+1]-1]}\"\nend\nend\nputs \"#{b[bp[a-2]..(b.length-1)]}\"\nend\nend", "src_uid": "c1b071f09ef375f19031ce99d10e90ab"} {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nsum = a.inject(:+)\nif a[0]*2 > sum\n puts 1,1\nelse\n ans = [1]\n s = a[0]\n (1...n).each do |i|\n if a[i]*2 <= a[0]\n ans << i+1\n s += a[i]\n end\n end\n if s*2 > sum\n puts ans.size,ans.join(\" \")\n else\n puts 0\n end\nend", "src_uid": "0a71fdaaf08c18396324ad762b7379d7"} {"source_code": "#!/usr/bin/ruby\n# coding: utf-8\nrequire 'rational'\n\na, x, y = $stdin.gets.split(/\\s+/).map(&:to_i)\nh = a.to_r / 2\n\nif y % a == 0\n puts -1\nelsif y < a\n if -h < x and x < h\n puts 1\n else\n puts -1\n end\nelse\n n = 2\n y1 = 2*a\n loop do\n if y < y1\n if -h < x and x < h\n puts n\n else\n puts -1\n end\n break\n end\n y1 += a\n if y < y1\n if -a < x and x < 0\n puts n+1\n elsif 0 < x and x < a\n puts n+2\n else\n puts -1\n end\n break\n end\n y1 += a\n n += 3\n end\nend\n", "src_uid": "cf48ff6ba3e77ba5d4afccb8f775fb02"} {"source_code": "$boyhs={0=>0,1=>0,2=>0}\nj=0;\nfor i in 3..100\n\tif i%2!=0\n\t\tj+=1\n\tend\n\t$boyhs[i]=j\nend\ndef main()\n\tgf=gets.chomp.split(\" \")\n\tgf=gf.map{|i| i.to_i}\n\tgl=gf[0]\n\tgr=gf[1]\n\tbf=gets.chomp.split(\" \")\n\tbf=bf.map{|i| i.to_i}\n\tbl=bf[0]\n\tbr=bf[1]\n\tif checkcomfort(gl,br) || checkcomfort(gr,bl)\n\t\tputs \"YES\"\n\telse\n\t\tputs \"NO\"\n\tend\nend\ndef checkcomfort(g,b)\n\tif b>=g-1 && g>=$boyhs[b]\n\t\treturn true;\n\tend\n\treturn false;\nend\t\nmain()", "src_uid": "36b7478e162be6e985613b2dad0974dd"} {"source_code": "a, b = gets.chomp.split.map(&:to_i)\ni =0\nwhile(true) do\n a = a*3\n b = b*2\n i = i+1\n if(a>b) then\n break\n end\nend\nprint(i,\"\\n\")", "src_uid": "a1583b07a9d093e887f73cc5c29e444a"} {"source_code": "s = gets.strip.split\na = s[0].split(//)\nk = s[1].to_i\naa = []\nwhile k > 0 && a.size > 0\n\tm = k < a.size ? a[0..k].max : a[0..a.size-1].max\n\tmp = a.index(m)\n\tk -= mp if mp != 0\n\taa << a[mp]\n\ta.delete_at(mp)\nend\naa << a\nputs aa.join", "src_uid": "e56f6c343167745821f0b18dcf0d0cde"} {"source_code": "princess_speed = gets.to_f\ndragon_speed = gets.to_f\ndelay_time = gets.to_f\ntresuary_time = gets.to_f\ndistance = gets.to_f\n\nnumber_of_bijous = 0\n\ninitial_princess_travelled_distance = princess_speed * delay_time\nprincess_travelled_distance = initial_princess_travelled_distance\ndragon_travelled_distance = 0\n\nif princess_speed >= dragon_speed\n puts 0\n exit\nelse\n first_time_dragon_catch_princess = initial_princess_travelled_distance / (dragon_speed - princess_speed)\n\n dragon_travelled_distance = first_time_dragon_catch_princess * dragon_speed\n princess_travelled_distance = dragon_travelled_distance\n\n while princess_travelled_distance < distance\n number_of_bijous += 1\n extra_distance = (2 * dragon_travelled_distance / dragon_speed + tresuary_time) * princess_speed\n time_to_catch = extra_distance / (dragon_speed - princess_speed)\n princess_travelled_distance += extra_distance + time_to_catch * princess_speed\n dragon_travelled_distance = princess_travelled_distance\n end\n\n puts number_of_bijous\n exit\nend", "src_uid": "c9c03666278acec35f0e273691fe0fff"} {"source_code": "n, x, y = gets.chomp.split(\" \").map{|e| e.to_f}\n\na = (n * (y / 100.0)).ceil\n\nans = (a - x).to_i\nif ans < 0\n puts 0\nelse\n puts ans\nend", "src_uid": "7038d7b31e1900588da8b61b325e4299"} {"source_code": "def read_next_line\n gets.split.map { |x| x.to_i }\nend\n\nn = gets.to_i\nc = read_next_line\nx, y = read_next_line\ns1 = 0\ns2 = c.inject(:+)\nfor i in 0...n\n if s1 >= x && s1 <= y && s2 >= x && s2 <= y\n puts i + 1\n exit\n elsif s1 >= y\n break\n end\n s1 += c[i]\n s2 -= c[i]\nend\nputs 0", "src_uid": "e595a1d0c0e4bbcc99454d3148b4557b"} {"source_code": "r=gets.split.map(&:to_i)\nputs (r[-2]..r[-1]).map{|v| (v%r[0,4].min==v)?1:0}.count(1)", "src_uid": "63b9dc70e6ad83d89a487ffebe007b0a"} {"source_code": "\nr,h=gets.split.map(&:to_f)\nd=(h/r+0.5).to_i\np ((h/r+1-d)*1.154701).to_i+d*2\n", "src_uid": "ae883bf16842c181ea4bd123dee12ef9"} {"source_code": "puts gets.gsub(/-?./){47-($&+?/)[1].ord}", "src_uid": "46b5a1cd1bd2985f2752662b7dbb1869"} {"source_code": "cw_pos = %w{v < ^ >}\nccw_pos = %w{v > ^ <}\nstart, fin = gets.strip.split\nstart_pos_cw = cw_pos.index start\nstart_pos_ccw = ccw_pos.index start\nn = gets.strip.to_i\nn %= 4\ncw = cw_pos[start_pos_cw + (n - 4)] == fin\nccw = ccw_pos[start_pos_ccw + (n - 4)] == fin\nif cw && !ccw\n puts \"cw\"\nelsif ccw && !cw\n puts \"ccw\"\nelse\n puts \"undefined\"\nend\n", "src_uid": "fb99ef80fd21f98674fe85d80a2e5298"} {"source_code": "include Math\nrequire \"prime\"\nrequire \"bigdecimal\"\nrequire \"bigdecimal/math\"\nrequire \"matrix\"\nrequire \"pp\"\nrequire \"benchmark\"\n\nInfinity = 1/0.0\nclass Matrix;def inspect;empty? ? \"Matrix.empty(#{row_size}, #{column_size})\":\"Matrix[\\n#{@rows.map(&:inspect).join(\"\\n\")}\\n]\";end;end\ndef pbin(obj);case obj;when Integer;puts obj.to_s(2);end;end\nclass String;def to_a;split(\"\");end;end\nclass String;def to_ia;split.map(&:to_i);end;end\ndef getia;gets.to_ia;end\ndef geti;gets.to_i;end\nclass Object;def dcopy;Marshal.load(Marshal.dump(self));end;end\n\ndef chk(x,y,h,b)\n yy=y.to_a\n xx=x.to_a\n xx.each{|c|b-=1 if yy.include?(c)}\n b+=h\n xx.zip(yy){|s,t|h-=1 if s==t}\n return true if h.zero? && b.zero?\n return false\nend\n\nn=geti\na=[]\nn.times{\n i=gets.split\n i[1]=i[1].to_i\n i[2]=i[2].to_i\n a<0 && t==1 && @r1[i] == '0' && @r1[i-1]=='0' && @r2[i-1]=='0'\n ans = [ans, solve(i-1, 0, 0)+1].max\n end\n if i>0 && b==1 && @r2[i] == '0' && @r1[i-1]=='0' && @r2[i-1]=='0'\n ans = [ans, solve(i-1, 0, 0)+1].max\n end\n if i>0 && t==1 && b==1 && @r1[i] == '0' && @r2[i]=='0'\n ans = [ans, solve(i-1, 0, 1)+1].max if @r1[i-1] == '0'\n ans = [ans, solve(i-1, 1, 0)+1].max if @r2[i-1] == '0'\n end\n @cache[get_key(i,t,b)] = ans\n end\n @cache[get_key(i,t,b)]\nend\n\nputs solve(n, 1, 1)\n", "src_uid": "e6b3e787919e96fc893a034eae233fc6"} {"source_code": "n, m, x = gets.split.map(&:to_i)\nx-=1\nputs \"#{(x/2)/m + 1} #{(x/2)%m+1} #{(x%2==0)?'L':'R'}\"", "src_uid": "d6929926b44c2d5b1a8e6b7f965ca1bb"} {"source_code": "n = gets.chomp.to_i\nd = gets.chomp.split.map(&:to_i)\nans1 = d.sort[d.size-1]\nb = d.select{|x| ans1 % x == 0}.uniq!\nb.each{|y| d.delete_at(d.index(y))}\nans2 = d.sort[d.size-1]\nputs \"#{ans1} #{ans2}\"", "src_uid": "868407df0a93085057d06367aecaf9be"} {"source_code": "arr = readline.split(' ').collect(&:to_i)\nn = arr[0]\narr = arr[1..-1]\na = [arr[0] + arr[1], arr[0] + arr[2], arr[1] + arr[3], arr[2] + arr[3]]\nd = a.max - a.min\nc = [0, n - d].max\nputs c * n\n", "src_uid": "b732869015baf3dee5094c51a309e32c"} {"source_code": "def dot(x0, y0, x1, y1, x2, y2)\n\t(x1 - x0) * (x2 - x0) + (y1 - y0) * (y2 - y0)\nend\n\ndef right(x0, y0, x1, y1, x2, y2)\n\t[x0, y0] != [x1, y1] and [x0, y0] != [x2, y2] and [x1, y1] != [x2, y2] and\n\t\tdot(x0, y0, x1, y1, x2, y2) == 0 ||\n\t\tdot(x1, y1, x0, y0, x2, y2) == 0 ||\n\t\tdot(x2, y2, x0, y0, x1, y1) == 0\nend\n\ndef gao(a)\n\treturn \"RIGHT\" if right(*a)\n\ta.each_index do |i|\n\t\ta[i] += 1\n\t\treturn \"ALMOST\" if right(*a)\n\t\ta[i] -= 2\n\t\treturn \"ALMOST\" if right(*a)\n\t\ta[i] += 1\n\tend\n\t\"NEITHER\"\nend\n\nputs gao gets.split.map &:to_i\n", "src_uid": "8324fa542297c21bda1a4aed0bd45a2d"} {"source_code": "arr = gets.split.map &:to_i\n$n, x0, y0, dx, dy, t = arr\n\ndef mod(a)\n (a - 1) % $n + 1\nend\n\ndx, dy = mod(dx), mod(dy)\n\ndef zmul(a, b)\n ans = 0\n 6.times do |i|\n ans += mod(a[i] * b[i])\n ans -= $n if ans > $n\n end\n ans\nend\n\nclass Matrix\n def initialize(n)\n @mat = Array.new(n) do |i|\n Array.new(n) { |j| i == j ? 1 : 0 }\n end\n end\n\n def [](index)\n @mat[index]\n end\n\n def []=(index, val)\n @mat[index] = val\n end\n\n def mul(rhs)\n ans = Matrix.new(6)\n 6.times do |i|\n 6.times do |j|\n ans[i][j] = 0\n 6.times do |k|\n ans[i][j] += mod(@mat[i][k] * rhs[k][j])\n ans[i][j] -= $n if ans[i][j] > $n\n end\n end\n end\n ans\n end\n\n def pow(e)\n ans = Matrix.new(6)\n tmp = Matrix.new(6)\n 6.times { |i| tmp[i] = Array.new(6) { |j| @mat[i][j] } }\n while e > 0\n ans = ans.mul(tmp) if (e & 1) == 1\n tmp = tmp.mul(tmp) if (e >>= 1) > 0\n end\n ans\n end\nend\n\n\nmat = Matrix.new(6)\nmat[0] = [2, 1, 1, 0, 1, 0]\nmat[1] = [1, 2, 0, 1, 1, 0]\nmat[2] = [1, 1, 1, 0, 1, 0]\nmat[3] = [1, 1, 0, 1, 1, 0]\nmat[4] = [0, 0, 0, 0, 1, 1]\nmat[5] = [0, 0, 0, 0, 0, 1]\n\nmat = mat.pow(t)\n\narr.shift\narr[-1] = 0\narr << 1\nputs \"#{zmul(mat[0], arr)} #{zmul(mat[1], arr)}\"\n", "src_uid": "ee9fa8be2ae05a4e831a4f608c0cc785"} {"source_code": "k,r = [],0\ndef rec(kk, l, s)\n kk<0)\n rec kk, l+1, s*10+4 if (l<10)\n rec kk, l+1, s*10+7 if (l<10)\nend\nrec(k, 0,0)\nk.sort!\na,b = gets.split.collect{|x| x.to_i }\n0.upto(k.length) do |i|\n if a<=b && a<=k[i]\n n=[b,k[i]].min-a+1\n r+= n*k[i]\n a=k[i]+1\n end\nend\nputs r", "src_uid": "8a45fe8956d3ac9d501f4a13b55638dd"} {"source_code": "\nn = gets.to_i\n\nnumber = gets\n\n#4 => 3,2,2\n#6 => 3,5\n#8 => 7,2,2,2\n#9 => 7,3,3,2\nsh = { '4' => [3,2,2],\n '6' => [5,3],\n '8' => [7,2,2,2],\n '9' => [7,3,3,2]\n }\nres = []\nnumber.each_char do |ch|\n if (sh[ch].nil?)\n res << ch.to_i\n else\n res << (sh[ch])\n end\nend\nres = res.flatten.sort.reverse.reject { |s| s < 2 }.join('') \nputs res.to_s\n", "src_uid": "60dbfc7a65702ae8bd4a587db1e06398"} {"source_code": "n, k, t = gets.split.map(&:to_i)\n\nif t <= k\n puts t\nelsif t < n\n puts k\nelse\n puts k - (t-n)\nend\n", "src_uid": "7e614526109a2052bfe7934381e7f6c2"} {"source_code": "#!/usr/bin/env ruby\n\ndef cb(n, m)\n return 0 if n < m || m == 0\n ((n-m+1)..n).inject(&:*) / (1..m).inject(&:*)\nend\n\nn, m, t = gets.split.map(&:to_i)\n\nans = 0\n(4..n).each do |i|\n j = t - i\n break if j == 0\n next if j > m\n ans += cb(n,i)*cb(m,j)\nend\np ans\n", "src_uid": "489e69c7a2fba5fac34e89d7388ed4b8"} {"source_code": "n = gets.to_i\nx = Regexp.new gets.chomp\nputs [ \"vaporeon\", \"jolteon\", \"flareon\", \"espeon\", \"umbreon\", \"leafeon\", \"glaceon\", \"sylveon\" ].find { |i|\n i.size == n && i =~ x\n}", "src_uid": "ec3d15ff198d1e4ab9fd04dd3b12e6c0"} {"source_code": "#!/usr/bin/ruby\n\nstr = gets.chomp\n\nmax_size = 0\n1.upto(str.size) {|len|\n 0.upto(str.size - len - 1) {|first|\n (first + 1).upto(str.size - len) {|second|\n# p \"#{str[first, len]} #{str[second, len]}\"\n max_size = len if str[first, len] == str[second, len]\n }\n }\n}\n\nputs max_size\n\n \n", "src_uid": "13b5cf94f2fabd053375a5ccf3fd44c7"} {"source_code": "i=0\na=[]\ngets.split.each do |s|\n if a.include?(s)\n i += 1\n else\n a << s\n end\nend \nputs i\n", "src_uid": "38c4864937e57b35d3cce272f655e20f"} {"source_code": "n = gets.to_i\nstart = [0, n - 100].max\nres = (start..n).to_a.map do |x|\n x + (x.to_s.split('').map(&:to_i).inject(:+)) == n ? x : nil\nend.reject(&:nil?)\nputs res.size\nres.each { |x| puts x }\n", "src_uid": "ae20ae2a16273a0d379932d6e973f878"} {"source_code": "def IsVowel(c)\n \"aeiouy\".include?(c)\nend\n\ndef HasConsVowels(s)\n s.each_cons(2).to_a.map{|a, b| IsVowel(a)&&IsVowel(b)}.include?(true)\nend\ngets\ns = gets.chomp.chars\nuntil !HasConsVowels(s) do\ns.each_index do |i|\n next if i == 0\n s.delete_at(i) if IsVowel(s[i]) && IsVowel(s[i-1])\nend\nend\nputs s.join", "src_uid": "63a4a5795d94f698b0912bb8d4cdf690"} {"source_code": "n,pos,l,r = gets.split.map(&:to_i)\nif r <= pos\n a = l==1 ? -r : -l+1\n b = r==n ? 0 : 1\n ans = pos + a + b\nelsif l >= pos\n a = r==n ? l : r+1\n b = l==1 ? 0 : 1\n ans = -pos + a + b\nelse\n a = l==1 ? 0 : pos-l+1\n b = r==n ? 0 : r-pos+1\n c = (a==0 || b==0) ? 0 : [pos-l,r-pos].min\n ans = a + b + c\nend\nputs ans\n", "src_uid": "5deaac7bd3afedee9b10e61997940f78"} {"source_code": "puts (x=gets.chomp)>?1 ? x+' '+x : -1", "src_uid": "883f67177474d23d7a320d9dbfa70dd3"} {"source_code": "tmp = $stdin.gets.chomp.split(' ')\nn = tmp[0].to_i\nm = tmp[1].to_i\n\nnn=[]\nmm=[]\nnc=0\nmc=0\n\nwhile n%2==0\n nc+=1\n n/=2\nend\n\nnn.push(nc)\nnc=0\nwhile n%3==0\n nc+=1\n n/=3\nend\nnn.push(nc)\n\n#puts \"-- #{n} \"\n\nwhile m%2==0\n mc+=1\n m/=2\nend\n\nmm.push(mc)\nmc=0\nwhile m%3==0\n mc+=1\n m/=3\nend\n#puts \"-- #{m} \"\nmm.push(mc)\n\n#puts nn,mm\n\na1 = (mm[0]-nn[0])\na2 = (mm[1]-nn[1])\nif a1<0 || a2<0 || n!=m\n puts \"-1\"\nelse\n puts a1+a2\nend\n", "src_uid": "3f9980ad292185f63a80bce10705e806"} {"source_code": "n = gets.split(\" \").map(&:to_i)\nsum = 0\nn.each { |a| sum+=a }\ntag = false\nfor i in 0..3\n\tfor j in (i+1)..4\n\t\tfor k in (j+1)..5\n\t\t\tif 2*(n[j] + n[i] +n[k]) == sum\n\t\t\t\ttag = true\n\t\t\t\tbreak\n\t\t\tend\n\t\tend\n\tend\nend\n\nif tag\n\tprint('YES')\nelse\n\tprint('NO')\nend", "src_uid": "2acf686862a34c337d1d2cbc0ac3fd11"} {"source_code": "def scan; gets.split.map(&:to_i); end\n\nl,r = scan\n\nputs l != r ? 2 : l", "src_uid": "a8d992ab26a528f0be327c93fb499c15"} {"source_code": "def count0(x)\n\tans, mul = 0, 5\n\tans, mul = ans + x / mul, mul * 5 while mul <= x\n\tans\nend\n\nn = gets.strip.to_i\nbeg = 0\nbeg += 1 while count0(beg) < n\nans = []\nwhile count0(beg) == n\n\tans.push(beg)\n\tbeg += 1\nend\nputs ans.length\nputs ans.map(&:to_s).join(' ')\n", "src_uid": "c27ecc6e4755b21f95a6b1b657ef0744"} {"source_code": "puts Math.log2(gets.to_i+1).ceil", "src_uid": "95cb79597443461085e62d974d67a9a0"} {"source_code": "def calc(digits, base)\n digits.reverse.map.with_index do |d, idx|\n d * (base**idx)\n end.inject(0, :+)\nend\n\n_, base = gets.chomp.split.map(&:to_i)\na = calc(gets.chomp.split.map(&:to_i), base)\n\n_, base = gets.chomp.split.map(&:to_i)\nb = calc(gets.chomp.split.map(&:to_i), base)\n\nans = \"\".tap do |out|\n case\n when a == b\n out << \"=\"\n when a > b\n out << \">\"\n else\n out << \"<\"\n end\nend\nputs ans\n", "src_uid": "d6ab5f75a7bee28f0af2bf168a0b2e67"} {"source_code": "hash = {\n 0 => \"zero\",\n 1 => \"one\",\n 2 => \"two\",\n 3 => \"three\",\n 4 => \"four\",\n 5 => \"five\",\n 6 => \"six\",\n 7 => \"seven\",\n 8 => \"eight\",\n 9 => \"nine\",\n 10 => \"ten\",\n 11 => \"eleven\",\n 12 => \"twelve\",\n 13 => \"thirteen\",\n 14 => \"fourteen\",\n 15 => \"fifteen\",\n 16 => \"sixteen\",\n 17 => \"seventeen\",\n 18 => \"eighteen\",\n 19 => \"nineteen\",\n 20 => \"twenty\",\n 30 => \"thirty\",\n 40 => \"forty\",\n 50 => \"fifty\",\n 60 => \"sixty\",\n 70 => \"seventy\",\n 80 => \"eighty\",\n 90 => \"ninety\",\n}\nn = gets.to_i\nif n <= 20 || n % 10 == 0\n puts hash[n]\nelse\n puts \"#{hash[n/10 * 10]}-#{hash[n % 10]}\"\nend\n", "src_uid": "a49ca177b2f1f9d5341462a38a25d8b7"} {"source_code": "n=gets.to_i\nx=gets.chomp.split.map(&:to_i)\na,b=0,0\nfor i in 0..n-1\n\ta,b=0,0\n\tfor j in i+2..n-1\n\t\tif x[j]>x[i] && x[j]>x[i+1] || x[j]n{(2..10).all?{|e|n%e!=0}}\ng=->n{(1..n).count{|e|f[e]}}\nd,r=gets.to_i.divmod(2520)\np g[2520]*d+g[r]", "src_uid": "e392be5411ffccc1df50e65ec1f5c589"} {"source_code": "#!ruby -parprime\np=Prime\neval'$_=p.each(%d).reject{|i|!p.each(i).each_cons(2).any?{|q,r|i==q+r+1}}.size>=%d?\"YES\": :NO'%$F", "src_uid": "afd2b818ed3e2a931da9d682f6ad660d"} {"source_code": "n, c = gets.split(\" \").map(&:to_i)\np = gets.split(\" \").map(&:to_i)\nt = gets.split(\" \").map(&:to_i)\n\np1 = 0\nt1 = 0\nn.times do |i|\n t1 += t[i]\n p1 += [p[i] - c*t1, 0].max\nend\n\np2 = 0\nt2 = 0\nn.times do |i|\n t2 += t[n-i-1]\n p2 += [p[n-i-1] - c*t2,0].max\nend\n\nif p1 > p2\n puts \"Limak\"\nelsif p2 > p1\n puts \"Radewoosh\"\nelse\n puts \"Tie\"\nend\n", "src_uid": "8c704de75ab85f9e2c04a926143c8b4a"} {"source_code": "a,b,c = gets.split.map(&:to_i)\nif (a-b+c)*(a-b-c) <= 0 && c != 0\n puts \"?\"\nelsif a-b > 0\n puts \"+\"\nelsif a-b < 0\n puts \"-\"\nelse\n puts \"0\"\nend", "src_uid": "66398694a4a142b4a4e709d059aca0fa"} {"source_code": "n,*a=gets.split.map &:to_i\nn%=4\nif n==0\n p 0\nelsif n==1\n p [a[0]*3, a[2], a[0]+a[1]].min\nelsif n==2\n p [a[0]*2, a[1], a[2]*2].min\nelse\n p [a[0], a[2]*3, a[1]+a[2]].min\nend\n", "src_uid": "c74537b7e2032c1d928717dfe15ccfb8"} {"source_code": "a, b = STDIN.readline.split.collect {|s| s.to_i }\nif b > a\n puts 0\nelsif b == a\n puts 'infinity'\nelse\n c = a-b\n count = 0\n x = 1\n while x*x <= c\n if c%x == 0\n y = c/x\n if y > b\n count += 1\n end\n if x != y and x > b\n count += 1\n end\n end\n x += 1\n end\n puts count\nend\n", "src_uid": "6e0715f9239787e085b294139abb2475"} {"source_code": "s = gets.chomp.split.sort\nans = 2\nif s[0] == s[1]\n if s[1] == s[2]\n ans = 0\n else\n ans = 1\n end\nelsif s[1] == s[2]\n ans = 1\nelse\n a = Hash.new\n a[\"s\"] = 0\n a[\"p\"] = 1\n a[\"m\"] = 2\n b = Array.new(3).map{Array.new(10,0)}\n 3.times do |i|\n b[a[s[i][1]]][s[i][0].to_i] += 1\n end\n 3.times do |i|\n c = 1\n (2..9).each do |j|\n if b[i][j] == 1 && b[i][j-1] == 1\n c += 1\n ans = [ans,3-c].min\n else\n c = 1\n end\n end\n (2..8).each do |j|\n if b[i][j-1] == 1 && b[i][j+1] == 1\n ans = [ans,1].min\n end\n end\n end\nend\nputs ans", "src_uid": "7e42cebc670e76ace967e01021f752d3"} {"source_code": "x, s = gets.split.map &:to_i\n\nif x > s || x[0] != s[0]\n\tputs -1\n\texit\nend\n\nBIT = 64\nans = Array.new(BIT, 0)\n(0...BIT).select{|i| x[i] == 1}.each{|i| ans[i] += 1}\n(0...BIT).select{|i| (s - x)[i] == 1}.each{|i| ans[i-1] += 2}\n\na = Array.new(ans.max, 0)\na.each_index do |i|\n\t(0...BIT).select{|j| ans[j] > i}.each{|j| a[i] += 1 << j}\nend\nputs a.size, a.sort.join(' ')", "src_uid": "490f23ced6c43f9e12f1bcbecbb14904"} {"source_code": "n,a,x,b,y = gets.split.map(&:to_i)\nf = false\nwhile a != x && b != y\n a += 1\n a = 1 if a > n\n b -= 1\n b = n if b <= 0\n if a == b\n f = true\n break\n end\nend\nputs (f ? \"YES\" : \"NO\")", "src_uid": "5b889751f82c9f32f223cdee0c0095e4"} {"source_code": "print (gets.to_i + 1) / 2", "src_uid": "30e95770f12c631ce498a2b20c2931c7"} {"source_code": "n = gets.chomp.to_i\ncontainer = gets.chomp.split().map { |x| x.to_i }\n\nif container.count(0) == n\n puts \"NO\"\nelse\n numDifZero = [0]\n for i in 0 ... n\n if container[i] != 0\n numDifZero.push(i+1)\n end\n end\n if numDifZero[-1] != n\n numDifZero[-1] = n\n end\n puts \"YES\"\n puts (numDifZero.length-1)\n for i in 1 ... numDifZero.length\n print (numDifZero[i-1]+1),\" \",numDifZero[i],\"\\n\"\n end\n\nend", "src_uid": "3a9258070ff179daf33a4515def9897a"} {"source_code": "n = gets.to_i\na = n.times.map{gets.split.map(&:to_i)}\nc = [[0, 0], [0, 0]]\na.each do |x, y|\n c[x % 2][y % 2] += 1\nend\nif (c[1][0] + c[1][1]).even? && (c[0][1] + c[1][1]).even?\n puts 0\nelsif (c[1][0] + c[0][1]).even? && c[1][0] + c[0][1] != 0\n puts 1\nelse\n puts -1\nend\n", "src_uid": "f9bc04aed2b84c7dd288749ac264bb43"} {"source_code": "n = gets.to_i * 2\narr = Array.new(10){0}\n4.times do\n str = gets\n str.size.times do |i|\n arr[str[i].to_i] += 1 if str[i] != '.'\n end\nend\nisYes = true\n1.upto(arr.size) do |i|\n if arr[i].to_i > n\n isYes = false\n break\n end\nend\n(isYes == true) ? printf('YES') : printf('NO')", "src_uid": "5fdaf8ee7763cb5815f49c0c38398f16"} {"source_code": "a,b,c=gets.split.map &:to_i\ns=[(a+b)*2,a+b+c,(a+c)*2,(b+c)*2]\np s.min", "src_uid": "26cd7954a21866dbb2824d725473673e"} {"source_code": "l = [gets.to_i, gets.to_i, gets.to_i, gets.to_i]\nputs (1..gets.to_i).to_a.select{ |x| l.any?{ |y| x >= y and x % y == 0 } }.size", "src_uid": "46bfdec9bfc1e91bd2f5022f3d3c8ce7"} {"source_code": "BEGIN{\n\tdef get_line_int()\n\t\treturn gets.split.map(&:to_i)\n\tend\n\tdef getA(n, m)\n\t\tcc = 0\n\t\tn -= 1\n\t\tif n % 2 == 0 then\n\t\t\tcc += n\n\t\telse\n\t\t\tcc += n - 1\n\t\tend\n\t\tcc += m - n - 1\n\tend\n\tdef getB(n, m)\n\t\tcc = 0\n\t\tm -= 1\n\t\tif n % 2 == 0 then\n\t\t\tcc += n\n\t\telse\n\t\t\tcc += n - 1\n\t\tend\n\t\tcc += m - n - 1\n\t\tcc += 1\n\tend\n\tdef main()\n\t\tn, m = get_line_int\n\t\tn, m = m, n if n > m\n\t\tans1 = getA(n, m)\n\t\tans2 = getB(n, m)\n\t\tans = ans1 > ans2 ? ans1 : ans2\n\t\tprint ans, \" \", n + m - 1 - ans\n\t\tputs\n\tend\n\tTest_case = 1\n\tTest_case.times do\n\t\tmain()\n\tend\n}\n", "src_uid": "c8378e6fcaab30d15469a55419f38b39"} {"source_code": "n, cnt = gets.to_i, Hash.new(0)\nn.times {cnt[gets.chomp] += 1}\nif cnt.each_value.inject(true) {|r, v| r &&= v * 2 == n}\n puts :YES\n cnt.each_key {|k| print k, ' '}\nelse\n puts :NO\nend\n", "src_uid": "2860b4fb22402ea9574c2f9e403d63d8"} {"source_code": "n = gets.chomp.to_i\ns = gets.chomp\nans = s.chars.chunk { |chr| chr == 'B' }.select(&:first).map { |chunk| chunk.last.length }\nputs ans.length\nputs ans.join(\" \")\n", "src_uid": "e4b3a2707ba080b93a152f4e6e983973"} {"source_code": "gets\ns,ans=[],0\ngets.split.map(&:to_i).each do |i|\n while s[-2]&&(k=[s[-2],i].min)>=s[-1]\n ans+=k\n s.pop\n end\n s.push i\nend\ns.sort!\n(0..s.size-3).each{|i| ans+=s[i]}\np ans", "src_uid": "e7e0f9069166fe992abe6f0e19caa6a1"} {"source_code": "board = Hash.new\nres = 0\nfor i in 0...8\n\tboard[i] = gets.split(//)\n\tunless board[i].include?(\"W\")\n\t\tres += 1\n\tend\nend\nif res == 8\n\tputs \"8\"\nelse\n\tfor i in 0...8\n\t\tincrease = true\n\t\tfor j in 0...8\n\t\t\tif board[j][i] == \"W\"\n\t\t\t\tincrease = false\n\t\t\tend\n\t\tend\n\t\tif increase\n\t\t\tres += 1\n\t\tend\n\tend\n\tputs res.to_s\nend\n", "src_uid": "8b6ae2190413b23f47e2958a7d4e7bc0"} {"source_code": "k = readline.chomp.to_i\nn = 34\n\nseats = [\n (k > 0 ? 1 : 0) + ((k > 4 ? k - 4 : 0) / 3.0).ceil,\n (k > 1 ? 1 : 0) + ((k > 5 ? k - 5 : 0) / 3.0).ceil,\n (k > 2 ? 1 : 0),\n (k > 3 ? 1 : 0) + ((k > 6 ? k - 6 : 0) / 3.0).ceil\n].map {|i| i >= 0 ? i : 0}\n\ndef pr(n, a)\n ('O' * a + '#' * (n - a)).split('').join('.')\nend\n\nputs '+------------------------+'\nputs \"|#{pr(11, seats[0])}.|D|)\"\nputs \"|#{pr(11, seats[1])}.|.|\"\nputs \"|#{pr(1, seats[2])}#{'.' * 23}|\"\nputs \"|#{pr(11, seats[3])}.|.|)\"\nputs '+------------------------+'\n", "src_uid": "075f83248f6d4d012e0ca1547fc67993"} {"source_code": "puts gets.size*25+1", "src_uid": "556684d96d78264ad07c0cdd3b784bc9"} {"source_code": "#!/usr/bin/env ruby\n\ns, t, p = gets.strip, gets.strip, 0\nt.each_char { |i| p = p + 1 if s[p] == i }\nputs p + 1\n", "src_uid": "f5a907d6d35390b1fb11c8ce247d0252"} {"source_code": "n, k = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\nv = []\n(0...(2E5+11).to_i).each do |i|\n v << []\nend\n(0...n).each do |i|\n cur = a[i]\n res = 0\n while cur > 0\n v[cur] << res\n res += 1\n cur /= 2\n end\nend\nres = 1E9.to_i\n(0..2E5.to_i).each do |i|\n v[i].sort!\n next if v[i].length < k\n sum = 0\n (0...k).each do |j|\n sum += v[i][j]\n end\n res = [res, sum].min\nend\nputs res", "src_uid": "ed1a2ae733121af6486568e528fe2d84"} {"source_code": "gets\nputs gets[/^1*0?/].length\n", "src_uid": "54cb2e987f2cc06c02c7638ea879a1ab"} {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i).map{|x|x % 2}\nif a[0] == 0 || a[-1] == 0\n puts \"No\"\nelse\n b = []\n tmp = []\n n.times do |i|\n tmp.push(a[i])\n if i < n - 1 && a[i] == 1 && a[i + 1] == 1 && tmp.size % 2 == 1\n b.push(tmp)\n tmp = []\n end\n end\n cnt = b.size\n if tmp.size % 2 == 0\n if cnt == 0\n puts \"No\"\n exit\n end\n else\n cnt += 1\n end\n puts cnt % 2 == 1 ? \"Yes\" : \"No\"\nend", "src_uid": "2b8c2deb5d7e49e8e3ededabfd4427db"} {"source_code": "ax,ay,bx,by,cx,cy=gets.split.map(&:to_i)\nans = true\nif ax == bx\n if ax == cx\n ans = false\n end\nelse\n if (cy - ay) * (ax - bx) == (ay - by) * (cx - ax)\n ans = false\n end\nend\n\nif ans\n puts (ax - bx) ** 2 + (ay - by) ** 2 == (bx - cx) ** 2 + (by - cy) ** 2 ? \"Yes\" : \"No\"\nelse\n puts \"No\"\nend", "src_uid": "05ec6ec3e9ffcc0e856dc0d461e6eeab"} {"source_code": "n, v = gets.strip.split(' ').map(&:to_i)\nc = (1..n).to_a\ntank = 0\ncost = 0\n\nc.each_with_index do |_, idx|\n tank -= 1 unless idx.zero?\n togo = n - idx - 1\n if togo > tank\n leftintank = v - tank\n tofill = [leftintank, togo].min\n cost += (1 + idx) * tofill\n tank += tofill\n end\nend\nputs cost", "src_uid": "f8eb96deeb82d9f011f13d7dac1e1ab7"} {"source_code": "#!/usr/bin/ruby\nh=Hash.new(0)\ngets.chomp.chars{|c|h[c]+=1}\np [[(h['n']-1)/2,0].max,h['i'],h['e']/3,h['t']].min", "src_uid": "bb433cdb8299afcf46cb2797cbfbf724"} {"source_code": "input = gets.chomp.to_i\nif input % 2 == 0 && input != 2\n puts \"YES\"\nelse\n puts \"NO\"\nend", "src_uid": "230a3c4d7090401e5fa3c6b9d994cdf2"} {"source_code": "n, m = gets.chomp.split(' ').map { |x| x.to_i }\n\nbuttons = gets.chomp.split(' ').map { |x| x.to_i }\n\n\nn.times do |i|\n\n\tbuttons.each do |button|\n\n\t\tif button <= i+1\n\t\t\tprint button,\" \"\n\t\t\tbreak\n\t\tend\n\tend\nend\n\nputs\n\n", "src_uid": "2e44c8aabab7ef7b06bbab8719a8d863"} {"source_code": "def step(a,op)\n\ta.permutation.map{|v| ( ( [ (op==\"+\") ? v[0]+v[1] : v[0]*v[1] ] ) + ( (v.drop(2)) ? v.drop(2) : [] ) ).sort }.uniq\nend\n\n\na=gets.split.map{|v| v.to_i}\noper=gets.split\nres=[]\nstep(a,oper[0]).each do |v| \n step(v,oper[1]).each do |t|\n\tres+=step(t,oper[2])\n end\nend\nputs res.min", "src_uid": "7a66fae63d9b27e444d84447012e484c"} {"source_code": "debug = 0\nif debug==1 then f=File.open \"c1.txt\"\nelse f = $stdin\nend\n\nweek = [\"monday\", \"tuesday\", \"wednesday\", \"thursday\", \"friday\", \"saturday\", \"sunday\"]\nmonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n\nday0, day1 = f.read.chomp.split \"\\n\"\nid0 = week.find_index day0\nid1 = week.find_index day1\ngood = FALSE\n12.times do |i|\n\t#month i starts with day 0, does month i+1 start with day 1?\n\t(good = TRUE) and break if (id0 + month[i])%7==id1\n#\tif (id0 + month[i])%7==id1 then\n#\t\tgood = TRUE\n#\t\tbreak\n#\tend\nend\n$stdout.puts (if good then \"YES\" else \"NO\" end)", "src_uid": "2a75f68a7374b90b80bb362c6ead9a35"} {"source_code": "x,y,z,k=gets.split.map(&:to_i)\nx,y,z=[x,y,z].sort\nx=[x-1,k/3].min\nk-=x\ny=[y-1,k/2].min\nk-=y\np -~x*-~y*-~[z-1,k].min", "src_uid": "8787c5d46d7247d93d806264a8957639"} {"source_code": "#!/usr/bin/ruby\ns=gets.chomp\nk=gets.to_i\nl=s.size\nm=l+k\nm=m-m%2\nif k>=l\n\tp m\nelse\n\tma=0\n\tl.times{|i|\n\t\t1.step(l-i){|j|\n\t\t\tif 2*j>ma && i.step(i+j-1).all?{|o|(o+j>=l&&o+j0]\n", "src_uid": "44bed0ca7a8fb42fb72c1584d39a4442"} {"source_code": "t = gets.chomp.to_i\ns = gets.chomp\n\nputs s.count('L') + s.count('R') + 1", "src_uid": "098ade88ed90664da279fe8a5a54b5ba"} {"source_code": "p gets.split.map{|_|_.to_i(A=$_.bytes.max-47)}.inject(:+).to_s(A).size\n", "src_uid": "8ccfb9b1fef6a992177cc49bd56fab7b"} {"source_code": "#!/usr/bin/env ruby\nT='CODEFORCES'\nS=gets.chomp\n0.step(S.size){|i|\n\ti.step(S.size){|j|\n\t\tif S[0,i]+S[j..-1]==T\n\t\t\tputs :YES\n\t\t\texit\n\t\tend\n\t}\n}\nputs :NO", "src_uid": "bda4b15827c94b526643dfefc4bc36e7"} {"source_code": "a=gets.to_i\nb=gets.to_i\nc=a+b\na=a.to_s.split(\"\")\nb=b.to_s.split(\"\")\nc=c.to_s.split(\"\")\na.delete(\"0\") \nb.delete(\"0\") \nc.delete(\"0\")\na=a.join.to_i\nb=b.join.to_i\nc=c.join.to_i\nif a+b==c\nputs \"YES\"\nelse\nputs \"NO\"\nend\n", "src_uid": "ac6971f4feea0662d82da8e0862031ad"} {"source_code": "def solve(a)\n n = a.size\n sum = 0\n res = 360\n n.times do |i|\n sum += a[i]\n res = [res, (360 - 2 * sum).abs].min\n end\n return res\nend\n\nn = gets.to_i\na = gets.split.map(&:to_i)\nans = 360\nn.times do |i|\n ans = [ans, solve(a)].min\n a.push(a.shift)\nend\nputs ans", "src_uid": "1b6a6aff81911865356ec7cbf6883e82"} {"source_code": "gets.to_i.times { a=gets+gets;puts a.include?('1') ? (!a.include?('0') ? 2 : 1) : 0}\r\n", "src_uid": "7336b8becd2438f0439240ee8f9610ec"} {"source_code": "#!/usr/bin/ruby\nn=gets.to_i\na=n\nb=[1,n-1].max\nc=[1,n%2>0 ? n-2 : n-3].max\nr=a.lcm(b).lcm(c)\nr=[r,(a-1).lcm(b-1).lcm(c)].max if n%2==0&&n%3==0\np r", "src_uid": "25e5afcdf246ee35c9cef2fcbdd4566e"} {"source_code": "\ndef sum(x) \n\n return x[0] + x[1] + x[2]\n\nend\n\ni = (sum(gets.split.map(&:to_i)) + 4) / 5\n\nj = (sum(gets.split.map(&:to_i)) + 9) / 10\n\nn = gets.to_i\n\nif (i + j <= n)\n puts \"YES\"\nelse\n puts \"NO\"\nend", "src_uid": "fe6301816dea7d9cea1c3a06a7d1ea7e"} {"source_code": "puts \"Karen\"", "src_uid": "1649d2592eadaa8f8d076eae2866cffc"} {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nc = [0, 0, 0]\nn.times{|i| c[i % 3] += a[i]}\nif c[0] == c.max\n puts \"chest\"\nelsif c[1] == c.max\n puts \"biceps\"\nelse\n puts \"back\"\nend\n", "src_uid": "579021de624c072f5e0393aae762117e"} {"source_code": "gets\nar = gets.chomp!.split ' '\n\npart = 0\nok = true\nlst = -1\nar.each do |ai|\n\tai = ai.to_i\n\tif part == 0\n\t\tif lst == ai\n\t\t\tpart = 1\n\t\telsif lst > ai\n\t\t\tpart = 2\n\t\tend\n\telsif part == 1\n\t\tif lst > ai\n\t\t\tpart = 2\n\t\telsif lst < ai\n\t\t\tok = false\n\t\tend\n\telse\n\t\tif lst <= ai\n\t\t\tok = false\n\t\tend\n\tend\n\tlst = ai\nend\n\nputs(if ok; \"YES\"; else; \"NO\"; end)\n", "src_uid": "5482ed8ad02ac32d28c3888299bf3658"} {"source_code": "n = gets.chomp\nn = n.split\nrows = n[0].to_i\ncolumns = n[1].to_i\n\nc = []\nfor i in (1..rows)\n\tc[i] = gets.chomp\nend\n\ncolors = []\ncount = 0\nfor i in (1..rows)\n\tcolors << c[i].split\nend\n\nfor i in (0..colors.size-1)\n\tfor x in (0..columns-1)\n\t\tif colors[i][x] == \"C\" || colors[i][x] == \"M\" || colors[i][x] == \"Y\"\n\t\t\tcount += 1\n\t\t\tbreak\n\t\tend\n\tend\nend\n\nif count >= 1\n\tprint \"#Color\"\nelse\n\tprint \"#Black&White\"\nend", "src_uid": "19c311c02380f9a73cd477e4fde27454"} {"source_code": "#!/usr/bin/env ruby\n\nm, s = $stdin.gets.split.map { |d| d.to_i }\n\n# Special case of sum zero\nif s == 0\n if m == 1\n puts \"0 0\"\n else\n puts \"-1 -1\"\n end\n exit 0\nend\n\ndef increment(a)\n i = a.size - 1\n while i >= 0\n if a[i] != 9\n a[i] += 1\n return true\n end\n i -= 1\n end\n return false\nend\n\ndef decrement(a)\n i = a.size - 1\n while i >= 0\n if a[i] != 0\n a[i] -= 1\n return true\n end\n i -= 1\n end\n return false\nend\n\ndef sum(a)\n a.inject(:+)\nend\n\ndef print_a(a)\n a.map{|d| d.to_i} * \"\"\nend\n\nsmallest = [0] * m\nsmallest[0] = 1\nwhile sum(smallest) < s and increment(smallest); end\n\nlargest = [9] * m\nwhile sum(largest) > s and decrement(largest); end\n\nif sum(smallest) == s and sum(largest) == s\n puts \"#{print_a(smallest)} #{print_a(largest)}\"\nelse\n puts \"-1 -1\"\nend\n", "src_uid": "75d062cece5a2402920d6706c655cad7"} {"source_code": "a, b, x = gets.strip.split.map(&:to_i)\n\nstarter = (b>a ? 1 : 0)\nif starter == 1\n str = \"1\"\n x.times do |i|\n str << (i%2).to_s\n end\n\n r0 = [a - str.count(\"0\"), 0].max\n r1 = [b - str.count(\"1\"), 0].max\n\n if str[-1] == \"0\"\n r0.times do |i|\n str << \"0\"\n end\n else\n str = str[0...-1]\n r0.times do |i|\n str << \"0\"\n end\n str << \"1\"\n end\n\n str = (\"1\"*r1) + str\n puts str\nelse\n str = \"0\"\n x.times do |i|\n str << ((i+1)%2).to_s\n end\n\n r0 = [a - str.count(\"0\"), 0].max\n r1 = [b - str.count(\"1\"), 0].max\n\n if str[-1] == \"1\"\n r1.times do |i|\n str << \"1\"\n end\n else\n str = str[0...-1]\n r1.times do |i|\n str << \"1\"\n end\n str << \"0\"\n end\n\n str = (\"0\"*r0) + str\n puts str\nend", "src_uid": "ef4123b8f3f3b511fde8b79ea9a6b20c"} {"source_code": "T='fedabc'\ns=gets.chomp\nx=T.index(s[-1])+1\ns=s.to_i-1\nd,r=s.divmod(4)\nif r%2==1\n\tx+=7\nend\np x+d*16", "src_uid": "069d0cb9b7c798a81007fb5b63fa0f45"} {"source_code": "n=gets.to_i\n4.times do |v|\n a = gets.split.map(&:to_i)\n 2.times do |i|\n 2.times do |j|\n if a[i]+a[2+j] <=n\n puts \"#{v+1} #{a[i]} #{n-a[i]}\"\n exit\n end\n end\n end\nend\np -1\n\n", "src_uid": "6e7ee0da980beb99ca49a5ddd04089a5"} {"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\nn = inp[0]\nn.times do\n n, d, k = inp\n onf = na(d+1)\n t = inp\n min = 9999999\n now = 0\n t.size.times do |i|\n if(i-k >= 0)\n min = [now,min].min\n onf[t[i-k]] -= 1\n if(onf[t[i-k]] == 0)\n now -= 1\n end\n end\n if(onf[t[i]] == 0)\n now += 1\n end\n onf[t[i]] += 1\n end\n min = [now,min].min\n p min\nend\n", "src_uid": "56da4ec7cd849c4330d188d8c9bd6094"} {"source_code": "puts ((a=gets.next)=7 then\n\tbreak\n\n elsif temp == team_situation.split(\"\")[num] then\n\t$cnt += 1\n\n else\n\ttemp = team_situation.split(\"\")[num]\n\t$cnt = 1\n end\n\nend\n\n#puts $cnt\nif $cnt >= 7 then \n puts \"YES\"\nelse\n puts \"NO\"\nend\n\n", "src_uid": "ed9a763362abc6ed40356731f1036b38"} {"source_code": "n, m = gets.split.map(&:to_i)\nans = 0\n0.upto(1000) do |a|\n 0.upto(1000) do |b|\n ans+=1 if a*a+b==n && a+b*b==m\n end\nend\n\nputs ans", "src_uid": "03caf4ddf07c1783e42e9f9085cc6efd"} {"source_code": "n = gets.to_i\n\narr = gets.split.map{|x| x.to_i}\n\nmin = max = f = s = 0\n\n1.upto(n) do |i|\n\tf, s = arr[-i] + min, max\n\tf, s = s, f if arr[-i] + min < max\n\t\n\tmax, min = f, s\nend\n\nprint s, \" \", f", "src_uid": "414540223db9d4cfcec6a973179a0216"} {"source_code": "require 'date'\na, b = 2.times.map{gets.split('.').map(&:to_i).reverse}\na[0] += 2000\nputs b.permutation.map{|c|\n\tc[0] += 2000\n\tbegin\n\t\tDate.new(*a) >= Date.new(*c).next_year(18)\n\trescue ArgumentError\n\t\tnil\n\tend\n}.any? ? :YES : :NO\n\n", "src_uid": "5418c98fe362909f7b28f95225837d33"} {"source_code": "l,r = gets.split(\" \").map(&:to_i)\nanswer = -1\nl.upto(r) {|i|\n j = i.to_s.split(\"\")\n if (j.count - j.uniq.count) == 0\n answer = i\n break\n end\n}\nputs answer", "src_uid": "3041b1240e59341ad9ec9ac823e57dd7"} {"source_code": "def solve(v,k)\n k = k.to_f\n res = 0\n i = 0\n while v / (k**i) >= 1.0\n res += (v/(k**i)).to_i\n i += 1\n end\n return res\nend\n\nn,k = gets.split.map(&:to_i)\nstart = n * (k - 1) / k\nfor v in (start - 10000)..(start + 10000)\n if solve(v,k) >= n\n puts v\n exit\n end\nend\n\n", "src_uid": "41dfc86d341082dd96e089ac5433dc04"} {"source_code": "def dist(x1,y1,x2,y2)\n x1-=x2\n y1-=y2\n x1=x1>0?x1:-x1\n y1=y1>0?y1:-y1\n return x1+y1\nend\n \nposx=[]\nposy=[]\ndelta=[]\nsm=[]\nargs=gets.split.collect{|s|s.to_i}\nx0,y0,ax,ay,bx,by=args[0],args[1],args[2],args[3],args[4],args[5]\nargs=gets.split.collect{|s|s.to_i}\nxs,ys,t=args[0],args[1],args[2]\nposx.push(x0)\nposy.push(y0)\ndelta.push(0)\nsm.push(0)\nwhile delta[-1]<=t+xs+ys\n x0,y0=ax*posx[-1]+bx,ay*posy[-1]+by\n delta.push(dist(x0,y0,posx[-1],posy[-1]))\n sm.push(delta[-1]+sm[-1])\n posx.push(x0)\n posy.push(y0)\nend\n \nma=0\nl=posx.length\nfor i in 0..l-1\n king=dist(xs,ys,posx[i],posy[i])\n for j in 0..i\n miles=(sm[i]-sm[j])+king\n cnt=i-j+1\n if miles<=t&&cnt>ma\n ma=cnt\n end\n miles+=(sm[i]-sm[j])\n for k in i+1..l-1\n miles+=delta[k]\n if miles<=t\n cnt+=1\n if(cnt>ma)\n ma=cnt\n end\n else \n break\n end\n end\n end\nend\nputs ma", "src_uid": "d8a7ae2959b3781a8a4566a2f75a4e28"} {"source_code": "i=1\ns=\"\"\nwhile s.size<1001\n\ts< 0\n for i in 0...ans.abs\n s[s.index('x')] = 'X'\n end\nelse\n for i in 0...ans.abs\n s[s.index('X')] = 'x'\n end\nend\nputs ans.abs\nputs s\n", "src_uid": "fa6311c72d90d8363d97854b903f849d"} {"source_code": "#!/usr/bin/ruby\n\ninput_line = gets\nparams = input_line.split(' ')\n\np1 = params[0].to_i\np2 = params[1].to_i\nt1 = params[2].to_f\nt2 = params[3].to_f\nres1 = [3*p1/10, p1-t1*p1/250].max\nres2 = [3*p2/10, p2-t2*p2/250].max\nif (res1 > res2)\n puts \"Misha\"\nelsif (res2 > res1)\n puts \"Vasya\"\nelse\n puts \"Tie\"\nend", "src_uid": "95b19d7569d6b70bd97d46a8541060d0"} {"source_code": "s=gets.chomp\nputs s[0,-~s.size/2].reverse.chars.zip(s[-~s.size/2..-1].chars).map{|x,y|x+y.to_s}*''", "src_uid": "992ae43e66f1808f19c86b1def1f6b41"} {"source_code": "# http://codeforces.com/problemset/problem/41/A\n\nbir = gets.chomp\nber = gets.chomp\n\nputs (bir.reverse == ber) ? \"YES\" : \"NO\"", "src_uid": "35a4be326690b58bf9add547fb63a5a5"} {"source_code": "n = gets.chomp.to_i\narr = []\nfor i in (0..n-1)\n\tarr << gets.chomp.to_i\nend\n\nfor i in (0..n-1)\n\tif arr[i]%3 == 0 || arr[i]%7 == 0\n\t\tputs \"YES\"\n\telse\n\t\tx = arr[i]\n\t\twhile x > 0\n\t\t\tif x%7 == 0\n\t\t\t\tx = 0\n\t\t\t\tbreak\n\t\t\telsif x%3 == 0\n\t\t\t\tx = 0\n\t\t\t\tbreak\n\t\t\telsif x - 7 >= 0\n\t\t\t\tx -= 7\n\t\t\telsif x - 3 >= 0\n\t\t\t\tx -= 3\n\t\t\telse\n\t\t\t\tbreak\n\t\t\tend\n\t\tend\n\t\tif x == 0\n\t\t\tputs \"YES\"\n\t\telse\n\t\t\tputs \"NO\"\n\t\tend\n\tend\nend", "src_uid": "cfd1182be98fb5f0c426f8b68e48d452"} {"source_code": "def calc(n, g)\n\tx = n/g\n\trem = n%g\n\treturn rem*(@c1+@c2*x**2) + (g-rem)*(@c1+@c2*(x-1)**2)\nend\n\ninp = gets.split(\" \")\nn = inp[0].to_i\n@c1 = inp[1].to_i\n@c2 = inp[2].to_i\ns = gets\na = 0\nfor i in 0..n-1\n\ta+=1 if s[i]=='1'\nend\nans = calc(n, 1)\nfor i in 2..a\n\tans = [ans, calc(n, i)].min\nend\nputs ans", "src_uid": "78d013b01497053b8e321fe7b6ce3760"} {"source_code": "board = Array.new(3) { Array.new(3, 0) }\n3.times do |i|\n line = gets.strip.split.map(&:to_i)\n 3.times do |j|\n if line[j] > 0\n board[i][j] += line[j]\n board[i][j + 1] += line[j] if j + 1 < 3\n board[i][j - 1] += line[j] if j - 1 > -1\n board[i + 1][j] += line[j] if i + 1 < 3\n board[i - 1][j] += line[j] if i - 1 > -1\n end\n end\nend\nboard.each do |line|\n text = \"\"\n line.each do |a|\n text += '1' if a.even?\n text += '0' if a.odd?\n end\n puts text\nend\n", "src_uid": "b045abf40c75bb66a80fd6148ecc5bd6"} {"source_code": "n=gets.to_i;s=i=0;s+=i+=1while s first_line[0].to_i, \"y\" => first_line[1].to_i, \"z\" => first_line[2].to_i}\n\nsecond_line = gets.split(\" \")\nbox = {\"x\" => second_line[0].to_i, \"y\" => second_line[1].to_i, \"z\" => second_line[2].to_i}\n\narray = gets.split(\" \")\n\n\narray[5] = 0 if vasya[\"x\"] <= box[\"x\"]\narray[4] = 0 if vasya[\"x\"] >= 0\n\narray[1] = 0 if vasya[\"y\"] <= box[\"y\"] \narray[0] = 0 if vasya[\"y\"] >= 0\n\narray[3] = 0 if vasya[\"z\"] <= box[\"z\"]\narray[2] = 0 if vasya[\"z\"] >= 0\n\nsum = 0\narray.each do |el|\n\tsum += el.to_i\nend\n\nputs sum", "src_uid": "c7889a8f64c57cf7be4df870f68f749e"} {"source_code": "#!/usr/bin/env ruby\n\na,b = STDIN.gets.split.map(&:to_i)\n\nif b - a > 10\n puts '0'\nelse\n x = 1\n (a+1).upto(b) { |i| x = (x * i % 10) }\n puts x\nend\n", "src_uid": "2ed5a7a6176ed9b0bda1de21aad13d60"} {"source_code": "n = gets.to_i \nk = 0;\nfor i in 1..n-1\n if((n%i) == 0)\n k+=1;\n end\nend \np k", "src_uid": "89f6c1659e5addbf909eddedb785d894"} {"source_code": "def solve?\n rec = []\n hen,shu = 0,0\n xx,yy = [],[]\n 4.times{\n x1,y1,x2,y2 = gets.split.map(&:to_i)\n if x1 == x2 then\n shu += 1\n xx << x1\n end\n if y1 == y2 then\n hen += 1\n yy << y1\n end\n rec << [x1,y1,x2,y2]\n }\n return false if shu != 2 || hen != 2 || xx[0] == xx[1] || yy[0] == yy[1]\n 4.times do |i|\n return false if rec[i][0] == rec[i][2] &&\\\n (![rec[i][1],rec[i][3]].include?(yy[0]) ||\\\n ![rec[i][1],rec[i][3]].include?(yy[1]))\n return false if rec[i][1] == rec[i][3] &&\\\n (![rec[i][0],rec[i][2]].include?(xx[0]) ||\\\n ![rec[i][0],rec[i][2]].include?(xx[1]))\n end\n return true\nend\n\nputs solve? ? 'YES' : 'NO'", "src_uid": "ad105c08f63e9761fe90f69630628027"} {"source_code": "a,b,c=gets.split.map &:to_i;p 3*[a+1,b,c-1].min", "src_uid": "03ac8efe10de17590e1ae151a7bae1a5"} {"source_code": "def gcd(a, b)\n if b == 0\n return a\n else\n return gcd(b, a % b)\n end\nend\n\na, b = readline.split(' ').collect(&:to_i)\ng = a\na.upto(b) do |num|\n g = gcd(g, num)\n if g == 1\n break\n end\nend\n\nputs g\n", "src_uid": "9c5b6d8a20414d160069010b2965b896"} {"source_code": "n=gets.to_i\nputs n%2>0?\"black\":[\"white\",\"1 2\"]", "src_uid": "52e07d176aa1d370788f94ee2e61df93"} {"source_code": "def invalid?(s)\n (s[0] == \"0\" and s.size > 1) or s.to_i > 10**6\nend\n\nARGF.each_line do |line|\n max = -1\n digit = line.chomp!.size\n 1.upto(digit) do |i|\n 1.upto(digit - i - 1) do |j|\n k = digit - i - j\n\n a = line[0...i]\n b = line[i...(i + j)]\n c = line[(i + j)...digit]\n if invalid?(a) or invalid?(b) or invalid?(c)\n next\n end\n point = a.to_i + b.to_i + c.to_i\n max = point if max < point\n end\n end\n puts max\nend\n", "src_uid": "bf4e72636bd1998ad3d034ad72e63097"} {"source_code": "class C\n def initialize\n a, b = gets.chomp.split(' ').map(&:to_i)\n\n puts dfs(a, b)\n end\n\n def dfs(a, b)\n count = 0\n\n if a == 1\n count += b\n else\n sub = a / b\n if sub > 0\n count += sub\n count += dfs( a % b, b )\n else\n count += dfs( b, a )\n end\n end\n\n count\n end\nend\n\nc = C.new\n", "src_uid": "792efb147f3668a84c866048361970f8"} {"source_code": "a = gets()\nb = gets()\nc = \"\"\nflag = -1\n\n# f(a,c) = b\n\n(0..a.length - 1).each do |x|\n if a[x] < b[x]\n flag = 0\n puts \"-1\"\n break\n end\n any = a[x] > b[x] ? b[x] : a[x]\n c << any\nend\nputs c if flag == -1\n", "src_uid": "ce0cb995e18501f73e34c76713aec182"} {"source_code": "a = gets.split.map &:to_i\np (a[0] + a[1] + a[2])**2 - a[0]**2 - a[2]**2 - a[4]**2", "src_uid": "382475475427f0e76c6b4ac6e7a02e21"} {"source_code": "_, debuff = gets.chop.split.map(&:to_i)\nprices = gets.chop.split.map(&:to_i).sort\nquests_count = gets.chop.to_i\n\nif quests_count > prices.count\n ns = debuff * (quests_count - prices.count )\n quests_count = prices.count\nend\n\nns ||= 0\nps = prices.first(quests_count).reduce(0, :+)\n\nputs ps - ns\n", "src_uid": "5c21e2dd658825580522af525142397d"} {"source_code": "N, M = gets.split.map(&:to_i)\nast = gets.split.map(&:to_i)\nbst = gets.split.map(&:to_i)\nas, bs = [], []\nN.times do |i|\n as[i] = ast.shift(2)\nend\nM.times do |i|\n bs[i] = bst.shift(2)\nend\n\nacand = []\nas.each do |a|\n cand = []\n bs.each do |b|\n ab = a & b\n if ab.length == 1\n cand.push(ab[0])\n end\n end\n cand.uniq!\n if cand.length > 1\n puts -1\n exit\n else\n acand.concat(cand)\n end\nend\n\nbs.each do |b|\n cand = []\n as.each do |a|\n ab = a & b\n if ab.length == 1\n cand.push(ab[0])\n end\n end\n cand.uniq!\n if cand.length > 1\n puts -1\n exit\n end\nend\n\nacand.uniq!\nif acand.length == 1\n puts acand[0]\nelsif acand.length > 1\n puts 0\nelse\n puts -1\nend", "src_uid": "cb4de190ae26127df6eeb7a1a1db8a6d"} {"source_code": "point=gets.split.map(&:to_i)\nx=point[0]\ny=point[1]\nif x.abs==0 || y.abs==0 then\n puts \"black\"\n exit\nend\nd=x*x+y*y\n1.upto(999999){|i|\n if (i%2==1 && x*y>0) || (i%2==0 && x*y<0) then\n #black\n if d<=i*i then\n puts \"black\"\n exit\n end\n else\n #white\n if d b then\n return a\n else\n return b\n end\nend\n\ny,w = gets.split.map{|i| i.to_i}\n\ni = max(y,w)\ni = 7 - i\n\nn = 6\n\nif i == 0 then\n n = 1\nelsif i % 6 == 0 then\n i /= 6\n n /= 6\nelsif i % 3 == 0 then\n i /= 3\n n /= 3\nelsif i % 2 == 0 then\n i /= 2\n n /= 2\nend\n\nputs i.to_s + \"/\" + n.to_s", "src_uid": "f97eb4ecffb6cbc8679f0c621fd59414"} {"source_code": "class List\n attr_accessor :element, :next_elem\n\n def initialize(element, next_elem)\n @element = element\n @next_elem = next_elem\n end\nend\n\nclass Graph\n attr_accessor :vertices\n\n def initialize(vertices)\n @vertices = vertices\n end\n\n def add_edge(number1, number2)\n if vertices[number1].nil? then\n vertices[number1] = List.new(number2, nil)\n else\n vertices[number1] = List.new(number2, vertices[number1])\n end\n end\n\n def print_edges \n vertices.each_with_index do |vertex, index| \n # next if vertex == \"\"\n while !vertex.nil? do \n puts \"edge #{index} - #{vertex.element}\"\n vertex = vertex.next_elem \n end \n end \n end \n\nend \n\ndef dfs(graph, number, visited)\n visited[number] = true\n next_vert = graph.vertices[number]\n # puts \"Processing number: #{number}\"\n # p next_vert\n stack = [] \n # return [number] if next_vert.nil? \n while !next_vert.nil? do \n # puts \"#{next_vert.element} is not nil. Process it\"\n if !visited[next_vert.element]\n # puts \"#{next_vert.element}'s is not visited. Processing it\"\n new_number = dfs(graph, next_vert.element, visited)\n # puts new_number\n stack = new_number + stack\n end\n next_vert = next_vert.next_elem\n end\n # p [number] + stack\n return [number] + stack\nend\n\ndef reverse_graph(graph)\n reversed_graph = Graph.new([])\n graph.vertices.each_with_index do |vertex, index|\n next_vertex = vertex\n while !next_vertex.nil? do \n reversed_graph.add_edge(next_vertex.element, index)\n next_vertex = next_vertex.next_elem\n end\n end\n reversed_graph\nend\n\n\nintersections = Graph.new([])\nn, m = gets.strip.split(\" \").map(&:to_i)\nhorizontal = gets.strip\nvertical = gets.strip\nvisited = Array.new(m*n, false)\n\nn.times do |i|\n # puts i\n # puts horizontal[i]\n if horizontal[i] == \">\"\n (m - 1).times do |j|\n # puts j\n intersections.add_edge(i*m + j, i*m + j + 1)\n end\n else\n (m - 1).times do |j|\n intersections.add_edge(i*m + j + 1, i*m + j)\n end\n end\nend\nm.times do |i|\n if vertical[i] == \"v\"\n (n - 1).times do |j|\n intersections.add_edge(j*m + i, (j+1)*m + i)\n end\n else\n (n - 1).times do |j|\n intersections.add_edge((j+1)*m + i, j*m + i)\n end\n end\nend \n# intersections.print_edges\nstack = []\n(n*m).times do |i|\n if !visited[i]\n stack = dfs(intersections, i, visited) + stack\n # p stack\n end\nend\n# p intersections.vertices.count\nanswer = 'YES'\nreversed_graph = reverse_graph(intersections)\n# reversed_graph.print_edges\n# p visited\nvisited = Array.new(m*n, false)\n# (m*n).times do |i|\n# visited[i] = false\n# end\n# p visited\n# p stack\n# p intersections.vertices[stack.first]\ndfs(reversed_graph, stack.first, visited) \n# p visited\nif visited.any?{|visited| !visited}\n answer = 'NO'\nend\nputs answer\n", "src_uid": "eab5c84c9658eb32f5614cd2497541cf"} {"source_code": "n, d = gets.chomp.split(' ').map(&:to_i)\n\npoints = gets.chomp.split(' ').map(&:to_i)\n\nresult = 0\n\nwhile true\n hash = Hash.new(0)\n \n points.each_with_index do |point, index|\n points.each_with_index do |p, i|\n hash[index] += 1 if((point - p).abs > d and index != i)\n end \n end\n \n hash = hash.sort{|x, y| y[1] <=> x[1]}\n break if hash.empty?\n ind, repeat = hash[0][0], hash[0][1]\n if repeat > 0\n points.delete_at(ind)\n result += 1\n else\n break\n end\nend\n\nputs result", "src_uid": "6bcb324c072f796f4d50bafea5f624b2"} {"source_code": "number=gets.chomp.split\nn=number[0].to_i\nk=number[1].to_i\n#puts n,k\nif n==0\n\tputs 0\nelse\n\tzeros=0\n\tnon_zeros=0\n\tdigits=0\n\twhile n>0\n\t\tif zeros==k \n\t\t\tbreak\n\t\telsif n%10==0\n\t\t\tzeros+=1\n\t\telse\n\t\t\tnon_zeros+=1\n\t\tend\n\t\tdigits+=1\n\t\tn=n/10\n\tend\n\t#puts \"zeros=#{zeros}\"\n\t#puts \"digits=#{digits}\"\n\tif zeros==k\n\t\tputs non_zeros\n\telsif zeros= g ? (total_interval - (till_a % total_interval)) : 0\n# puts \"#{extra_time}\"\na_to_b = (l-d) / v.to_f\n# puts \"#{a_to_b}\"\n# \n\nputs till_a + extra_time + a_to_b", "src_uid": "e4a4affb439365c843c9f9828d81b42c"} {"source_code": "n = gets.to_i\ncase n%4\nwhen 0\n\tputs \"1 A\"\nwhen 1\n\tputs \"0 A\"\nwhen 3\n\tputs \"2 A\"\nelse\n\tputs \"1 B\"\nend", "src_uid": "488e809bd0c55531b0b47f577996627e"} {"source_code": "n = Integer(gets.chomp)\nputs(n > 2 ? \"#{(2..n).to_a*' '} 1\" : -1)", "src_uid": "fe8a0332119bd182a0a5b7758716317e"} {"source_code": "p gets.to_i/2+1", "src_uid": "5551742f6ab39fdac3930d866f439e3e"} {"source_code": "s = gets()\na = s.to_i\ns.reverse!\nb = s.to_i\n\nwhile(1) do\n if(a%10==0)\n a=a/10\n else\n break\n end\nend\n\nif a==b\n puts \"YES\"\nelse\n puts \"NO\"\nend", "src_uid": "d82278932881e3aa997086c909f29051"} {"source_code": "#!/usr/bin/env ruby\nrequire 'set'\n\ns = gets.chomp.to_s\nn = s.length - 1\n\np = Set.new [ s ]\n\nn.times do\n s = s[ n ] + s[ 0 ... n ]\n p.add( s )\nend\n\nputs p.length", "src_uid": "8909ac99ed4ab2ee4d681ec864c7831e"} {"source_code": "H=Hash.new 0\ngets\ngets.chomp.chars{|c|H[c]+=1}\np [H['U'],H['D']].min+[H['L'],H['R']].min<<1", "src_uid": "b9fa2bb8001bd064ede531a5281cfd8a"} {"source_code": "def cani(grandma, me)\n\tfor card in me\n\t\tcard = card.split(//)\n\t\tfor character in card\n\t\t\treturn \"YES\" if grandma.include?(character)\n\t\tend\n\tend\n\treturn \"NO\"\nend\n\ngrandma = gets.chomp\nme = gets.chomp.split(\" \")\nputs(cani(grandma, me))", "src_uid": "699444eb6366ad12bc77e7ac2602d74b"} {"source_code": "puts gets.delete\"^\"+$_.chars.max", "src_uid": "9a40e9b122962a1f83b74ddee6246a40"} {"source_code": "x = gets.to_i\n p (x==3 ? 5 : (Math::sqrt(2*(x-1)+0.9).floor+1)/2*2+1)\n", "src_uid": "01eccb722b09a0474903b7e5abc4c47a"} {"source_code": "a, b, c, d, k = *gets.split(\" \").map(&:to_i)\n# p [a, b, c, d, k]\n# if b < c\n# p 0\n# exit\n# end\n\nstart = [a, c].max\nfim = [b, d].min\n# p [start, fim]\nif fim < start\n p 0\n exit\nend\n\nif k >= start && k <= fim\n fim -= 1\nend\n\np fim-start+1\n", "src_uid": "9a74b3b0e9f3a351f2136842e9565a82"} {"source_code": "X,Y,x,y,a,b=$<.read.split.map &:to_i\nx-=X\ny-=Y\nputs x%a==0&&y%b==0&&x/a%2==y/b%2 ? :YES : :NO", "src_uid": "1c80040104e06c9f24abfcfe654a851f"} {"source_code": "n = gets.to_i\na,b,i = 0,1,0\nwhile a<=n\n a,b, = b, a+b\n i +=1\nend\np i-3\n", "src_uid": "3d3432b4f7c6a3b901161fa24b415b14"} {"source_code": "n, k = gets.split.map &:to_i\na = gets.split.map &:to_i\np a.inject(k){|s, x| [s, k%x == 0 ? k/x : k].min}", "src_uid": "80520be9916045aca3a7de7bc925af1f"} {"source_code": "s = gets.chomp\nc=0\ns.length.times do |i|\n if s[i]=='7' or s[i]=='4'\n c=c+1\n end\nend\nif (c == 4 or c == 7)\n puts \"YES\"\nelse\n puts \"NO\"\nend", "src_uid": "33b73fd9e7f19894ea08e98b790d07f1"} {"source_code": "n, m, k = gets.split.map(&:to_i)\na = Array.new(n) do\n gets\n Array.new(m) do\n gets.split.map(&:to_i)\n end\nend\n\nans = 0\na.permutation(2) do |x, y|\n z = []\n m.times do |i|\n z <<= [y[i][1] - x[i][0], x[i][2]]\n end\n tmp = 0\n rem = k\n z.sort.reverse.each do |i, j|\n num = [rem, j].min\n tmp += i * num if i > 0\n rem -= num\n end\n ans = [ans, tmp].max\nend\np ans\n", "src_uid": "7419c4268a9815282fadca6581f28ec1"} {"source_code": "n, a = gets.split(' ').map(&:to_i)\nputs a.even? ? 1 + n / 2 - a / 2 : 1 + a / 2\n", "src_uid": "aa62dcdc47d0abbba7956284c1561de8"} {"source_code": "n,m = gets.split(' ').map(&:to_i)\ns = n/2\nif n==1\n puts \"1\"\n exit\nend\nif s >=m\n m += 1\n puts m\n exit\nend\nm -= 1\nputs m\n\n", "src_uid": "f6a80c0f474cae1e201032e1df10e9f7"} {"source_code": "a = gets.chomp!.split\nn = a[0].to_i\nr_ = a[1].to_i\nr = a[2].to_i\ns = r_ - r\n\nif s < 0 then puts(\"NO\")\nelsif s < r then \n\tif n == 1 then puts(\"YES\")\n\telse puts(\"NO\") end\nelsif n == 2 then\n\tif s >= r then puts(\"YES\")\n\telse puts(\"NO\") end\nelsif n == 6 then\n\tif r_ >= r * 3 then puts(\"YES\")\n\telse puts(\"NO\") end\nelse\n\tn = n.to_f\n\tr = r.to_f\n\ts = s.to_f\n\t#p Math.asin(r / s)\n\t#p Math::PI / n\n\tif Math.asin(r / s) <= Math::PI / n then puts(\"YES\")\n\telse puts(\"NO\") end\nend", "src_uid": "2fedbfccd893cde8f2fab2b5bf6fb6f6"} {"source_code": "require 'pp'\n\nn = STDIN.gets.chomp.to_i\n\nans = 0\nwhile true\n n+=1\n ans+=1\n n.to_s.split(//).each do |e|\n if e == '8'\n puts ans\n exit(0)\n end\n end\nend\n", "src_uid": "4e57740be015963c190e0bfe1ab74cb9"} {"source_code": "n,x,y=gets.split.map &:to_i;puts x%(q=2+n/=2) c_max\n\t(1..m-1).each do |n|\n\t\tnext if (m-n)%2 == 0\n\t\tnext if gcd(m, n) > 1\n\t\tsum = m*m + n*n\n\t\tbreak if sum > c_max\n\t\tdifference = m*m-n*n\n\t\tproduct = 2*m*n\n\t\tk = 1\n\t\twhile k*sum <= c_max\n\t\t\ta = k*difference\n\t\t\tb = k*product\n\t\t\tc = k*sum\n\t\t\ttriple_num[c] += 1\n\t\t\ttriple = [a, b, c]\n\t\t\ttriples[c].push(triple)\n\t\t\tcount += 1\n\t\t\tk += 1\n\t\tend\n\tend\n\tm += 1\nend\n\nputs count\n\n", "src_uid": "36a211f7814e77339eb81dc132e115e1"} {"source_code": "string = gets.chomp\nwords = []\nwords = string.gsub(\"WUB\", \"a\").split('a')\n\nwords.each do |word|\n\tprint \"#{word} \" if word != \"\"\nend", "src_uid": "edede580da1395fe459a480f6a0a548d"} {"source_code": "puts [:No, :Yes][gets.split.uniq.size == 1? 1:0]", "src_uid": "65f81f621c228c09915adcb05256c634"} {"source_code": "a,b,x,y=gets.split.map &:to_i;g=x.gcd y;p [a*g/x,b*g/y].min", "src_uid": "907ac56260e84dbb6d98a271bcb2d62d"} {"source_code": "n = gets.chomp.to_i\nanswer = false\na = 0\nwhile a <= n\n b = 0\n while a + b <= n\n if( ( n - ( a + b ) ) % 1234 == 0 )\n answer = true\n a = n;\n break;\n end\n b += 123456\n end\n a += 1234567\nend\n\nif answer\n puts \"YES\"\nelse\n puts \"NO\"\nend\n", "src_uid": "72d7e422a865cc1f85108500bdf2adf2"} {"source_code": "t = gets.to_i\r\nt.times{\r\n\tk = gets.to_i\r\n\tratio = Rational(k,100)\r\n\tp ratio.denominator\r\n}", "src_uid": "19a2bcb727510c729efe442a13c2ff7c"} {"source_code": "n, m = *STDIN.read.split(' ').map(&:to_i)\n\nlb = (n+1)/2 ;\na = (lb+m-1)/m*m ;\nif a>n\n a = -1\nend\n\nputs a\n", "src_uid": "0fa526ebc0b4fa3a5866c7c5b3a4656f"} {"source_code": "s=gets.chomp\na=nil\n(0..s.size).find{|i|(?a..?z).find{|c|t=s.dup;t[i,0]=c;(t==t.reverse&&a=t)}}\nputs a||\"NA\"", "src_uid": "24e8aaa7e3e1776adf342ffa1baad06b"} {"source_code": "def subsetSum(set, n, sum)\n subset = (n + 1).times.map { [true] * (sum + 1) }\n 1.upto(sum) {|i| subset[0][i] = false }\n 1.upto(n) do |i|\n 1.upto(sum) do |j|\n subset[i][j] = subset[i - 1][j] if j < set[i - 1]\n subset[i][j] = subset[i - 1][j] || subset[i - 1][j - set[i - 1]] if j >= set[i - 1]\n end\n end\n return subset[n][sum]\nend\n\ndef solve(a)\n while true\n sumall = a.sum\n if sumall % 2 == 1\n printf(\"0\\n\")\n return\n end\n a.each.with_index do |x, i|\n if x % 2 == 1\n if !subsetSum(a, a.size, a.sum / 2)\n printf(\"0\\n\")\n return\n end\n printf(\"1\\n\")\n printf(\"%d\\n\", i + 1)\n return\n end\n end\n a.map! {|x| x / 2 }\n end\nend\n\nn = gets.to_s.to_i\na = gets.to_s.split.map {|x| x.to_i }\n\nsolve(a)\n", "src_uid": "29063ad54712b4911c6bf871969ee147"} {"source_code": "n, m = gets.split.collect{|i| i.to_i}\nmm = Array.new\n(1..n).each{mm.push(gets.chomp.split(''))}\nans = 0\nfor i in 0...n\n for j in 0...m\n next unless mm[i][j] == 'P'\n if i-1 >= 0 and mm[i-1][j] == 'W'\n mm[i-1][j] = '.'\n ans += 1\n next\n end\n if i+1 < n and mm[i+1][j] == 'W'\n mm[i+1][j] = '.'\n ans += 1\n next\n end\n if j-1 >= 0 and mm[i][j-1] == 'W'\n mm[i][j-1] = '.'\n ans += 1\n next\n end\n if j+1 < m and mm[i][j+1] == 'W'\n mm[i][j+1] = '.'\n ans += 1\n next\n end\n end\nend\nputs ans\n", "src_uid": "969b24ed98d916184821b2b2f8fd3aac"} {"source_code": "input_origen=gets.chomp\ninput_destino=gets.chomp\n\nar_origen=input_origen.split(\" \")\nar_destino=input_destino.split(\" \")\n\nx1=ar_origen[0].to_i; y1=ar_origen[1].to_i\nx2=ar_destino[0].to_i; y2=ar_destino[1].to_i\n\nx2=(x2-x1).abs\ny2=(y2-y1).abs\n\nx1=0;y1=0\nif y2>=x2\n\t$pasos=y2\nelse\n\t$pasos=x2\nend\nprint $pasos", "src_uid": "a6e9405bc3d4847fe962446bc1c457b4"} {"source_code": "left, right = Hash.new(0), Hash.new(0)\nn = gets.to_i\nfor i in 0...n\n l, r = gets.split.map(&:to_i)\n left[l] += 1\n right[r] += 1\nend\nsum = 0\nleft.each do |k, v| \n sum += v * right[k]\n left[k] = 0\nend\nright.each do |k, v| \n sum += v * left[k]\n left[k] = 0\nend\nputs sum", "src_uid": "745f81dcb4f23254bf6602f9f389771b"} {"source_code": "def s x\n\tx.to_s.chars.map { |c| c.to_i }.reduce(:+)\nend\n\na, b, c = gets.split.map { |x| x.to_i }\n\nans = []\n1.upto(100) do |i|\n\tx = b * i ** a + c\n\tif x > 0 and x < 1e9.to_i and s(x) == i\n\t\tans << x\n\tend\nend\n\nputs ans.size\nputs ans.sort.join ' '", "src_uid": "e477185b94f93006d7ae84c8f0817009"} {"source_code": "n,k=gets.split(\" \").map(&:to_i)\nx,y=Array.new(n),Array.new(k)\nans=k>1 ?1:0\nik=gets.split(\" \")\nfor i in 0..n-1 do\nx[i]=ik[i].to_i\nend\nik=gets.split(\" \")\nfor i in 0..k-1 do\ny[i]=ik[i].to_i\nend\nif x[0]==0&&k==1 then x[0]=y[0] end\nfor i in 1..n-1 do\nif x[i]==0&&k==1 then x[i]=y[0] end\nif x[i] (s.size / 2) ? s.upcase! : s.downcase!\nputs s", "src_uid": "b432dfa66bae2b542342f0b42c0a2598"} {"source_code": "def dep?(arr)\n size = arr.size - 1\n for i in 1...size do\n return true if arr[i - 1] + arr[i] > arr[i + 1]\n end\n false\nend\nn = gets.chomp.to_i\narr = gets.split.map(&:to_i)\narr.sort!\n\nputs dep?(arr) ? 'YES' : 'NO'\n", "src_uid": "897bd80b79df7b1143b652655b9a6790"} {"source_code": "n = gets.to_i\n\nx = (n / 2.0).ceil - 1.0\n\nputs x.to_i", "src_uid": "dfe9446431325c73e88b58ba204d0e47"} {"source_code": "c,d = gets.split.map &:to_i\nm,n = gets.split.map &:to_i\nk = gets.to_i\n\n\nneed = m*n - k\nif need <= 0\n puts 0\n exit\nend\n\n$hash = Hash.new -1\ndef solve(need, c, d, m)\n return $hash[need] if $hash[need] != -1\n return $hash[need] = 0 if need <= 0\n if need <= m then return $hash[need] = [c, need * d].min end\n return $hash[need] = [solve(need - m, c, d, m) + c, solve(need - 1, c, d, m) + d].min\nend\n\nputs solve(need, c, d, m)\n\nexit\n\nr = 0\nif c < m*d # better use typical round\n r = ((need+m) / m) * c\nelse\n r = need * d\nend\n\nputs r\n\n", "src_uid": "c6ec932b852e0e8c30c822a226ef7bcb"} {"source_code": "a,b,c = gets.split.map(&:to_i)\np (c*a-c*b-1)/b+1\n\n", "src_uid": "7dd098ec3ad5b29ad681787173eba341"} {"source_code": "=begin\n , \\ / ,\n / \\ )\\__/( / \\\n / \\ (_\\ /_) / \\\n ____/_____\\__\\@ @/___/_____\\____\n | |\\../| |\n | \\VV/ |\n | ------hoi------- |\n |_________________________________|\n | /\\ / \\\\ \\ /\\ |\n | / V )) V \\ |\n |/ ` // ' \\|\n ` V '\n=end\n\n n, m = gets.split.map(&:to_i).sort\np [m, m / 4 * 4 + [0, 2, 4, 4][m % 4], (n * m + 1) / 2][[n - 1, 2].min]", "src_uid": "e858e7f22d91aaadd7a48a174d7b2dc9"} {"source_code": "a,b=gets.split.map &:to_i;r=0;[2,5,8].map{|i|r+=(i*a+b-1)/b};p r", "src_uid": "d259a3a5c38af34b2a15d61157cc0a39"} {"source_code": "require 'date'\na = Date::MONTHNAMES[1..-1]\nb = gets.chomp\nc = gets.to_i\nputs a[(a.index(b) + c) % 12]\n", "src_uid": "a307b402b20554ce177a73db07170691"} {"source_code": "def solution(days)\n prev = nil\n rest_days = 0\n days.each_with_index do |activity, index|\n (rest_days += 1; prev = 0; next) if activity == 0\n (rest_days += 1; prev = 0; next) if activity == prev && activity != 3\n if activity == 3\n days[index] = 2 if prev == 1\n days[index] = 1 if prev == 2\n end\n prev = days[index]\n end\n rest_days\nend\n\n_ = gets\nputs solution(gets.split.map(&:to_i))\n", "src_uid": "08f1ba79ced688958695a7cfcfdda035"} {"source_code": "a,b,s=gets.split.map(&:to_i)\nt=s-a.abs-b.abs\nputs t>=0&&t%2==0?\"Yes\":\"No\"", "src_uid": "9a955ce0775018ff4e5825700c13ed36"} {"source_code": "#!/usr/bin/env ruby\n# -*- coding: utf-8 -*-\n\n# b.rb\n\ndef main()\n v1, v2 = gets.chomp.split(\" \").map{|s| next s.to_i }\n t, d = gets.chomp.split(\" \").map{|s| next s.to_i }\n\n r = 0\n t.times do |tt|\n t1 = tt\n t2 = t - 1 - tt\n r += [v1 + d * t1, v2 + d * t2].min\n end\n puts r\n \nend\n \nif __FILE__ == $0 then\n main()\nend\n", "src_uid": "9246aa2f506fcbcb47ad24793d09f2cf"} {"source_code": "gets\na=gets.split.reverse.uniq.reverse\np a.size\nputs a*' '", "src_uid": "1b9d3dfcc2353eac20b84c75c27fab5a"} {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\n# n - 방문한 버텍스까지의 웨이트 총합\n# k - 트리의 유형(the number of children)\n# d - 웨이트가 d인 에지로, 반드시 포함되어야함\n# 1<=d<=k 이므로 d가 k보다 커질 일은 없음\n# 1<=n,k<=100\nn, k, d = gets.split.map(&:to_i)\nMODULO_BASE = 10**9 + 7\ndp = Array.new(n+1) { [0, 0] }\n# dp factors: '합'과 weight d 이상의 노드 방문 여부\n# 그래서 트리 전체가 아니고, n까지 도달하는 과정을 점진적으로 만들어간다.\n# 합이 S1 인 지점에서 S1 + 1, S1 + 2, ... S1 + K 에 도달하는 방법.\n\n# 자, 리셋해뒀으니 내일 다시 풀어봅시다.\n# 코드를 외우든지 dp 를 정복하기 위한 생각을 만들든지!\n# 지금이 내일이다 새끼야\n\n# 합이 0이 되는 경로를 우선 고려(zero) depth 0\ndp[0][0] = 1 # 0 을 통과하는 경로는 하나 존재할 수 있음. (이후엔 존재해선 안됨)\ndp[0][1] = 0 # 0 < d 가 항상 성립하므로 경로의 수가 없다.\nfor i in 1..n\n # initialize intermediate sum to zero\n dp[i][0] = 0\n dp[i][1] = 0\n for j in 1..k # 만날때마다 k개의 차일드 노드에 대해 평가를 한다.\n if i < j\n break # depth 1에서, i < j 인 경우 이전 경유 노드를 판단할 수 없다.\n end\n\n # 현재 weight 가 j인 경로로 노드를 찾아갈 때\n # 이전에는 몇개 경우의 수가 있었는지 파악한다.\n if j < d\n # j < d인 경우, 현재 방문하려는 노드들은 d보다 작은 weight를 가진\n # 경로로 방문하게 된다.\n # 이때 가능한 경우는, 계속 d보다 작은 경로를 이용한 경우와\n # 이전에 d와 같거나 보다 큰 weight를 가진 경로를 방문한 뒤 j < d 인\n # 경로를 이용한 경우이다.\n dp[i][0] = dp[i][0] + dp[i-j][0] # 계속 j < d인 경로를 이용한 경우끼리 합한다.\n dp[i][1] = dp[i][1] + dp[i-j][1] # 이전 한번 이상 j >= d 인 경로를 방문한 경우를 합산한다.\n else\n # j >= d 인 경우, 현재 방문하려는 노드들은 항상 d보다 같거나 큰 weight의\n # 경로를 이용한다.\n # 이때 가능한 경우는,\n # 1) 연이어 j >= d를 만족하는 경로를 방문한 경우\n # 2) 이전까지 j < d 경로를 만났지만 이번에 j >= d 를 처음으로 만난 경우\n # 따라서 dp[i][0] 의 경우에 대해 전혀 계산해줄 필요가 없다.\n # 1과 2의 경우를 모두 dp[i][1]에 더해주면 된다.\n dp[i][1] = dp[i][1] + dp[i-j][0]\n dp[i][1] = dp[i][1] + dp[i-j][1]\n end\n end\nend\n\n# 최종적으로 dp[n] 에는 n까지 합을 구했을 때, weight < d로만 방문한 경우와\n# 한번 이상 weight >= d를 방문한 경우의 숫자 합이 남는다.\n# 물론 숫자가 꽤 크기 때문에, 큰 숫자 구현이 없는 경우에는 계속 modulo 연산을\n# 수행하면서 합을 구한다.\nputs dp[n][1]%MODULO_BASE", "src_uid": "894a58c9bba5eba11b843c5c5ca0025d"} {"source_code": "n, m, a = gets.split.map &:to_i\nr = n/a * (m/a)\nif n%a!=0\n r+=m/a\n n+=a\nend\nif m%a!=0\n r+=n/a\nend\np r\n", "src_uid": "ef971874d8c4da37581336284b688517"} {"source_code": "def main\n w, m = gets.split.map(&:to_i)\n return true if w == 2\n ma = []\n while m > 0\n ma << (m % w)\n m /= w\n end\n i = 0\n while i < ma.size\n if ma[i] >= w - 1\n ma[i] = 0\n ma[i + 1] = 0 if ma[i + 1].nil?\n ma[i + 1] += 1\n elsif ma[i] >= 2\n return false\n end\n i += 1\n end\n true\nend\n\nputs (main ? \"YES\" : \"NO\")", "src_uid": "a74adcf0314692f8ac95f54d165d9582"} {"source_code": "cards = gets.chomp.split.map(&:to_i)\n\nhash = Hash.new { 0 }.tap do |h|\n cards.each { |card| h[card] += 1 }\nend\n\nkeys = hash.keys.select { |key| hash[key] >= 2 }\nkeys.map! do |key|\n hash[key] > 3 ? key * 3 : key * hash[key]\nend\n\nputs cards.inject(0, :+) - (keys.empty? ? 0 : keys.max)\n", "src_uid": "a9c17ce5fd5f39ffd70917127ce3408a"} {"source_code": "l=\"6789TJQKA\";A,B,C,D,E=gets(p).scan(/\\w/);puts A==C&&A!=E||C==E&&l.index(B)>l.index(D)?:YES:\"NO\"\n", "src_uid": "da13bd5a335c7f81c5a963b030655c26"} {"source_code": "gets\nk=[gets.split]\nh={}\nputs (while g=k.pop\nh[g*\"\"]||(h[g*\"\"]=0\nbreak 0if !g[1]\nf=g.pop\n[-1,-3].map{|i|(k<=a[0] || a==[2, 4, 4]\n puts \"YES\"\nelse\n puts \"NO\"\nend\n", "src_uid": "df48af9f5e68cb6efc1214f7138accf9"} {"source_code": "buf=gets.split(\" \")\nn,k=buf[0].to_i,buf[1].to_i\nn-=1\nans=0\nwhile n>0&&k>0\n\tans+=n*2-1\n\tn-=2\n\tk-=1\nend\nputs ans", "src_uid": "ea36ca0a3c336424d5b7e1b4c56947b0"} {"source_code": "h, n = gets.chomp.split.map(&:to_i)\n\nans = 0\noffset = 0\nflag = false\nm = 2 ** h\n\nwhile m != 1\n m /= 2\n if flag ^ (offset + m >= n)\n ans += 1\n flag = !flag\n offset += m unless flag\n else\n ans += 2 * m\n offset += m unless flag\n end\nend\n\nputs ans\n", "src_uid": "3dc25ccb394e2d5ceddc6b3a26cb5781"} {"source_code": "a=gets.chomp.to_i\nb=a%7\nc=(a/7)*2\nif b==0\nputs\"#{c} #{c}\"\nelsif b==1\nputs \"#{c} #{c+1}\"\nelsif b>1 && b<6\nputs \"#{c} #{c+2}\"\nelse\nputs \"#{c+1} #{c+2}\"\nend", "src_uid": "8152daefb04dfa3e1a53f0a501544c35"} {"source_code": "#!/usr/bin/ruby\nn = gets.chomp.to_i\ninp = gets.chomp\ndays = inp.split(' ')\nk = false\nwhile k == false\n\tfor i in 0..6\n\t\tn = n - days[i].to_i\n\t\tif n <= 0\n\t\t\tputs((i+1).to_s)\n\t\t\tk=true;\n\t\t\tbreak\n\t\tend\n\tend\nend\n", "src_uid": "007a779d966e2e9219789d6d9da7002c"} {"source_code": "n = gets.to_i\nif n % 2 == 0\n puts n / 2\nelse\n puts -n + n / 2\nend", "src_uid": "689e7876048ee4eb7479e838c981f068"} {"source_code": "k,b,n,t=gets.split.map{|i| i.to_i};x=1;\nx,n=x*k+b,n-1 until x>t\nputs [0,n+1].max\n", "src_uid": "e2357a1f54757bce77dce625772e4f18"} {"source_code": "M=10**9+7;gets.to_i.times.map{n,k=gets.split.map &:to_i;x=2.pow(n-1,M);p [((2*x).pow(k,M)+x*(x-1).pow(k,M))*((x+1).pow(M-2,M))%M,(x+1).pow(k,M)][n%2]}", "src_uid": "02f5fe43ea60939dd4a53299b5fa0881"} {"source_code": "p 2.step(10,2).map{|k|[*0...k].map{|i|3*10**i}.combination(k/2).map{|a|(?7*k).to_i-a.inject(:+)}}.flatten.reject{|n|n<$m||=gets.to_i}.min\n", "src_uid": "77b5f83cdadf4b0743618a46b646a849"} {"source_code": "def toi(n, x, y)\n\tif x == 0\n\t\treturn y\n\telsif y == n\n\t\treturn n + x\n\telsif x == n\n\t\treturn n + n + (n - y)\n\telse\n\t\treturn n + n + n + (n - x)\n\tend\nend\n\nn, x1, y1, x2, y2 = gets.split.map(&:to_i)\nz1 = toi(n, x1, y1)\nz2 = toi(n, x2, y2)\nm = 4 * n\nd = (z2 - z1 + m) % m\np [d, m - d].min\n", "src_uid": "685fe16c217b5b71eafdb4198822250e"} {"source_code": "s=eval gets.sub(' ','^');99.times{s|=s/2};p s\n", "src_uid": "d90e99d539b16590c17328d79a5921e0"} {"source_code": "n = gets().to_i()\nif(n==0) then puts 0\nelsif((n&1)==1) then puts((n+1)/2)\nelse puts(n+1) end\n\n\n", "src_uid": "236177ff30dafe68295b5d33dc501828"} {"source_code": "#!/usr/bin/ruby\n\ndef read_vector\n gets.split(/\\s+/)\nend\n\ndef read_vector_int\n read_vector.map(&:to_i)\nend\n\nn, l, r, x = read_vector_int\ntasks = read_vector_int\nres = 0\n(1...(1< 0 }.each{ |i| dif.push tasks[i] }\n sum = dif.reduce(:+)\n next unless l <= sum && sum <= r\n next unless dif.min + x <= dif.max\n res += 1\nend\nputs res\n", "src_uid": "0d43104a0de924cdcf8e4aced5aa825d"} {"source_code": "a, b, c, n = gets.split.map(&:to_i)\nx = a + b - c\nputs (a >= c && b >= c && n - x > 0) ? (n - x) : -1\n", "src_uid": "959d56affbe2ff5dd999a7e8729f60ce"} {"source_code": "N = gets.chomp\ndigits = Hash.new(0)\nN.chars do |c|\n digits[c] += 1\nend\n\nnums = ('0'..'9').map{|i| digits[i]}.select{|n| n > 0}\nmax = nums.inject(:*)\n\ncomb = Array.new(20){Array.new(20, 0)}\ncomb[0][0] = 1\n20.times do |i|\n 20.times do |j|\n comb[i][j] += comb[i-1][j-1] if i>0 && j>0\n comb[i][j] += comb[i-1][j] if i>0\n end\nend\n\nans = 0\n(0...max).each do |i|\n use = []\n nums.each do |n|\n use.push(i % n + 1)\n i /= n\n end\n sum = use.inject(:+)\n prod = 1\n use.each do |u|\n prod *= comb[sum][u]\n sum -= u\n end\n ans += prod\n\n if digits['0'] > 0\n use[0] -= 1\n sum = use.inject(:+)\n prod = 1\n use.each do |u|\n prod *= comb[sum][u]\n sum -= u\n end\n ans -= prod\n end\nend\np ans", "src_uid": "7f4e533f49b73cc2b96b4c56847295f2"} {"source_code": "dp=(0..4001).map{0}\nn,*a=gets.split.map{|e| e.to_i}\na.each{|e|\n\t(0..(n-e)).each{|i|\n\t\tif dp[i]>0 || i==0 then\n\t\t\tdp[i+e]=[dp[i+e],dp[i]+1].max\n\t\tend\n\t}\n}\nputs dp[n]\n", "src_uid": "062a171cc3ea717ea95ede9d7a1c3a43"} {"source_code": "a,b = gets.chomp.split(' ').map{|x|x.to_i}\nh = 0\nif b > a\n\tputs 3*b\n\texit\nend\n\nif a > b+1\n\tc = [(a-b)/2, b].min\n\th+= c*6\n\ta = a - 3*c\n\tb = b - c\nend\n\nif b % 2 == 0\n\th+=(b/2)*6\n\ta = a-b\n\tb = 0\nelse\n\th+=(b/2)*6\n\th+=3\n\ta = a - b\n\tb = 0\nend\n\nif a > 0\n\tif h%2 ==1\n\t\th+=1\n\t\ta-=1\n\tend\nend\n\nh+=2*a\n\nputs h\n", "src_uid": "23f2c8cac07403899199abdcfd947a5a"} {"source_code": "c, v0, v1, a, l=gets.split.map &:to_i\nr=0\nt=0\nv=v0\nwhile r0\n r+=v\n t+=1\n v+=a\n v=v1 if v>v1\nend\nputs t\n", "src_uid": "b743110117ce13e2090367fd038d3b50"} {"source_code": "a = gets.chomp.split(/ /).map!{|x|x.to_i}\nb = gets.chomp.split(/ /).map!{|x|x.to_i}\nret = \"NO\"\nfor i in 0..2\n\tif a[i] == b[i]\n\t\tret = \"YES\"\n\tend\nend\n\nputs ret", "src_uid": "91c9dbbceb467d5fd420e92c2919ecb6"} {"source_code": "def fac(n)\n if n == 1\n 1\n else\n n * fac(n-1)\n end\nend\n\nx = gets.to_r\np (fac(x) / x**2 * 2).to_i\n", "src_uid": "ad0985c56a207f76afa2ecd642f56728"} {"source_code": "n = gets.to_i\na = n.times.map{ gets.split.map(&:to_i) }\n\nsum = 0\nm = (n-1)/2\n\nsum += a[m].inject(:+)\nsum += a.transpose[m].inject(:+)\ni = -1\nsum += a.map{|aa| i += 1; aa[i] }.inject(:+)\ni += 1\nsum += a.map{|aa| i -= 1; aa[i] }.inject(:+)\n\np sum -= a[m][m]*3\n", "src_uid": "5ebfad36e56d30c58945c5800139b880"} {"source_code": "p [0,1,2,6,20,70,252,924,3432,12870,48620][gets.to_i]\n", "src_uid": "2f650aae9dfeb02533149ced402b60dc"} {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\ns = gets.chomp.split(//).map(&:to_i).reverse\ncatch :found do\n loop do\n if s.reduce(&:+)%4 == 0\n puts s.reverse.join('')\n throw :found\n else\n i = 0\n s[i] += 1\n loop do\n carry = s[i]/10\n if carry > 0\n s[i] = s[i]%10\n if i == s.length-1\n s << carry\n carry = 0\n else\n i += 1\n s[i] += 1\n end\n else\n break\n end\n end\n end\n end\nend", "src_uid": "bb6fb9516b2c55d1ee47a30d423562d7"} {"source_code": "n, m = gets.strip.split.map(&:to_i)\nary = gets.strip.split.map(&:to_i)\nhsh = {}\nary.each {|ai| hsh[ai] = ((hsh[ai] || 0)+1) }\n\ndef can?(hsh, n, days)\n support_n = 0\n hsh.keys.each do |ai|\n support_n += (hsh[ai]/days)\n end\n support_n >= n\nend\n\nans=0\n105.downto(1).each do |d|\n if can?(hsh, n, d)\n ans=d\n break\n end\nend\nputs ans", "src_uid": "b7ef696a11ff96f2e9c31becc2ff50fe"} {"source_code": "w,h=gets.split.map{|i| i.to_i}\np (w+w%2)*(w/2)*(h+h%2)*(h/2)/4\n", "src_uid": "42454dcf7d073bf12030367eb094eb8c"} {"source_code": "x = gets.chomp\ny = x.downcase\na = y.split('')\n\nfor i in a do\n\tif i != \"a\" and i != \"e\" and i != \"i\" and i != \"o\" and i != \"u\" and i != \"y\"\n\t\tprint \".#{i}\"\n\tend\nend", "src_uid": "db9520e85b3e9186dd3a09ff8d1e8c1b"} {"source_code": "n = gets.strip.to_i\n\ndenominator = n - 1\nnumerator = 1.0\nmax = 0\nmax_numerator = 0\nmax_denominator = 0\ndef gcd(a, b)\n b == 0 ? a : gcd(b, a.modulo(b))\n end\nwhile (numerator < denominator) \n if (numerator % denominator != 0 && numerator/denominator > max && gcd(numerator, denominator) == 1)\n max = numerator/denominator\n max_numerator = numerator\n max_denominator = denominator\n end\n numerator += 1\n denominator -= 1\nend\nputs \"#{max_numerator.to_i} #{max_denominator.to_i}\"", "src_uid": "0af3515ed98d9d01ce00546333e98e77"} {"source_code": "gets\ns = gets\na ={}\ns.each_char do\n |c|\n if c>= 'A' && c<='Z'\n a[c.downcase] = 1;\n else\n a[c] = 1\n end\nend\nres = true\n('a'..'z').each do\n |c|\n if a[c] != 1\n res = false\n end\nend\nif res == true\n puts \"YES\";\nelse\n puts \"NO\";\nend", "src_uid": "f13eba0a0fb86e20495d218fc4ad532d"} {"source_code": "x=0;(2...a=gets.to_i).map{|i|t=a;(x+=t%i;t/=i)while t>0};puts x.to_r/a-=2", "src_uid": "1366732dddecba26db232d6ca8f35fdc"} {"source_code": "w, h = gets.strip.split(\" \").map(&:to_i)\n\ncnt = 0\nwhile w > 0 and h > 0 do\n if w > h then\n k = w / h\n w = w % h\n else \n k = h / w\n h = h % w\n end\n cnt += k\nend\n\np cnt", "src_uid": "ce698a0eb3f5b82de58feb177ce43b83"} {"source_code": "n,a,b,x,y=gets.split.map(&:to_i)\nc=n/a.lcm(b)\na=n/a\nb=n/b\np a*x+b*y-c*[x,y].min", "src_uid": "35d8a9f0d5b5ab22929ec050b55ec769"} {"source_code": "class Matrix2x2\n attr_accessor :a, :b, :c, :d\n def initialize(a=0,b=0,c=0,d=0)\n @a = a\n @b = b\n @c = c\n @d = d\n end\nend\n\ndef mult(x, y)\n z = Matrix2x2.new\n z.a = (x.a*y.a + x.b*y.c)%1000000007\n z.b = (x.a*y.b + x.b*y.d)%1000000007\n z.c = (x.c*y.a + x.d*y.c)%1000000007\n z.d = (x.c*y.b + x.d*y.d)%1000000007\n z\nend\n\ndef expt(a, p)\n if p == 1\n a.clone\n elsif p % 2 == 1\n t = expt(a, p-1)\n mult(a, t)\n else\n t = expt(a, p/2)\n mult(t, t)\n end\nend\n\nn = gets.to_i\nif n == 0\n puts 0\nelse\n a = Matrix2x2.new(0, 3, 1, 2)\n an = expt(a, n)\n puts an.a\nend\n", "src_uid": "77627cc366a22e38da412c3231ac91a8"} {"source_code": "p (gets.to_i(2)<<$_.size-2)%(10**9+7)", "src_uid": "89b51a31e00424edd1385f2120028b9d"} {"source_code": "input = gets.chomp.split(' ').map(&:to_i)\n\nn = input[0]\na = input[1]\nb = input[2]\n\nns = n * 6\n\nif a * b >= ns\n puts a * b\n puts \"#{a} #{b}\"\n\nelse \n mina = a\n minb = b\n min = 2 ** 64\n troca = false\n\n if a > b\n a, b = b, a\n troca = true\n end\n\n a.upto(Math.sqrt(ns)) do |x|\n auxb = ns / x\n if auxb * x < ns\n auxb +=1\n end\n\n if auxb < b\n next\n end\n\n if auxb * x < min\n min = auxb * x\n mina = x\n minb = auxb\n end\n end\n\n puts min\n if a <= b and not troca\n puts \"#{[mina, minb].min} #{[mina, minb].max}\"\n else\n puts \"#{[mina, minb].max} #{[mina, minb ].min}\"\n end\nend\n\n", "src_uid": "6a2a584d36008151d18e5080aea5029c"} {"source_code": "def get_sumator(arr)\n return -1 if arr.length > 3\n case arr.length\n when 1\n return 0\n when 2\n max = arr.max\n min = arr.min\n if (max - min) % 2 == 0\n return (max - min) / 2\n else\n return (max - min)\n end\n when 3\n max = arr[-1]\n min = arr[0]\n # if the average of max and min is the same as\n # the middle one it can be done\n if (max + min) % 2 == 0 && (max + min) / 2 == arr[1]\n return (max - min)/ 2\n else\n return -1\n end\n else\n return -1\n end\nend\n\nn = gets.chomp.to_i\nnums = gets.chomp.split(\" \").map(&:to_i)\nunique_arr = []\nnums.each do |num|\n unique_arr.push(num) if !unique_arr.include?(num)\nend\n\nputs get_sumator(unique_arr.sort)\n", "src_uid": "d486a88939c132848a7efdf257b9b066"} {"source_code": "puts \"0 0 \"+gets", "src_uid": "db46a6b0380df047aa34ea6a8f0f93c1"} {"source_code": "n = gets.to_i\na = gets.split.map { |x| x.to_i }\n\nans = 2333\n1.upto(n - 2) do |i|\n\tb = a[0, i] + a[i + 1, n - i - 1]\n\ttmp = 0\n\t0.upto(n - 3) do |j|\n\t\ttmp = [tmp, b[j + 1] - b[j]].max\n\tend\n\tans = [ans, tmp].min\nend\nputs ans\n", "src_uid": "8a8013f960814040ac4bf229a0bd5437"} {"source_code": "n = gets().to_i\n\nans = 0\nfor i in 1..n\n\tfor j in 1..i-1\n\t\tk = i^j\n\t\tif k <= j and k + j > i\n\t\t\tans += 1\n\t\tend\n\tend\nend\nputs ans\n", "src_uid": "838f2e75fdff0f13f002c0dfff0b2e8d"} {"source_code": "s=gets.to_s.chomp\nif s.index(\"ftp\")==nil||s.index(\"http\")==nil then\n\ts.sub!(\"http\",\"http://\") if s.index(\"ftp\")==nil\n\ts.sub!(\"ftp\",\"ftp://\") if s.index(\"http\")==nil\n\telse\n\t\ts.sub!(\"http\",\"http://\") if s.index(\"http\")s.index(\"ftp\")\nend\nif s.rindex(\"ru\")>s.index(\"ru\") then\n s.reverse!\n s.insert(s.index(\"ur\")+2,'.')\n s.insert(s.index(\"ur.\"),'/') if s.index(\"ur.\")!=0\n s.reverse!\n else\n\ts.insert(s.index(\"ru\"),'.')\n\ts.insert(s.index(\".ru\")+3,'/') if s.index(\".ru\")+3!=s.size\nend\nputs s\n", "src_uid": "4c999b7854a8a08960b6501a90b3bba3"} {"source_code": "x,y,l,r=gets.split(\" \").map(&:to_i)\nxp=[]\nyp=[]\nt=1\nwhile t=r then\n #p [ans,tl,i]\n r-=1 if r==i\n\n ans=[ans,r+1-tl].max\n tl=r+1\n break\n end\n if tl<=i then\n ans=[ans,i-tl].max\n tl=i+1\n end\n #p [ans,i]\nend\n#p [ans,tl]\nans=[ans,r+1-tl].max\n\nputs ans", "src_uid": "68ca8a8730db27ac2230f9fe9b120f5f"} {"source_code": "def square(x) \n x * x\nend\n\ndef triangle(x)\n x * (x + 1) / 2\nend\n\ndef solve(n, x, y, t)\n count = t * t + (t + 1) * (t + 1)\n 4.times do\n count -= square(t - x + 1) if x <= t\n count += triangle(t - x - y + 1) if x + y <= t\n x, y = n + 1 - y, x\n end\n count\nend\n\nn, x, y, c = gets.split.map(&:to_i)\nlow, high = 0, (n - 1) * 2\nwhile low < high\n middle = (low + high) / 2\n if solve(n, x, y, middle) >= c\n high = middle \n else\n low = middle + 1\n end\nend\np high\n", "src_uid": "232c5206ee7c1903556c3625e0b0efc6"} {"source_code": "n=gets.to_i\ns=gets.to_s\np=s.chomp.split(\"\")\nx=1;\n10000.times do\n x*=10;\nend\ndp = Array.new(100,x)\ndp[0]=0;\ny=p.size.to_i\nfor i in 0..y-1 do\n tmp=0\n j=i\n while j 36\n puts -1\nelse\n puts '8'*(k/2)+'4'*(k%2)\nend\n", "src_uid": "0c9973792c1976c5710f88e3520cda4e"} {"source_code": "def binpow(a,n,m)\n return 1%m if n == 0\n if n%2 == 0\n b = binpow(a,n/2,m)\n return (b*b)%m\n end\n return (a*binpow(a,n-1,m))%m\nend\nn,m = gets.split.map &:to_i\n\nputs (binpow(3,n,m)-1)%m\n", "src_uid": "c62ad7c7d1ea7aec058d99223c57d33c"} {"source_code": "n, k = gets.chomp.split(\" \").map(&:to_i)\nans = 1;(ans +=1; k/=2;) while(k%2==0);\np ans\n", "src_uid": "0af400ea8e25b1a36adec4cc08912b71"} {"source_code": "if File.exists?(\"input\")\n $stdin = File.open(\"input\")\n $stdout = File.open(\"output\",\"w\")\nend\n\ntime1 = gets.chomp.split(\":\").map(&:to_i)\ntime2 = gets.chomp.split(\":\").map(&:to_i)\n\nthetime1 = time1[0]*60+time1[1]\nthetime2 = time2[0]*60+time2[1]\n\nave = (thetime1+thetime2)/2\n\ndef pad(i)\n\treturn i.to_s if(i>9)\n\treturn \"0\"+i.to_s\nend\n\nputs pad(ave/60) + \":\" + pad(ave%60)", "src_uid": "f7a32a8325ce97c4c50ce3a5c282ec50"} {"source_code": "class Solver\n\tdef main\n\t\tn = gets.to_i\n\t\tp = []\n\t\tn.times do\n\t\t\tp << Hash[[:x, :y].zip(gets.split.map{ |x| x.to_i })]\n\t\tend\n\t\tif n == 1 then\n\t\t\tputs -1\n\t\telsif n == 2 then\n\t\t\tif p[0][:x] == p[1][:x] || p[0][:y] == p[1][:y] then\n\t\t\t\tputs -1\n\t\t\telse\n\t\t\t\tputs (p[0][:x] - p[1][:x]).abs *\n\t\t\t\t\t(p[0][:y] - p[1][:y]).abs\n\t\t\tend\n\t\telse\n\t\t\tx = p.map{ |poi| poi[:x] }.uniq\n\t\t\ty = p.map{ |poi| poi[:y] }.uniq\n\t\t\tputs (x[1] - x[0]).abs * (y[1] - y[0]).abs\n\t\tend\n\tend\nend\n\nSolver.new.main\n", "src_uid": "ba49b6c001bb472635f14ec62233210e"} {"source_code": "class BallSeq\n attr_accessor :color, :count\n def initialize(color)\n @color = color\n @count = 1\n end\n def to_s()\n @color + \" \" + @count.to_s\n end\nend\n\nclass Solution\n def initialize()\n @n = gets.to_i\n @s = gets.chomp!\n @st = []\n end\n def solve()\n result = 0\n @st << BallSeq.new(@s[0])\n (1...@s.size).each do |i|\n c = @s[i]\n if c == @st.last.color\n @st.last.count += 1\n else\n @st << BallSeq.new(c)\n end\n end\n while @st.size > 1 do\n bseq = @st.shift\n if bseq.color == 'R'\n result += (1 << bseq.count)\n if @st.first.count > 1\n @st.first.count -= 1\n bseq.count += 1\n else\n @st.shift\n below = @st.shift\n bseq.count += (below.nil?? 0 : below.count) + 1\n end\n @st.unshift(bseq)\n else\n result += (1 << bseq.count) - 1\n @st.first.count += bseq.count\n end\n end\n if @st.first.color == 'B'\n result += (1 << @st.first.count) - 1\n end\n puts result\n end\nend\n\nsolution = Solution.new\nsolution.solve\n", "src_uid": "d86a1b5bf9fe9a985f7b030fedd29d58"} {"source_code": "r,c = gets.split(\" \").map(&:to_i)\nmatrix = []\nr.times {\n matrix << gets.chomp.split(\"\")\n}\n\n# puts \"#{matrix}\"\nstraw_row = []\nstraw_col = []\nmatrix.each_with_index do |row,i|\n row.each_with_index do |val, j|\n if val == \"S\"\n straw_row << i\n straw_col << j\n end\n end\nend\n# puts \"#{straw_col} #{straw_row}\"\nrows = (0..r-1).to_a\ncols = (0..c-1).to_a\nrem_rows = rows - straw_row\nrem_cols = cols - straw_col\nres = []\nr.times{\n res << [false] * c\n}\nrem_rows.each{ |i|\n (0..c-1).each {|j|\n res[i][j] = true\n }\n\n}\n\nrem_cols.each{ |j|\n (0..r-1).each {|i|\n res[i][j] = true\n }\n\n}\n\nputs \"#{res.flatten.count(true)}\"", "src_uid": "ebaf7d89c623d006a6f1ffd025892102"} {"source_code": "n,k,*a=$<.read.split.map &:to_i\ns=a.reduce :+\nl=[0]*k\nn.times{|i|l[i%k]+=a[i]}\np [(s-l.max).abs,(s-l.min).abs].max", "src_uid": "6119258322e06fa6146e592c63313df3"} {"source_code": "s = gets\nt = gets\na = [0]\nn = s.size\n(0...n).each do |i|\n (i...n).each do |j|\n cur = 0\n (0...n).each do |k|\n next if i <= k and k <= j\n cur += 1 if cur < t.size and t[cur] == s[k]\n end\n a << j - i + 1 if cur == t.size\n end\nend\nputs a.max", "src_uid": "0fd33e1bdfd6c91feb3bf00a2461603f"} {"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\na,b = inp\nif(a==b)\n puts \"#{a}0 #{b}1\"\nelsif(a == b-1)\n puts \"#{a}9 #{b}0\"\nelsif(a == 9 and b == 1)\n puts \"9\" + \" \" + \"10\"\nelse\n puts -1\nend", "src_uid": "3eff6f044c028146bea5f0dfd2870d23"} {"source_code": "coin_count = gets.to_i\ncoins = gets.split(' ').map(&:to_i)\n\npockets = 0\ncoin_counts = Hash.new {|h, k| h[k] = 0}\n\ncoins.each do |c|\n coin_counts[c] += 1\n pockets = [pockets, coin_counts[c]].max\nend\n\nputs pockets", "src_uid": "f30329023e84b4c50b1b118dc98ae73c"} {"source_code": "n = gets.to_i\nputs (n.to_f / 5).ceil", "src_uid": "4b3d65b1b593829e92c852be213922b6"} {"source_code": "a, b, c = gets.chomp.split(' ')\n\na = a.to_i\nb = b.to_i\nc = c.to_i\n\nfound = false\n\nfor position in 1..1000000\n a = a * 10 if a < b\n if ( a / b ).to_i == c\n print position.to_s + \"\\n\"\n found = true\n break\n end\n a = a % b\nend\n\nprint \"-1\\n\" if not found\n", "src_uid": "0bc7bf67b96e2898cfd8d129ad486910"} {"source_code": "n = gets.to_i\nas = gets.split.map(&:to_i)\n\nas_max = as.max\n\ne = as.inject(:+)\naw = as.map { |a| as_max - a }.inject(:+)\nans = -1\n(as_max..10000).each do |a|\n if aw + (a-as_max)*n > e\n ans = a\n break\n end\nend\nputs ans", "src_uid": "d215b3541d6d728ad01b166aae64faa2"} {"source_code": "n =gets.to_s.chomp\na = n.count(\"4\")\nb = n.count(\"7\")\n\nif a > b or ((b == a) and b !=0 and a!=0)\n puts 4\nelsif b > a\n puts 7\nelsif b == 0 and a == 0\n puts -1\nend\n", "src_uid": "639b8b8d0dc42df46b139f0aeb3a7a0a"} {"source_code": "Mod = (10**9)+7\n\ndef solve n,m,k \n if n == k \n ans = 1\n for i in 0 ... ((n+1)/2)\n ans = ans * m\n ans = ans%Mod\n end\n ans\n elsif k == 1 || n < k\n ans = 1\n for i in 0 ... n\n ans = ans * m\n ans = ans % Mod\n end\n ans\n elsif k%2 == 1\n (m*m)%Mod\n elsif k%2 == 0\n m\n end\nend\n\nwhile line = gets\n a = line.split\n puts solve(a[0].to_i,a[1].to_i,a[2].to_i)\nend\n", "src_uid": "1f9107e8d1d8aebb1f4a1707a6cdeb6d"} {"source_code": "#!/usr/bin/ruby\ng,h,a,b=$<.read.split.map(&:to_i)\nr=(15..1e6).find{|t|\n\tif 10=h\n}\np r ? r/24 : -1\n", "src_uid": "2c39638f07c3d789ba4c323a205487d7"} {"source_code": "#!/usr/bin/ruby\n\na = gets.chomp\n\nb = \"hello\"\n\ncountA = 0\ndem = 0\n\nfor i in (0..(a.length-1)) do\n if a[i] == b[countA]\n countA += 1\n dem += 1\n end\nend\nif dem >= 5\n puts \"YES\"\nelse\n puts \"NO\"\nend\n", "src_uid": "c5d19dc8f2478ee8d9cba8cc2e4cd838"} {"source_code": "def get_paginate(page_count, current_page, proper)\n prev_numbers = []\n index = 1\n proper.times.each do\n number = current_page - index\n break if number.eql?(0)\n\n prev_numbers << number\n index += 1\n end\n next_numbers = []\n index = 1\n proper.times.each do\n number = current_page + index\n break if number > page_count\n\n next_numbers << number\n index += 1\n end\n prev_simbol = nil\n prev_simbol = '<<' if !prev_numbers.empty? && !prev_numbers.min.eql?(1)\n next_simbol = nil\n next_simbol = ' >>' if !next_numbers.empty? && !next_numbers.last.eql?(page_count)\n puts generate_paginate(prev_simbol, next_simbol, prev_numbers, next_numbers, current_page)\nend\n\ndef generate_paginate(prev_simbol, next_simbol, prev_numbers, next_numbers, current_number)\n paginate_string = ''\n paginate_string += prev_simbol unless prev_simbol.nil?\n prev_numbers.sort.each do |number|\n paginate_string += \" #{number}\"\n end\n paginate_string += \" (#{current_number})\"\n next_numbers.sort.each do |number|\n paginate_string += \" #{number}\"\n end\n paginate_string += next_simbol unless next_simbol.nil?\n paginate_string.strip\nend\n\ninput = gets.chomp\n\nintput_array = input.split(' ').map(&:to_i)\n\nget_paginate(intput_array[0], intput_array[1], intput_array[2])\n", "src_uid": "526e2cce272e42a3220e33149b1c9c84"} {"source_code": "p (Math.sqrt(gets.to_f)*2).ceil", "src_uid": "eb8212aec951f8f69b084446da73eaf7"} {"source_code": "code = gets\nkeys = Hash.new\n(0..9).each { |index| keys[gets.chop] = index }\n\npass = \"\"\ncode.scan(/\\d{10}/).each { |key| pass += keys[key].to_s }\nputs pass", "src_uid": "0f4f7ca388dd1b2192436c67f9ac74d9"} {"source_code": "gets\nputs gets.split.map(&:to_i).sort.uniq.each_cons(2).any?{|a,b|2*a>b}?\"YES\":\"NO\"", "src_uid": "ab003ab094931fc105384df9d144131e"} {"source_code": "board = Array.new\n3.times do\n board << gets.split(//)\nend\nfl = false\nsl = false\nfc = 0\nsc = 0\n0.upto(2) do |i|\n 0.upto(2) do |j|\n if board[i][j]==\"X\"\n fc+=1\n elsif board[i][j]==\"0\"\n sc+=1\n end\n end\n if board[i][0]==board[i][1] and board[i][1]==board[i][2]\n if board[i][0]==\"X\"\n fl = true\n elsif board[i][0]==\"0\"\n sl = true\n end\n end\n if board[0][i]==board[1][i] and board[1][i]==board[2][i]\n if board[0][i]==\"X\"\n fl = true\n elsif board[0][i]==\"0\"\n sl = true\n end\n end\nend\nif board[0][0]==board[1][1] and board[1][1]==board[2][2]\n if board[0][0]==\"X\"\n fl = true\n elsif board[0][0]==\"0\"\n sl = true\n end\nend\nif board[2][0]==board[1][1] and board[1][1]==board[0][2]\n if board[2][0]==\"X\"\n fl = true\n elsif board[2][0]==\"0\"\n sl = true\n end\nend\nif fc==sc\n if fl\n puts \"illegal\"\n elsif sl\n puts \"the second player won\"\n else\n puts \"first\"\n end\nelsif fc==sc+1\n if sl\n puts \"illegal\"\n elsif fl\n puts \"the first player won\"\n else\n if fc+sc==9\n puts \"draw\"\n else\n puts \"second\"\n end\n end\nelse\n puts \"illegal\"\nend\n", "src_uid": "892680e26369325fb00d15543a96192c"} {"source_code": "a, b = gets.split(' ').map(&:to_i)\nprint [a,b].min.to_s + ' ' + (((a+b)-2*[a,b].min)/2).to_s", "src_uid": "775766790e91e539c1cfaa5030e5b955"} {"source_code": "k = gets.to_i - 1\n(1..100).each do |d|\n all = d * 9 * 10**(d-1)\n if k >= all\n k -= all\n else\n num = 10**(d-1) + k/d\n puts num.to_s[k%d]\n exit\n end\nend", "src_uid": "1503d761dd4e129fb7c423da390544ff"} {"source_code": "#!/usr/bin/ruby\nrequire 'set'\nrequire 'scanf'\n\nj0, j1 = scanf(\"%d %d\").map(&:to_i)\n\nminutes = 0\nj0, j1 = j1, j0 if j0 > j1\nwhile j0 >= 1 && j1 >= 2\n j0 += 1\n j1 -= 2\n\n j0, j1 = j1, j0 if j0 > j1\n minutes += 1\nend\n\nputs minutes\n", "src_uid": "ba0f9f5f0ad4786b9274c829be587961"} {"source_code": "s = gets.chomp.split(' ')\nn = s[0].to_i\nb = s[1].to_i\np = s[2].to_i\n\nx = 0\ny = n*p\nwhile(n/2>0)\n x = x + (b*2+1)*(n/2)\n n = n/2 + n%2\nend\nputs x.to_s + \" \" + y.to_s\n", "src_uid": "eb815f35e9f29793a120d120968cfe34"} {"source_code": "shift = gets.chomp\nm = gets.chomp\nmessage = m.split(\"\")\n\nkeyboard = ['q','w','e','r','t','y','u','i','o','p','[',']','a','s','d','f','g','h','j','k','l',';','z','x','c','v','b','n','m',',','.','/']\n\nnew_message = []\nif shift == \"R\"\n\tfor i in (0..message.size-1)\n\t\tnew_message[i] = keyboard[keyboard.index(message[i])-1]\n\tend\nelse\n\tfor i in (0..message.size-1)\n\t\tnew_message[i] = keyboard[keyboard.index(message[i])+1]\n\tend\nend\n\nfor i in (0..message.size-1)\n\tprint new_message[i]\nend\n\t", "src_uid": "df49c0c257903516767fdb8ac9c2bfd6"} {"source_code": "h, m = gets.chomp.split(\":\").map do |s|\n s.sub(/^0+(.)/, '\\1').bytes.to_a.map do |s|\n if s <= 57\n s - 48\n else\n s - 55\n end\n end\nend\n\nif h.size == 1 && m.size == 1 && h.first < 24 && m.first < 60\n puts -1\n exit\nend\n\ndef cand(a, n)\n sum = 0\n a.reverse.each_with_index do |i, index|\n sum += i * (n ** index)\n end\n sum\nend\n\nhh = []\nmm = []\n(2..60).each do |n|\n hh << n if h.all?{|i| i < n} && cand(h, n) < 24\n mm << n if m.all?{|i| i < n} && cand(m, n) < 60\nend\nr = hh & mm\nputs r.empty? ? 0 : r.join(\" \")\nexit\n", "src_uid": "c02dfe5b8d9da2818a99c3afbe7a5293"} {"source_code": "n = gets.chomp.to_i\n\nputs (n / 2520).to_i", "src_uid": "8551308e5ff435e0fc507b89a912408a"} {"source_code": "puts \"/\"+gets.split(\"/\").reject{|str| str=~/^\\s*$/}.join(\"/\")", "src_uid": "6c2e658ac3c3d6b0569dd373806fa031"} {"source_code": "def solve(str)\n x,m = str.split.map{|x| x.to_i}\n data = []\n t = 0\n loop do\n t += 1 if x > m\n d = x % m\n if d.zero?\n puts 'Yes'\n return\n end\n x = x + d\n if data.include?(d) || t>20\n puts 'No'\n return\n else\n data << d\n end\n #puts \"x:#{x} d:#{d} m:#{m}\"\n end\nend\n\nputs solve(gets)", "src_uid": "f726133018e2149ec57e113860ec498a"} {"source_code": "a, b=gets.split\na+=b\ni=1\ni+=1 while a[i] && a[i]= 0\n\t\tputs \"YES\"\n\telse\n\t\tputs \"NO\"\n\tend\nend\n", "src_uid": "9edf42c20ddf22a251b84553d7305a7d"} {"source_code": "a = gets.split.map(&:to_i)\nb = [0,0,1,2,0,2,1]\nans = 0\n7.times do |i|\n r = [a[0]/3,a[1]/2,a[2]/2].min\n c = a[0..-1]\n c[0] -= r*3\n c[1] -= r*2\n c[2] -= r*2\n r *= 7\n 7.times do |j|\n if c[b[(i+j)%7]] > 0\n r += 1\n c[b[(i+j)%7]] -= 1\n else\n break\n end\n end\n ans = [ans,r].max\nend\nputs ans", "src_uid": "e17df52cc0615585e4f8f2d31d2daafb"} {"source_code": "hash = {}\n1.upto(100000) do |i|\n hash[(i * (i + 1)) / 2] = true\nend\nn = gets.to_i\nhash.each do |k, v|\n break if k >= n\n if hash[n - k]\n puts \"YES\"\n exit\n end\nend\nputs \"NO\"\n", "src_uid": "245ec0831cd817714a4e5c531bffd099"} {"source_code": "n, k = gets.split.map(&:to_i)\nif k > 43\n puts \"No\"\n exit 0\nend\nputs (1..k).to_a.map{|x| n % x}.uniq.size == k ? \"Yes\" : \"No\"", "src_uid": "5271c707c9c72ef021a0baf762bf3eb2"} {"source_code": "$><<\"%0#{gets=~/$/}b\"%($_.to_i(2)^gets.to_i(2))", "src_uid": "3714b7596a6b48ca5b7a346f60d90549"} {"source_code": "n,m=gets.split.map &:to_i;x=gets.to_i-1\np [n,m].min>2*x ?[n+m-4*x-2,1].max: 0\n", "src_uid": "fa1ef5f9bceeb7266cc597ba8f2161cb"} {"source_code": "class Solver\n\tdef main\n\t\tn = gets.to_i\n\t\tarr = gets.split.map { |x| x.to_i }\n\n\t\tans = 1\n\t\tlast = nil\n\t\tarr.each.with_index do |v, id|\n\t\t\tif v == 1\n\t\t\t\tans *= (id - last) if last != nil\n\t\t\t\tlast = id\n\t\t\tend\n\t\tend\n\t\tans = 0 if arr.count(1) == 0\n\t\tputs ans\n\tend\nend\nSolver.new.main", "src_uid": "58242665476f1c4fa723848ff0ecda98"}