{"lang": "Ruby", "source_code": "a, b, c = gets.split.map(&:to_i)\nputs ( ( c == 0 && b == a ) || ( c != 0 && (b - a) * c >= 0 && (b - a) % c == 0 ) ) ? 'YES' : 'NO'\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "904e8fb2a1ef3e5152fcd773417cfa63", "src_uid": "9edf42c20ddf22a251b84553d7305a7d", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b,c=gets.split.map{|e| e.to_i}\nif a==b then\n\tputs \"YES\"\nelsif c==0 then\n\tif a==b then\n\t\tputs \"YES\"\n\telse\n\t\tputs \"NO\"\n\tend\nelsif c<0 && b0 && ab and c>0\n print(\"NO\")\n exit(0)\nend\nif a= m\n x = n\n y = m\n else\n x = m\n y = n\n end\n \n \n c = y / a\n if y % a != 0\n e = c + 1\n else\n e = c\n end\n \n d = x / a\n if x % a != 0\n f = d + 1\n else\n f = d\n end\nreturn e * f\nend\n\n\ninput = gets.chomp\nnums = input.split\nn = Integer(nums[0])\nm = Integer(nums[1])\na = Integer(nums[2])\n\n\nputs number_of_flagstones(n, m, a)", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "d5941000101f70dda72fdbbac74bdbe8", "src_uid": "ef971874d8c4da37581336284b688517", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,m,a = gets.split\nn,m,a = n.to_f, m.to_f, a.to_f\nputs (( (n/a).ceil)*( (m/a).ceil ))\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "61797f417b0c3553980348f4279f5c31", "src_uid": "ef971874d8c4da37581336284b688517", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,m,a = gets.split.map &:to_i\np -n/a * (-m/a)", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "807ee28a1ade77ee8b06e0179dd88a36", "src_uid": "ef971874d8c4da37581336284b688517", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "k = gets.to_i\nl = gets.to_i\n\nn = 1\n\nloop do\n if k**n == l\n puts \"YES\"\n puts n-1\n break\n elsif k**n > l\n puts \"NO\"\n break\n end\n n += 1\nend\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "c88a6f1f4e3e2fd2800d72d0d0711775", "src_uid": "8ce89b754aa4080e7c3b2c3b10f4be46", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "k = gets.to_i\nl = gets.to_i\na = 1\nc = 0\nwhile a < l\n a *= k\n c += 1\nend\nputs k ** c == l ? \"YES\\n#{c - 1}\" : 'NO'\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "1416c25ec8343f5c0f90387edd9f2eba", "src_uid": "8ce89b754aa4080e7c3b2c3b10f4be46", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "k = gets.to_i\nl = gets.to_i\ni = 0\ny = false\nt = k\ny = true if k == l\nwhile (t < l)\n i += 1\n t *= k\n y = true if t == l\nend\nif y == true\n puts 'YES', i\nelse\n puts 'NO'\nend ", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "e56f6b25a9cfe4fc0c791519764a05b8", "src_uid": "8ce89b754aa4080e7c3b2c3b10f4be46", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\ns = gets.strip\n\ndef mv(l)\n case l\n when 'U' then [0, 1]\n when 'R' then [1, 0]\n when 'L' then [-1, 0]\n when 'D' then [0, -1]\n end\nend\n\nct = 0\n\nfor i in 0...s.size\n x, y = mv(s[i])\n for j in (i+1)...s.size\n dx, dy = mv(s[j])\n x += dx\n y += dy\n if x==0 && y==0\n ct+=1\n end\n end\nend\n\nputs ct", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "a679e185168e538ba5a7b373fd533f9b", "src_uid": "7bd5521531950e2de9a7b0904353184d", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.chomp\ns = gets.chomp\narr = s.split('')\ndef process(arr)\n\tres = 0\n\twhile !arr.empty?\n\t\ttmp = arr.pop\n\t\tarr_tmp = []\n\t\tarr_tmp.push(tmp)\n\t\ti = arr.length-1\n\t\twhile i >= 0\n\t\t\tarr_tmp.push(arr[i])\n\t\t\tu = 0\n\t\t\tr = 0\n\t\t\td = 0\n\t\t\tl = 0\n\t\t\tarr_tmp.each{ |e|\n\t\t\t\tif e == 'U' \n\t\t\t\t\tu += 1\n\t\t\t\telsif e == 'R'\n\t\t\t\t\tr += 1\n\t\t\t\telsif e == 'D'\n\t\t\t\t\td += 1\n\t\t\t\telsif e == 'L'\n\t\t\t\t\tl += 1\n\t\t\t\tend\n\t\t\t}\n\t\t\tres += 1 if u == d && r == l\n\t\t\ti -= 1\n\t\tend\n\tend\n\tputs res\n\t\nend\nprocess(arr)", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "02186dbfa4a1545458f79d8908df8612", "src_uid": "7bd5521531950e2de9a7b0904353184d", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.chomp\ns = gets.chomp\n# s = 'RLRLRLR'\ndef process(s)\n\tres = 0\n\tfor i in 0..s.length-1\n\t\tj = i + 1\n\t\tu = 0\n\t\tr = 0\n\t\td = 0\n\t\tl = 0\n\t\tcase s[i]\n\t\t\twhen 'U'\n\t\t\t\tu += 1\n\t\t\twhen 'R'\n\t\t\t\tr += 1\n\t\t\twhen 'D'\n\t\t\t\td += 1\n\t\t\twhen 'L'\n\t\t\t\tl += 1\n\t\tend\n\t\twhile j < s.length\n\t\t\tcase s[j]\n\t\t\twhen 'U'\n\t\t\t\tu += 1\n\t\t\twhen 'R'\n\t\t\t\tr += 1\n\t\t\twhen 'D'\n\t\t\t\td += 1\n\t\t\twhen 'L'\n\t\t\t\tl += 1\n\t\t\tend\n\t\t\tres += 1 if u == d && r == l\n\t\t\tj += 1\n\t\tend\n\tend\n\tputs res\nend\nprocess(s)", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "d8056a3bca52cd1b15d50b0883ebd31e", "src_uid": "7bd5521531950e2de9a7b0904353184d", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "# frozen_string_literal: true\n\ndef split_watermellow(w)\n w = w.to_i\n return unless valid?(w)\n\n if divisors_are_even?(w)\n puts 'YES'\n else\n puts 'NO'\n end\nend\n\ndef valid?(w)\n w.is_a?(Integer) &&\n w >= 1 &&\n w <= 100\nend\n\ndef divisors_are_even?(w)\n return false if w == 2\n\n divisors = []\n (1..w / 2).each { |x| divisors << ((w % x == 0) && (w / x).even?) }\n divisors.any?(&:trust)\nend\n\nw = gets\nsplit_watermellow(w)\n", "lang_cluster": "Ruby", "tags": ["brute force", "math"], "code_uid": "f2048ddef8b144a2a9edfeea50f09243", "src_uid": "230a3c4d7090401e5fa3c6b9d994cdf2", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.to_i;\n if ((n % 2)==0)\n if ((n/2) >= 2) \n puts \"YES\";\n else\n puts \"NO\";\n end\n else\n puts \"NO\";\n end", "lang_cluster": "Ruby", "tags": ["brute force", "math"], "code_uid": "c164e1f02f9bb7a1a0ed85bad978d058", "src_uid": "230a3c4d7090401e5fa3c6b9d994cdf2", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a = gets.to_i\n\nif (a % 2 == 0) && a != 0 && a != 2\n puts \"YES\"\nelse\n puts \"NO\"\nend", "lang_cluster": "Ruby", "tags": ["brute force", "math"], "code_uid": "6e2467b405f1355c8818979524ebbee7", "src_uid": "230a3c4d7090401e5fa3c6b9d994cdf2", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def check(x1,y1,x2,y2,x3,y3 )\n\ta2=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)\n\tb2=(x2-x3)*(x2-x3)+(y2-y3)*(y2-y3)\n\tc2=(x3-x1)*(x3-x1)+(y3-y1)*(y3-y1)\n\treturn false if a2==0 || b2==0 || c2==0\n\ta2+b2==c2 || b2+c2==a2 || c2+a2==b2\nend\n\na=gets.chomp.split.map(&:to_i)\n\nans=\"NEITHER\"\nif check(a[0],a[1],a[2],a[3],a[4],a[5])\n\tans = \"RIGHT\" \nelse\n\t6.times do |i|\n\t\ta[i] += 1\n\t\tans = \"ALMOST\" if check(a[0],a[1],a[2],a[3],a[4],a[5])\n\t\ta[i] -= 2\n\t\tans = \"ALMOST\" if check(a[0],a[1],a[2],a[3],a[4],a[5])\n\t\ta[i] += 1\n\tend\nend\nputs ans", "lang_cluster": "Ruby", "tags": ["brute force", "geometry"], "code_uid": "16d1895dc6764b879f815182d7787f70", "src_uid": "8324fa542297c21bda1a4aed0bd45a2d", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def dist(x1,y1,x2,y2)\n\tMath.sqrt(((x2-x1)**2) + ((y2-y1)**2))\nend\n\ndef right?(distances)\n\t# puts \"#{distances}\"\n\tdistances.sort!\n\treturn false if distances.any? { |e| e.round ==0 }\n\t(distances[0] ** 2).round + (distances[1] ** 2).round == (distances[2] ** 2).round\nend\n\ndef almost?(points)\n\t(0..points.length-1).each do |ind|\n\t\tx1,y1,x2,y2,x3,y3 = points.map.each_with_index { |e,i| i == ind ? e + 1 : e }\n\t\t# puts x1,y1,x2,y2,x3,y3\n\t\treturn true if right?([dist(x1,y1,x2,y2),dist(x1,y1,x3,y3),dist(x3,y3,x2,y2)])\n\t\t\n\t\tx1,y1,x2,y2,x3,y3 = points.map.each_with_index { |e,i| i == ind ? e - 1 : e }\n\t\t# puts x1,y1,x2,y2,x3,y3\n\t\treturn true if right?([dist(x1,y1,x2,y2),dist(x1,y1,x3,y3),dist(x3,y3,x2,y2)])\n\tend\n\treturn false\nend\n\nx1,y1,x2,y2,x3,y3 = gets.split(\" \").map(&:to_i)\ndistances = [dist(x1,y1,x2,y2),dist(x1,y1,x3,y3),dist(x3,y3,x2,y2)]\ndistances.sort!\n# puts distances\n# puts \"#{(distances[0] ** 2).to_i} #{(distances[1] ** 2).to_i} #{(distances[2] ** 2).to_i}\"\n# puts right?(distances)\nans = \"NEITHER\"\n\nif (right?(distances))\n\tans = \"RIGHT\"\nelsif almost?([x1,y1,x2,y2,x3,y3])\t\t\t\n\tans = \"ALMOST\"\nend\n\n\nputs ans\n\n", "lang_cluster": "Ruby", "tags": ["brute force", "geometry"], "code_uid": "f553fa7aab230e46ac18f76a36506c69", "src_uid": "8324fa542297c21bda1a4aed0bd45a2d", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def isright( x1, y1, x2, y2, x3, y3 )\n\ta2 = (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2)\n\tb2 = (x2-x3)*(x2-x3) + (y2-y3)*(y2-y3)\n\tc2 = (x3-x1)*(x3-x1) + (y3-y1)*(y3-y1)\n\treturn false if a2 == 0 || b2 == 0 || c2 == 0\n\ta2 + b2 == c2 || b2 + c2 == a2 || c2 + a2 == b2\nend\n\ns = gets.chomp\nar = s.split(/ /)\nar.map!{|x| x.to_i }\n\nret = \"NEITHER\"\nif isright(ar[0],ar[1],ar[2],ar[3],ar[4],ar[5])\n\tret = \"RIGHT\" \nelse\n\tfor i in 0..5\n\t\tar[i] += 1\n\t\tif isright(ar[0],ar[1],ar[2],ar[3],ar[4],ar[5])\n\t\t\tret = \"ALMOST\"\n\t\tend\n\t\tar[i] -= 2\n\t\tif isright(ar[0],ar[1],ar[2],ar[3],ar[4],ar[5])\n\t\t\tret = \"ALMOST\"\n\t\tend\n\t\tar[i] += 1\n\tend\nend\nputs ret\n", "lang_cluster": "Ruby", "tags": ["brute force", "geometry"], "code_uid": "b7aafdd69198c652b13f491a8f74e421", "src_uid": "8324fa542297c21bda1a4aed0bd45a2d", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.chomp.to_i\n\nb=1\ni=2\n\nif n!=1\n\tif n%i==0\n\t\tb*=i\n\t\twhile n%i==0\n\t\t\tn/=i\n\t\tend\n\t\ti+=1\n\telse\n\t\ti+=1\n\tend\n\n\tk=(n**0.5).to_i+1\n\n\twhile i<=k\n\t\tif n%i==0\n\t\t\tb*=i\n\t\t\twhile n%i==0\n\t\t\t\tn/=i\n\t\t\tend\n\t\tend\n\t\ti+=2\n\tend\n\tif n!=1\n\t\tb*=n\n\tend\nend\n\nputs b", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "a3d7681482e75a25dd838dc6d6449d25", "src_uid": "6d0da975fa0961acfdbe75f2f29aeb92", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "require 'prime'\nputs gets.to_i.prime_division.map(&:first).inject(1, :*)\n\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "6558ea0698f998b2ddefa032a3c04dce", "src_uid": "6d0da975fa0961acfdbe75f2f29aeb92", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "require 'prime'\nputs gets.to_i.prime_division.map(&:first).inject(1, :*)\n\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "4ce450fdff70b4af48499e519e3909c7", "src_uid": "6d0da975fa0961acfdbe75f2f29aeb92", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\nn = gets.to_i\nthreshold = n/2 # 1 leader, 1 member. this is minimum.\npossible_combinations = 0\nleaders = 0\nwhile n > threshold\n leaders += 1\n n -= 1\n\n if n%leaders == 0\n possible_combinations += 1\n end\nend\nputs possible_combinations", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "042d15699d84443bbd07200e6bde1f9d", "src_uid": "89f6c1659e5addbf909eddedb785d894", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\n\nputs(1.upto(n/2).count { |x| n.modulo(x).zero? && n.div(x) > 1 })\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "593e9b8f5dfd7fd2707dfabe631a6862", "src_uid": "89f6c1659e5addbf909eddedb785d894", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\ns = 0\n(1..n-1).each do |x|\n s += 1 if (n - x)%x == 0\nend\nputs s\n\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "e07fc3e93aaf95bbf7e19cbab63fe98d", "src_uid": "89f6c1659e5addbf909eddedb785d894", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/ruby\na, b, c = *$stdin.gets.split.map(&:to_i)\nputs (a*c.to_r/b).ceil - c\n", "lang_cluster": "Ruby", "tags": ["brute force", "math", "binary search"], "code_uid": "cc49239430b4592fe6ba7c8a67b41346", "src_uid": "7dd098ec3ad5b29ad681787173eba341", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b,c = gets.split.map(&:to_i)\np (c*a-c*b-1)/b+1\n\n", "lang_cluster": "Ruby", "tags": ["brute force", "math", "binary search"], "code_uid": "29dc212e0d78d14e8d2ae51487414900", "src_uid": "7dd098ec3ad5b29ad681787173eba341", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b,c = gets.split.map(&:to_i)\np (c*a-c*b-1)/b+1\n\n", "lang_cluster": "Ruby", "tags": ["brute force", "math", "binary search"], "code_uid": "b9795e1a9a53d8189aadee653f2aed75", "src_uid": "7dd098ec3ad5b29ad681787173eba341", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = gets\ns = s.downcase\nn = gets.to_i\nq = \"\"\ns.chars.each {|ch|\n\tif ch.ord' then\n ct[al.index(r[0])]+=1\nend\nend \n\nif ct[0]!=ct[1]&&ct[1]!=ct[2] then\n hlist=ct.zip(al)\n h= Hash[*hlist.flatten]\n print(\"#{h[0]}#{h[1]}#{h[2]}\\n\")\nelse\n print(\"Impossible\\n\")\nend\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "e232480fe6dcd361fb2ca5915971b770", "src_uid": "97fd9123d0fb511da165b900afbde5dc", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "x=gets(p).split\n[1,2,3].permutation(3){|a,b,c|f=->(_){eval _.downcase}\nif x.all?(&f)\n$><<[*?A..?C].sort_by(&f)*\"\"\nexit\nend}\n$><<:Impossible\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "1e42b559d259e7e75c8aaba09bea7511", "src_uid": "97fd9123d0fb511da165b900afbde5dc", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "x=gets(p).split\n[1,2,3].permutation(3){|a,b,c|f=->(_){eval _.downcase}\nif x.all?(&f)\n$><<[*?A..?C].sort_by(&f)*\"\"\nexit\nend}\n$><<:Impossible", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "c67f64b433baabebb3d09bc328b6e63d", "src_uid": "97fd9123d0fb511da165b900afbde5dc", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "din=gets\ndata = din.split\nmishP=[data[0].to_i*3/10,data[0].to_i-data[0].to_i/250*data[2].to_i].max\nvasyP=[data[1].to_i*3/10,data[1].to_i-data[1].to_i/250*data[3].to_i].max\nputs \"Misha\" if mishP>vasyP\nputs \"Vasya\" if vasyP>mishP\nputs \"Tie\" if vasyP==mishP", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "ef7192676a7893c799010abe7fea3252", "src_uid": "95b19d7569d6b70bd97d46a8541060d0", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b,c,d=gets.split.map(&:to_i)\ne,f=[[a,c],[b,d]].map{|x,y|[75,250-y].max*x}\nputs [:Vasya,:Tie,:Misha][(e<=>f)+1]\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "29ec818d7349e519f43d1322bc785a74", "src_uid": "95b19d7569d6b70bd97d46a8541060d0", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b,c,d=gets.split.map(&:to_i)\ne,f=[[a,c],[b,d]].map{|x,y|[75,250-y].max*x}\nputs [:Vasya,:Tie,:Misha][(e<=>f)+1]", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "d59ead68200cb49849c9033c79a2c494", "src_uid": "95b19d7569d6b70bd97d46a8541060d0", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "MOD=10**9+7\ncnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)\ndef gs() gets.chomp end\ndef gi() gets.to_i end\ndef gsmi() gets.chomp.split.map(&:to_i) end\n\ndef desc(ar) ar.sort{|x,y|y<=>x} end##\ndef min(a,b) a<=b ? a : b end\ndef max(a,b) a>=b ? a : b end\ndef sum(ar) ar.inject(:+) end\n\ndef C(a,b) b==0||a==b ? 1 : (b=a-b if a/20 do\n ar=[]\n prev.each do |pr|\n l.times do |i|\n st=pr[0,i]+pr[(i+1)..-1]\n ar<=1\nend\n\nputs cnt", "lang_cluster": "Ruby", "tags": ["dp", "implementation", "graphs", "shortest paths"], "code_uid": "cda3b18f74bafd4777ad97fe59cfa954", "src_uid": "ae5d21919ecac431ea7507cb1b6dc72b", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "N,k=gets.split.map &:to_i\ns=gets.chomp\ndp=(0..100).map{[0]*101}\ndp[0][0]=1\nN.times{|i|\n\t(1..i+1).each{|j|\n\t\t0.upto(i){|k|dp[i+1][j]+=dp[k][j-1]}\n\t\ti.times{|k|dp[i+1][j]-=dp[k+1][j] if s[i]==s[k]}\n\t}\n}\nSUM=(0..N).map{|i|t=0;(0..N).each{|j|t+=dp[j][i]};t}\nans=0\nN.downto(0){|i|\n\tt=[SUM[i],k].min\n\tk-=t\n\tans+=t*(N-i)\n}\np k>0 ? -1 : ans", "lang_cluster": "Ruby", "tags": ["strings", "dp"], "code_uid": "971fbf7dc9c665380782d61d6461d8f0", "src_uid": "ae5d21919ecac431ea7507cb1b6dc72b", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "p gets.to_i%2", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "fdb6df1ee123586613a5fa104bbebc41", "src_uid": "78e64fdbf59c5ce89d0f0a1d0591f795", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a = gets.to_i\nputs a%2", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "61fe42ae42b1d11c735a8eec0d1ce4c2", "src_uid": "78e64fdbf59c5ce89d0f0a1d0591f795", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "puts gets.to_i % 2", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "9c6e85de5f9cb069c7ded9c4c1a90355", "src_uid": "78e64fdbf59c5ce89d0f0a1d0591f795", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "k,n,w=gets.split.map(&:to_i)\np [w*-~w/2*k-n,0].max", "lang_cluster": "Ruby", "tags": ["brute force", "math", "implementation"], "code_uid": "674afc64cbfa8fc7be670fbf7708cc30", "src_uid": "e87d9798107734a885fd8263e1431347", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "k, n, w = gets.split.map(&:to_i)\nputs [k * (1 + w) * w / 2 - n, 0].max", "lang_cluster": "Ruby", "tags": ["brute force", "math", "implementation"], "code_uid": "1c3dc26d100b581e1d769d552238d925", "src_uid": "e87d9798107734a885fd8263e1431347", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "k,n,w=gets.split.map(&:to_i)\np [w*-~w/2*k-n,0].max", "lang_cluster": "Ruby", "tags": ["brute force", "math", "implementation"], "code_uid": "700c3d088d6092aaf41a8273f9ab3748", "src_uid": "e87d9798107734a885fd8263e1431347", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\na = Array.new(n) { Array.new(n) }\nfor i in 0...n\n\ta[0][i] = 1\n\ta[i][0] = 1\nend\nfor i in 1...n\t\n\tfor j in 1...n\n\t\ta[i][j] = a[i][j - 1] + a[i - 1][j] \n\tend\nend\nputs a[n-1][n-1]\n\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "0e5d2d0c68bf6b7109f71a63e0f828c8", "src_uid": "2f650aae9dfeb02533149ced402b60dc", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "p [0,1,2,6,20,70,252,924,3432,12870,48620][gets.to_i]\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "ede95b31830bf15fdc1282aace9163a8", "src_uid": "2f650aae9dfeb02533149ced402b60dc", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "puts([1, 2, 6, 20, 70, 252, 924, 3432, 12870, 48620][gets().to_i() - 1])", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "94b79c1aef70b4814e37f09fee6ebebd", "src_uid": "2f650aae9dfeb02533149ced402b60dc", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "d = gets.to_i; p ((2*((-1)**(d%2))*d)+((-1)**(d%2))-1)/4", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "a57d9805970f8026dae080eb45b6f4fd", "src_uid": "689e7876048ee4eb7479e838c981f068", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.to_i;puts(n.odd?()?-(n+1)/2:n/2)", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "699c8d6df95d94720411cf1cd0435550", "src_uid": "689e7876048ee4eb7479e838c981f068", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.chomp.to_i\n\n# i = 1\n# count = 0\n# while i <= n\n# \tif i%2 == 0\n# \t\tcount += i\n# \telse\n# \t\tcount -= i\n# \tend\n# \ti += 1\n# end\n\n# i = 1\n# while i <= n\n\n# \ti += 1\n# end\n\n# puts count\n\nif n%2 == 0\n\tputs n / 2\nelse\n\tputs (n/2) - n\nend", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "79f795800c2cd8857954c89d165aa349", "src_uid": "689e7876048ee4eb7479e838c981f068", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "input = gets.chomp\nnums = input.split\na = Integer(nums[0])\nb = Integer(nums[1])\n\ndef sov(x,y)\n if x < y\n return 0\n else\n c = x / y\n d = x % y\n e = c + d\n \n return sov(e,y) + c\n\n end\nend\nif a < b\n puts a\nelsif a == b\n puts a + 1\n\nelse\n puts sov(a,b) + a\nend\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "bffcbe839200014c61b9b66b0cd9bd25", "src_uid": "a349094584d3fdc6b61e39bffe96dece", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b=gets.split.map(&:to_i)\np (a*b-1)/(b-1)", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "0c558a360c98dc6a0a209ab5bf1bcac1", "src_uid": "a349094584d3fdc6b61e39bffe96dece", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a1=gets.chomp\nw=a1.split(\" \")\na=w[0].to_i\nb=w[1].to_i\n\nputs (a*b-1)/(b-1)", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "c0691b0b383e82db8a9cb79236de001e", "src_uid": "a349094584d3fdc6b61e39bffe96dece", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a = Complex(*gets.split.map{ |x| Integer(x) })\nb = Complex(*gets.split.map{ |x| Integer(x) })\nc = Complex(*gets.split.map{ |x| Integer(x) })\n\ncase(((c-a)/(b-a)).polar[1] <=> 0)\nwhen -1\n\tputs 'RIGHT'\nwhen 0\n\tputs 'TOWARDS'\nwhen 1\n\tputs 'LEFT'\nend\n", "lang_cluster": "Ruby", "tags": ["geometry"], "code_uid": "5c5073d5fcfabad4c95cb7d1841efe3e", "src_uid": "f6e132d1969863e9f28c87e5a44c2b69", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["geometry"], "code_uid": "e66be6353bf96bab4de47f1a7b7907f1", "src_uid": "f6e132d1969863e9f28c87e5a44c2b69", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["geometry"], "code_uid": "8ef7ec096e21eb89f6192a40daff8b16", "src_uid": "f6e132d1969863e9f28c87e5a44c2b69", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "puts gets=~/[AEIOUY]\\W*\\?/i? :YES : :NO", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "73c0a2f9ed1d2e87544c47f30c4a3ab4", "src_uid": "dea7eb04e086a4c1b3924eff255b9648", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "puts gets=~/[AEIOUY]\\W*\\?/i? :YES : :NO\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "0684904a662382f2a2d8040cca92a12c", "src_uid": "dea7eb04e086a4c1b3924eff255b9648", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = gets.chop.chop.reverse\n\ns = s.upcase\ns = s.gsub(/[AEIOUY]/, \"*\").gsub(/[BCDFGHJKLMNPQRSTVWXZ]/, \"#\")\ni = s.index(\"*\")\nj = s.index(\"#\")\n\nif i then\n if j then\n if i < j then\n puts \"YES\"\n else\n puts \"NO\"\n end\n else\n puts \"YES\"\n end\nelse\n puts \"NO\"\nend", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "cd7f378b249455bbc8e662221bd14b27", "src_uid": "dea7eb04e086a4c1b3924eff255b9648", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!ruby\n\nn, m = gets.split.map{|e| e.to_i}\n\np = gets.split.map{|e| e.to_i}\n\nans = 9999\n\np.sort!\n\n(m-n+1).times do |i|\n ans = [ans, p[i+n-1]-p[i]].min\nend\n\nputs ans\n", "lang_cluster": "Ruby", "tags": ["greedy"], "code_uid": "a61f4c68384a5c762f05bcdb0c5b2c18", "src_uid": "7830aabb0663e645d54004063746e47f", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def main\n n = gets.chomp.to_i\n fi = gets.chomp.split(\" \").map{ |e| e.to_i }.sort\n\n r = 0\n r_s = fi[n-1]-fi[0]\n i = 1\n k = fi.size - n + 1\n while i=y || ed<=x)\n\t\tans+=1\n\tend\n\tx+=a2\nend\nputs ans", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "b31e615622b8cf69a64c4a885de000f3", "src_uid": "1c4cf1c3cb464a483511a8a61f8685a7", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a, ta = readline.split(' ').collect(&:to_i)\nb, tb = readline.split(' ').collect(&:to_i)\nh, m = readline.split(':').collect(&:to_i)\ntt = h * 60 + m\nat = tt + ta\nif at > 23 * 60 + 59\n at = 23 * 60 + 60\nend\n\nct = 0\nt = 5 * 60\nwhile t < at\n aat = t + tb\n if t < at && aat > tt\n ct += 1\n end\n t += b\nend\n\nputs ct\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "f558d704a043e37fb21f040d8fac478b", "src_uid": "1c4cf1c3cb464a483511a8a61f8685a7", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def ascan; gets.split.map(&:to_i); end\n\nn = gets.to_i\n\nif n == 1\n p 1\nelsif n == 2\n p 2\nelse \n p 1\nend", "lang_cluster": "Ruby", "tags": ["math", "constructive algorithms"], "code_uid": "70b03e3829780bdfed4e1f3e3d29b65b", "src_uid": "c30b372a9cc0df4948dca48ef4c5d80d", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "p gets.to_i==2?2:1", "lang_cluster": "Ruby", "tags": ["math", "constructive algorithms"], "code_uid": "f216b31a479b67fce20846c46577d025", "src_uid": "c30b372a9cc0df4948dca48ef4c5d80d", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\ni = n\ni -= 1\nif( i != 0)\n while(n % i != 1)\n i -= 1\n break if i == 0\n end\nend\nputs n - i", "lang_cluster": "Ruby", "tags": ["math", "constructive algorithms"], "code_uid": "ccc8d8423e107224bb4c55654f339125", "src_uid": "c30b372a9cc0df4948dca48ef4c5d80d", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "p eval(gets.tr\" \",?*)/2", "lang_cluster": "Ruby", "tags": ["math", "greedy"], "code_uid": "4ecd43d4b192e0d469f5cc332549074a", "src_uid": "e840e7bfe83764bee6186fcf92a1b5cd", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "temp = gets.split\na = temp[0].to_i\nb = temp[1].to_i\n\nc = a*b / 2\nputs c", "lang_cluster": "Ruby", "tags": ["math", "greedy"], "code_uid": "8690273207d113f9849651447e63413d", "src_uid": "e840e7bfe83764bee6186fcf92a1b5cd", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "arr = gets.split(\" \")\nm = arr[0].to_i\nn = arr[1].to_i\n\nresult = m * (n / 2)\nif n > 2 and n % 2 == 1\n result = result + (m / 2)\nend\n\nprint result\n", "lang_cluster": "Ruby", "tags": ["math", "greedy"], "code_uid": "34ffb5fa56f838d43cbe1ecae06a66b1", "src_uid": "e840e7bfe83764bee6186fcf92a1b5cd", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "x = gets.to_i\nputs (x/5.0).ceil.to_i\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "f9e12549d1e18e82b36bca571434af43", "src_uid": "4b3d65b1b593829e92c852be213922b6", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "p (gets.to_i+4)/5\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "3ea3178e3d4f9693524f00c96309fdf4", "src_uid": "4b3d65b1b593829e92c852be213922b6", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\nif n % 5 != 0\n puts n / 5 + 1\nelse\n puts n / 5\nend\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "d83f23375aa93fd007e4de05cc0c8854", "src_uid": "4b3d65b1b593829e92c852be213922b6", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "DBG = true\nw1,h1,w2,h2 = gets.split.map{|z| z.to_i}\nputs \"#{2*(w1+h1+h2)+4}\"\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "3e2211faef534a7fc6d4eeebabac2bbb", "src_uid": "b5d44e0041053c996938aadd1b3865f6", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b,c,d = gets.split.map(&:to_i)\np a+2*b+c+2*d+(a-c).abs+4", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "e087c4d856390b00773f380482556991", "src_uid": "b5d44e0041053c996938aadd1b3865f6", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def lscan; gets.split.map(&:to_i); end\n\nw1,h1,w2,h2 = lscan\n\nans = (w2+1)*2+(h1+h2+1)*2\nans += (w1-w2)*2\n\np ans", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "7463d20af01150ce4114d5a42933398a", "src_uid": "b5d44e0041053c996938aadd1b3865f6", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.to_i-3;p 3*4**n*(8+3*n)", "lang_cluster": "Ruby", "tags": ["math", "combinatorics"], "code_uid": "6bce58afb8eaf0d97b584825cbc1d920", "src_uid": "3b02cbb38d0b4ddc1a6467f7647d53a9", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.to_i-3;p 3*4**n*(8+3*n)\n", "lang_cluster": "Ruby", "tags": ["math", "combinatorics"], "code_uid": "aeff152c5e4ad89f024203744591942c", "src_uid": "3b02cbb38d0b4ddc1a6467f7647d53a9", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.to_i-3;p 3*4**n*(8+3*n)", "lang_cluster": "Ruby", "tags": ["math", "combinatorics"], "code_uid": "cfb1a7882250d95b248add144ba8c041", "src_uid": "3b02cbb38d0b4ddc1a6467f7647d53a9", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "m = gets.chomp\nputs m.match(/1{7,}|0{7,}/) ? 'YES' : 'NO'\n", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "1bb95b90c808f56710fa78c0b764a1fa", "src_uid": "ed9a763362abc6ed40356731f1036b38", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "numbers = gets.strip.split('').map(&:to_i)\n\nconsecutive = 1\nnumbers.each_with_index do |number, index|\n if index > 0 && consecutive < 7\n number == numbers[index-1] ? (consecutive += 1) : (consecutive = 1)\n end\nend\n\nconsecutive >= 7 ? (puts 'YES') : (puts 'NO')\n", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "f8d49515b795700973bbff9c6cbfa785", "src_uid": "ed9a763362abc6ed40356731f1036b38", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "x = gets.to_s\n\nif x[\"1111111\"] or x[\"0000000\"]\n\tputs \"YES\"\nelse\n\tputs \"NO\"\nend", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "9f68db6ac818e2ad54d6b59c7a3a2c4b", "src_uid": "ed9a763362abc6ed40356731f1036b38", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/ruby2.0\n\nn = STDIN.readline.to_i\n\ncandidates = []\n\n(1..162).each do |c|\n\tlow, high = 1, n\n\twhile high-low > 1e-6\n\t\tmid = (low+high)/2.0\n\t\tif n/mid - mid > c\n\t\t\tlow = mid\n\t\telse\n\t\t\thigh = mid\n\t\tend\n\tend\n\tx = mid.round\n\tnext if n != c*x + x*x\n\tt = x\n\ttotal = 0\n\twhile t != 0\n\t\ttotal += t%10\n\t\tt /= 10\n\tend\n\tif total == c\n\t\tcandidates.push(x)\n\tend\nend\n\nif candidates.length == 0\n\tputs -1\nelse\n\tputs candidates.sort[0]\nend\n", "lang_cluster": "Ruby", "tags": ["brute force", "math", "binary search"], "code_uid": "c1774510f6a0351b2b1110db9034589a", "src_uid": "e1070ad4383f27399d31b8d0e87def59", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\n\n# while l <= r\n# \tx = l + (r-l)/2\n# \ts = x.to_s.split(\"\").map(&:to_i).inject(0,:+)\n# \tputs x\n# \tif ((x * x) + (s * x) - n) == 0 \n# \t\tans = x\n# \t\tbreak\n# \telse\n# \t\tr = x - 1\n# \tend\n# end\n\n# puts x\nans = false\nmin = n\n(1..90).each do |s|\n\ta = 1\n\tb = s\n\tc = -n\n\td = (b ** 2) - (4 * a * c)\n\tif d >=0\n\t\tr1 = (-b + Math.sqrt(d))/(2 * a)\n\t\tr2 = (-b - Math.sqrt(d))/(2 * a)\n\telsif d == 0\n\t\tr1 = r2 = (-b)/(2 * a)\n\tend\n\t# puts \"sum #{s} roots #{r1} #{r2}\"\n\tif r1 && r2\n\t\tarr = []\n\t\tsum = r1.to_i.to_s.split(\"\").map(&:to_i).inject(0,:+)\n\t\tarr << r1 if r1 % 1 == 0 && r1 > 0 && s == sum\n\t\tsum = r2.to_i.to_s.split(\"\").map(&:to_i).inject(0,:+)\n\t\tarr << r2 if r2 % 1 == 0 && r2 > 0 && s == sum\n\t\tunless arr.empty?\n\t\t# puts \"s #{s} ar #{r1} #{r2}\"\n\t\t\tval = arr.min \n\t\t\tmin = val if val && val < min\n\t\t\t# puts \"#{val}\"\n\t\t\tans = true\n\t\tend\n\tend\nend\nif ans\n\tif min == 999959999\n\t\tputs -1\n\telse\n\tputs min.to_i\n\tend\nelse\n\tputs \"-1\"\nend", "lang_cluster": "Ruby", "tags": ["brute force", "math", "binary search"], "code_uid": "8a6358e3bd532f21889589b09d1f1a42", "src_uid": "e1070ad4383f27399d31b8d0e87def59", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\n\ndef s(x)\n sum = 0\n x.to_s.each_byte { |c| sum += c - 48 }\n sum\nend\n\ndef sqrt(y)\n lo, hi = 1, y\n while lo <= hi do\n mid = (lo + hi) / 2\n return mid if mid * mid == y\n lo = mid + 1 if mid * mid < y\n hi = mid - 1 if mid * mid > y\n end\n return -1\nend\n\nans = []\n\nfor i in 1..81 do\n t = sqrt(i * i + 4 * n) \n if t != -1 then\n if t - i > 0 && (t - i) % 2 == 0 then\n ans << (t - i) / 2 if s((t - i) / 2) == i\n end\n end \nend\n\nif ans.size == 0 then\n puts \"-1\"\nelse\n puts ans.min\nend\n", "lang_cluster": "Ruby", "tags": ["brute force", "math", "binary search"], "code_uid": "0fb31fe3b3b04138ebb2b1887eb564ca", "src_uid": "e1070ad4383f27399d31b8d0e87def59", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["brute force", "dp", "binary search", "implementation", "number theory"], "code_uid": "9b8633e493393f185f60ec1a2896562c", "src_uid": "0a98a6a15e553ce11cb468d3330fc86a", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\n# \uc644\uc804\uc218!\n# \ubaa8\ub4e0 \uc790\ub9ac\uc218\uc758 \ud569\uc744 \ub354\ud558\uba74 10\uc774 \ub41c\ub2e4.\n# \ucd5c\uace0 \uc22b\uc790\ubd80\ud130 \uac70\uafb8\ub85c \ub9cc\ub4e4\uc5b4\uac00\ub294\uac74 \uc26c\uc6b8\uae4c?\n# \uc791\uc740\uc21c\uc11c\ub300\ub85c\ub2c8\uae4c \uc624\ub984\ucc28\uc21c\uc73c\ub85c \ub9cc\ub4e4\uc5b4\uc9c0\uac8c\n# 19, 28, 37, 46, 45, 64, 73, 82, 91 -> 9 \ub4f1\ucc28\uc218\uc5f4\n# 109, 118, 127, 136, 145, 154, 163, 172, 181, 190 -> 9 \ub4f1\ucc28\uc218\uc5f4\n# 208 ......................................., 280,\n# 289 -> 298 -> 307\n# 802 -> 811 -> 820,\n# 901 -> 910\n# 1009 -> ... -> 1090 -> 1099 -> 1108 -> 1117\n# 10009 -> ... -> 19000\n# 10018 -> 10091 -> 10100 -> 10190 -> 10199 -> 10208\n# (0\uc758 \uac1c\uc218\ub9cc\ud07c )\n\nk = gets.to_i\nkc =1\nka = [9, 1] # reversed order\nwhile kc < k\n ka[0] += 9\n carry = 0\n for i in 0...(ka.length)\n ka[i] += carry\n carry = 0\n\n if ka[i] > 9\n ka[i] = ka[i]%10\n carry = 1\n end\n\n break if carry == 0\n end\n\n if carry == 1 # fimally!\n ka.push(1)\n carry = 0\n end\n\n if ka.reduce(:+) == 10\n kc += 1\n #puts \"Reached point: #{kc}\" if kc%100 == 0\n #p \"#{ka}\" if kc%100 == 0\n end\nend\n\nputs ka.reverse.join\n", "lang_cluster": "Ruby", "tags": ["brute force", "dp", "binary search", "implementation", "number theory"], "code_uid": "2ee065bc32f424ccf58a825dfae42eb1", "src_uid": "0a98a6a15e553ce11cb468d3330fc86a", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["math", "number theory"], "code_uid": "f6e240869503d98ceb6096c34fef9f5f", "src_uid": "9c5b6d8a20414d160069010b2965b896", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a, b = gets.chomp.split.map(&:to_i)\nputs a == b ? a : 1\n", "lang_cluster": "Ruby", "tags": ["math", "number theory"], "code_uid": "b9fc686c84166bf4f38ff3477ccb5b22", "src_uid": "9c5b6d8a20414d160069010b2965b896", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def gcd(a, b)\n if a%b == 0\n return b\n else\n return gcd(b, a%b)\n end\nend\n\nfoo = gets\nb, a = foo.chomp.split.map(&:to_i)\n\nif(a == b)\n puts a\nelse\n puts 1\nend\n", "lang_cluster": "Ruby", "tags": ["math", "number theory"], "code_uid": "fcd8834a3573a231c8de3635b61c9801", "src_uid": "9c5b6d8a20414d160069010b2965b896", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "t,s,x = gets.split(\" \").map(&:to_i)\nx -= t\nputs ((x>=0 and x%s < 2 and x!=1) ? \"YES\" :\"NO\")", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "aafff1832fe5620e87bef9211a1acb71", "src_uid": "3baf9d841ff7208c66f6de1b47b0f952", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "I =->{gets.split.map &:to_i}\nt, s, x = I[]\nif x == t || x >= s + t && ((x - t) % s == 0 || ((x - t - 1)) % s == 0)\n print 'YES'\nelse\n print 'NO'\nend\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "439febcf8d7e8534054141dfc1cd20c7", "src_uid": "3baf9d841ff7208c66f6de1b47b0f952", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a=gets.chomp.split(\" \").map{|i| i.to_i}\nif(a[0]==a[2])\nputs \"YES\"\nelsif ((a[2]-a[0])>0 && (a[2]-a[0])/a[1]>0 && ((a[2]-a[0])%a[1]==0 || (a[2]-a[0])%a[1]==1) )\nputs \"YES\"\nelse\nputs \"NO\"\nend\n\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "58bf1baf48ec219a1a2bab30ec16cd51", "src_uid": "3baf9d841ff7208c66f6de1b47b0f952", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "input = STDIN.read.gsub(/\\s/, '')\nSTDOUT.puts input == input.reverse ? \"YES\" : \"NO\"", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "67d2be20e584542a4209724a50e2b498", "src_uid": "6a5fe5fac8a4e3993dc3423180cdd6a9", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a='\n'+gets+gets+gets;puts a.reverse==a ?'YES':'NO'", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "ca78582ae303bb723e6a77f4b0e5491d", "src_uid": "6a5fe5fac8a4e3993dc3423180cdd6a9", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "t=$<.read.chop;puts(t==t.reverse ? :YES:'NO')\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "f662f8114b6ae1b48b7bdcee1b7e2562", "src_uid": "6a5fe5fac8a4e3993dc3423180cdd6a9", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "puts gets.chomp.split('+').sort * '+'", "lang_cluster": "Ruby", "tags": ["sortings", "strings", "implementation", "greedy"], "code_uid": "ad9bc4ec10f329b6cdb6130d3bcc3771", "src_uid": "76c7312733ef9d8278521cf09d3ccbc8", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#puts \"Enter any string\\n\"\ns = gets.chomp.to_s\nl = s.length\n#puts l\nm = l/2\nif l%2 == 1\n m += 1\nend\n#puts m\ni = 0\nj = 0\na = [m]\nwhile i=0\n\t\tc+=1\n\tend\nend\nif c>2\n\tputs \"Yes\"\nelsif c<2\n\t if Math.sqrt(k[0]**2)+Math.sqrt(k[1]**2)==(k[2]/2)\n\t\tputs \"Yes\"\n\telse\n\t\tputs \"No\"\n\tend\t\nelse\n if Math.sqrt(k[0]**2)<=(k[1]/2)+(k[2]/2)\n\t\tputs \"Yes\"\n\telse\n\t\tputs \"No\"\n\tend\t\nend\t", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "af84fe8632d00a4b3bca36ed0b14e5d6", "src_uid": "1db4ba9dc1000e26532bb73336cf12c3", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "old = gets.split(' ')\nsp = gets.split(' ')\nold.map!{|o| o.to_i}\nsp.map!{|s| s.to_i}\npos, neg = 0, 0\nold.size.times do |i|\n a = old[i]\n b = sp[i]\n a>b ? neg+=(a-b)/2 : pos+=(b-a)\nend\nif(neg>=pos)\n puts \"Yes\"\nelse\n puts \"No\"\nend", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "107171d083e1c78b55f5ced742d656f7", "src_uid": "1db4ba9dc1000e26532bb73336cf12c3", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a=gets.chomp.split(\" \")\n0.upto(2){|i| a[i]=a[i].to_i}\nb=gets.chomp.split(\" \")\n0.upto(2){|i| b[i]=b[i].to_i}\nk=[]\n0.upto(2){|i| k[i]= a[i]-b[i]}\nk.sort!\nc=0\nk.each do |i|\n\tif i>=0\n\t\tc+=1\n\tend\nend\nif c>2\n\tputs \"Yes\"\nelsif c<2\n\t if Math.sqrt(k[0]**2)+Math.sqrt(k[1]**2)==(k[2]/2)\n\t\tputs \"Yes\"\n\telse\n\t\tputs \"No\"\n\tend\t\nelse\n if Math.sqrt(k[0]**2)<=(k[1]/2)+(k[2]/2)\n\t\tputs \"Yes\"\n\telse\n\t\tputs \"No\"\n\tend\t\nend\t\n\t", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "6f5094597daa4a027e618ae1ee443961", "src_uid": "1db4ba9dc1000e26532bb73336cf12c3", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "# cook your code here\n\na1,b1=gets.chomp.split\nans = 0;\n\na = a1.to_i\nb = b1.to_i\n\nwhile a>0 and b>0 \n if a>=b \n ans += a/b; \n a %= b;\n else \n ans += b/a; \n b %= a; \n end\nend \n\nputs ans; ", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "9bbc9f3c2035e743a60f92427e2d3fc5", "src_uid": "ce698a0eb3f5b82de58feb177ce43b83", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "b73007047bb89fd4d7362b67df11fc4c", "src_uid": "ce698a0eb3f5b82de58feb177ce43b83", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b = gets.split.map(&:to_i)\ncount = 0\nxx = 0\nwhile b > 0 do \n count += a /b\n xx = a % b\n a = b\n b = xx\nend\n\nputs count\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "23d09b2fe81647e37dd113d39c8e25f8", "src_uid": "ce698a0eb3f5b82de58feb177ce43b83", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "x, y, z = gets.split.map(&:to_i)\n\na, b, c = gets.split.map(&:to_i)\n\nif x <= a and y <= a - x + b and z <= a + b + c - x - y\n puts \"YES\"\nelse\n puts \"NO\"\nend\n\n", "lang_cluster": "Ruby", "tags": ["brute force", "greedy", "implementation"], "code_uid": "3caae13204d509a939200f1c4ac484c7", "src_uid": "d54201591f7284da5e9ce18984439f4e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def ascan; gets.split.map(&:to_i); end\n\nx,y,z = ascan\na,b,c = ascan\n\nif x > a\n puts \"NO\"; exit\nend\na -= x\n\nif y > a + b\n puts \"NO\"; exit\nend\n\nif z > a + b + c - y\n puts \"NO\"; exit\nend\n\nputs \"YES\"\n", "lang_cluster": "Ruby", "tags": ["brute force", "greedy", "implementation"], "code_uid": "30a7ae03e5fe92fe9aeb11428bf42a4a", "src_uid": "d54201591f7284da5e9ce18984439f4e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "x, y, z = gets.split.map(&:to_i)\na, b, c = gets.split.map(&:to_i)\n\nif x <= a && x + y <= a + b && x + y + z <= a + b + c\n puts 'YES'\nelse\n puts 'NO'\nend", "lang_cluster": "Ruby", "tags": ["brute force", "greedy", "implementation"], "code_uid": "cda8207b049e20b2d08470f64edddc34", "src_uid": "d54201591f7284da5e9ce18984439f4e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, k = gets.strip.split.map(&:to_i)\na = gets.strip.split.map(&:to_i)\nans = curr = 0\nn.times do |i|\n break if k <= 0\n curr += a[i]\n given = [curr, 8].min\n curr -= given\n k -= given\n ans += 1\nend\nans = -1 if k > 0\nputs ans\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "2f444e93620194b167da34fb05f82062", "src_uid": "24695b6a2aa573e90f0fe661b0c0bd3a", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "k, a, r = gets.split[1].to_i, 0, -1\ngets.split.each_with_index do |s, i|\n a += s.to_i\n p = [a, k, 8].min\n if (k -= p) == 0\n r = i + 1\n break\n end\n a -= p\nend\nputs r\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "b76092956289e422ef475357311eda52", "src_uid": "24695b6a2aa573e90f0fe661b0c0bd3a", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "6dfab75896c3f414d8a071b128e4ec41", "src_uid": "24695b6a2aa573e90f0fe661b0c0bd3a", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "puts gets.gsub(\"WUB\",' ')", "lang_cluster": "Ruby", "tags": ["strings"], "code_uid": "8934fe456305450410000857d56dd534", "src_uid": "edede580da1395fe459a480f6a0a548d", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "puts gets.gsub\"WUB\",\" \"", "lang_cluster": "Ruby", "tags": ["strings"], "code_uid": "5eabfad8998ba8a71ff3e5bf9b6dc75e", "src_uid": "edede580da1395fe459a480f6a0a548d", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/ruby\n\nwhile s = gets\n\ts.gsub!(/WUB/, \" \")\n\tputs s.gsub(/WUB/, \" \").gsub(/^ */, \"\").gsub(/ *$/, \"\").gsub(/ +/, \" \")\nend\n", "lang_cluster": "Ruby", "tags": ["strings"], "code_uid": "29bfa6e5c3c80f67a2098322932859de", "src_uid": "edede580da1395fe459a480f6a0a548d", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = gets.strip\nnxt = 'a'\ncount = Array.new(26, 0)\nvalid = true\ns.each_char do |c|\n if c == nxt\n count[c.ord - 'a'.ord] += 1\n nxt = (nxt.ord + 1).chr\n else\n if count[c.ord - 'a'.ord] == 0\n valid = false\n break\n end\n end\nend\nif !valid\n puts \"NO\"\nelse\n puts \"YES\"\nend\n", "lang_cluster": "Ruby", "tags": ["greedy", "strings", "implementation"], "code_uid": "95226c154d983b768d9813152038a2e7", "src_uid": "c4551f66a781b174f95865fa254ca972", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "sticks = gets.split(\" \")\nnumbers = []\nfor i in 0..sticks.size-1\n\t\tnumber = sticks[i].to_i\n\t\tnumbers< sorted[0].to_i || sorted[3].to_i + sorted[2].to_i > sorted[0].to_i || sorted[1].to_i + sorted[3].to_i > sorted[0].to_i || sorted[2].to_i + sorted[3].to_i > sorted[1].to_i \n\tres = \"TRIANGLE\"\nelsif sorted[1].to_i + sorted[2].to_i == sorted[0].to_i || sorted[3].to_i + sorted[2].to_i == sorted[0].to_i || sorted[1].to_i + sorted[3].to_i == sorted[0].to_i || sorted[2].to_i + sorted[3].to_i == sorted[1].to_i\n\tres = \"SEGMENT\"\nelse\n\tres = \"IMPOSSIBLE\"\nend\nputs res", "lang_cluster": "Ruby", "tags": ["brute force", "geometry"], "code_uid": "3233a5be0817c049c32956e52e213394", "src_uid": "8f5df9a41e6e100aa65b9fc1d26e447a", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b,c,d = gets.split(/\\s/).map{|x| x.to_i}\ntr = false\nseg = false\n\n[[a,b,c],\n [a,b,d],\n [b,c,d],\n [a,c,d]].each do |x,y,z|\n p = (x+y+z)/2.0\n f = p*(p-x)*(p-y)*(p-z)\n if f > 0.0\n tr = true\n break\n elsif f == 0.0\n seg = true\n end\nend\n\nif tr\n puts \"TRIANGLE\"\nelsif seg\n puts \"SEGMENT\"\nelse\n puts \"IMPOSSIBLE\"\nend\n", "lang_cluster": "Ruby", "tags": ["brute force", "geometry"], "code_uid": "72f724384ad7b2df8d2b08e145f4821b", "src_uid": "8f5df9a41e6e100aa65b9fc1d26e447a", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def isTriangle?(a, b, c)\n isTriangle = (a <= b + c and b <= a + c and c <= a + b)\n return isTriangle\nend\n\ndef isDegenerate?(a, b, c)\n isDegenerate = (a == b + c or b == a + c or c == a + b)\n return isDegenerate\nend\n\nCASES = [\n [0, 1, 2], [0, 1, 3], [0, 2, 3], [1, 2, 3]\n]\n\npoints = []\npoints = gets.chomp.split(\" \").map(&:to_i)\n\n# File.open(\"input2\", \"r\") do |file|\n# points = file.readline.split(\" \").map(&:to_i)\n# end\n\ncanFormDegenerate = false\ncanFormTriangle = false\n\nCASES.each do |cs|\n if isTriangle?(points[cs[0]], points[cs[1]], points[cs[2]])\n if isDegenerate?(points[cs[0]], points[cs[1]], points[cs[2]])\n canFormDegenerate = true\n else\n canFormTriangle = true\n end\n end\n\n break if canFormTriangle\nend\n\nif canFormTriangle\n puts \"TRIANGLE\"\nelsif canFormDegenerate\n puts \"SEGMENT\"\nelse\n puts \"IMPOSSIBLE\"\nend\n\n\n\n", "lang_cluster": "Ruby", "tags": ["brute force", "geometry"], "code_uid": "a62d9b9628b8ca9c68c8c229d723ff02", "src_uid": "8f5df9a41e6e100aa65b9fc1d26e447a", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b=gets.split.map{|e| e.to_i}\nx=gets.split.map{|e| e.to_i}\n\nb-=1\nans=0\na.times{|i|\n\ti=i+1\n\tl1=false\n\tr1=false\n\tc1=0\n\tif b-i<0 then\n\t\tl1=true\n\telse\n\t\tc1+=x[b-i]\n\tend\n\tif b+i>=a then\n\t\tr1=true\n\telse\n\t\tc1+=x[b+i]\n\tend\n\tif l1==true && r1==true then\n\t\tbreak\n\telsif l1==true && r1==false then\n\t\tans+=c1\n\telsif l1==false && r1==true then\n\t\tans+=c1\n\telse\n\t\tans+=c1 if c1==2\n\tend\n}\nputs ans+x[b]\n\n", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation"], "code_uid": "5ce65f18e6d0f98a5845757512a807ad", "src_uid": "4840d571d4ce6e1096bb678b6c100ae5", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/ruby\nn,k,*a=$<.read.split.map(&:to_i)\nk-=1\nr=[]\nn.times{|i|\n\th=[]\n\tif k-i>=0\n\t\th.push(a[k-i]==0 ? nil : k-i)\n\tend\n\tif k+i mi\nend\nputs ans\n", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation"], "code_uid": "2f351618db112108c3726b2e7850df7c", "src_uid": "4840d571d4ce6e1096bb678b6c100ae5", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = gets.chomp\nif s.length < 5 or s.scan(/[a-z]/).length < 1 or s.scan(/[A-Z]/).length < 1 or s.scan(/\\d/).length < 1\n puts 'Too weak'\nelse\n puts 'Correct'\nend", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "570d97ff8eadde98561d4cbc74827757", "src_uid": "42a964b01e269491975965860ec92be7", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "pw = gets.chomp\ncheck = true\ncheck = false if pw.length < 5\ncheck = false if not pw.match(/[A-Z]/)\ncheck = false if not pw.match(/[a-z]/)\ncheck = false if not pw.match(/[0-9]/)\nif check\n puts \"Correct\"\nelse\n puts \"Too weak\"\nend\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "2a822675c8c0c8b5b7bcf2db2dd906c6", "src_uid": "42a964b01e269491975965860ec92be7", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = gets.chomp\nlength = s.length > 4\nlarge = false\nsmall = false\ndigit = false\ns.each_char do |x|\n\tlarge = true if (\"A\" .. \"Z\").include? x\n\tsmall = true if (\"a\" .. \"z\").include? x\n\tdigit = true if (\"0\" .. \"9\").include? x\nend\nputs length && large && small && digit ? \"Correct\" : \"Too weak\"\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "b9fb1d7b24686cdaecdfef43b3b3c10b", "src_uid": "42a964b01e269491975965860ec92be7", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "puts gets.to_i.to_s(2).count('1')", "lang_cluster": "Ruby", "tags": ["bitmasks"], "code_uid": "4e9e8cb5194656b0ceeee3eba7f79311", "src_uid": "03e4482d53a059134676f431be4c16d2", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a = gets.to_i\nsum = 0\n(0..48).each {|n| sum += a[n]}\nputs sum", "lang_cluster": "Ruby", "tags": ["bitmasks"], "code_uid": "a8316eb1a975ac1717d3287a3ba68be3", "src_uid": "03e4482d53a059134676f431be4c16d2", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.chomp.to_i\n\nc = 0\n\nwhile n > 1\n\n if n % 2 == 0\n n /= 2\n else\n c += 1\n n -= 1\n end\nend\n\nputs c + 1\n", "lang_cluster": "Ruby", "tags": ["bitmasks"], "code_uid": "c74972e7efb780fe9b1ab9e460e5dd3b", "src_uid": "03e4482d53a059134676f431be4c16d2", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "puts Math.log2(gets.to_i+1).ceil", "lang_cluster": "Ruby", "tags": ["math", "greedy", "constructive algorithms"], "code_uid": "a377cf668cf3eb4f66f0114a9c221010", "src_uid": "95cb79597443461085e62d974d67a9a0", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "puts gets.chomp.to_i.to_s(2).length", "lang_cluster": "Ruby", "tags": ["math", "greedy", "constructive algorithms"], "code_uid": "6c8e1dc8a143fc3b668568629eac7135", "src_uid": "95cb79597443461085e62d974d67a9a0", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "pages, week, c, i, d = gets.to_i, gets.split.map(&:to_i), 0, 0, nil\n\nloop do\n d = i % 7\n c += week[d]\n i += 1\n break if pages <= c\nend\n\nprint d + 1", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "7ab4d0e940776c891661a14a549b2378", "src_uid": "007a779d966e2e9219789d6d9da7002c", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = STDIN.readline.to_i\ndays = STDIN.readline.split.map {|s| s.to_i }\npos = 0\nwhile true\n n -= days[pos]\n if n <= 0\n puts pos+1\n exit\n end\n pos = (pos+1)%days.length\nend\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "299d89989c3fcc308d31fbe76fe84d26", "src_uid": "007a779d966e2e9219789d6d9da7002c", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "total = Integer(gets)\nw_pace = 0\npaces = gets.split.map { |x| \n\tn = Integer(x)\n\tw_pace += n \n\tn\n}\n\nwhile (total - w_pace > 0) do\n\ttotal -= w_pace\nend\nday = 0\npaces.each_with_index { |n, i|\n\ttotal -= n\n\tif (total <= 0)\n\t\tday = i + 1\n\t\tbreak\n\tend\n}\nputs day\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "d1c9752bccb2da0a4691bb949561e77d", "src_uid": "007a779d966e2e9219789d6d9da7002c", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,m,a,b = gets.split(\" \").map(&:to_i)\nno_of_special_tickets = n / m\none_way = n % m\nputs [one_way * a + no_of_special_tickets * b, (n.to_f/m).ceil * b,n * a].min\n#min(all sp,all one way,mix)", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "a3377f310ef754bc3a3581440b8bc314", "src_uid": "faa343ad6028c5a069857a38fa19bb24", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,m,a,b=gets.split.map &:to_i\np [n*a,n/m*b+n%m*a,n/m*b+b].min\n\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "7ea424209198a0278f379258cfbd1455", "src_uid": "faa343ad6028c5a069857a38fa19bb24", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n_m_a_b = gets.split\nn = n_m_a_b[0].to_i\nm = n_m_a_b[1].to_i\na = n_m_a_b[2].to_f\nb = n_m_a_b[3].to_f\n\nif b / m < a\n cost = n / m * b + [n % m * a, b ].min\n puts cost.to_i\nelse\n cost = n * a \n puts cost.to_i\nend", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "e5ddea93625b14e7dee3febc1a7cf0e0", "src_uid": "faa343ad6028c5a069857a38fa19bb24", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "array = gets.split(/:/)\n\n h = array[0].to_f\n m = array[1].to_f\n\nif h >= 12\n h -= 12\nend\n\nh = 360 / 12 * h\n\nm = 360 / 60 * m\n\nh += 15 * m / 180\n\nprint h, \" \", m.to_i, \"\\n\"\n", "lang_cluster": "Ruby", "tags": ["math", "geometry"], "code_uid": "06f4319a4b2a6b6eb83fe66e2903d93f", "src_uid": "175dc0bdb5c9513feb49be6644d0d150", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "input = gets.split(\":\").map {|e| e.to_f}\ninput[0]-=12 if input[0] >= 12\nangle = []\nangle[0] = input[0] * 360/12 + input[1] * 360/12/60\nangle[1] = input[1] * 360/60\n\nputs angle.join ' '\n", "lang_cluster": "Ruby", "tags": ["math", "geometry"], "code_uid": "a873ccd7a1b105104d6953e56a551b57", "src_uid": "175dc0bdb5c9513feb49be6644d0d150", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "hour, minute = gets.split(\":\").map(&:to_i)\nprint (hour*30)%360 + minute/2\nprint \".5\" if minute%2 != 0\nprint \" \", minute*6", "lang_cluster": "Ruby", "tags": ["math", "geometry"], "code_uid": "8da43c4f2530ba3d228291572b627744", "src_uid": "175dc0bdb5c9513feb49be6644d0d150", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.to_i-1;n=n-5>>1until n<5;puts %w[Sheldon Leonard Penny Rajesh Howard][n]", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "f350cb63a37ae66584c88b8d220b3fc5", "src_uid": "023b169765e81d896cdc1184e5a82b22", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\na = [0]\ncount = 0\nnames = %w{Sheldon Leonard Penny Rajesh Howard}\nfor i in 1..2*n\n a[i] = (2**i - 1) * 5\n if a[i-1] < n and a[i] >= n\n n -= count + 1\n print names[n/2**(i-1)]\n break\n else\n count += 5*2**(i-1)\n end\nend\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "0e2386f712cc3acd40ea2d549a6bfd9e", "src_uid": "023b169765e81d896cdc1184e5a82b22", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "QUEUE = [\"Sheldon\", \"Leonard\", \"Penny\", \"Rajesh\", \"Howard\"]\n\nn = gets().to_i\n\ngeneration = (Math.log2(n/5.to_f + 1)/Math.log2(2)).ceil\nfirst_index_of_generation = 5 * (2 ** (generation - 1) - 1)\ngeneration_group_size = 2 ** (generation - 1) \n\nindex = 1\nwhile n > generation_group_size * index + first_index_of_generation\n index += 1\nend\n\nputs QUEUE[index-1]", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "91a0c4ad0ea13ad0aa7876fd6edcd50b", "src_uid": "023b169765e81d896cdc1184e5a82b22", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def pos(x,y)\n if x > 1 && y > 1 then\n return true\n elsif x > 0 && y > 11 then\n return true\n elsif y > 21 then\n return true\n end\n return false\nend\n\nx,y = gets.split.map{|i| i.to_i}\n\nk = true\nt = true\nwhile k do\n if t then\n if k = pos(x,y) then\n if x > 1 then\n x -= 2\n y -= 2\n elsif x > 0 then\n x -= 1\n y -= 12\n else\n y -= 22\n end\n else\n name = \"Hanako\"\n end\n else\n if k = pos(x,y) then\n if y > 21 then\n y -= 22\n elsif y > 11 then\n y -= 12\n x -= 1\n else\n x -= 2\n y -= 2\n end\n else\n name = \"Ciel\"\n end\n end\n t = !t\nend\n\nputs name", "lang_cluster": "Ruby", "tags": ["greedy"], "code_uid": "091b45cc34944d283d760ddf5f561ac0", "src_uid": "8ffee18bbc4bb281027f91193002b7f5", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "input=gets.split.map(&:to_i)\nx=input[0]\ny=input[1]\nturn=0\nname=[\"Ciel\",\"Hanako\"];\nloop do\n if x*100+y*10<220 || y<2 then\n puts name[1-turn]\n break\n end\n if turn==0 then\n 2.downto(0){|i|\n if i<=x then\n x-=i\n y-=22-10*i\n break\n end\n }\n else\n 22.downto(0){|i|\n if i<=y then\n if (220-i*10) % 100 ==0 then\n if (220-i*10)/100<=x then\n y-=i\n x-=(220-i*10)/100\n break\n end\n end\n end\n }\n end\n\n turn=1-turn\nend", "lang_cluster": "Ruby", "tags": ["greedy"], "code_uid": "0892b776b6d518fa32ee5934b39c8e87", "src_uid": "8ffee18bbc4bb281027f91193002b7f5", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.split\nx = n[0].to_i\ny = n[1].to_i\n\nloop{\n if x >= 2 && y >= 2\n x -= 2\n y -= 2\n elsif x == 1 && y >= 12\n x -= 1\n y -= 12\n elsif x == 0 && y >= 22\n y -= 22\n else\n puts \"Hanako\"\n break\n end\n\n if y >= 22\n y -= 22\n elsif y >= 12 && x >= 1\n y -= 12\n x -= 1\n elsif y >= 2 && x >= 2\n y -= 2\n x -= 2\n else\n puts \"Ciel\"\n break\n end\n}\n", "lang_cluster": "Ruby", "tags": ["greedy"], "code_uid": "34baf40ea31e844bd7be70cf467d42e7", "src_uid": "8ffee18bbc4bb281027f91193002b7f5", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "input = $stdin.readline.split(' ')\nn = input[0].to_i; x=input[1].to_i; y=input[2].to_i\n\nif n%2==0 then\n center = (n/2)\n if (x==center or x==center+1) and (y==center or y==center+1) then puts \"NO\"\n else puts \"YES\" end\nelse\n puts \"NO\"\nend\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "3ff22611efc87752522ab4b95396ca2a", "src_uid": "dc891d57bcdad3108dcb4ccf9c798789", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,x,y=gets.split.map &:to_i;puts x%(q=2+n/=2) z) then\n\t\tif (dist == 7) then\n\t\t\tkiten = z\n\t\telse\n\t\t\tkiten = x\n\t\tend\t\n\telse\n\t\tif (dist == 7) then\n\t\t\tkiten = x\n\t\telse\n\t\t\tkiten = z\n\t\tend\t\n\tend\n\n\tchk = (y - kiten)\n\tchk += 12 if chk < 0\n\t\n\treturn 1 if chk == 4\n\treturn 2 if chk == 3\n\treturn 0\nend\n\nchord = [\"C\", \"C#\", \"D\", \"D#\", \"E\", \"F\", \"F#\", \"G\", \"G#\", \"A\", \"B\", \"H\"]\nar = gets.chomp.split(/ /).map!{|x| chord.index(x)}\n\nret = check(ar[0],ar[1],ar[2])\nret = check(ar[0],ar[2],ar[1]) if ret == 0\nret = check(ar[1],ar[0],ar[2]) if ret == 0\n\nputs \"strange\" if ret == 0\nputs \"major\" if ret == 1\nputs \"minor\" if ret == 2\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "f53d0e7ce36aaaa6cc2e6dfe001553da", "src_uid": "6aa83c2f6e095848bc63aba7d013aa58", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/env ruby\n# -*- coding: utf-8 -*-\n\ndef getis;gets.split.map(&:to_i);end\ndef log(m); warn(m); end\n\nnotes = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'B', 'H']\n\nins = gets.chomp.split(' ')\nns = ins.map{|i| notes.index(i) }.sort\n\ndivs=[]\ndivs << [ns[1]-ns[0], ns[2]-ns[1]]\ndivs << [ns[2]-ns[1], ns[0]-ns[2]]\ndivs << [ns[0]-ns[2], ns[1]-ns[0]]\ndivs.map!{ |x| x.map{ |y| y %=notes.size} }\n\nif divs.include? [4,3]\n puts \"major\"\nelsif divs.include? [3, 4]\n puts \"minor\"\nelse\n puts \"strange\"\nend\n\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "ccebea94dc1f88d33f3c9fe37a44ac10", "src_uid": "6aa83c2f6e095848bc63aba7d013aa58", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def check(x,y,z)\n\treturn 0 if x == z || x==y || y==z\n\tdist = (z - x).abs\n\treturn 0 if (dist != 5) && (dist != 7)\n\n\tman = (x>z) ? ((dist==7) ? z : x) : ((dist==7) ? x : z)\n\n\tchk = (y - man)\n\tchk += 12 if chk < 0\n\t\n\treturn 1 if chk == 4\n\treturn 2 if chk == 3\n\treturn 0\nend\n\nchords=[\"C\",\"C#\",\"D\",\"D#\",\"E\",\"F\",\"F#\",\"G\",\"G#\",\"A\",\"B\",\"H\"]\nar = gets.chomp.split.map!{|x| chords.index(x)}\n\nchk=check(ar[0],ar[1],ar[2])\nchk=check(ar[0],ar[2],ar[1]) if chk == 0\nchk=check(ar[1],ar[0],ar[2]) if chk == 0\n\nputs (chk==0) ? \"strange\" : ((chk==1)? \"major\" : \"minor\")", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "7813bf1c81123ce6d5604fc78b812e9b", "src_uid": "6aa83c2f6e095848bc63aba7d013aa58", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "puts gets.chomp =~ /.*h.*e.*l.*l.*o.*/ ? \"YES\" : \"NO\"", "lang_cluster": "Ruby", "tags": ["greedy", "strings"], "code_uid": "aa6b760a94ab3fe11fdd88d19c9c80b0", "src_uid": "c5d19dc8f2478ee8d9cba8cc2e4cd838", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = gets.chomp\nputs s[/h.*e.*l.*l.*o/].nil? ? 'NO' : 'YES'", "lang_cluster": "Ruby", "tags": ["greedy", "strings"], "code_uid": "7fa2683bd2928b950dfda16649bba404", "src_uid": "c5d19dc8f2478ee8d9cba8cc2e4cd838", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "stringArr = gets.chomp.split('')\n\nhFlag = false\neFlag = false\nlFlag = false\nl2Flag = false\noFlag = false\n\nfoundIndex = 0\n\nuntil foundIndex == stringArr.length\n\tif stringArr[foundIndex] == 'h' && !hFlag\n\t\thFlag = true\n\tend\n\n\tif stringArr[foundIndex] == 'e' && hFlag\n\t\teFlag = true\n\tend\n\n\tif stringArr[foundIndex] == 'l' && lFlag\n\t\tl2Flag = true\n\tend\n\n\tif stringArr[foundIndex] == 'l' && eFlag\n\t\tlFlag = true\n\tend\n\n\tif stringArr[foundIndex] == 'o' && l2Flag\n\t\toFlag = true\n\tend\n\tfoundIndex += 1\nend\n\nif hFlag && eFlag && lFlag && l2Flag && oFlag\n\tputs \"YES\"\nelse\n\tputs \"NO\"\nend", "lang_cluster": "Ruby", "tags": ["greedy", "strings"], "code_uid": "a5324ccf26ccb233a333f4d30412f538", "src_uid": "c5d19dc8f2478ee8d9cba8cc2e4cd838", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "z=0;n,m=gets.split.map &:to_i;m.times.to_a.map{gets.split.map(&:to_i).reverse}.sort.reverse.each{|x,y|t=[n,y].min;n-=t;z+=x*t;};p z", "lang_cluster": "Ruby", "tags": ["sortings", "implementation", "greedy"], "code_uid": "c2ba05cb7f14955f2682f3dc3282b91e", "src_uid": "c052d85e402691b05e494b5283d62679", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "\nn,m=gets.split.map(&:to_i)\ncnt=Array.new(11,0)\nm.times{\n a,b=gets.split.map(&:to_i)\n cnt[b]+=a\n}\nans=0\n10.downto(1){|i|\n if(n>=cnt[i]) then\n n-=cnt[i]\n ans+=cnt[i]*i\n else\n ans+=n*i\n n=0\n end\n}\np ans\n", "lang_cluster": "Ruby", "tags": ["sortings", "implementation", "greedy"], "code_uid": "c8fbab595fcf75d66e66bed2d2a3d3cc", "src_uid": "c052d85e402691b05e494b5283d62679", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "tab=[]; result=0\nn, m = gets.split.map(&:to_i)\nm.times{tab << gets.split.map(&:to_i)}\ntab.sort!{|a, b| a[1] <=> b[1]}.reverse!\ntab.each do |x|\n\tresult += [x[0], n].min * x[1]\n\tn -= [x[0], n].min\nend\n\nputs result\n\n\n\n\n\n\n", "lang_cluster": "Ruby", "tags": ["sortings", "implementation", "greedy"], "code_uid": "eba0f359db8b805feb21c5e31210f245", "src_uid": "c052d85e402691b05e494b5283d62679", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "d22a4001382d89dafd64ddc2a3f9e542", "src_uid": "a49ca177b2f1f9d5341462a38a25d8b7", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = Integer(gets.chomp)\n\ndef unit(x)\n if x == 1\n return \"one\"\n elsif x == 2\n return \"two\"\n elsif x == 3\n return \"three\"\n elsif x == 4\n return \"four\"\n elsif x == 5\n return \"five\"\n elsif x == 6\n return \"six\"\n elsif x == 7\n return \"seven\"\n elsif x == 8\n return \"eight\"\n elsif x == 9\n return \"nine\"\n end\nend\n\ndef teen(x)\n if x == 11\n print \"eleven\"\n elsif x == 12\n print \"twelve\"\n elsif x == 13\n print \"thirteen\"\n elsif x == 14\n print \"fourteen\"\n elsif x == 15\n print \"fifteen\"\n elsif x == 16\n print \"sixteen\"\n elsif x == 17\n print \"seventeen\"\n elsif x == 18\n print \"eighteen\"\n elsif x == 19\n print \"nineteen\"\n end\nend\n\ndef ten(x)\n if x == 2\n return \"twenty\"\n elsif x == 3\n return \"thirty\"\n elsif x == 4\n return \"forty\"\n elsif x == 5\n return \"fifty\"\n elsif x == 6\n return \"sixty\"\n elsif x == 7\n return \"seventy\"\n elsif x == 8\n return \"eighty\"\n elsif x == 9\n return \"ninety\"\n end\nend\n\nif n <= 10\n if n == 0\n print \"zero\"\n elsif n == 10\n print \"ten\"\n else\n print unit(n)\n end\nelsif n > 10 && n < 20\n teen(n)\nelse\n quotient = n / 10\n remainder = n % 10\n if remainder == 0\n print ten(quotient)\n else\n print ten(quotient) + \"-\" + unit(remainder)\n end\nend\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "9f36891cf63372155147ab0bcd27125e", "src_uid": "a49ca177b2f1f9d5341462a38a25d8b7", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "group1 = [\n 'zero',\n 'one',\n 'two',\n 'three',\n 'four',\n 'five',\n 'six',\n 'seven',\n 'eight',\n 'nine',\n]\n\ngroup2 = [\n 'ten',\n 'eleven',\n 'twelve',\n 'thirteen',\n 'fourteen',\n 'fifteen',\n 'sixteen',\n 'seventeen',\n 'eighteen',\n 'nineteen', \n]\n\ngroup3 = [\n 'twenty',\n 'thirty',\n 'forty',\n 'fifty',\n 'sixty',\n 'seventy',\n 'eighty',\n 'ninety',\n]\n\nn = gets.to_i\n\nif n < 10\n puts group1[n]\nelsif n < 20\n puts group2[n - 10]\nelse\n print group3[(n / 10) - 2]\n\n if n % 10 > 0\n print '-' + group1[n % 10]\n end\n\n print $/\nend\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "df92a5c41bce2d9297d3645eea76a398", "src_uid": "a49ca177b2f1f9d5341462a38a25d8b7", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a=gets.chomp.split(\" \")\nstone=a[2].to_i\ns=a[0].to_i\na=a[1].to_i\nans=\"\"\ntog=0\nloop do\nt2=0\nif tog==0 && stone.gcd(s)<=stone\nstone-=stone.gcd(s)\nans=\"0\"\ntog=1\nt2=1\nelsif tog==1 && stone.gcd(a)<=stone\nstone-=stone.gcd(a)\nans=\"1\"\ntog=0\nt2=1\nend\nbreak if stone<1 || t2==0\nend\nif ans==\"0\"\nputs \"0\"\nelse \nputs \"1\"\nend", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "f75b764db4d1e6e02dac1bfc6e636db8", "src_uid": "0bd6fbb6b0a2e7e5f080a70553149ac2", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a, b, n = gets.split.map {|x| x.to_i}\n\nwhile true\n n = n - n.gcd(a)\n if n < 0\n puts 1\n exit\n end\n n = n - n.gcd(b)\n if n < 0\n puts 0\n exit\n end\nend", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "2ec5bcf104a10693d90c4e8d25081863", "src_uid": "0bd6fbb6b0a2e7e5f080a70553149ac2", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a, b, n = gets.split.map(&:to_i)\n\ni=0\nwhile n>0\n\tt=n.gcd([a,b][i])\n\ti^=1\n\tn-=t\nend\n\np i^=1\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "4587d28e18e96603f2caf0051dd10fb6", "src_uid": "0bd6fbb6b0a2e7e5f080a70553149ac2", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "gets.to_i.times{\n puts [1, 2, 4, 5, 8, 11].include?(gets.to_i) ? \"NO\" : \"YES\"\n}", "lang_cluster": "Ruby", "tags": ["greedy", "implementation"], "code_uid": "49934680ed10b74e59f7e22db6b27a27", "src_uid": "cfd1182be98fb5f0c426f8b68e48d452", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "input = Array.new\nn = $stdin.gets.to_i\nn.times do\n line = $stdin.gets\n input << line.to_i\nend\n \ninput.each do |a|\n if a == 0\n puts 'NO'\n elsif a%3 == 0\n puts 'YES'\n elsif a%7 == 0\n puts 'YES'\n elsif a%21 == 0\n puts 'YES'\n elsif a%3%7 == 0\n puts 'YES'\n elsif a%7%3 == 0\n puts 'YES'\n elsif a >= 12\n puts 'YES' \n else\n puts 'NO'\n end\nend\n\n", "lang_cluster": "Ruby", "tags": ["greedy", "implementation"], "code_uid": "8463df6a66ac18c3d71c1c8c8360ba49", "src_uid": "cfd1182be98fb5f0c426f8b68e48d452", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["greedy", "implementation"], "code_uid": "75bd0ea4de26fa41ff7bcf278e9fb512", "src_uid": "cfd1182be98fb5f0c426f8b68e48d452", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#gets1 = '8 5'\n#gets2 = '10 9 8 7 7 7 5 5'\n\n#n, k = gets1.split(/\\s+/).map {|x| x.to_i}\nn, k = gets.split(/\\s+/).map {|x| x.to_i}\n#scores = gets2.split(/\\s+/).map {|x| x.to_i}\nscores = gets.split(/\\s+/).map {|x| x.to_i}\netalon = scores[k-1]\n\nwinners = 0\nscores.each do |score|\n if score >= etalon and score > 0\n winners += 1\n end\nend\n\nputs winners\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "465c5c9cfbbe088d0e5e164ea3a07677", "src_uid": "193ec1226ffe07522caf63e84a7d007f", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "x=gets(p).split.map &:to_i\nk,*x=x[1..-1];p x.count{|i|i>0&&i>=x[k-1]}", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "b7e43ad6a3e763830108456d184231b2", "src_uid": "193ec1226ffe07522caf63e84a7d007f", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "(n, k), participants = STDIN.readlines.map{|i| i.split(\" \").map(&:to_i)}\nlim_point = [participants[(participants.size > k-1)? k-1 : -1], 1].max\nputs participants.select.with_index{|point, idx| point >= lim_point}.size\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "cf80ed5d69907b57515a5ca7a07da26c", "src_uid": "193ec1226ffe07522caf63e84a7d007f", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#! /usr/bin/env ruby\nx = gets.chomp\nn = gets.to_i\n\nx << '*'*n\nmax = 0\n(0..(x.size-1)).each do |st|\n en = st + 1\n\n while en < x.size\n len = en-st+1\n half_en = st + (len)/2\n # puts [x[st..en], st, en, len, half_en, x[st..half_en-1], x[half_en..en]].inspect\n flag = true\n (len/2-1).times do |i|\n\n # puts [x[st+i], x[half_en+i], st+i, half_en+i].inspect\n if x[st+i] != x[half_en+i] && x[half_en+i] != '*'\n flag = false\n break\n end\n end\n\n # puts [flag, len, max, x[st..en]].inspect\n # puts ''\n max = len if flag && max < len\n en +=2\n end\nend\n\nputs max\n", "lang_cluster": "Ruby", "tags": ["brute force", "strings", "implementation"], "code_uid": "8f90db5aee8f7fdebf4933587d49b3d6", "src_uid": "bb65667b65ff069a9c0c9e8fe31da8ab", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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+j1 || b>1\n\t\t#puts 'a='+a.to_s+' b='+b.to_s\n\t\tif a==0 || b==0\n\t\t\tbreak\n\t\tend\n\t\tif a0&&a2>0\n\tif a1>=3\n\t\ta1-=2\n\t\ta2+=1\n\t\tans+=1\n\telsif a2>=3\n\t\ta1+=1\n\t\ta2-=2\n\t\tans+=1\n\telsif a1>=2 or a2 >= 2\n\t\ta1=0\n\t\ta2=0\n\t\tans+=1\n\telse\n\t\ta1=a2=0\n\tend\nend \nputs ans", "lang_cluster": "Ruby", "tags": ["math", "greedy", "dp", "implementation"], "code_uid": "9615d2daf9b4796602a7033dfccb91e2", "src_uid": "ba0f9f5f0ad4786b9274c829be587961", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def gao(a, b)\n a, b = b, a if a > b\n if a == 0 || a == 1 && b == 1\n return 0\n else\n return 1 + gao(b - 2, a + 1)\n end\nend\na, b = readline.split(' ').collect(&:to_i)\nputs gao(a, b)\n", "lang_cluster": "Ruby", "tags": ["math", "greedy", "dp", "implementation"], "code_uid": "fa2a8202ce8be6fe3a86e71747ade1b6", "src_uid": "ba0f9f5f0ad4786b9274c829be587961", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def run(input = STDIN.read)\n line1, line2 = input.split(\"\\n\")\n line1.each_char.each_with_index do |char, index|\n next if char.downcase == line2[index].downcase\n\n puts char.downcase > line2[index].downcase ? \"1\" : \"-1\"\n return\n end\n puts \"0\"\nend\nrun", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "52091b13f6e13f77650329509e26b989", "src_uid": "ffeae332696a901813677bd1033cf01e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "l1 = gets.chomp.downcase\nl2 = gets.chomp.downcase\n\nputs l1 <=> l2\n", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "fa439d1de95cc81e8f2dba987e40d389", "src_uid": "ffeae332696a901813677bd1033cf01e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a = gets.chomp.split.map(&:downcase).join\nb = gets.chomp.split.map(&:downcase).join\nputs (a == b) ? 0 : a>b ? 1 : -1", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "44d0a3e4e790058d155e343091658ed2", "src_uid": "ffeae332696a901813677bd1033cf01e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "names= '',\n'Washington',\n'Adams',\n'Jefferson',\n'Madison',\n'Monroe',\n'Adams',\n'Jackson',\n'Van Buren',\n'Harrison',\n'Tyler',\n'Polk',\n'Taylor',\n'Fillmore',\n'Pierce',\n'Buchanan',\n'Lincoln',\n'Johnson',\n'Grant',\n'Hayes',\n'Garfield',\n'Arthur',\n'Cleveland',\n'Harrison',\n'Cleveland',\n'McKinley',\n'Roosevelt',\n'Taft',\n'Wilson',\n'Harding',\n'Coolidge',\n'Hoover',\n'Roosevelt',\n'Truman',\n'Eisenhower',\n'Kennedy',\n'Johnson',\n'Nixon',\n'Ford',\n'Carter',\n'Reagan',\n'George H. W. Bush',\n'Bill Clinton',\n'George W. Bush',\n'Barack Hussein Obama'\n\nputs names[gets.to_i]\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "988296e1113cee2ce8a44a729c79b9a7", "src_uid": "0b51a8318c9ec0c80c0f4dc04fe0bfb3", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "puts ['Washington',\n 'Adams',\n 'Jefferson',\n 'Madison',\n 'Monroe',\n 'Adams',\n 'Jackson',\n 'Van Buren',\n 'Harrison',\n 'Tyler',\n 'Polk',\n 'Taylor',\n 'Fillmore',\n 'Pierce',\n 'Buchanan',\n 'Lincoln',\n 'Johnson',\n 'Grant',\n 'Hayes',\n 'Garfield',\n 'Arthur',\n 'Cleveland',\n 'Harrison',\n 'Cleveland',\n 'McKinley',\n 'Roosevelt',\n 'Taft',\n 'Wilson',\n 'Harding',\n 'Coolidge',\n 'Hoover',\n 'Roosevelt',\n 'Truman',\n 'Eisenhower',\n 'Kennedy',\n 'Johnson',\n 'Nixon',\n 'Ford',\n 'Carter',\n 'Reagan'][gets.to_i - 1]", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "64839d507d6f0ead2dd0382fb1a3cdca", "src_uid": "0b51a8318c9ec0c80c0f4dc04fe0bfb3", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#/usr/bin/env ruby\n\nP = [\n\t\"Washington\",\n\t\"Adams\",\n\t\"Jefferson\",\n\t\"Madison\",\n\t\"Monroe\",\n\t\"Adams\",\n\t\"Jackson\",\n\t\"Van Buren\",\n\t\"Harrison\",\n\t\"Tyler\",\n\t\"Polk\",\n\t\"Taylor\",\n\t\"Fillmore\",\n\t\"Pierce\",\n\t\"Buchanan\",\n\t\"Lincoln\",\n\t\"Johnson\",\n\t\"Grant\",\n\t\"Hayes\",\n\t\"Garfield\",\n\t\"Arthur\",\n\t\"Cleveland\",\n\t\"Harrison\",\n\t\"Cleveland\",\n\t\"McKinley\",\n\t\"Roosevelt\",\n\t\"Taft\",\n\t\"Wilson\",\n\t\"Harding\",\n\t\"Coolidge\",\n\t\"Hoover\",\n\t\"Roosevelt\",\n\t\"Truman\",\n\t\"Eisenhower\",\n\t\"Kennedy\",\n\t\"Johnson\",\n\t\"Nixon\",\n\t\"Ford\",\n\t\"Carter\",\n\t\"Reagan\",\n\t\"Bush\",\n\t\"Clinton\",\n\t\"Bush\",\n\t\"Hussein Obama\"\n]\n\nputs P[gets.to_i-1]\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "0499769e4b0d1c62e0440931d73a018b", "src_uid": "0b51a8318c9ec0c80c0f4dc04fe0bfb3", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def fill_primes(max)\n primes = [2,3]\n now = primes[-1]\n loop{\n now+=2\n break if now>max\n prime, check = true, 0\n while primes[check]**2 <= now do\n prime = false if now%primes[check]==0\n break if not prime\n check+=1\n end\n primes << now if prime\n }\n return primes\nend\n\ndef is_almost_prime(num, primes)\n check = 0\n divisors = [1]\n while num>1\n while num % primes[check] == 0\n num /= primes[check]\n divisors << primes[check] if divisors[-1] != primes[check]\n end\n check+=1\n end\n if divisors.length == 3\n 1\n else\n 0\n end\nend\n\nprimes = fill_primes(3000)\n\nprimes, n, ans = fill_primes(3000), gets.chomp.to_i, 0\n2.upto(n){|i| ans+=is_almost_prime(i, primes) }\np ans", "lang_cluster": "Ruby", "tags": ["number theory"], "code_uid": "d73ae519c2dc72ae491378dfb21aaac6", "src_uid": "356666366625bc5358bc8b97c8d67bd5", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "require\"prime\"\np (2..gets.to_i).count{|n|n.prime_division.size==2}", "lang_cluster": "Ruby", "tags": ["number theory"], "code_uid": "72a2656ed59845587e8ff161bd16c93c", "src_uid": "356666366625bc5358bc8b97c8d67bd5", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "require 'prime'\np 1.upto(gets.to_i).count{|i| Prime.prime_division(i).size == 2}\n", "lang_cluster": "Ruby", "tags": ["number theory"], "code_uid": "d582c7c567c4a90a15fe4802ea4aa32f", "src_uid": "356666366625bc5358bc8b97c8d67bd5", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "puts 25", "lang_cluster": "Ruby", "tags": ["number theory"], "code_uid": "bbdac6842189deb9347a1cc0622c27be", "src_uid": "dcaff75492eafaf61d598779d6202c9d", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "puts(25)", "lang_cluster": "Ruby", "tags": ["number theory"], "code_uid": "805243d96b14ebd1152a0f7826afe1b0", "src_uid": "dcaff75492eafaf61d598779d6202c9d", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "puts \"25\"", "lang_cluster": "Ruby", "tags": ["number theory"], "code_uid": "673e8f94ceeb11c879c28b8384280f0c", "src_uid": "dcaff75492eafaf61d598779d6202c9d", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "puts gets.gsub(/\\/+/, \"/\").gsub(/([^\\/])\\/$/,'\\1')\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "41ef41868b8d81e23b815603fc97354e", "src_uid": "6c2e658ac3c3d6b0569dd373806fa031", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "puts gets.gsub(/\\/+/, \"/\").gsub(/([^\\/])\\/$/,'\\1')\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "b6afb7c82330e6ce7e61e02eee84f244", "src_uid": "6c2e658ac3c3d6b0569dd373806fa031", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "input = gets.to_s.chomp.gsub(/\\/+/,'/')\nc = input.length\ninput = input[0,c-1] if input[-1,1].eql?('/') && c > 1\nputs input", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "11955f531e641a894c775a478fc6aa96", "src_uid": "6c2e658ac3c3d6b0569dd373806fa031", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "gets;a=1;gets.tr(' ','').scan(/10*(?=1)/){a*=$&.size};p$_['1'].to_i+a-1\n\n", "lang_cluster": "Ruby", "tags": ["combinatorics"], "code_uid": "22a4cbef63cf114b907534e3c32d2f04", "src_uid": "58242665476f1c4fa723848ff0ecda98", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\na = gets.split.join\np a.delete('0').size.zero? ? 0 : a.scan(/(?<=1)0*(?=1)/).map{|x| x.size + 1}.reduce(1, :*)\n", "lang_cluster": "Ruby", "tags": ["combinatorics"], "code_uid": "f88748e12aa12cfc32b0939c2af8191d", "src_uid": "58242665476f1c4fa723848ff0ecda98", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\ns = a.join\nt = a.inject(:+)\nans = t == 0 ? 0 : 1\n(t - 1).times do\n ss = s.scan(/10*1/)[0]\n ans *= (ss.size - 1)\n s.sub!(ss, '1')\nend\np ans\n", "lang_cluster": "Ruby", "tags": ["combinatorics"], "code_uid": "70038207cc3bdbbfbde0ab53eb840b58", "src_uid": "58242665476f1c4fa723848ff0ecda98", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "infile = STDIN\nx, a, b = infile.readline.split.map(&:to_i)\nc, y, d = infile.readline.split.map(&:to_i)\ne, f, z = infile.readline.split.map(&:to_i)\nz = (b+c+e-f)/2\ny = b+d-a-f+z\nx = f-c+z\nprint x, ' ', a, ' ', b, \"\\n\"\nprint c, ' ', y, ' ', d, \"\\n\"\nprint e, ' ', f, ' ', z", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "f36a4eca753cf67c9b3f602589209faa", "src_uid": "0c42eafb73d1e30f168958a06a0f9bca", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def check mat, sum\n 3.times do |i|\n return false if mat[i].inject(:+)!=sum\n end\n\n 3.times do |i|\n return false if mat[0][i]+mat[1][i]+mat[2][i]!=sum \n end\n \n return false if mat[0][0]+mat[1][1]+mat[2][2]!=sum\n mat[0][2]+mat[1][1]+mat[2][0]==sum\nend\n\nmat=[]\nmat< 9\n checked[n] = true\n n += 1\n n = n.to_s.reverse.to_i.to_s.reverse.to_i\nend\n\nputs checked.keys.count + 9\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "19001f1387788d3e2e6bda1348b0081a", "src_uid": "055fbbde4b9ffd4473e6e716da6da899", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "# your code goes here\n\n$store = {}\n\ndef trim_trailing_zeroes(y)\n\ty_string = y.to_s\n\ti = y_string.length - 1\n\tindex_non_zero = 0\n\twhile i >= 1 do\n\t\tif y_string[i] != \"0\"\n\t\t\tindex_non_zero = i\n\t\t\tbreak\n\t\tend\n\t\ti -= 1\n\tend\n\t\n\treturn y_string[0..index_non_zero]\nend\n\ndef cal(x)\n\tif !$store[x].nil?\n\t\treturn\n\tend\n\t$store[x] = 1\n\texecute_for = trim_trailing_zeroes(x + 1)\n\tcal(execute_for.to_i)\nend\n\n\nvalue = gets.to_i\ncal(value)\n\np $store.keys.size", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "6346ccf44bf2045e8840990d91dce011", "src_uid": "055fbbde4b9ffd4473e6e716da6da899", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\na = Hash.new(false)\nwhile !a[n]\n a[n] = true\n n += 1\n n /= 10 while n%10 == 0\nend\nputs a.size", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "502f996b0bfcb916da55e6fbcee1ee75", "src_uid": "055fbbde4b9ffd4473e6e716da6da899", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def execute(n, interesting_minutes)\n @count_step = 1\n @step = 15\n\n # special case\n return @step if interesting_minutes[0] > @step\n\n # 7 20 88\n interesting_minutes.each_with_index do |minute, index|\n @max_minutes = minute + 15\n\n return @max_minutes if index + 1 >= n\n\n break if @max_minutes < interesting_minutes[index + 1]\n end\n\n return @max_minutes\nend\n\n\nn = gets.chomp.to_i\ninteresting_minutes = gets.chomp.split(' ').map!(&:to_i)\n\nresult = execute(n, interesting_minutes)\nif result > 90\n puts 90\nelse\n puts result\nend\n\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "760f495d70623a5c41507dbe841769e7", "src_uid": "5031b15e220f0ff6cc1dd3731ecdbf27", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def calculate_minutes(n, list)\n return 15 if list[0] > 15\n for i in 0..(list.length - 1)\n if list[i] == list[-1]\n sub = 90 - list[i]\n return sub < 15 ? 90 : list[i] + 15\n else\n sub = list[i + 1] - list[i]\n if sub > 15\n return list[i] + 15\n end\n end\n end\nend\n\nnumber_of_interesting_mins = gets.chomp.to_i\nlist_interesting_mins = gets.chomp.split.map(&:to_i)\n\nputs calculate_minutes(number_of_interesting_mins, list_interesting_mins)\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "a891e476661c62ed5124207ea928b67a", "src_uid": "5031b15e220f0ff6cc1dd3731ecdbf27", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "c547aaebcb070047c0f4baacdbf0b35e", "src_uid": "5031b15e220f0ff6cc1dd3731ecdbf27", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a=gets.split.map &:to_i;puts a[0,2].min>=a[2]*2?\"First\":\"Second\"", "lang_cluster": "Ruby", "tags": ["math", "constructive algorithms", "games"], "code_uid": "719119a308c575ca7a4643c11e59ff89", "src_uid": "90b9ef939a13cf29715bc5bce26c9896", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["math", "constructive algorithms", "games"], "code_uid": "b31a58eb92e519999791aa05247838cd", "src_uid": "90b9ef939a13cf29715bc5bce26c9896", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "l,b,r = gets.split(\" \").map(&:to_i)\nd = r * 2\nans = true\nans = false if d > [l,b].min\n# x = 0\n# y = 0\n\n# count = 0\n# left_x = d\n# right_x = l - d\n# top_y = d\n# bottom_y = b - d\n\n# while true\n# \twhile x + d <= l\n# \t\tbreak if (x >= left_x && x <= right_x && y >=top_y && y <= bottom_y)\n# \t\tcount += 1\n# \t\tx += d\n# \tend\n# \ty += d\n# \tbreak if y + d > b\n# \tx = 0\n# end\n# puts \"#{count}\"\nputs ans ? \"First\" : \"Second\"\n\n#Good - Dont ever think of playing the game in game questions. Just think of the best move and work backwards", "lang_cluster": "Ruby", "tags": ["math", "constructive algorithms", "games"], "code_uid": "679ea9df9cffce0353472ec943f09698", "src_uid": "90b9ef939a13cf29715bc5bce26c9896", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, pos, l, r = gets.split.map(&:to_i)\n\nif r == n && l == 1\n puts 0\nelsif r == n || l == 1\n puts 1 + (pos - ((r == n)? l : r)).abs\nelse\n puts 2 + [(pos - l).abs, (pos - r).abs].min + r - l\nend\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "f553baaf9b4d318d77af5ad97c6ade3d", "src_uid": "5deaac7bd3afedee9b10e61997940f78", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "0a8efa07d51cbdfa585a9adf73155186", "src_uid": "5deaac7bd3afedee9b10e61997940f78", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def solve(n, pos, l, r)\n result = 0\n if(l == 1 and r == n)\n elsif(l != 1 and r != n)\n if pos < l\n result += l - pos\n pos = l\n elsif pos > r \n result += pos - r\n pos = r\n elsif(pos < r and pos > l)\n if (r - pos) > (pos -l)\n result += pos -l\n else\n result += r - pos\n end\n end\n result += (1 + r - l + 1)\n elsif(l == 1)\n if r > pos\n result += (r - pos + 1)\n else\n result += (pos - r + 1)\n end\n elsif(r == n)\n if l > pos\n result += (l - pos + 1)\n else\n result += (pos - l + 1)\n end\n end\n result \nend\n\nn, pos, l, r = gets.chomp.split(' ').map(&:to_i)\nputs solve(n, pos, l, r)\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "9b8ccdd58cb0dc613291be13744b5168", "src_uid": "5deaac7bd3afedee9b10e61997940f78", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.chomp.to_i\nf = false\n\nfor a in 0..(n / 1234567)\n for b in 0..((n - a * 1234567) / 123456)\n if (n - a * 1234567 - b * 123456) % 1234 == 0\n f = true\n end\n end\nend\n\nputs f ? \"YES\" : \"NO\"\n", "lang_cluster": "Ruby", "tags": ["brute force"], "code_uid": "025793dd9b9cb655195dfc45209f4c68", "src_uid": "72d7e422a865cc1f85108500bdf2adf2", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\n\n1000.times do |i|\n\t10000.times do |j|\n\t\trest = n - 1234567 * i - 123456 * j\n\t\tif rest < 0 then\n\t\t\tbreak\n\t\tend\n\n\t\tif 0 <= rest and rest % 1234 == 0 then\n\t\t\tputs \"YES\"\n\t\t\texit 0\n\t\tend\n\tend\nend\n\nputs \"NO\"\n", "lang_cluster": "Ruby", "tags": ["brute force"], "code_uid": "f239468ff5cf21ef05f65cc95b239c9d", "src_uid": "72d7e422a865cc1f85108500bdf2adf2", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/ruby\nn=gets.to_i\n0.step(n,1234567){|a|\n\t0.step(n-a,123456){|b|\n\t\tif (n-a-b)%1234==0\n\t\t\tputs :YES\n\t\t\texit\n\t\tend\n\t}\n}\nputs :NO\n\n\n\n", "lang_cluster": "Ruby", "tags": ["brute force"], "code_uid": "77f04ba0b7a34f323214f06cf7c8fdc8", "src_uid": "72d7e422a865cc1f85108500bdf2adf2", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "tc = gets.to_i \ntc.times do \n\tn = gets.to_i\n\tans = 10**12\n\toans = 1\n\tlopz = Math.sqrt(n).to_i + 1 \n\tfor i in 1..lopz \n\t\tif(n % i == 0) \n\t\t\ta = i\n\t\t\tb = n / i\n\t\t\tc = a.lcm(n-a) \n\t\t\td = b.lcm(n-b) \n\t\t\t# print(\"#{c} #{d}\\n\")\n\t\t\tif(ans > c && c != 0) \n\t\t\t\tans = c \n\t\t\t\toans = a \n\t\t\tend\n\t\t\tif(ans > d && d != 0) \n\t\t\t\tans = d \n\t\t\t\toans = b \n\t\t\tend\n\t\tend\n\t\t# puts \"#{oans}\"\n\tend \n\tputs \"%d %d\" %[oans , n-oans]\nend", "lang_cluster": "Ruby", "tags": ["math", "greedy", "number theory"], "code_uid": "2294885849e34ff89a207d00f7de9510", "src_uid": "3fd60db24b1873e906d6dee9c2508ac5", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["math", "implementation", "binary search"], "code_uid": "1c949dd5ff681230d5ce50489b232765", "src_uid": "8ef8a09e33d38a2d7f023316bc38b6ea", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def find_next(m)\n ret = 1\n while ret <= m\n ret = ret * 10\n end\n return ret\nend\n\ndef find_cost(w)\n ret = 1;\n pow = 1\n while pow <= w\n pow = pow * 10\n ret = ret + 1\n end\n return ret - 1\nend\n\nw, m, k = gets.chomp.split.map{|i| i.to_i}\n\nstart = m\nwhile w != 0\n nextm = find_next(m)\n cost = find_cost(m)\n rest_cost = cost * k * (nextm - m);\n if w > rest_cost\n w = w - rest_cost;\n m = nextm\n else\n m = m + w / cost / k\n puts m - start\n break\n end\nend\n", "lang_cluster": "Ruby", "tags": ["math", "implementation", "binary search"], "code_uid": "4c1310328a90aac7086626652dc89522", "src_uid": "8ef8a09e33d38a2d7f023316bc38b6ea", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["math", "implementation", "binary search"], "code_uid": "c0fe51aa8c0ee1c2e9963922822e82e0", "src_uid": "8ef8a09e33d38a2d7f023316bc38b6ea", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "gets\nputs gets.chomp.gsub(/o(go)+/, \"***\")", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "818e8c3343a031761b5774a16d964a44", "src_uid": "619665bed79ecf77b083251fe6fe7eb3", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "gets;s=gets.chomp;\n\n\nputs s.gsub(/o(?:go)+/,'***')", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "ef995f2be3109aec711be10ca45ebfa6", "src_uid": "619665bed79ecf77b083251fe6fe7eb3", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.strip.to_i\ns = gets.strip\nt = ''\ni = 0\nwhile i < n\n if i < n - 2 && (s[i] == 'o' && s[i + 1] == 'g' && s[i + 2] == 'o')\n j = i + 3\n while j < n\n if j < n - 1 && (s[j] == 'g' && s[j + 1] == 'o')\n j += 2\n next\n end\n break\n end\n t += '***'\n i += j - i\n next\n end\n t += s[i]\n i += 1\nend\nputs t\n", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "4dbf698f20390dadda8be8281c27a792", "src_uid": "619665bed79ecf77b083251fe6fe7eb3", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/env ruby\nn = gets.to_i\nk = 0\nloop do\n if n % (3**k) != 0\n ret = n / (3**k)\n ret += 1 if ret * (3**k) != n\n puts ret\n break\n end\n k += 1\nend\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "a97f8f7388b6af8dae63b1756bc4de32", "src_uid": "7e7b59f2112fd200ee03255c0c230ebd", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.chomp.to_i\n\nk = 1\n\nwhile (n % 3**k == 0) \n k+=1\nend\n\nputs n / 3 ** k + 1\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "524821d9ff1b81a8b3c46637f2ba917e", "src_uid": "7e7b59f2112fd200ee03255c0c230ebd", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.to_i\nn/=3 while n%3==0\np (n+2)/3\n", "lang_cluster": "Ruby", "tags": ["greedy"], "code_uid": "7f516c84d970b9d4e2f8f56b75cdb277", "src_uid": "7e7b59f2112fd200ee03255c0c230ebd", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\nputs gets.split(' ').sort_by{ |x| x.to_i}.join(' ')\n", "lang_cluster": "Ruby", "tags": ["sortings", "implementation", "greedy"], "code_uid": "ed865ec26fc5bdb2edbfcd2c6352b8d5", "src_uid": "ae20712265d4adf293e75d016b4b82d8", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\na = gets.split(' ').map { |e| e = e.to_i }\n\na.sort!\nputs a.join(' ')", "lang_cluster": "Ruby", "tags": ["sortings", "implementation", "greedy"], "code_uid": "0cbcf0a6b2bb0a889758d3cd68120190", "src_uid": "ae20712265d4adf293e75d016b4b82d8", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "gets\nputs gets.split(' ').map(&:to_i).sort.join(' ')\n", "lang_cluster": "Ruby", "tags": ["sortings", "implementation", "greedy"], "code_uid": "16d2a28aa42ab7df8962e69099fabc11", "src_uid": "ae20712265d4adf293e75d016b4b82d8", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "r, g, b = gets.split.map(&:to_i)\np (0..[2,r,g,b].min).map {|i| i+(r-i)/3+(b-i)/3+(g-i)/3}.max\n", "lang_cluster": "Ruby", "tags": ["math", "combinatorics"], "code_uid": "1044b3c9124485e26e32ab8987b90e34", "src_uid": "acddc9b0db312b363910a84bd4f14d8e", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "\n r,g,b = STDIN.readline.split.map(&:to_i)\n val0 = r/3 + b/3 + g/3\n if r > 0 and g > 0 and b > 0\n val1 = (r-1)/3 + (b-1)/3 + (g-1)/3 + 1\n else \n val1 = 0\n end\n\n\n if r > 1 and g > 1 and b > 1\n val2 = (r-2)/3 + (b-2)/3 + (g-2)/3 +2\n else \n val2 = 0\n end\n\n puts [val0,val1,val2].max\n", "lang_cluster": "Ruby", "tags": ["math", "combinatorics"], "code_uid": "6edb719b3abb144b6ebdad33aa8b478a", "src_uid": "acddc9b0db312b363910a84bd4f14d8e", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "r, g, b = gets.split.map(&:to_i)\np (0..[2,r,g,b].min).map {|i| i+(r-i)/3+(b-i)/3+(g-i)/3}.max\n", "lang_cluster": "Ruby", "tags": ["math", "combinatorics"], "code_uid": "663de3f4ce6aa4db7b4b2b8c3aa62e1e", "src_uid": "acddc9b0db312b363910a84bd4f14d8e", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "x, y = gets.split(' ').map(&:to_i)\nt1 = x.abs+y.abs\nt2 = y>0 ? t1 : -t1\nif x>0\n puts \"0 #{t2} #{t1} 0\"\nelse\n puts \"#{-t1} 0 0 #{t2}\"\nend\n\n# The truth is, the sample doesn't correct\n# A(0,2y) C(2x,0) makes the area minimum\n\n# if x>0\n# puts \"0 #{2*y} #{2*x} 0\"\n# else\n# puts \"#{2*x} 0 0 #{2*y}\"\n# end", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "2daba038ab808fc05887f3d57b0b9dbe", "src_uid": "e2f15a9d9593eec2e19be3140a847712", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "x, y =gets.split.map{|i| i.to_i}\nif(x>0) then\n if(y>0) then\n puts(\"0 #{x+y} #{x+y} 0\")\n else\n puts(\"0 #{y-x} #{x-y} 0\")\n end\nelse\n if(y>0) then\n puts(\"#{x-y} 0 0 #{y-x}\")\n else\n puts(\"#{x+y} 0 0 #{x+y}\")\n end\nend\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "6dcb4199995f5e344f9e74c0dc5c2c0e", "src_uid": "e2f15a9d9593eec2e19be3140a847712", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#monkeycode\nx, y =gets.split.map{|i| i.to_i}\nif(x>0) then\n if(y>0) then\n puts(\"0 #{x+y} #{x+y} 0\")\n else\n puts(\"0 #{y-x} #{x-y} 0\")\n end\nelse\n if(y>0) then\n puts(\"#{x-y} 0 0 #{y-x}\")\n else\n puts(\"#{x+y} 0 0 #{x+y}\")\n end\nend", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "a287d25d09ba96945295b55714a864fb", "src_uid": "e2f15a9d9593eec2e19be3140a847712", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = gets.strip\nif s.size < 3\n puts s\nelse\n o = s[0, 1] + s[1..-2].gsub('dot', '.').sub('at','@') + s[-1, 1]\n puts o\nend\n", "lang_cluster": "Ruby", "tags": ["expression parsing", "implementation"], "code_uid": "618a283b5b8dee14ddb892091e801d05", "src_uid": "a11c9679d8e2dca51be17d466202df6e", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "str = gets.chomp\n\nres = [str[0], str[1..-2].sub(/at/,'@').gsub('dot', '.'), str[-1]].join\n\nputs res", "lang_cluster": "Ruby", "tags": ["expression parsing", "implementation"], "code_uid": "ba4ff6e60a418be8e9563df33e182372", "src_uid": "a11c9679d8e2dca51be17d466202df6e", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "gets\n$_.sub! /(?!^)at/,?@\n$_.gsub! /(?!^)dot(?!$)/,?.\n$><<$_\n\n", "lang_cluster": "Ruby", "tags": ["expression parsing", "implementation"], "code_uid": "4207451e9fc2300859318c25c200a2d8", "src_uid": "a11c9679d8e2dca51be17d466202df6e", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = STDIN.gets.strip\nl = s[1...-1]\nl[\"at\"] = \"@\"\n\nl[\"dot\"] = \".\" while l[\"dot\"]\nputs \"#{s[0].chr}#{l}#{s[-1].chr}\"", "lang_cluster": "Ruby", "tags": ["expression parsing", "implementation"], "code_uid": "60981a4dcd6c11e2c397a3128c11573f", "src_uid": "a11c9679d8e2dca51be17d466202df6e", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "gets\n$_.sub! /(?!^)at/,?@\n$_.gsub! /(?!^)dot(?!$)/,?.\n$><<$_\n\n", "lang_cluster": "Ruby", "tags": ["expression parsing", "implementation"], "code_uid": "b05ee6cd49040d7beec58a095ca22740", "src_uid": "a11c9679d8e2dca51be17d466202df6e", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.chomp.to_s\n\ns = n[1..-2].gsub(\"dot\", \".\")\nk = s[0..-1].sub(\"at\", \"@\")\n\nputs n[0]+k+n[-1]", "lang_cluster": "Ruby", "tags": ["expression parsing", "implementation"], "code_uid": "beb3b216b0b3c17018c4704cb21bfff7", "src_uid": "a11c9679d8e2dca51be17d466202df6e", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "email = gets.strip\nhead, tail = email[0, 1], email[1 .. -1].sub(/at/, '@').gsub(/dot(?=.)/, '.')\nemail = head + tail\nputs email\n", "lang_cluster": "Ruby", "tags": ["expression parsing", "implementation"], "code_uid": "f6a40d2bb3f70cb9badda3fa7bbae64c", "src_uid": "a11c9679d8e2dca51be17d466202df6e", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "gets\n$_.sub! /(?!^)at/,?@\n$_.gsub! /(?!^)dot(?!$)/,?.\n$><<$_\n\n", "lang_cluster": "Ruby", "tags": ["expression parsing", "implementation"], "code_uid": "257620cc1884bc569712386e2ad52036", "src_uid": "a11c9679d8e2dca51be17d466202df6e", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a=gets.chomp\nb=a[1..-2]\nc=b.index('at')\nb[c..c+1]=\"@\"\nb.gsub!(/dot/,\".\")\nputs a[0..0]+b+a[-1..-1]", "lang_cluster": "Ruby", "tags": ["expression parsing", "implementation"], "code_uid": "45add3c181eb007f5f7bff3b154ae567", "src_uid": "a11c9679d8e2dca51be17d466202df6e", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "w = gets.chomp\nh_a, l = false, w.length\nret = \"\"\ni = 0\nwhile i < l\n if w[i] == 'a' && i + 1 < l && w[i + 1] == 't'\n if i == 0 || i == l - 2\n ret += \"at\"\n i += 2\n else\n if h_a\n ret += \"at\"\n i += 2\n else\n h_a = true\n ret += \"@\"\n i += 2\n end\n end\n elsif w[i] == 'd' && i + 1 < l && w[i + 1] == 'o' && i + 2 < l && w[i + 2] == 't'\n if i == 0 || i == l - 3 \n ret += \"dot\"\n i += 3\n else\n ret += \".\"\n i += 3\n end\n else\n ret += w[i]\n i += 1\n end\nend\nputs ret\n", "lang_cluster": "Ruby", "tags": ["expression parsing", "implementation"], "code_uid": "c8c11582a67ca232bbdff9229b991822", "src_uid": "a11c9679d8e2dca51be17d466202df6e", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "gets\n$_.sub! /(?!^)at/,?@\n$_.gsub! /(?!^)dot(?!$)/,?.\n$><<$_\n\n", "lang_cluster": "Ruby", "tags": ["expression parsing", "implementation"], "code_uid": "f22c1288c9cfc463921c870b82160fcb", "src_uid": "a11c9679d8e2dca51be17d466202df6e", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "gets\n$_.sub! /(?!^)at/,?@\n$_.gsub! /(?!^)dot(?!$)/,?.\n$><<$_\n\n", "lang_cluster": "Ruby", "tags": ["expression parsing", "implementation"], "code_uid": "8d62b9bc9ed13603d9cb99d2db8373a2", "src_uid": "a11c9679d8e2dca51be17d466202df6e", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "gets\n$_.sub! /(?!^)at/,?@\n$_.gsub! /(?!^)dot(?!$)/,?.\n$><<$_\n\n", "lang_cluster": "Ruby", "tags": ["expression parsing", "implementation"], "code_uid": "0153bffd5503a69e3ab42d469300debf", "src_uid": "a11c9679d8e2dca51be17d466202df6e", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = gets.chomp.to_s\nwhile !!(s =~ /(.)dot(.)/m)\n\ts = s.gsub(/(.)dot(.)/m,'\\1.\\2')\nend\ns = s.sub(/(.)at(.)/m,'\\1@\\2')\nputs s", "lang_cluster": "Ruby", "tags": ["expression parsing", "implementation"], "code_uid": "021ae44001571bbea1fa4a92ec25ac57", "src_uid": "a11c9679d8e2dca51be17d466202df6e", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "gets\n$_.sub! /(?!^)at/,?@\n$_.gsub! /(?!^)dot(?!$)/,?.\n$><<$_\n", "lang_cluster": "Ruby", "tags": ["expression parsing", "implementation"], "code_uid": "b17cdc6905c30dbba23be1a4ba7e5585", "src_uid": "a11c9679d8e2dca51be17d466202df6e", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def run\n x, y, m = $stdin.gets.split.map(&:to_i)\n x, y = [x, y].sort\n\n if y >= m\n puts \"0\"\n elsif x <= 0 and y <= 0 and m > y\n puts \"-1\"\n else\n cnt = 0\n if x + y < 0\n cnt = (x / y).abs + 1\n x += y * cnt\n end\n\n while [x, y].max < m\n x > y ? y += x : x += y\n cnt += 1\n end\n\n puts cnt\n end\nend\n\nrun if $0 == __FILE__\n", "lang_cluster": "Ruby", "tags": ["brute force"], "code_uid": "e71b959b481b2eb911b4feaa52f5d696", "src_uid": "82026a3c3d9a6bda2e2ac6e14979d821", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def dfs(x, y, m, step)\n if x >= m || y >= m\n puts step\n return\n end\n dfs(y, x + y, m, step + 1)\nend\ndef cal(x, y, m)\n x, y = [x, y].min, y = [x, y].max\n if x < 0\n to_positive = x.abs / y + 1\n dfs(x + to_positive * y, y, m, to_positive)\n else\n dfs(x, y, m, 0)\n end\nend\nx, y, m = gets.split(' ').map(&:to_i)\nif x >= m || y >= m\n puts 0\nelsif x + y <= x && x + y <= y\n puts -1\nelse\n cal(x, y, m)\nend", "lang_cluster": "Ruby", "tags": ["math", "greedy"], "code_uid": "09b7414e7e48aefddc0611f8f2f1d572", "src_uid": "82026a3c3d9a6bda2e2ac6e14979d821", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def dfs(x, y, m, step)\n if x >= m || y >= m\n puts step\n return\n end\n dfs(x, x + y, m, step + 1) if x >= y\n dfs(x + y, y, m, step + 1) if y > x\nend\n\ndef cal(x, y, m)\n if x < y && x < 0\n to_positive = x.abs / y + 1\n to_m = (m - x) / y\n to_m += 1 if (m - x) % y != 0\n if to_m <= to_positive\n puts to_m\n else\n dfs(x + to_positive * y, y, m, to_positive)\n end\n elsif y < x && y < 0\n to_positive = y.abs / x + 1\n to_m = (m - y) / x\n to_m += 1 if (m - y) % x != 0\n if to_m <= to_positive\n puts to_m\n else\n dfs(x, y + to_positive * x, m, to_positive)\n end\n else\n dfs(x, y, m, 0)\n end\nend\n\nx, y, m = gets.split(' ').map(&:to_i)\nif x >= m || y >= m\n puts 0\nelsif x + y <= x && x + y <= y\n puts -1\nelse\n cal(x, y, m)\nend", "lang_cluster": "Ruby", "tags": ["math", "greedy"], "code_uid": "6204d5938d38dc9b994727bf261890af", "src_uid": "82026a3c3d9a6bda2e2ac6e14979d821", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "p gets.to_i/2520", "lang_cluster": "Ruby", "tags": ["math", "number theory"], "code_uid": "400e36eb6f96a3116bdcd64c42d07221", "src_uid": "8551308e5ff435e0fc507b89a912408a", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.chomp.to_i\n\nputs (n / 2520).to_i", "lang_cluster": "Ruby", "tags": ["math", "number theory"], "code_uid": "dd034e78960fb1c18b194db08c8db063", "src_uid": "8551308e5ff435e0fc507b89a912408a", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "p gets.to_i/2520\n", "lang_cluster": "Ruby", "tags": ["math", "number theory"], "code_uid": "d1a188cfc11dfe385939f3a341019260", "src_uid": "8551308e5ff435e0fc507b89a912408a", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a, b, m, r0 = gets.split.map{|i| i.to_i}\ns = Array.new(100000, 0)\nt = 1\nr = r0\nwhile s[r] == 0\n s[r] = t\n t += 1\n r = (a * r + b) % m\nend\nputs t - s[r]\n", "lang_cluster": "Ruby", "tags": ["implementation", "number theory"], "code_uid": "dba9c7683cedda1fa3a69e7c73efed2f", "src_uid": "9137197ee1b781cd5cc77c46f50b9012", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b,m,r = gets.split.map &:to_i\nar = [nil]*100000\ni = 0\nwhile true \n r = (a*r+b)%m\n if ar[r]\n p i-ar[r]\n exit\n end \n ar[r] = i\n i += 1\nend\n", "lang_cluster": "Ruby", "tags": ["implementation", "number theory"], "code_uid": "edc35e931c13df2da2c0bfd8c06c93c0", "src_uid": "9137197ee1b781cd5cc77c46f50b9012", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b,m,r = gets.split.map &:to_i\nt = [0]*m\nwhile t[r] != 3\n\tt[r = (a*r+b)%m] += 1\nend\n\nputs 1+t.count(2)", "lang_cluster": "Ruby", "tags": ["implementation", "number theory"], "code_uid": "80a26b6a9914d542ab294d8d0b8f47a9", "src_uid": "9137197ee1b781cd5cc77c46f50b9012", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "input_string = gets.chomp\nstring_length= input_string.length\nstring_array = Array.new\nstring_length_temp = 0\nres_string = \".\"\nwhile string_length_temp < string_length do\n\ncase input_string.split(\"\").at(string_length_temp)\nwhen \"O\",\"Y\",\"E\",\"U\",\"I\",\"A\",\"o\",\"y\",\"e\",\"u\",\"i\",\"a\"\n string_length_temp+=1\n else\n res_string = res_string + input_string.split(\"\").at(string_length_temp) + \".\"\n string_length_temp+=1\n end\n\nend\nres_string[res_string.length-1]=\"\"\n\nprint res_string.downcase+\"\\n\"\n", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "ce57e51b6b8ccc473076f89941754438", "src_uid": "db9520e85b3e9186dd3a09ff8d1e8c1b", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a=gets.chomp\nb=a.dup\na.scan(/([aoieuyAOIEUY])|(.)/) do\n if $1\n b.sub!(/#{$1}/,\"\")\n else b.sub!(/(?='A'||c[i]<='Z'\nprint \".#{c[i].downcase}\"\nelse\n print \".#{c[i]}\"\nend\nend", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "4f8ecf6b95f31a44a3dc872f19e44b66", "src_uid": "db9520e85b3e9186dd3a09ff8d1e8c1b", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a=(1..400).to_a\na=a.join\nputs \"#{a[gets.chomp.to_i-1]}\"", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "0a73df39d6317d258ea492242efe5744", "src_uid": "2d46e34839261eda822f0c23c6e19121", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = readline.to_i - 1\n1.upto(1000) do |i|\n s = i.to_s\n if s.length <= n\n n -= s.length\n else\n puts s[n]\n break\n end\nend\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "8a1c9abf75e288af504b05aed476a2f8", "src_uid": "2d46e34839261eda822f0c23c6e19121", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.to_i\nfor i in 1..1000\n\tx=i\n\tif n<=x.to_s.length\n\t\tputs x.to_s[n-1]\n\t\tbreak\n\telse\n\t\tn-=x.to_s.length\n\tend\nend", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "76a34e6d620f6e8ccbe721ddc32548ba", "src_uid": "2d46e34839261eda822f0c23c6e19121", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "dx = [0, 1, 0, -1, 0]\ndy = [0, 0, -1, 0, 1]\n\ns = Array.new(3){ Array.new(3, 0) }\n\n3.times do |i|\n \n r = gets.split.map(&:to_i)\n \n 3.times do |j|\n \n 5.times do |k|\n \n x = i + dx[k]\n y = j + dy[k] \n s[x][y] += r[j] if ( 0 <= x && x < 3 && 0 <= y && y < 3 )\n \n end\n end\nend\n\ns.each do |r|\n r.each do |l|\n print (l+1) % 2\n end\n puts \"\"\nend\n \n ", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "6e22e96baed0af505c4608e01ed495b5", "src_uid": "b045abf40c75bb66a80fd6148ecc5bd6", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "# lamer code!!\n\na,b,c = gets.chomp.split(\" \")\nd,e,f = gets.chomp.split(\" \")\ng,h,i = gets.chomp.split(\" \")\n\na = a.to_i.%(2)\nb = b.to_i.%(2)\nc = c.to_i.%(2)\nd = d.to_i.%(2)\ne = e.to_i.%(2)\nf = f.to_i.%(2)\ng = g.to_i.%(2)\nh = h.to_i.%(2)\ni = i.to_i.%(2)\n\na1=(a+b+d+1)%2\nb1=(a+b+c+e+1)%2\nc1=(b+c+f+1)%2\nd1=(a+d+e+g+1)%2\ne1=(b+d+e+f+h+1)%2\nf1=(c+e+f+i+1)%2\ng1=(d+g+h+1)%2\nh1=(e+g+h+i+1)%2\ni1=(f+h+i+1)%2\n\nputs a1.to_s+b1.to_s+c1.to_s\nputs d1.to_s+e1.to_s+f1.to_s\nputs g1.to_s+h1.to_s+i1.to_s", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "cbb06b80aba1790db0d8363b9e389cc0", "src_uid": "b045abf40c75bb66a80fd6148ecc5bd6", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a=Array.new(3);\n@b=Array.new(3,1);\nfor i in 0..2 do\n a[i]=gets().split.map{|e| e.to_i%2};\n @b[i]=Array.new(3,1);\nend\n\ndef f(x,y)\n if (x>0) then @b[x-1][y]=(@b[x-1][y]+1)%2 end\n if (x<2) then @b[x+1][y]=(@b[x+1][y]+1)%2 end\n if (y>0) then @b[x][y-1]=(@b[x][y-1]+1)%2 end\n if (y<2) then @b[x][y+1]=(@b[x][y+1]+1)%2 end\n @b[x][y]=(@b[x][y]+1)%2\nend\n \nfor i in 0..2 do\n for j in 0..2 do\n if (a[i][j]==1) then f(i,j) end\n end\nend\n\nfor i in 0..2 do\n for j in 0..2 do\n print @b[i][j]\n end\n puts\nend", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "aca717214f0c7b2d050bffcb183ef45c", "src_uid": "b045abf40c75bb66a80fd6148ecc5bd6", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\nxx = []\nyy = []\nn.times do\n x, y = gets.split.map(&:to_i)\n xx << x\n yy << y\nend\nxx.sort!\nyy.sort!\nans = (xx[-1] - xx[0]) * (yy[-1] - yy[0])\nputs ans > 0? ans : -1\n", "lang_cluster": "Ruby", "tags": ["geometry", "implementation"], "code_uid": "56df439004034e077318a5f426c1caac", "src_uid": "ba49b6c001bb472635f14ec62233210e", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "# http://codeforces.com/contest/596/problem/A\nn = gets.chomp.to_i\npoints = [].tap do |a|\n n.times { a << gets.chomp.split.map(&:to_i) }\nend\n\nif n == 1\n puts -1\nelsif n == 2\n if points.map(&:first).uniq.length == 1 || points.map(&:last).uniq.length == 1\n puts -1\n else\n puts (points[0][0] - points[1][0]).abs * (points[0][1] - points[1][1]).abs\n end\nelse\n x = points.map(&:first).uniq\n y = points.map(&:last).uniq\n puts (x[0] - x[1]).abs * (y[0] - y[1]).abs\nend\n", "lang_cluster": "Ruby", "tags": ["geometry", "implementation"], "code_uid": "6a8378e8adb09e79095940624a009329", "src_uid": "ba49b6c001bb472635f14ec62233210e", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def solve(a)\n xs = a.map(&:first)\n ys = a.map(&:last)\n xus = xs.uniq\n return -1 unless xus.size == 2\n yus = ys.uniq\n return -1 unless yus.size == 2\n\n x1, x2 = *xus\n y1, y2 = *yus\n s = ((x1-x2) * (y1-y2)).abs\n s > 0 ? s : -1\nend\n\nn = gets.to_i\na = Array.new(n) do\n gets.split.map(&:to_i)\nend\n\nputs solve(a)\n", "lang_cluster": "Ruby", "tags": ["geometry", "implementation"], "code_uid": "93e2dad5d5ab0a0f26772767885d8dda", "src_uid": "ba49b6c001bb472635f14ec62233210e", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def love(s)\n\twhile \"love\" == \"love\"\n\t\ta = s.scan('a').length\n\t\tothers = s.scan(/[b-z]/).length\n\t\tif a > others then return s.length else s = s.sub(/[b-z]/, '') end\n\tend\nend\n\ns = gets.chomp\nputs(love(s))", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "d3ac351e164e55c6a85824bb21e876fb", "src_uid": "84cb9ad2ae3ba7e912920d7feb4f6219", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = gets.chomp\np (s.length+1)/2 < s.count(\"a\") ? s.length : s.count(\"a\")*2-1", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "007a576308d686277cde1f1220fdfa58", "src_uid": "84cb9ad2ae3ba7e912920d7feb4f6219", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = gets.chomp\nacnt = s.count(\"a\")\nif acnt > s.length / 2 then\n\tputs s.length\nelse\n\tputs 2 * acnt - 1\nend\n\n", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "dff4cee75f692c787e504950eaf1dc8e", "src_uid": "84cb9ad2ae3ba7e912920d7feb4f6219", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "h, m = gets.split(':').map &:to_i\n\nloop do\n m += 1\n h += 1 if m > 59\n h = 0 if h > 23\n m = 0 if m > 59\n\n break :b if (\"%02d\" % h) == (\"%02d\" % m).to_s.reverse\nend\n\nprint [(\"%02d\" % h), (\"%02d\" % m)].join ':'\n", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "9ab4867319c05605419416fa4cc79a7d", "src_uid": "158eae916daa3e0162d4eac0426fa87f", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "\ndef toMin arg\n arg[0].to_i*60 + arg[1].to_i\nend\narg = STDIN.gets.split(\":\")\n\nnow = toMin(arg)\ncand = toMin([arg[0],arg[0].reverse])\nif cand > now and arg[0].reverse.to_i < 60\n puts sprintf(\"%02d:%02d\",arg[0].to_i,arg[0].reverse.to_i)\n exit 0\nelse\n begin\n arg[0] = sprintf(\"%02d\",((arg[0].to_i + 1) % 24))\n\n cand = toMin([arg[0],arg[0].reverse])\n if ( cand > now and arg[0].reverse.to_i < 60)\n puts sprintf(\"%02d:%02d\",arg[0].to_i,arg[0].reverse.to_i)\n exit 0\n end\n end while (arg[0].to_i > 0)\n puts \"00:00\"\nend\n", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "fa16d7587ccabda7d04cbd984ca05b8e", "src_uid": "158eae916daa3e0162d4eac0426fa87f", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "h,m=gets.split(':').map &:to_i;s=0;loop{m=m.succ%60;h=h.succ%24 if m==0;s=\"%02d:%02d\"%[h,m];break if s==s.reverse};puts s", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "166c123616c8747dd00dab77eb4242f4", "src_uid": "158eae916daa3e0162d4eac0426fa87f", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "username = gets.chomp\nputs (username.split(//).uniq.length % 2 == 1)? \"IGNORE HIM!\" : \"CHAT WITH HER!\"\n", "lang_cluster": "Ruby", "tags": ["brute force", "strings", "implementation"], "code_uid": "92d2dcb93243bf7bf1038606bfe1d369", "src_uid": "a8c14667b94b40da087501fd4bdd7818", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "puts gets.chomp.chars.uniq.size % 2 == 0 ? \"CHAT WITH HER!\" : \"IGNORE HIM!\"\n", "lang_cluster": "Ruby", "tags": ["brute force", "strings", "implementation"], "code_uid": "0ddae4df09690574c9569451b3d1fb66", "src_uid": "a8c14667b94b40da087501fd4bdd7818", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "printf(gets.chomp.each_char.to_a.uniq.size.odd? ? 'IGNORE HIM!' : 'CHAT WITH HER!')", "lang_cluster": "Ruby", "tags": ["brute force", "strings", "implementation"], "code_uid": "3fcf9249b1685cd33d54e939b16778e4", "src_uid": "a8c14667b94b40da087501fd4bdd7818", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a=gets.split.collect{|s|s.to_i}\n m=0\nfor i in 0..13\n b=a.collect{|s|s}\n k=b[i]\n b[i]=0\n kd=k/14\n km=k%14\n res=0\n for j in 1..14\n b[(i+j)%14]+=((j<=km) ? kd+1:kd)\n end\n for j in 0..13\n if(b[j]%2==0)\n res+=b[j]\n end\n end\n if res>m\n m=res\n end\nend\nputs m", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "df6e22ad5f09ca28edcfe61bcad10bca", "src_uid": "1ac11153e35509e755ea15f1d57d156b", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def solve(idx, b)\n a = Array.new(b)\n if a[idx] == 0\n return -1\n end\n num = a[idx] / 14\n (a[idx] % 14).times do |i|\n a[(idx + i + 1) % 14] += 1\n end\n a[idx] = 0\n res = 0\n 14.times do |i|\n a[i] += num\n if a[i] % 2 == 0\n res += a[i]\n end\n end\n return res\nend\n \na = gets.split.map(&:to_i)\nans = 0\n14.times do |i|\n ans = [ans, solve(i, a)].max\nend\nputs ans", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "88d17cfdf023d6923becdb3a508cf444", "src_uid": "1ac11153e35509e755ea15f1d57d156b", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s=gets\n[[?>,\"1000\"],[?<,\"1001\"],[?+,\"1010\"],[?-,\"1011\"],[?.,\"1100\"],[?,,\"1101\"],[?[,\"1110\"],[?],\"1111\"]].each{|pattern,replace|s.gsub!(pattern,replace)}\np s.to_i(2)%1000003", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "f4fb7a262728e09ea2950e07227d04ac", "src_uid": "04fc8dfb856056f35d296402ad1b2da1", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "\nhash={\"+\"=>\"1010\",\">\"=>\"1000\",\"<\"=>\"1001\",\"-\"=>\"1011\",\".\"=>\"1100\",\",\"=>\"1101\",\"[\"=>\"1110\",\"]\"=>\"1111\"}\nprogram=gets.split[0]\nans=\"\"\n0.upto(program.length-1){|i|\n ans+=hash[program[i]]\n}\np ans.to_i(2)%1000003\n\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "f2aade6a46b286e39bfd2f05f897876a", "src_uid": "04fc8dfb856056f35d296402ad1b2da1", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "line = STDIN.gets\nline.chomp!\nnum = 0\nline.each_char { |c|\n num *= 16\n case c\n when '>'\n num += 0b1000\n when '<'\n num += 0b1001\n when '+'\n num += 0b1010\n when '-'\n num += 0b1011\n when '.'\n num += 0b1100\n when ','\n num += 0b1101\n when '['\n num += 0b1110\n when ']'\n num += 0b1111\n end\n}\n\nprint num % 1000003\n\n ", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "d27fd41ef011fab9b44ab38b78dd0f85", "src_uid": "04fc8dfb856056f35d296402ad1b2da1", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/ruby\ns=gets.chomp\nprintf(\"%0#{s.size}b\",s.to_i(2)^gets.to_i(2))", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "36d9e1a051ece7a6b0bbb7f2a5b28a47", "src_uid": "3714b7596a6b48ca5b7a346f60d90549", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "as=gets.chomp\nbs=gets.chomp\n0.upto(as.length-1) do |i|\nif as[i]==bs[i]\nprintf \"0\"\nelse\nprintf \"1\"\nend\nend", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "adf985f8a09cdd9641ec52d1fb8ca2c1", "src_uid": "3714b7596a6b48ca5b7a346f60d90549", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a = gets.chomp\nb = gets.chomp\n\na.length.times do |index|\n print ((a[index, 1].to_i == b[index,1].to_i) ? \"0\": \"1\")\nend", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "b545f143ad854c97a424f69366e57639", "src_uid": "3714b7596a6b48ca5b7a346f60d90549", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def get_div_5(n, m)\n lasts = [[1, 4], [2, 4], [3, 4], [3, 3], [4, 4]]\n l2 = n * m / 5.0\n\n if (lasts.include?([n % 5, m % 5]) || lasts.include?([m % 5, n % 5])) && l2 % 1 != 0\n l2 += 1\n end\n\n l2.floor\nend\n\n\nb = gets\n\nb = b.strip.split(\" \").map {|v| v.to_i}\nputs get_div_5(b[0], b[1])\n", "lang_cluster": "Ruby", "tags": ["math", "constructive algorithms", "number theory"], "code_uid": "7eb7744dda4b0c7865908dc6c85df9c9", "src_uid": "df0879635b59e141c839d9599abd77d2", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,m=gets.split.map(&:to_i)\np (1..n).reduce(0){|s,i|s+(m+i%5)/5}", "lang_cluster": "Ruby", "tags": ["math", "constructive algorithms", "number theory"], "code_uid": "162b115345648b16ffea274db78dd118", "src_uid": "df0879635b59e141c839d9599abd77d2", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "x,y=gets.split.map{|e| e.to_i}\nx,y=[x,y].min,[x,y].max\nz=x+y\nans=0\n4.step(z,5){|i|\n\tif i>y then\n\t\tans+=(x-(i-y))\n\telse\n\t\tans+=[x,i].min\n\tend\n}\nputs ans\n\n", "lang_cluster": "Ruby", "tags": ["math", "constructive algorithms", "number theory"], "code_uid": "b943394a9dba08594809a6bf3a1a3151", "src_uid": "df0879635b59e141c839d9599abd77d2", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "f=r=z=0;q=1;1.upto(gets.to_i){f+=gets.to_i;r+=1;f*q maxavg\nend\n\nputs maxavg", "lang_cluster": "Ruby", "tags": ["implementation", "trees", "graph matchings"], "code_uid": "46f44d6c99ba0da750877ccfdfb72d5e", "src_uid": "32fc378a310ca15598377f7b638eaf26", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def max(a,b)\n a > b ? a : b\nend\n\nTUX = gets.to_i\nFOO = 0\nBAR = 0\nBAZ = 0\nQUZ = 1\nTUX.times {\n PUR = gets.to_i\n FOO = FOO + PUR\n BAR = BAR + 1\n if max(FOO * QUZ, BAR * BAZ) == FOO * QUZ then\n BAZ = FOO\n QUZ = BAR\n end\n}\np BAZ * 1.0 / QUZ\n", "lang_cluster": "Ruby", "tags": ["implementation", "trees", "graph matchings"], "code_uid": "3bb69ce2ef075968dd7166cb33479de9", "src_uid": "32fc378a310ca15598377f7b638eaf26", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/ruby\n\ntux = gets.to_i\nfoo = 0\nbar = 0\nbaz = 0\nquz = 1\nit = false\ntux.times do\n pur = gets.to_i\n foo = foo + pur\n bar = bar + 1\n it = [foo*quz, bar*baz].max == foo*quz\n if it\n baz = foo\n quz = bar\n end\nend\n\nprintf(\"%.10f\\n\", baz/quz.to_f)\n", "lang_cluster": "Ruby", "tags": ["implementation", "trees", "graph matchings"], "code_uid": "08df3a787e174d03d38728587d60acf7", "src_uid": "32fc378a310ca15598377f7b638eaf26", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "f=0;p 1.upto(gets.to_i).map{|r|(f+=gets.to_f)/r}.max\n", "lang_cluster": "Ruby", "tags": ["implementation", "trees", "graph matchings"], "code_uid": "0177f0be5fc6c102d150ca5bee2657c3", "src_uid": "32fc378a310ca15598377f7b638eaf26", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/ruby\nr=w=0.0\ngets.to_i.times{|i|\n\tw+=1 if gets.to_i==1\n\tr=[r,w/-~i].max\n}\np r", "lang_cluster": "Ruby", "tags": ["implementation", "trees", "graph matchings"], "code_uid": "16149b945ae906709a037968bec90121", "src_uid": "32fc378a310ca15598377f7b638eaf26", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "tux = $stdin.gets.chomp.to_i\n\nfoo = 0\nbar = 0\nbaz = 0\nquz = 1\n\nnums = []\n\ntux.times do\n pur = $stdin.gets.chomp.to_i\n foo += pur\n bar += 1\n\n if foo*quz >= bar*baz \n baz = foo\n quz = bar\n end\nend\n\nputs sprintf(\"%0.6f\", baz/quz.to_f)", "lang_cluster": "Ruby", "tags": ["implementation", "trees", "graph matchings"], "code_uid": "9f8dc2f3cd7e5fc09cacc8404a03bcbe", "src_uid": "32fc378a310ca15598377f7b638eaf26", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "f=0;p 1.upto(gets.to_i).map{|r|(f+=gets.to_f)/r}.max\n", "lang_cluster": "Ruby", "tags": ["implementation", "trees", "graph matchings"], "code_uid": "e377bcdddd95200c9512ee2595067549", "src_uid": "32fc378a310ca15598377f7b638eaf26", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "f=0;p 1.upto(gets.to_i).map{|r|(f+=gets.to_f)/r}.max", "lang_cluster": "Ruby", "tags": ["implementation", "trees", "graph matchings"], "code_uid": "7d8070f9c4bf0c93ffa23ebf34ca9bce", "src_uid": "32fc378a310ca15598377f7b638eaf26", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "foo,bar,baz,quz=0,0,0,1\ngets.to_i.times do\n foo+=gets.to_i\n bar+=1\n if foo*quz>baz*bar\n baz=foo\n quz=bar\n end\nend\nputs '%.6f'%(baz*1.0/quz)", "lang_cluster": "Ruby", "tags": ["implementation", "trees", "graph matchings"], "code_uid": "70634bd7564f630b42f591baeae338f1", "src_uid": "32fc378a310ca15598377f7b638eaf26", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "f=0;p 1.upto(gets.to_i).map{|r|(f+=gets.to_f)/r}.max\n", "lang_cluster": "Ruby", "tags": ["implementation", "trees", "graph matchings"], "code_uid": "8d5cba629e58147da4374718f03e5b71", "src_uid": "32fc378a310ca15598377f7b638eaf26", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "tux = gets.to_i\nfoo = 0\nbar = 0\nbaz = 0\nquz = 1\n\ntux.downto(1) do\n pur = gets.to_i\n foo = foo+pur\n bar = bar+1\n if foo*quz >= bar*baz\n baz = foo\n\tquz = bar\n end\nend\n\nbaz = baz.to_f\n\nputs baz/quz\n", "lang_cluster": "Ruby", "tags": ["implementation", "trees", "graph matchings"], "code_uid": "ece0d448c19b2863b537d1c132f03790", "src_uid": "32fc378a310ca15598377f7b638eaf26", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "foo = 0\nbar = 0\nbaz = 0\nquz = 1\ntux = gets.to_i\nwhile tux!=0\npur =gets.to_i\nfoo = foo + pur\nbar = bar + 1\nif bar*baz 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", "lang_cluster": "Ruby", "tags": ["brute force", "math", "binary search"], "code_uid": "790cbc747bcf2563ed901717d905b759", "src_uid": "17b5ec1c6263ef63c668c2b903db1d77", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "$><<(7-gets.split.max.to_i.to_r)/6", "lang_cluster": "Ruby", "tags": ["math", "probabilities"], "code_uid": "f6bf1cfab3a6337f3c9ab51b2629252c", "src_uid": "f97eb4ecffb6cbc8679f0c621fd59414", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "require 'rational'\nputs( (7-gets().chomp!.split(\" \").max.to_i)/6.to_r )\n", "lang_cluster": "Ruby", "tags": ["math", "probabilities"], "code_uid": "220a62be60d2c0fc17177cc36dc93440", "src_uid": "f97eb4ecffb6cbc8679f0c621fd59414", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/ruby\nrequire \"rational\"\nm=gets.chomp.split(\" \").map!{|i|i=i.to_i}.max\nputs m==1?\"1/1\":Rational(7-m,6)\n", "lang_cluster": "Ruby", "tags": ["math", "probabilities"], "code_uid": "6041dd15037acf0e5e9afb4a5e56f143", "src_uid": "f97eb4ecffb6cbc8679f0c621fd59414", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "$><<(7-gets.split.max.to_i.to_r)/6\n", "lang_cluster": "Ruby", "tags": ["math", "probabilities"], "code_uid": "416774179838e30e3f84ad5bc333c616", "src_uid": "f97eb4ecffb6cbc8679f0c621fd59414", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "yw = readline.split(' ').map(&:to_i).max\nc = 7-yw\nd = 6\n2.upto(5) do |x|\n if c%x==0 && d%x==0\n c/=x\n d/=x\n end\nend\nputs \"#{c}/#{d}\"\n", "lang_cluster": "Ruby", "tags": ["math", "probabilities"], "code_uid": "0131128ab333b9df29c731cf28384746", "src_uid": "f97eb4ecffb6cbc8679f0c621fd59414", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\nyw = gets.split.map(&:to_i)\nhighest_score_for_now = yw.max\n# an ordinary six-side die: 1,2,3,4,5,6\n# numerator(\ubd84\uc790): one of aboves\n# denominator(\ubd84\ubaa8): 6\nnumerator, denominator = 6 - highest_score_for_now + 1, 6 #handling equality\n\n[2, 3].each { |i|\n if numerator%i == 0 && denominator%i == 0\n numerator /= i\n denominator /= i\n end\n}\n\nputs \"#{numerator}/#{denominator}\"\n", "lang_cluster": "Ruby", "tags": ["math", "probabilities"], "code_uid": "bafb49ec9e0cb1f960f87bb8e061b8ec", "src_uid": "f97eb4ecffb6cbc8679f0c621fd59414", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, m = gets.split.map(&:to_i)\np = %w(1/6 1/3 1/2 2/3 5/6 1/1)\nputs p[6 - [n, m].max]", "lang_cluster": "Ruby", "tags": ["math", "probabilities"], "code_uid": "a22dc3cf30cc51e2f474d74d64150a84", "src_uid": "f97eb4ecffb6cbc8679f0c621fd59414", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "puts (7-gets.split.max.to_i)/6.to_r\n", "lang_cluster": "Ruby", "tags": ["math", "probabilities"], "code_uid": "8bdda94d31cc4a985bff3367762d9a23", "src_uid": "f97eb4ecffb6cbc8679f0c621fd59414", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a = gets.split(\" \").map{|i|i.to_i}.max\nu = 7-a\nd = 6\nf = u.gcd(d)\nu/=f\nd/=f\nputs \"#{u}/#{d}\"", "lang_cluster": "Ruby", "tags": ["math", "probabilities"], "code_uid": "7314ad75fc5636ebdf41fb21e4e490a0", "src_uid": "f97eb4ecffb6cbc8679f0c621fd59414", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "print (7-gets.split.max.to_i.to_r)/6", "lang_cluster": "Ruby", "tags": ["math", "probabilities"], "code_uid": "bf67ffc95744ce92b4241a5d907b9310", "src_uid": "f97eb4ecffb6cbc8679f0c621fd59414", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = 6 - gets.split.map(&:to_i).max + 1\ncase s\n when 0\n puts '0/1'\n when 1\n puts '1/6'\n when 2, 3\n puts \"#{1}/#{6 / s}\"\n when 4\n puts '2/3'\n when 5\n puts '5/6'\n when 6\n puts '1/1'\nend\n", "lang_cluster": "Ruby", "tags": ["math", "probabilities"], "code_uid": "f05d0b6da0f386ef6ed0ce640d142b40", "src_uid": "f97eb4ecffb6cbc8679f0c621fd59414", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "y,w=gets.split.map(&:to_i)\nputs \"#{6-[y,w].max+1}/6\".to_r\n", "lang_cluster": "Ruby", "tags": ["math", "probabilities"], "code_uid": "55c12769451e5972301b91f4b8d8c8c3", "src_uid": "f97eb4ecffb6cbc8679f0c621fd59414", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "puts Rational(7-gets.split.map{|i|i.to_i}.max,6)", "lang_cluster": "Ruby", "tags": ["math", "probabilities"], "code_uid": "54929615c6855fa96f63aa6464b8dce3", "src_uid": "f97eb4ecffb6cbc8679f0c621fd59414", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "# $stdin = File.open('in')\nputs (7-gets.split.max.to_i)/6.to_r", "lang_cluster": "Ruby", "tags": ["math", "probabilities"], "code_uid": "2cc01450ebba80becad27a2e3508dcc2", "src_uid": "f97eb4ecffb6cbc8679f0c621fd59414", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "$><<(7-gets.split.max.to_i.to_r)/6\n", "lang_cluster": "Ruby", "tags": ["math", "probabilities"], "code_uid": "5dac6df73555b04143aa8d18ecefb463", "src_uid": "f97eb4ecffb6cbc8679f0c621fd59414", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a=gets.chomp.split(\" \").sort\nb=6-a[1].to_i + 1\nif b==2\nputs \"1/3\"\nelsif b==3\nputs \"1/2\"\nelsif b==4\nputs \"2/3\"\nelsif b==6\nputs \"1/1\"\nelse \nputs \"#{b}/6\"\nend", "lang_cluster": "Ruby", "tags": ["math", "probabilities"], "code_uid": "7c25e2867de7e59d1601be5e9c083972", "src_uid": "f97eb4ecffb6cbc8679f0c621fd59414", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def gcd a, b\n\treturn a if b == 0\n\tgcd b, a % b\nend\n\ny, w = gets.split.map { |x| x.to_i }\n\na = 6 - [y, w].max + 1\nb = 6\ng = gcd a, b\nputs [a / g, b / g].join '/'\n", "lang_cluster": "Ruby", "tags": ["math", "probabilities"], "code_uid": "59b06cc2a016964af46912c8bf225615", "src_uid": "f97eb4ecffb6cbc8679f0c621fd59414", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "$><<(7-gets.split.max.to_i.to_r)/6", "lang_cluster": "Ruby", "tags": ["math", "probabilities"], "code_uid": "aed5f0d7f3692213a5c37501787f67f7", "src_uid": "f97eb4ecffb6cbc8679f0c621fd59414", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "# 09 A\ndef gcd(a, b)\n while b != 0 do\n c = a % b\n a = b\n b = c\n end\n return a;\nend\n\nnum = gets.split.map(&:to_i)\nrem = 6 + 1 - num.max;\nc = gcd(6, rem)\n\nprint rem/c, \"/\", 6/c\nputs\n\n", "lang_cluster": "Ruby", "tags": ["math", "probabilities"], "code_uid": "fd3ba02670beb7d5f7b18b2ab74ef8ca", "src_uid": "f97eb4ecffb6cbc8679f0c621fd59414", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "$><<(7-gets.split.max.to_i.to_r)/6", "lang_cluster": "Ruby", "tags": ["math", "probabilities"], "code_uid": "df96dbb07b9bd046c32cc4b20e56ccfb", "src_uid": "f97eb4ecffb6cbc8679f0c621fd59414", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "min = gets().chomp!.split(\" \").max {|a, b| a.to_i <=> b.to_i}.to_i - 1\ncase min \n when 0 then puts( \"1/1\" )\n when 1 then puts( \"5/6\" )\n when 2 then puts( \"2/3\" )\n when 3 then puts( \"1/2\" )\n when 4 then puts( \"1/3\" )\n when 5 then puts( \"1/6\" )\nend\n", "lang_cluster": "Ruby", "tags": ["math", "probabilities"], "code_uid": "c06cb476d47bd99176189b5bef793690", "src_uid": "f97eb4ecffb6cbc8679f0c621fd59414", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a=gets.chomp.split(\" \").sort\nb=6-a[1].to_i + 1\nif b==2\nputs \"1/3\"\nelsif b==3\nputs \"1/2\"\nelsif b==4\nputs \"2/3\"\nelsif b==6\nputs \"1/1\"\nelse \nputs \"#{b}/6\"\nend\n", "lang_cluster": "Ruby", "tags": ["math", "probabilities"], "code_uid": "e7489aa44780bb11ded6e2e9529af597", "src_uid": "f97eb4ecffb6cbc8679f0c621fd59414", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def norm(arr)\n 6.downto(1) do |x|\n arr = arr.map { |e| e / x } if arr.all? { |e| e.modulo(x).zero? }\n end\n\n arr\nend\n\nputs norm([(gets.split(' ').map(&:to_i).max..6).size, 6]).join('/')\n", "lang_cluster": "Ruby", "tags": ["math", "probabilities"], "code_uid": "5cefc0cb9fec8f9e497178d99d71c88d", "src_uid": "f97eb4ecffb6cbc8679f0c621fd59414", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "y,w = gets.chomp.split(/ /).map!{|x| x.to_i}\nyw = [y,w].max\n\nc = (6-(yw-1))\nd = c.gcd(6)\nc = c/d\nm = 6/d\nputs c.to_s + \"/\" + m.to_s\n", "lang_cluster": "Ruby", "tags": ["math", "probabilities"], "code_uid": "c85d657d58fce6253a1ab2da63165a48", "src_uid": "f97eb4ecffb6cbc8679f0c621fd59414", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["dp", "games"], "code_uid": "5ff0da0926a43acc87b076cf9c2dd795", "src_uid": "414540223db9d4cfcec6a973179a0216", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\n\npiece = gets.split.map{|x| x.to_i}\n\nbob = alice = 0\n\n1.upto(n) do |i|\n\tbob, alice = piece[-i] + alice, bob\n\tbob, alice = alice, bob if bob < alice\nend\n\nprint alice, \" \", bob", "lang_cluster": "Ruby", "tags": ["dp", "games"], "code_uid": "a14727a5beebf08717d7cce51a6e3c96", "src_uid": "414540223db9d4cfcec6a973179a0216", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "x,t,a,b,da,db=gets.split.map(&:to_i)\nyes=false\nyes=true if x==0\nt.times do |i|\n t.times do |j|\n if a-da*i+b-db*j==x or a-da*i==x or b-db*j==x\n yes=true\n end\n end\nend\nif yes then puts \"YES\"\nelse puts \"NO\"\nend", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "7c7a6f17c16ff3275b16df58af36d020", "src_uid": "f98168cdd72369303b82b5a7ac45c3af", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "\ufeff# codeforce#128(Div2.A)\n\ndef solve(x, t, a, b, d1, d2)\n for i in 0 .. (t - 1) do\n for j in 0 .. (t - 1) do\n if x == (a - i * d1 + b - j * d2)\n return \"YES\"\n end\n \n if (x == 0) or (x == (a - i * d1)) or (x == (b - j * d2)) \n return \"YES\"\n end\n end \n end\n return \"NO\"\nend\n\nx, t, a, b, d1, d2 = gets.chomp.split(\" \").map{|e| e.to_i}\n\nputs solve(x, t, a, b, d1, d2)\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "54c4138ae2960c2c79e342731052991d", "src_uid": "f98168cdd72369303b82b5a7ac45c3af", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a=gets.chomp.split(\" \")\nt=0\n0.upto(6) {|i| a[i]=a[i].to_i }\n0.upto(a[1]-1) do |i|\n0.upto(a[1]-1) do |j|\nnum=a[2]+a[3]-a[4]*i-a[5]*j\nif num==a[0]\nt=1\nbreak\nend\nend\nbreak if t==1\nend\nif t!=1\n0.upto(a[1]-1) do |j|\nnum=a[3]-a[5]*j\nif num==a[0]\nt=1\nbreak\nend\nend\nend\n\nif t!=1\n0.upto(a[1]-1) do |j|\nnum=a[2]-a[4]*j\nif num==a[0]\nt=1\nbreak\nend\nend\nend\n\nif a[0]==0\nt=1\nend\n\nif t==1\nputs \"YES\"\nelse\nputs \"NO\"\nend\n\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "ecafae8ba3f4c26e2af50554d9a5d6e4", "src_uid": "f98168cdd72369303b82b5a7ac45c3af", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = gets.strip\nk = Array.new(4)\ncount = Array.new(4, 0)\ni = 0\nwhile i < s.length\n c = s[i]\n if c == '!'\n count[i % 4] += 1\n else\n k[i % 4] = c\n end\n i += 1\nend\nkr = kb = ky = kg = 0\n4.times do |x|\n case k[x]\n when \"R\"\n kr = count[x]\n when \"B\"\n kb = count[x]\n when \"Y\"\n ky = count[x]\n when \"G\"\n kg = count[x]\n end\nend\nputs \"#{kr} #{kb} #{ky} #{kg}\"\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation", "number theory"], "code_uid": "7b06b7ffcc2efed28989c7c8f6f5afde", "src_uid": "64fc6e9b458a9ece8ad70a8c72126b33", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "garland = gets.chomp\n\ncontainer = Array.new(4)\nfor i in 0 ... garland.length\n if garland[i] != \"!\"\n container[i % 4] = garland[i]\n end\nend\n\nanswerColor = Hash.new(0)\nfor i in 0 ... garland.length\n if garland[i] == \"!\"\n answerColor[ container[i % 4] ] += 1\n end\nend\n\n\"RBYG\".each_char do |x|\n print \"#{answerColor[x]} \"\nend\nprint \"\\n\"", "lang_cluster": "Ruby", "tags": ["brute force", "implementation", "number theory"], "code_uid": "7a53a3c3929ad4dd28235108ab5c0612", "src_uid": "64fc6e9b458a9ece8ad70a8c72126b33", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "require 'set'\nclass B\n attr_reader(:xs)\n def initialize(s)\n @xs = s.split(\"\")\n end\n\n def r\n xs.index(\"R\") % 4\n end\n\n def g\n xs.index(\"G\") % 4\n end\n\n def b\n xs.index(\"B\") % 4\n end\n\n def y\n xs.index(\"Y\") % 4\n end\n\n def colors\n [:r, :b, :y, :g]\n end\n\n def bangs\n @bangs ||= xs.map.with_index{|a, i| [a, i]}.select{|a, i| a == \"!\"}.map{|a, b| b % 4}\n end\n\n def mapper\n @mapper ||= Hash[indexs.zip(colors)]\n end\n\n def indexs\n @indexs ||= colors.map{|c| send(c) }\n end\n\n def corrections\n @corrections ||= bangs.map{|ba| mapper[ba]}\n end\n\n def out\n colors.map{|c| corrections.select{|c2| c == c2}.length }\n end\n\n def ans\n out.join(\" \")\n end\n\nend\n\ns = gets.strip\nb = B.new(s)\n\nputs b.ans\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation", "number theory"], "code_uid": "1b89dc9d813036c6d7621b96184845a8", "src_uid": "64fc6e9b458a9ece8ad70a8c72126b33", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, k, D = gets.split.map(&:to_i)\nd = Array.new(n+1)\n(n+1).times { |i| d[i] = Array.new(2) }\nd[0][0] = 1\nd[0][1] = 0\nm = 1000000007\nn.times do |i|\n d[i+1][0] = d[i+1][1] = 0\n k.times do |j|\n if i>=j\n if (j+1= d \uc778 \uacbd\ub85c\ub97c \ubc29\ubb38\ud55c \uacbd\uc6b0\ub97c \ud569\uc0b0\ud55c\ub2e4.\n else\n # j >= d \uc778 \uacbd\uc6b0, \ud604\uc7ac \ubc29\ubb38\ud558\ub824\ub294 \ub178\ub4dc\ub4e4\uc740 \ud56d\uc0c1 d\ubcf4\ub2e4 \uac19\uac70\ub098 \ud070 weight\uc758\n # \uacbd\ub85c\ub97c \uc774\uc6a9\ud55c\ub2e4.\n # \uc774\ub54c \uac00\ub2a5\ud55c \uacbd\uc6b0\ub294,\n # 1) \uc5f0\uc774\uc5b4 j >= d\ub97c \ub9cc\uc871\ud558\ub294 \uacbd\ub85c\ub97c \ubc29\ubb38\ud55c \uacbd\uc6b0\n # 2) \uc774\uc804\uae4c\uc9c0 j < d \uacbd\ub85c\ub97c \ub9cc\ub0ac\uc9c0\ub9cc \uc774\ubc88\uc5d0 j >= d \ub97c \ucc98\uc74c\uc73c\ub85c \ub9cc\ub09c \uacbd\uc6b0\n # \ub530\ub77c\uc11c dp[i][0] \uc758 \uacbd\uc6b0\uc5d0 \ub300\ud574 \uc804\ud600 \uacc4\uc0b0\ud574\uc904 \ud544\uc694\uac00 \uc5c6\ub2e4.\n # 1\uacfc 2\uc758 \uacbd\uc6b0\ub97c \ubaa8\ub450 dp[i][1]\uc5d0 \ub354\ud574\uc8fc\uba74 \ub41c\ub2e4.\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# \ucd5c\uc885\uc801\uc73c\ub85c dp[n] \uc5d0\ub294 n\uae4c\uc9c0 \ud569\uc744 \uad6c\ud588\uc744 \ub54c, weight < d\ub85c\ub9cc \ubc29\ubb38\ud55c \uacbd\uc6b0\uc640\n# \ud55c\ubc88 \uc774\uc0c1 weight >= d\ub97c \ubc29\ubb38\ud55c \uacbd\uc6b0\uc758 \uc22b\uc790 \ud569\uc774 \ub0a8\ub294\ub2e4.\n# \ubb3c\ub860 \uc22b\uc790\uac00 \uaf64 \ud06c\uae30 \ub54c\ubb38\uc5d0, \ud070 \uc22b\uc790 \uad6c\ud604\uc774 \uc5c6\ub294 \uacbd\uc6b0\uc5d0\ub294 \uacc4\uc18d modulo \uc5f0\uc0b0\uc744\n# \uc218\ud589\ud558\uba74\uc11c \ud569\uc744 \uad6c\ud55c\ub2e4.\nputs dp[n][1]%MODULO_BASE", "lang_cluster": "Ruby", "tags": ["dp", "implementation", "trees"], "code_uid": "52f6f58e999ac98154436dd1f2185afd", "src_uid": "894a58c9bba5eba11b843c5c5ca0025d", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def count(sum,k,d,i,arr)\n\tif sum < 0\n\t\treturn\t\t\t\t\t\n\tend\n\n\tif sum == 0 && arr.any? { |e| e >= d }\n\t\t@c += 1\n\t\treturn\n\tend\n\n\t(1..k).each do |v|\n\t\tarr[i] = v\n\t\tcount(sum-v,k,d,i+1,arr.dup)\n\tend\nend\n\nn,k,d = gets.split(\" \").map(&:to_i)\n# @c = 0\n# count(n,k,d,0,[])\n# puts @c\nMOD = 1000000007\ndp = Array.new(n+1,0)\ndp_more = Array.new(n+1,0)\n(1..k).each do |i|\n\tdp[i] = 1\n\tdp_more[i] = 1 if i < d\nend\n\n(1..n).each do |i|\n\t(1..k).each do |j|\n\t\tbreak if i < j\n\t\tdp[i] = dp[i] + dp[i-j] % MOD\n\tend\nend\n\n(1..n).each do |i|\n\t(1..k).each do |j|\n\t\tbreak if i < j\n\t\t# puts \"#{i-j} #{dp_more}\"\n\t\tdp_more[i] = dp_more[i] + dp_more[i-j] % MOD if (j < d)\n\tend\nend\n\nputs (dp[n] - dp_more[n] + MOD) % MOD", "lang_cluster": "Ruby", "tags": ["dp", "implementation", "trees"], "code_uid": "1abff6e0eddb7a6b47cede3ebdab279a", "src_uid": "894a58c9bba5eba11b843c5c5ca0025d", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "e4a4a0fa3f6c78af59f8769acdfd37b0", "src_uid": "1366732dddecba26db232d6ca8f35fdc", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "9ae9812e35d34554697fd594cf074dae", "src_uid": "1366732dddecba26db232d6ca8f35fdc", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def f(x, r)\n\tl = []\n\twhile x != 0\n\t\tl << x % r\n\t\tx /= r\n\tend\n\t\n\treturn l\nend\n\na = gets.to_i\ns = Rational(0)\n(2...a).each do |r|\n\tl = f(a, r)\n\ts += l.reduce(:+)\nend\n\nputs s / (a - 2)", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "4f79fef922194504d5f36a0c36e3c8a0", "src_uid": "1366732dddecba26db232d6ca8f35fdc", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "c, v0, v1 , a, l = gets.strip.split(' ').map(&:to_i)\n\ncnt = 0\ni = 0\ntotal = 0\nwhile true\n break if cnt >= c\n if i == 0\n x = 0\n else \n x = l\n end\n cnt += [(v0 + (i * a)), v1].min\n cnt -= x\n i += 1\nend\n\nputs i\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "5f6ef2ae3297855726e4f1eb0a1259be", "src_uid": "b743110117ce13e2090367fd038d3b50", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "01e9175aac98053061142f2ae4f96a3c", "src_uid": "b743110117ce13e2090367fd038d3b50", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,v0,v1,a,l=gets.split.map &:to_i\nv=v0\ni=0\nwhile n>0\nn+=l if i>0\nn-=v\ni+=1\nv=[v+a,v1].min\nend\np i", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "171c46cec4623f523795fe9b11aec9b1", "src_uid": "b743110117ce13e2090367fd038d3b50", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, x = gets.split.map(&:to_i)\nputs (1..n).count{|i| x % i == 0 && x / i <= n}\n", "lang_cluster": "Ruby", "tags": ["implementation", "number theory"], "code_uid": "8f7bfe5f701d2d941dc5c864b13097fb", "src_uid": "c4b139eadca94201596f1305b2f76496", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, x = gets.split(' ').map(&:to_i)\nresult = 0\n\n(1..n).each do |i|\n result += 1 if (x % i == 0) && (x / i <= n)\nend\n\nputs result\n", "lang_cluster": "Ruby", "tags": ["implementation", "number theory"], "code_uid": "d7c8e2f3a784b7612b1c9f8ff7caca84", "src_uid": "c4b139eadca94201596f1305b2f76496", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, s = gets.split(' ').map{|i| i.to_i }, 0\n(1..n[0]).each {|i|\n s+=1 if n[1] % i == 0 && n[1] / i <= n[0]\n}\nputs s", "lang_cluster": "Ruby", "tags": ["implementation", "number theory"], "code_uid": "450adc503dd112fbda77325bad14730f", "src_uid": "c4b139eadca94201596f1305b2f76496", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "puts gets.count(\"47\").to_s.split('').map{|x| ['4', '7'].include? x}[0] ? :YES : :NO\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "b188d5e50a12f20a69eeb3c6366a3922", "src_uid": "33b73fd9e7f19894ea08e98b790d07f1", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "puts [4,7].index(gets.count\"47\")?:YES:\"NO\"\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "d18ca256cceabbd004a42e98c13758eb", "src_uid": "33b73fd9e7f19894ea08e98b790d07f1", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = $stdin.readline.to_i\nk = 0\nwhile n>0\n k+=1 if n%10 ==4 || n%10==7\n n/=10\nend\n\nputs (k==4||k==7)?\"YES\":\"NO\"", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "70eeb5cf14b0177a189444a86ae37dd5", "src_uid": "33b73fd9e7f19894ea08e98b790d07f1", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "3d57671a98620c5d7070c1dcba38d13f", "src_uid": "5fb635d52ddccf6a4d5103805da02a88", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "e7bd158d38cf230bb1a2a171b1dec41e", "src_uid": "5fb635d52ddccf6a4d5103805da02a88", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "str = STDIN.gets.chomp.split(' ')\na = str[0].to_i.to_s(3)\nc = str[1].to_i.to_s(3)\nmaxlen = a.to_s.length > c.to_s.length ? a.to_s.length : c.to_s.length\na = a.rjust(maxlen, '0')\nc = c.rjust(maxlen, '0')\nc = c.split('').map{|ch| ch.to_i + 3}.join\nputs c.split('').zip(a.split('')).inject(\"\") {|str, i| str += ((i[0].to_i - i[1].to_i) % 3).to_s; str}.to_i(3)", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "a4d6bf3aa044e1ef97b4ff876bc86cdb", "src_uid": "5fb635d52ddccf6a4d5103805da02a88", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "if File.exists?(\"input\")\n $stdin = File.open(\"input\")\n $stdout = File.open(\"output\",\"w\")\nend\n\na = gets.chomp.to_i\n\ndef interesting(a)\n\tif(a.to_s.each_char.to_a.map(&:to_i).inject(:+)%4==0)\n\t\treturn true\n\telse\n\t\treturn false\n\tend\nend\n\nwhile(!interesting(a))\n\ta+=1\nend\n\nputs a", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "195dfc25796ea9575e62c189378a0945", "src_uid": "bb6fb9516b2c55d1ee47a30d423562d7", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "# def adjust_number(number)\n# if(number % 3 == 0)\n# find_number(number)\n# elsif\n# find_number(number + 1)\n# else\n# find_number(number + 2)\n# end\n# end\ndef find_number(number)\n loop do\n if (sum_of_digit(number) % 4 == 0)\n puts number\n break\n end\n number += 1\n end\nend\ndef sum_of_digit(number)\n @sum = 0\n while number > 0\n @sum += (number)%10\n number /= 10\n end\n return @sum\nend\nnumber = gets.chomp.to_i\nfind_number(number)", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "cb798182b75e1f112a3b49f8c9be0784", "src_uid": "bb6fb9516b2c55d1ee47a30d423562d7", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "MOD=10**9+7\ncnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)\ndef gs() gets.chomp end\ndef gi() gets.to_i end\ndef gsmi() gets.chomp.split.map(&:to_i) end\n\ndef desc(ar) ar.sort{|x,y|y<=>x} end##\ndef min(a,b) a<=b ? a : b end\ndef max(a,b) a>=b ? a : b end\ndef sum(ar) ar.inject(:+) end\n\ndef C(a,b) b==0||a==b ? 1 : (b=a-b if a/20 && s[i+1]>0 && s[i+2]>0\n\t\tputs \"YES\"\n\t\texit(0)\n\tend\nend\nputs \"NO\"", "lang_cluster": "Ruby", "tags": ["brute force", "sortings", "implementation"], "code_uid": "896494f57019028e4f213d82c794d5b6", "src_uid": "d6c876a84c7b92141710be5d76536eab", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nb = a.uniq.sort\nans = 'NO'\n(b.size - 2).times do |i|\n ans = 'YES' if b[i + 2] - b[i] == 2\nend\nputs ans\n", "lang_cluster": "Ruby", "tags": ["brute force", "sortings", "implementation"], "code_uid": "29216f0b0e031a08f40e3de833a0568f", "src_uid": "d6c876a84c7b92141710be5d76536eab", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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\n", "lang_cluster": "Ruby", "tags": ["brute force", "math", "number theory"], "code_uid": "431d9defdb9028c7c8422528cc08ecde", "src_uid": "afd2b818ed3e2a931da9d682f6ad660d", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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\n", "lang_cluster": "Ruby", "tags": ["brute force", "math", "number theory"], "code_uid": "b55664b7cd6412d18546acf563b890bc", "src_uid": "afd2b818ed3e2a931da9d682f6ad660d", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["brute force", "math", "number theory"], "code_uid": "5d0c20895ea9000d6577e2bba205b88d", "src_uid": "afd2b818ed3e2a931da9d682f6ad660d", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "ary = STDIN.gets.chomp.split('')\ni = 0\nc = 0\nlast = nil\nary.each do |type|\n if last != type || c >= 5\n i += 1\n c = 0\n end\n c += 1\n last = type\nend\np i\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "631c610706d65742d48dd26b94ed9814", "src_uid": "5257f6b50f5a610a17c35a47b3a0da11", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/env ruby\nresult, length, lastChar= 0, 0, 'G'\ngets.each_byte { |c|\n break if c == 10\n if c == lastChar\n if length < 5\n length += 1\n elsif\n result += 1\n length = 1\n end\n elsif\n result += 1\n length = 1\n lastChar = c\n end\n}\nputs result\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "9fb0f80c07bdf1325abbbb6b85975382", "src_uid": "5257f6b50f5a610a17c35a47b3a0da11", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "CAPACITY = 5\n\ncount = 0\non_hand = 0\nprevious ||= nil\n\ngets.strip.split('').each do |c|\n c = c.upcase\n\n if on_hand >= CAPACITY || previous != c\n count +=1\n on_hand = 0\n end\n\n on_hand += 1\n previous = c\nend\nputs count\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "f8a520761a5da46130676048072ca983", "src_uid": "5257f6b50f5a610a17c35a47b3a0da11", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "N=gets.to_i\np (1..1/0.0).find{|i|(N+i).to_s.include?('8')}", "lang_cluster": "Ruby", "tags": ["brute force"], "code_uid": "07fc8983266c9440eaaa0b9b8bfcdb42", "src_uid": "4e57740be015963c190e0bfe1ab74cb9", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a=gets.chomp.to_i\ni=0\nloop do\na+=1\ni+=1\nif \"#{a}\".count(\"8\")>0\nbreak\nend\nend\nputs \"#{i}\"", "lang_cluster": "Ruby", "tags": ["brute force"], "code_uid": "bf9e3ebec26457e31755af3128de4f05", "src_uid": "4e57740be015963c190e0bfe1ab74cb9", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a, b = [gets.chomp.to_i, 0]\nuntil ((a + (b += 1)).to_s.include?('8'))\nend\nputs b", "lang_cluster": "Ruby", "tags": ["brute force"], "code_uid": "94de309e046fea86e60378c85a893986", "src_uid": "4e57740be015963c190e0bfe1ab74cb9", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b=gets.split\np a.to_i+b.reverse.to_i", "lang_cluster": "Ruby", "tags": ["constructive algorithms"], "code_uid": "ca00ec944d7520f91fad7d82b40aad8d", "src_uid": "69b219054cad0844fc4f15df463e09c0", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b=gets.split\np a.to_i+b.reverse.to_i\n", "lang_cluster": "Ruby", "tags": ["constructive algorithms"], "code_uid": "bb57ca358e59fde2a55e9d0d29f559ea", "src_uid": "69b219054cad0844fc4f15df463e09c0", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b=gets.split\np a.to_i+b.reverse.to_i\n", "lang_cluster": "Ruby", "tags": ["constructive algorithms"], "code_uid": "0ccfe264bf3c5ba0568d5eabb5a33681", "src_uid": "69b219054cad0844fc4f15df463e09c0", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "\n\nsfriends = gets.chomp\nsfingers = gets.chomp\n\nfriends = sfriends.to_i\nfingers = sfingers.split(\" \").map{|x| x.to_i}\ntotalFingers = fingers.reduce{|a,b| a+b}\n\nsum = 0\n(1..5).each do |x|\n\tif (((totalFingers + x) -1) % (friends+1)) != 0 then\n\t\tsum += 1\n\tend\t\nend\n\nputs sum\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "5d1649d7db19d88cbb80feb1f1a3bb34", "src_uid": "ff6b3fd358c758324c19a26283ab96a4", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def run\n n = ARGF.readline.to_i\n c = ARGF.readline.split.map(&:to_i).reduce(&:+)\n\n cnt = 0\n 1.upto(5) do |i|\n cnt += 1 if ((c + i) % (n + 1)) != 1\n end\n\n puts cnt\nend\n\nrun if $0 == __FILE__\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "c97f1e00b88e56c1f9aac182183a5a17", "src_uid": "ff6b3fd358c758324c19a26283ab96a4", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "31e698534510234171395a57a86da654", "src_uid": "ff6b3fd358c758324c19a26283ab96a4", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a, b, c, d = gets.split.map(&:to_i)\np = a * d\nq = b * c\nputs [Rational(p - q, p), Rational(q - p, q)].max\n", "lang_cluster": "Ruby", "tags": ["math", "greedy", "number theory"], "code_uid": "5a442a2f3d8c49fcaed84ac89d49b889", "src_uid": "b0f435fc2f7334aee0d07524bc37cb1e", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b,c,d=gets.split.map(&:to_i)\np=a*d\nq=b*c\nputs [Rational(p-q,p),Rational(q-p,q)].max\n", "lang_cluster": "Ruby", "tags": ["math", "greedy", "number theory"], "code_uid": "2a46e2242d36422736f17328fbae4630", "src_uid": "b0f435fc2f7334aee0d07524bc37cb1e", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b,c,d=gets.split.map(&:to_i)\np=a*d\nq=b*c\nputs [Rational(p-q,p),Rational(q-p,q)].max\n", "lang_cluster": "Ruby", "tags": ["math", "greedy", "number theory"], "code_uid": "48338dbba5aefac717a4b1d77c94741a", "src_uid": "b0f435fc2f7334aee0d07524bc37cb1e", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = gets.chomp\ncount = Hash.new(0)\ns.each_char do |c|\n\tcount[c] += 1 if c == \"4\" || c == \"7\"\nend\n\nkeys = count.keys\n\nif keys.empty?\n\tans = \"-1\"\t\nelse\n\tif count[\"4\"] && count[\"7\"]\n\t\tif count[\"4\"] >= count[\"7\"]\n\t\t\tans = \"4\"\n\t\telse\n\t\t\tans = \"7\"\n\t\tend\n\telsif count[\"4\"]\n\t\tans = \"4\"\n\telse\n\t\tans = \"7\"\n\tend\n\nend\n\nputs ans", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "1e6cc709ffcafcd543aa79a810140f99", "src_uid": "639b8b8d0dc42df46b139f0aeb3a7a0a", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "t = gets\ns, f = t.count(\"7\"), t.count(\"4\")\nputs s + f == 0 ? -1 : s == f ? 4 : s > f ? 7 : 4\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "76c6aa8dbab14ef2c7c27eb643e859e7", "src_uid": "639b8b8d0dc42df46b139f0aeb3a7a0a", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = gets\na = s.count('4')\nb = s.count('7')\np a == 0 && b == 0 ? -1 : a >= b ? 4 : 7\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "e24169dbc7e1505236c0f7fe5b4d0433", "src_uid": "639b8b8d0dc42df46b139f0aeb3a7a0a", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["brute force", "greedy"], "code_uid": "0ca53fea31400a1da5e48a2b7d8e26c9", "src_uid": "3153cfddae27fbd817caaf2cb7a6a4b5", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\ns = gets.chomp\ni = 0\nloop do\n break if i >= s.length\n # length 3 first\n if s[i..(i+2)] == \"144\"\n i += 3\n else\n if s[i..(i+1)] == \"14\"\n i += 2\n else\n if s[i] == \"1\"\n i += 1\n else\n break\n end\n end\n end\nend\n\nif i == s.length\n puts \"YES\"\nelse\n puts \"NO\"\nend\n", "lang_cluster": "Ruby", "tags": ["brute force", "greedy"], "code_uid": "499a58bfe7dad7d0d18506145f788a8f", "src_uid": "3153cfddae27fbd817caaf2cb7a6a4b5", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "number = gets.chomp.split('')\nlength = number.length\nif (length <= 3 && (number.join == \"1\" || number.join == \"14\" || number.join == \"144\")) || (number.count(\"1\") == length)\n\tputs \"YES\"\nelsif length >= 3\n\ti = 0\n\twhile i < length\n\t\tif number[i] == \"1\" && number[i+1] == \"4\" && number[i+2] == \"4\"\n\t\t\ti += 3\n\t\t\tacc = 1\n\t\telsif number[i] == \"1\" && number[i+1] == \"4\"\n\t\t\ti += 2\n\t\t\tacc = 1\n\t\telsif number[i] == \"1\"\n\t\t\ti += 1\n\t\t\tacc = 1\n\t\telse\n\t\t\tacc = 0\n\t\t\tbreak\n\t\tend\n\tend\n\t\n\tif acc == 1 \n\t\tputs \"YES\"\n\telse \n\t\tputs \"NO\"\n\tend\nelse\n\tputs \"NO\"\nend\n", "lang_cluster": "Ruby", "tags": ["brute force", "greedy"], "code_uid": "1e85d516f812ca4a8c7c3e52b6440fef", "src_uid": "3153cfddae27fbd817caaf2cb7a6a4b5", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "year = gets.to_i\n\nfor i in year+1..10000\n\tk = []\n\tm = i\n\tok = true\n\twhile m > 0\n\t\tt = m % 10\n\t\tm /= 10 \n\t\tif k.include?(t)\n\t\t\tok = false\n\t\tend\n\t\tk << t\n\tend\n\n\tif ok\n\t\tputs i\n\t\texit\n\tend\nend", "lang_cluster": "Ruby", "tags": ["brute force"], "code_uid": "16e9682730764aa437659de562fdcd5c", "src_uid": "d62dabfbec52675b7ed7b582ad133acd", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.to_i\n0while\"#{n+=1}\"[/(.).*\\1/]\np n\n", "lang_cluster": "Ruby", "tags": ["brute force"], "code_uid": "5a1786d7caf5b89f40aa2e5643ad42ce", "src_uid": "d62dabfbec52675b7ed7b582ad133acd", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "numb = gets.to_i + 1\nwhile numb.to_s.scan(/./).uniq.size < 4\n numb += 1\nend\nputs numb\n", "lang_cluster": "Ruby", "tags": ["brute force"], "code_uid": "bfc559e0ae9813fb46a006bb76374841", "src_uid": "d62dabfbec52675b7ed7b582ad133acd", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "min = gets.split.map(&:to_i).min\nanswer = min % 2 == 0 ? \"Malvika\" : \"Akshat\"\nputs answer\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "7741f486d095460e4d5e3f8e39d37961", "src_uid": "a4b9ce9c9f170a729a97af13e81b5fe4", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "puts gets.split(' ').map(&:to_i).min.odd? ? 'Akshat' : 'Malvika'\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "021fdcc25e77852b35c4ce7276cefd9f", "src_uid": "a4b9ce9c9f170a729a97af13e81b5fe4", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "puts gets.split.map{|e| e.to_i}.min%2==0?\"Malvika\":\"Akshat\"", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "fce6aeb969d08cae353004cfba378e26", "src_uid": "a4b9ce9c9f170a729a97af13e81b5fe4", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def dist(x1, y1, x2, y2)\n\t(x1 - x2)**2 + (y1- y2)**2\nend\n\nax, ay, bx, by, cx, cy = gets.split.map{|x| x.to_i}\nputs ((ay - by) * (ax - cx) == (ay - cy) * (ax - bx)) || (dist(ax, ay, bx, by) != dist(cx, cy, bx, by)) ? \"No\" : \"Yes\"", "lang_cluster": "Ruby", "tags": ["math", "geometry"], "code_uid": "027e1c098f8097e09fe59b9a1265ddb1", "src_uid": "05ec6ec3e9ffcc0e856dc0d461e6eeab", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["math", "geometry"], "code_uid": "f24effc8d740c20527ccb6f995a5e161", "src_uid": "05ec6ec3e9ffcc0e856dc0d461e6eeab", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "m = Array.new\n\n4.times do\n m << gets.chomp\nend\n\n3.times do |y|\n 3.times do |x|\n c = (m[y][x] + m[y+1][x] + m[y][x+1] + m[y+1][x+1]).delete(\".\").length\n unless c == 2\n puts 'YES'\n exit 0\n end\n end\nend\n\nputs 'NO'\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "7ac4ebdade2f7d95888c2b7704d2a2e2", "src_uid": "01b145e798bbdf0ca2ecc383676d79f3", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "class A\n def initialize\n @cells = []\n @list = [[1,1],[1,2],[2,1],[2,2]]\n @pos1 = [[-1,0],[-1,1],[0,1]]\n @pos2 = [[-1,0],[-1,-1],[0,-1]]\n @pos3 = [[0,-1],[1,-1],[1,0]]\n @pos4 = [[0,1],[1,1],[1,0]]\n 4.times do\n @cells << $stdin.gets.chomp.split('')\n end\n\n check\n puts \"NO\"\n end\n\n def check\n flag = false\n @list.each do |elem|\n y = elem[0]\n x = elem[1]\n\n flag ||= right_up(y, x)\n flag ||= left_up(y, x)\n flag ||= left_up(y, x)\n flag ||= right_down(y, x)\n\n if flag \n puts \"YES\"\n exit\n end\n end\n end\n\n def right_up(ypos,xpos)\n white = 0\n black = 0\n if @cells[ypos][xpos] == \"#\"\n black += 1\n else\n white += 1\n end\n\n @pos1.each do |pos|\n y = pos[0]\n x = pos[1]\n\n if @cells[ypos+y][xpos+x] == \"#\"\n black += 1\n else\n white += 1\n end\n\n end\n if black >= 3 || white >= 3\n true\n else\n false\n end\n end\n\n def left_up(ypos,xpos)\n white = 0\n black = 0\n if @cells[ypos][xpos] == \"#\"\n black += 1\n else\n white += 1\n end\n\n @pos2.each do |pos|\n y = pos[0]\n x = pos[1]\n\n if @cells[ypos+y][xpos+x] == \"#\"\n black += 1\n else\n white += 1\n end\n\n end\n if black >= 3 || white >= 3\n true\n else\n false\n end\n end\n def left_down(ypos,xpos)\n white = 0\n black = 0\n if @cells[ypos][xpos] == \"#\"\n black += 1\n else\n white += 1\n end\n\n @pos3.each do |pos|\n y = pos[0]\n x = pos[1]\n\n if @cells[ypos+y][xpos+x] == \"#\"\n black += 1\n else\n white += 1\n end\n\n end\n if black >= 3 || white >= 3\n true\n else\n false\n end\n end\n\n def right_down(ypos,xpos)\n white = 0\n black = 0\n if @cells[ypos][xpos] == \"#\"\n black += 1\n else\n white += 1\n end\n\n @pos4.each do |pos|\n y = pos[0]\n x = pos[1]\n\n if @cells[ypos+y][xpos+x] == \"#\"\n black += 1\n else\n white += 1\n end\n end\n if black >= 3 || white >= 3\n true\n else\n false\n end\n end\nend\n\na = A.new", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "79b06d131d805d21c488bc1a3970f855", "src_uid": "01b145e798bbdf0ca2ecc383676d79f3", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a=[]\n4.times do\na << gets.chomp.split(\"\")\nend\nans=0\n0.upto(2) do |i|\n0.upto(2) do |j|\nw=0\nb=0\nif a[i][j]==\"#\"\nb+=1\nelse \nw+=1\nend\nif a[i+1][j]==\"#\"\nb+=1\nelse \nw+=1\nend\nif a[i][j+1]==\"#\"\nb+=1\nelse \nw+=1\nend\nif a[i+1][j+1]==\"#\"\nb+=1\nelse \nw+=1\nend\nif w>2 || b>2\nans=1\nend\nbreak if ans==1\nend\nbreak if ans==1\nend\nif ans==1\nputs \"YES\"\nelse \nputs \"NO\"\nend\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "b57d62d73ce4eeaf438a38d7cbdee72c", "src_uid": "01b145e798bbdf0ca2ecc383676d79f3", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a=gets.chomp.split(\" \")\nn=a[0].to_i\nm=a[1].to_i\nans=0\n0.upto(m) do |a|\n0.upto(n) do |b|\nif a**2+b==n && b**2+a==m\nans+=1\nend\nend\nend\nputs \"#{ans}\"", "lang_cluster": "Ruby", "tags": ["brute force"], "code_uid": "328232c0b728fd97e8e1e24a2fc9d61e", "src_uid": "03caf4ddf07c1783e42e9f9085cc6efd", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "inp=gets.chomp.split\nn=inp[0].to_i\nm=inp[1].to_i\nres=0\nas=[*0..(Math.sqrt(n).to_i+1)]\nbs=[*0..(Math.sqrt(m).to_i+1)]\n#puts as.each{|a| puts a, bs.collect{|b| ((a*a)+b==n)&&((b*b)+a==m) } }\nputs as.collect{|a| bs.collect{|b| ((a*a)+b==n)&&((b*b)+a==m) } }.flatten.count true\n", "lang_cluster": "Ruby", "tags": ["brute force"], "code_uid": "47c78b09b03c9fae81f5cc2ea948b538", "src_uid": "03caf4ddf07c1783e42e9f9085cc6efd", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,m=gets.split.map &:to_i;p (0..n).to_a.map{|i|m>=i*i&&i+(m-i*i)**2==n}.count(true)", "lang_cluster": "Ruby", "tags": ["brute force"], "code_uid": "2f031a8e8a98f27b31c5cee14d58e9ed", "src_uid": "03caf4ddf07c1783e42e9f9085cc6efd", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "p (0..l=gets.size).select{|i|q={};l.times{|j|q[$_[j,i]]=1};q.size upperBound\n low = mid +1 \n else\n minn = [mid,minn].min\n high = mid - 1 \n end\n end\n minn\n\nend\n\n\n\n\n\nn , k =gets.split.map(&:to_i)\nlower = 2 \nupper = (k*(k-1) / 2 )+ 1 \n\nif n < lower || n > upper \n puts n==1?0:-1\nelse\n if n <= k\n puts 1 \n elsif n == upper\n puts k-1\n else\n puts howMany(2,k-1,k,n)\n end\nend\n\n\n", "lang_cluster": "Ruby", "tags": ["math", "binary search"], "code_uid": "49fbfb621a78ea6cba552d6a943fe3b2", "src_uid": "83bcfe32db302fbae18e8a95d89cf411", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/ruby1.9\n\nn, k = STDIN.readline.split.collect {|s| s.to_i }\n\nneed = n-1\nmax = k-1\n\nif need == 0\n\tputs 0\n\texit\nend\n\nif (max+1)*max/2 < need\n\tputs -1\n\texit\nend\n\nlow, high = 1, max\nwhile low < high\n\tmid = (low+high)/2\n\tsum = (mid+max)*(max-mid+1)/2\n\tif sum == need\n\t\tbreak\n\telsif sum < need\n\t\thigh = mid\n\telse\n\t\tlow = mid+1\n\tend\nend\n\nmid = (low+high)/2\nif (mid+max)*(max-mid+1)/2 >= need\n\tputs max-mid+1\nelse\n\tputs max-mid+2\nend\n", "lang_cluster": "Ruby", "tags": ["math", "binary search"], "code_uid": "5d82d3fd4b3cc952284b38b7e03c22c5", "src_uid": "83bcfe32db302fbae18e8a95d89cf411", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "N, K = gets.split.map &:to_i\nl = -1\nu = K\nwhile l + 1 < u\n m = l + u >> 1\n (K - 1 + K - m) * m / 2 + 1 >= N ? u = m : l = m\nend\np u == K ? -1 : u\n", "lang_cluster": "Ruby", "tags": ["math", "binary search"], "code_uid": "1735b5848a3b7136a13d9757a4fd014e", "src_uid": "83bcfe32db302fbae18e8a95d89cf411", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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 do|i|\n r+=f[$n]*pow(f[$n-i]*f[i],$m-2) if g($a*i+($n-i)*$b)>0\nend\np r%$m", "lang_cluster": "Ruby", "tags": ["brute force", "combinatorics"], "code_uid": "d58aa641c2bb8eba5d249158c6791327", "src_uid": "d3e3da5b6ba37c8ac5f22b18c140ce81", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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 false if d!=$a&&d!=$b end;true end\ndef pow(x,p)p<1?1:pow(x,p/2)**2*x**(p%2)%$m end\nr=0\n($n+1).times do|i|\n if g($a*i+($n-i)*$b)\n r+=f[$n]*pow(f[$n-i]*f[i],$m-2)\n end\nend\np r%$m", "lang_cluster": "Ruby", "tags": ["brute force", "combinatorics"], "code_uid": "f7169872b340c97a93a7446ae3471d0e", "src_uid": "d3e3da5b6ba37c8ac5f22b18c140ce81", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b,n=gets.split.map(&:to_i)\nm=10**9+7\ndef pow a,n,m\n return 1 if n==0\n d=n%2\n r=pow(a,n/2,m)**2\n r*=a if d==1\n r%=m\nend\nf=[1.0]\n1.upto(n){|i|f[i]=f[i-1]*i%m}\nf.map!(&:to_i)\ndef g x,a,b\n while x>0\n d=x%10\n return false if d!=a&&d!=b\n x/=10\n end\n true\nend\nr=0\n(n+1).times do|i|\n if g(a*i+(n-i)*b,a,b)\n r+=f[n]*pow(f[n-i]*f[i],m-2,m)\n r%=m\n end\nend\np r", "lang_cluster": "Ruby", "tags": ["brute force", "combinatorics"], "code_uid": "3e5d41d93106f258ff46b09d598e44f2", "src_uid": "d3e3da5b6ba37c8ac5f22b18c140ce81", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "# inputs\na, b, c = gets.split.map!{ |s| s.to_i }\n\n# answers\nres = []\n\ndef s(x)\n res = 0\n x.to_s.each_char{|c|\n res += c.to_i\n }\n return res\nend\n\nfor sx in 0 .. 81\n x = b * sx**a + c\n if x > 0 and x < 10**9 and s(x) == sx then res << x end\nend\n\nputs res.size\nfor x in res\n print x, \" \"\nend\nputs\n", "lang_cluster": "Ruby", "tags": ["brute force", "math", "implementation", "number theory"], "code_uid": "0d6c2d8912268f4058ccb8f364c01cc2", "src_uid": "e477185b94f93006d7ae84c8f0817009", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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 ' '", "lang_cluster": "Ruby", "tags": ["brute force", "math", "implementation", "number theory"], "code_uid": "0377a94f2fe4a4879a234567bac126c8", "src_uid": "e477185b94f93006d7ae84c8f0817009", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "\n\ndef digit_sum(a)\n a.to_s.split(//).map(&:to_i).inject(:+)\nend\n\na, b, c = gets.split.map(&:to_i)\n\nresult = []\n\n(1..81).each do |sx|\n num = b * (sx ** a) + c\n if num > 0 && digit_sum(num) == sx && num < 1000000000\n result << num\n end\nend\n\n\nputs result.size\nputs result.sort.map(&:to_s).join(\" \")\n\n\n\n\n", "lang_cluster": "Ruby", "tags": ["brute force", "math", "implementation", "number theory"], "code_uid": "933c42798b89ba0d8d152a0f39b07f15", "src_uid": "e477185b94f93006d7ae84c8f0817009", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "w,h = gets.split.map(&:to_i)\nmod = 998244353\nans = 4\n(w-1).times do\n ans *= 2\n ans %= mod\nend\n(h-1).times do\n ans *= 2\n ans %= mod\nend\nputs ans", "lang_cluster": "Ruby", "tags": ["math", "greedy", "combinatorics"], "code_uid": "6bf5fb864315979d9764441b2a742c28", "src_uid": "8b2a9ae21740c89079a6011a30cd6aee", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "w, h = gets.strip.split(' ').map(&:to_i)\n\nputs ( (2**w) * (2**h) ) % 998244353", "lang_cluster": "Ruby", "tags": ["math", "greedy", "combinatorics"], "code_uid": "64d50d296c948f6ca3e194d4b6627a4e", "src_uid": "8b2a9ae21740c89079a6011a30cd6aee", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "k = gets.to_i\nmonthes = gets.split.map(&:to_i).sort.reverse\nif k <= 0\n puts 0\n exit\nend\n\nsum = 0\nmonthes.each_with_index do |m, i|\n if (sum += m) >= k\n puts i + 1\n exit\n end\nend\nputs -1\nexit\n", "lang_cluster": "Ruby", "tags": ["sortings", "implementation", "greedy"], "code_uid": "fa99b1706ab34be1a0fdaffcaf6d1046", "src_uid": "59dfa7a4988375febc5dccc27aca90a8", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a=gets.chomp.to_i\nb=gets.chomp.split(\" \")\n0.upto(11) {|i| b[i]=b[i].to_i}\nb.sort!\nb.reverse!\ni=0\nans=0\nloop do \nbreak if a<=0\na-=b[i]\ni+=1\nans+=1\nbreak if i==12\nend\nif a<=0\nputs \"#{ans}\"\nelse\nputs \"-1\"\nend", "lang_cluster": "Ruby", "tags": ["sortings", "implementation", "greedy"], "code_uid": "2a820960b5f05e5c901212d213c14e20", "src_uid": "59dfa7a4988375febc5dccc27aca90a8", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\n\na.sort!.reverse!\n\ni = -1\ns = 0\nwhile s < n and i n}}}.inject{|h,n| h.merge(n){|d,n1,n2| n1+n2}}\nans = []\nuntil digits.empty?\n d = digits.keys.max\n 2.upto(d) do |d|\n ds = factorize[d]\n ds.each {|d| digits[d] -= 1}\n digits.delete_if {|d,n| n == 0}\n end\n ans << d\nend\nputs ans.join", "lang_cluster": "Ruby", "tags": ["math", "sortings", "greedy"], "code_uid": "a6051c31ffbf4e5c4cf12f725a590690", "src_uid": "60dbfc7a65702ae8bd4a587db1e06398", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,*a=$<.read.split.map &:to_i\nb=[0];c=[0]\na.each{|e|b<= 2 * choices.values[-2]\n\t\tval = choices.key(choices.values[-1])\n\t\tif val\n\t\t\tchoice = (choice ? nil : val)\n\t\tend\n\tend\n\t\n\tchoice = \"C\" unless choice\n\tputs choice\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "dda95ed93a2a7e2d6fd1d1141ca719ac", "src_uid": "30725e340dc07f552f0cce359af226a4", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a=[]; 4.times do\n\ta<= B * 2 && A >= C * 2 && A >= D * 2) || (A * 2<= B && A * 2 <= C && A * 2 <= D)\nx<<\"B\" if (B >= A * 2 && B >= C * 2 && B >= D * 2) || (B * 2 <= A && B * 2 <= C && B * 2 <= D)\nx<<\"C\" if (C >= A * 2 && C >= B * 2 && C >= D * 2) || (C * 2 <= A && C * 2 <= B && C * 2 <= D)\nx<<\"D\" if (D >= A * 2 && D >= B * 2 && D >= C * 2) || (D * 2 <= A && D * 2 <= B && D * 2 <= C)\nputs x.size==1? x[0]:'C'", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "5f2935c7bc43e879a53313f6afe862b0", "src_uid": "30725e340dc07f552f0cce359af226a4", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "A = gets.strip.split('.')[1].size\nB = gets.strip.split('.')[1].size\nC = gets.strip.split('.')[1].size\nD = gets.strip.split('.')[1].size\nary = []\nary << 'A' if (A >= B * 2 && A >= C * 2 && A >= D * 2) \\\n || (A * 2 <= B && A * 2 <= C && A * 2 <= D)\nary << 'B' if (B >= A * 2 && B >= C * 2 && B >= D * 2) \\\n || (B * 2 <= A && B * 2 <= C && B * 2 <= D)\nary << 'C' if (C >= A * 2 && C >= B * 2 && C >= D * 2) \\\n || (C * 2 <= A && C * 2 <= B && C * 2 <= D)\nary << 'D' if (D >= A * 2 && D >= B * 2 && D >= C * 2) \\\n || (D * 2 <= A && D * 2 <= B && D * 2 <= C)\nputs ary.size == 1 ? ary[0] : 'C'", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "54d60782b6f8d0a28c388f867bc5c9d8", "src_uid": "30725e340dc07f552f0cce359af226a4", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "str1 = gets\n101\nstr2 = gets\n102\na = str1.to_i\nb = str2.to_i\n\nstr1.delete!(\"0\")\nstr2.delete!(\"0\")\n\nx,y = str1.to_i,str2.to_i\nc = a+b\nz = x+y\nans = c.to_s.delete(\"0\")\nputs \"YES\" if z.to_s == ans\nputs \"NO\" unless z.to_s == ans", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "cfa78586eab47c8966fd786f4a3a1edc", "src_uid": "ac6971f4feea0662d82da8e0862031ad", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a = gets.to_i\nb = gets.to_i\nc = a + b\nputs (a.to_s.tr(\"0\", \"\").to_i + b.to_s.tr(\"0\", \"\").to_i == c.to_s.tr(\"0\", \"\").to_i ? :YES : :NO)", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "d02a47052eecf99fca37bbfac16088be", "src_uid": "ac6971f4feea0662d82da8e0862031ad", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a = gets.to_i\nb = gets.to_i\nc = (a + b).to_s.gsub(\"0\",\"\").to_i\na1 = a.to_s.gsub(\"0\",\"\").to_i\nb1 = b.to_s.gsub(\"0\",\"\").to_i\nc1 = a1 + b1\n\nputs c == c1 ? \"YES\" : \"NO\"\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "6a9ff1522d3c1202cb51d027766c7198", "src_uid": "ac6971f4feea0662d82da8e0862031ad", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = STDIN.readline.split(\" \").map{|a| a.to_i}.inject(:+)\nputs ((n % 5 == 0 && n != 0? n / 5 : -1))", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "625435db9a9da40dfee8823e5bd4322e", "src_uid": "af1ec6a6fc1f2360506fc8a34e3dcd20", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "a2903f9b3336519e867425106caa6080", "src_uid": "af1ec6a6fc1f2360506fc8a34e3dcd20", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s=0\ngets.split.map{|i|s+=i.to_i}\np s>0&&s%5==0?s/5:-1\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "08bb91e2f6c0c95a8e7146ac4be29619", "src_uid": "af1ec6a6fc1f2360506fc8a34e3dcd20", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "# Input\nn, k = gets.split(\" \").map { |e| e.to_i }\na = gets.split(\" \").map { |e| e.to_i }\n\n# Processing\niteration_results = []\n1.upto(k) do |b|\n #puts \"Checking b = #{b}\"\n b = Array.new(a).delete_if.with_index { |val, index| (index - b + 1) % k == 0 }\n #puts \"New array: #{a_.inspect}\"\n diff = (b.length - 2 * b.count(-1)).abs\n #puts \"Difference : #{diff}\"\n iteration_results << diff\nend\nresult = iteration_results.max\n\n# Output\nputs result\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "0c507555d39bf76fe1b211a9681aae8b", "src_uid": "6119258322e06fa6146e592c63313df3", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "bab09caeb59ef7b5ae067772d7bf048a", "src_uid": "6119258322e06fa6146e592c63313df3", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,k = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\nans = 0\nfor i in 0..k-1\n x = y = 0\n for j in 0..n-1\n next if j%k == i%k\n if a[j] == 1\n x += 1\n else\n y += 1\n end\n end\n ret = (x-y).abs\n ans = ret if ans < ret\nend\nputs ans", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "b239f79c1d7396d7bc3cb72f07303e81", "src_uid": "6119258322e06fa6146e592c63313df3", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/env ruby\n\nn = ARGF.gets.to_i # number of cards\ncards1 = ARGF.gets.split(' ').map{ |s| s.to_i } # number and values of cards ...\ncards2 = ARGF.gets.split(' ').map{ |s| s.to_i } # ... from top to bottom of stack\n\ncards1.shift\ncards2.shift\n\nfor i in 1..1024 do\n a = cards1.shift rescue nil\n b = cards2.shift rescue nil\n if a.nil?\n puts \"#{i-1} #{2}\"\n exit\n elsif b.nil?\n puts \"#{i-1} #{1}\"\n exit\n elsif a > b\n cards1 << b << a\n elsif b > a\n cards2 << a << b\n end\nend\n\np -1\n \n", "lang_cluster": "Ruby", "tags": ["dfs and similar", "brute force", "games"], "code_uid": "33028d151903f6acb6be0533ba05771a", "src_uid": "f587b1867754e6958c3d7e0fe368ec6e", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["dfs and similar", "brute force", "games"], "code_uid": "c7b206fef94aa51ba0838c80c786fa90", "src_uid": "f587b1867754e6958c3d7e0fe368ec6e", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "\ndef play_war(stack1, stack2)\n moves = 0\n i = 0\n while !stack1.empty? && !stack2.empty? && i < 5000000\n #puts \"Decks are\"\n #puts stack1.inspect\n #puts stack2.inspect\n i+=1\n val1 = stack1.shift\n val2 = stack2.shift\n #puts \"\\tWar against #{val1} : #{val2}\"\n if val1 < val2\n # puts \"\\t\\t2 Won \"\n #opponet won\n stack2.push(val1)\n stack2.push(val2)\n else\n #I won\n #puts \"\\t\\t1 Won \"\n\n stack1.push(val2)\n stack1.push(val1)\n end\n moves += 1\n end\n\n if stack1.empty?\n puts \"#{moves} #{2}\"\n elsif stack2.empty?\n puts \"#{moves} #{1}\"\n else\n puts '-1'\n end\nend\n\ngets\narr1 = gets.split(\" \").collect{|i| i.to_i}\narr1.shift\narr2 = gets.split(\" \").collect{|i| i.to_i}\narr2.shift\nplay_war(arr1, arr2)", "lang_cluster": "Ruby", "tags": ["dfs and similar", "brute force", "games"], "code_uid": "e91cd6011df5b6462502b7c65a43b874", "src_uid": "f587b1867754e6958c3d7e0fe368ec6e", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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])", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "6fdbe344048a97fed39dcb9f36e64a26", "src_uid": "6c7ab07abdf157c24be92f49fd1d8d87", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\na = [1, 2]\nb = 3\nn.times do\n x = gets.to_i\n if a.include?(x)\n if a[0] == x\n tmp = a[1]\n a[1] = b\n b = tmp\n else\n tmp = a[0]\n a[0] = b\n b = tmp\n end\n else\n puts \"NO\"\n exit\n end\nend\nputs \"YES\"", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "3561137bc2e0bba796bcd1590e371589", "src_uid": "6c7ab07abdf157c24be92f49fd1d8d87", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\ntemp = gets.to_i\na = []\na[0] = 2 if temp == 1\na[0] = 1 if temp == 2\na[1] = temp\nflag = true\nflag = false if temp==3\nty = [1,2,3]\nty.delete a[0]\nfor i in 2..n\n\ta[i] = gets.to_i\n\tflag = false if !ty.include? a[i]\n\tty.delete a[i]\n\ttyr = ty.first\n\tty = [1,2,3]\n\tty.delete tyr\nend\nif temp == 3 || flag == false\n\tprint('NO')\nelse\n\tprint(\"YES\")\nend\n\n\n\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "4c2a08c89623b6d5f26e8fc144191f07", "src_uid": "6c7ab07abdf157c24be92f49fd1d8d87", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s=gets()\nif not s.index '1'\nprint 'no'\nexit\nend\nindex=s.index('1')\ns=s[index..-1]\nprint s.count('0')>=6 ? 'yes' : 'no'", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "6e62b6a9f33d482aa7ef3e9af8946096", "src_uid": "88364b8d71f2ce2b90bdfaa729eb92ca", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = gets.chomp\nind = s.index(?1)\n\nif ind\n if s[ind+1..-1].delete(?1).size >= 6\n puts \"yes\"\n else\n puts \"no\"\n end\nelse\n puts \"no\"\nend", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "0fb08d948c3f55a933636a12a77ddb87", "src_uid": "88364b8d71f2ce2b90bdfaa729eb92ca", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = gets.chomp\ni = s.index(?1)\nif i == nil\n puts \"no\"\n exit\nend\ncnt = 0\n(i + 1).upto(s.size - 1) do |i|\n if s[i] == ?0\n cnt += 1\n end\nend\nif cnt >= 6\n puts \"yes\"\nelse\n puts \"no\"\nend", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "7d1658946e2643b9d626ccc2b72d376f", "src_uid": "88364b8d71f2ce2b90bdfaa729eb92ca", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "puts %w(Draw White Black)[$<.read.chars.inject(0){|s,c|s+(Hash[\"QRBNPKqrbnpk\".chars.zip([9,5,3,3,1,0,-9,-5,-3,-3,-1,0])][c]||0)}<=>0]\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "a00cbb7e8d892e2fca877c051858bbb0", "src_uid": "44bed0ca7a8fb42fb72c1584d39a4442", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "piece_value = { 'q' => 9, 'r' => 5, 'n' => 3, 'b' => 3, 'p' => 1, 'k' => 0 }\nwhite = 0\nblack = 0\n8.times do\n row = gets.chomp\n row_piece = row.split''\n row_piece.each do |piece|\n \tif(piece == 'Q' || piece == 'R' || piece == 'B' || piece == 'N' || piece == 'P' || piece == 'K')\n \t piece = piece.downcase\n \t\twhite = white + piece_value[piece]\n \telsif(piece == 'q' || piece == 'r' || piece == 'b' || piece == 'n' || piece == 'p' || piece == 'k')\n \t\tblack = black + piece_value[piece]\n \tend\n end\nend\nif white > black\n\tputs \"White\"\nelsif black > white\n\tputs \"Black\"\nelse\n\tputs \"Draw\"\nend\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "89ffdd573332eecd99cb85b4f6335f91", "src_uid": "44bed0ca7a8fb42fb72c1584d39a4442", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\ndef weigh(c)\n c = c.capitalize\n case c\n when 'Q'\n 9\n when 'R'\n 5\n when 'B'\n 3\n when 'N'\n 3\n when 'P'\n 1\n else\n 0\n end\nend\n\nwhite, black = 0, 0\n8.times {\n gets.chomp.split(//).each { |c|\n if c == '.'\n next\n elsif c == c.upcase\n white += weigh(c)\n else\n black += weigh(c)\n end\n }\n}\n\nif black < white\n puts \"White\"\nelsif black == white\n puts \"Draw\"\nelse\n puts \"Black\"\nend", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "860e248bef3a0ff9ab9fe0c5338ee089", "src_uid": "44bed0ca7a8fb42fb72c1584d39a4442", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\n\nbad = false\n1.upto(n - 1){|i|\n if (a[i] - a[i-1]).abs >= 2 then\n bad = true;\n end\n}\n\n\nif bad then\n puts \"NO\"\nelse\n puts \"YES\"\nend", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "2b167a83d75c692fdde5ecb39f207bda", "src_uid": "704d0ae50bccaa8bc49319812ae0be45", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,*a=$<.read.split.map &:to_i\nputs a.each_cons(2).all?{|x,y|(x-y).abs<2} ? :YES : :NO", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "a3fd15bb8aef63d66964dd95be4875cd", "src_uid": "704d0ae50bccaa8bc49319812ae0be45", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "gets\nputs (gets.split.map(&:to_i).each_cons(2).any? { |a| (a[0] - a[1]).abs > 1 } ? :NO : :YES)\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "897771da6aefca042ead03d15c73a140", "src_uid": "704d0ae50bccaa8bc49319812ae0be45", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,m=gets.split.map &:to_i;p (m*n-1)/(m-1)\n", "lang_cluster": "Ruby", "tags": ["brute force", "math", "implementation"], "code_uid": "b527e69890d14145e4f7e37e85b1ae44", "src_uid": "42b25b7335ec01794fbb1d4086aa9dd0", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "input=gets.split(\" \")\nn=input[0].to_i\nm=input[1].to_i\nk=n\ndays=0\nwhile k>0\n days+=1\n k=k-1\n if days % m == 0\n k=k+1\n end\nend\nputs days", "lang_cluster": "Ruby", "tags": ["brute force", "math", "implementation"], "code_uid": "0cbce1595de88a427df68c2c89bf2244", "src_uid": "42b25b7335ec01794fbb1d4086aa9dd0", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,m = gets.split.map(&:to_i)\nday = 0\nwhile n > 0\n day += 1\n n -= 1 if day % m != 0\nend\nputs day", "lang_cluster": "Ruby", "tags": ["brute force", "math", "implementation"], "code_uid": "afbd131c1a79305cbb138a53cc67e137", "src_uid": "42b25b7335ec01794fbb1d4086aa9dd0", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def print_and_exit(v)\n puts v\n exit 0\nend\n\nh1, h2 = gets.split.map(&:to_i)\na, b = gets.split.map(&:to_i)\n\nprint_and_exit(0) if h1 + 8*a >= h2\nprint_and_exit(-1) if a <= b\n\np (h2 - h1 - 8 * a).quo(12 * (a - b)).ceil", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "154e43bf5bd66deeecdebdf44032bb94", "src_uid": "2c39638f07c3d789ba4c323a205487d7", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "h1, h2 = gets.split.map(&:to_i)\na, b = gets.split.map(&:to_i)\n\nh1 += a * 8\nif h1 < h2 and b >= a\n puts -1\nelse\n cnt = 0\n rem = (h2 - h1)\n while rem > 0 do\n rem -= (a - b) * 12\n cnt += 1\n end\n puts cnt\nend\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "3eb4bb71dee7de01488be77e7c41cdd8", "src_uid": "2c39638f07c3d789ba4c323a205487d7", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a=gets.chomp.split(\" \")\n0.upto(1) {|i| a[i]=a[i].to_i}\nb=gets.chomp.split(\" \")\n0.upto(1) {|i| b[i]=b[i].to_i}\ndis=a[1]-a[0]\nfd=8*b[0]\nfn=12*b[1]\nad=12*b[0]\nan=12*b[1]\nif dis-fd<=0\nputs \"0\"\nelsif ad-an<=0\nputs \"-1\"\nelse\ndis=dis-fd+fn\nans=1\nloop do\ndis-=ad\nbreak if dis<=0\nans+=1\ndis+=an\nend\nputs \"#{ans}\"\nend", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "f509fa477b4950becf74e128a49c6307", "src_uid": "2c39638f07c3d789ba4c323a205487d7", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b,s=gets.split.map(&:to_i)\nt=s-a.abs-b.abs\nputs t>=0&&t%2==0?\"Yes\":\"No\"", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "ba13335e6891d3902019a46a22514082", "src_uid": "9a955ce0775018ff4e5825700c13ed36", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/ruby\n# coding: utf-8\n\na, b, c = gets.split.map &:to_i\nc -= a.abs + b.abs\nputs c < 0 || c % 2 > 0 ? \"No\" : \"Yes\"", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "dde2cfe38bdb2094c0bdf1f4e7eeba16", "src_uid": "9a955ce0775018ff4e5825700c13ed36", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a=gets.chomp.split(\" \").map {|i| i.to_i}\nneed=a[0].abs+a[1].abs\nstep=a[2]\nif need>step\n puts \"No\"\nelsif need==step \n puts \"Yes\"\nelse \n if (need-step)%2==0 \n puts \"Yes\"\n else\n puts \"No\"\n end\nend", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "ad10a4a0cd68e4f0689eb9ab97754197", "src_uid": "9a955ce0775018ff4e5825700c13ed36", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets\ns = gets\n\n1000.times{s = s.sub(/([aeiouy])[aeiouy]/,'\\1')}\n\nputs s\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "9172ccb70320803a59cc6706a600dbe6", "src_uid": "63a4a5795d94f698b0912bb8d4cdf690", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def read_input()\n \n cnt = Integer(STDIN.gets())\n string = String(STDIN.gets())[0...-1]\n \n raise \"Invalid input\" if string.length != cnt\n \n return string\n \nend\n\ndef trim_string()\n \n string = read_input()\n new_string = \"\"\n \n vowels = \"aeiouy\"\n prev_is_vowel = false\n \n string.each_char { |c|\n \n is_vowel = vowels.include? c\n \n new_string.concat(c) if (is_vowel and !prev_is_vowel) or !is_vowel\n \n prev_is_vowel = true ? is_vowel : false\n \n }\n \n puts new_string\n \nend\n\ntrim_string() \n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "e544df4a75704c41396a8a12a7802563", "src_uid": "63a4a5795d94f698b0912bb8d4cdf690", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\ns = gets.chomp\ncorrected = s[0]\nVowels = ['a', 'e', 'i', 'o', 'u', 'y']\nfor i in 1...n\n\tif (!Vowels.include? s[i]) || (!Vowels.include? s[i-1])\n\t\tcorrected += s[i]\n\tend\nend\n\nputs corrected", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "23de891a933ec783693ac389feef44ce", "src_uid": "63a4a5795d94f698b0912bb8d4cdf690", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s=gets.chomp\ni=0\nj=s.length-1\ndiff=0\nwhile i0 && s[i] == s[i-1] then\n\t\tr=r+1\n\tend\n\ti=i+1\nend\nputs r\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "54c6d621b16c40451292423bd64abafd", "src_uid": "d561436e2ddc9074b98ebbe49b9e27b8", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/ruby\n\n@anser_was_put = false\ndef put_answer(answer)\n if !@anser_was_put\n @anser_was_put = true\n puts answer\n end\nend\n\ndest_X, dest_Y = gets.chomp.split(\" \").map { |e| e.to_i }\ncommands = gets.chomp\n\n# Stupidity check\nif dest_X == 0 && dest_Y == 0 \n put_answer \"Yes\"\nend\n\nx, y = 0, 0\n\ncommands.each_char { |chr| \ncase chr\nwhen 'U'\n y += 1\nwhen 'D'\n y -= 1\nwhen 'L'\n x -= 1\nwhen 'R' \n x += 1\nelse\n\nend\n\n# First-time check\nif dest_X == x && dest_Y == y \n put_answer \"Yes\"\nend\n\n}\n\n\n# we've returned to the same point...\n# returning\nif x == 0 && y == 0\n put_answer \"No\"\nend \n\nx_coeff = x\ny_coeff = y\n\n# \n# dest_X = x_coeff * t + position[p].x \n# dest_Y = y_coeff * t + position[p].y\n# t > 0\n\nx, y = 0, 0\n\ncommands.each_char { |chr| \ncase chr\nwhen 'U'\n y += 1\nwhen 'D'\n y -= 1\nwhen 'L'\n x -= 1\nwhen 'R' \n x += 1\nelse\n\nend\n\n# put_answer \"Im here\" +x.to_s + \" \" + y.to_s\n\n#Three points\n# t_x = (dest_X - position[p].x) / x_coeff\n# t_y = (dest_Y - position[p].y) / y_coeff\nt_x = -1\nt_y = -1\ncurr_dest_x = 0\ncurr_dest_y = 0\nif x_coeff == 0\n curr_dest_x = x\nelse\n t_x = (dest_X - x) / x_coeff\n curr_dest_x = x + x_coeff * t_x \nend\n\nif y_coeff == 0\n curr_dest_y = y\nelse\n t_y = (dest_Y - y) / y_coeff\n curr_dest_y = y + y_coeff * t_y\nend\n\n#Le'ts check complex one\nif curr_dest_x == dest_X && curr_dest_y == dest_Y\n if x_coeff != 0 && y_coeff != 0\n if t_x == t_y && t_x >= 0 && t_y >= 0\n put_answer \"Yes\"\n # put_answer \"tx : #{t_x.to_s} ty : #{t_y.to_s} \"\n end\n elsif x_coeff == 0\n if t_y >= 0\n put_answer \"Yes\"\n # put_answer \"tx : #{t_x} ty : #{t_y} \"\n end\n elsif y_coeff == 0\n if t_x >= 0\n put_answer \"Yes\"\n # put_answer \"tx : #{t_x} ty : #{t_y} \"\n end\n end\n\nend\n\n\n}\n\nput_answer \"No\"\n", "lang_cluster": "Ruby", "tags": ["math", "implementation", "number theory"], "code_uid": "aa34ab25401e44b584ab81d78aecf1c5", "src_uid": "5d6212e28c7942e9ff4d096938b782bf", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "tx, ty = gets.strip.split(\" \").collect{|v| v.to_i}\ns = []\nidx = 0\ndx = dy = 0\ngets.strip.split(\"\").collect do |c|\n s[idx] = [1, 0] if c == 'R'\n s[idx] = [-1, 0] if c == 'L'\n s[idx] = [0, 1] if c == 'U'\n s[idx] = [0, -1] if c == 'D'\n dx += s[idx][0]\n dy += s[idx][1]\n idx += 1\nend\n\nif tx == 0 and ty == 0 then\n puts \"Yes\"\n exit\nend\n\nx = y = 0\ns.size.times do |i|\n x += s[i][0]\n y += s[i][1]\n k = 10**10\n k = (tx - x) / dx if dx != 0\n k = [k, (ty - y) / dy].min if dy != 0\n k = 0 if k < 0 or k == 10**10\n if k * dx + x == tx and k * dy + y == ty then\n puts \"Yes\"\n exit\n end\nend\n\nputs \"No\"", "lang_cluster": "Ruby", "tags": ["math", "implementation", "number theory"], "code_uid": "d5d83b4e9cbbdea453b52255344d66e6", "src_uid": "5d6212e28c7942e9ff4d096938b782bf", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b=gets.split.map(&:to_i)\ns=gets.chop\nx=y=0\ndef step(x,y,c)\n if c=='U' then y+=1\n elsif c=='D' then y-=1\n elsif c=='R' then x+=1\n elsif c=='L' then x-=1\n end\n [x, y]\nend\ns=\"0#{s}\"\ns.each_char {|c| x,y = step x,y,c}\n\ninf = 2**31\nk = inf\nk = a / x if x != 0\nk = [k, b / y].min if y != 0\nk-=100\nk = 0 if k == inf or k < 0\n\nx = k * x\ny = k * y\n200.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\nputs 'No'\n\n\n", "lang_cluster": "Ruby", "tags": ["math", "implementation", "number theory"], "code_uid": "7ca7e81dbf74d30d404d5657af664be0", "src_uid": "5d6212e28c7942e9ff4d096938b782bf", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/ruby\n\ndef f(x)\n\tif x == [0]\n\t\t0\n\telsif x == [1]\n\t\t1\n\telsif x[0] == 0\n\t\t2 * f(x[1..-1])\n\telse # x[0] == 1\n\t\t2 * f(x[1..-1]) + 2**(2*(x.size - 1))\n\tend\nend\n\nx = gets.strip.split(//).map(&:to_i)\nputs f(x) % 1000000007\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "da2803f395debc24d247b3d4cfccd5cb", "src_uid": "89b51a31e00424edd1385f2120028b9d", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "p (gets.to_i(2)<<$_.size-2)%(10**9+7)\n", "lang_cluster": "Ruby", "tags": ["math", "combinatorics"], "code_uid": "04b5467355510c6408c1c85fa9546f6e", "src_uid": "89b51a31e00424edd1385f2120028b9d", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "p (gets.to_i(2)<<$_.size-2)%(10**9+7)\n", "lang_cluster": "Ruby", "tags": ["math", "combinatorics"], "code_uid": "be3ca6ceedec02163248d10b0213f17c", "src_uid": "89b51a31e00424edd1385f2120028b9d", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.chomp.to_i\na=[]\nb=[]\nn.times do\n\tx,y=gets.chomp.split.map(&:to_i)\n\ta.push(x)\n\tb.push(y)\nend\ni=0\nres=0\nwhile i (b-i).abs\n p2+=1\n else\n d+=1\n end\n end\n end\n \n print \"#{p1} #{d} #{p2}\\n\"", "lang_cluster": "Ruby", "tags": ["brute force"], "code_uid": "a9229aa019364a6c89ba6e8f63d7ffbf", "src_uid": "504b8aae3a3abedf873a3b8b127c5dd8", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "A, B = gets.split.map(&:to_i) \n\naw, bw ,dw = 0,0,0\nfor i in 1..6\n if (i - A).abs < (i - B).abs \n aw+=1;\n elsif (i - A).abs > (i - B).abs\n bw+=1;\n else\n dw+=1;\n end\nend\nputs \"#{aw} #{dw} #{bw}\"", "lang_cluster": "Ruby", "tags": ["brute force"], "code_uid": "14fa29d059331f9441026533caef1826", "src_uid": "504b8aae3a3abedf873a3b8b127c5dd8", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/ruby\na,b=gets.split.map(&:to_i)\nh=1.step(6).group_by{|i|(a-i).abs<=>(b-i).abs}\nputs -1.step(1).map{|i|h[i] ? h[i].size : 0}*' '", "lang_cluster": "Ruby", "tags": ["brute force"], "code_uid": "e83b9962078b70fdd1c5b38c5972543f", "src_uid": "504b8aae3a3abedf873a3b8b127c5dd8", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def is_prime( n )\n\n\treturn false if n % 2 == 0 && n != 2\n\n\tdiv = 3\n\twhile( div * div <= n )\n\t\treturn false if n % div == 0\n\t\tdiv += 2\n\tend\n\n\treturn true;\nend\n\nn = gets.chomp.to_i\n\nif is_prime( n )\n\tputs 1\nelsif n % 2 == 0 || is_prime( n-2 )\n\tputs 2\nelse\n\tputs 3\nend\n", "lang_cluster": "Ruby", "tags": ["math", "number theory"], "code_uid": "f9fc4389431a63327c0bcc4b438dcff9", "src_uid": "684ce84149d6a5f4776ecd1ea6cb455b", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "# be name khoda ...\ndef read_ints; STDIN.gets.split.map(&:to_i); end\ndef isPrime(x)\n t = 2\n while (t*t <= x)\n if(x % t == 0) \n return false\n end\n t+=1;\n end\n return true\nend\nn = gets.to_i\nres = '85'\nif(n % 2 == 0)\n if(n == 2)\n res = '1'\n else\n res = '2'\n end\nelse\n if(isPrime(n))\n res = '1'\n elsif(isPrime(n-2))\n res = '2'\n else\n res = '3'\n end\nend\nputs res", "lang_cluster": "Ruby", "tags": ["math", "number theory"], "code_uid": "751dd3db699bb7c25b1daad3305dd69b", "src_uid": "684ce84149d6a5f4776ecd1ea6cb455b", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def isPrime?(x)\n d = 2\n until (d*d > x)\n if(x % d == 0)\n return false\n end\n d = d + 1\n end\n return true\nend\n\nn = gets.to_i\n\nif (n==2)\n puts 1\nelsif (n == 3)\n puts 1\nelsif (n == 4)\n puts 2\nelsif (n == 5)\n puts 1\nelsif (n == 6)\n puts 2\nelsif (n == 7)\n puts 1\nelsif (n % 2 == 0)\n puts 2\nelsif (isPrime?(n))\n puts 1\nelsif (isPrime?(n-2))\n puts 2\nelse\n puts 3\nend\n\n", "lang_cluster": "Ruby", "tags": ["math", "number theory"], "code_uid": "ebc52aa589f62e9dd8fbab0d3a5728e9", "src_uid": "684ce84149d6a5f4776ecd1ea6cb455b", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, x = gets.strip.split.map(&:to_i)\na = gets.strip.split.map(&:to_i)\ncount = Array.new(101, 0)\nn.times do |i|\n curr = a[i]\n count[curr] += 1\nend\nans = count[x] > 0 ? 1 : 0\nx.times do |i|\n ans += 1 if count[i] == 0\nend\nputs ans\n", "lang_cluster": "Ruby", "tags": ["greedy", "implementation"], "code_uid": "d1ecce6e66914f53995399b12d70796d", "src_uid": "21f579ba807face432a7664091581cd8", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,x,*a=$<.read.split.map &:to_i\nb=[*0...x]-a\np b.size+(a.include?(x)?1:0)", "lang_cluster": "Ruby", "tags": ["greedy", "implementation"], "code_uid": "26a988a16563e99dde788656aea1ea73", "src_uid": "21f579ba807face432a7664091581cd8", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a, q = gets.split.map(&:to_i)\n\nset = [[]]\nset << gets.split.map(&:to_i) if set[0].size != a\nset.flatten!\nset.sort!\n\n\ncounter = 0\n\nif set.include? q\n for i in 0...q\n counter += 1 unless set.include? i\n end\n counter += 1\nelse\n set << q\n set.sort!\n for i in 0...q\n counter += 1 unless set.include? i\n end\nend\n\nputs counter", "lang_cluster": "Ruby", "tags": ["greedy", "implementation"], "code_uid": "772278d43eb7245eab45fd3fa0d654ef", "src_uid": "21f579ba807face432a7664091581cd8", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "gets\ns=gets.chop\nputs [s.gsub(p=/\\(\\w*\\)/,?_).split(/_+/).map(&:size).max||0,(s.scan(/#{p}/)*?_).split(/[_()]+/).select{|e|e[0]}.size]*' '", "lang_cluster": "Ruby", "tags": ["expression parsing", "strings", "implementation"], "code_uid": "1268ca3d4051ee948ded9f8a4bbabe4f", "src_uid": "fc86df4931e787fa3a1a40e2aecf0b92", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.strip.to_i\ns = gets.strip\ninside = []\noutside = []\ninword = outword = 0\nis_open = false\n(0...n).each do |i|\n curr = s[i]\n case curr\n when '_'\n outword += 1\n inword += 1 if is_open\n next\n when '('\n is_open = true\n inword += 1\n next\n when ')'\n is_open = false\n inword += 1\n outword += 1\n next\n end\n if !curr.nil? && !curr.empty?\n if is_open\n inside[inword] = \"\" if inside[inword].nil?\n inside[inword] += curr\n else\n outside[outword] = \"\" if outside[outword].nil?\n outside[outword] += curr\n end\n end\nend\nmax_len = 0\noutside.each do |w|\n next if w.nil?\n max_len = [max_len, w.length].max\nend\nputs \"#{max_len} #{inside.each.select { |w| !w.nil? }.length}\"\n", "lang_cluster": "Ruby", "tags": ["expression parsing", "strings", "implementation"], "code_uid": "49a92b031a9e0d5fac59c042aca78e02", "src_uid": "fc86df4931e787fa3a1a40e2aecf0b92", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "gets\ns=gets.chop\nputs [s.gsub(p=/\\(\\w*\\)/,?_).split(?_).map(&:size).max||0,(s.scan(/#{p}/)*?_).split(/[_()]/).select{|e|e[0]}.size]*' '", "lang_cluster": "Ruby", "tags": ["expression parsing", "strings", "implementation"], "code_uid": "0f7f975a2c0c519e3ce6062a8b85bb49", "src_uid": "fc86df4931e787fa3a1a40e2aecf0b92", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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}\"", "lang_cluster": "Ruby", "tags": ["expression parsing", "strings", "implementation"], "code_uid": "56951e62022bb29c212ce4c072b39a3d", "src_uid": "fc86df4931e787fa3a1a40e2aecf0b92", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "\n\ndef main\n n = gets\n words = gets\n in_brackets = /\\([^)]+\\)/\n out_brackets = /(?:\\A|\\))[^\\(]+(?:\\(|\\z)/\n word_gex = /[A-Za-z]+/\n inner_brackets = words.scan(in_brackets)\n outer_brackets = words.scan(out_brackets)\n inner_words = inner_brackets.map{|s| s.scan(word_gex)}.flatten\n outer_words = outer_brackets.map{|s| s.scan(word_gex)}.flatten\n l = (outer_words.map(&:length).max) || 0\n i = (inner_words.length)\n puts(\"#{l} #{i}\")\nend\n\nmain\n", "lang_cluster": "Ruby", "tags": ["expression parsing", "strings", "implementation"], "code_uid": "01480334b03a852ee0c9657218b9e938", "src_uid": "fc86df4931e787fa3a1a40e2aecf0b92", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "gets\ntokenq = Queue.new\ncur_token = \"\"\n(gets.chomp + \"_\").each_char do |ch|\n if (ch == \"_\") || (ch == \")\") || (ch == \"(\")\n unless cur_token == \"\"\n tokenq << cur_token\n cur_token = \"\"\n end\n tokenq << ch \n else\n cur_token << ch\n end\nend\n\nbr_depth = 0\nans = [0,0]\nwhile true\n if tokenq.empty? then break else token = tokenq.pop end\n if token == \"(\"\n br_depth += 1 \n elsif token == \")\"\n br_depth -= 1 \n elsif token != \"_\"\n \n if br_depth > 0\n ans[1] += 1\n else\n ans[0] = [ans[0], token.length].max\n end\n \n end\n \nend\n\nputs ans.join(\" \")\n", "lang_cluster": "Ruby", "tags": ["expression parsing", "strings", "implementation"], "code_uid": "a24da5233d7a604967e011e7eaf8fab0", "src_uid": "fc86df4931e787fa3a1a40e2aecf0b92", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\ns = gets.chomp\nouts = ''\nins = ''\ninParen = false\nind = 0\nn.times do |i|\n next unless '(_)'.include?(s[i])\n if inParen\n ins << s[ind...i]\n ins << '_'\n ind = i\n else\n outs << s[ind...i]\n outs << '_'\n ind = i\n end\n case s[i]\n when '('\n inParen = true\n when ')'\n inParen = false\n end\nend\nouts << s[ind...n] if ind != n - 1 || n == 1\nreg = /\\(|\\)|_/\nans2 = ins.split(reg)\nans2.delete('')\nputs \"#{outs.split(reg).map(&:size).max || 0} #{ans2.size}\"\n", "lang_cluster": "Ruby", "tags": ["expression parsing", "strings", "implementation"], "code_uid": "f73576efc999dc1ad07dd198e53540f4", "src_uid": "fc86df4931e787fa3a1a40e2aecf0b92", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.to_i\ns1=gets.chomp\ns2=s1.gsub(/[(][^)]*?[)]/,\"_\")\n\nt1=s2.split(\"_\").map{|e| e.size}.max\nif t1!=nil then\n\tprint t1\nelse\n\tprint 0\nend\nprint \" \"\nans=0\nwhile t=s1.match(/[(][^)]*?[)]/)\n\tans+= t.to_s.gsub(/[)(]/,\"\").to_s.split(\"_\").count{|e| e.size>0}\n\ts1.sub!(/[(][^)]*?[)]/,\"\")\nend\nprint ans\nprint \"\\n\"\n\n", "lang_cluster": "Ruby", "tags": ["expression parsing", "strings", "implementation"], "code_uid": "39630cfe81f22555da9124efa5aef81b", "src_uid": "fc86df4931e787fa3a1a40e2aecf0b92", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "strLen = gets.chomp.to_i\nstr = gets.chomp\ninStr = []\n\nuntil str.index('(').nil?\n\topen = str.index('(')\n\tclose = str.index(')')\n\n\tinStr << str[open + 1..close - 1]\n\tstr = str[0...open] + '_' + str[(close + 1)...str.length]\nend\n\nstr = str.split('_')\n\ninStr.each_index do |i|\n\tinStr[i] = inStr[i].split('_')\n\tinStr[i].delete('')\nend\n\nstr.delete('')\noutLongestWord = 0\ninWord = 0\n\nstr.sort! do |a, b| \n\tif a.length > b.length \n\t\t-1 \n\telsif a.length == b.length \n\t\t0 \n\telse \n\t\t1 \n\tend\nend\n\nif str.length > 0\n\toutLongestWord = str[0].length\nend\n\ninStr.each do |is|\n\tinWord += is.length if is.length > 0\nend\n\nputs \"#{outLongestWord} #{inWord}\"", "lang_cluster": "Ruby", "tags": ["expression parsing", "strings", "implementation"], "code_uid": "b5234d77d1b5dee7722014e41a4acbbd", "src_uid": "fc86df4931e787fa3a1a40e2aecf0b92", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/ruby\na=0;b=0\n$<.read.split(')').each{|e|\n\tx,y=e.split('(')\n\t(x||'').scan(/[A-Za-z]+/).each{|f|a=[a,f.size].max}\n\tb+=(y||'').scan(/[A-Za-z]+/).size\n}\nputs [a,b]*' '", "lang_cluster": "Ruby", "tags": ["expression parsing", "strings", "implementation"], "code_uid": "c0baa8969999ba0df4611d9162d88fb9", "src_uid": "fc86df4931e787fa3a1a40e2aecf0b92", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "gets\nres=0, 0\ns=gets.chomp\nwhile s=~/\\(_*([^()]*)_*\\)/\n res[1]+=$1.split(/_+/).size if $1\n s[/\\([^()]*\\)/]=?_\nend\nres[0]=s.split(/_+/).map(&:size).max || 0\nputs res*' '\n", "lang_cluster": "Ruby", "tags": ["expression parsing", "strings", "implementation"], "code_uid": "f60aee828323f0f74a62ce3bf0407d45", "src_uid": "fc86df4931e787fa3a1a40e2aecf0b92", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "gets\nstr = gets.chomp\ninside = 0\nstr.gsub!(/\\(\\w*\\)/) do |m|\n inside += m.split(/[_\\(\\)]/).select { |s| s != '' }.size\n '_'\nend\nputs \"#{str.split('_').map(&:size).sort.last.to_i} #{inside}\"\n", "lang_cluster": "Ruby", "tags": ["expression parsing", "strings", "implementation"], "code_uid": "d9e1166a2e6a094938203faba9bf790f", "src_uid": "fc86df4931e787fa3a1a40e2aecf0b92", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "gets\ns=gets.chomp\nq=s.scan(/\\(\\w*\\)/).map{|v|v[1...v.size-1]}*'_'\nr=s.split(/\\(\\w*\\)/)*'_'\nputs \"#{(r.split('_')+[\"\"]).map{|v|v.size}.max} #{q.split('_').select{|v|v!=\"\"}.size}\"\n", "lang_cluster": "Ruby", "tags": ["expression parsing", "strings", "implementation"], "code_uid": "c2f5361d51603fc79dd335882ea7848e", "src_uid": "fc86df4931e787fa3a1a40e2aecf0b92", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "x = gets.to_i\n\nm = x % 4\n\nif m == 1\n puts \"0 A\"\nelsif m == 2\n puts \"1 B\"\nelsif m == 3\n puts \"2 A\"\nelse\n puts \"1 A\"\nend\n", "lang_cluster": "Ruby", "tags": ["brute force"], "code_uid": "85ddb2a4730513abcacc16328b15895e", "src_uid": "488e809bd0c55531b0b47f577996627e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\nif n % 4 == 1\n puts \"0 A\"\nelsif n % 4 == 3\n puts \"2 A\"\nelsif n % 4 == 2\n puts \"1 B\"\nelse\n puts \"1 A\"\nend", "lang_cluster": "Ruby", "tags": ["brute force"], "code_uid": "5663cd5e6b3693b3fa2d8edb4905043a", "src_uid": "488e809bd0c55531b0b47f577996627e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i%4\nif n == 0\n puts \"1 A\"\nelsif n == 1\n puts \"0 A\"\nelsif n == 2\n puts \"1 B\"\nelse\n puts \"2 A\"\nend", "lang_cluster": "Ruby", "tags": ["brute force"], "code_uid": "d34d7390a3058427766f784c44a271af", "src_uid": "488e809bd0c55531b0b47f577996627e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,R,r = gets.split.map{|x| x.to_f}\n\nif R-r >= r\n\ttheta = 2*Math.acos(r/(R-r))\n\n\tif (n-2)*Math::PI <= n * theta then\n\t\tputs \"YES\"\n\telse\n\t\tputs \"NO\"\n\tend\nelsif R-r>=0\n\tputs \"YES\" if n == 1\n\tputs \"NO\" if n != 1\nelse\n\tputs \"NO\"\nend\n", "lang_cluster": "Ruby", "tags": ["math", "geometry"], "code_uid": "f417c5e296b699f7d52571356d3a9852", "src_uid": "2fedbfccd893cde8f2fab2b5bf6fb6f6", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,R,r=gets.split.map{|_|_.to_i}\n\nif n == 1\n if R>=r\n puts \"YES\"\n else\n puts \"NO\"\n end\nelsif n == 2\n if R>=r*2\n puts \"YES\"\n else\n puts \"NO\"\n end\nelse\n if r/Math.sin(Math::PI/n)+r<=R+1e-14\n puts \"YES\"\n else\n puts \"NO\"\n end\nend\n", "lang_cluster": "Ruby", "tags": ["math", "geometry"], "code_uid": "4ad888aa46bb98f39a6e10b0a4db17ae", "src_uid": "2fedbfccd893cde8f2fab2b5bf6fb6f6", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, u, r = gets.split.map { |x| x.to_i }\nr_max = u\nif n > 1\n s = Math.sin(Math::PI / n).round(10)\n r_max = s * u / (1 + s)\nend\nputs(r <= r_max ? 'YES' : 'NO')", "lang_cluster": "Ruby", "tags": ["math", "geometry"], "code_uid": "9768b76d8743f9d138c87527a0572fe0", "src_uid": "2fedbfccd893cde8f2fab2b5bf6fb6f6", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "arr=gets.chomp.split.map(&:to_i)\nco = {}\narr.each do |a|\n if co[a].nil?\n co[a] = 1\n else\n co[a] +=1\n end\nend\n\nputs 4 - co.keys.length", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "252194da73181aee6102387a2748a50c", "src_uid": "38c4864937e57b35d3cce272f655e20f", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "puts 4-gets.strip.split(/ /).uniq.length\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "c4b4761753588a4866d9139b3090a6e7", "src_uid": "38c4864937e57b35d3cce272f655e20f", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "p 4-gets.split.uniq.size", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "f34e276f58525b3bb6176ae0543f2ed4", "src_uid": "38c4864937e57b35d3cce272f655e20f", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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< 1\n\tputs 'Need more data'\nelse\n\tputs x[0]\nend\n\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "19d839e4d158cc9b08f015dc47f8693e", "src_uid": "142e5f2f08724e53c234fc2379216b4c", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def gao1(a, b)\n\tc = 0\n\t4.times{|i| c += 1 if a[i] == b[i]}\n\tc\nend\n\ndef gao2(a, b)\n\tc = 0\n\t4.times{|i| c += 1 if b.index(a[i])}\n\tc\nend\n\nn = gets.to_i\nx = 100.upto(9999).map{|_| '%04d' % _}\nx.reject!{|_| _.bytes.sort.uniq.size < 4}\nn.times do\n\ta, b, c = gets.split.map(&:to_i)\n\ta = '%04d' % a\n\tc += b\n\tx.reject!{|_| gao1(_, a) != b || gao2(_, a) != c}\nend\n\nif x.empty?\n\tputs 'Incorrect data'\nelsif x.size > 1\n\tputs 'Need more data'\nelse\n\tputs x[0]\nend\n\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "78194cb9859fb8fd713eb0a84c388689", "src_uid": "142e5f2f08724e53c234fc2379216b4c", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "gets\nb=$_.each_char.max.to_i+1\nx,y=$_.split.map{|i|i.to_i(b)}\np (x+y).to_s(b).size\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "5f75aaa49b5857eb92203ba1ab92dc6d", "src_uid": "8ccfb9b1fef6a992177cc49bd56fab7b", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "p gets.split.map{|_|_.to_i(A=$_.bytes.max-47)}.inject(:+).to_s(A).size\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "de00a28d6ec4ec26738e164a3b6abf83", "src_uid": "8ccfb9b1fef6a992177cc49bd56fab7b", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "p gets.split.map{|_|_.to_i(A=$_.bytes.max-47)}.inject(:+).to_s(A).size\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "971d233a041c90af772942f35a99918c", "src_uid": "8ccfb9b1fef6a992177cc49bd56fab7b", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, m, k = gets.strip.split(' ').map(&:to_i)\nputs [m, k].min >= n ? \"Yes\" : \"No\"", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "558883662a5ea9fbc49a65efc9a31b8d", "src_uid": "6cd07298b23cc6ce994bb1811b9629c4", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!usr/bin/env ruby\n\n# https://codeforces.com/problemset/problem/1186/A\n\ninput = gets.chomp.split(' ').map(&:to_i)\n\nputs (input[0] <= input[1] && input[0] <= input[2]) ? \"Yes\" : \"No\"\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "067174852fbe7083b12eee9734e4a1f4", "src_uid": "6cd07298b23cc6ce994bb1811b9629c4", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,m,k = readline.split.map(&:to_i)\n\nputs (n <= [m,k].min) ? \"Yes\" : \"No\"\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "de05e070857fe4e3df8b1b2f61f70576", "src_uid": "6cd07298b23cc6ce994bb1811b9629c4", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\nputs 3*n/2\n", "lang_cluster": "Ruby", "tags": ["math", "number theory"], "code_uid": "8618a5f1b1dadcabc56b79685d8cbcce", "src_uid": "031e53952e76cff8fdc0988bb0d3239c", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.to_i\nputs n+n/2\n", "lang_cluster": "Ruby", "tags": ["math", "number theory"], "code_uid": "787e609f3da2779c8a318495b69d5451", "src_uid": "031e53952e76cff8fdc0988bb0d3239c", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.chomp.to_i\nputs (n*3)/2\n", "lang_cluster": "Ruby", "tags": ["math", "number theory"], "code_uid": "bbf1302bde3ac7e81e63d2667e9adbd8", "src_uid": "031e53952e76cff8fdc0988bb0d3239c", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\nas = gets.split.map(&:to_i)\n\nb = 0\nc = 0\n(0..n-1).each do |i|\n a = as[i]\n if a > 0\n b += a\n else\n c += a\n end\nend\nputs b - c", "lang_cluster": "Ruby", "tags": ["greedy"], "code_uid": "a43dc780fa304f11a3b9b6e6dff9ad92", "src_uid": "4b5d14833f9b51bfd336cc0e661243a5", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,*a=$<.read.split.map &:to_i\nx,y=a.partition{|e|e>0}\np x.reduce(0,:+)-y.reduce(0,:+)", "lang_cluster": "Ruby", "tags": ["greedy"], "code_uid": "475ba3621b97b1ebe2af4db0d1ee72b9", "src_uid": "4b5d14833f9b51bfd336cc0e661243a5", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\n\nnumbers = gets.split.map(&:to_i)\npositive_sum = 0\nnegative_sum = 0\n\nnumbers.each do |number|\n number >= 0 ? positive_sum += number : negative_sum += number\nend\n\nputs positive_sum - negative_sum", "lang_cluster": "Ruby", "tags": ["greedy"], "code_uid": "aff80cfd1f30306335eb24b97eec7ef1", "src_uid": "4b5d14833f9b51bfd336cc0e661243a5", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def cal(p, t, c)\n sum, sumt = 0, 0\n p.zip(t).each do |pp, tt|\n sumt += tt * c\n if pp > sumt\n sum += (pp - sumt)\n end\n end\n return sum\nend\n\nn, c = readline.split(' ').collect(&:to_i)\np = readline.split(' ').collect(&:to_i)\nt = readline.split(' ').collect(&:to_i)\ndiff = cal(p, t, c) - cal(p.reverse, t.reverse, c)\nif diff > 0\n puts \"Limak\"\nelsif diff < 0\n puts \"Radewoosh\"\nelse\n puts \"Tie\"\nend\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "e3e70ea742787926d398441733a887af", "src_uid": "8c704de75ab85f9e2c04a926143c8b4a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "7027200639d8a5c048714cbf15519728", "src_uid": "8c704de75ab85f9e2c04a926143c8b4a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "(n,c),s,t=$<.map{|e|e.split.map(&:to_i)}\na,b=[n.times,(n-1).downto(0)].map{|e|x=y=0;e.each{|i|y+=[0,s[i]-c*x+=t[i]].max};y}\nputs [:Tie,:Limak,:Radewoosh][a<=>b]", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "3aa1d1b0e18bd6a5963b013ac10e1881", "src_uid": "8c704de75ab85f9e2c04a926143c8b4a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "MOD=10**9+7\ncnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)\ndef gs() gets.chomp end\ndef gi() gets.to_i end\ndef gsmi() gets.chomp.split.map(&:to_i) end\n\ndef desc(ar) ar.sort!{|x,y|y<=>x} end\ndef min(a,b) a<=b ? a : b end\ndef max(a,b) a>=b ? a : b end\ndef sum(ar) ar.inject(:+) end\n\n#def bs(ar,eq,n) en=(eq==1 ? :>= : :>); ar.bsearch_index{|x|x.send(en,n)} end\ndef C(a,b) b==0||a==b ? 1 : (b=a-b if a/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", "lang_cluster": "Ruby", "tags": ["math", "number theory"], "code_uid": "b8b9ab64f8e6dae5f10c346a8254feb3", "src_uid": "04610fbaa746c083dda30e21fa6e1a0c", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, m = readline.split.map(&:to_i)\ni = 2\ncnt = 0\nl = Array.new(100)\nwhile i*i<=n\n\tif n%i == 0 \n\t\tl[cnt] = i\n\t\tcnt += 1\n\t\twhile n % i == 0 do n/=i end\n\tend\n\ti += 1\nend\nif n > 1 \n\tl[cnt] = n\n\tcnt += 1\nend\nans = 1\n$mod = 1000000007\ndef qp x, y\n\tans = 1\n\twhile y>0\n\t\tif (y&1)==1 then ans = ans * x % $mod end\n\t\tx = x * x % $mod\n\t\ty >>= 1\n\tend\n\tans\nend\nfor i in 0..cnt-1\n\ttmp = m\n\twhile tmp > 0\n\t\tans *= qp(l[i], tmp/l[i])\n\t\tans %= $mod\n\t\ttmp/=l[i]\n\tend\nend\nputs ans", "lang_cluster": "Ruby", "tags": ["math", "number theory"], "code_uid": "2554ac74928f5319fd6e246e8b3dd020", "src_uid": "04610fbaa746c083dda30e21fa6e1a0c", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\nt = gets\ns = t.chomp.split(//).map(&:to_i)\nputs (t=~/^(4|7)+$/ && s[0...n/2].reduce(:+) == s[n/2...n].reduce(:+))?'YES':'NO'\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "a7bd2d07add2d0fc89474609a910211e", "src_uid": "435b6d48f99d90caab828049a2c9e2a7", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def check_lucky(num)\n\tfor char in num.split('')\n\t\tif char != '4' && char != '7'\n\t\t\treturn false\n\t\tend\n\tend\n\treturn true\nend\n\nn = gets.to_i\na = gets.chomp\n\nif check_lucky(a) && a.split('').map(&:to_i).slice(0,n/2).sum == a.split('').map(&:to_i).slice(n/2,n).sum\n\tputs \"YES\"\nelse\n\tputs \"NO\"\nend", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "4cf2f998485c8885c4fcfa836cccb529", "src_uid": "435b6d48f99d90caab828049a2c9e2a7", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.to_i\nputs gets=~/^[47]+$/ && $_[0..n/2-1].sum==$_[n/2..n-1].sum ? \"YES\" : \"NO\"\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "a87b9b2b4276d29b0ab22acdd6aceedc", "src_uid": "435b6d48f99d90caab828049a2c9e2a7", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "input = Array.new\nwhile i = $stdin.gets\n input << i.strip\nend\n\nn, k = input.shift.split.map(&:to_i)\n\nif k % 2 == 1\n puts 1\nelse\n pow_of_two = 0\n while k >= 2 do\n break if k % 2 == 1\n k = k / 2\n pow_of_two += 1\n end\n puts pow_of_two + 1\nend\n", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "binary search", "implementation", "bitmasks"], "code_uid": "b545cfbed05bf81d688adc797562145e", "src_uid": "0af400ea8e25b1a36adec4cc08912b71", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "length, index = gets.split.map(&:to_i)\nans = 1\n\nwhile((index%2)==0)\n ans += 1\n index /= 2\nend\nputs ans\n", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "binary search", "implementation", "bitmasks"], "code_uid": "0d7650ad95515095fc61da282da49adc", "src_uid": "0af400ea8e25b1a36adec4cc08912b71", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, k = gets.chomp.split(\" \").map(&:to_i)\nans = 1;(ans +=1; k/=2;) while(k%2==0);\np ans\n", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "binary search", "implementation", "bitmasks"], "code_uid": "4e22db6bbe29d434e97ea29ea9abcc51", "src_uid": "0af400ea8e25b1a36adec4cc08912b71", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "x = gets.to_i\n p (x==3 ? 5 : (Math::sqrt(2*(x-1)+0.9).floor+1)/2*2+1)\n", "lang_cluster": "Ruby", "tags": ["math", "dp", "constructive algorithms"], "code_uid": "9597280c63e787e787c294d0e38d230f", "src_uid": "01eccb722b09a0474903b7e5abc4c47a", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "x = gets.to_i\n p (x==3 ? 5 : (Math::sqrt(2*(x-1)+0.9).floor+1)/2*2+1)", "lang_cluster": "Ruby", "tags": ["math", "dp", "constructive algorithms"], "code_uid": "a109b1f968329f18a1128286c181a2c3", "src_uid": "01eccb722b09a0474903b7e5abc4c47a", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/env ruby\n\nxval = gets.to_i\nn = 1\ncatch(:found) do\n loop do\n field = Array.new(n){Array.new(n, false)}\n cnt = 0\n (1..(n+1)/2).each do |y|\n neigh_y = n-y+1\n next if (y-neigh_y).abs == 1\n (1..(n+1)/2).each do |x|\n neigh_x = n-x+1\n next if (x-neigh_x).abs == 1\n next if (x-1 >= 1 && field[x-1-1][y-1]) || (y-1 >= 1 && field[x-1][y-1-1])\n\n tmp = nil\n if neigh_x != x && neigh_y != y\n tmp = 4\n elsif neigh_x == x && neigh_y == y\n tmp = 1\n else\n tmp = 2\n end\n #puts \"#{x} #{y} #{tmp}\" if n == 5\n if cnt+tmp == xval\n throw :found\n elsif cnt+tmp < xval\n cnt += tmp\n field[x-1][y-1] = true\n end\n end\n end\n n += 1\n end\nend\n\np n\n", "lang_cluster": "Ruby", "tags": ["math", "dp", "constructive algorithms"], "code_uid": "6df6ee2f35940e36b118928e895e6845", "src_uid": "01eccb722b09a0474903b7e5abc4c47a", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "\ns = gets.chomp.to_i\nar = gets.chomp.split.map {|x| x.to_i}\nmin = []\n\nunless ar.size != s \n\t(0...ar.size).each do |n|\n\t\tif ar[n] != ar.first and ar[n] != ar.last\n\t\t\tcomb = (ar - [ar[n]]) \n\t\t\tm = []\n\t\t\t(1...comb.size).each do |c|\n\t\t\t\tif comb[c] != comb.first\n\t\t\t\t\t#puts \"#{comb[c]} - #{comb[c-1]} = #{(comb[c] - comb[c-1])}\" \n\t\t\t\t\tm << (comb[c] - comb[c-1])\n\t\t\t\tend\n\t\t\tend\n\t\t\tmin << m.max\n\t\tend\n\t\t#if ar[n] == ar.first then puts ar.first end\n\tend \n\tp min.min\nend\n\n", "lang_cluster": "Ruby", "tags": ["brute force", "math", "implementation"], "code_uid": "b55d2236a42d0f2840f72a8a5a2dd10b", "src_uid": "8a8013f960814040ac4bf229a0bd5437", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\n\na = gets.split.map(&:to_i).sort\n\nres = a[n-1] - a[0]\n\nfor i in 1..n-2\n mx = 0\n for j in 1..n-1\n if j == i\n next\n elsif j - 1 == i\n mx = a[j] - a[j-2] if a[j] - a[j-2] > mx\n else\n mx = a[j] - a[j-1] if a[j] - a[j-1] > mx\n end\n end\n res = mx if mx < res\nend\n\nputs res", "lang_cluster": "Ruby", "tags": ["brute force", "math", "implementation"], "code_uid": "e74d8598ee011ba0ba6619b815f0d2fc", "src_uid": "8a8013f960814040ac4bf229a0bd5437", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "\nn = gets.chomp.to_i;\narr = gets.chomp.split.map(&:to_i);\nmax = 0;\nans = 0x7fffffff;\n\n(1...n).each {|i| max = [max, arr[i] - arr[i - 1]].max};\n(2...n).each {|i| ans = [ans, [max, arr[i] - arr[i - 2]].max].min};\np ans;", "lang_cluster": "Ruby", "tags": ["brute force", "math", "implementation"], "code_uid": "8544a9aee48262d43b4482a35ab51cc1", "src_uid": "8a8013f960814040ac4bf229a0bd5437", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def same(pos, p)\n 4.times do | i |\n if pos[i] == p then return i end\n if pos[i] == (p[2..3] + p[0..1]) then return i end\n end\n return -1\nend\ndef solve(pos , xmin, xmax, ymin, ymax)\n ans = Array.new\n ans[0] = same(pos, [xmin, ymin, xmin, ymax])\n ans[1] = same(pos, [xmin, ymin, xmax, ymin])\n ans[2] = same(pos, [xmin, ymax, xmax, ymax])\n ans[3] = same(pos, [xmax, ymin, xmax, ymax])\n# p ans\n ans.sort!\n 4.times do |i|\n if ans[i] != i then return false end\n end\n return true\nend\nxmin = 1000000000\nymin = 1000000000\nxmax = -1000000000\nymax = -1000000000\npos = Array.new\n4.times do \n data = gets.split.map(&:to_i)\n pos.push(data)\n if xmin > data[0] then xmin = data[0] end\n if xmin > data[2] then xmin = data[2] end\n if xmax < data[0] then xmax = data[0] end\n if xmax < data[2] then xmax = data[2] end\n if ymin > data[1] then ymin = data[1] end\n if ymin > data[3] then ymin = data[3] end\n if ymax < data[1] then ymax = data[1] end\n if ymax < data[3] then ymax = data[3] end\nend\n\nif solve(pos, xmin, xmax, ymin, ymax) then\n puts \"YES\"\nelse\n puts \"NO\"\nend\n\n", "lang_cluster": "Ruby", "tags": ["brute force", "constructive algorithms", "math", "implementation", "geometry"], "code_uid": "d79b2e56d69e099405f52831c83792f3", "src_uid": "ad105c08f63e9761fe90f69630628027", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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'", "lang_cluster": "Ruby", "tags": ["brute force", "constructive algorithms", "math", "implementation", "geometry"], "code_uid": "7d5cd5306b98f61655df0e7baf92b8d7", "src_uid": "ad105c08f63e9761fe90f69630628027", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "=begin\n , \\ / ,\n / \\ )\\__/( / \\\n / \\ (_\\ /_) / \\\n ____/_____\\__\\@ @/___/_____\\____\n | |\\../| |\n | \\VV/ |\n | ------hoi------- |\n |_________________________________|\n | /\\ / \\\\ \\ /\\ |\n | / V )) V \\ |\n |/ ` // ' \\|\n ` V '\n=end\n\nrequire 'set'\n\nvertices = Set.new\nsegments = Set.new\nhorizontal, vertical = 0, 0\nrectangle = true\n4.times do\n\tx1, y1, x2, y2 = gets.split.map(&:to_i)\n\tsegments << [x1, y1, x2, y2]\n\tif x1 == x2\n\t\tvertical += 1\n\telsif y1 == y2\n\t\thorizontal += 1\n\telse\n\t\thorizontal, vertical = -1, -1\n\t\tbreak\n\tend\n\tvertices << [x1, y1] and vertices << [x2, y2]\nend\n\nif vertices.size == 4 && segments.size == 4 && horizontal == 2 && vertical == 2\n puts \"YES\";\nelse\n puts \"NO\";\nend", "lang_cluster": "Ruby", "tags": ["brute force", "constructive algorithms", "math", "implementation", "geometry"], "code_uid": "6b3dfcec217a2578c528feec38b63cb4", "src_uid": "ad105c08f63e9761fe90f69630628027", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "j, count = 0, 0\nn = gets.chomp.to_i\ns = 0\nif n==1\n puts n\nelse\n for i in 1..n\n j+=i\n s+=j\n break if s>n\n count+=1\n end\n puts count\nend\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "07ca9fec5a4d694d96293b2ceeed4a6d", "src_uid": "873a12edffc57a127fdfb1c65d43bdb0", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "cubes = gets.chomp.to_i\nmax_height = 0\ncube_height = [0, 0]\n\n\nfor num in 1...10000\n cube_height[num] = num + cube_height[num-1]\n cubes -= cube_height[num]\n if cubes >= 0\n max_height += 1\n else\n break\n end\nend\n\nputs max_height\n\n\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "eb24d52d824b6187c5c32519b1adb140", "src_uid": "873a12edffc57a127fdfb1c65d43bdb0", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\ni=1;s=1;s1=1\nwhile s1<=n\n i+=1\n s+=i\n s1+=s\nend\nputs i-1", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "21be7f74e4957035f7fe8e24c989c4ef", "src_uid": "873a12edffc57a127fdfb1c65d43bdb0", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, k = gets.split.map(&:to_i)\nk.times do\n if n % 10 == 0\n n /= 10\n else\n n -= 1\n end\nend\nputs n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "9559faee2fe29e2de726dda3eb4f247b", "src_uid": "064162604284ce252b88050b4174ba55", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "first = gets.chomp.split(\" \")\n\nnumber = first[0].to_i\nn = first[1].to_i\n\nfor i in (1...n+1)\n if number%10 == 0\n number /= 10\n else\n number -= 1\n end\nend\n\nputs number", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "881a458e1be393044deaab37906200c3", "src_uid": "064162604284ce252b88050b4174ba55", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, k = gets.split.map(&:to_i)\n\nk.times do\n if n % 10 == 0\n n /= 10\n else\n n -= 1\n end\nend\nputs n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "68ff2ecdd1818486948d55ab291307f2", "src_uid": "064162604284ce252b88050b4174ba55", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "gets\nh={}\ngets.split.map(&:to_i).each{|e| h[e] ? h[e]+=1 : h[e]=1}\nf=->(n){n*(n+1)/2}\nres=0\nx=10**9*2\nh.sort.reverse.each{|k,v|\n a=f[x=[k, x].min]\n b=f[[x-v, 0].max]\n res+=a-b\n x=[x-v, 0].max\n}\nputs res\n", "lang_cluster": "Ruby", "tags": ["sortings", "greedy"], "code_uid": "e4fcebcd5338850036576a719b36a217", "src_uid": "3c4b2d1c9440515bc3002eddd2b89f6f", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.chomp.to_i\nas = gets.chomp.split.map(&:to_i)\nans = 0\n\nas.sort!.reverse!\nb = as[0]\nas.each do |a|\n ans += [a, b].min\n b = [[a - 1, b - 1].min, 0].max\nend\n\nputs ans\n", "lang_cluster": "Ruby", "tags": ["sortings", "greedy"], "code_uid": "999a81fdc7f4e138be1aceb82e240649", "src_uid": "3c4b2d1c9440515bc3002eddd2b89f6f", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "gets\na=gets.split.map &:to_i\nh = {}\na.sort.each{|x|\n x -= 1 while h[x]\n h[x] = true\n}\np h.map{|k,v|[k,0].max}.inject :+\n", "lang_cluster": "Ruby", "tags": ["sortings", "greedy"], "code_uid": "c1734762ba6cc1f46e57dbdef35583a8", "src_uid": "3c4b2d1c9440515bc3002eddd2b89f6f", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "vp = gets.to_f\nvd = gets.to_f\nt = gets.to_f\nf = gets.to_f\nc = gets.to_f\n\ndist = vp * t\ncount = 0\nwhile (dist + 0.0000000000001) < c\n catch = (dist / (vd - vp)) * vd\n if (catch + 0.0000000000001) >= c\n break\n else\n count += 1\n\tdist = catch + (((catch / vd) + f) * vp)\n end\nend\n\nif(vd > vp)\n puts count\n else\n puts 0\n end", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "47f09e7875b808b1bdd4bdbb24a00b5f", "src_uid": "c9c03666278acec35f0e273691fe0fff", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def escape\n vp, vd, t, f, c = 5.times.map{gets.to_f}\n d, b = vp * t, 0\n\n if vd > vp\n while true\n d += d / (vd - vp) * vp\n\n break if d >= c\n\n d += (d / vd + f) * vp\n b += 1\n end\n end\n\n puts b\nend\n\nescape", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "a566165008f99db00ae55c2ce282c16a", "src_uid": "c9c03666278acec35f0e273691fe0fff", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "vp = gets.to_f\nvd = gets.to_f\nt = gets.to_f\nf = gets.to_f\nc = gets.to_f\n\nif vp >= vd\n dem = 0\nelse\n mile = c/vp\n dem = 0\n T = []\n T[dem] = t*vp/(vd-vp)\n\n while t < mile do\n t += T[dem]\n if t < mile\n t += T[dem] + f\n dem += 1\n T[dem] = t*vp/(vd-vp)\n end\n end\nend\n\nputs dem ", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "cede4ccc848f8a4d23eb50c95819062e", "src_uid": "c9c03666278acec35f0e273691fe0fff", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "$n, $k = gets.split.map(&:to_i)\ndef calc(v)\n base = $k\n sum = v\n t = v / base\n while t > 0\n sum += t\n base *= $k\n t = v / base\n end\n sum\nend\n\ndef binary_search(l, r)\n return l if l > r\n m = (l + r) / 2\n t = calc(m)\n if t > $n\n return binary_search(l, m-1)\n elsif t < $n\n return binary_search(m+1, r)\n else\n return m\n end\nend\n\nputs binary_search(1, $n)\n", "lang_cluster": "Ruby", "tags": ["implementation", "binary search"], "code_uid": "11198667a3ac55919766306d9be33517", "src_uid": "41dfc86d341082dd96e089ac5433dc04", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "$n,$k=gets.split.map(&:to_i)\n\ndef line(v)\n\tret=v\n\tm=$k\n\t31.times{\n\t\tret+=v/m\n\t\tm*=$k\n\t}\n\tret\nend\n\ndef bin_search(l,r)\n\treturn -1 if l>r\n\tif l==r\n\t\treturn line(l)<$n ? -1 : l\n\tend\n\tm=(l+r)/2\n\tlines=line(m)\n\tif lines<$n\n\t\treturn bin_search(m+1,r)\n\telse\n\t\tbs=bin_search(l,m-1)\n\t\treturn bs==-1 ? m : bs\n\tend\nend\n\np bin_search(1,10**9)", "lang_cluster": "Ruby", "tags": ["implementation", "binary search"], "code_uid": "4a28aa9afad0c10b1e4e153598d21586", "src_uid": "41dfc86d341082dd96e089ac5433dc04", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,k = gets.split.map(&:to_i)\n\ndef search n,h,k\n i = 0\n s = 0\n loop do\n return false if h.zero?\n s += h\n return true if s >= n\n h /= k\n end\nend\nl = 1\nu = n\nh = (l+u)/2\nloop do\n if search n,h,k\n u = h\n else\n l = h\n end\n break if u-l < 5\n h = (l+u)/2\nend\nl.upto u do |h|\n if search n,h,k\n p h\n break\n end\nend\n", "lang_cluster": "Ruby", "tags": ["implementation", "binary search"], "code_uid": "8f6af1137480113bf7cd57b92c772fa4", "src_uid": "41dfc86d341082dd96e089ac5433dc04", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "x, y = gets.split.map(&:to_i)\nn = (gets.to_i-1)%6\nputs [x,y,y-x,0-x,0-y,x-y][n] % (1000000007)", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "fda5869b10fee98d57ff6a706034da71", "src_uid": "2ff85140e3f19c90e587ce459d64338b", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "# coding: utf-8\n\nx, y = gets.split.map(&:to_i)\nn = gets.to_i\n\n# f1 = x, f2 = y\n# f_i = f_i-1 + f_i+1\n# f_i+1 = f_i - f_i-1\n# f1 = x\n# f2 = y\n# f3 = y - x\n# f4 = f3 - f2 = y - x - y = -x\n# f5 = f4 - f3 = -x - (y - x) = -y\n# f6 = f5 - f4 = -y - (-x) = -y + x\n# f7 = f6 - f5 = -y + x - (-y) = x = f1 cycle!\n# f8 = f7 - f6 = x - (-y + x) = y = f2 cycle!\n# f9 = f8 - f7 = y - x = f3 cycle!\nMODULO_BASE = 10**9 + 7\narf = [x, y, y - x, -x, -y, -y + x]\nn_mod_index = (n-1)%6\nputs \"#{arf[n_mod_index] % MODULO_BASE}\"\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "20b212b36e3eb48201df4ec1523d61ea", "src_uid": "2ff85140e3f19c90e587ce459d64338b", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "x,y = gets.split(' ').map{|x| x.to_i}\nn =gets.split(' ')[0].to_i\na = [x,y,y-x,-x,-y,x-y]\nn-=1\np a[n%6]%1000000007\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "fa411685b8315b10ddfd843b62a102a9", "src_uid": "2ff85140e3f19c90e587ce459d64338b", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def run\n m, n = $stdin.gets.split.map(&:to_i)\n b = $stdin.gets.split.map(&:to_i)\n # a = [nil] * m\n a = []\n b.each_with_index do |v, i|\n v.upto(m) do |j|\n a[j - 1] = v unless a[j - 1]\n end\n end\n puts a.join(\" \")\nend\n\nrun if $0 == __FILE__\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "bb3f1737faaea0bd2f1ab93898aa5ac6", "src_uid": "2e44c8aabab7ef7b06bbab8719a8d863", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, m = gets.chomp.split(/\\s+/).map(&:to_i)\nb = gets.chomp.split(/\\s+/).map(&:to_i)\nn.times do |i|\n print b.select{ |t| (t - 1) <= i }.first\n print \" \"\nend\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "2d053594494a390e511a8432254bd600", "src_uid": "2e44c8aabab7ef7b06bbab8719a8d863", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "\nn, m = gets.split(' ').map {|x| x.to_i}\narr_true = Array.new(n, 0)\narr = Array.new\narr = gets.split(' ').map {|x| x.to_i}\nfor i in 0..m-1\n\tfor j in arr[i]..n\n\t\tif (arr_true[j-1] == 0)\n\t\t\tarr_true[j-1] = arr[i]\n\t\tend\n\tend\nend\n\narr_true.each do |x|\n\tprint (x)\n\tprint (' ')\nend\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "947cb3ba7cf6702c6947b5942f42a965", "src_uid": "2e44c8aabab7ef7b06bbab8719a8d863", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby 3", "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]}", "lang_cluster": "Ruby", "tags": ["math", "dp", "combinatorics", "bitmasks", "matrices"], "code_uid": "a20f7f0994ca7de5b4b9abd21fa7093a", "src_uid": "02f5fe43ea60939dd4a53299b5fa0881", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby 3", "source_code": "m=10**9+7;f=->a,n{a.pow(n,m)};gets;$<.map{|s|n,k=s.split.map &:to_i;a=f[2,n-1];p [(f[a*2,k]+a*f[a-1,k])*f[a+1,m-2]%m,f[a+1,k]][n%2]}", "lang_cluster": "Ruby", "tags": ["math", "dp", "combinatorics", "bitmasks", "matrices"], "code_uid": "333f73dbc56607fda7b93cc0c38d80ca", "src_uid": "02f5fe43ea60939dd4a53299b5fa0881", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby 3", "source_code": "M=10**9+7;w=->(b,e){b.pow(e,M)}\r\ngets.to_i.times.map{n,k=gets.split.map &:to_i;x=w.(2,n-1);p [(w.(2*x,k)+x*w.(x-1,k))*w.(x+1,M-2)%M,w.(x+1,k)][n%2]}", "lang_cluster": "Ruby", "tags": ["math", "dp", "combinatorics", "bitmasks", "matrices"], "code_uid": "039241bccde0e32427ef7de0e36bb23d", "src_uid": "02f5fe43ea60939dd4a53299b5fa0881", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby 3", "source_code": "m=10**9+7;f=->{_1.pow(_2,m)};gets;$<.map{n,k=_1.split.map &:to_i;a=f[2,n-1];p [(f[a*2,k]+a*f[a-1,k])*f[a+1,m-2]%m,f[a+1,k]][n%2]}", "lang_cluster": "Ruby", "tags": ["math", "dp", "combinatorics", "bitmasks", "matrices"], "code_uid": "727d3dca901e8eeaab505df4726f42fa", "src_uid": "02f5fe43ea60939dd4a53299b5fa0881", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b,c,d,e=gets.chomp.split.map(&:to_i)\nputs (Math.hypot((d-b),(e-c))/(2*a)).ceil", "lang_cluster": "Ruby", "tags": ["math", "geometry"], "code_uid": "84d84a875685a977e791f3d71ff7474b", "src_uid": "698da80c7d24252b57cca4e4f0ca7031", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b,c,d,e=gets.chomp.split.map(&:to_i)\nputs (Math.hypot((d-b),(e-c))/(2*a)).ceil\n", "lang_cluster": "Ruby", "tags": ["math", "geometry"], "code_uid": "0922bec7d6d01f5a160e3876dcb55db8", "src_uid": "698da80c7d24252b57cca4e4f0ca7031", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "r,x,y,x1,y1 = gets.split(\" \").map(&:to_i)\nd = Math.sqrt((y1-y)**2 + (x1-x)**2)\nputs (d/(2*r).to_f).ceil", "lang_cluster": "Ruby", "tags": ["math", "geometry"], "code_uid": "a277a5fcf07dc76ccb1583c49dff7035", "src_uid": "698da80c7d24252b57cca4e4f0ca7031", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "gets;puts gets.upcase.chars.uniq.size<27?:NO:'YES'", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "54f35b2bd2a48c2cb7fa2a0149584dd8", "src_uid": "f13eba0a0fb86e20495d218fc4ad532d", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "count = gets.to_i\nword = gets.downcase.chomp\nif count < 26\n puts 'NO'\nelse \n mas = Array.new(26) { |i| 0 }\n word.each_char{ |i| mas[i.ord - 97] = 1 }\n puts mas.inject(0){ |result, elem| result + elem} == 26 ? \"YES\" : \"NO\" \nend", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "4a28fb7ac7489adeb7631209b040f8e1", "src_uid": "f13eba0a0fb86e20495d218fc4ad532d", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "gets;puts gets.upcase.chars.uniq.size<27?:NO:'YES'\n", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "f9b84500ed67dd524d74b8c66b362947", "src_uid": "f13eba0a0fb86e20495d218fc4ad532d", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "puts (1..gets.split(' ').map(&:to_i).min).to_a.inject(:*)\n", "lang_cluster": "Ruby", "tags": ["math", "implementation", "number theory"], "code_uid": "2cc3895f4a6d32e4dd2af4e2c6437ac6", "src_uid": "7bf30ceb24b66d91382e97767f9feeb6", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "puts (1..gets.split.map(&:to_i).min).inject(1, :*)", "lang_cluster": "Ruby", "tags": ["math", "implementation", "number theory"], "code_uid": "cb1fd3fccdaec6651a566d4d16a3e67f", "src_uid": "7bf30ceb24b66d91382e97767f9feeb6", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b=gets.split.map &:to_i\np (1..[a,b].min).reduce :*", "lang_cluster": "Ruby", "tags": ["math", "implementation", "number theory"], "code_uid": "a0faeb85a69ad69730c2c6a2cbd39fe5", "src_uid": "7bf30ceb24b66d91382e97767f9feeb6", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "t, a, b = gets.split(\" \").map &:to_i\ngcab = a.gcd(b)\nnok = a * b / gcab\nnoks = t / nok\ntmk = t - nok * noks\nminab = [a,b].min\nans = (noks+1) * minab - 1 - [0, minab - 1 - tmk].max\ngc = ans.gcd(t)\nputs \"#{ans/gc}/#{t/gc}\"", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "f04ed6f9671ef2c5e1dd135996f3f30a", "src_uid": "7a1d8ca25bce0073c4eb5297b94501b5", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#! /usr/bin/env ruby\n\nt,w,b = $stdin.gets.split.map {|v| v.to_i}\n\nlcm = w.lcm(b)\ncnt = (t / lcm) * [w,b].min\ncnt += [w, b, t % lcm + 1].min\ncnt -= 1 # L = 0 doesn't count\n\ntmp = t.gcd(cnt)\nputs \"#{cnt/tmp}/#{t/tmp}\"\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "4cb3b24def54d44da14c464aeb2fea85", "src_uid": "7a1d8ca25bce0073c4eb5297b94501b5", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "t, w, b = gets.split(\" \").map &:to_i\nx = [w, b].min * (t / w.lcm(b)) + ([w, b, 1 + t - t / w.lcm(b) * w.lcm(b)].min - 1)\ny = t\nputs Rational(x, y)\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "4841d7be29ced650f569fd65a4d34c4d", "src_uid": "7a1d8ca25bce0073c4eb5297b94501b5", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = gets.strip\n\nupc = s.scan(/[A-Z]/).size\ndownc = s.scan(/[a-z]/).size\n\nputs s.upcase if upc > downc\nputs s.downcase if upc <= downc", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "6b853e72b744a06b506875738a32879b", "src_uid": "b432dfa66bae2b542342f0b42c0a2598", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = gets\nif s.scan(/[a-z]/).size >= s.scan(/[A-Z]/).size\n\tputs s.downcase\nelse\n\tputs s.upcase\nend", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "84bb4a45d6c07cc76435cef7e45bae16", "src_uid": "b432dfa66bae2b542342f0b42c0a2598", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "puts (gets.scan(/[A-Z]/).size>$_.scan(/[a-z]/).size)?$_.upcase : $_.downcase\n", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "3697f9bd6d49fb692e3952c6e9ceda4b", "src_uid": "b432dfa66bae2b542342f0b42c0a2598", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/ruby\n\nx, y, z = STDIN.readline.split.collect {|s| s.to_i }\na = (x*z/y)**0.5\nb = x/a\nc = z/a\nputs 4*(a + b + c).to_i\n\n", "lang_cluster": "Ruby", "tags": ["brute force", "math", "geometry"], "code_uid": "12b34a56cf5b2a1852c8648ae80edad9", "src_uid": "c0a3290be3b87f3a232ec19d4639fefc", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s1, s2, s3 = gets.chomp.split.map { |x| x.to_i }\nputs 4*(Math.sqrt(s1*s2/s3) + Math.sqrt(s1*s3/s2) + Math.sqrt(s2*s3/s1)).to_i", "lang_cluster": "Ruby", "tags": ["brute force", "math", "geometry"], "code_uid": "d61c37cd0d9d9ddb68b31d4357e5cce9", "src_uid": "c0a3290be3b87f3a232ec19d4639fefc", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "include Math\n\ndef calculate(s1, s2, s3)\n a = sqrt(s1*s3/s2).round\n b = sqrt(s1*s2/s3).round\n c = sqrt(s2*s3/s1).round\n\n puts 4*(a+b+c)\nend\n\nn,m,p = gets.chomp.split(/\\s/).map(&:to_i)\ncalculate(n,m,p)", "lang_cluster": "Ruby", "tags": ["brute force", "math", "geometry"], "code_uid": "9ae16b9c886753a3c3910501b701515b", "src_uid": "c0a3290be3b87f3a232ec19d4639fefc", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,m=gets.split.map(&:to_i)\na=gets.split.map(&:to_i).reverse\no=0\nwhile !a.empty?\n\td=m\n\twhile !a.empty?&&d>=a[-1]\n\t\td-=a.pop\n\tend\n\to+=1\nend\np o", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "fb1b18805241aac3dc5a93f3beb1552c", "src_uid": "5c73d6e3770dff034d210cdd572ccf0f", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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 m\n bus = x\n count += 1\n end\n}\nputs count", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "257811af2f450d005a4cb10a87583f09", "src_uid": "5c73d6e3770dff034d210cdd572ccf0f", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,k=gets.strip.split.map(&:to_i)\n\nif k<=n\n ans = k/2\n ans -= 1 if k%2==0\n puts ans\nelse\n mp = k/2\n ans = n-mp\n # ans -= 1 if k%2==0\n puts [0,ans].max\nend", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "5417eec31d3a96bd57278abed8f038ce", "src_uid": "98624ab2fcd2a50a75788a29e04999ad", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, k=gets.split.map &:to_i\nif n+n-1 0 and s[j-1] == 'B' and s[j] == 'G'\n\t\t\tt[j-1], t[j] = 'G', 'B'\t\t\n\t\tend\n\tend\n\ts = Array.new t\nend\n\nputs s.join\n", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation", "shortest paths", "graph matchings"], "code_uid": "aaf7e2fa3bef3fbec7e1330bff671b9d", "src_uid": "964ed316c6e6715120039b0219cc653a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, t = gets.chomp.split(' ').map {|x| x.to_i}\ns = gets.chomp\nt.times do\n i = 0\n while i < n\n if s[i] == 'B' && s[i+1] == 'G'\n s[i], s[i+1] = s[i+1], s[i]\n i += 1\n end\n i += 1\n end\nend\nputs s", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation", "shortest paths", "graph matchings"], "code_uid": "f86dff7488eb512d3eb2f64e00b606df", "src_uid": "964ed316c6e6715120039b0219cc653a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a=gets.split[1].to_i;b=gets;a.times{b.gsub!(\"BG\",\"GB\")};puts b\n", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation", "shortest paths", "graph matchings"], "code_uid": "3db28fa4d6ea7fa45d65c4fef616a70a", "src_uid": "964ed316c6e6715120039b0219cc653a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "\nn,t = gets.split.map(&:to_i)\nco = gets.chomp.split(//)\n\ncounter = 0\nfor j in 0..n-1\n i = 0\n while i < n\n if co[i+1]==\"G\" && co[i]==\"B\"\n co[i],co[i+1] = co[i+1],co[i]\n i+=1\n end\n i+=1\n end\n counter+=1\n break if counter == t\nend \n\nputs co.join('')", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation", "shortest paths", "graph matchings"], "code_uid": "a760f41774a67232c7290da0ac188e5f", "src_uid": "964ed316c6e6715120039b0219cc653a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "BEGIN{\n\tdef gint()\n\t\treturn gets.split.map(&:to_i)\n\tend\n\tdef main()\n\t\tn, t = gint\n\t\ts = gets.to_s\n\t\tt.times do |item|\n\t\t\ti = 0\n\t\t\twhile i <= s.length - 2 do\n\t\t\t\tc = s[i]\n\t\t\t\tif c == 'B' && s[i + 1] == 'G' then\n\t\t\t\t\ts[i] = \"G\"\n\t\t\t\t\ts[i + 1] = \"B\"\n\t\t\t\t\ti += 1\n\t\t\t\tend\n\t\t\t\ti += 1\n\t\t\tend\n\t\tend\n\t\tputs s\n\tend\n\tTest_case = 1\n\tTest_case.times do\n\t\tmain()\n\tend\n}\n", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation", "shortest paths", "graph matchings"], "code_uid": "f720add2e3660697ee4bfc3cf38dd59c", "src_uid": "964ed316c6e6715120039b0219cc653a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b=gets.split.map{|e| e.to_i}\nc=gets.chomp\n\nb.times{\n\tp=0\n\twhile p 0\n if line[runner] == 'G' && line[runner-1] == 'B'\n line[runner], line[runner-1] = line[runner-1], line[runner]\n runner -= 1\n end\n runner -= 1\n end\nend\n\nputs line.join\n", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation", "shortest paths", "graph matchings"], "code_uid": "7e5785c417a9194147cbbdf01b2ce592", "src_uid": "964ed316c6e6715120039b0219cc653a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a=gets.split[1].to_i;b=gets;a.times{b.gsub!(\"BG\",\"GB\")};puts b\n", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation", "shortest paths", "graph matchings"], "code_uid": "6ee250691d406babd8d47899dc21fb2a", "src_uid": "964ed316c6e6715120039b0219cc653a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a=gets.split[1].to_i;b=gets;a.times{b.gsub!(\"BG\",\"GB\")};puts b", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation", "shortest paths", "graph matchings"], "code_uid": "036d682e6cc139b3d00d69e7120addef", "src_uid": "964ed316c6e6715120039b0219cc653a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, t = gets.split.map(&:to_i)\ns = gets.strip\nt.times do\n\ts.gsub!(\"BG\",\"GB\")\nend\nputs s", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation", "shortest paths", "graph matchings"], "code_uid": "2d1db26ad38fe7e337c43cd1755a8851", "src_uid": "964ed316c6e6715120039b0219cc653a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "input = gets.chomp\nnums = input.split\nn = Integer(nums[0])\nt = Integer(nums[1])\ns = Array.new\ns = gets.chomp\n\nj = 0\nfor j in 0...t\n if j < t\n a = Array.new\n for i in 0...n\n if s[i] == \"B\" && s[i + 1] == \"G\"\n a.push(i)\n end\n end\n for i in 0...a.length\n s[a[i]] = \"G\"\n s[a[i] + 1] = \"B\"\n end\n j += 1\n end\n \n\nend\n\nprint s\n", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation", "shortest paths", "graph matchings"], "code_uid": "8baf0b6e7dbefa1916205206ac4eccb0", "src_uid": "964ed316c6e6715120039b0219cc653a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a=gets.split[1].to_i;b=gets;a.times{b.gsub!(\"BG\",\"GB\")};puts b", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation", "shortest paths", "graph matchings"], "code_uid": "948dc286ec22c9b59c0aa2cff653362c", "src_uid": "964ed316c6e6715120039b0219cc653a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, t = gets.strip.split.map(&:to_i)\ns = gets.strip\nt.times do |j|\n s2 = s.clone\n s.length.times do |i|\n if i < s.length - 1 && s[i] == \"B\" && s[i + 1] == \"G\"\n s2[i] = \"G\"\n s2[i + 1] = \"B\"\n end\n end\n s = s2.clone\nend\nputs s\n", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation", "shortest paths", "graph matchings"], "code_uid": "472a69da29f33945009071892cacfa4e", "src_uid": "964ed316c6e6715120039b0219cc653a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, t = gets.split(' ').map(&:to_i)\nar = gets\nt.times do\n ar = ar.split(/(?=BG)/).map{|x| x.sub(/BG/,\"GB\")}.join\nend\nputs ar", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation", "shortest paths", "graph matchings"], "code_uid": "268b19ef035a99f34e9326180108cb4c", "src_uid": "964ed316c6e6715120039b0219cc653a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,t = gets.split(\" \").map(&:to_i)\nq = gets\nt.times{\n\ti=0\n\twhile i= 0 do\n\t\tif chars[i] == 'G' and i-1 >= 0 and chars[i-1] == 'B'\n\t\t\tnew_chars.insert(0, 'B')\n\t\t\tnew_chars.insert(0, 'G')\n\t\t\ti -= 2\n\t\telse\n\t\t\tnew_chars.insert(0, chars[i])\n\t\t\ti -= 1\n\t\tend\n\tend\n\tchars = new_chars\nend\nputs chars.join('')\n\n", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation", "shortest paths", "graph matchings"], "code_uid": "5b1debd94d5c5b53d2a4172e551d7d8a", "src_uid": "964ed316c6e6715120039b0219cc653a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, t = gets.split.map(&:to_i)\ns = gets.to_s.chomp\nfor i in 1..t do\n i = 0\n\twhile i < n-1 do\n\t\tif s[i] == 'B' and s[i+1] == 'G' then\n\t\t\ts[i], s[i+1] = s[i+1], s[i]\n\t\t\ti += 2\n\t\telse\n\t\t\ti += 1\n\t\tend \n\tend\nend\nputs s\n", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation", "shortest paths", "graph matchings"], "code_uid": "9d1603b093c4539fa30ef5d3a8eac036", "src_uid": "964ed316c6e6715120039b0219cc653a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, t = gets.chomp.split\npresent_queue = gets.chomp\n\ng_indexs = []\n\nt.to_i.times do\n (0...(n.to_i)).each do |i|\n if i != 0\n if present_queue[i] == 'G' && present_queue[i - 1] == 'B'\n g_indexs << i\n end\n end\n end\n \n g_indexs.each do |i| \n present_queue[i], present_queue[i - 1] = present_queue[i - 1], present_queue[i]\n end\n \n g_indexs = []\nend\n\nputs \"#{present_queue}\"", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation", "shortest paths", "graph matchings"], "code_uid": "5d3f3d9440a31d83854a0ad6b7b61e1e", "src_uid": "964ed316c6e6715120039b0219cc653a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, t = gets.split.map{ |e| e.to_i}\nq = gets.chomp\n\nfor i in 1..t\n q += ' '\n s = q.split('BG')\n q = s[0]\n for i in 1..s.size-1\n q += 'GB' + s[i]\n end\nend\n\nputs q\n", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation", "shortest paths", "graph matchings"], "code_uid": "bf7da16c9ad2c8be7c11fb60330d083a", "src_uid": "964ed316c6e6715120039b0219cc653a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a=gets.split[1].to_i;b=gets;a.times{b.gsub!(\"BG\",\"GB\")};puts b\n", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation", "shortest paths", "graph matchings"], "code_uid": "888150a71944c65fc7b83be6163aded1", "src_uid": "964ed316c6e6715120039b0219cc653a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "childrens, time = gets.split(' ').map(&:to_i)\nqueue = gets.chomp\n\ntime.times do\n i = 0\n while i < (queue.length - 1) do\n if queue[i] == 'B' && queue[i + 1] == 'G'\n queue[i], queue[i + 1] = queue[i + 1], queue[i]\n i = i + 1\n end\n i = i + 1\n end\nend\n\nputs queue\n", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation", "shortest paths", "graph matchings"], "code_uid": "463663c3b6bd17e3e8f0541c110d1563", "src_uid": "964ed316c6e6715120039b0219cc653a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a=gets.split[1].to_i;b=gets;a.times{b.gsub!(\"BG\",\"GB\")};puts b\n", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation", "shortest paths", "graph matchings"], "code_uid": "8c5b5e21b7bf972df8304cb396902880", "src_uid": "964ed316c6e6715120039b0219cc653a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, t = gets.split.map(&:to_i)\ns = gets.chomp\n\nt.times do\n i = 0\n while i < s.size-1 do\n if s[i] + s[i+1] == \"BG\"\n s[i] = \"G\"\n s[i+1] = \"B\"\n i += 1\n end\n i += 1\n end\nend\n\nputs s", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation", "shortest paths", "graph matchings"], "code_uid": "3cacefbf39177378bc68eca0ce1151b0", "src_uid": "964ed316c6e6715120039b0219cc653a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, t = gets.split(\" \").map(&:to_i)\narr = gets.split(\"\")\nlength = arr.length\n(1..t).each do |i_t|\n index = 0\n while index < (length-1) do\n if arr[index] == 'B' && arr[index +1] == 'G'\n arr[index + 1] = 'B'\n arr[index] = 'G'\n index += 1\n end\n index += 1\n end\nend\nputs arr.join(\"\")", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation", "shortest paths", "graph matchings"], "code_uid": "a01d9edddf34512cf58335f9d52e0bc6", "src_uid": "964ed316c6e6715120039b0219cc653a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a=gets.split[1].to_i;b=gets;a.times{b.gsub!(\"BG\",\"GB\")};puts b", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation", "shortest paths", "graph matchings"], "code_uid": "652c311d3c907f4b308fe592a7941857", "src_uid": "964ed316c6e6715120039b0219cc653a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "BEGIN{\n\tdef gint()\n\t\treturn gets.split.map(&:to_i)\n\tend\n\tdef main()\n\t\tn, t = gint\n\t\ts = gets.to_s\n\t\tl = s.length - 1\n\t\tt.times do |item|\n\t\t\tflag = false\n\t\t\t(0..l).each do |i|\n\t\t\t\tif flag then\n\t\t\t\t\tflag = false\n\t\t\t\t\tnext\n\t\t\t\tend\n\t\t\t\tif s[i] == 'B' and s[i + 1] == 'G' then\n\t\t\t\t\ts[i], s[i + 1] = s[i + 1], s[i]\n\t\t\t\t\tflag = true\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\t\tputs s\n\tend\n\tTest_case = 1\n\tTest_case.times do\n\t\tmain()\n\tend\n}\n", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation", "shortest paths", "graph matchings"], "code_uid": "8f12d67f99c94f9887d8539d700d6e63", "src_uid": "964ed316c6e6715120039b0219cc653a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a=gets.split[1].to_i;b=gets;a.times{b.gsub!(\"BG\",\"GB\")};puts b\n", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation", "shortest paths", "graph matchings"], "code_uid": "18ba936fd97112ae37d30f043f8c7d55", "src_uid": "964ed316c6e6715120039b0219cc653a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, s = gets.split.map &:to_i\nq = gets\ns.times { q.gsub!(\"BG\", \"GB\") }\nputs q\n", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation", "shortest paths", "graph matchings"], "code_uid": "1281dd8b155edf814759574ab5bdc0db", "src_uid": "964ed316c6e6715120039b0219cc653a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "# cook your code here\n\nn,t = gets.chomp.split \nn = n.to_i \nt = t.to_i \n\nq = gets \n\nfor j in 0...t\n i=0\n while i < n-1\n if(q[i]=='B' and q[i+1]=='G') \n q[i],q[i+1]=q[i+1],q[i] \n #puts q + i.to_s \n i+=1\n end \n i+=1\n end \nend \n\nputs q \n ", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation", "shortest paths", "graph matchings"], "code_uid": "0b84c773d01a6d1581e06eea1485a9d5", "src_uid": "964ed316c6e6715120039b0219cc653a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation", "shortest paths", "graph matchings"], "code_uid": "140202d22b905b7ba85334d85ebcc552", "src_uid": "964ed316c6e6715120039b0219cc653a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a=gets.split[1].to_i;b=gets;a.times{b.gsub!(\"BG\",\"GB\")};puts b", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation", "shortest paths", "graph matchings"], "code_uid": "709f959779bf62a8f4434d49c47626d5", "src_uid": "964ed316c6e6715120039b0219cc653a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def switch(a, n)\n b = Array.new(n)\n n.times do |i|\n if a[i] == \"B\" && a[i + 1] == \"G\"\n b[i] = \"G\"\n b[i + 1] = \"B\"\n elsif b[i] == nil\n b[i] = a[i]\n end\n end\n b\nend\nn, t = gets.split.map(&:to_i)\na = gets.chomp.chars\nt.times do\n a = switch(a, n)\nend\nputs a.join(\"\")\n", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation", "shortest paths", "graph matchings"], "code_uid": "c860322ed966769f5158def6f76fbe8a", "src_uid": "964ed316c6e6715120039b0219cc653a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, t = gets.chomp.split.map &:to_i\nf = gets.chomp\nt.times do |i|\n f.gsub!(/BG/) { |x| 'GB' }\nend\nputs f", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation", "shortest paths", "graph matchings"], "code_uid": "602ca091c52b3a04f122867d8f55de1d", "src_uid": "964ed316c6e6715120039b0219cc653a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a = gets.split(' ')[1].to_i\ns = gets\n\na.times do\n s.gsub!(/BG/, 'GB')\nend\nputs s", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation", "shortest paths", "graph matchings"], "code_uid": "68d7c4695ee5895fd096c052d06edf4b", "src_uid": "964ed316c6e6715120039b0219cc653a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a=gets.split[1].to_i;b=gets;a.times{b.gsub!(\"BG\",\"GB\")};puts b\n", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation", "shortest paths", "graph matchings"], "code_uid": "723e5bd52a734d751f62c7fb9037970e", "src_uid": "964ed316c6e6715120039b0219cc653a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, t = gets.split(' ').map &:to_i\ns = gets.chomp\n\nt.times do\n s.gsub!(/BG/, 'GB')\nend\n\nputs s", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation", "shortest paths", "graph matchings"], "code_uid": "9e9daf8fceef4b5a3d41c5633e3bfdf5", "src_uid": "964ed316c6e6715120039b0219cc653a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a=gets.split[1].to_i;b=gets;a.times{b.gsub!(\"BG\",\"GB\")};puts b\n", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation", "shortest paths", "graph matchings"], "code_uid": "c432ee402f0e889f7ef03652ee10de6a", "src_uid": "964ed316c6e6715120039b0219cc653a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "childrens, time = gets.split(' ').map(&:to_i)\nqueue = gets.chomp\n\ntime.times do\n queue.gsub!(/BG/, 'GB')\nend\n\nputs queue\n", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation", "shortest paths", "graph matchings"], "code_uid": "dd2e41624ed55c61cebbeb06cdd2b4b7", "src_uid": "964ed316c6e6715120039b0219cc653a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "nt=gets.split(' ')\ns=gets.split('')\n\n@n = nt[0].to_i\nt = nt[1].to_i\n\ndef menyaem(str)\n\tj = 0\n\t@n.times do\n\t\tbreak if j >= @n\n\t\tif str[j] == 'B' && str[j+1] == 'G'\n\t\t\tstr[j] = 'G'\n\t\t\tstr[j+1] = 'B'\n\t\t\tj += 2\n\t\telse\n\t\t\tj += 1\n\t\tend\n\tend\n\treturn str\nend\n\nt.times do |i|\n\ts = menyaem(s)\nend\n\nputs s.join('')", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation", "shortest paths", "graph matchings"], "code_uid": "6063ef0b67938ef87b999a27d8622313", "src_uid": "964ed316c6e6715120039b0219cc653a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, t = $stdin.readline.split.map(&:to_i)\nq = $stdin.readline.scan(/./)\n\nk = 0\nwhile k=len\nend\nend\nputs \"#{b.join}\"", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation", "shortest paths", "graph matchings"], "code_uid": "39cdbc50b8e76606f8f5fb69bf84ccc3", "src_uid": "964ed316c6e6715120039b0219cc653a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def run\n n, t = ARGF.readline.chomp.split.map(&:to_i)\n s = ARGF.readline.chomp\n l = s.length\n\n t.times do\n ns = []\n i = 0\n while i < l\n if i < l - 1 and s[i] == 'B' and s[i + 1] == 'G'\n ns[i] = 'G'\n ns[i + 1] = 'B'\n i += 1\n else\n ns[i] = s[i]\n end\n\n i += 1\n end\n s = ns.join(\"\")\n end\n\n puts s\nend\n\nrun if $0 == __FILE__\n", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation", "shortest paths", "graph matchings"], "code_uid": "08864872f010395e4764df9ec08db98d", "src_uid": "964ed316c6e6715120039b0219cc653a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a=gets.chomp.split(\" \")\nlen=a[0].to_i\ntime=a[1].to_i\nb=gets.chomp.split(\"\")\n\n\n(time).times do\ni=0\nc=b.join \nloop do\n\tp=0\n if (b[i]==\"B\" && b[i+1]==\"G\")\n b[i]=\"G\" \n b[i+1]=\"B\"\n\t\tp=1\n end\n\tif p==1\n i+=2\n\telse \n\ti+=1\n\tend\n\t\n break if i>=len\nend\nend\nputs \"#{b.join}\"", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation", "shortest paths", "graph matchings"], "code_uid": "4f0942b97fe72df3fe2ff35a1c767242", "src_uid": "964ed316c6e6715120039b0219cc653a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, t = gets.chomp.split(/ /).map(&:to_i)\nline = gets.chomp\n(1..t).each do |time|\n student = 0\n while student <= n\n first = line[student]\n nxt = line[student + 1]\n if nxt == 'G' && first == 'B'\n line[student + 1] = 'B'\n line[student] = 'G'\n student += 2\n next\n end\n student += 1\n end\nend\nputs line\n", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation", "shortest paths", "graph matchings"], "code_uid": "6fb723da7155e680011f5d4c238be8ef", "src_uid": "964ed316c6e6715120039b0219cc653a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "nums = gets.chomp.split\nn = Integer(nums[0])\nt = Integer(nums[1])\ninitial = []\ninitial = gets.chomp\n\nwhile t > 0 do\n i = 0\n while i < n-1 do\n if initial[i] == \"B\" && initial[i+1] == \"G\"\n initial[i] = \"G\"\n initial[i+1] = \"B\"\n i += 2\n else\n i += 1\n end\n end\n t -= 1\nend\nprint initial", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation", "shortest paths", "graph matchings"], "code_uid": "b282dc1819fe6188ca1c4669a379f896", "src_uid": "964ed316c6e6715120039b0219cc653a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,t=gets.chomp.split.map(&:to_i)\ns=gets.chomp\nt.times do\n\ti=n-1\n\twhile i>0\n\t\tif s[i]=='G' && s[i-1]=='B'\n\t\t\ts[i]='B'\n\t\t\ts[i-1]='G'\n\t\t\ti-=1\n\t\tend\n\t\ti-=1\n\tend\nend\nputs s", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation", "shortest paths", "graph matchings"], "code_uid": "fd2b4d92a83163ac554ead3fbe358838", "src_uid": "964ed316c6e6715120039b0219cc653a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, k = readline.split(' ').collect(&:to_i)\nputs (n * 2 - 3).step(1, -4).to_a[0..([k - 1, (n / 2) - 1].min)].inject(0, :+)\n", "lang_cluster": "Ruby", "tags": ["math", "greedy"], "code_uid": "cd0846a020e95e85d1da8c0164af8200", "src_uid": "ea36ca0a3c336424d5b7e1b4c56947b0", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["math", "greedy"], "code_uid": "90708b619c99331308981c5ffffc3bc9", "src_uid": "ea36ca0a3c336424d5b7e1b4c56947b0", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets\nn.chomp!\nmemo=[]\nn.length.times do |i|\n memo << n[i].to_i\nend\nmemo.sort!\nif memo[0] == 0\n j=0\n while memo[j]==0\n j+=1\n end\n if j!=memo.length\n memo[0],memo[j]=memo[j],memo[0]\n end\nend\nt=gets\nt.chomp!\nmemo2=[]\nt.length.times do |i|\n memo2 << t[i].to_i\nend\nif memo2 == memo\n puts \"OK\"\nelse\n puts \"WRONG_ANSWER\"\nend\n", "lang_cluster": "Ruby", "tags": ["sortings", "implementation"], "code_uid": "3be877e01f15527bc0f6b94ab45e74fb", "src_uid": "d1e381b72a6c09a0723cfe72c0917372", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "count=0;str=''\na = gets().chomp().split(\"\").each {|x| (x=='0') ? count+=1 : x.to_i }\na.sort!{|x,y| x<=>y}\nif (count!=0); str=\"\"+a[count].to_s;a.delete(a[count]) end\na.each {|x| str+=x.to_s}\nb=gets().chomp()\nif(str==b)\n print 'OK'\nelse print 'WRONG_ANSWER'\nend", "lang_cluster": "Ruby", "tags": ["sortings", "implementation"], "code_uid": "29d2d247e18b25ae4c21eb2fe7345860", "src_uid": "d1e381b72a6c09a0723cfe72c0917372", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.chomp.to_s\nm = gets.chomp.to_s\nindex = 0\nif m.length != n.length\n puts \"WRONG_ANSWER\"\nelse\n n = n.chars.sort.join\n if n[0] == \"0\"\n for i in 0...n.length\n if n[i] > \"0\"\n inicio = n.index(n[i])\n fin = n.rindex(n[i])\n alta = n[inicio+1..n.length]\n baja = n[0..inicio-1]\n n = n[inicio..fin] + baja + alta\n break\n end\n end\n end\n if m == n\n puts \"OK\"\n else\n puts \"WRONG_ANSWER\"\n end\nend\n", "lang_cluster": "Ruby", "tags": ["sortings", "implementation"], "code_uid": "6036780221adf2d03531224929df75a8", "src_uid": "d1e381b72a6c09a0723cfe72c0917372", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = gets.chomp.split('')\nx = 'a'\nc = 0\ns.each do |y|\n v = (y.ord - x.ord).abs\n v = 26 - v if v > 13\n c += v\n x = y\nend\nputs c\n", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "b289d4e4857f0d59031df70a033daa55", "src_uid": "ecc890b3bdb9456441a2a265c60722dd", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = gets.strip\ncount = 0\ncurrent = 'a'\n(0...s.length).each do |i|\n clockwise = current.ord - s[i].ord\n counterclock = s[i].ord - current.ord\n clockwise = 26 + clockwise if clockwise < 0\n counterclock = 26 + counterclock if counterclock < 0\n min_count = [clockwise, counterclock].min\n count += min_count\n current = s[i]\nend\nputs count\n", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "e369f5f90492b5ccfdaa04d0b1bc71d6", "src_uid": "ecc890b3bdb9456441a2a265c60722dd", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = gets.strip\n\nmp = {}\n(0..25).each do |i|\n mp[('a'.ord + i).chr] = i\nend\n\ncnt = 0\ncurr = 'a'\ns.split('').each do |l|\n i = mp[curr]\n j = mp[curr]\n while(1)\n if i == mp[l] || j == mp[l]\n break\n end\n i -= 1\n j += 1\n j = 0 if j >= 26\n i = 25 if i < 0\n end\n if (mp[curr] - i).abs < (mp[curr] - j).abs\n cnt += (mp[curr] - i).abs \n else\n cnt += (mp[curr] - j).abs\n end\n\n curr = l\n\nend\n\nprintf(\"%d\\n\", cnt)\n", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "bd7108cc2ef6b28e33b6b5bfc4d48e77", "src_uid": "ecc890b3bdb9456441a2a265c60722dd", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "x,y,a,b=gets.split.map(&:to_i)\nq=x.lcm y\np b/q-(a-1)/q\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "b2de5d3358fe7c5fe9b0d120c0e47d9d", "src_uid": "c7aa8a95d5f8832015853cffa1374c48", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "x,y,a,b=gets.split.map(&:to_i)\nq=x.lcm y\np b/q-(a-1)/q\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "b83026322dbaf57a75943cd94960e9fa", "src_uid": "c7aa8a95d5f8832015853cffa1374c48", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "input = gets.split(\" \").map {|e| e.to_i}\nx = input[0]\ny = input[1]\na = input[2]\nb = input[3]\n\ndiv = x.lcm(y)\nputs (b / (div) - (a.to_f / (div).to_f).ceil + 1)\n\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "4ef02af47fd54bcd5eb9025c446ef322", "src_uid": "c7aa8a95d5f8832015853cffa1374c48", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,k=gets.split.map(&:to_i)\nt=(n+1)/2\np k>t ? 2*(k-t) : 2*k-1\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "59fa9ddba748ab1888f4221a4d62fb70", "src_uid": "1f8056884db00ad8294a7cc0be75fe97", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,k=gets.split.map(&:to_i)\nt=(n+1)/2\np k>t ? 2*(k-t) : 2*k-1", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "94b98f43b6f16e2957bf7db98f749462", "src_uid": "1f8056884db00ad8294a7cc0be75fe97", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, k = $stdin.readline.split.map(&:to_i)\n\nif n%2==0\n if k <= n/2\n puts 2*(k-1)+1\n else\n k -= n/2\n puts 2*(k)\n end\nelse\n if k <= n/2+1\n puts 2*(k-1)+1\n else\n k -= n/2+1\n puts 2*(k)\n end\nend", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "f627908fbe6dc7adf6c289924cef0787", "src_uid": "1f8056884db00ad8294a7cc0be75fe97", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "require \"date\"\n\nm = Date.new(*gets.split(\":\").map(&:to_i))\nn = Date.new(*gets.split(\":\").map(&:to_i))\n\np (n - m).to_i.abs", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "13fcb81beca22ab500cc11e7943cbc0c", "src_uid": "bdf99d78dc291758fa09ec133fff1e9c", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "require 'date'\nputs (Date.parse(gets.gsub(\":\",\"-\"))-Date.parse(gets.gsub(\":\",\"-\"))).to_i.abs", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "1020eb0153b2ae6684bc102bc621030d", "src_uid": "bdf99d78dc291758fa09ec133fff1e9c", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/env ruby\n\nrequire 'date'\nputs (Date.parse(gets.gsub(':','-')).ld - Date.parse(gets.gsub(':','-')).ld).abs\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "88d6fbaf88ff1c7a4a1ff1bc29c0e08e", "src_uid": "bdf99d78dc291758fa09ec133fff1e9c", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["binary search", "number theory"], "code_uid": "187e834248a6f4a7a1913f024f702a7b", "src_uid": "97999cd7c6de79a4e39f56a41ff59e7a", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "\na,b,x,y=gets.split.map(&:to_i)\nx,y=x/x.gcd(y),y/x.gcd(y)\nsc=(1..2*10**9).bsearch{|i| i*x > a || i*y > b}-1\nprint(x*sc, \" \", y*sc, \"\\n\")\n\n\n\n", "lang_cluster": "Ruby", "tags": ["binary search", "number theory"], "code_uid": "83d3b3d887bfa2de5542ec09e327d375", "src_uid": "97999cd7c6de79a4e39f56a41ff59e7a", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,m=gets.split.map(&:to_i)\nputs m==[*n+1..m].find{|_|2**_%_==2}?\"YES\":\"NO\"\n", "lang_cluster": "Ruby", "tags": ["brute force"], "code_uid": "d2b70b0464e477e49bfa8ad4d0eed546", "src_uid": "9d52ff51d747bb59aa463b6358258865", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/ruby\n\nprimes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]\n\nn, m = gets.split.map { |e| e.to_i }\n\nputs primes.include?( m ) && primes.index(m) == primes.index(n)+1 ? \"YES\" : \"NO\"\n\n", "lang_cluster": "Ruby", "tags": ["brute force"], "code_uid": "dfb9cf5447047336229ac8a490ea37f4", "src_uid": "9d52ff51d747bb59aa463b6358258865", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,m=gets.split.map(&:to_i)\nputs m==(n+1..m).find{|i|2**i%i==2}?\"YES\":\"NO\"\n", "lang_cluster": "Ruby", "tags": ["brute force"], "code_uid": "83bdab7164ad97a915b5da25240ae8ab", "src_uid": "9d52ff51d747bb59aa463b6358258865", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "gets\np gets.split.uniq.delete_if{|x| x == \"0\"}.size", "lang_cluster": "Ruby", "tags": ["sortings", "implementation"], "code_uid": "f8964f918bd229c0b5a80c6773d93d41", "src_uid": "3b520c15ea9a11b16129da30dcfb5161", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "gets;p (gets.split.uniq-['0']).size", "lang_cluster": "Ruby", "tags": ["sortings", "implementation"], "code_uid": "7df50c25f1b01482874ab9a97002beab", "src_uid": "3b520c15ea9a11b16129da30dcfb5161", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\na = gets.split.map &:to_i\nputs a.uniq.size - (a.any? { |x| x == 0 } ? 1 : 0)\n", "lang_cluster": "Ruby", "tags": ["sortings", "implementation"], "code_uid": "05c939832329c3afb1fa441fc087c858", "src_uid": "3b520c15ea9a11b16129da30dcfb5161", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "gets\na = gets.split(' ').map! {|x| x.to_i} << 0\na.unshift(0)\nans = 0\n\na.size.times do |i|\n ans += 1 if (a[i] == 1.to_i) || ((a[i - 1] == 1) && (a[i + 1] == 1))\nend\n\np ans\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "f692a2ecefa34b6f4d4e1f9d71f72d9d", "src_uid": "2896aadda9e7a317d33315f91d1ca64d", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "\nn = gets.to_i\nv = gets.split.map(&:to_i)\ncont = 0\nsw = 0\nc = 0\nfor i in(0..(n-1))\n if v[i] == 1\n sw = 1\n end\n if sw == 1\n if(v[i]==0)\n c+=1\n elsif c < 2 \n cont=cont+1+c\n c=0\n else\n cont+=1\n c=0\n end\n end\nend\np cont", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "ab9a6ad2771ed21a69d27e3a5ed715ea", "src_uid": "2896aadda9e7a317d33315f91d1ca64d", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, pairs = gets.chomp.to_i, gets.chomp.split(\" \").join(\"\")\npairs.gsub! /(^0+|00+|0+$)/, \"\"\nputs pairs.length ", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "10cea8d3ce685a68920b9d10c8797db7", "src_uid": "2896aadda9e7a317d33315f91d1ca64d", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "cbe076d9b7f9b4fabbf2fc9fab56bdd3", "src_uid": "5418c98fe362909f7b28f95225837d33", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "59ec41c2ee5de285d2f99ec8ebcc6564", "src_uid": "5418c98fe362909f7b28f95225837d33", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "require 'date'\na, b = 2.times.map{gets.split('.').map(&:to_i).reverse}\na[0] += 2000\nputs b.permutation.map{|c|\n c[0] += 2000\n begin\n Date.new(*a) >= Date.new(*c).next_year(18)\n rescue ArgumentError\n nil\n end\n}.any? ? :YES : :NO", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "278e6a03d75b2e2abad9826b6d0938b5", "src_uid": "5418c98fe362909f7b28f95225837d33", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a=gets.chomp.to_i\nb=gets.chomp.to_i\nc=gets.chomp.to_i\nd=gets.chomp.to_i\ne=gets.chomp.to_i\nk=a.lcm(b)\nl=a.lcm(c)\nm=a.lcm(d)\ni=b.lcm(c)\nn=b.lcm(d)\nj=c.lcm(d)\ng=[a,b,c].reduce(:lcm)\nh=[a,b,d].reduce(:lcm)\no=[a,d,c].reduce(:lcm)\np=[d,b,c].reduce(:lcm)\nq=[a,b,c,d].reduce(:lcm)\n\n\nf=(e/a)+(e/b)+(e/c)+(e/d)-e/k-e/l-e/m-e/i-e/n-e/j+e/g+e/h+e/o+e/p-e/q\nputs \"#{f}\"\n", "lang_cluster": "Ruby", "tags": ["math", "constructive algorithms", "implementation"], "code_uid": "36180c693ecddf7d96cef94f4ba3fa2d", "src_uid": "46bfdec9bfc1e91bd2f5022f3d3c8ce7", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "k = gets.to_f\nl = gets.to_f\nm = gets.to_f\nn = gets.to_f\nd = gets.to_i\n\nresult = 0\nd.times do |i|\n i = i + 1\n result += 1 if i%k == 0 or i%l == 0 or i%m == 0 or i%n == 0\nend\n\nputs result", "lang_cluster": "Ruby", "tags": ["math", "constructive algorithms", "implementation"], "code_uid": "533d56da7cb16d5b44f48aa628ebd0d7", "src_uid": "46bfdec9bfc1e91bd2f5022f3d3c8ce7", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "ar = []\n4.times {ar << gets.to_i}\nn = gets.to_i\nputs (1..n).to_a.count{|i| ar.index{|x| i%x == 0}}", "lang_cluster": "Ruby", "tags": ["math", "constructive algorithms", "implementation"], "code_uid": "a63337a2e6fccda70e82eeda95027afe", "src_uid": "46bfdec9bfc1e91bd2f5022f3d3c8ce7", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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]", "lang_cluster": "Ruby", "tags": ["greedy", "constructive algorithms", "implementation"], "code_uid": "b798d0c93be9ee04d06df06f8878519a", "src_uid": "e858e7f22d91aaadd7a48a174d7b2dc9", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "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]\n", "lang_cluster": "Ruby", "tags": ["greedy", "constructive algorithms", "implementation"], "code_uid": "25f0f03323f8a08a0638286f0b2b2f94", "src_uid": "e858e7f22d91aaadd7a48a174d7b2dc9", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "x,y=2.times.map{n,a=gets.split.map(&:to_i)\ngets.split.map(&:to_i).inject{|x, y|x*=a;x+=y}}\nputs'=><'[x<=>y]\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "98e9a62f141e5cf04160c806f28b8593", "src_uid": "d6ab5f75a7bee28f0af2bf168a0b2e67", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "x, y = 2.times.map {\n n, b = gets.split.map(&:to_i)\n gets.split.map(&:to_i).inject{|x,y| x *= b ; x+y}\n}\nputs '<' if x < y\nputs '>' if x > y\nputs '=' if x == y\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "c30ecf11e96993a2f7d2906b9b7eb403", "src_uid": "d6ab5f75a7bee28f0af2bf168a0b2e67", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "x_i=gets.chomp.split(\" \")\n0.upto(1) {|i| x_i[i]=x_i[i].to_i}\nx=gets.chomp.split(\" \")\n0.upto(x_i[0]-1) {|i| x[i]=x[i].to_i}\ny_i=gets.chomp.split(\" \")\n0.upto(1) {|i| y_i[i]=y_i[i].to_i}\ny=gets.chomp.split(\" \")\n0.upto(y_i[0]-1) {|i| y[i]=y[i].to_i}\ny.reverse!\nx.reverse!\ndef Con(a,b)\nk=0\n0.upto(a.length-1){|i| k=k+(a[i]*(b**i)) } \nreturn k\nend\nX=Con(x,x_i[1])\nY=Con(y,y_i[1])\nd=X<=>Y\nif d==0\n\tputs \"=\"\nelsif d==-1\n\tputs \"<\"\nelse\n\tputs \">\"\nend\n\t", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "649965c9285c66b0270357f421d47509", "src_uid": "d6ab5f75a7bee28f0af2bf168a0b2e67", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\n1.upto(n - 1){|i| puts 1.upto(n - 1).map{|j| (i * j).to_s(n)} * ' '}", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "38d4f6059f0c2f05a57c332964db9f71", "src_uid": "a705144ace798d6b41068aa284d99050", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\n1.upto(n - 1){|i| puts 1.upto(n - 1).map{|j| (i * j).to_s(n)} * ' '}\n\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "862540917bbe65c1dd2dc9aa941cb355", "src_uid": "a705144ace798d6b41068aa284d99050", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "1234d1a27b26d154b11898c0e3550905", "src_uid": "a705144ace798d6b41068aa284d99050", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "\ufeffdef min(n, m)\n if n >= m\n n\n else\n (m - n) + n\n end\nend\n\ndef max(n, m)\n if m > 0\n (m - 1) + n\n else\n n\n end\nend\n\nn, m = gets.chomp.split(\" \").map{|e| e.to_i}\n\nif n == 0 and m > 0\n puts \"Impossible\"\nelse\n puts \"#{min(n, m)} #{max(n,m)}\"\nend\n", "lang_cluster": "Ruby", "tags": ["math", "greedy"], "code_uid": "3f978728714351bce92ac64b25e90163", "src_uid": "1e865eda33afe09302bda9077d613763", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/ruby\ninclude Math\n\ndata = gets.split.map{ |x| x.to_i}\notona = data[0]\nkodomo = data[1]\n\nif otona == 0 \n if kodomo != 0 then puts \"Impossible\" else puts \"#{0} #{0}\"end\nelse\n m_max = otona+kodomo\n m_max -= 1 if kodomo > 0\n kodomo -= [otona,kodomo].min\n m_min = otona+kodomo\n puts \"#{m_min} #{m_max}\"\nend\n", "lang_cluster": "Ruby", "tags": ["math", "greedy"], "code_uid": "db8cc46c6861df133a652ff7b0afa8f4", "src_uid": "1e865eda33afe09302bda9077d613763", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,m=gets.split.map(&:to_i)\nif n==0 && m!=0\n puts \"Impossible\"\nelsif m==0\n puts \"#{n} #{n}\"\nelsif n \"YES\", false => \"NO\" }\nputs bool[b.count(a) > 0]", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "5686165f8ec6783410d792d14ba0a589", "src_uid": "699444eb6366ad12bc77e7ac2602d74b", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.chomp.chars\nputs [n[0...n.size - 1].join.to_i, (n[0...n.size - 2] + n[n.size - 1..n.size - 1]).join.to_i, n.join.to_i].max\n", "lang_cluster": "Ruby", "tags": ["implementation", "number theory"], "code_uid": "489ead6e063a72ce16882ace8036cfa0", "src_uid": "4b0a8798a6d53351226d4f06e3356b1e", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.chomp.to_i\nif n>=0\n puts n\nelse\n n *= -1\n dig1,dig2 = n%10, (n/10)%10\n n1= n/10\n n1*=-1\n n2 = n1-dig1+dig2\n if n1>n2\n puts n1\n else\n puts n2\n end\nend", "lang_cluster": "Ruby", "tags": ["implementation", "number theory"], "code_uid": "661c3c027d4760683db8d5ed8976e1ac", "src_uid": "4b0a8798a6d53351226d4f06e3356b1e", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\n\nif n >= 0\n puts n\n exit\nend\n\nn *= -1\n\ncandidates = []\n\ncandidates << n / 10\ncandidates << n / 100 * 10 + n % 10\n\nputs -candidates.min\n", "lang_cluster": "Ruby", "tags": ["implementation", "number theory"], "code_uid": "fcb28bbd9912c851708d71a95c6f6e21", "src_uid": "4b0a8798a6d53351226d4f06e3356b1e", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.strip.to_i\nputs(1 + n*(2*6 + 6*(n-1))/2)", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "477e705494d7a7d04b480159d3a7659d", "src_uid": "c046895a90f2e1381a7c1867020453bd", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.to_i;p 3*n*(n+1)+1", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "a0abb3a24b920481a67ea899de81c9d0", "src_uid": "c046895a90f2e1381a7c1867020453bd", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.to_i;p 6*n*(n+1)/2+1", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "e824bb8e2a012bbe512b4f99dfca9802", "src_uid": "c046895a90f2e1381a7c1867020453bd", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "all = []\n1.upto(9) do |x|\n 4.times do |i|\n all << (x.to_s * (i + 1))\n end\nend\ngets.to_i.times do\n n = gets.chomp\n puts (all.inject(0) do |acc, s|\n acc += s.length\n break acc if s == n\n acc\n end)\nend\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "b73a5b86a4f109e144d5d17ba37c7bf3", "src_uid": "289a55128be89bb86a002d218d31b57f", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "t = gets.chomp.to_i\nt.times do \n x = gets.chomp.split(\"\")\n ookisa = x.size\n count = 0\n if x[0] == \"1\"\n me = 1 + ookisa\n kazu = ookisa * me\n count += kazu / 2\n else\n mezi = (x[0].to_i - 1) * 10\n me = 1 + ookisa\n kazu = ookisa * me\n count += kazu / 2\n count += mezi\n end\n puts count\nend\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "90cbdaeee58093bda32a8559425aab90", "src_uid": "289a55128be89bb86a002d218d31b57f", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "T = gets.to_i\n\nT.times do\n x = gets.chomp\n d = x[0].to_i\n\n puts 10 * (d - 1) + (1..x.size).sum\nend\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "cff45287b9a229b672895efd4c37b8e0", "src_uid": "289a55128be89bb86a002d218d31b57f", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "PLAYERS = %w[F M S]\nRANKS = %w[rock paper scissors]\n\ndef winner?(g1, g2)\n r1 = RANKS.rindex(g1)\n r2 = RANKS.rindex(g2)\n return true if r1 == 0 and r2 == 2\n return false if r1 == 2 and r2 == 0\n return true if r1 > r2\n false\nend\n\ngestures = []\n3.times { gestures << STDIN.gets.chomp }\nwinners = []\n\ngestures.each_index do |i|\n gestures.each_index do |j|\n g1, g2 = gestures[i], gestures[j]\n next if g1 == g2\n winners << PLAYERS[i] if winner?(g1, g2)\n end\nend\n\nputs (winners.uniq.count == 1) ? winners[0] : \"?\"", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "0e5ac3922d13b88b92bcbbd9d5ecd97e", "src_uid": "072c7d29a1b338609a72ab6b73988282", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/ruby\n\ndef win?(me, him)\n return true if (me == \"rock\" && him == \"scissors\")\n return true if (me == \"paper\" && him == \"rock\")\n return true if (me == \"scissors\" && him == \"paper\")\n return false\nend\n\nf = gets.chomp\nm = gets.chomp\ns = gets.chomp\n\nif (win?(f, m) && win?(f, s))\n puts \"F\"\nelsif (win?(m, f) && win?(m, s))\n puts \"M\"\nelsif (win?(s, f) && win?(s, m))\n puts \"S\"\nelse\n puts \"?\"\nend\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "ea33426a12b4c0f55eb0eae5f8d41f71", "src_uid": "072c7d29a1b338609a72ab6b73988282", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "h = {'scissors'=>'paper','paper'=>'rock','rock'=>'scissors'}\nx = [*$<].map &:chomp\nif h[x[0]] == x[1] && h[x[0]] == x[2] ; puts 'F' else\nif h[x[1]] == x[0] && h[x[1]] == x[2] ; puts 'M' else\nif h[x[2]] == x[0] && h[x[2]] == x[1] ; puts 'S' else\nputs '?' end end end\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "60f9c02c498afe1be5e5b37429b063fa", "src_uid": "072c7d29a1b338609a72ab6b73988282", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,k,l,c,d,p,nl,np=gets.split.map{|e| e.to_i}\n\na1=(k*l)/nl\na2=c*d\na3=p/np\nputs ([a1,a2,a3].min)/n\n\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "2380b3f9c9d1012c3578651060ff340a", "src_uid": "67410b7d36b9d2e6a97ca5c7cff317c1", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "arr = gets.chomp.split.map(&:to_i)\narray = []\narray[0] = (arr[1] * arr[2])/arr[6]\narray[1] = arr[3] * arr[4]\narray[2] = arr[5] / arr[7]\n\nprint array.min / arr[0]\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "f4e3c126d6294c3b3793900640df7344", "src_uid": "67410b7d36b9d2e6a97ca5c7cff317c1", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, k, l, c, d, p, nl, np = gets.split(' ').map(&:to_i)\nx = []\nx << k * l / nl\nx << c * d\nx << p / np\np x.min / n\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "b3feb5eda37b7fbe80dff22bd888438a", "src_uid": "67410b7d36b9d2e6a97ca5c7cff317c1", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "j=gets.to_i.abs;i=0;j-=i+=1 while j>0||j&1>0;puts i\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "d1e2534df6e8d023c836f640e0c94801", "src_uid": "18644c9df41b9960594fdca27f1d2fec", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "j=gets.to_i.abs;i=0;j-=i+=1 while j>0||j&1>0;puts i", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "9f587f9b84fb6bc9a5f9fb64d90688b2", "src_uid": "18644c9df41b9960594fdca27f1d2fec", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.to_i.abs;s=i=0;s+=i+=1 while s0;p i", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "e98049de0bf258ac8a38248edb489eb8", "src_uid": "18644c9df41b9960594fdca27f1d2fec", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "puts ({\"3\" => 1, \"1\" => 2, \"2\" => 3, \"4\" => 2, \"5\" => 1})[readline.strip]\n\n", "lang_cluster": "Ruby", "tags": ["brute force"], "code_uid": "ed9ca7912f03a60f775c4cffc9334ca7", "src_uid": "c702e07fed684b7741d8337aafa005fb", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "p [0,2,3,1,2,1][gets.to_i]\n", "lang_cluster": "Ruby", "tags": ["brute force"], "code_uid": "30738a2d57a25c5526c4a6dcd6aaef70", "src_uid": "c702e07fed684b7741d8337aafa005fb", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "p [0,2,3,1,2,1][gets.to_i]\n", "lang_cluster": "Ruby", "tags": ["brute force"], "code_uid": "a511bf636bf897dee2a8e55c84bccb73", "src_uid": "c702e07fed684b7741d8337aafa005fb", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "p gets.scan(/[aeiou13579]/).size", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "ccec71187a9525e2941b5bab7a0b91e6", "src_uid": "b4af2b8a7e9844bf58ad3410c2cb5223", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = gets.chomp\n\nans = 0\nve = %w(a i u e o 1 3 5 7 9)\ns.each_char do |c|\n ans += 1 if ve.include?(c)\nend\n\nputs ans", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "2f5bc6fee160058e76b815c7e060f474", "src_uid": "b4af2b8a7e9844bf58ad3410c2cb5223", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a = \"aoeui13579\"\ns = gets.chomp\nans = 0;\nfor i in (0...s.length)\n ans += a.count(s[i])\nend\nputs ans", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "e0dd8d8a072d27e48d620a30774aa294", "src_uid": "b4af2b8a7e9844bf58ad3410c2cb5223", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.chomp.to_i\ns = gets.chomp\n\nsf = 0\nfs = 0\n(n-1).times do |i|\n\tsf += 1 if s[i] == \"S\" && s[i + 1] == \"F\" \n\tfs += 1 if s[i] == \"F\" && s[i + 1] == \"S\"\nend\nputs sf > fs ? \"YES\" : \"NO\"", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "cf009ae759acb0fcbba644dc396034d0", "src_uid": "ab8a2070ea758d118b3c09ee165d9517", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\ns = gets.chomp\nssf = 0\nsfs = 0\n(0..n-2).each do |i|\n if s[i] == 'S' && s[i+1] == 'F'\n ssf += 1\n end\n if s[i] == 'F' && s[i+1] == 'S'\n sfs += 1\n end\nend\nputs ssf > sfs ? 'YES' : 'NO'", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "3f572dc2ce2cc9aec126cae762b8a86d", "src_uid": "ab8a2070ea758d118b3c09ee165d9517", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.chomp.to_i\ns = gets.chomp\n\nif s[0] == 'S' && s[-1] == 'F' \n puts \"YES\"\nelse \n puts \"NO\"\nend", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "74e354f7f7f5dafd1448950449d52275", "src_uid": "ab8a2070ea758d118b3c09ee165d9517", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, k = gets.chomp.split().map { |x| x.to_i }\npath = gets.chomp\nposT = -1; posG = -1\nfor i in 0 ... n\n if path[i] == \"G\"\n posG = i\n elsif path[i] == \"T\"\n posT = i\n end\n if posG != -1 and posT != -1\n break\n end\nend\n\nanswer = true\nif ( posG - posT ).abs % k != 0\n answer = false\nelse\n if posG > posT\n posG, posT = posT, posG\n end\n i = posG + k\n while i < posT\n if path[i] == \"#\"\n answer = false\n break\n end\n i += k\n end\nend\n\nputs ( answer ? \"YES\": \"NO\" )\n", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "fdf2d15d702a07d8dc09d4eeafe131e9", "src_uid": "189a9b5ce669bdb04b9d371d74a5dd41", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,k=gets.split.map{|e| e.to_i}\ns=gets.chomp\np1=s.index(\"G\")\np2=s.index(\"T\")\n\nif p1>p2 then\n\tp1,p2=p2,p1\nend\n\nif (p2-p1)%k!=0 then\n\tputs \"NO\"\nelse\n\tok=\"YES\"\n\tp1.step(p2,k){|i|\n\t\tok=\"NO\" if s[i]==\"#\"\n\t}\n\tputs ok\nend\n\n", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "48546a4581b98a740b2fc491be0131c0", "src_uid": "189a9b5ce669bdb04b9d371d74a5dd41", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, k = gets.strip.split.map(&:to_i)\npath = gets.strip\nstart = path.index 'G'\ntarget = path.index 'T'\ni = start\nans = \"NO\"\nwhile i < n && ans == \"NO\"\n i += k\n break if path[i] == '#'\n ans = \"YES\" if i == target\nend\nwhile i >= 0 && ans == \"NO\"\n i -= k\n break if path[i] == '#'\n ans = \"YES\" if i == target\nend\nputs ans\n", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "79a2d842b5ec289e97a29aefc0cd0217", "src_uid": "189a9b5ce669bdb04b9d371d74a5dd41", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.chomp.to_i\nbills = [100, 20, 10, 5]\nsum = 0\nbills.each do |b|\n\twhile n >= b\n\t\tsum += n / b\n\t\tn %= b\n\t\t#puts \"#{n} #{b}\"\n\tend\nend\nputs sum + n\n\n", "lang_cluster": "Ruby", "tags": ["greedy", "dp"], "code_uid": "d0a23d9770f3bf42c9a480efba8f8617", "src_uid": "8e81ad7110552c20297f08ad3e5f8ddc", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!usr/bin/env ruby\n\n# https://codeforces.com/problemset/problem/996/A\n\namount = gets.to_i\n\nbills = [100, 20, 10, 5, 1]\n\nanswer = 0\n\nbills.each do |bill|\n current_bill_count = amount / bill\n answer += current_bill_count\n amount -= current_bill_count * bill\nend\n\nputs answer\n", "lang_cluster": "Ruby", "tags": ["greedy", "dp"], "code_uid": "9dbc6f90de8fab90b5e22882f437ecd3", "src_uid": "8e81ad7110552c20297f08ad3e5f8ddc", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "cash = gets.to_i\nbills = [100,20,10,5,1]\nx = 0\nt = 0\n\nwhile cash > 0\n if cash/bills[x] >= 0\n t+=cash/bills[x]\n cash = cash%bills[x]\n x+=1\n end\nend\n\nputs t", "lang_cluster": "Ruby", "tags": ["greedy", "dp"], "code_uid": "98c62234bfedb69ca63fb07ffdb5962d", "src_uid": "8e81ad7110552c20297f08ad3e5f8ddc", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "puts gets.chomp==gets.chomp.reverse!? \"YES\":\"NO\"", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "a6a0144c2376c9b1cd73efb629102422", "src_uid": "35a4be326690b58bf9add547fb63a5a5", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a, b = gets.strip, gets.strip\nputs a.reverse == b ? \"YES\" : \"NO\"\n", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "0d2b5adbd68496eba4fa14ec813db8ac", "src_uid": "35a4be326690b58bf9add547fb63a5a5", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "string1 = gets.chomp\nstring2 = gets.chomp\nif string1 == string2.reverse then\n puts \"YES\"\nelse\n puts \"NO\"\nend\n", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "b3316f9f8c1f26f5c042e335038e7520", "src_uid": "35a4be326690b58bf9add547fb63a5a5", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "i=(1..12).map{|i|Time.gm(1,i).strftime(\"%B\n\")}\n$><<< blue_socks\n print blue_socks,\" \"\n\n res = (red_socks-blue_socks)/2\n puts res\n elsif red_socks < blue_socks\n print red_socks, \" \"\n res = (blue_socks-red_socks)/2\n puts res\n else\n print red_socks,\" \", \"0\"\n print \"\\n\"\n end\nend", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "9e1ed7bc8ff13088afba56129f14f8b2", "src_uid": "775766790e91e539c1cfaa5030e5b955", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a, b = gets.split(' ').map(&:to_i).sort\n\nputs \"#{a} #{(b-a).div(2)}\"\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "702ad2342a4d9f7ab5a534321a6ad12f", "src_uid": "775766790e91e539c1cfaa5030e5b955", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a, b=gets.split.map &:to_i\nres=0\nwhile a<=b\n res+=1\n a*=3\n b*=2\nend\nputs res\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "ef2fb52936213d299cd26abfee90a8e5", "src_uid": "a1583b07a9d093e887f73cc5c29e444a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "l, b = gets.chomp.split.map(&:to_i)\ny = 0\nuntil l > b\n l *= 3\n b *= 2\n y += 1\nend\nputs y", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "9d8454a3602d030830f86cfcfa88a185", "src_uid": "a1583b07a9d093e887f73cc5c29e444a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "$a = gets\n$a,$b = $a.split(' ').to_a\n$k = 0\n$a = $a.to_i\n$b = $b.to_i\nuntil $a > $b\n\t$a *= 3\n\t$b *= 2\n\t$k += 1\nend\nprint $k", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "4b12d0f3947746db93080e27acc3b01d", "src_uid": "a1583b07a9d093e887f73cc5c29e444a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def read_next_line\n gets.split.map(&:to_i)\nend\n\nn, k = read_next_line\na = read_next_line\n\nr = Array.new(k) { Array.new(2, 0) }\n(0...n).each { |i|\n r[i % k][a[i] - 1] += 1\n}\n\nputs r.inject(0) { |s, x| s + x.min }", "lang_cluster": "Ruby", "tags": ["math", "greedy", "implementation"], "code_uid": "2fd77f12f034d358d9c902b8f32449c1", "src_uid": "5f94c2ecf1cf8fdbb6117cab801ed281", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "\ndef solve arr, k\n one = Array.new(k) {0}\n two = Array.new(k) {0}\n (0...arr.length).each do |i|\n if arr[i] == 1\n one[i % k] += 1\n else\n two[i % k] += 1\n end\n end\n tot = 0\n (0...k).each do |i|\n tot += [one[i], two[i]].min\n end\n tot\nend\n\nn, k = STDIN.gets.chomp.split.map {|i| i.to_i}\narr = STDIN.gets.chomp.split.map {|i| i.to_i}\n\nputs solve arr, k\n", "lang_cluster": "Ruby", "tags": ["math", "greedy", "implementation"], "code_uid": "48371f2e767d5e61a09820c7dfdffa8c", "src_uid": "5f94c2ecf1cf8fdbb6117cab801ed281", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, k = gets.split.collect{|i| i.to_i}\na = gets.split.collect{|i| i.to_i}\nans = 0\n(0...k).each do |i|\n j = 0\n tmp = Array.new\n while i+j < n\n tmp.push(a[i+j])\n j += k\n end\n ans += [tmp.count(1), tmp.count(2)].min\nend\nputs ans\n", "lang_cluster": "Ruby", "tags": ["math", "greedy", "implementation"], "code_uid": "0ea4b14ef494eea9daea06f55c2de758", "src_uid": "5f94c2ecf1cf8fdbb6117cab801ed281", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["number theory"], "code_uid": "d29e1a8b0a12d494358eebcebfac7e84", "src_uid": "25e5afcdf246ee35c9cef2fcbdd4566e", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\nif n == 3\n print 6\nelsif n <= 2\n print n\nelse\nn -= 1 if n%6 == 0\na = n-2\na -= 1 if n%2 == 0\nprint n*(n-1)*a\nend", "lang_cluster": "Ruby", "tags": ["number theory"], "code_uid": "90cb3f59ac9d469d9c312a9c1826d2e5", "src_uid": "25e5afcdf246ee35c9cef2fcbdd4566e", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.chomp.to_i\nif n <= 2\n puts n\nelsif n % 6 == 0\n puts (n-1) * (n-2) * (n-3)\nelsif n % 2 == 0\n puts n * (n-1) * (n-3)\nelse\n puts n * (n-1) * (n-2)\nend\n", "lang_cluster": "Ruby", "tags": ["number theory"], "code_uid": "91490deafbed5959517ef084f927cd3d", "src_uid": "25e5afcdf246ee35c9cef2fcbdd4566e", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a, b, c, d = gets.split.map{|i| i.to_i}\nputs a > b ? 'First' : 'Second'", "lang_cluster": "Ruby", "tags": ["math", "constructive algorithms"], "code_uid": "d0c90126246bc01489aedc8902dcf67c", "src_uid": "aed24ebab3ed9fd1741eea8e4200f86b", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n1, n2, k1, k2 = $stdin.readline.split.map(&:to_i)\n\nif n1>n2\n puts \"First\"\nelse\n puts \"Second\"\nend", "lang_cluster": "Ruby", "tags": ["math", "constructive algorithms"], "code_uid": "d93d6aeb1fb3adc119f96163ae98f7bd", "src_uid": "aed24ebab3ed9fd1741eea8e4200f86b", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "arr = $stdin.readline.split(\" \")\nn1= arr[0].to_i\nn2 = arr[1].to_i\nif (n2 + 1 > n1 )\n puts \"Second\"\nelse\n puts \"First\"\nend", "lang_cluster": "Ruby", "tags": ["math", "constructive algorithms"], "code_uid": "864d158a0d53a8ecef9f5b890b7e9d49", "src_uid": "aed24ebab3ed9fd1741eea8e4200f86b", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,a,x,b,y = gets.split.map(&:to_i)\nflag = 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 flag = true\n break\n end\nend\nif flag\n puts(\"YES\")\nelse\n puts(\"NO\")\nend", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "2264ab2b7af4f7f06d8a226933deac19", "src_uid": "5b889751f82c9f32f223cdee0c0095e4", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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\")", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "15fe37125c48284ee9e1bfe1476ac1f2", "src_uid": "5b889751f82c9f32f223cdee0c0095e4", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a=gets\nstr=\"qwertyuiopasdfghjkl;zxcvbnm,./\"\nstrk=gets\nif a==\"R\\n\"\n for i in 0...strk.size-1\n strk[i]=str[str.index(strk[i])-1]\n end\nend \nif a==\"L\\n\"\n for i in 0...strk.size-1\n strk[i]=str[str.index(strk[i])+1]\n end\nend\nputs strk", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "4bc5a55ddbad8b4132065d4d5f91c2c8", "src_uid": "df49c0c257903516767fdb8ac9c2bfd6", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "$normal = [[\"q\", \"w\", \"e\", \"r\", \"t\", \"y\", \"u\", \"i\", \"o\", \"p\"],\n [\"a\", \"s\", \"d\", \"f\", \"g\", \"h\", \"j\", \"k\", \"l\", \";\"],\n [\"z\", \"x\", \"c\", \"v\", \"b\", \"n\", \"m\", \",\", \".\", \"/\"]]\nd = gets.chomp\ns = gets.chomp.split(\"\")\ndef right(c)\n for i in 0...3\n for j in 0...10\n if c == $normal[i][j]\n return $normal[i][j+1]\n end\n end\n end\nend\n\ndef left(c)\n for i in 0...3\n for j in 0...10\n if c == $normal[i][j]\n if j == 0\n return nil\n else\n return $normal[i][j-1]\n end\n end\n end\n end\nend\nfor i in 0...s.size\n if d == \"L\"\n print right(s[i])\n elsif d == \"R\"\n print left(s[i])\n end \nend\nprint \"\\n\"\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "27ef88aadf462c21f20400138811de86", "src_uid": "df49c0c257903516767fdb8ac9c2bfd6", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = \"qwertyuiopasdfghjkl;zxcvbnm,./\"\nk = gets.chomp == \"L\" ? 1 : -1\nputs gets.chomp.split('').map{|x|s[s.index(x)+k]}.join\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "9f1fd1e3bb566098548c49a6793d51cd", "src_uid": "df49c0c257903516767fdb8ac9c2bfd6", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def conv(a,b)\n if b > a/2\n b = a - b\n end\n ans = 1\n div = 1\n b.times do |i|\n ans *= a - i\n div *= (i+1)\n end\n ans = ans / div\n ans\nend\n\nn = gets.to_i\nx = conv(n,n/2) / 2\nfor i in 2..((n/2)-1)\n x *= i\n x *= i\nend\nputs x", "lang_cluster": "Ruby", "tags": ["math", "combinatorics"], "code_uid": "9070d10457d92bbdaa506c4ade8a692e", "src_uid": "ad0985c56a207f76afa2ecd642f56728", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def factorial(n)\n return (1..n).inject(:*)\nend\n\nn = gets.to_i\nputs factorial(n) / (n / 2) ** 2 / 2\n", "lang_cluster": "Ruby", "tags": ["math", "combinatorics"], "code_uid": "a0ef62be797ac9f596e270cd98ce45cc", "src_uid": "ad0985c56a207f76afa2ecd642f56728", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "N=STDIN.gets.to_i\nans=1\n(1..N-1).each do |i|\n\tans*=i\nend\nans/=(N+1)/2\nputs ans", "lang_cluster": "Ruby", "tags": ["math", "combinatorics"], "code_uid": "86c6e50703de447ea4092e43d7c1a584", "src_uid": "ad0985c56a207f76afa2ecd642f56728", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\nn, k = gets.split.map(&:to_i)\n\nif (n/k).odd?\n puts \"YES\"\nelse\n puts \"NO\"\nend", "lang_cluster": "Ruby", "tags": ["math", "games"], "code_uid": "3beb01d85f904103ce55618651fcc19c", "src_uid": "05fd61dd0b1f50f154eec85d8cfaad50", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "# Try Codeforces\n# author: Leonardone @ NEETSDKASU\n\nn, k = gets.strip.split.map &:to_i\n\nv = n / k\n\nif v.even?\n puts :NO\nelse\n puts :YES\nend", "lang_cluster": "Ruby", "tags": ["math", "games"], "code_uid": "d3d3b20e0d0a8250f9d587cbe650ec1e", "src_uid": "05fd61dd0b1f50f154eec85d8cfaad50", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "# https://codeforces.com/problemset/problem/832/A\ns = gets.chomp\narr = s.split(' ')\n\nn = arr[0].to_i\nk = arr[1].to_i\nif ((n % k == 0) && (n / k % 2 != 0)) || ((n % k != 0) && (n / k % 2 != 0))\n puts 'YES'\nelse\n puts 'NO'\nend\n", "lang_cluster": "Ruby", "tags": ["math", "games"], "code_uid": "586265b204feb9cb04819a6d40ad43fd", "src_uid": "05fd61dd0b1f50f154eec85d8cfaad50", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "$><< 10\n\tputs \"0\"\nelse\n\t(1..(b-a)).each do |i|\n\t\tresult = result * (b + 1 - i)\t\n\tend\n\tputs result%10\nend", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "64a0842e820e62861b587069de794f33", "src_uid": "2ed5a7a6176ed9b0bda1de21aad13d60", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a, b = gets.split.map{|x| x.to_i}\n\ncase b - a\n\twhen 0..4\n\t\tans = 1\n\t\t(b - a).times {|i| ans *= (b - i) % 10}\n\t\tp ans % 10\n\telse\n\t\tp 0\nend", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "989f211cb9df017e97edda6bf7791933", "src_uid": "2ed5a7a6176ed9b0bda1de21aad13d60", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b=gets.split.map &:to_i;z=1;(a+1..b).each{|i|z=z*i%10;if z==0 then break end};p z", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "8274105dc62d9aa0cc5f0a92cd859751", "src_uid": "2ed5a7a6176ed9b0bda1de21aad13d60", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, m = gets.split.map { |x| x.to_i }\nneed = gets.split.map.with_index { |x, i| [(x.to_i+m-1)/m, i+1] }\nputs need.reverse.max[1]\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "eee1c994784d2e64ad15f524ed5c2c07", "src_uid": "c0ef1e4d7df360c5c1e52bc6f16ca87c", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, m = gets.split.map &:to_i\narr = gets.split.map &:to_i\nif m >= arr.max\n puts arr.size\nelse\n arr.map! { |x| x = (x / m.to_f).ceil }\n puts arr.rindex(arr.max) + 1\nend\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "d4b6da07527d6ba3b4b6cc3d918a935e", "src_uid": "c0ef1e4d7df360c5c1e52bc6f16ca87c", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "m=gets.split[1].to_i;a=gets.split.map{|x|-x.to_i/m};p a.rindex(a.min)+1", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "21791a506783f69ee6ca67a731f9c44d", "src_uid": "c0ef1e4d7df360c5c1e52bc6f16ca87c", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "rts = Array.new(5)\nfor i in 0..4\n rts[i] = Hash.new\n for j in 1..5\n rts[i][j] = 0\n end\nend\n\nn = gets.chomp.to_i\nfor i in 1..n\n a,b = gets.chomp.split(/ /).map!{|x| x.to_i}\n rts[a-1][b] = 1\n rts[b-1][a] = 1\nend\n\nret = \"FAIL\"\nfor i in 0..2\n for j in i+1..3\n for k in j+1..4\n wk = rts[i][j+1] + rts[i][k+1] + rts[j][k+1]\n if wk == 3 || wk == 0 then\n ret = \"WIN\"\n break\n end\n end\n end\nend\nputs ret\n\n", "lang_cluster": "Ruby", "tags": ["math", "implementation", "graphs"], "code_uid": "090fc74e8b781a790d35915be8f0ad79", "src_uid": "2bc18799c85ecaba87564a86a94e0322", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "acs = []\ngets.strip.to_i.times do\n acs << gets.strip.split(/\\s/).map(&:to_i).sort\nend\n\n[1,2,3,4,5].combination(3).each do |m|\n count = 0\n m.combination(2).each do |n|\n count += 1 if acs.include?(n)\n end\n if count == 0 || count == 3\n puts 'WIN'\n exit\n end\nend\nputs 'FAIL'\n\n", "lang_cluster": "Ruby", "tags": ["math", "implementation", "graphs"], "code_uid": "d5310d4da7cdc4a74389b082f003f8f0", "src_uid": "2bc18799c85ecaba87564a86a94e0322", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.to_i;d=Array.new(6){Array.new(6){0}}\nn.times{f,t=gets.split.map(&:to_i);d[f][t]=d[t][f]=1}\nfor i in 1..5\n for j in 1..5\n next if i==j\n \n for k in 1..5\n next if i==j || j==k || i==k\n \n if d[i][j]+d[j][k]+d[k][i]==3 || d[i][j]+d[j][k]+d[k][i]==0\n puts :WIN;exit\n end\n end\n end\nend\nputs :FAIL", "lang_cluster": "Ruby", "tags": ["math", "implementation", "graphs"], "code_uid": "3daf0567d02262675b6a696cb61cdeef", "src_uid": "2bc18799c85ecaba87564a86a94e0322", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "gets p\nputs [*1..5].combination(3).any?{|x|x.permutation(2).select{|a,b|$_=~/#{a} #{b}/}.size%3<1} ? \"WIN\" : \"FAIL\"", "lang_cluster": "Ruby", "tags": ["math", "implementation", "graphs"], "code_uid": "7fbff5e55587265c4a7ec211ebf18d5b", "src_uid": "2bc18799c85ecaba87564a86a94e0322", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\na = Array.new(5){[false] * 5}\nn.times do\n\tx, y = gets.split.map{|_| _.to_i - 1}\n\ta[x][y] = a[y][x] = true\nend\n5.times do |i|\n\ti.times do |j|\n\t\tj.times do |k|\n\t\t\tif (a[i][j] && a[j][k] && a[k][i]) || !(a[i][j] || a[j][k] || a[k][i])\n\t\t\t\tputs :WIN\n\t\t\t\texit\n\t\t\tend\n\t\tend\n\tend\nend\nputs :FAIL\n", "lang_cluster": "Ruby", "tags": ["math", "implementation", "graphs"], "code_uid": "63464fd47f73046a877acaceb72ef15d", "src_uid": "2bc18799c85ecaba87564a86a94e0322", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "m=gets.to_i\nk=Array.new(5){Array.new(5,0)}\nm.times{\n input=gets.split.map(&:to_i)\n k[input[0]-1][input[1]-1]=1\n k[input[1]-1][input[0]-1]=1\n}\n5.times{|i|\n 5.times{|j|\n 5.times{|x|\n if i==j || j==x || x==i then\n next\n end\n if k[i][j]==1 && k[j][x]==1 && k[x][i]==1 then\n puts \"WIN\"\n exit\n end\n if k[i][j]==0 && k[j][x]==0 && k[x][i]==0 then\n puts \"WIN\"\n exit\n end\n }\n }\n}\nputs \"FAIL\"", "lang_cluster": "Ruby", "tags": ["math", "implementation", "graphs"], "code_uid": "4d8760e8438e928b4b076b5f209dfec9", "src_uid": "2bc18799c85ecaba87564a86a94e0322", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\ncount = Hash.new(0)\nn.times do\n\ta,b = gets.split(\" \").map(&:to_i)\n\tcount[a] += 1\n\tcount[b] += 1\t\nend\n\nans = false\n\n(1..5).each do |i|\n\ta = count[i]\n\tif a >= 3 || a <= 1\n\t\tans = true\n\t\tbreak\n\tend\nend\n\nputs ans ? \"WIN\" : \"FAIL\"", "lang_cluster": "Ruby", "tags": ["math", "implementation", "graphs"], "code_uid": "4b0e27a9e805217f99da483ae0d0446c", "src_uid": "2bc18799c85ecaba87564a86a94e0322", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = gets.chomp.split(\" \").map(&:to_i)\n\nlol = s[0] + s[1] + s[2]\nlol = (lol.to_f / 3.to_f).floor\n\nputs [s[0]+s[1], s[1]+s[2],s[0]+s[2],lol].min\n", "lang_cluster": "Ruby", "tags": ["greedy"], "code_uid": "ce498687555519d732d025f0e2096823", "src_uid": "bae7cbcde19114451b8712d6361d2b01", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "rgb=gets.split.map(&:to_i); s=rgb.inject(0, :+); puts [s/3, s-rgb.max].min\n", "lang_cluster": "Ruby", "tags": ["greedy"], "code_uid": "70d237918ccaf1f480bb9ef63d26299c", "src_uid": "bae7cbcde19114451b8712d6361d2b01", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "r, g, b = STDIN.readline.split.map{|x| x.to_i}\nn = [r + g + b - [r,g,b].max, (r + g + b) / 3].min\nputs (n.to_s)", "lang_cluster": "Ruby", "tags": ["greedy"], "code_uid": "07720a113ad216a75989df6692ed7dc9", "src_uid": "bae7cbcde19114451b8712d6361d2b01", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "gets;p gets.chomp.gsub(/(RU|UR)/,?D).size", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "d340236929513217abf6462c50d3e07e", "src_uid": "986ae418ce82435badadb0bd5588f45b", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "gets.chomp\nputs gets.chomp.gsub(/RU|UR/,\"D\").length\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "52e92c3270ba866e0958034996fe910b", "src_uid": "986ae418ce82435badadb0bd5588f45b", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\nans = n\ns = gets.chomp\nwhile n > 1\n\tpair = s[n - 2.. n - 1]\n\tif pair[/(RU|UR)/] != nil\n\t\tans -= 1\n\t\tn -= 2\n\telse \n\t\tn -= 1\n\tend\nend\nputs ans", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "908f2a9b59dd06c88126932d57414bc9", "src_uid": "986ae418ce82435badadb0bd5588f45b", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "require 'prime'\n\ndef sub(b, s)\n if b.empty?\n v = (s[0]+1)*(s[1]+2)*(s[2]+2) - s[0]*s[1]*s[2]\n return [v, v]\n end\n\n b = b.dup\n k, v = b.pop\n\n result = [1e100, 0]\n 0.upto(v) do |i|\n 0.upto(v-i) do |j|\n mn, mx = sub(b, [s[0]*k**i, s[1]*k**j, s[2]*k**(v-i-j)])\n result[0] = [result[0], mn].min\n result[1] = [result[1], mx].max\n end\n end\n\n result\nend\n\n\ndef solve(n)\n a = Prime.prime_division(n)\n\n s1 = sub(a, [1, 1, 1])\n\n=begin\n b = a.map{|k,v| [k]*v}.flatten\n r = []\n (3**b.size).times do |i|\n o = [1]*3\n (\"0\"*b.size+i.to_s(3))[-b.size,b.size].each_char.zip(b) do |j, k|\n o[j.to_i] *= k\n end\n r << [(o[0]+1)*(o[1]+2)*(o[2]+2) - o[0]*o[1]*o[2], o]\n end\n s2 = [r.min[0], r.max[0]]\n=end\n s1\nend\n\nn = gets.to_i\nputs solve(n)*\" \"\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "5fbc882a89685313d42d130290a3e853", "src_uid": "2468eead8acc5b8f5ddc51bfa2bd4fb7", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "f=->{gets(\" \").to_i};p [f[]-f[],f[]+1].min\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "ea6e29c65b5fc8ef53844b9c2591ba45", "src_uid": "51a072916bff600922a77da0c4582180", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,a,b=gets.split.map(&:to_i)\nans=0\n(1..n).each{|_| ans+=1 if (_-1)>=a && (n-_)<=b}\nputs ans\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "2ead57af919da3a4aba9412bdc8d6577", "src_uid": "51a072916bff600922a77da0c4582180", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,a,b = gets.split.map &:to_i\n\nresult = 0\n\nfor i in a..n-1\n\tfor j in 0..b \n\t\tif i+j+1 == n\n\t\t\tresult +=1\n\t\tend\n\tend\nend\n\nputs result", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "0c937f0c52a41cb3ef2a5585fc37f0fc", "src_uid": "51a072916bff600922a77da0c4582180", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "gets\ns = gets\nresult = 0\n\nwhile s.include? 'xxx'\n s.slice!(s.index('xxx'))\n result += 1\nend\n\nputs result\n", "lang_cluster": "Ruby", "tags": ["greedy", "strings"], "code_uid": "7248b51d768faa49839ba4ab98283eac", "src_uid": "8de14db41d0acee116bd5d8079cb2b02", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "class Main\n #def get_problem_link\n # problem_link = \"https://codeforces.com/contest/978/problem/B\"\n # return problem_link\n #end\n\n #def get_submission_link\n # submission_link = ''\n # return submisson_link\n #end\n\n #begin\n #of codeforces interface\n def run_interface\n n = gets.to_i\n k = gets.chomp\n puts solution(n, k)\n end\n #end\n #of codeforces interface\n\n def solution(n, string)\n res = 0\n for i in 0...n do\n if string[i..i+2] === 'xxx'\n res+=1\n end\n end\n return res\n end\n\nend\n\n#then upload to codeforces uncomment this line:\nMain.new.run_interface\n", "lang_cluster": "Ruby", "tags": ["greedy", "strings"], "code_uid": "972f35cb7787bcfb97687430451e7892", "src_uid": "8de14db41d0acee116bd5d8079cb2b02", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["greedy", "strings"], "code_uid": "748cfc780712fd4a9579d995e3b266f1", "src_uid": "8de14db41d0acee116bd5d8079cb2b02", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, x, y = gets.split(\" \").map(&:to_i)\nd = x + (-n * y / 100)\nd = 0 if d > 0\nputs -d", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "2f3864e86a410ce54525030395f0b050", "src_uid": "7038d7b31e1900588da8b61b325e4299", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "inp=gets.chomp.split.collect{|a| a.to_i}\nres=(Float((inp[2]*inp[0]))/100.0).ceil.to_i-inp[1]\nif res>0\n puts res\nelse\n puts 0\nend\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "8e60d195fc3319c03e4922e8ebe3d17c", "src_uid": "7038d7b31e1900588da8b61b325e4299", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,x,p = gets.split.map(&:to_i)\nk = ((n/100.0*p).ceil - x)\nputs k >= 0 ? k : 0", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "c0cbef427276635613eb73b83ea72f65", "src_uid": "7038d7b31e1900588da8b61b325e4299", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "r = gets.split.map{|e| e.to_i}\nn = r[0]\nc = r[1..3]\nl = []\nfor i in (0..8000) do l[i] = 0 end\nc.each do |e|\n l[e]=1\nend\n\nfor i in (1..n) do\n c.each do |e|\n if l[i]==0 then next end\n l[i+e] = [l[i+e],l[i]+1].max\n end\nend\nputs l[n]\n", "lang_cluster": "Ruby", "tags": ["brute force", "dp"], "code_uid": "cafc3e691790069d21c281425f1ded6c", "src_uid": "062a171cc3ea717ea95ede9d7a1c3a43", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, a, b, c = gets.split(' ').map(&:to_i)\na, b, c = [a, b, c].sort\n\nresult = 0\n\n(n.div a).downto(0) do |k|\n m = n-k*a\n (m.div b).downto(0) do |l|\n d, m = (n - k*a - l*b).divmod(c)\n if m.zero?\n result = [result, d + k + l].max \n break\n end\n end\nend\n\nputs result\n", "lang_cluster": "Ruby", "tags": ["brute force", "dp"], "code_uid": "0f3f461fd2e04f7ebb2c5302c4ac6000", "src_uid": "062a171cc3ea717ea95ede9d7a1c3a43", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "input = gets.chomp\ninput = input.split\n\nn = input[0].to_i\na = input[1].to_i\nb = input[2].to_i\nc = input[3].to_i\n\ndp = Array.new(n + 1, -1)\ndp[0] = 0\n\n(1..n).each do |i|\n do_a = dp[i - a] if i - a >= 0\n do_b = dp[i - b] if i - b >= 0\n do_c = dp[i - c] if i - c >= 0\n\n dp[i] = [dp[i], do_a + 1].max if do_a && do_a != -1\n dp[i] = [dp[i], do_b + 1].max if do_b && do_b != -1\n dp[i] = [dp[i], do_c + 1].max if do_c && do_c != -1\nend\n\nputs dp[n]", "lang_cluster": "Ruby", "tags": ["brute force", "dp"], "code_uid": "ed9f41bec769c382f5012d605694807c", "src_uid": "062a171cc3ea717ea95ede9d7a1c3a43", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "x1,x2,x3 = gets.split.map(&:to_i).sort\n\nputs x3-x1", "lang_cluster": "Ruby", "tags": ["math", "sortings", "implementation"], "code_uid": "9d1728175d05c8c552993f514154017a", "src_uid": "7bffa6e8d2d21bbb3b7f4aec109b3319", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b=gets.split.map(&:to_i).minmax;p b-a", "lang_cluster": "Ruby", "tags": ["math", "sortings", "implementation"], "code_uid": "b7fd74ff511a2697cf8b8964934dc6da", "src_uid": "7bffa6e8d2d21bbb3b7f4aec109b3319", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "xs = gets.split.map(&:to_i)\nputs ((1..100).map do |i|\n xs.map { |x| (x - i).abs }.inject(&:+)\nend.min)\n", "lang_cluster": "Ruby", "tags": ["math", "sortings", "implementation"], "code_uid": "865ba3236da7662c4b38721745eaa7b4", "src_uid": "7bffa6e8d2d21bbb3b7f4aec109b3319", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.to_i;x,y=2,3;n.times{x,y=y,(x+y)%1000000007};p x-2\n", "lang_cluster": "Ruby", "tags": ["math", "dp"], "code_uid": "edbcc05df0f6e435e8d40e75902d9f44", "src_uid": "5c4bd12df3915186a7b506c2060db125", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.to_i;x,y=2,3;n.times{x,y=y,(x+y)%1000000007};p x-2", "lang_cluster": "Ruby", "tags": ["math", "dp"], "code_uid": "363857da66fe3206103892d0252c9b09", "src_uid": "5c4bd12df3915186a7b506c2060db125", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.to_i;x,y=2,3;n.times{x,y=y,(x+y)%1000000007};p x-2\n", "lang_cluster": "Ruby", "tags": ["math", "dp"], "code_uid": "333c5b54a012f2ce908687e584f09fc3", "src_uid": "5c4bd12df3915186a7b506c2060db125", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "af2f712e156cdd4e5472b7c25df6dc31", "src_uid": "496baae594b32c5ffda35b896ebde629", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,s = gets.split.map(&:to_i)\nmugs = gets.split.map(&:to_i)\n\nif mugs.sort.slice(0,n-1).sum <= s\n\tputs \"YES\"\nelse\n\tputs \"NO\"\nend", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "8ca2f3470580941a7f5de624c8546b7a", "src_uid": "496baae594b32c5ffda35b896ebde629", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, s = gets.split.map(&:to_i)\na = gets.split.map(&:to_i).sort\na.pop\nputs a.inject(:+) > s ? 'NO' : 'YES'\n\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "8b6ec6165dff435fbb89d5d081892642", "src_uid": "496baae594b32c5ffda35b896ebde629", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "str = gets.chomp\n\nstr =~ /^(\\d)\\.(\\d+)e(\\d+)$/\na = $1\nd = $2\nb = $3.to_i\n\nwhile 0 < d.size && d[-1] == '0'\n d = d[0...d.size - 1]\nend\n\nif b < d.size\n ans0 = a + d[0...b]\n if ans0 =~ /([1-9]\\d*)$/ \n ans0 = $1\n else\n ans0 = '0'\n end\n ans1 = d[b...d.size]\n if ans1 == ''\n puts ans0\n else\n puts ans0 + '.' + ans1 \n end\nelse\n ans = a + d + '0' * (b - d.size)\n if ans =~ /([1-9]\\d*)$/ \n ans = $1\n else\n ans = '0'\n end\n puts ans\nend\n\n \n", "lang_cluster": "Ruby", "tags": ["brute force", "math", "strings", "implementation"], "code_uid": "5935596e3fe92383b1bc0a089699240d", "src_uid": "a79358099f08f3ec50c013d47d910eef", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "inp = gets\na,b = inp.split('e')\nc,d = a.split('.')\nif b.to_i >= d.length\n out = c + d\n add_zeros = b.to_i - d.length\n out += '0' * add_zeros\nelse\n out = c + d[0,b.to_i]\n out += ('.' + d[b.to_i,a.length]) if d[b.to_i,a.length].to_i != 0\nend\nputs out\n", "lang_cluster": "Ruby", "tags": ["brute force", "math", "strings", "implementation"], "code_uid": "37cf846a3f0de611bfb412122a25b64a", "src_uid": "a79358099f08f3ec50c013d47d910eef", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["brute force", "math", "strings", "implementation"], "code_uid": "6115f4447da6690e80525779deaa783c", "src_uid": "a79358099f08f3ec50c013d47d910eef", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "gets\nputs gets[/^1*0?/].length\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "51a6270c8b9e4355125fc602bcedbde3", "src_uid": "54cb2e987f2cc06c02c7638ea879a1ab", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/ruby\nn = gets.to_i - 1\np (gets.index('0') || n) + 1", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "e6c7b2fc57e5b14f398fa84bfb98cf79", "src_uid": "54cb2e987f2cc06c02c7638ea879a1ab", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "gets\nputs gets[/^1*0?/].length\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "9d7e38185f9f66bd8dc4ae0ba181953b", "src_uid": "54cb2e987f2cc06c02c7638ea879a1ab", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a=gets.chomp.split(\" \")\nweek_arry=[0,0]\nmonth_arry=[0,0]\n0.upto(6) do |i|\n\tweek_arry[i]=52\n\tif i==4 || i==5\n\t\tweek_arry[i]=53\n\tend\nend\n0.upto(30) do |i|\n\tmonth_arry[i]=12\n\tif i==29\n\t\tmonth_arry[i]=11\n\telsif i==30\n\t\tmonth_arry[i]=7\n\tend\nend\nif a[2]==\"week\"\n puts week_arry[a[0].to_i-1]\nelsif a[2]==\"month\"\n puts month_arry[a[0].to_i-1]\nend", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "7c15af4ff775af5b5a88627e920706b1", "src_uid": "9b8543c1ae3666e6c163d268fdbeef6b", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "require \"date\"\n\nd = Date.new(2016, 1, 1)\ne = Date.new(2017, 1, 1)\n\ns = gets\n\nans = 0\nif s =~ /week/\n x = s.split[0].to_i\n x = 0 if x == 7\n while d != e\n if d.wday == x\n ans = ans+1\n end\n d = d+1\n end\nelse\n x = s.split[0].to_i\n while d != e\n if d.day == x\n ans = ans+1\n end\n d = d+1\n end\nend\n\nputs ans\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "0ef8f960436dac916708c7244a0c3e55", "src_uid": "9b8543c1ae3666e6c163d268fdbeef6b", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a=gets.chomp.split(\" \")\nweek_arry=[0,0]\nmonth_arry=[0,0]\n0.upto(6) do |i|\n\tweek_arry[i]=52\n\tif i==4 || i==5\n\t\tweek_arry[i]=53\n\tend\nend\n0.upto(30) do |i|\n\tmonth_arry[i]=12\n\tif i==29\n\t\tmonth_arry[i]=11\n\telsif i==30\n\t\tmonth_arry[i]=7\n\tend\nend\nif a[2]==\"week\"\n puts week_arry[a[0].to_i-1]\nelsif a[2]==\"month\"\n puts month_arry[a[0].to_i-1]\nend", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "d93420de5b3f19f209eedb686fef2b07", "src_uid": "9b8543c1ae3666e6c163d268fdbeef6b", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\np gets.split.map(&:to_i).inject(:gcd) * n\n\n", "lang_cluster": "Ruby", "tags": ["math", "greedy"], "code_uid": "98beef4af004e8b04227ef6e0f147b65", "src_uid": "042cf938dc4a0f46ff33d47b97dc6ad4", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.to_i\na=gets.chomp.split.map(&:to_i)\nans=a[0]\nfor i in a do\n\tans=ans.gcd(i)\nend\nputs ans*n", "lang_cluster": "Ruby", "tags": ["math", "greedy"], "code_uid": "f7a40e63f0655eccaa60127413e14634", "src_uid": "042cf938dc4a0f46ff33d47b97dc6ad4", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def gcd a, b\n\treturn a if b == 0\n\tgcd b, a % b\nend\n\nn = gets.to_i\na = gets.split.map { |x| x.to_i }\n\ng = a[0]\na.each do |x|\n\tg = gcd g, x\nend\nputs g * n\n", "lang_cluster": "Ruby", "tags": ["math", "greedy"], "code_uid": "4505e9a103282d4ee6c6c72f75bb4400", "src_uid": "042cf938dc4a0f46ff33d47b97dc6ad4", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/ruby\n# -*- coding: utf-8 -*-\ninclude Math\n\ndef solve xs\n return xs[1]*xs[2] if xs[0]==1\n xs.map!{ |x| x-1}\n return xs.inject(:+)*2 + solve(xs)\nend\nputs solve (gets.split.map{ |x| x.to_i}.sort)\n\n\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "7ba9acfd8c8360ddcc7832a6bc13c188", "src_uid": "8ab25ed4955d978fe20f6872cb94b0da", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b,c=gets.split.map &:to_i;p a*b+b*c+c*a-a-b-c+1", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "f941458864012c2e5ee9c27de6e4b6de", "src_uid": "8ab25ed4955d978fe20f6872cb94b0da", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b,c = gets.split.map(&:to_i)\nputs a*b+b*c+a*c - a - b - c + 1", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "1404545ca3a5f38ce5d505660093432b", "src_uid": "8ab25ed4955d978fe20f6872cb94b0da", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["brute force", "binary search", "bitmasks"], "code_uid": "3d0854ee321b5391a9e5f78558532cd8", "src_uid": "77b5f83cdadf4b0743618a46b646a849", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def generate_lucky(i,n,arr)\n\tif i >= n\n\t\t@no_list << arr\n\t\treturn\n\tend\n\n\tfour_count = arr.count(\"4\")\n\tseven_count = arr.count(\"7\")\n\texpected = n/2\n\n\tif four_count < expected\n\t\tarr[i] = \"4\"\n\t\tgenerate_lucky(i+1,n,arr.dup)\n\tend\n\n\tif seven_count < expected\n\t\tarr[i] = \"7\"\n\t\tgenerate_lucky(i+1,n,arr.dup)\n\tend\nend\n\n\n@no_list = []\n# generate_lucky(0,2,\"\")\n# generate_lucky(0,4,\"\")\n\nn = gets.to_i\n\nl = n.to_s.length\n\nif l.odd?\n\tgenerate_lucky(0,l+1,\"\")\nelse \n\tgenerate_lucky(0,l,\"\")\n\tgenerate_lucky(0,l+2,\"\")\nend\n\n@no_list = @no_list.map(&:to_i)\n@no_list.sort!\nans = @no_list.detect { |e| e >= n }\nputs ans", "lang_cluster": "Ruby", "tags": ["brute force", "binary search", "bitmasks"], "code_uid": "def7b806dae15d134cce9d46cc2704fc", "src_uid": "77b5f83cdadf4b0743618a46b646a849", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "digits = STDIN.readline.strip.split('').map {|s| s.to_i }.reverse\n\npos = 0\nwhile pos < digits.length\n digit = digits[pos]\n if digit == 4 or digit == 7\n pos += 1\n next\n end\n (0..pos-1).each {|i| digits[i] = 4 }\n if digit < 4\n digits[pos] = 4\n elsif digit < 7\n digits[pos] = 7\n else\n digits[pos] = 4\n seek = pos+1\n while seek < digits.length and digits[seek] == 9\n digits[seek] = 0\n seek += 1\n end\n if seek < digits.length\n digits[seek] += 1\n else\n digits = (digits.length + 1).times.map { 4 }\n break\n end\n end\n pos += 1\nend\n\nwhile digits.count(4) != digits.count(7)\n pos = 0\n while pos < digits.length and digits[pos] == 7\n digits[pos] = 4\n pos += 1\n end\n if pos < digits.length\n digits[pos] = 7\n else\n digits.push(4)\n end\nend\n\nputs digits.reverse.map {|i| i.to_s }.join\n", "lang_cluster": "Ruby", "tags": ["brute force", "binary search", "bitmasks"], "code_uid": "225066decda72f70639bebb0be94d917", "src_uid": "77b5f83cdadf4b0743618a46b646a849", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, m = gets.split.map(&:to_i)\nputs n == 1 ? 1 : n - m > m - 1 ? m + 1 : m - 1\n", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "games", "math", "greedy", "implementation"], "code_uid": "85fb0d3711705c695490ce1337660aec", "src_uid": "f6a80c0f474cae1e201032e1df10e9f7", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#http://codeforces.com/contest/570/problem/B\n\nn, m = gets.split().map(&:to_i)\n\nif n== 1 \n puts 1 \n\nelsif 2*m <=n\n puts m+1 \nelse \n puts m-1 \nend \n", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "games", "math", "greedy", "implementation"], "code_uid": "1579b804d7e4762a894c4165ea1a86d7", "src_uid": "f6a80c0f474cae1e201032e1df10e9f7", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/ruby\nN,M=gets.split.map(&:to_i)\np N==1 ? 1 : M-10\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 D ? :YES : :NO", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "ee965ee2d6a7efe25870078ae8e30429", "src_uid": "32c866d3d394e269724b4930df5e4407", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "N,T,K,D=gets.split.map &:to_i\nputs (N-1)/K*T > D ? :YES : :NO\n\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "e61168a48e49cf4b0caa98c3ffca2e54", "src_uid": "32c866d3d394e269724b4930df5e4407", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["greedy", "implementation"], "code_uid": "483cccf18e63b86514383c56f9fa042d", "src_uid": "51155e9bfa90e0ff29d049cedc3e1862", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["greedy", "implementation"], "code_uid": "a9c03a10691b0ed6bc7107fd16180ae6", "src_uid": "51155e9bfa90e0ff29d049cedc3e1862", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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!\"", "lang_cluster": "Ruby", "tags": ["greedy", "implementation"], "code_uid": "2e4524aaa9381f98d4fc8fa60b51a5e8", "src_uid": "51155e9bfa90e0ff29d049cedc3e1862", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["brute force", "math", "number theory"], "code_uid": "9664c7f53703f0237d1f03d2c1cdd815", "src_uid": "38690bd32e7d0b314f701f138ce19dfb", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = gets.chomp.split(\"\").map(&:to_i).reverse\nans = s.inject(:*)\nn = s.size\n(n-1).times do |i|\n if i != n-2 || (s[-1] != 1)\n s[i+1] -= 1\n elsif i == n-2 && s[-1] == 1\n s.pop\n end\n s[i] = 9\n ans = [ans,s.inject(:*)].max\nend\nputs ans", "lang_cluster": "Ruby", "tags": ["brute force", "math", "number theory"], "code_uid": "ba37aa20a55dcfb9aa4f8f8eac0784cb", "src_uid": "38690bd32e7d0b314f701f138ce19dfb", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, m = gets.split.map(&:to_i)\nds = [[-1,0],[1,0],[0,-1],[0,1]]\ndata = Array.new(n){|_| [\".\"]*m}\nres = 0\nn.times { |i|\n line = gets.strip\n line.length.times { |j| data[i][j] = line[j] }\n}\n\nn.times { |i|\n m.times{ |j|\n next if data[i][j] != \"W\"\n ds.each { |x, y|\n if i+x>=0 && i+x=0 && j+y 0 and field[x - 1][y] == \"P\"\n pos = [x - 1, y]\n\n elsif x < n - 1 and field[x + 1][y] == \"P\"\n pos = [x + 1, y]\n\n elsif y > 0 and field[x][y - 1] == \"P\"\n pos = [x, y - 1]\n\n elsif y < m - 1 and field[x][y + 1] == \"P\"\n pos = [x, y + 1]\n end\n end\n\n unless pos.empty?\n field[pos[0]][pos[1]] = \"\"\n pigs = pigs + 1\n pos = []\n end\n end\nend\n\nputs pigs\n", "lang_cluster": "Ruby", "tags": ["greedy", "implementation"], "code_uid": "df722c11f814c8440db0f61f2ec75639", "src_uid": "969b24ed98d916184821b2b2f8fd3aac", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["greedy", "implementation"], "code_uid": "5751bfa2aeff14ca4047ed2aec5e40ce", "src_uid": "969b24ed98d916184821b2b2f8fd3aac", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, l, r = gets.split.map(&:to_i)\n\nmin = (n-l) + 2**l-1\nmax = 2**(r-1)*(n-r) + 2**r-1\n\nputs \"#{min} #{max}\"", "lang_cluster": "Ruby", "tags": ["math", "greedy"], "code_uid": "facf4ac14efdf363391942e587231c03", "src_uid": "ce220726392fb0cacf0ec44a7490084a", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,l,r = gets.split.map(&:to_i)\nmn = n-l\nmx = (n-r)*(2**(r-1))\nl.times do |i|\n mn += 2**i\nend\nr.times do |i|\n mx += 2**i\nend\nputs \"#{mn} #{mx}\"", "lang_cluster": "Ruby", "tags": ["math", "greedy"], "code_uid": "8a1948a80575e844c9834c3c520fb9cd", "src_uid": "ce220726392fb0cacf0ec44a7490084a", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "N = gets.to_i\nR = gets.split.map(&:to_i)\nB = gets.split.map(&:to_i)\n\nonly_cnt = 0\nfail_cnt = 0\n\nN.times do |i|\n r = R[i]\n b = B[i]\n\n next if r == b\n\n if r == 1\n only_cnt += 1\n else\n fail_cnt += 1\n end\nend\n\nif only_cnt == 0\n puts -1\n exit\nend\n\nng = 0\nok = 1000\n\nwhile (ok - ng).abs > 1\n x = (ok + ng) / 2\n\n if only_cnt * x > fail_cnt\n ok = x\n else\n ng = x\n end\nend\n\nputs ok\n", "lang_cluster": "Ruby", "tags": ["greedy"], "code_uid": "82b858c0ca4e12e0b17bcd010e15acd7", "src_uid": "b62338bff0cbb4df4e5e27e1a3ffaa07", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "t = gets.to_i(2)\nk = 0\nwhile 4**k < t\n k += 1\nend\nputs k\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "1357df529a4a3fa72811bada97d520e0", "src_uid": "d8ca1c83b431466eff6054d3b422ab47", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a=Array.new(gets.split.map(&:to_i))\nb=Array.new(gets.split.map(&:to_i))\nn=gets.to_i\n\n\nn1=((a[0]+a[1]+a[2]).to_f/5).ceil\nn2=((b[0]+b[1]+b[2]).to_f/10).ceil\n\nif(n1+n2<=n)\n puts \"YES\"\nelse\n puts \"NO\"\nend", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "1b3716217b6981a33c9b48c4d8777136", "src_uid": "fe6301816dea7d9cea1c3a06a7d1ea7e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a = $stdin.readline.split.map(&:to_i)\nb = $stdin.readline.split.map(&:to_i)\nn = $stdin.readline.to_i\n\nna = a.inject(&:+)\nnb = b.inject(&:+)\n\nk = (na/5 + (((na%5)>0)?1:0)) + (nb/10 + (((nb%10)>0)?1:0))\n\nputs (k<=n) ? \"YES\" : \"NO\"", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "8305f7a726501ad0e66a88175a20f94a", "src_uid": "fe6301816dea7d9cea1c3a06a7d1ea7e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a=gets.split.inject(0){|sum,e| sum+=e.to_i}\nb=gets.split.inject(0){|sum,e| sum+=e.to_i}\nc=gets.to_i\na=-(-a/5)\nb=-(-b/10)\nputs (c-a-b>=0)?\"YES\":\"NO\"", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "31a18ce1c4a6693e13d110224fb10336", "src_uid": "fe6301816dea7d9cea1c3a06a7d1ea7e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "# 489C\n\nm, s = gets.chomp.split.map &:to_i\nif m == 1 && s == 0\n puts '0 0'\n exit\nend\nif (s - 1) / (m * 9) > 0 || s == 0\n puts '-1 -1'\n exit\nend\n\na = Array.new(m, 0)\na[-1] = 1\n(s - 1).times do |i|\n a[i / 9] += 1\nend\nprint a.reverse.join ''\nprint ' '\n\na = Array.new(m, 0)\ns.times do |i|\n a[i / 9] += 1\nend\nprint a.join ''", "lang_cluster": "Ruby", "tags": ["greedy", "dp", "implementation"], "code_uid": "db4332af7af52ec16a9a6ea101b78908", "src_uid": "75d062cece5a2402920d6706c655cad7", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "m, s = gets.split(' ').map(&:to_i)\n\nk = s\nnum = ''\nnum = '0' if s == 0\n9.downto(1) do |i|\n next if k.div(i).zero?\n\n num += i.to_s * k.div(i)\n k = k.modulo(i)\nend\n\nif num.length > m || (num.length < m && num == '0')\n puts '-1 -1'\nelsif num.length == m\n puts \"#{num.reverse} #{num}\"\nelse\n # Doing MIN\n min = '1' + '0' * (m - num.length - 1) + (num.reverse[0].to_i - 1).to_s + num.reverse[1..-1]\n # Doing MAX\n max = num + '0' * (m - num.length)\n\n puts \"#{min} #{max}\"\nend\n", "lang_cluster": "Ruby", "tags": ["greedy", "dp", "implementation"], "code_uid": "7022781c86248f665137444b2557bf08", "src_uid": "75d062cece5a2402920d6706c655cad7", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def fmin(m,s)\n\tif m==1 then\n\t\treturn [s]\t\n\telse\n\t\td=[s-1,9].min\n\t\treturn fmin(m-1,s-d)<r+a\n ttl=(r+a)*2\n end\nend\nputs ttl", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "a1a6d45074d9d3db88cfa90dca356881", "src_uid": "e8148140e61baffd0878376ac5f3857c", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b,c=gets.split.map &:to_i\nr=[a,b].min\na-=r\nb-=r\na+=b\ns=[a,c].min\na-=s\nc-=s\np r*2+s*2+c/2*2", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "ffb1ef042c3ad054609e70741b2661b4", "src_uid": "e8148140e61baffd0878376ac5f3857c", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "l, r, a = gets.split.map(&:to_i)\nar = [l, r].sort\nwhile a != 0\nar[0] += 1\na -= 1\nar.sort!\nend\nputs ar.min * 2", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "25680c93e0c17d053d12cf2375cc3de4", "src_uid": "e8148140e61baffd0878376ac5f3857c", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby 3", "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", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "305fafdfdbcc98d672edc57c3619f8f7", "src_uid": "d5e66e34601cad6d78c3f02898fa09f4", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby 3", "source_code": "main = -> {\n t = int\n t.times do\n n = int\n puts 2**n - 1\n end\n}\n\nDEBUG = true\nMOD = 10**9+7\n$yesno = %w(No Yes)\nYesNo = %w(No Yes)\nYESNO = %w(NO YES)\nINF = 10**9\n\nrequire \"set\"\nrequire \"prime\"\n\ndef int; gets.to_s.to_i end\ndef ints; gets.to_s.split.map { |s| s.to_i } end\ndef int1s; gets.to_s.split.map { |s| s.to_i - 1 } end\ndef float; gets.to_s.to_f end\ndef floats; gets.to_s.split.map { |s| s.to_f } end\ndef array_of(&convert); gets.to_s.split.map(&convert) end\ndef string; gets.to_s.chomp end\ndef strings; gets.to_s.split end\ndef rep(n, &b); Array.new(n, &b) end\ndef yes; puts $yesno[1] end\ndef no; puts $yesno[0] end\ndef yesno t; puts $yesno[t] end\ndef YesNo t; puts YesNo[t] end\ndef YESNO t; puts YESNO[t] end\ndef zip(xs, *yss); Enumerator.new { |y| xs.zip(*yss) { |a| y.yield(*a) } } end\ndef max(*xs, &block); block_given? ? xs.max_by(&block) : xs.max end\ndef min(*xs, &block); block_given? ? xs.min_by(&block) : xs.min end\ndef minmax(*xs, &block); block_given? ? xs.minmax_by(&block) : xs.minmax end\ndef gcd(*xs); xs.inject(0, :gcd) end\ndef matrix(h, w, fill=nil, &block); return Array.new(h) { Array.new(w, &block) } if block_given?; Array.new(h) { [fill] * w } end\ndef debug(x = nil); STDERR.puts (block_given? ? yield(x) : x).inspect if DEBUG; x end\ndef debug_grid(grid, width = 1); grid.each { |row| STDERR.puts row.map { |x| x.inspect.ljust(width) }.join(\"\") } if DEBUG; grid end\ndef if_debug; yield if DEBUG end\n\nmodule Boolean\n def coerce(other); [other, to_i] end\n def +@; to_i end\n def to_int; to_i end\n def *(other); to_i * other end\nend\n\nclass TrueClass\n include Boolean\n def to_i; 1 end\nend\n\nclass FalseClass\n include Boolean\n def to_i; 0 end\nend\n\nclass Integer\n def div_ceil(y); (self + y - 1) / y end\n def mod_inv(mod = MOD); pow(mod-2, mod) end\n def mod_div(y, mod = MOD); self * y.mod_inv(mod) % mod end\n def mod_nCr(r, mod = MOD); x = y = 1; (1..r).each { |i| x = x * (self + 1 - i) % mod; y = y * i % mod }; x.mod_div(y, mod); end\n def factorial(mod = MOD); (2..self).inject(1) { |f, x| f * x % mod } end\n def popcount; x = self; c = 0; while x > 0; c += 1 if x & 1 == 1; x >>= 1 end; c end #TODO: faster\n def bitbrute(&block); (1< 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\n def lower_bound; ac, wa = self.end_open, self.begin; while ac - wa > 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\n def shakutori(r2, &pred); Enumerator.new { |y| j, r = r2.begin, r2.end_open; each { |i| j += 1 while j + 1 < r and pred[i, j+1]; y.yield(i, j) } }; end\n def widest(&block); Enumerator.new { |y| j, n = self.begin, self.end_open; each { |i| j += 1 while j < n and block[i, j]; y.yield(i, j) if block[i, j] } } end\nend\n\nclass Array\n def power(&block); (0 ... 1 << size).each(&block) end\n def sorted_merge(other); a = []; i = j = 0; n, m = size, other.size; if j < m and other[j] < self[i]; a << other[j]; j += 1 else; a << self[i]; i += 1 end while i < n; a.push(*other[j..-1]) if j < m; a end\n def upper_bound; ac, wa = 0, size; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\n def lower_bound; ac, wa = size, 0; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\n def cum(*xs, &op); a = []; a << xs[0] if xs.size > 0; a << x = self[0]; (1...size).each { |i| a << x = op[x, self[i]] }; a end\n def cumdiff(range); self[range.end_open] - self[range.begin]; end\n def compress(kinds = uniq.sort!); map { |x| kinds.bsearch_index { _1 >= x } }; end\nend\n\nmodule Enumerable\n def sorted_uniq; x = nil; filter { |y| c = x === y; x = y; !c } end\n def cumsum; ys = [0]; each { |x| ys << x + ys[-1] }; ys end\nend\n\nmain[]", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "260bb8805497640da162ea11e4a752e8", "src_uid": "d5e66e34601cad6d78c3f02898fa09f4", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b=$<.map &:to_i;p ((a-b).abs+1)**2/4", "lang_cluster": "Ruby", "tags": ["math", "greedy", "implementation", "brute force"], "code_uid": "b54dc71018260c7c72478402ee2b681c", "src_uid": "d3f2c6886ed104d7baba8dd7b70058da", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a = gets.to_i\nb = gets.to_i\nd = a>b ? a-b : b-a\nsteps, rem = d.divmod 2\nsum = steps*(steps+1) + (steps+1)*rem\nputs sum", "lang_cluster": "Ruby", "tags": ["math", "greedy", "implementation", "brute force"], "code_uid": "0b1be36de70aa765625b469a564225d6", "src_uid": "d3f2c6886ed104d7baba8dd7b70058da", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\nm = gets.to_i\nx = ((n - m ).abs)/2\nrmendX = ((n - m ).abs)%2\ny = ((x*(x+1))/2)*2\nif rmendX > 0\n y += x+1\nend\np y", "lang_cluster": "Ruby", "tags": ["math", "greedy", "implementation", "brute force"], "code_uid": "d12a1f5656775753e6ceb01b552043e7", "src_uid": "d3f2c6886ed104d7baba8dd7b70058da", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.to_i\na=gets.split.map(&:to_i)\n#m,n=gets.split.map(&:to_i)\ni=0\nif n<=3 then\n puts \"chest\" if a.max==a[0]\n puts \"biceps\" if a.max==a[1]\n puts \"back\" if a.max==a[2]\nelse\nk,b,c=0,0,0\nwhile i< n do \n k+=a[i]\n i+=3 \nend\ni=1\nwhile ibiceps && chest>back\n\tputs \"chest\"\nelsif biceps>chest && biceps>back\n\tputs \"biceps\"\nelse\n\tputs \"back\"\nend", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "8a2c49c066a78a8241ba270bb668674a", "src_uid": "579021de624c072f5e0393aae762117e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.chomp.to_i\nexercises = gets.chomp.split(/ /).map(&:to_i)\nans = {}\nindex = 0\n(0...n).each do |step|\n index = 0 if index == 3\n if !ans.keys.include? index\n ans.store index, exercises[step]\n else\n ans[index] += exercises[step]\n end\n index += 1\nend\nmax = ans.values.max\nexercise = ans.select { |key, value| value == max }.to_a[0][0]\ncase exercise\nwhen 0\n puts \"chest\"\nwhen 1\n puts \"biceps\"\nwhen 2\n puts \"back\"\nend\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "295ac956bb1ebe55578fecc9b2851368", "src_uid": "579021de624c072f5e0393aae762117e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = gets.chomp\nans = ((s[0] == \"h\") ? (j=4; s[0..3]) : (j=3; s[0..2])) + \"://\"\ni = j\nj += 1\nwhile s[j..j+1] != \"ru\"\n j += 1\nend\nans += s[i...j] + \".\" + s[j..j+1]\nj += 2\nans += \"/\" + s[j..-1] if j < s.size\nputs ans", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "92f6f772b894f07817401870939f21bb", "src_uid": "4c999b7854a8a08960b6501a90b3bba3", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = gets.chomp\nstr = \"\"\nif s.start_with? \"ftp\" then \n str += \"ftp://\"\n s = s[3..-1]\nelse\n str += \"http://\"\n s = s[4..-1]\nend\nk = s.index(\"ru\")\nif k == 0 then k = s.index(\"ru\", 1)\nend\nstr = str + s[0...k] + \".ru\"\ns = s[k+2..-1]\nif s.size != 0 then\n str = str + \"/\" + s\nend\nputs \"#{str}\"", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "9707d9ae7235620aef431a782e407848", "src_uid": "4c999b7854a8a08960b6501a90b3bba3", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "# http://codeforces.com/problemset/problem/3/C\n\nclass Grid\n def initialize(gridStr)\n @numX = gridStr.count('X')\n @num0 = gridStr.count('0')\n @numP = gridStr.count('.')\n split = gridStr.split(\"\\n\")\n @lines = split.map { |line| line.split(\"\") }\n @num_winning_rows = how_many_in_a_row?\n end\n\n def analyze\n return \"illegal\" if is_illegal?\n return \"draw\" if is_draw?\n return \"the second player won\" if second_won?\n return \"the first player won\" if first_won?\n return \"second\" if second_turn?\n return \"first\" if first_turn?\n end\n\n def is_illegal?\n return true if @num0 > @numX\n return true if @numX > @num0 + 1\n return true unless @numX + @num0 + @numP == 9\n return true if too_many_wins?\n return true if move_after_win?\n end\n\n def is_draw?\n return false if @num_winning_rows > 0\n return true if @numX + @num0 == 9\n end\n\n def second_won?\n return false if too_many_wins?\n return @ohWins\n end\n\n def first_won?\n return false if too_many_wins?\n return @xWins\n end\n\n def second_turn?\n @numX == @num0 + 1\n end\n\n def first_turn?\n @numX == @num0\n end\n\n def move_after_win?\n return true if first_won? && @num0 >= @numX\n return true if second_won? && @numX > @num0\n end\n\n def how_many_in_a_row?\n num = 0\n (0..2).each { |col| num += 1 if horizontal_win(col) }\n (0..2).each { |row| num += 1 if vertical_win(row) }\n num += 1 if left_right_win\n num += 1 if right_left_win\n num\n end\n\n def horizontal_win(xPos)\n return false unless @lines[xPos][0] == \"X\" || @lines[xPos][0] == \"0\"\n if @lines[xPos][0] == @lines[xPos][1] && @lines[xPos][1] == @lines[xPos][2]\n set_winner(@lines[xPos][0])\n @horizontal_winner = true\n return true\n end\n end\n\n def vertical_win(yPos)\n return false unless @lines[0][yPos] == \"X\" || @lines[0][yPos] == \"0\"\n if @lines[0][yPos] == @lines[1][yPos] && @lines[1][yPos] == @lines[2][yPos]\n set_winner(@lines[0][yPos])\n @vertical_winner = true\n return true\n end\n end\n\n def left_right_win\n return false unless @lines[0][0] == \"X\" || @lines[0][0] == \"0\"\n if @lines[0][0] == @lines[1][1] && @lines[1][1] == @lines[2][2]\n set_winner(@lines[0][0])\n @diag_winner = true\n return true\n end\n end\n\n def right_left_win\n return false unless @lines[2][0] == \"X\" || @lines[2][0] == \"0\"\n if @lines[2][0] == @lines[1][1] && @lines[1][1] == @lines[0][2]\n set_winner(@lines[2][0])\n @diag_winner = true\n return true\n end\n end\n\n def set_winner(player)\n @xWins = true if player == \"X\"\n @ohWins = true if player == \"0\"\n end\n\n def too_many_wins?\n return false if @num_winning_rows == 1 || @num_winning_rows == 0\n return true if @num_winning_rows > 2\n winner = @xWins ? \"X\" : \"0\"\n return true if @horizontal_winner && !@diag_winner && !@vertical_winner\n return true if @vertical_winner && !@diag_winner && !@horizontal_winner\n return false\n end\nend\n\n\ndef solve\n l1 = gets.chomp\n l2 = gets.chomp\n l3 = gets.chomp\n grid = Grid.new([l1, l2, l3].join(\"\\n\"))\n puts grid.analyze()\nend\n\nsolve()", "lang_cluster": "Ruby", "tags": ["brute force", "implementation", "games"], "code_uid": "f4b546c73109ab2de4598e5beeb06352", "src_uid": "892680e26369325fb00d15543a96192c", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def winning(x)\n result = []\n 3.times do |i|\n if x[i][0] == x[i][1] && x[i][1] == x[i][2] then\n if x[i][0] == \"X\" then\n result << 1\n elsif x[i][0] == \"0\"\n# puts \"horiz\"\n result << 0\n end\n end\n if x[0][i] == x[1][i] && x[1][i] == x[2][i] then\n if x[0][i] == \"X\" then\n result << 1\n elsif x[0][i] == \"0\"\n# puts \"vert\"\n# p i \n result << 0\n end\n end\n end\n if x[0][0] == x[1][1] && x[1][1] == x[2][2] then\n if x[0][0] == \"X\" then\n result << 1\n elsif x[0][0] == \"0\"\n# puts \"main di\"\n result << 0\n end\n end\n if x[0][2] == x[1][1] && x[1][1] == x[2][0] then\n if x[0][2] == \"X\" then\n result << 1\n elsif x[0][2] == \"0\"\n# puts \"second di\"\n result << 0\n end\n end\n if result.size == 1 then\n return result[0]\n elsif result.size > 1 then\n t = true\n i = 1\n while i < result.size do\n if result[i] != result[i-1] then\n t = false\n end\n i += 1\n end\n if t then \n return result[0]\n else\n return \"illegal\"\n end\n else\n return false\n end\nend\n\nfield = []\nx = 0\no = 0\ndots = 0\n\n3.times do |i|\n s = gets.chomp\n# p s\n 3.times do |j|\n field[i] = s\n# p field[i]\n# p field[i][j]\n if field[i][j] == \"X\" then\n x += 1\n elsif field[i][j] == \"0\" then\n o += 1\n else\n dots += 1\n end\n end\nend\n\nif (x-o).abs > 1 || o > x then\n puts \"illegal\"\nelse\n t = true\n k = winning(field)\n if k == \"illegal\" then\n puts k\n t = false\n elsif k == 0 then\n if x > o then \n puts \"illegal\"\n else\n puts \"the second player won\"\n end\n t = false\n elsif k == 1 then\n if x == o then\n puts \"illegal\"\n else\n puts \"the first player won\"\n end\n t = false\n end\n if x == o && t && dots != 0 then\n puts \"first\"\n t = false\n elsif t && dots != 0 then\n puts \"second\"\n t = false\n end\n if !k && t then\n puts \"draw\"\n end\nend", "lang_cluster": "Ruby", "tags": ["brute force", "implementation", "games"], "code_uid": "4615e21eb55f89ccaf44e492bbcea96f", "src_uid": "892680e26369325fb00d15543a96192c", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "# 3C\n\ndef read_line\n gets.chomp.split('')\nend\n\ndef count(grid, p)\n grid.map { |line|\n line.count p\n }.inject(:+)\nend\n\ndef won?(grid, p)\n grid.any? { |line|\n line.count(p) == 3\n } || (0...3).any? { |i|\n grid[0][i] == p && grid[1][i] == p && grid[2][i] == p\n } || (grid[0][0] == p && grid[1][1] == p && grid[2][2] == p) ||\n (grid[0][2] == p && grid[1][1] == p && grid[2][0] == p)\nend\n\ndef has?(grid, p)\n grid.any? { |line|\n line.include? p\n }\nend\n\na = (0...3).map { read_line }\ndiff = count(a, 'X') - count(a, '0')\nunless diff == 1 || diff == 0\n puts 'illegal'\n exit\nend\nx_won, o_won = won?(a, 'X'), won?(a, '0')\nif x_won && o_won\n puts 'illegal'\n exit\nend\nif x_won\n puts(diff == 1 ? 'the first player won' : 'illegal')\n exit\nend\nif o_won\n puts(diff == 0 ? 'the second player won' : 'illegal')\n exit\nend\nif has?(a, '.')\n puts(diff == 0 ? 'first' : 'second')\nelse\n puts 'draw'\nend", "lang_cluster": "Ruby", "tags": ["brute force", "implementation", "games"], "code_uid": "abc820a024e49cdb60df6477bb4b18d3", "src_uid": "892680e26369325fb00d15543a96192c", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "$_=$<.map(&:chop)*?o\nputs [0,3,4,5].map{|n|~/(x#{t=?.*n}x#{t}\\.|x#{t}\\.#{t}x|\\.#{t}x#{t}x)/}.any?? :YES: :NO", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "f26b051a744a73b9ab48af17ffb9a89c", "src_uid": "ca4a77fe9718b8bd0b3cc3d956e22917", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "$_=$<.map{|s|s.chop+?o}*''\nputs [0,3,4,5].map{|n|~/(x.{#{n}}){2}\\./||~/x.{#{n}}\\..{#{n}}x/||~/\\.(.{#{n}}x){2}/}.any?? :YES: :NO", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "954186beb013d61e91abe19ef02f1bf5", "src_uid": "ca4a77fe9718b8bd0b3cc3d956e22917", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "$_=$<.map{|s|s.chop+?o}*''\nf=->n{~/x.{#{n}}x.{#{n}}\\./||~/x.{#{n}}\\..{#{n}}x/||~/\\..{#{n}}x.{#{n}}x/}\nputs f[0]||f[3]||f[4]||f[5]?:YES: :NO", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "8f00377b207c347b89aa7bf617f8d86b", "src_uid": "ca4a77fe9718b8bd0b3cc3d956e22917", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def fact(n)\n\treturn @dp[n] if @dp[n]\n\ti = 1\n\t(2..n).each do |a|\n\t\ti *= a\n\tend\n\t@dp[n] = i\n\ti\nend\n\ndef comb(n,r=2)\n\treturn 0 if n < r\n return 1 if n == r\n return n if r == 1\n return 1 if n == 0 \n # comb(n-1,r) + comb(n-1,r-1)\n # num = fact(n)\n # denom = fact(r) * fact(n-r)\n # num / denom\n \t(n * (n-1))/2\nend\n@dp = {}\nn,m = gets.split(\" \").map(&:to_i)\nmax = comb(n-m+1,2)\n\nq = n / m\nr = n % m\nmin = 1\nmin = (r * comb(q+1,2)) + ((m-r) * comb(q,2))\n\nputs \"#{min} #{max}\"", "lang_cluster": "Ruby", "tags": ["math", "greedy", "constructive algorithms", "combinatorics"], "code_uid": "c5c854ca5a240482455ad3a554359c81", "src_uid": "a081d400a5ce22899b91df38ba98eecc", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a=gets.chomp.split(\" \")\nn=a[0].to_i\nt=a[1].to_i\nmax=n-t+1\nmax=(max*(max-1))/2\ng=n/t\ng2=n%t\nt=t-g2\nmin=(g2*(g)*(g+1))/2+ (t*g*(g-1))/2\nputs \"#{min} #{max}\"", "lang_cluster": "Ruby", "tags": ["math", "greedy", "constructive algorithms", "combinatorics"], "code_uid": "b921a272b591c6a46b1384ab51ccf28f", "src_uid": "a081d400a5ce22899b91df38ba98eecc", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def pairs(r)\n\treturn (r*r-r)/2\nend\nn, m = STDIN.readline.split().map {|q| q.to_i}\nr = n - m + 1\nmod = n % m\ndiv = n / m\nmin = (m - mod) * pairs(div) + mod * pairs(div + 1)\nputs(min.to_s + \" \" + (pairs(r).to_s))\n\n\t", "lang_cluster": "Ruby", "tags": ["math", "greedy", "constructive algorithms", "combinatorics"], "code_uid": "bb605309ffe9f36f5d513967109eab92", "src_uid": "a081d400a5ce22899b91df38ba98eecc", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.to_i\n(p 1;exit)if n<10\nx=10**Math.log10(n).to_i\nn=(x-n)%x\np n<1 ? x : n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "33b9042e6ad0a9732f863f57a418d81d", "src_uid": "a3e15c0632e240a0ef6fe43a5ab3cc3e", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def scan;gets.split.map(&:to_i);end\ns = gets.chomp\nsn = s[0].succ + '0'*s[1..-1].size\np sn.to_i - s.to_i\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "8ea70eeff721179a404de41dbb6533ee", "src_uid": "a3e15c0632e240a0ef6fe43a5ab3cc3e", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.to_i\n(p 1;exit)if n<10\nx=10**Math.log10(n).to_i\np (x-n-1)%x+1", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "e68b7f51f19b09faa170569a2abff769", "src_uid": "a3e15c0632e240a0ef6fe43a5ab3cc3e", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/Users/mike/.rvm/rubies/ruby-1.9.3-p327/bin/ruby\n\nredNum, blueNum = STDIN.readline.split.collect {|s| s.to_i}\n\ndef msg s=''\n\t#puts s\nend\n\ndef simulate(red, redCount, blueCount, petyaMove)\n\tpetya, vasya = 0, 0\n\twhile redCount+blueCount > 0\n\t\tif petyaMove\n\t\t\tif red and redCount > 0\n\t\t\t\tredCount -= 1\n\t\t\t\tpetya += 1\n\t\t\telsif not red and blueCount > 0\n\t\t\t\tblueCount -= 1\n\t\t\t\tpetya += 1\n\t\t\telsif redCount > 0\n\t\t\t\tred = true\n\t\t\t\tredCount -= 1\n\t\t\t\tvasya += 1\n\t\t\telse\n\t\t\t\tred = false\n\t\t\t\tblueCount -= 1\n\t\t\t\tvasya += 1\n\t\t\tend\n\t\telse\n\t\t\tif red and blueCount > 0\n\t\t\t\tred = false\n\t\t\t\tblueCount -= 1\n\t\t\t\tvasya += 1\n\t\t\telsif not red and redCount > 0\n\t\t\t\tred = true\n\t\t\t\tredCount -= 1\n\t\t\t\tvasya += 1\n\t\t\telsif redCount > 0\n\t\t\t\tred = true\n\t\t\t\tredCount -= 1\n\t\t\t\tpetya += 1\n\t\t\telse\n\t\t\t\tred = false\n\t\t\t\tblueCount -= 1\n\t\t\t\tpetya += 1\n\t\t\tend\n\t\tend\n\t\tif red\n\t\t\tmsg 'red'\n\t\telse\n\t\t\tmsg 'blue'\n\t\tend\n\t\tpetyaMove = !petyaMove\n\tend\n\treturn [petya, vasya]\nend\n\nmsg 'red'\npetya0, vasya0 = simulate(true, redNum-1, blueNum, false)\nmsg\nmsg 'blue'\npetya1, vasya1 = simulate(false, redNum, blueNum-1, false)\nmsg\n\nif (petya0 > petya1)\n\tputs '%s %s' % [petya0, vasya0]\nelse (petya1 > petya0)\n\tputs '%s %s' % [petya1, vasya1]\nend\n", "lang_cluster": "Ruby", "tags": ["greedy", "implementation", "games"], "code_uid": "ba3a7ff9fc346e4edda6cd1e613e331d", "src_uid": "c8378e6fcaab30d15469a55419f38b39", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/Users/mike/.rvm/rubies/ruby-1.9.3-p327/bin/ruby\n\nredNum, blueNum = STDIN.readline.split.collect {|s| s.to_i}\n\ndef msg s=''\n\t#puts s\nend\n\ndef simulate(red, redCount, blueCount, petyaMove)\n\tpetya, vasya = 0, 0\n\twhile redCount+blueCount > 0\n\t\twasRed = red\n\t\tif petyaMove and red and redCount > 0\n\t\t\tred = true\n\t\telsif petyaMove and !red and blueCount > 0\n\t\t\tred = false\n\t\telsif !petyaMove and red and blueCount > 0\n\t\t\tred = false\n\t\telsif !petyaMove and !red and redCount > 0\n\t\t\tred = true\n\t\telsif redCount > 0\n\t\t\tred = true\n\t\telse\n\t\t\tred = false\n\t\tend\n\t\tif red\n\t\t\tredCount -= 1\n\t\t\tif wasRed\n\t\t\t\tpetya += 1\n\t\t\telse\n\t\t\t\tvasya += 1\n\t\t\tend\n\t\t\tmsg 'red'\n\t\telse\n\t\t\tblueCount -= 1\n\t\t\tif wasRed\n\t\t\t\tvasya += 1\n\t\t\telse\n\t\t\t\tpetya += 1\n\t\t\tend\n\t\t\tmsg 'blue'\n\t\tend\n\t\tpetyaMove = !petyaMove\n\tend\n\treturn [petya, vasya]\nend\n\nmsg 'red'\npetya0, vasya0 = simulate(true, redNum-1, blueNum, false)\nmsg\nmsg 'blue'\npetya1, vasya1 = simulate(false, redNum, blueNum-1, false)\nmsg\n\nif (petya0 > petya1)\n\tputs '%s %s' % [petya0, vasya0]\nelse (petya1 > petya0)\n\tputs '%s %s' % [petya1, vasya1]\nend\n", "lang_cluster": "Ruby", "tags": ["greedy", "implementation", "games"], "code_uid": "729433d128b8fa8de82f958fbb3d937d", "src_uid": "c8378e6fcaab30d15469a55419f38b39", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def max(x,y)\n if x > y then\n return x\n else\n return y\n end\nend\n\ndef min(x,y)\n if x < y then\n return x\n else\n return y\n end\nend\n\nst = gets.split\nred = st[0].to_i\nblue = st[1].to_i\npoints = []\n\nif red == blue then\n points << red - 1 << red\nelse\n points << max(red,blue) - 1 << min(red,blue)\nend\n\nresult = points.join(\" \")\nputs result", "lang_cluster": "Ruby", "tags": ["greedy", "implementation", "games"], "code_uid": "ab77c1230b5e8121944118263ec61006", "src_uid": "c8378e6fcaab30d15469a55419f38b39", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/ruby\nhash = {'9' => '0', '8' => '1','7' => '2','6' => '3','5' => '4'}\ninput_line = gets\nres = ''\ninput_line.each_char do |ch|\n if hash[ch].nil?\n res+=ch;\n else\n if (ch == '9' && res == '')\n res+=ch\n else\n res+=hash[ch]\n end\n end\nend\n\nputs res\n\n", "lang_cluster": "Ruby", "tags": ["greedy", "implementation"], "code_uid": "21801c6c405370a55dd4ce51eda4ec58", "src_uid": "d5de5052b4e9bbdb5359ac6e05a18b61", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "arr = gets.chomp.split(\"\")\narr.each_with_index do |item, index|\n print item.to_i <= 4 ? item : index.to_i == 0 && item.to_i == 9 ? item : 9 - item.to_i\nend\n", "lang_cluster": "Ruby", "tags": ["greedy", "implementation"], "code_uid": "ff742c32d37eaa315851d4346e41e3ad", "src_uid": "d5de5052b4e9bbdb5359ac6e05a18b61", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "x = gets.chomp.chars.map(&:to_i)\n\ntmp = x[0]\nx = x[1..-1]\n\ntmp = 9 - tmp if tmp > 4 and tmp < 9\n\nx = x.map { |i|\n if i > 4\n 9 - i\n else\n i\n end }\n\nputs ([tmp] + x).join(\"\")", "lang_cluster": "Ruby", "tags": ["greedy", "implementation"], "code_uid": "49c874911039380a54f56583a9a317b6", "src_uid": "d5de5052b4e9bbdb5359ac6e05a18b61", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, d = gets.split.map(&:to_i)\na = gets.split.map(&:to_i).sort\nm = gets.to_i\n\nprofit = 0\n\nm.times { a << -d }\nm.times { |i| profit += a[i] }\n\nputs profit", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "5f1120b673e96e21ad26323b5dc545ed", "src_uid": "5c21e2dd658825580522af525142397d", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def run\n n, d = $stdin.gets.split.map(&:to_i)\n a = $stdin.gets.split.map(&:to_i).sort\n m = $stdin.gets.to_i\n\n sum = a[0, [n, m].min].reduce(0) {|x, sum| sum + x}\n sum -= (m - n) * d if m >= n\n puts sum\nend\n\nrun if $0 == __FILE__\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "162c2f02d508514fdb79c6c774387ad1", "src_uid": "5c21e2dd658825580522af525142397d", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, pnlt = gets.split(\" \").map{|s| s.to_i}\ncost = gets.split(\" \").map{|s| s.to_i}\nm = gets.to_i\nret = 0\ncost = cost.sort()\nif (m<=n) \n\tm.times {|i| ret += cost[i]}\nelse\n\tn.times {|i| ret += cost[i]}\n\tret -= (m-n)*pnlt\nend\nputs ret", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "9f05bc7f8d81a0aebd3b96e25edd30b7", "src_uid": "5c21e2dd658825580522af525142397d", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a, b, c = gets.split(' ').map(&:to_i)\n\nputs [a+b+c, 2*a+2*b, 2*a+2*c, 2*b+2*c].min\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "c067d4ea460185163fb7a8e814eeeeca", "src_uid": "26cd7954a21866dbb2824d725473673e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b,c = gets.split.map(&:to_i)\nx = [a,b].min\ny = [a,b].max\nputs x + [a + b,c].min + [y,x + c].min", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "246af56943fdef23f83ec75c8833a63a", "src_uid": "26cd7954a21866dbb2824d725473673e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a=gets.chomp.split(\" \")\n0.upto(2){|i| a[i]=a[i].to_i}\na.sort!\nk=(a[0]*2+a[1]*2)\nl=0\na.each{|i| l=l+i }\nif l>k\n\tputs k\nelse\n puts l\nend", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "cf0ba54afe36cde255506c3ff4b8af75", "src_uid": "26cd7954a21866dbb2824d725473673e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def delegate_boxes\n n, m, a, b = gets.split.map(&:to_i)\n l = n % m\n return 0 if l == 0\n\n if n < m\n return min(n * b, (m - n) * a)\n end\n\n min(l * b, (m - l) * a)\nend\n\ndef min(a, b)\n a <= b ? a : b\nend\n\nputs delegate_boxes", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "12e12bb756791b545ee3d82d2ca69ac3", "src_uid": "c05d753b35545176ad468b99ff13aa39", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, m, a, b = gets.strip.split.map(&:to_i)\ntd = n % m\ntb = m - td\nputs [td*b, tb*a].min", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "4014670f7ba2b6ad82b6413b9998c177", "src_uid": "c05d753b35545176ad468b99ff13aa39", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, m, a, b = gets.split.map &:to_i\nx = [n / m - 1, 0].max\nans = Float::INFINITY\nx.upto(x + 2) do |i|\n ans = [ans, i * m < n ? (n - i * m) * b : (i * m - n) * a].min\nend\nputs ans\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "1ba209b9b7a96463b0271187ce177359", "src_uid": "c05d753b35545176ad468b99ff13aa39", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, m, k = gets.strip.split.map(&:to_i)\npos = k.odd? ? \"L\" : \"R\"\ncol_sum = m * 2\nmod = k % col_sum\ndiv = k / col_sum\nmod += 1 if k.odd?\ndesk = (mod / 2).ceil\ndesk = m if mod == 0\nlane = div + (mod > 0 ? 1 : 0)\nputs \"#{lane} #{desk} #{pos}\"\n", "lang_cluster": "Ruby", "tags": ["math", "constructive algorithms"], "code_uid": "bd237cfcfd70ab5b1c9658b0560ac1f6", "src_uid": "d6929926b44c2d5b1a8e6b7f965ca1bb", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "N, S = gets.split(\" \").map(&:to_i)\nlb, ub = 0, N + 1\nuntil lb + 1 == ub do\n mid = lb + ub >> 1\n mid - mid.to_s.chars.map(&:to_i).reduce(:+) >= S ? ub = mid : lb = mid\nend\nputs N - ub + 1\n", "lang_cluster": "Ruby", "tags": ["brute force", "math", "dp", "binary search"], "code_uid": "a6cfacccfc9f43729a6f40f70fac76c7", "src_uid": "9704e2ac6a158d5ced8fd1dc1edb356b", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "375e5e75151bfd3067cdbd5b4525aa89", "src_uid": "e4b3a2707ba080b93a152f4e6e983973", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "gets\na = []\nc = 0\ngets.strip.split('').each do |x|\n if x == 'B'\n c += 1\n else\n a << c if c > 0\n c = 0\n end\nend\na << c if c > 0\nputs(a.size, a.join(' '))\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "3f0abf9cd8bebf224ed878791212bfb6", "src_uid": "e4b3a2707ba080b93a152f4e6e983973", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.strip.to_i\ns = gets.strip\nans = []\nprev = ''\ncount = prev == 'B' ? 1 : 0\n(0...n).each do |i|\n curr = s[i]\n if (curr == prev && curr == 'B') || (curr != prev && curr == 'B')\n count += 1\n else\n ans << count if count > 0\n count = curr == 'B' ? 1 : 0\n end\n prev = curr\nend\nans << count if count > 0\nputs ans.length\nputs ans.join(\" \") if ans.length > 0\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "7e7ba742ee0e66b0aa2442870236ce02", "src_uid": "e4b3a2707ba080b93a152f4e6e983973", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "input=gets.chomp.to_i\nif input>5 && input%2==0\nputs (input-2)/4\nelsif input>5 && input%2==1\nputs 0\nelse\nputs 0\nend", "lang_cluster": "Ruby", "tags": ["math", "combinatorics"], "code_uid": "46df9729e96a7b537c96469f35175688", "src_uid": "32b59d23f71800bc29da74a3fe2e2b37", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\nputs (n.odd? || n <= 5) ? 0 : (n / 4 - ((n / 2).even? ? 1 : 0))\n", "lang_cluster": "Ruby", "tags": ["math", "combinatorics"], "code_uid": "a9cb88315777c2b8020d7af0d2d84651", "src_uid": "32b59d23f71800bc29da74a3fe2e2b37", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.to_i\nif n%2==1 then\n\tputs 0\nelse\n\tn=n/2\n\tans=n/2-(1-n%2)\n\tans=0 if ans<0\n\tputs ans\nend\n\n", "lang_cluster": "Ruby", "tags": ["math", "combinatorics"], "code_uid": "2a3d1dc43e052b38887084ef4222a5cb", "src_uid": "32b59d23f71800bc29da74a3fe2e2b37", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "I=gets(p).split.map &:to_i\n[*1..9].permutation(4){|a,b,c,d|(puts\"%d %d\\n%d %d\"%[a,b,c,d];exit)if[a+b,c+d,a+c,b+d,a+d,b+c]==I}\np -1\n", "lang_cluster": "Ruby", "tags": ["brute force", "math"], "code_uid": "9096cfb9c032845948579915bbb1c81d", "src_uid": "6821f502f5b6ec95c505e5dd8f3cd5d3", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "I=gets(p).split.map &:to_i\n[*1..9].permutation(4){|a,b,c,d|(puts\"%d %d\\n%d %d\"%[a,b,c,d];exit)if[a+b,c+d,a+c,b+d,a+d,b+c]==I}\np -1", "lang_cluster": "Ruby", "tags": ["brute force", "math"], "code_uid": "20f9a1ea0c5ee1e5fc416fae4368f7fd", "src_uid": "6821f502f5b6ec95c505e5dd8f3cd5d3", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["brute force", "math"], "code_uid": "7ee78281c4e322bac2aa219872a1c547", "src_uid": "6821f502f5b6ec95c505e5dd8f3cd5d3", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "require 'matrix'\n\na1, b1, c1 = gets.split.map { |v| v.to_i }\na2, b2, c2 = gets.split.map { |v| v.to_i }\na3,b3,c3=0,0,0\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", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "515ccdc4c658f2735531e5da31a25fbf", "src_uid": "c8e869cb17550e888733551c749f2e1a", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def num_solutions(a1, b1, c1, a2, b2, c2)\n if a2 == 0 and b2 == 0\n if c2 != 0\n return 0\n else\n if a1 == 0 and b1 == 0\n return (c1 == 0 ? -1 : 0)\n else\n return -1\n end\n end\n end\n det = a1*b2-a2*b1\n return 1 if det != 0\n det2 = a1*c2-a2*c1\n det3 = b1*c2-b2*c1\n return ((det2 == 0 and det3 == 0) ? -1 : 0)\nend\n\na1, b1, c1 = gets.split.map(&:to_i)\na2, b2, c2 = gets.split.map(&:to_i)\n\nif a1 == 0 and b1 == 0\n a1, b1, c1, a2, b2, c2 = a2, b2, c2, a1, b1, c1\nend\n\nputs num_solutions(a1, b1, c1, a2, b2, c2)\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "dd454808ba99222299dcec9b0efdb89a", "src_uid": "c8e869cb17550e888733551c749f2e1a", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "gets=~/\\D/\nn=$`.to_i-1\np n/4*16+n%2*7+\" fedabc\".index($&)", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "bff80132c58e6e5be3a4dc6b8352e803", "src_uid": "069d0cb9b7c798a81007fb5b63fa0f45", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.chomp.to_s\nr = n[-1]\nx = n.to_i\n\nif(r=='f')\n ans=1\nend\nif(r=='e')\n ans=2\nend\nif(r=='d')\n ans=3\nend\nif(r=='a')\n ans=4\nend\nif(r=='b')\n ans=5\nend\nif(r=='c')\n ans=6\nend\n\nf = (x-1)/4\nans+=f*16\nf = x%4\nif(f==2 || f==0)\n ans+=7\nend\np ans", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "686bed6349f68ebc32e7f79596028360", "src_uid": "069d0cb9b7c798a81007fb5b63fa0f45", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a = gets.chomp\nn = a[0..-2].to_i - 1\nans = 0\nans += (4 + 2 * 6) * (n / 4)\nn %= 4\nans += 6 + 1 if n == 1 || n == 3 \nans += 'xfedabc'.index(a[-1])\nputs ans\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "a560944aa66cb657c4ec8e156d4695bd", "src_uid": "069d0cb9b7c798a81007fb5b63fa0f45", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def ab a, b\n result = []\n cant_do_it = false\n while a < b\n result << b\n if b % 2 == 0\n b /= 2\n elsif b % 10 == 1\n b = (b - 1) / 10\n else\n cant_do_it = true\n break\n end\n end\n result << a if a == b\n result unless cant_do_it || a != b\nend\n\ndef ab_print(a, b)\n result = ab(a, b)\n if result.nil?\n puts \"NO\"\n else\n puts \"YES\"\n puts result.size\n puts(result.reverse*' ')\n end\nend\n\n# ab_print(2, 162)\n# ab_print(4, 42)\n# ab_print(100, 40021)\na, b = gets.chomp.split(/\\s+/, 2).map {|x| x.to_i}\nab_print(a, b)\n", "lang_cluster": "Ruby", "tags": ["dfs and similar", "math", "brute force"], "code_uid": "6e426ba9430eb77aac87d750771b5135", "src_uid": "fc3adb1a9a7f1122b567b4d8afd7b3f3", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b=gets.split.map(&:to_i)\nprev={a=>nil}\nq=[a]\nwhile !q.empty?\n\tcur=q.shift\n\t[cur*10+1,cur*2].each{|e|\n\t\tnext if e>b\n\t\tif !prev.has_key?(e)\n\t\t\tprev[e]=cur\n\t\t\tq< a do\n\ts << b\n\tif b % 2 == 0 then\n\t\tb /= 2\n\telsif b % 10 == 1 then \n\t\tb /= 10\n\telse\n\t\tbreak\n\tend\nend\nif b == a then\n\ts << b\n\tputs 'YES'\n\tputs s.size\n\tputs (s.reverse.map &:to_s) * ' '\nelsif \n\tputs 'NO'\nend\n", "lang_cluster": "Ruby", "tags": ["dfs and similar", "math", "brute force"], "code_uid": "196bd0bb61a489a70cecf8bc02edb0d2", "src_uid": "fc3adb1a9a7f1122b567b4d8afd7b3f3", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "x, y, n = gets.split(' ').collect!{|i| i.to_i}\n\n\nk = x.to_f/y\n# p k\na = 0\nb = 0\nmin = 100000\n\n(1..n).each do |i|\n\tj = k*i\n\t\n\tif j - j.to_i > 0.5\n\t\tj = j.round.to_i\n\telse\n\t\tj = j.to_i\n\tend\n\n\tcur = (k - j/i.to_f).abs\n\t# p j if j == 38236\n\t# p i if j == 38236\n\t# p j/i.to_f if j == 38236\n\tif cur < min\n\t\ta = j\n\t\tb = i\n\t\tmin = cur\n\tend\nend\n\nprint a, \"/\", b\n", "lang_cluster": "Ruby", "tags": ["two pointers", "implementation", "brute force"], "code_uid": "c56cfb26603d43c12b12de074919eab5", "src_uid": "827bc6f120aff6a6f04271bc84e863ee", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/ruby1.9\n\nx, y, n = STDIN.readline.split.collect {|s| s.to_i }\n\nbest_diff = x\nbest_a = -1\nbest_b = -1\n\n(1..n).each do |b|\n\ta = (x*b)/y\n\ta += 1 if (x*b)%y > y/2\n\tdiff = ((x*b - a*y)*1.0/(y*b)).abs\n\tif diff < best_diff\n\t\tbest_diff = diff\n\t\tbest_a = a\n\t\tbest_b = b\n\tend\nend\n\nputs '%d/%d' % [best_a, best_b]\n\n", "lang_cluster": "Ruby", "tags": ["two pointers", "implementation", "brute force"], "code_uid": "d15b540300d412ef958c2d3374c4b3eb", "src_uid": "827bc6f120aff6a6f04271bc84e863ee", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["two pointers", "implementation", "brute force"], "code_uid": "4b9c26a70916b73e1dfee223aa003957", "src_uid": "827bc6f120aff6a6f04271bc84e863ee", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "x,y,n = gets.split(' ').map{ |e| e.to_i }\na = x\nb = y\n\n\tz = x.to_f / y\n\tmin_diff = nil\n\t(1..n).each do |i|\n\t\taa = -((-i.to_f * x / y - 0.5).floor) - 1\n\t\tdiff = (aa.to_f / i - z).abs\n\t\tif (!min_diff || min_diff > diff)\n\t\t\tmin_diff = diff\n\t\t\ta = aa\n\t\t\tb = i\n\t\tend\n\t\tif min_diff == 0\n\t\t\tbreak\n\t\tend\n\tend\n\t\t\n\nputs \"#{a}/#{b}\"\n\n\n", "lang_cluster": "Ruby", "tags": ["two pointers", "implementation", "brute force"], "code_uid": "a3d16085f3a359789adae1f65b456e7b", "src_uid": "827bc6f120aff6a6f04271bc84e863ee", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "x,y,n = gets.split(\" \").map(&:to_i)\n# if y < n\n# \tputs \"#{x}/#{y}\"\n# else\n\tmin_diff = n\n\tgiven_div = x/y.to_f\n\tval1 = nil\n\tval2 = nil\n\tn.downto(0) do |b|\n\t\ta1 = (given_div * b).floor\n\t\ta2 = a1 + 1\n\t\t# puts \"a #{a} b #{b} #{div} #{min_diff}\"\n\t\t[a1,a2].each do |a|\n\t\t\tdiv = (a/b.to_f)\n\t\t\tdiff = (given_div - div).abs.round(15)\n\t\t\tif diff < min_diff || (diff == min_diff && a < val1)\n\t\t\t\t# puts \"#{a} #{b} #{(given_div - div).abs} #{min_diff}\"\n\t\t\t\tval1 = a\n\t\t\t\tval2 = b\n\t\t\t\tmin_diff = diff\n\t\t\tend\n\t\tend\n\tend \n\n\tputs \"#{val1}/#{val2}\"\n# end", "lang_cluster": "Ruby", "tags": ["two pointers", "implementation", "brute force"], "code_uid": "cf5e24bf8ec72cc2ecf569272ec2497b", "src_uid": "827bc6f120aff6a6f04271bc84e863ee", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\na = gets.strip.split.map{|s| s.to_i}\n\nx = a.select{|i| i == 200}.length\ny = a.length - x\n\nox = x % 2\noy1 = y % 2\noy2 = ([y,1].max - 2) % 2\n\nverdict = (1 - oy1)**(1 - ox) * (1 - oy2)**ox\n\nputs \"YES\" if verdict == 1\nputs \"NO\" if verdict == 0", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "f5e3292de1a42669a277796900b632bd", "src_uid": "9679acef82356004e47b1118f8fc836a", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets().to_i\nline=gets().split(\" \")\nc100=0\nc200=0\nfor i in 0...line.size\n c100+=1 if line[i].to_i==100\n c200+=1 if line[i].to_i==200\nend\nif c100%2==0 and c100>=2 or c200%2==0 and c100%2==0\n puts \"YES\"\nelse\n puts \"NO\"\nend", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "b572bb76bb4822660cb21937872a839f", "src_uid": "9679acef82356004e47b1118f8fc836a", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\n\nx = 0\ny = 0\na.each { |z| z==200 ? x+=1 : y+=1 }\nx+=1 if x%2==1 && y>1\nx = x%2 + y%2\n\nputs x==0 ? \"YES\" : \"NO\"\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "3116aba7286364dbd34b8a51b54e323a", "src_uid": "9679acef82356004e47b1118f8fc836a", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.chomp.to_i\nputs n % 2 == 0 ? 2 : 1", "lang_cluster": "Ruby", "tags": ["math", "games"], "code_uid": "69e1e1adf48800b1574b587bf3eae8e7", "src_uid": "816ec4cd9736f3113333ef05405b8e81", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "p 2-gets.to_i%2", "lang_cluster": "Ruby", "tags": ["math", "games"], "code_uid": "04e653a1bbee71c8cff2a8399e6f2c2f", "src_uid": "816ec4cd9736f3113333ef05405b8e81", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "p 2-gets.to_i%2\n", "lang_cluster": "Ruby", "tags": ["math", "games"], "code_uid": "fa972709bafe1abae4d6dbf381b2723d", "src_uid": "816ec4cd9736f3113333ef05405b8e81", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "c, d = gets.split.map {|x| Integer x}\nn, m = gets.split.map {|x| Integer x}\nk = Integer gets\na = n * m - k\nputs [[a / n * c + (a % n) * d, a * d, (a + n - 1) / n * c].min, 0].max\n", "lang_cluster": "Ruby", "tags": ["math", "dp", "implementation"], "code_uid": "999239116f99e9ee0545a7587434bf3a", "src_uid": "c6ec932b852e0e8c30c822a226ef7bcb", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "c, d = gets.split.map {|x| Integer x}\nn, m = gets.split.map {|x| Integer x}\nk = Integer gets\na = n * m - k\nputs [[a / n * c + (a % n) * d, a * d, (a + n - 1) / n * c].min, 0].max\n", "lang_cluster": "Ruby", "tags": ["math", "dp", "implementation"], "code_uid": "32452b7d4917d83fd350ee8546401f21", "src_uid": "c6ec932b852e0e8c30c822a226ef7bcb", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "c, d = gets.split.map {|x| Integer x}\nn, m = gets.split.map {|x| Integer x}\nk = Integer gets\na = n * m - k\nputs [[a / n * c + (a % n) * d, a * d, (a + n - 1) / n * c].min, 0].max\n", "lang_cluster": "Ruby", "tags": ["math", "dp", "implementation"], "code_uid": "65c1231252969d651ae98281e073f40d", "src_uid": "c6ec932b852e0e8c30c822a226ef7bcb", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a = 3.times.map { |_| gets.to_i }\np (case a.zip([1, 1, 1]).map { |x, y| x * y }\n when [1, a[1], 1]\n a[0] + a[1] + a[2]\n when [1, a[1], a[2]]\n (a[0] + a[1]) * a[2]\n when [a[0], a[1], 1]\n a[0] * (a[1] + a[2])\n when [a[0], 1, a[2]]\n ([a[0], a[2]].min + 1) * [a[0], a[2]].max\n else\n a[0] * a[1] * a[2]\n end)", "lang_cluster": "Ruby", "tags": ["brute force", "math"], "code_uid": "e543a71408acd522f39f4c2d84250230", "src_uid": "1cad9e4797ca2d80a12276b5a790ef27", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a = gets.chomp.to_i\nb = gets.chomp.to_i\nc = gets.chomp.to_i\narray = []\narray << (a + ( b * c ))\narray << (a * ( b + c ))\narray << (a * b * c)\narray << (( a + b ) * c)\narray << a + b + c\n\nputs array.max\n", "lang_cluster": "Ruby", "tags": ["brute force", "math"], "code_uid": "d04495c22bf1769bd9841ab74b55d330", "src_uid": "1cad9e4797ca2d80a12276b5a790ef27", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b,c=$<.map &:to_i;p [a+b+c,(a+b)*c,a*(b+c),a*b*c].max\n", "lang_cluster": "Ruby", "tags": ["brute force", "math"], "code_uid": "cb676e612be57980c5af9c711793068f", "src_uid": "1cad9e4797ca2d80a12276b5a790ef27", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "gets\nr=0;gets.split.map(&:to_i).sort.each_slice(2){|x,y|r+=y-x};p r", "lang_cluster": "Ruby", "tags": ["sortings"], "code_uid": "575bd04234f5f57c2fbde571949076cf", "src_uid": "55485fe203a114374f0aae93006278d3", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\nas = gets.split.map(&:to_i).sort\nans = 0\n(0..(n/2-1)).each do |i|\n ans += (as[2*i] - as[2*i+1]).abs\nend\nputs ans\n", "lang_cluster": "Ruby", "tags": ["sortings"], "code_uid": "2dd3709ab8609d6a2b0a8f02e4e941df", "src_uid": "55485fe203a114374f0aae93006278d3", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\narr = gets.split.map(&:to_i).sort\nres = 0\narr.each_slice(2) do |slice|\n res += slice[1] - slice[0]\nend\nputs res", "lang_cluster": "Ruby", "tags": ["sortings"], "code_uid": "654fb3904af3a2702141d6f11235cc5b", "src_uid": "55485fe203a114374f0aae93006278d3", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "N = gets.to_i\nx = gets.split.map(&:to_i).inject(:+)\ny = gets.split.map(&:to_i).inject(:+)\nputs x >= y ? 'Yes' : 'No'", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "364784b179f47fc4fcdd6587ce2a0607", "src_uid": "e0ddac5c6d3671070860dda10d50c28a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\nxs = gets.split.map(&:to_i)\nys = gets.split.map(&:to_i)\nputs xs.inject(:+) >= ys.inject(:+) ? 'Yes' : 'No'", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "fbbc8de66bfe38271ea0548ba7386dfe", "src_uid": "e0ddac5c6d3671070860dda10d50c28a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "ebe16b984e6c2f8277eb7b32d0c9809b", "src_uid": "e0ddac5c6d3671070860dda10d50c28a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "\narr = gets.split.map(&:reverse).sort\nSTDERR.puts \"#{arr}\"\nset = arr.uniq\nif set.size == 1\n\t# \u5df2\u7ecf\u662fkoutsu\n\tputs 0\n\texit\nelsif set.size == 2\n\t# \u6709\u91cd\u590d\uff0c\u518d\u6478\u724c\u5c31\u53ef\u51d1\u9f50\u523b\u5b50\n\tputs 1\n\texit\nend\nif arr[0].succ == arr[1] && arr[1].succ == arr[2]\n\t# \u5df2\u7ecf\u662fshuntsu\n\tputs 0\n\texit\nend\nfor k in 0..1\n\tif arr[k][0] == arr[k+1][0]\t\n\t\t# \u82b1\u8272\u76f8\u540c\u624d\u6709\u53ef\u80fd\u51d1\u987a\u5b50\uff1b\u7531\u4e8earr\u6392\u5e8f\u8fc7\uff0c\u82b1\u8272\u76f8\u540c\u7684\u724c\u76f8\u90bb\n\t\tif arr[k+1][1].to_i - arr[k][1].to_i <= 2\n\t\t\t# \u82b1\u8272\u76f8\u540c\u7684\u724c\u82e5\u5dee\u503c\u5c0f\u4e8e\u7b49\u4e8e2\uff0c\u53ef\u4ee5\u6478\u724c\u51d1\u987a\u5b50\n\t\t\tputs 1\n\t\t\texit\n\t\tend\n\tend\nend\nputs 2\n# \u4e0d\u5c5e\u4e8e\u4ee5\u4e0a\u60c5\u51b5\uff0c\u5c31\u5fc5\u987b\u6478\u4e24\u6b21\u724c\u624d\u53ef\u4ee5\u51d1\u9f50\u523b\u6216\u987a\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "a7cf7202687d6905916ee9b8c441205f", "src_uid": "7e42cebc670e76ace967e01021f752d3", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def neighbor(a,b)\n return (a[1].to_i - b[1].to_i).abs == 1 && a[0] == b[0]\nend\ndef neighbor2(a,b)\n return (a[1].to_i - b[1].to_i).abs == 2 && a[0] == b[0]\nend\n\nt = gets.split\nt.each do |s|\n s.reverse!\nend\nt.sort!\n\nif t[0] == t[1] && t[1] == t[2]\n p 0\nelsif neighbor(t[0],t[1]) && neighbor(t[1],t[2])\n p 0\nelsif t[0] == t[1] || t[1] == t[2]\n p 1\nelsif neighbor(t[0],t[1]) || neighbor(t[1],t[2])\n p 1\nelsif neighbor2(t[0],t[1]) || neighbor2(t[0],t[2]) || neighbor2(t[1],t[2])\n p 1\nelse\n p 2\nend\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "8abf75a00937b8c2a656b4ab51ae7a3e", "src_uid": "7e42cebc670e76ace967e01021f752d3", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "5ca86c88e3aef53e8caf11858eaed592", "src_uid": "7e42cebc670e76ace967e01021f752d3", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["brute force"], "code_uid": "48692b47f3269636cfe27fdd4d69e767", "src_uid": "a8da7cbd9ddaec8e0468c6cce884e7a2", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, k = $stdin.read.split.map(&:to_i)\n@pow = []\n# puts n\n# puts k\n(n + 1).times do |i|\n\t@pow << 2**(i-1)\nend\n# puts @pow\ndef find(n, k)\n\t# puts \"observing #{n} #{k}\"\n\tif (n == 1)\n\t\traise \"#{k}\" unless k == 1\n\t\treturn [1]\n\tend\n\tif @pow[n - 1] >= k\n\t\tres = find(n - 1, k)\n\t\t[1] + res.map{|i| i + 1}\n\telse\n\t\tres = find(n - 1, k - @pow[n - 1])\n\t\tres.map{|i| i + 1} + [1]\n\tend\nend\n\nputs find(n, k).join(\" \")", "lang_cluster": "Ruby", "tags": ["math", "divide and conquer", "bitmasks"], "code_uid": "a4a50bbf380ba6282ecb45c99bae3a9e", "src_uid": "a8da7cbd9ddaec8e0468c6cce884e7a2", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/ruby\n# coding: utf-8\n\nn, m = gets.split.map &:to_i\ndef f(n, i, m)\n if i == n\n return i.to_s\n elsif m > 2 ** (n - i - 1)\n return f(n, i + 1, m - 2 ** (n - i - 1)) + ' ' + i.to_s\n else\n return i.to_s + ' ' + f(n, i + 1, m)\n end\nend\nputs f(n, 1, m)", "lang_cluster": "Ruby", "tags": ["math", "divide and conquer", "bitmasks"], "code_uid": "5c0943d0918f63ab6f39ed2129d6ba26", "src_uid": "a8da7cbd9ddaec8e0468c6cce884e7a2", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,k=gets.split.map(&:to_i)\np (1..9).find{|i|n*i%10==k||n*i%10==0}", "lang_cluster": "Ruby", "tags": ["brute force", "math", "constructive algorithms", "implementation"], "code_uid": "5ddea7a146786ce43ae82bd8493fdb69", "src_uid": "18cd1cd809df4744bb7bcd7cad94e2d3", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "k,r = gets.split.map(&:to_i)\n1.upto(10) do |n|\t\n\tif (k * n) % 10 == 0 or (k * n) % 10 == r\t\t\n\t\tputs n\t\n\t\tbreak\n\tend\nend\n", "lang_cluster": "Ruby", "tags": ["brute force", "math", "constructive algorithms", "implementation"], "code_uid": "07fec2b5eaa7fad955d5e258615d6442", "src_uid": "18cd1cd809df4744bb7bcd7cad94e2d3", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "# 3\nkr = gets.chomp\nkr = kr.split\nk = kr[0].to_i\nr = kr[1].to_i\n\ni = 1\nwhile i > 0\n\tif ((i*k) - r) % 10 == 0 || (i*k) % 10 == 0\n\t\tprint i\n\t\tbreak\n\tend\n\ti+= 1\nend", "lang_cluster": "Ruby", "tags": ["brute force", "math", "constructive algorithms", "implementation"], "code_uid": "ff5daaadf26e978d8228290597f123e2", "src_uid": "18cd1cd809df4744bb7bcd7cad94e2d3", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def dp(idx , bool)\n if idx == $n\n\treturn 0\n end\n ret = $mem[bool][idx]\n if ret != -100000\n\treturn ret\n end\n if bool == 1\n\tret = [dp(idx+1,1)+$number[idx],0].max \n else\n\tret = [dp(idx+1,0),dp(idx+1,1)+$number[idx]].max\n end\n $mem[bool][idx] = ret\n return ret\nend\n\n$n = gets.to_i\n$mem = Array.new(2){Array.new($n,-100000)}\n$number = gets.split.collect {|element| element.to_i}\nsum = 0\n$number.each{|x| sum += (x==1?1:0)}\nfor i in 0...$n do\n $number[i] = ($number[i]==1?-1:1)\nend\nif sum == $n\n puts sum-1\nelse\n puts \"#{sum+dp(0,0)}\"\nend", "lang_cluster": "Ruby", "tags": ["brute force", "dp", "implementation"], "code_uid": "7a40d8ffed2a88b2b98383b33c19ffd9", "src_uid": "9b543e07e805fe1dd8fa869d5d7c8b99", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "N = Integer(gets)\n\nstr = gets\nnums = str.split.map! {|a| Integer(a)}\ntotal = 0\nfor i in 0...nums.length\n total += nums[i]\nend\n\ndp = Array.new\ncount = Array.new\n\ndp.push(1 - nums[0])\ncount.push(nums[0])\nfor i in 1...nums.length\n dp.push([count[i-1], dp[i-1]].max + 1 - nums[i])\n count.push(count[i-1] + nums[i])\nend\n\nans = 0\nfor i in 0...nums.length\n if ans < total - count[i] + dp[i]\n ans = total - count[i] + dp[i]\n end\nend\n\nputs ans\n", "lang_cluster": "Ruby", "tags": ["brute force", "dp", "implementation"], "code_uid": "faca900846ffddfe576c09539468d06b", "src_uid": "9b543e07e805fe1dd8fa869d5d7c8b99", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = Integer(gets)\ninput = gets.chomp\nnums = input.split\nnumber = Array.new\nnumber1 = Array.new\n\nfor i in 0...n\n number[i] = number1[i] = Integer(nums[i])\nend\n\n\ndef sum(a)\n x = 0\n for i in 0...a.length\n x += a[i]\n end\n return x\nend\ndef restore(number1,number)\n for i in 0...number.length\n number1[i] = number[i]\n end\nend\n\nc = 0\nfor i in 0...n\n for j in i...n\n for x in i..j\n if number[x] == 1\n number1[x] = 0\n else\n number1[x] = 1\n end\n end\n if sum(number1) > c\n c = sum(number1)\n end\n restore(number1,number)\n end\nend\nif sum(number) == n\n puts n - 1\nelse\n\n if c > sum(number)\n puts c\n else\n puts sum(number)\n end\nend\n", "lang_cluster": "Ruby", "tags": ["brute force", "dp", "implementation"], "code_uid": "f708b41a54840358fbd556b0f9635b93", "src_uid": "9b543e07e805fe1dd8fa869d5d7c8b99", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b,c = gets.split.map(&:to_i)\nk = [a,b].min\np 2*c + [a,b].min*2 + (a > k ? 1 : 0) + (b > k ? 1 : 0)\n", "lang_cluster": "Ruby", "tags": ["greedy"], "code_uid": "bebce47ef74bbf1edcbaff2d5bad9b1d", "src_uid": "609f131325c13213aedcf8d55fc3ed77", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a, b, c = gets.split.map(&:to_i)\nif a == b\n puts a + b + c * 2\nelse\n puts [a, b].min * 2 + 1 + c * 2\nend", "lang_cluster": "Ruby", "tags": ["greedy"], "code_uid": "f65296d6d3438619ae2dbd3368380a0d", "src_uid": "609f131325c13213aedcf8d55fc3ed77", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a, b, c = gets.split.map(&:to_i)\nputs c * 2 + [a, b].min * 2 + (a != b ? 1 : 0)\n", "lang_cluster": "Ruby", "tags": ["greedy"], "code_uid": "85ba6c1d66776cff3492b36e3f40ac43", "src_uid": "609f131325c13213aedcf8d55fc3ed77", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\nans = 2*n-1\n(n-1).times do |i|\n ans += (i*2+1)*2\nend\np ans", "lang_cluster": "Ruby", "tags": ["math", "dp", "implementation"], "code_uid": "24d56dd262039e29bde826bbd31d8af3", "src_uid": "758d342c1badde6d0b4db81285be780c", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.chomp.to_i\n\ndef solve(n)\n dp = [0] * (n + 1)\n dp[1] = 1\n for i in 2...n+1 do\n dp[i] = dp[i-1] + 4*(i-1)\n end\n return dp[n]\nend\n\nputs solve(n)\n", "lang_cluster": "Ruby", "tags": ["math", "dp", "implementation"], "code_uid": "13324dd85b6d0c480c712c4842253647", "src_uid": "758d342c1badde6d0b4db81285be780c", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\nn = gets.to_i\n\nputs n*n*2 - (2*n - 1)", "lang_cluster": "Ruby", "tags": ["math", "dp", "implementation"], "code_uid": "ef1271e708e9f5f6bc76121e1396d51a", "src_uid": "758d342c1badde6d0b4db81285be780c", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "64ab19c88e01226b9fc216297ea3131a", "src_uid": "fa1ef5f9bceeb7266cc597ba8f2161cb", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "8fff3b9561bc80bb3ef832474449b7db", "src_uid": "fa1ef5f9bceeb7266cc597ba8f2161cb", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "dabaa4fcff16af2be8f1f9beec2f79da", "src_uid": "fa1ef5f9bceeb7266cc597ba8f2161cb", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "8d24c8c0fdc1ece8fcbc7ed3172d54d6", "src_uid": "ed1a2ae733121af6486568e528fe2d84", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.to_i\nif n%2==1\nputs 0\nelse\nputs 2**(n/2)\nend\n", "lang_cluster": "Ruby", "tags": ["math", "dp"], "code_uid": "d55a37e0911a3ea5d5306fc38db5dfc1", "src_uid": "4b7ff467ed5907e32fd529fb39b708db", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.to_i\nif n.odd?\n p 0\nelse\n p 2**(n/2)\nend\n", "lang_cluster": "Ruby", "tags": ["math", "dp"], "code_uid": "ce139bf65e1eed2f1e821a568d0b9986", "src_uid": "4b7ff467ed5907e32fd529fb39b708db", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.chomp!.to_i\n\nputs (n < 2 ? 0 : (n.even? ? (2 ** (n / 2)) : 0)) \n", "lang_cluster": "Ruby", "tags": ["math", "dp"], "code_uid": "f5f43c2c738de75da1f104f6d86889fa", "src_uid": "4b7ff467ed5907e32fd529fb39b708db", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,c = gets.split.map(&:to_i)\nx =gets.split.map(&:to_i)\ndx = []\n\n0.upto(n-2) do |i|\n dx << x[i] - x[i+1]\nend\n\nmdx = dx.max\nputs [mdx - c, 0].max\n", "lang_cluster": "Ruby", "tags": ["brute force", "greedy", "implementation"], "code_uid": "d2e40fc176bfe4c8ffc2bb204e17a5db", "src_uid": "411539a86f2e94eb6386bb65c9eb9557", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, c = gets.split.map &:to_i\nx = gets.split.map &:to_i\nans = 0\n(1...x.size).step(1) { |i|\n temp = x[i - 1] - x[i] - c\n ans = temp if temp > ans\n}\np ans\n", "lang_cluster": "Ruby", "tags": ["brute force", "greedy", "implementation"], "code_uid": "2f63d982036a24b2fd7d80f6df474046", "src_uid": "411539a86f2e94eb6386bb65c9eb9557", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, c = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\ndiff = a.drop(1).zip(a).map{|x, y| y - x}.max\nputs [diff - c, 0].max\n", "lang_cluster": "Ruby", "tags": ["brute force", "greedy", "implementation"], "code_uid": "a79036ac5ef32e12c6f1dc258666cd92", "src_uid": "411539a86f2e94eb6386bb65c9eb9557", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "d=0\no=\"WBWBWBWB\"\np=\"BWBWBWBW\"\n8.times do |i|\nj=gets.chomp\nif j==o\n d+=1 \nelsif j==p\n d+=1\nelse\n d=-1\nend\nend\nif d!=8\n puts \"NO\"\nelse\n puts \"YES\"\nend", "lang_cluster": "Ruby", "tags": ["brute force", "strings"], "code_uid": "187750709e07fd5b3f5a01fb621ed9af", "src_uid": "ca65e023be092b2ce25599f52acc1a67", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "puts [*$<].map{|s| s=~/WW|BB/}.any? ? :NO : :YES\n", "lang_cluster": "Ruby", "tags": ["brute force", "strings"], "code_uid": "a911c9fe9b23d7df8fcb7dff1b9667cd", "src_uid": "ca65e023be092b2ce25599f52acc1a67", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "f = true\n8.times do\n b = nil\n gets.each_char do |c|\n f = false if b == c\n b = c\n end\nend\n\nif f\n puts 'YES'\nelse\n puts 'NO'\nend\n", "lang_cluster": "Ruby", "tags": ["brute force", "strings"], "code_uid": "111c4a275e115a7f0810c678a5378b09", "src_uid": "ca65e023be092b2ce25599f52acc1a67", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "e18206e1ce582730466bcd3fa4cf0150", "src_uid": "c02dfe5b8d9da2818a99c3afbe7a5293", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "$d0='0'.ord\n$d9='9'.ord\n$A='A'.ord\ndef value (c)\n if(c>=$d0 && c<=$d9)\n return c-$d0\n else\n c-$A+10\n end\nend\n\n\n\ns=gets\ns=s.chop\nt=s.split(/:/)\nlist=[]\nfor radix in (2..1000)\n\n ok=true\n for i in (0..1)\n max=0\n num=0\n if i==0\n max=23\n else\n max=59\n end\n for j in(0..t[i].length-1)\n w=value(t[i][j].ord)\n if(w>=radix)\n ok=false\n end\n num=radix*num+w\n\n end\n if(num>max)\n ok=false\n end\n end\n if(ok)\n list.insert(list.size,radix)\n end\n\nend\nif(list.size==0)\n puts 0\nelsif(list.size>500)\n puts -1\nelse\n for x in list\n print x\n print ' '\n end\nend\n\n\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "ae54e264b3371fd6036f08b0b3c6cb28", "src_uid": "c02dfe5b8d9da2818a99c3afbe7a5293", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "S = [*'0'..'9'] + [*'A'..'Z']\ndef gao(s, b)\n x = 0\n s.each_char do |c|\n x *= b\n i = S.index(c)\n return nil unless i && i < b\n x += i\n end\n return x\nend\n\na, b = gets.chop.split(/:/).map{|_| _.gsub(/^0*(?=.)/, '')}\nc = []\n2.upto(100) do |d|\n x = gao(a, d)\n y = gao(b, d)\n c << d if x && x < 24 && y && y < 60\nend\n\nif c.empty?\n p 0\nelsif c[-1] > 60\n p -1\nelse\n puts c * ' '\nend\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "e17b6b741e416e094139460e471bf8e9", "src_uid": "c02dfe5b8d9da2818a99c3afbe7a5293", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,a,b,c,d=gets.split.map(&:to_i)\np n*[0,n+[a+b,a+c,b+d,c+d].minmax.reduce(:-)].max", "lang_cluster": "Ruby", "tags": ["brute force", "math", "constructive algorithms"], "code_uid": "520dbcf50da5e85ba4572c6a56b767fe", "src_uid": "b732869015baf3dee5094c51a309e32c", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, a, b, c, d = gets.split.map { |x| x.to_i }\n\nf = [a + b, b + d, d + c, c + a]\nmax = f.max\nmin = f.min\ndiff = max - min\n\nif diff > n - 1\n\tputs 0\nelse\n\tputs n * (n - 1 - diff + 1)\nend", "lang_cluster": "Ruby", "tags": ["brute force", "math", "constructive algorithms"], "code_uid": "a900d15d59c0790f7fd8f72c06a75fb5", "src_uid": "b732869015baf3dee5094c51a309e32c", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, a, b, c, d = gets.chomp.split.map(&:to_i)\n\nans = 0\nfor nw in 1..n\n ne = nw + b - c\n if ne < 1 || n < ne\n next\n end\n sw = nw + a - d\n if sw < 1 || n < sw\n next\n end\n se = nw + a + b - c - d\n if se < 1 || n < se\n next\n end\n ans += 1\nend\n\nans *= n\n\nputs ans\n", "lang_cluster": "Ruby", "tags": ["brute force", "math", "constructive algorithms"], "code_uid": "b5c589672d319c2b46271e43f87593f8", "src_uid": "b732869015baf3dee5094c51a309e32c", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "7634b717b50d8e64978ae24a2fd519a7", "src_uid": "e2357a1f54757bce77dce625772e4f18", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "fcf835cb0b119c812661671c82e59f3d", "src_uid": "e2357a1f54757bce77dce625772e4f18", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/ruby\n\nk, b, n, t = STDIN.readline.split.map {|s| s.to_i }\nx, m = 1, n \nwhile t >= x and m != -1\n\tx = k*x + b\n\tm -= 1\nend\nputs m+1\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "ec806c5b5e2a45896619083a5853bbc1", "src_uid": "e2357a1f54757bce77dce625772e4f18", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "l,r,x,y,k=gets.split.map &:to_i\nl+=k-1\nl/=k\nr/=k\nputs l>r||x>r||l>y ?\"NO\":\"YES\"", "lang_cluster": "Ruby", "tags": ["two pointers", "brute force"], "code_uid": "e85d7b890a8081b55b2b6b60205e4138", "src_uid": "1110d3671e9f77fd8d66dca6e74d2048", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "l,r,x,y,k=gets.split.map &:to_i\nputs (l=(l+k-1)/k)>(r/=k)||x>r||l>y ?\"NO\":\"YES\"", "lang_cluster": "Ruby", "tags": ["two pointers", "brute force"], "code_uid": "553c4a6a0fe07347a81660c0183d9bd9", "src_uid": "1110d3671e9f77fd8d66dca6e74d2048", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = gets.chomp\nif s == s[0] * s.length\n puts \"0\"\nelse\n puts \"#{s.length - (s == s.reverse ? 1 : 0)}\"\nend", "lang_cluster": "Ruby", "tags": ["brute force", "strings", "implementation"], "code_uid": "4a2b05a07780a518539fb043b54cfb3a", "src_uid": "6c85175d334f811617e7030e0403f706", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def f(v, a, b)\n v<0\n f v,a+1,b*10+4 if a<10\n f v,a+1,b*10+7 if a<10\nend\nk,r = [],0\nf(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 r+=([b,k[i]].min-a+1)*k[i]\n a=k[i]+1\n end\nend\nputs r", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "05e00741118f086dceb0a344ffcc4730", "src_uid": "8a45fe8956d3ac9d501f4a13b55638dd", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def f(v, a, b)\n v<0\n f v,a+1,b*10+4 if a<10\n f v,a+1,b*10+7 if a<10\nend\nk,r = [],0\nf(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 r+=([b,k[i]].min-a+1)*k[i]\n a=k[i]+1\n end\nend\nputs r", "lang_cluster": "Ruby", "tags": ["brute force", "math"], "code_uid": "76dd2c7b93feef0673c76494bed56281", "src_uid": "8a45fe8956d3ac9d501f4a13b55638dd", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def generate_lucky_seq(n)\n r = [p = ['4', '7']]\n (n - 1).times {\n a = r.last\n w = []\n p.each { |b|\n a.each { |x|\n w << b + x\n }\n }\n r << w\n }\n r.flatten.map { |x| x.to_i }\nend\n\nlucky_seq = generate_lucky_seq(9) << 4_444_444_444\n\na, b = gets.split.map { |x| x.to_i }\nprev = a\nind = nil\nlucky_seq.each_with_index { |x, i|\n if x >= a\n ind = i\n break\n end\n}\n\nsum = 0\nloop do\n if lucky_seq[ind] < b\n sum += lucky_seq[ind] * (lucky_seq[ind] - prev + 1)\n prev = lucky_seq[ind] + 1\n ind += 1\n else\n sum += lucky_seq[ind] * (b - prev + 1)\n break\n end\nend\n\nputs sum", "lang_cluster": "Ruby", "tags": ["brute force", "math"], "code_uid": "448724848cde549af3ccd3a994edb470", "src_uid": "8a45fe8956d3ac9d501f4a13b55638dd", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "p gets.chomp.chars.chunk{|c|c}.count{|e|e[1].size.even?}\n", "lang_cluster": "Ruby", "tags": ["two pointers", "implementation"], "code_uid": "8c70cf8abccf474cd58b079b11964711", "src_uid": "8b26ca1ca2b28166c3d25dceb1f3d49f", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "p gets.chomp.chars.chunk{|c|c}.count{|e|e[1].size.even?}\n", "lang_cluster": "Ruby", "tags": ["two pointers", "implementation"], "code_uid": "542d3964f69b43a9a0ef7ca7cac1975f", "src_uid": "8b26ca1ca2b28166c3d25dceb1f3d49f", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "p gets.chomp.chars.chunk{|c|c}.count{|e|e[1].size.even?}", "lang_cluster": "Ruby", "tags": ["two pointers", "implementation"], "code_uid": "a74794e64c228c72d4e41df244efbf77", "src_uid": "8b26ca1ca2b28166c3d25dceb1f3d49f", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#$stdin.reopen('/home/chen/Desktop/input.txt', 'r')\n\n\ngene=gets\nsize = gene.size\n\ni,j,s,ans=0,1,1,0\n\nwhile j9)\n\treturn \"0\"+i.to_s\nend\n\nputs pad(ave/60) + \":\" + pad(ave%60)", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "eaaf24c230f4b287ed617213ab9b47d5", "src_uid": "f7a32a8325ce97c4c50ce3a5c282ec50", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "gets.chomp.split('').map { |x| x.to_i }.reverse.each { |x|\n left = x < 5 ? 'O-' : '-O'\n m = x % 5\n right = 'O' * m + '-' + 'O' * (4 - m)\n puts left + '|' + right\n}", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "9d5d70c190197db349c710e2af784c03", "src_uid": "c2e3aced0bc76b6484360563355d23a7", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.chomp.to_i\n\ndef draw(i)\n str = \"\"\n if i >= 5\n str = \"-O|\"\n else\n str = \"O-|\"\n end\n\n (i % 5).times do\n str += \"O\"\n end\n\n str += \"-\"\n (4 - (i % 5)).times do\n str += \"O\"\n end\n puts str\nend\n\nif n == 0\n draw(n)\nend\n\nwhile n != 0\n draw(n % 10)\n n /= 10\nend\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "e5a71c36ab1db08479aac6d7701aef77", "src_uid": "c2e3aced0bc76b6484360563355d23a7", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.chomp\nrep = {0 => 'O-|-OOOO', \n 1 => 'O-|O-OOO', \n 2 => 'O-|OO-OO', \n 3 => 'O-|OOO-O', \n 4 => 'O-|OOOO-', \n 5 => '-O|-OOOO', \n 6 => '-O|O-OOO', \n 7 => '-O|OO-OO', \n 8 => '-O|OOO-O', \n 9 => '-O|OOOO-'\n}\n\narr = []\nn.each_char do |c|\n\tarr << rep[c.to_i]\nend\narr.reverse!\narr.each do |a|\n\tputs a\nend", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "54b09ab8054ae3f9f7e0d86a6cad0d60", "src_uid": "c2e3aced0bc76b6484360563355d23a7", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\narr = gets.strip.split(' ').map(&:to_i)\n\npos = []\narr.each_with_index do |value, index|\n if 1 == value\n pos.push index\n elsif n == value\n pos.push index\n end\nend\n\np [pos[1], n - pos[0] - 1].max\n", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation"], "code_uid": "c88b6028c3ca250c82c7f935aa160ef8", "src_uid": "1d2b81ce842f8c97656d96bddff4e8b4", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = 0\nnums = Array.new\n\n\n\nbiggest = 0\nsmallest = 100\n\nn = gets.chomp.to_i\nnums = gets.split.map(&:to_i)\n\n#p nums\n#puts n\n#puts nums.last\n\nfor i in 0..n\n\t#nums.push($stdin.read.chomp.to_i) \n\t#thing = gets.chomp.split('|')[1].scan(/\\d+/).map{|n| n.to_i}\n\tif n == nums[i]\n\t\tbiggest = i + 1\n\tend\n\tif 1 == nums[i]\n\t\tsmallest = i + 1\n\tend\nend\n\n#puts \"Biggest: #{biggest}, smallest: #{smallest}\\n\\n\"\n\nputs [n - [smallest, biggest].min, [smallest, biggest].max - 1].max\n\n=begin\n7\n1 \n6 \n5 \n3 \n4 \n7 \n2\n\n6\n6 \n5 \n4 \n3 \n2 \n1\n\n3\n2 3 1\n\n\n=end", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation"], "code_uid": "6cd9496bd0cebc2de660966cae176c22", "src_uid": "1d2b81ce842f8c97656d96bddff4e8b4", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.chomp.to_i\nas = gets.chomp.split.map(&:to_i)\n\nif n <= 3\n puts n - 1\nelse\n i = as.index(1)\n j = as.index(n)\n ans = (i - j).abs\n ans = [ans, n - 1 - [i, j].min].max\n ans = [ans, [i, j].max].max\n puts ans\nend\n", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation"], "code_uid": "019560c3db84146785b2dd7409e36fa2", "src_uid": "1d2b81ce842f8c97656d96bddff4e8b4", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\nm = gets.to_i\n\narr = []\nn.times {arr.push gets.to_i}\n\nmax = arr.max\nsum = arr.inject(:+)\n\nif n==1\n print \"#{arr[0]+m} #{arr[0]+m}\\n\"\n exit\nend\n\n\nif max*n>(m+sum)\n print \"#{max} \"\nelse\n ans = max+(m-(max*n-sum))/n\n ans += 1 unless (m-(max*n-sum))%n==0\n printf \"#{ans} \"\nend\n\nputs arr.max+m\n", "lang_cluster": "Ruby", "tags": ["implementation", "binary search"], "code_uid": "d348053822a7309e6f11afc4a81f0472", "src_uid": "78f696bd954c9f0f9bb502e515d85a8d", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\nm = gets.to_i\n\nmaxa = 0\nsuma = 0\n\nn.times do \n ai = gets.to_i\n maxa = ai if ai > maxa\n suma += ai\nend\n\nmink = [((suma + m).to_f / n).ceil, maxa].max\nmaxk = maxa + m\n\nputs \"#{mink} #{maxk}\"", "lang_cluster": "Ruby", "tags": ["implementation", "binary search"], "code_uid": "7c82af0bb5f87ca1e9a07e926d32d121", "src_uid": "78f696bd954c9f0f9bb502e515d85a8d", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.chomp.to_i\nm = gets.chomp.to_i\na = []\n\nn.times.each do |_|\n\ta << gets.chomp.to_i\nend\n\nputs \"#{[(((a.reduce(&:+) + m) * 1.0)/n).ceil, *a].max} #{a.max + m}\"", "lang_cluster": "Ruby", "tags": ["implementation", "binary search"], "code_uid": "8fcaf00a64983021546a030b6f2c59bf", "src_uid": "78f696bd954c9f0f9bb502e515d85a8d", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/env ruby\n\nn,m = gets.chomp.split(\" \").map(&:to_i)\n\nif m true }\n end\n\n def minimum_times\n t = 0\n until @array.include?(@m)\n operate\n t += 1\n end\n\n t\n end\n\n def self.minimum_times(n, m)\n new(n, m).minimum_times\n end\n\n private\n\n def operate\n @array = [].tap do |out|\n @array.each do |a|\n out << a * 2 if a < @m && !@memo.key?(a * 2)\n out << a - 1 if a > 1 && !@memo.key?(a - 1)\n end\n\n out.each { |a| @memo[a] = true }\n end\n end\nend\n\nn, m = gets.chomp.split.map(&:to_i)\nputs StrangeDevice.minimum_times(n, m)\n", "lang_cluster": "Ruby", "tags": ["dfs and similar", "shortest paths", "math", "graphs", "greedy", "implementation"], "code_uid": "0e66ba09b43cecb4fcc7bf9b7dd9763a", "src_uid": "861f8edd2813d6d3a5ff7193a804486f", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "# \n# require 'pry'\nn,m = gets.chomp.split(' ').map(&:to_i)\n\nx = Math.log2(m.to_f/n).ceil\nx = 0 if x < 0\n\nneed = (2**x)*n - m\n\nresult=x\n\n\nx.downto(1) do |i|\n\tx = need.to_i/2**i\n\tneed-=x*2**i\n\tresult+=x\n\tbreak if need == 0\nend if x>0\n\nprint result+need", "lang_cluster": "Ruby", "tags": ["dfs and similar", "shortest paths", "math", "graphs", "greedy", "implementation"], "code_uid": "9e75ab91f780e61c4d7b172d3ff9197c", "src_uid": "861f8edd2813d6d3a5ff7193a804486f", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/env ruby\n\nn,m = gets.chomp.split(\" \").map(&:to_i)\n\nif m<=n\n\tputs n-m\nelse\n\tstep = 0\n\twhile n 0 and !vis[x - 1]\n\t\tvis[x - 1] = vis[x] + 1\n\t\tqueue.unshift(x - 1)\n\tend\n\tif x * 2 < N and !vis[x * 2]\n\t\tvis[x * 2] = vis[x] + 1\n\t\tqueue.unshift(x * 2)\n\tend\nend\nputs vis[m]", "lang_cluster": "Ruby", "tags": ["dfs and similar", "shortest paths", "math", "graphs", "greedy", "implementation"], "code_uid": "4191ec967e142b9e07d77a8188125818", "src_uid": "861f8edd2813d6d3a5ff7193a804486f", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a=gets.split(' ').map(&:to_i)\nq = Queue.new\nq.push([a[0],0])\nvis = Array.new(100000,false)\nwhile true\n val = q.pop\n if val[0]==a[1]\n puts val[1]\n exit\n end\n q.push([val[0]-1,val[1]+1])if val[0]>0 and !vis[val[0]-1]\n vis[val[0]-1]=val[0]>0\n q.push([val[0]<<1,val[1]+1])if (val[0]<<1) < 100000 and !vis[val[0]<<1]\n vis[val[0]<<1]=(val[0]<<1) < 100000\nend\n", "lang_cluster": "Ruby", "tags": ["dfs and similar", "shortest paths", "math", "graphs", "greedy", "implementation"], "code_uid": "c73655a08e871c432234e3a6dde9016b", "src_uid": "861f8edd2813d6d3a5ff7193a804486f", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/env ruby\n\nn,m = gets.chomp.split(\" \").map(&:to_i)\n\nif m 1\n\t\tif f - 1 == m\n\t\t\tprint visited[f]\n\t\t\tbreak\n\t\tend\n\t\tvisited[f - 1] = visited[f] + 1\n\t\tq.push(f - 1)\n\tend\nend\n", "lang_cluster": "Ruby", "tags": ["dfs and similar", "shortest paths", "math", "graphs", "greedy", "implementation"], "code_uid": "72cf3c71d54f1600a9b5e96d68c67f00", "src_uid": "861f8edd2813d6d3a5ff7193a804486f", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "data = gets.chomp.split\n\na = data[0].to_i\nb = data[1].to_i\n\nn=0\n\nif ba\n\t\t\tif b%2!=0\n\t\t\t\tb+=1\n\t\t\t\tn+=1\n\t\t\telse\n\t\t\t\tb/=2\n\t\t\t\tn+=1\n\t\t\tend\n\t\telse\n\t\t\tk=a-b\n\t\t\tb+=k\n\t\t\tn+=k\n\t\tend\n\tend\nend\n\nputs n", "lang_cluster": "Ruby", "tags": ["dfs and similar", "shortest paths", "math", "graphs", "greedy", "implementation"], "code_uid": "ce637d819b68d7bc1324288152a522f1", "src_uid": "861f8edd2813d6d3a5ff7193a804486f", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "# http://codeforces.com/contest/520/problem/B\nclass StrangeDevice\n def initialize(n, m)\n @m = m\n @array = [n]\n @memo = { n => true }\n end\n\n def minimum_times\n t = 0\n until @array.include?(@m)\n operate\n memonize\n t += 1\n end\n\n t\n end\n\n def self.minimum_times(n, m)\n new(n, m).minimum_times\n end\n\n private\n\n def memonize\n @array.each { |a| @memo[a] = true }\n end\n\n def operate\n @array = [].tap do |out|\n @array.each do |a|\n out << a * 2 if a < @m && !@memo.key?(a * 2)\n out << a - 1 if a > 1 && !@memo.key?(a - 1)\n end\n end\n end\nend\n\nn, m = gets.chomp.split.map(&:to_i)\nputs StrangeDevice.minimum_times(n, m)\n", "lang_cluster": "Ruby", "tags": ["dfs and similar", "shortest paths", "math", "graphs", "greedy", "implementation"], "code_uid": "9140044e22764ce24f0c78305928b6c1", "src_uid": "861f8edd2813d6d3a5ff7193a804486f", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/ruby\nclass Array\n def sum\n ret=0\n self.length.times{|i| ret+=self[i]}\n return ret\n end\nend\n\na=Array.new(8)\n8.times{|i|\n a[i]=gets.chomp.unpack(\"C*\").map!{|i|i-=87}\n}\nm=M=0\n8.times{|i|\n if a[i].sum==-168 then m+=1 end\n}\nif m==8 then puts 8; exit end\n8.times{|i|\n if a.transpose[i].sum==-168 then M+=1 end\n}\nputs m+M\n", "lang_cluster": "Ruby", "tags": ["brute force", "constructive algorithms"], "code_uid": "50578d5cad5788e31772b7b066006d8a", "src_uid": "8b6ae2190413b23f47e2958a7d4e7bc0", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = 0\nr = []\n8.times do |i|\n s = gets.chomp\n if !s.include? \"W\" then\n n += 1\n elsif k = s.index(\"B\") then\n while k do\n if !r.include? k then\n r << k\n n += 1\n end\n k = s.index(\"B\", k+1)\n end\n end \nend\n\nputs n", "lang_cluster": "Ruby", "tags": ["brute force", "constructive algorithms"], "code_uid": "a910fe61c24e2727037707db9183d34b", "src_uid": "8b6ae2190413b23f47e2958a7d4e7bc0", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a=[]\n8.times{\n a.push(gets.split[0])\n}\nres=0\n8.times{|i|\n if a[i]==\"BBBBBBBB\" then\n res+=1\n end\n ok=1\n 8.times{|j|\n if a[j][i]!=\"B\" then\n ok=0\n end\n }\n res+=ok\n}\nres=res==16 ? 8 : res\nputs res", "lang_cluster": "Ruby", "tags": ["brute force", "constructive algorithms"], "code_uid": "4788f7e7faa6def39b6f32b34a93c36d", "src_uid": "8b6ae2190413b23f47e2958a7d4e7bc0", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\nif n >= -128 && n <= 127\n puts \"byte\"\nelsif n >= -32768 && n <= 32767\n puts \"short\"\nelsif n >= -2147483648 && n <= 2147483647\n puts \"int\"\nelsif n >= -9223372036854775808 && n <= 9223372036854775807\n puts \"long\"\nelse\n puts \"BigInteger\"\nend\n", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "e902400aa8a9009857382ff1f2218f08", "src_uid": "33041f1832fa7f641e37c4c638ab08a1", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a = gets.to_i\na=a<0? a*(-1)-1:a\nputs a<128 ?\"byte\":(a<32768 ?\"short\":(a<2147483648 ?\"int\":(a<9223372036854775808 ?\"long\":\"BigInteger\")))", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "f432b26fd335e1548772dbfe2b453fe1", "src_uid": "33041f1832fa7f641e37c4c638ab08a1", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "d=gets.to_i\nif d>=-128 and d<=127 then puts 'byte'\nelsif d>=-32768 and d<=32767 then puts 'short'\nelsif d>=-2147483648 and d<=2147483647 then puts 'int'\nelsif d>=-9223372036854775808 and d<=9223372036854775807 then puts 'long'\nelse puts 'BigInteger' \nend", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "49e9158ef86ca659b748cbed1b2b8891", "src_uid": "33041f1832fa7f641e37c4c638ab08a1", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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\"", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "2d681191303a740179b8041ae086fd2d", "src_uid": "da13bd5a335c7f81c5a963b030655c26", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "r = %w[6 7 8 9 T J Q K A]\n\nt = gets.chomp\nf, s = gets.chomp.split\nputs((f[1] == s[1] && r.index(f[0]) > r.index(s[0]) || (f[1] == t && s[1] != t)) ? 'YES' : 'NO')", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "cb59e0f8a77428186cb5e92bd4c4403d", "src_uid": "da13bd5a335c7f81c5a963b030655c26", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "27a82d60da039db311009a9e745629bd", "src_uid": "da13bd5a335c7f81c5a963b030655c26", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b=gets.split;a=a.to_i+1;a+=1 until a.to_s.gsub(/[^47]/,'')==b;p a\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "d180f9c4b7c917ae581705221b7bf6a9", "src_uid": "e5e4ea7a5bf785e059e10407b25d73fb", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b=gets.split;a=a.to_i+1;a+=1 until a.to_s.gsub(/[^47]/,'')==b;p a\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "eb592e30c3f49e2db2cd6d2252925205", "src_uid": "e5e4ea7a5bf785e059e10407b25d73fb", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "f225b56ccfaa7084bbeef3a96e1639c7", "src_uid": "e5e4ea7a5bf785e059e10407b25d73fb", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "points = 8.times.map{|i| gets.split.map(&:to_i) }.uniq\nputs [:first, :last].all?{|sym| points.group_by(&sym).to_a.sort_by(&:first).map{|x| x.last.length} == [3,2,3] } ? \"respectable\" : \"ugly\"\n\n", "lang_cluster": "Ruby", "tags": ["sortings"], "code_uid": "e9d0f4d02428d0479a0b2f005ad1e46a", "src_uid": "f3c96123334534056f26b96f90886807", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def runb(list)\n x = list.map{|x,y| x}.uniq.sort\n y = list.map{|x,y| y}.uniq.sort\n \n return false unless x.size == 3\n return false unless y.size == 3\n x.each_with_index do |x,i|\n y.each_with_index do |y,j|\n if (i == j) and (j == 1)\n return false if list.member?([x,y])\n else\n return false unless list.member?([x,y])\n end\n end\n end\n return true\nend\n\ndef run(list)\n runb(list) ? \"respectable\" : \"ugly\"\nend\n\ndef convert(n)\n n.split(' ').map(&:to_i)\nend\n\nn = gets\nlist = []\nwhile n != nil\n list << convert(n)\n if list.size == 8\n puts run(list)\n list = []\n end\n n = gets\nend\n\n#0 0\n#2 1\n#1 0\n#0 2\n#2 2\n#1 0\n#2 1\n#0 2\n\n", "lang_cluster": "Ruby", "tags": ["sortings"], "code_uid": "585b41af831a6fa010027bd8e27ff3aa", "src_uid": "f3c96123334534056f26b96f90886807", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "points = 8.times.map{|i| gets.split.map(&:to_i) }.uniq\nputs [:first, :last].all?{|sym| points.group_by(&sym).to_a.sort_by(&:first).map{|x| x.last.length} == [3,2,3] } ? \"respectable\" : \"ugly\"\n\n", "lang_cluster": "Ruby", "tags": ["sortings"], "code_uid": "6f67f565c161100eddbaa839bc2e6e03", "src_uid": "f3c96123334534056f26b96f90886807", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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\n", "lang_cluster": "Ruby", "tags": ["dfs and similar", "math", "number theory", "brute force"], "code_uid": "bc0ab53e2506a2af547cde360c43083f", "src_uid": "75739f77378b21c331b46b1427226fa1", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["dfs and similar", "math", "number theory", "brute force"], "code_uid": "95cec8a63330b7a8b3bc69b20cb95277", "src_uid": "75739f77378b21c331b46b1427226fa1", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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\n", "lang_cluster": "Ruby", "tags": ["dfs and similar", "math", "number theory", "brute force"], "code_uid": "7691aac12d323fd7a5322c5045678cdc", "src_uid": "75739f77378b21c331b46b1427226fa1", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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\n", "lang_cluster": "Ruby", "tags": ["dfs and similar", "math", "number theory", "brute force"], "code_uid": "1cb7a5be9857efd78242e03574581672", "src_uid": "75739f77378b21c331b46b1427226fa1", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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\n", "lang_cluster": "Ruby", "tags": ["dfs and similar", "math", "number theory", "brute force"], "code_uid": "8140f4d85e8176b8ca7d1a82dd3a7f28", "src_uid": "75739f77378b21c331b46b1427226fa1", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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\n", "lang_cluster": "Ruby", "tags": ["dfs and similar", "math", "number theory", "brute force"], "code_uid": "5ff660f7d853517228e0c591edd0177f", "src_uid": "75739f77378b21c331b46b1427226fa1", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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\n", "lang_cluster": "Ruby", "tags": ["dfs and similar", "math", "number theory", "brute force"], "code_uid": "ed17df893a3be4af2a19bbca2b5171f4", "src_uid": "75739f77378b21c331b46b1427226fa1", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["dfs and similar", "math", "number theory", "brute force"], "code_uid": "9dce57e52c07a87f2a731ce07894cef8", "src_uid": "75739f77378b21c331b46b1427226fa1", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def solve(n,k)\n big=n;small=k\n a=0\n while big!=1||small!=1\n t=big/small\n if big%small==0 then t-=1 end\n a+=t\n big-=t*small\n if big0;x==1&&z>o&&z=o};p z-1\n", "lang_cluster": "Ruby", "tags": ["dfs and similar", "math", "number theory", "brute force"], "code_uid": "9d40f8a7a447204a5b86a9248f45020b", "src_uid": "75739f77378b21c331b46b1427226fa1", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.to_i\nans=n-1\n2.upto(n/2){|a|\n\tk=0\n\tb=n\n\tuntil a==b\n\t\td=(b-a-1)/a+1\n\t\tk+=d\n\t\tb-=a*d\n\t\ta,b=b,a\n\tend\n\tans=k if (b==1)&&(k@phases[@n-2]\n puts \"UP\"\n elsif \n puts \"DOWN\"\n end\n\n end\n\n # def putsResult()\n # puts @result.join(' ')\n # end\n\n def run()\n getData\n # getFileData\n getResult\n # putsResult\n end\n\nend\nif __FILE__ == $0\n pc = Task1.new\n pc.run\nend\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "e5fb12e0eed7e3500eaba7cd36416c77", "src_uid": "8330d9fea8d50a79741507b878da0a75", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\narr = gets.split.map(&:to_i)\nif arr[-1] == 15\n print \"DOWN\"\nelsif arr[-1] == 0\n print \"UP\"\nelsif n == 1\n print \"-1\"\nelsif arr[-1] > arr[-2]\n print \"UP\"\nelse\n print \"DOWN\"\nend", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "5979f9e04ca84d5a4113dd5dcb218ebd", "src_uid": "8330d9fea8d50a79741507b878da0a75", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.chomp.to_i\nmoon = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1]\nrecords = gets.chomp.split(' ').map(&:to_i)\n\nif records.length <= 1\n\n\tif records[0] != 0 && records[0] != 15\n\t\tputs -1\n\t\texit\n\tend\n\n\tputs 'UP' if records[0] == 0\n\tputs 'DOWN' if records[0] == 15\n\texit\nend\n\nstartM = 0\nnextM = 0\n\nfor i in (0...(moon.length - 1))\n\tif records[records.length - 2] == moon[i] && records[records.length - 1] == moon[i + 1]\n\t\tstartM = i\n\t\tnextM = i + 1\n\t\tbreak\n\tend\nend\n\nif (moon[startM] > moon[nextM] && moon[nextM] != 0) || moon[nextM] == 15\n\tputs 'DOWN'\nelse\n\tputs 'UP'\nend", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "09b62ae81cba243a6e3ca42e20cc8a00", "src_uid": "8330d9fea8d50a79741507b878da0a75", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "POSSIBLES = [\n [[1, 2], [18, 20], [11, 12], [13, 15]],\n [[3, 4], [17, 19], [9, 10], [14, 16]],\n [[2, 4], [6, 8], [10, 12], [21, 23]],\n [[1, 3], [5, 7], [9, 11], [22, 24]],\n [[13, 14], [5, 6], [17, 18], [21, 22]],\n [[15, 16], [7, 8], [19, 20], [23, 24]],\n]\n\n\nFACES = [\n (1..4).to_a,\n (5..8).to_a,\n (9..12).to_a,\n (13..16).to_a,\n (17..20).to_a,\n (21..24).to_a,\n]\n\ndef check_solved(c)\n FACES.each do |face|\n return false unless face.map { |f| c[f] }.uniq.size == 1\n end\n true\nend\n\ndef solve(cube)\n # [[[2, 4], [6, 8], [10, 12], [21, 23]]].each_with_index do |possib|\n POSSIBLES.each_with_index do |possib|\n face_colors = possib.map { |p| cube[p.first] == cube[p.last] }\n next if face_colors.include?(false)\n colors = possib.map { |p| cube[p.first] }\n [possib.rotate(1), possib.rotate(-1)].each do |rot|\n c = cube.dup\n rot.each_with_index do |curr, i|\n c[curr.first] = colors[i]\n c[curr.last] = colors[i]\n end\n if check_solved(c)\n return \"YES\"\n end\n end\n end\n return \"NO\"\nend\n\n\n\ncube = {}\nvals = gets.strip.split.map(&:to_i)\n\nvals.each_with_index do |v, i|\n cube[i + 1] = v\nend\n\nputs solve(cube)\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "dc3df8f8caf870b2ad8d23a5436e9989", "src_uid": "881a820aa8184d9553278a0002a3b7c4", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def solve(a)\n\ttag = true\n\tj = 1\n\twhile(j<=21 && tag)\n\t\tif(a[j-1] == a[j]&& a[j]==a[j+1]&&a[j+1]==a[j+2])\n\t\t\tj += 4\n\t\t\tnext\n\t\tend\n\t\ttag = false\n\tend\n \treturn tag\nend\n\ntag = false\nn = gets.split(' ').map(&:to_i)\na = n.dup\ntemp1 = a[1-1]\ntemp2 = a[3-1]\na[1-1] = a[24-1]\na[3-1] = a[22-1]\na[24-1] = a[9-1] \na[22-1] = a[11-1]\na[9-1] = a[5-1]\na[11-1] = a[7-1]\na[5-1] = temp1\na[7-1] = temp2\nif solve a\n\ttag = true\nend\na = n.dup\ntemp1 = a[1-1]\ntemp2 = a[3-1]\na[1-1] = a[5-1]\na[3-1] = a[7-1]\na[5-1] = a[9-1] \na[7-1] = a[11-1]\na[9-1] = a[24-1]\na[11-1] = a[22-1]\na[24-1] = temp1\na[22-1] = temp2\nif solve a\n\ttag = true\nend\n\n\na = n.dup\ntemp1 = a[2-1]\ntemp2 = a[4-1]\na[2-1] = a[23-1]\na[4-1] = a[21-1]\na[23-1] = a[10-1] \na[21-1] = a[12-1]\na[10-1] = a[6-1]\na[12-1] = a[8-1]\na[6-1] = temp1\na[8-1] = temp2\nif solve a\n\ttag = true\nend\na = n.dup\ntemp1 = a[2-1]\ntemp2 = a[4-1]\na[2-1] = a[6-1]\na[4-1] = a[8-1]\na[6-1] = a[10-1] \na[8-1] = a[12-1]\na[10-1] = a[23-1]\na[12-1] = a[21-1]\na[23-1] = temp1\na[21-1] = temp2\nif solve a\n\ttag = true\nend\n\n\na = n.dup\ntemp1 = a[5-1]\ntemp2 = a[6-1]\na[5-1] = a[13-1]\na[6-1] = a[14-1]\na[13-1] = a[21-1] \na[14-1] = a[22-1]\na[21-1] = a[17-1]\na[22-1] = a[18-1]\na[17-1] = temp1\na[18-1] = temp2\nif solve a\n\ttag = true\nend\na = n.dup\ntemp1 = a[5-1]\ntemp2 = a[6-1]\na[5-1] = a[17-1]\na[6-1] = a[18-1]\na[17-1] = a[21-1] \na[18-1] = a[22-1]\na[21-1] = a[13-1]\na[22-1] = a[14-1]\na[13-1] = temp1\na[14-1] = temp2\nif solve a\n\ttag = true\nend\n\n\n\n\na = n.dup\ntemp1 = a[7-1]\ntemp2 = a[8-1]\na[7-1] = a[15-1]\na[8-1] = a[16-1]\na[15-1] = a[23-1] \na[16-1] = a[24-1]\na[23-1] = a[19-1]\na[24-1] = a[20-1]\na[19-1] = temp1\na[20-1] = temp2\nif solve a\n\ttag = true\nend\na = n.dup\ntemp1 = a[7-1]\ntemp2 = a[8-1]\na[7-1] = a[19-1]\na[8-1] = a[20-1]\na[19-1] = a[23-1] \na[20-1] = a[24-1]\na[23-1] = a[15-1]\na[24-1] = a[16-1]\na[15-1] = temp1\na[16-1] = temp2\nif solve a\n\ttag = true\nend\n\n\na = n.dup\ntemp1 = a[18-1]\ntemp2 = a[20-1]\na[18-1] = a[1-1]\na[20-1] = a[2-1]\na[1-1] = a[15-1] \na[2-1] = a[13-1]\na[13-1] = a[11-1]\na[15-1] = a[12-1]\na[12-1] = temp1\na[11-1] = temp2\nif solve a\n\ttag = true\nend\na = n.dup\ntemp1 = a[18-1]\ntemp2 = a[20-1]\na[18-1] = a[12-1]\na[20-1] = a[11-1]\na[11-1] = a[13-1] \na[12-1] = a[15-1]\na[15-1] = a[1-1]\na[13-1] = a[2-1]\na[1-1] = temp1\na[2-1] = temp2\nif solve a\n\ttag = true\nend\n\n\n\n\n\na = n.dup\ntemp1 = a[17-1]\ntemp2 = a[19-1]\na[17-1] = a[10-1]\na[19-1] = a[9-1]\na[9-1] = a[14-1] \na[10-1] = a[16-1]\na[16-1] = a[3-1]\na[14-1] = a[4-1]\na[3-1] = temp1\na[4-1] = temp2\nif solve a\n\ttag = true\nend\na = n.dup\ntemp1 = a[17-1]\ntemp2 = a[19-1]\na[17-1] = a[3-1]\na[19-1] = a[4-1]\na[3-1] = a[16-1] \na[4-1] = a[14-1] \na[14-1] = a[9-1]\na[16-1] = a[10-1] \na[10-1] = temp1\na[9-1] = temp2\nif solve a\n\ttag = true\nend\nif tag\n\tprint('YES')\nelse\n\tprint('NO')\nend\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "0cdaa648879501e0b99e62bcd0e89392", "src_uid": "881a820aa8184d9553278a0002a3b7c4", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def judge(cube)\n 6.times do |i|\n if !(cube[4 * i] == cube[4 * i + 1] && cube[4 * i + 1] == cube[4 * i + 2] && cube[4 * i + 2] == cube[4 * i + 3])\n return false\n end\n end\n return true\nend\n\na1 = [0,2,4,6,8,10,23,21]\nb1 = [1,3,5,7,9,11,22,20]\na2 = [12,13,4,5,16,17,20,21]\nb2 = [14,15,6,7,18,19,22,23]\na3 = [2,3,16,18,9,8,15,13]\nb3 = [0,1,17,19,11,10,14,12]\n\ncube = gets.split.map(&:to_i)\nans = false\n\ntmp = Array.new(a1)\ntmp.rotate!(2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[a1[i]] = cube[tmp[i]]\nend\nans |= judge(cube2)\n\ntmp = Array.new(b1)\ntmp.rotate!(2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[b1[i]] = cube[tmp[i]]\nend\nans |= judge(cube2)\n\ntmp = Array.new(a2)\ntmp.rotate!(2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[a2[i]] = cube[tmp[i]]\nend\nans |= judge(cube2)\n\ntmp = Array.new(b2)\ntmp.rotate!(2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[b2[i]] = cube[tmp[i]]\nend\nans |= judge(cube2)\n\ntmp = Array.new(a3)\ntmp.rotate!(2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[a3[i]] = cube[tmp[i]]\nend\nans |= judge(cube2)\n\ntmp = Array.new(b3)\ntmp.rotate!(2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[b3[i]] = cube[tmp[i]]\nend\nans |= judge(cube2)\n\n\ntmp = Array.new(a1)\ntmp.rotate!(-2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[a1[i]] = cube[tmp[i]]\nend\nans |= judge(cube2)\n\ntmp = Array.new(b1)\ntmp.rotate!(-2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[b1[i]] = cube[tmp[i]]\nend\nans |= judge(cube2)\n\ntmp = Array.new(a2)\ntmp.rotate!(-2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[a2[i]] = cube[tmp[i]]\nend\nans |= judge(cube2)\n\ntmp = Array.new(b2)\ntmp.rotate!(-2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[b2[i]] = cube[tmp[i]]\nend\nans |= judge(cube2)\n\ntmp = Array.new(a3)\ntmp.rotate!(-2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[a3[i]] = cube[tmp[i]]\nend\nans |= judge(cube2)\n\ntmp = Array.new(b3)\ntmp.rotate!(-2)\ncube2 = Array.new(cube)\n8.times do |i|\n cube2[b3[i]] = cube[tmp[i]]\nend\nans |= judge(cube2)\n\nputs ans ? \"YES\" : \"NO\"", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "80ce33451d7a8af3be3b7d4f3f04475e", "src_uid": "881a820aa8184d9553278a0002a3b7c4", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s=gets.chomp\nputs s==s.reverse.tr('1234567890','##36947058')?:Yes: :No", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "51f95fe27db3fac21c7a999fc3ad326d", "src_uid": "0f11f41cefd7cf43f498e511405426c3", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s=gets.chomp\nputs s==s.reverse.tr('1234567890','##36947058')?:Yes: :No", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "1c737adab4c26eae2c765322543b9b42", "src_uid": "0f11f41cefd7cf43f498e511405426c3", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, k = gets.split.map(&:to_i)\nd = (n / (2 * (k + 1))).to_i\nc = k * d\nputs \"#{d} #{c} #{n-d-c}\"", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "1b67b6b4632080ca0dedcbdfda088b7e", "src_uid": "405a70c3b3f1561a9546910ab3fb5c80", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, k = gets.split\nn = n.to_i\nk = k.to_i\n\nd = n/(2*(k+1))\nc = d * k\n\nothers = n - (c + d)\n\nputs \"#{d} #{c} #{others}\"", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "289f272a87c96f35c873f8b20a8ca640", "src_uid": "405a70c3b3f1561a9546910ab3fb5c80", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\nans = 0\nlen = 1\nbase = 10\nwhile true\n if n < base then\n ans += (n - base / 10 + 1) * len\n break\n else\n ans += base / 10 * 9 * len\n end\n len += 1\n base *= 10\nend\nputs ans\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "57c2a1cf83559512ce935cb4acfd0a8f", "src_uid": "4e652ccb40632bf4b9dd95b9f8ae1ec9", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.strip!\ns,c = n.length,0\n(1...s).each{ |i| c += i*(9*10**(i-1)) }\np c+(n.to_i-(10**(s-1)-1))*s", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "cdd69b1482afc552086a9eda8b9439d5", "src_uid": "4e652ccb40632bf4b9dd95b9f8ae1ec9", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a=gets.chomp\nl=a.length-1\nif l==0\nputs a\nelse\nans=9\n2.upto l do |i|\nans+= (9*(10**(i-1)))*i\nend\nans+=(a.to_i-(\"9\"*l).to_i)*(l+1)\nputs ans.inspect\nend\n\n\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "9e4c6e87a0870636d77ff14b774dc648", "src_uid": "4e652ccb40632bf4b9dd95b9f8ae1ec9", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "LIMIT = 1000000007\n\n@res = []\nl = 1\nwhile l < LIMIT\n @res << l\n l = l * 2\nend\n\ndef power i\n return @res[i] if i < @res.size\n half_power = power(i/2)\n partial = (half_power * half_power) % LIMIT \n if i % 2 == 1\n partial = (partial * 2) % LIMIT\n end\n partial\nend\n\nyears = gets.to_i\n\nif years == 0\n puts 1\nelse\n partial = power(years-1)\n puts (partial * (((2 * partial) % LIMIT) + 1)) % LIMIT\nend\n\n# 2^(n-1) * (2^n +1)\n", "lang_cluster": "Ruby", "tags": ["math", "matrices", "dp", "number theory"], "code_uid": "77e3a936a65fefea9407b2aae4fde4ee", "src_uid": "782b819eb0bfc86d6f96f15ac09d5085", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "x = Integer gets.to_s\nif x == 0 then\n\tputs 1\n\texit\nend\nd = 1000000\nif x < d then\n\tx = 2**(x-1) * (1+2**x) % 1000000007\n\tputs x\n\texit\nend\n\nx -= 1\np = 1\nwhile x >= d\n\te = d\n\tq = 2**d % 1000000007\nwhile x >= e do\n\tp *= q\n\tp = p % 1000000007\n\tx -= e\n\te *= 10\n\tq = q**10 % 1000000007\n\nend\nend\n\np *= 2**x\np = p % 1000000007\n\np = (p * ( 1 + 2*p)) % 1000000007\n\nputs p\n", "lang_cluster": "Ruby", "tags": ["math", "matrices", "dp", "number theory"], "code_uid": "0fece5e614ccce076a632ca89e5b48d6", "src_uid": "782b819eb0bfc86d6f96f15ac09d5085", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "$p = 1000000007\ndef mul(a,b)\n n = a.size\n c = Array.new(n){Array.new(n){0}}\n n.times do |i|\n n.times do|j|\n n.times do |k|\n c[i][j] += a[i][k] * b[k][j]\n c[i][j] %= $p\n end\n end\n end\n c\nend\n\ndef po(m)\n e = [[3,1],[1,3]]\n ret = [[1,0],[0,1]]\n \n while m > 0\n if m % 2 == 1\n ret = mul(ret,e)\n end\n e = mul(e,e)\n m /= 2\n end\n \n ret\nend\n\n\ndef work(n)\n if n == 1\n puts 3\n else\n ret = po(n)\n ans = ret[0][0]\n puts ans % $p\n end\nend\n\nn = gets.to_i\nwork n\n#10.times{|x| work x+1}\n\n ", "lang_cluster": "Ruby", "tags": ["math", "matrices", "dp", "number theory"], "code_uid": "350f029bf534698d57a301a4f09a5185", "src_uid": "782b819eb0bfc86d6f96f15ac09d5085", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "\n\n\n$p = 1000000007\ndef mul(a,b)\n n = a.size\n c = Array.new(n){Array.new(n){0}}\n n.times do |i|\n n.times do|j|\n n.times do |k|\n c[i][j] += a[i][k] * b[k][j]\n c[i][j] %= $p\n end\n end\n end\n c\nend\n\ndef po(m)\n e = [[3,1],[1,3]]\n ret = [[1,0],[0,1]]\n \n while m > 0\n if m % 2 == 1\n ret = mul(ret,e)\n end\n e = mul(e,e)\n m /= 2\n end\n \n ret\nend\n\n\ndef work(n)\n if n == 1\n puts 3\n else\n ret = po(n)\n ans = ret[0][0]\n puts ans % $p\n end\nend\n\nn = gets.to_i\nwork n\n\n", "lang_cluster": "Ruby", "tags": ["math", "matrices", "dp", "number theory"], "code_uid": "f77ee71b5a0e55cc529bcd6e511e5c8d", "src_uid": "782b819eb0bfc86d6f96f15ac09d5085", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def pow(a,k)\n n = 1000000007\n b = 1\n while (k!= 0) do\n if (k % 2 == 0 ) then\n k/=2\n a = (a*a) % n\n else\n k-=1\n b = (b*a) % n\n end\n end\n return b\nend\n\n\nn = gets.to_i\nk = pow(2,n)\nk = (k*(k-1)/2) % 1000000007\nif (n == 0) then\n puts \"1\"\nelse\n ans = (pow(4,n) - k) % 1000000007\n puts ans\nend\n", "lang_cluster": "Ruby", "tags": ["math", "matrices", "dp", "number theory"], "code_uid": "fb7c0fe56f4ae68856d4ecffce5ea384", "src_uid": "782b819eb0bfc86d6f96f15ac09d5085", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "puts (gets.to_i - 2) ** 2\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "d959a299d776a8c4a5c58326d751665c", "src_uid": "efa8e7901a3084d34cfb1a6b18067f2b", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "angles = gets.to_i\nputs (angles - 2) * (angles - 2)", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "49d06d2bc0110e4d5ca10f68f5514660", "src_uid": "efa8e7901a3084d34cfb1a6b18067f2b", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/env ruby\n\nN = gets.to_i\n\ndef total_sections\n return 1 if N == 3\n return 4 if N == 4\n\n sections_without_2_triangles = (3..N-2).map do |second_vertice|\n third_vertice = second_vertice + 1\n\n lines_from_second = N - second_vertice - 1\n lines_from_third = third_vertice - 3\n\n lines_from_second + lines_from_third + 1\n end.inject(:+)\n\n sections_without_2_triangles + (N-2)*2\nend\n\nputs total_sections\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "68c1632116aba366844fb0f6da4d281b", "src_uid": "efa8e7901a3084d34cfb1a6b18067f2b", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a = STDIN.read\nb = a.to_i(16)\nputs b % 2\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "dfb9dc6e19edffae7d5484e9b307b050", "src_uid": "e52bc741bb72bb8e79cf392b2d15354f", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "x = gets\nx=x.split('')\nans = 0\nx.each do |i|\n if i!=\"A\" and i!=\"\\n\"\n ans = i.to_i.modulo(2)\n end\nend\nputs ans", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "cc6d4b191c291e9f17a632d880fdc8a0", "src_uid": "e52bc741bb72bb8e79cf392b2d15354f", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "string = gets.chomp\n\nputs string.slice(/\\d+/).to_i % 2\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "db5e180d3ade1e357a7e9571fde66a72", "src_uid": "e52bc741bb72bb8e79cf392b2d15354f", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "N = gets.to_i\np (2...N).reduce(0){ |a,b| a + b*(b+1) }", "lang_cluster": "Ruby", "tags": ["math", "greedy", "dp"], "code_uid": "98d1949e73381f232a6ffe93af8bc42f", "src_uid": "1bd29d7a8793c22e81a1f6fd3991307a", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "\nn = gets.to_i\nbegin\n puts n%3 == 0 ? n/3 * 2 : n/3 * 2 + 1\nrescue\nend\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "700f9af65bd7055fbdda345905f5fff7", "src_uid": "a993069e35b35ae158d35d6fe166aaef", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\ncnt = (n / 3) * 2\nres = n % 3\ncnt += 1 if res >= 1\nputs cnt\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "f0a36ed8ab7e59698c79bb3306f9f19a", "src_uid": "a993069e35b35ae158d35d6fe166aaef", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = readline.to_i\nct = n / 3\nct *= 2\nif n % 3 != 0\n ct += 1\nend\nputs ct\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "034d1830547ad4310133b636cdb45417", "src_uid": "a993069e35b35ae158d35d6fe166aaef", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "# start from reverse and count till number_of_zeros == k\nn, k = gets.split(' ')\nk = k.to_i\nnum_of_zeros = 0\ndigit_removed = 0\nsuccess = false\nn.reverse.split('').each do |a|\n if a == '0'\n num_of_zeros += 1\n else\n digit_removed += 1\n end\n\n if num_of_zeros == k\n success = true\n break\n end\nend\n\nif success\n puts digit_removed\nelse\n puts n.length - 1\nend\n", "lang_cluster": "Ruby", "tags": ["brute force", "greedy"], "code_uid": "2d8427d5921adc3a0152049a1c86cc79", "src_uid": "7a8890417aa48c2b93b559ca118853f9", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, k = gets.chomp.split(\" \") \nk = k.to_i\n\nzeros = answer = 0\nfor i in (n.length - 1).downto( 0 )\n if n[ i ] == \"0\"\n zeros += 1\n else\n answer += 1\n end\n break if zeros == k\nend\n\nif zeros == k\n puts answer\nelse\n puts ( n.length - 1 )\nend\n", "lang_cluster": "Ruby", "tags": ["brute force", "greedy"], "code_uid": "5eee6733dab6e43246529b677fae2f5d", "src_uid": "7a8890417aa48c2b93b559ca118853f9", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,k = gets.split\nk = k.to_i\nif n.count('0') >= k\n output = 0\n zeros_so_far = 0\n n.chars.reverse.each do |c|\n if c == '0'\n zeros_so_far += 1\n else\n output += 1\n end\n break if zeros_so_far == k\n end\n puts output\nelse\n # have to make zero\n puts n.length - 1\nend\n", "lang_cluster": "Ruby", "tags": ["brute force", "greedy"], "code_uid": "1df18a2ed53eaf090d4bbdee78bfe4da", "src_uid": "7a8890417aa48c2b93b559ca118853f9", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["geometry"], "code_uid": "ba77abd20b9ff09f512ba9ffbc3103ca", "src_uid": "4c2865e4742a29460ca64860740b84f4", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b,c,d=gets.split.map &:to_i\ne,f,g,h=gets.split.map &:to_i\n$dd=Math.sqrt((a-e)**2+(b-f)**2)\ndef pf(r,r1,r2)\n return 1 if r1+r<=$dd&&r2+r<=$dd\n return 1 if r1-r>=$dd&&r2-r>=$dd\n return 1 if r-r1>=$dd&&r-r2>=$dd\n return 0\nend\np pf(c,g,h)+pf(d,g,h)+pf(g,c,d)+pf(h,c,d)", "lang_cluster": "Ruby", "tags": ["geometry"], "code_uid": "d577199232199d40e23891df60497708", "src_uid": "4c2865e4742a29460ca64860740b84f4", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/env ruby\n\ndef pow(n)\n n*n\nend\n\nclass Circle\n attr_accessor :x, :y, :r\n def initialize(x, y, r)\n @x = x\n @y = y\n @r = r\n end\n\n def include?(other)\n @r >= other.r && pow(@x-other.x) + pow(@y-other.y) <= pow(@r-other.r)\n end\n\n def collide?(other)\n (not include?(other)) && (not other.include?(self)) && pow(@x-other.x) + pow(@y-other.y) < pow(@r+other.r)\n end\n\n def in(area)\n area[1].include?(self) and not area[0].include?(self)\n end\nend\n\nblack_area = []\ncircles = []\n2.times do\n x, y, r1, r2 = gets.split.map(&:to_i)\n c1 = Circle.new(x, y, r1)\n c2 = Circle.new(x, y, r2)\n circles.push(c1, c2)\n black_area << [c1, c2]\nend\n\ncnt = 0\ncircles.each_with_index do |c1, i|\n valid = circles.all?{|c2| c1==c2 or not c1.collide?(c2)}\n valid = valid && !c1.in(black_area[1-i/2])\n cnt += 1 if valid\nend\n\np cnt\n", "lang_cluster": "Ruby", "tags": ["geometry"], "code_uid": "5dc784badbd13fc4285b21e3d6702267", "src_uid": "4c2865e4742a29460ca64860740b84f4", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "puts gets.chomp.chars.to_a.reduce(Hash.new(0)) {|s, x| s[x] += 1; s }.max_by {|k, v| k}.reduce(:*)", "lang_cluster": "Ruby", "tags": ["brute force", "binary search", "bitmasks", "greedy", "strings", "implementation"], "code_uid": "c67d5dff497b98f14f223ea0e84addc6", "src_uid": "9a40e9b122962a1f83b74ddee6246a40", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/ruby1.9\n\nbase = STDIN.readline.strip\n\ndef go(prefix, suffix, found)\n\tif suffix.length == 0\n\t\tfound.push(prefix) if prefix.reverse == prefix\n\t\treturn\n\tend\n\tgo(prefix, suffix[1..-1], found)\n\tgo(prefix+suffix[0], suffix[1..-1], found)\nend\n\nfound = []\ngo('', base, found)\nputs found.sort[-1]\n\n", "lang_cluster": "Ruby", "tags": ["brute force", "binary search", "bitmasks", "greedy", "strings", "implementation"], "code_uid": "6ea68e7ffde23094576215e145671ced", "src_uid": "9a40e9b122962a1f83b74ddee6246a40", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "puts gets.delete\"^\"+$_.chars.max\n", "lang_cluster": "Ruby", "tags": ["brute force", "binary search", "bitmasks", "greedy", "strings", "implementation"], "code_uid": "3a124188f4849f51a0902c1d26623bf7", "src_uid": "9a40e9b122962a1f83b74ddee6246a40", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b = gets.split.map(&:to_i)\nif b%a != 0\n puts \"-1\"\n exit\nend\nans = 0\nb /= a\nwhile b%2 == 0\n ans += 1\n b /= 2\nend\nwhile b%3 == 0\n ans += 1\n b /= 3\nend\nif b == 1\n puts ans\nelse\n puts \"-1\"\nend", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "64012b2a0f47415d85c3ed3c2c74357e", "src_uid": "3f9980ad292185f63a80bce10705e806", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "x,y=gets.split.map &:to_i\nn=y.to_f/x.to_f\nif n.to_i!=n\n puts \"-1\"\nelse\n res=0\n while n!=1\n if n%2==0\n n/=2\n res+=1\n elsif n%3==0\n n/=3\n res+=1\n else\n puts \"-1\"\n exit\n end\n end\n puts res\nend\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "4bdeae7e38091e09475784d5ec6d94c2", "src_uid": "3f9980ad292185f63a80bce10705e806", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,m = gets.chomp.split(\" \")\nn = n.to_i;\nm = m.to_i;\ndiv = m / n; \npmoves = true;\n\nunless (m % n == 0) \n puts \"-1\";\n pmoves = false\nend\n\nmoves = 0;\n\nwhile div != 1 && m % n == 0 do \n if div % 2 == 0 then \n moves += 1;\n div /= 2;\n elsif div % 3 == 0 then \n moves += 1;\n div /= 3;\n else \n puts \"-1\";\n pmoves = false;\n break;\n\n end\nend \n\nif pmoves then \n puts moves \nend\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "9e6ee612ff1995031d50b06c3fcc48a1", "src_uid": "3f9980ad292185f63a80bce10705e806", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "x, y = gets.chomp.split(' ').map(&:to_i)\nsides = [y, y, y]\n\nans = 0\n\nuntil sides.count(x) == 3\n sortedSides = Array.new(sides).sort\n power = x - sortedSides[0] \n \n power = sortedSides[1] + sortedSides[2] - sortedSides[0] - 1 if power >= sortedSides[1] + sortedSides[2] - sortedSides[0]\n sides[sides.index(sortedSides[0])] = sides[sides.index(sortedSides[0])] + power\n \n #print sides\n #puts ''\n \n ans += 1\nend\n\nputs ans", "lang_cluster": "Ruby", "tags": ["math", "greedy"], "code_uid": "48559e769578330f6f1bcba1eb710b69", "src_uid": "8edf64f5838b19f9a8b19a14977f5615", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "x, y = gets.split.map(&:to_i)\na = [y, y, y]\nc = 1\nloop do\n mx = a.min\n case mx\n when a[0]\n a[0] = [a[1] + a[2] - 1, x].min\n when a[1]\n a[1] = [a[0] + a[2] - 1, x].min\n when a[2]\n a[2] = [a[0] + a[1] - 1, x].min\n end\n break if a == [x, x, x]\n c += 1\nend\nputs c\n", "lang_cluster": "Ruby", "tags": ["math", "greedy"], "code_uid": "e8058b65470429ca4da19698e9dbc7be", "src_uid": "8edf64f5838b19f9a8b19a14977f5615", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def printlol(ar)\n for i in 0..(ar.length-2) do\n print ar[i]\n print \" \"\n end\n print ar.last\n puts \"\"\nend\n\n\ninput = gets.strip.split(' ').map(&:to_i)\nx = input[0]\ny = input[1]\n\nlol = [y, y, y]\ncount = 0\nwhile lol[0] != x or lol[1] != x or lol[2] != x do\n asd = lol.dup\n asd.slice!(lol.index(lol.min))\n top = (asd[0] + asd[1])\n \n if top - 1 > x\n asd << x\n else\n asd << top - 1\n end\n \n lol = asd\n count += 1\n #printlol(lol)\nend\n\nputs count", "lang_cluster": "Ruby", "tags": ["math", "greedy"], "code_uid": "88425c6f09031069d98f0fa67d78d83d", "src_uid": "8edf64f5838b19f9a8b19a14977f5615", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def bin_search(arr,e)\n\tn = arr.length\n\tl = 0\n\tr = n - 1\n\n\twhile l <= r\n\t\tm = l + (r-l) / 2\n\t\tif arr[m] == e\n\t\t\treturn true\n\t\telsif e < arr[m]\n\t\t\tr = m - 1\n\t\telse\n\t\t\tl = m + 1\n\t\tend\t\t\t\n\tend\n\n\treturn false\n\t\nend\n\ns = gets.to_i\narr = []\n(1..s).each do |a|\n\tval = (a * (a + 1) ) / 2\n\tarr << val\n\tbreak if val > s\nend\n\n\n\narr.sort!\nans = false\narr.each do |a|\n\tif bin_search(arr,s-a)\n\t\tans = true\n\t\tbreak \n\tend\nend\n\nputs ans ? \"YES\" : \"NO\"", "lang_cluster": "Ruby", "tags": ["brute force", "implementation", "binary search"], "code_uid": "8f3f9a555408a3e174d3de988cd6da0e", "src_uid": "245ec0831cd817714a4e5c531bffd099", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a=gets.chomp.to_i\ntrig=0\n1.upto(31623) do |i|\ntemp=a-(i*(i+1))/2\nbreak if temp<=0\nif (Math.sqrt(1+8*temp)/2.0-0.5)%1==0\ntrig=1\nbreak\nend\nend\n\nif trig == 0\nputs \"NO\"\nelse\nputs \"YES\"\nend\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation", "binary search"], "code_uid": "b7159c7da912a27c665b715ae7e4eb6e", "src_uid": "245ec0831cd817714a4e5c531bffd099", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def f(r,x)\n\tl=1\n\twhile l>1\n\t\treturn m if m*(m+1)==x\n\t\tif m*(m+1) 1}\nn = gets.to_i\np gao(n)\n", "lang_cluster": "Ruby", "tags": ["number theory"], "code_uid": "f8a0714ebe87e19a9df64b3211b5f485", "src_uid": "821c0e3b5fad197a47878bba5e520b6e", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def find_div(n)\n sq = Math.sqrt(n).floor\n (2..sq).each do |i|\n next if (n % i) != 0\n return n / i\n end\n 1\nend\n\nn = gets.to_i\nans = n\n\nwhile n > 1\n n = find_div(n)\n ans += n\nend\n\nputs ans\n", "lang_cluster": "Ruby", "tags": ["number theory"], "code_uid": "34919bded32b8f1b0ab2886ffa3eb377", "src_uid": "821c0e3b5fad197a47878bba5e520b6e", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def find_div(n)\n sq = Math.sqrt(n).floor\n (2..sq).each do |i|\n next if (n % i) != 0\n return n / i\n end\n 1\nend\n\nn = gets.to_i\nans = n\n\nwhile n > 1\n n = find_div(n)\n ans += n\nend\n\nputs ans\n", "lang_cluster": "Ruby", "tags": ["number theory"], "code_uid": "1df7ddc570b8382d7c0ad956f0ec0149", "src_uid": "821c0e3b5fad197a47878bba5e520b6e", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a = gets.split.map(&:to_i)\nputs(((a[2] == 0 && a[3] != 0) or (a[0] == 0 && a[1] != 0 && a[2] * a[3] != 0) or (a[0] * a[2] * a[4] < a[1] * a[3] * a[5])) ? \"Ron\" : \"Hermione\")", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "ddfbec8dfc42a3891a60255bc9db7953", "src_uid": "44d608de3e1447f89070e707ba550150", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a, b, c, d, e, f = gets.split(' ').map{|s| s.to_i}\nab, cd, ef = [[a, b], [c, d], [e, f]].map{|aa, bb|bb/aa.to_f}\ng = ab*cd*ef\nm = [cd.infinite?, ab.infinite?&&cd>0, ef.infinite?&&ab>0&&cd>0]\nputs (m.any?||g>1.0) ? 'Ron' : 'Hermione'", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "8e8ddfd16c7b4ab68af180d10b8fa4ce", "src_uid": "44d608de3e1447f89070e707ba550150", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b,c,d,e,f = gets.split(' ').map(&:to_i)\nif (c==0 && d !=0) || (a==0 && b !=0 && c*d !=0)\n puts \"Ron\"\nelse\n if (a*c*e) < (b*d*f)\n puts \"Ron\"\n else\n puts \"Hermione\"\n end\nend", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "13e25d19a5c656a04d4817192ad00de9", "src_uid": "44d608de3e1447f89070e707ba550150", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,*a=$<.read.split.map &:to_i\ns=a.reduce :+\nputs (1<0}.map{|j|a[j]}.reduce 0,:+;(s-2*t)%360==0} ? :YES : :NO", "lang_cluster": "Ruby", "tags": ["brute force", "dp", "bitmasks"], "code_uid": "3f0fdadee0c97c03185d185a817975ae", "src_uid": "01b50fcba4185ceb1eb8e4ba04a0cc10", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "N = gets.to_i\nas = [0]\nbs = nil\nN.times {\n rot = gets.to_i\n bs = as.map{ |a| [(a+rot)%360, (a-rot+360)%360]}.flatten.uniq\n as,bs = bs,as\n}\nputs as.include?(0) ? \"YES\" : \"NO\"", "lang_cluster": "Ruby", "tags": ["brute force", "dp", "bitmasks"], "code_uid": "a969f365f6a9b02277eaa66b5abc3211", "src_uid": "01b50fcba4185ceb1eb8e4ba04a0cc10", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets().to_i\narr = []\nn.times do\n arr += [gets().to_i]\nend\ncur = \"0\" * n\nlast = \"1\" * n\nf = false\nwhile (cur.to_i(10) < last.to_i(10))\n d = 0\n arr.each_with_index do |e, ind|\n if cur[ind] == '0'\n d -= e\n else\n d += e\n end\n end\n if (d % 360 == 0)\n f = true\n break\n end\n cur = (cur.to_i(2) + 1).to_s(2)\n # puts cur\n cur = (\"0\" * (n - cur.size)) + cur\nend\nif f\n puts \"YES\"\nelse\n puts \"NO\"\nend", "lang_cluster": "Ruby", "tags": ["brute force", "dp", "bitmasks"], "code_uid": "e556e8903305fa030296aeb0b957fa89", "src_uid": "01b50fcba4185ceb1eb8e4ba04a0cc10", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.chomp.to_i\ndays = 0\nif n <= 2\n puts \"0 #{n}\"\nelsif n <= 5\n puts \"0 2\"\nelsif n < 7\n puts \"#{n - 5} 2\"\nelse\n min_offs = 0\n remaining_days = n\n begin\n days += 7\n min_offs += 2\n remaining_days -= 7\n end while remaining_days >= 7\n max_offs = min_offs\n if remaining_days > 5\n min_offs += remaining_days - 5\n max_offs += 2\n elsif remaining_days < 2\n max_offs += remaining_days\n else\n max_offs += 2\n end\n puts \"#{min_offs} #{max_offs}\"\nend\n", "lang_cluster": "Ruby", "tags": ["math", "greedy", "constructive algorithms", "brute force"], "code_uid": "d8e6ecf2565abc6d117aba0765a53c5f", "src_uid": "8152daefb04dfa3e1a53f0a501544c35", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = readline.to_i\nmax, min = 0, 0\nmax = n / 7\nmin = n / 7\nmax *= 2\nmin *= 2\nn %= 7\nmax += [n, 2].min\nmin += [0, n - 5].max\nprint min, \" \", max\nputs \"\"\n", "lang_cluster": "Ruby", "tags": ["math", "greedy", "constructive algorithms", "brute force"], "code_uid": "15085a4bc2ab87e25dc3f5753184873b", "src_uid": "8152daefb04dfa3e1a53f0a501544c35", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\nmin = n/7*2\nmax = min\nn%=7\n\nif n < 7\n\tmax += n%7 > 2 ? 2 : n%7\n\tif n%7 == 6\n\t\tmin += 1\t\t\n\tend\n\tputs \"#{min} #{max}\"\t\nend\n", "lang_cluster": "Ruby", "tags": ["math", "greedy", "constructive algorithms", "brute force"], "code_uid": "2e08fe0ef36a85ee7ccf30ed77e1f3e2", "src_uid": "8152daefb04dfa3e1a53f0a501544c35", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = gets.strip\nif !s.include?( '/' )\n\ts += \"/a\"\nend\nputs /^\\w{1,16}@\\w{1,16}(\\.\\w{1,16})*\\/\\w{1,16}$/ =~ s && s.index( \"/\" ) - s.index( \"@\" ) - 1 <= 32 ? \"YES\" : \"NO\"\n", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "3d31ca719f7094d5bda2380e6c220389", "src_uid": "2a68157e327f92415067f127feb31e24", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "puts gets=~/^\\w{1,16}@\\w{1,16}(\\.\\w{1,16})*(\\/\\w{1,16})?\\n$/?\"YES\":\"NO\"", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "9eae9c0a5bce9c5b8d9171d7fc5bf50f", "src_uid": "2a68157e327f92415067f127feb31e24", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "puts gets=~/^\\w{1,16}@\\w{1,16}(\\.\\w{1,16})*(\\/\\w{1,16})?\\n$/?\"YES\":\"NO\"\n", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "b486cb91ec97c44c0a1fa643495a18d0", "src_uid": "2a68157e327f92415067f127feb31e24", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/ruby\n\ndef solution(n, arr)\n ans = 0\n m = arr[0]\n arr = arr.slice 1, arr.length\n while arr.any? {|a|a >= m}\n m += 1\n arr.sort!.reverse!\n arr[0]-=1\n ans += 1\n end\n puts ans\nend\n\nn = gets.to_i\narr = gets.split(' ').map{|i| i.to_i}\nsolution n, arr\n#\n# solution 5, [5,1,11,2,8]\n# solution 4, [1,8,8,8]\n# solution 2, [7,6]", "lang_cluster": "Ruby", "tags": ["greedy", "implementation"], "code_uid": "5cbb4bed0f66b16372460e3fb6e5e829", "src_uid": "aa8fabf7c817dfd3d585b96a07bb7f58", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a=gets.chomp.to_i\nb=gets.chomp.split(\" \")\nlm=b.delete_at(0).to_i\nans=0\n0.upto(a-2) {|i| b[i]=b[i].to_i}\nb.sort!\nb.reverse!\n\nloop do \ntrig=0\ntemp=0\nmax=b[0]\n\n1.upto(a-2) do|i|\nif b[i]>max\ntemp=i\nmax=b[i]\nend\nend\n\nif b[temp]>=lm\nans+=1\nlm+=1\nb[temp]-=1\ntrig=1\nend\nif trig ==0\nbreak\nend\nend\nputs \"#{ans}\"", "lang_cluster": "Ruby", "tags": ["greedy", "implementation"], "code_uid": "e968101545143c922964ed0c99f0e6bd", "src_uid": "aa8fabf7c817dfd3d585b96a07bb7f58", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "u = [0]*10000\na = gets.chomp.to_i\nb = gets.chomp.split(' ')\nstart = b[0].to_i\nme = start\nmx = 0\nb.delete_at(0)\nb.each do |i|\n i = i.to_i\n u[i]+=1\n mx=i if mx0 and me<=i\n me+=1\n u[i]-=1\n end\n u[i-1]+=z\n i-=1\nend\nif me == i\n me+=1\nend\nprint me-start\n", "lang_cluster": "Ruby", "tags": ["greedy", "implementation"], "code_uid": "a95c279ecbde289e67fbcda1e127713a", "src_uid": "aa8fabf7c817dfd3d585b96a07bb7f58", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["math", "greedy"], "code_uid": "c41b547394fab140b44f531bc5aac1a3", "src_uid": "8787c5d46d7247d93d806264a8957639", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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\n", "lang_cluster": "Ruby", "tags": ["math", "greedy"], "code_uid": "9711157bbbe589f1e9ece5e6e4f29765", "src_uid": "8787c5d46d7247d93d806264a8957639", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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\n", "lang_cluster": "Ruby", "tags": ["math", "greedy"], "code_uid": "1a4e31ce9bb09115aa2f0e20b5b64ee7", "src_uid": "8787c5d46d7247d93d806264a8957639", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "k=gets.to_i;b=Array.new(10,0)\n4.times{gets.split(\"\").map{|v|if v.to_i>0;b[v.to_i]+=1;end}}\nputs b.select{|v|v>k*2}.size>0?\"NO\":\"YES\"\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "1ce6bd852093a6f0fe235248e5f844c2", "src_uid": "5fdaf8ee7763cb5815f49c0c38398f16", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def main()\n k=gets.chomp.to_i\n mat=Array.new(4){Array.new(4)}\n for i in 1..4\n st=gets.chomp\n for j in 1..4\n mat[i-1][j-1]=st[j-1].chr.to_i\n end\n end\n f=true\n for i in 1..9\n toti=0\n for j in 0...4\n toti+=mat[j].count(i)\n end\n if toti>2*k\n f=false\n break;\n end\n end\n if f\n puts \"YES\"\n else\n puts \"NO\"\n end\nend\nmain()", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "a2b9fe5457ed1b30f1a492797f8d0009", "src_uid": "5fdaf8ee7763cb5815f49c0c38398f16", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a=gets.chomp.to_i*2\nhash=Hash.new(0)\n4.times do\ntemp=gets.chomp\ntemp.each_char do |i|\nif i!=\".\"\nhash[i]+=1\nend\nend\nend\nk=hash.values.sort.reverse\n\nif k.length!=0 \nif k[0]>a\nputs \"NO\"\nelse \nputs \"YES\"\nend\nelse\nputs \"YES\"\nend", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "39c22394334a02ea272c56c3b1f41e8b", "src_uid": "5fdaf8ee7763cb5815f49c0c38398f16", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.chomp.to_i\ndp1, dp2 = 20, 7\nmod = 1000000007\n(n - 1).times {\n dp1, dp2 = (dp1 * 27 + dp2 * 20) % mod, dp2 * 7 % mod \n}\nputs dp1\n", "lang_cluster": "Ruby", "tags": ["combinatorics"], "code_uid": "cb86dc6417177c304c26bff4ee284dc3", "src_uid": "eae87ec16c284f324d86b7e65fda093c", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "p=gets.chomp.to_i\ndef MOD (n,p)\n\tif p>19\n\tpmin=(Math.log(1000000007,n)).ceil\n\tpc=p/pmin\n\tpl=p%pmin\n\treturn ((MOD((n**pmin % 1000000007),pc) * (n**pl) ) % 1000000007)\n\telse\n\treturn (n**p)%1000000007\n\tend\n\tend\n\t\n\tc=(MOD(3,3*p)- MOD(7,p))% 1000000007\n\tputs \"#{c}\"", "lang_cluster": "Ruby", "tags": ["combinatorics"], "code_uid": "ab0fd38a72777b7eb3019e0518c37d4a", "src_uid": "eae87ec16c284f324d86b7e65fda093c", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "Mod = (1e9 + 7).to_i\n\nn = gets.to_i\n\nans1 = 1\nans2 = 1\n\nn.times do\n\tans1 *= 27\n\tans2 *= 7\n\n\tans1 %= Mod\n\tans2 %= Mod\nend\n\nans = (ans1 - ans2 + Mod) % Mod\nputs ans\n", "lang_cluster": "Ruby", "tags": ["combinatorics"], "code_uid": "6e4af2528f75ae02b4bd2d471136f866", "src_uid": "eae87ec16c284f324d86b7e65fda093c", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/ruby\nt,s,q=gets.split.map(&:to_i)\ni=0\nwhile s= k\n puts n*3-k\nelse\n puts 0\nend\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "d7b43765e0ad059aa708de3cd6e36de5", "src_uid": "5a5e46042c3f18529a03cb5c868df7e8", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "\ufeff# codeforce#122(Div2.A)\nn, k = gets.chomp.split(\" \").map{|e| e.to_i}\n\n0.upto(n) do |i|\n if (i * 2 + 5 * (n - i)) >= k and (i * 2 + 3 * (n - i)) <= k\n puts i\n break\n end\nend", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "ed893fa41ca48d27cd88e8229e2c4d3f", "src_uid": "5a5e46042c3f18529a03cb5c868df7e8", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,k = gets.split(\" \").map(&:to_i)\nq = k/n\nre = 0\nre = n - (k % n) if q == 2\nputs re", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "5316b0e3fd2e54ad1520daa5674e0109", "src_uid": "5a5e46042c3f18529a03cb5c868df7e8", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "l, r = gets.split.map(&:to_i)\nans = 0\nfor i in 0..32 do\n for j in 0..25 do\n now = (2**i)*(3**j)\n if( now >= l && now <= r)\n ans += 1\n end\n end\nend\n\np ans\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "e04d6cab3ebba57b02eb2a5f6fe0c6e2", "src_uid": "05fac54ed2064b46338bb18f897a4411", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "# cook your code here\na, b = gets.split.map(&:to_i);\nk = 0;\n(0..32).each do |x|\n (0..20).each do |y|\n r = (2**x) * (3**y);\n if a <= r && r <= b then\n k = k + 1;\n end\n end\nend\nputs k.to_s;", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "11a54e42f0f15f391b2c6b97ac3cebc5", "src_uid": "05fac54ed2064b46338bb18f897a4411", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "xxx=->{gets.split.map &:to_i}\nl,r=xxx[]\nans = 0\nfor i in (0..60)\n for j in (0..60)\n if ((2 ** i) * (3 ** j) >= l && (2 ** i) * (3 ** j) <= r)\n ans += 1\n end\n end\nend\nprint ans", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "9203ae47847ef67605ef4b9da3ed2ab2", "src_uid": "05fac54ed2064b46338bb18f897a4411", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = gets.chomp\nt = 'CODEFORCES'\ni, j = 0, 0\ns.each_char do |x|\n break if x != t[i]\n i += 1\nend\n(s.size - 1).downto(0) do |k|\n break if s[k] != t[9 - j]\n j += 1\nend\nputs i + j >= 10 ? 'YES' : 'NO'\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "222449937b750273e0fbd3fac1e1c4c5", "src_uid": "bda4b15827c94b526643dfefc4bc36e7", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "phrase = gets.strip\nrv_phrase = phrase.reverse\nlen = phrase.length\nfor i in 0..len\n\tfor j in 0..len - i\n\t\ttmp = phrase[0, i] << rv_phrase[0, j].reverse\n\t\tif tmp.eql? 'CODEFORCES'\n\t\t\tputs \"YES\"\n\t\t\texit\n\t\tend\n\tend\nend\nputs \"NO\"\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "a9cc94e966a244aa5a214c76986324b5", "src_uid": "bda4b15827c94b526643dfefc4bc36e7", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "str = gets.strip\ncmp = \"CODEFORCES\"\nleft = 0\nright = 0\n0.upto(cmp.size-1) do |i|\n break if i >= str.size\n break if str[i] != cmp[i]\n left += 1\nend\n0.upto(cmp.size-1) do |i|\n break if i >= str.size\n break if str[str.size-i-1] != cmp[cmp.size-i-1]\n right += 1\nend\n\nif left + right >= cmp.size\n puts \"YES\"\nelse\n puts \"NO\"\nend\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "f9e6c4c14af83d16875992c1303b7296", "src_uid": "bda4b15827c94b526643dfefc4bc36e7", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\nputs (n - 1) / 2\n", "lang_cluster": "Ruby", "tags": ["math", "greedy", "constructive algorithms"], "code_uid": "9a853b5a4efb7094060e2c1648d74e86", "src_uid": "dfe9446431325c73e88b58ba204d0e47", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "p (gets.to_i-1)/2", "lang_cluster": "Ruby", "tags": ["constructive algorithms"], "code_uid": "6e9b7ec0d680a78da4d580854a0c5f12", "src_uid": "dfe9446431325c73e88b58ba204d0e47", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!ruby\np (gets.to_i-1)/2\n", "lang_cluster": "Ruby", "tags": ["constructive algorithms"], "code_uid": "a3e39c3a22bfb8bc1a0a881f2f99693d", "src_uid": "dfe9446431325c73e88b58ba204d0e47", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, a, b = gets.split.map(&:to_i)\nputs (a - 1 + b) % n + 1\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "3f561536898abe671774542255840cdc", "src_uid": "cd0e90042a6aca647465f1d51e6dffc4", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, a, b = gets.split.map &:to_i;\nputs (n * 1000 + a + b - 1) % n + 1", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "484c6f9e98b4b540a238529e9897415e", "src_uid": "cd0e90042a6aca647465f1d51e6dffc4", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, a, b = gets.split.map(&:to_i)\n\na += b\n\na += 100 * n if a < 0\na %= n if a >= n\na = n if a == 0\n\nputs a", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "e587469b329265e0767a56327b93bb83", "src_uid": "cd0e90042a6aca647465f1d51e6dffc4", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def flips\n n = gets.chomp.to_i\n arr = []\n lowerTotal = 0\n upperTotal = 0\n n.times do\n split = gets.chomp.split(\" \")\n lower = split[0].to_i\n upper = split[1].to_i\n lowerTotal += lower\n upperTotal += upper\n arr.push([lower, upper])\n end\n\n if (lowerTotal % 2 == 0 && upperTotal % 2 == 0)\n puts \"0\"\n return\n elsif (lowerTotal % 2 != upperTotal % 2)\n puts \"-1\"\n return\n end\n\n if arr.length == 1\n puts \"-1\"\n return\n end\n\n isFlip = false\n arr.each do |e|\n if e[0] % 2 != e[1] % 2\n isFlip = true\n end\n end\n\n if isFlip\n puts \"1\"\n return\n end\n\n puts \"-1\"\nend\n\nflips\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "611c4876a863f21c13ac5549e3cebfe9", "src_uid": "f9bc04aed2b84c7dd288749ac264bb43", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\na = n.times.map{gets.split.map(&:to_i)}\nc = Array.new(4, 0)\na.each do |x, y|\n case [x.even?, y.even?]\n when [true, true]\n c[0] += 1\n when [true, false]\n c[1] += 1\n when [false, true]\n c[2] += 1\n when [false, false]\n c[3] += 1\n end\nend\nif (c[2] + c[3]) % 2 == 0 && (c[1] + c[3]) % 2 == 0\n puts 0\nelsif ((c[1] + c[2]).even? && c[1] + c[2] != 0) || (c[1].odd? && c[2].odd? && c[3].odd?)\n puts 1\nelse\n puts -1\nend\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "d733a4722663397a8b51e30b0cd08c9a", "src_uid": "f9bc04aed2b84c7dd288749ac264bb43", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "c0cc8b84fa93772a55fcd9fb9e1741a5", "src_uid": "f9bc04aed2b84c7dd288749ac264bb43", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "e815012b4f42e61ac54ce06311fb5c44", "src_uid": "d215b3541d6d728ad01b166aae64faa2", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\nary = gets.strip.split.map(&:to_i)\n\nev = ary.inject(:+)\n(ary.max).upto(1000).each do |k|\n av = ary.map{|x| [0,k-x].max }.inject(:+)\n if av>ev\n puts k\n break\n end\nend", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "822341ac179039c7ac659781f5f96576", "src_uid": "d215b3541d6d728ad01b166aae64faa2", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,*a=$<.read.split.map &:to_i\np [*a,2*a.reduce(:+)/n+1].max", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "f209ea1e120ec80ad411722289d3d91c", "src_uid": "d215b3541d6d728ad01b166aae64faa2", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["brute force", "implementation", "combinatorics"], "code_uid": "04b686ca74c1e761f7093a8d35f15a42", "src_uid": "08f85cd4ffbd135f0b630235209273a4", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["brute force", "implementation", "combinatorics"], "code_uid": "d1efc65c6911340dd4f7a1fa18659be3", "src_uid": "08f85cd4ffbd135f0b630235209273a4", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["brute force", "implementation", "combinatorics"], "code_uid": "beb386ca442d9acb33e37438856ccfba", "src_uid": "08f85cd4ffbd135f0b630235209273a4", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "gets;p (0..2).map{|i|30+i+~-$_.split[i].to_i/2*3}.max", "lang_cluster": "Ruby", "tags": ["math", "greedy"], "code_uid": "da281f639614f0d9ecbfe1026706a3cc", "src_uid": "a45daac108076102da54e07e1e2a37d7", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def solve\n \n r, g, b = readline.split(' ')\n r = r.to_i; g = g.to_i; b = b.to_i\n t = -1\n \n while ( r > 0 || g > 0 || b > 0 ) do\n t += 1;\n r -= 2 if (t % 3 == 0) \n g -= 2 if (t % 3 == 1)\n b -= 2 if (t % 3 == 2)\n end\n \n return t + 30\n \n end\n \n #$stdin = File.open(\"in.txt\", \"r\")\n puts solve", "lang_cluster": "Ruby", "tags": ["math", "greedy"], "code_uid": "924bdcd6836c4bbe668ad31c23ce6502", "src_uid": "a45daac108076102da54e07e1e2a37d7", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "gets;p (0..2).map{|i|30+i+~-$_.split[i].to_i/2*3}.max\n", "lang_cluster": "Ruby", "tags": ["math", "greedy"], "code_uid": "350e1b24c470f12a2a433e3cdc2e7012", "src_uid": "a45daac108076102da54e07e1e2a37d7", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\na, b = 1, n\n(1..Math.sqrt(n)).each do |i|\n a, b = i, n / i if n % i == 0\nend\nputs \"#{a} #{b}\"\n", "lang_cluster": "Ruby", "tags": ["brute force", "math"], "code_uid": "1831c8467a55013f46aa48b978e25055", "src_uid": "f52af273954798a4ae38a1378bfbf77a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\nx = 0\ny = 0\nfor i in 1..Math.sqrt(n).round\n if (n%i === 0)\n x = i\n y = n/i\n end\nend\nprint x\nprint \" \"\nprint y\n", "lang_cluster": "Ruby", "tags": ["brute force", "math"], "code_uid": "bb4806b272344dbe06a5b46fc1b03693", "src_uid": "f52af273954798a4ae38a1378bfbf77a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\na = (1..n).select { |x| x * x <= n && n % x == 0 }.last\nputs [a, n / a].join(' ')\n", "lang_cluster": "Ruby", "tags": ["brute force", "math"], "code_uid": "5b3aa47fc1d6743aea4a7ef619b1ac39", "src_uid": "f52af273954798a4ae38a1378bfbf77a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "p,d=gets.split.map &:to_i;z=p;d=p-d;t=10;loop{p-=(p+1)%t;break if p= limit\n return numbers\n end\n\n numbers = lucky_numbers(numbers, current * 10 + 4, limit)\n\n lucky_numbers(numbers, current * 10 + 7, limit)\nend\n\nn = gets.to_i\n\nputs lucky_numbers([], 4, n).concat(lucky_numbers([], 7, n)).sort.find_index(n) + 1\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation", "combinatorics", "bitmasks"], "code_uid": "8fd34d7bc674d177f6b7641d9e133de9", "src_uid": "6a10bfe8b3da9c11167e136b3c6fb2a3", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\nk = n\nsum = 0\nwhile k > 0 do\n sum += (n-k + 1) * (k - 1) + 1\n k -= 1\nend\nputs sum", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "649b0ced4a070d0ae61531de8b83f3b6", "src_uid": "6df251ac8bf27427a24bc23d64cb9884", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\nar = (1...n).to_a\nputs n + ar.reverse.zip(ar).map{|x,y| x*y}.inject(:+) if n>1\nputs 1 if n==1", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "e6a267bc727596b20d5e58320a34c1f2", "src_uid": "6df251ac8bf27427a24bc23d64cb9884", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = $stdin.readline.to_i\n\ndef s(n)\n n*(n-1)/2\nend\n\ndef k(n,l)\n if n == 1\n return 1+l\n else\n if l > 0\n return n*l + k(n-1, l+1)\n else\n return n-1 + k(n-1, l+1)\n end\n end\nend\n\nputs k(n,0)", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "b6e9f3063fea49ed8f79c2e2f157a888", "src_uid": "6df251ac8bf27427a24bc23d64cb9884", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "f37a5d1624abecff6aae58b5000b79c4", "src_uid": "ac244791f8b648d672ed3de32ce0074d", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets\nstr = gets\nmas = str.split(\"\").sort {|x, y| y <=> x }\nstr = mas.join\nper = 0\n(str.size - 1).times do |i|\n\tif str[i] == \"1\" and str[i+1] == \"1\"\n\t\tper = i + 1\n\tend\nend\nputs str[per..str.size]", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "2e8b3e191ce2f2bcc2b5d6dbede17281", "src_uid": "ac244791f8b648d672ed3de32ce0074d", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\ns = gets.chomp\nc = s.count(?0)\nans = '0' * c\nif s.count(?1) > 0\n ans = '1' + ans\nend\nputs ans", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "a5a1312d21944a419f8de36a44f1713f", "src_uid": "ac244791f8b648d672ed3de32ce0074d", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,d = gets.split.map(&:to_i)\nx = gets.split.map(&:to_i)\nx.sort!\nans = n-1\nn.times do |i|\n n.times do |j|\n a = (x[i] - x[j]).abs\n b = i + (n-1-j)\n ans = b if b < ans && a <= d\n end\nend\nputs ans\n", "lang_cluster": "Ruby", "tags": ["brute force", "sortings", "greedy"], "code_uid": "96a4853eb5670f50a5eb82d3b3068af7", "src_uid": "6bcb324c072f796f4d50bafea5f624b2", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["brute force", "sortings", "greedy"], "code_uid": "61a26e28c92d12800fb26511d1fc5a28", "src_uid": "6bcb324c072f796f4d50bafea5f624b2", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def getar\n return gets.split.map &:to_i\nend\ns = gets\na = getar\nb = getar\nc = a & b\n\nputs c.size > 0 ? c.min : [a.min,b.min].min.to_s + [a.min,b.min].max.to_s\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "a9780edbfba1b960d7b1e54dcb934b84", "src_uid": "3a0c1b6d710fd8f0b6daf420255d76ee", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "class Solver1\n def self.solve(arr)\n l1 = arr[0]\n l2 = arr[1]\n uniq = l2 & l1\n return uniq.min if uniq.size > 0\n min1 = l1.min\n min2 = l2.min\n return [(min2.to_s + min1.to_s).to_i, (min1.to_s + min2.to_s).to_i].min\n end\nend\nstring = ARGF.read\narr = string.split(\"\\n\")\narr.map! { |elem| elem.strip }\narr1 = arr.drop(1)\narr1.map! { |elem| elem.split }\nputs Solver1.solve(arr1)\nexit(true)\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "c95a40b9605dc2c9bf9cf481c7338bb9", "src_uid": "3a0c1b6d710fd8f0b6daf420255d76ee", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, m = gets.split.map(&:to_i)\na = gets.split\nb = gets.split\nfor i in 1 .. 99\n oka = false\n okb = false\n for c in i.to_s.split('')\n if a.include?(c)\n oka = true\n end\n if b.include?(c)\n okb = true\n end\n end\n if oka && okb\n puts i\n exit 0\n end\nend\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "61f72498def54c88e65201b959828083", "src_uid": "3a0c1b6d710fd8f0b6daf420255d76ee", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,d=gets.split(\" \").map {|x| x.to_i} \ncnt=0\ni=0\nraw=gets.split(\" \").map {|x| x.to_i}\nwhile(id)\n puts \"-1\"\nelse\n print \"#{2*(n-1)+(d-l)/5}\"\nend", "lang_cluster": "Ruby", "tags": ["greedy", "implementation"], "code_uid": "7f7d152a375b7f4c59a8b7c4098fa6ea", "src_uid": "b16f5f5c4eeed2a3700506003e8ea8ea", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,d=gets.split.map &:to_i\nmas=gets.split.map &:to_i\nc= (n-1)*10\nf=mas.inject(:+)\nif c+f > d\n puts -1\n exit\nelse\n puts (d-f)/5\nend", "lang_cluster": "Ruby", "tags": ["greedy", "implementation"], "code_uid": "9e19365faa33a332f59914db4115f52b", "src_uid": "b16f5f5c4eeed2a3700506003e8ea8ea", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a=gets.chomp.split(\" \")\nb=gets.chomp.split(\" \")\nsum=(a[0].to_i-1)*10\nb.each {|i| sum+=i.to_i}\nif sum>a[1].to_i\nputs \"-1\"\nelse\nans=(a[0].to_i-1)*2+(a[1].to_i-sum)/5\nputs \"#{ans}\"\nend", "lang_cluster": "Ruby", "tags": ["greedy", "implementation"], "code_uid": "5402ca6581ff314004987c9ee2a934ce", "src_uid": "b16f5f5c4eeed2a3700506003e8ea8ea", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "x,y = gets.split.map(&:to_i)\nd = x.times.map{gets.strip.chars.to_a}\nsum_i,sum_j = 0,0\nd.each {|x| sum_i+=1 if (x.sort.reverse.first == \".\")}\nd.transpose.each{|x| sum_j+=1 if(x.sort.reverse.first == \".\")}\np (sum_i*y)+(sum_j*x)-(sum_i*sum_j)", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "0ed66749af8cf4c35edfdaf308e82936", "src_uid": "ebaf7d89c623d006a6f1ffd025892102", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "r, c = gets.split.map(&:to_i)\na = r.times.map{gets.chomp.chars}\nrr = a.count{|x| x.include?('S')}\ncc = a.transpose.count{|x| x.include?('S')}\nputs r * c - rr * cc\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "7ef547fc5ae92b8b1c011255a33b0eeb", "src_uid": "ebaf7d89c623d006a6f1ffd025892102", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "r,c=gets.chomp.split.map(&:to_i)\na=[]\nr.times do\n\tb=gets.chomp.strip.split('')\n\ta.push(b)\nend\nrow=Array.new(20,0)\ncol=Array.new(20,0)\ni,j=0,0\nwhile i0\n\t\tk+=1\n\tend\n\tif col[i]>0\n\t\tl+=1\n\tend\nend\nputs (r*c)-(k*l)", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "ed248bb9a50a32d91c126a04365187bf", "src_uid": "ebaf7d89c623d006a6f1ffd025892102", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.chomp.to_i\n\nslimes = []\nn.times do\n slimes << 1\n while slimes.size >= 2 && slimes.last(2).uniq.length == 1\n v = slimes.pop(2)\n slimes << v[0] + 1\n end\nend\nputs slimes.join(\" \")\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "614ae043a5f5fa4cf0bc952408a4fe07", "src_uid": "757cd804aba01dc4bc108cb0722f68dc", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.to_i;puts 20.downto(1).select{|e|n[e-1]==1}*' '\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "06470a73955b31b64b5a34e12914d0c6", "src_uid": "757cd804aba01dc4bc108cb0722f68dc", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/env ruby\n\nslizen = gets.to_i\n\nresult = []\nfat = 1\n\nloop do\n break if slizen == 0\n result << fat if slizen%2 == 1\n slizen/=2\n fat+=1\nend\n\nprint result.reverse.join(' ')", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "a51af8ffd79ef97ece88791145afaf58", "src_uid": "757cd804aba01dc4bc108cb0722f68dc", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b=gets.split.map &:to_i\n30.times{\n\ta%=2*b if b>0\n\tb%=2*a if a>0\n}\nputs [a,b]*' '", "lang_cluster": "Ruby", "tags": ["math", "number theory"], "code_uid": "a800df92ea27d08ee58481491b194358", "src_uid": "1f505e430eb930ea2b495ab531274114", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a, b = gets.split.map(&:to_i)\nwhile a*b != 0\nif a >= 2*b\n a%=2*b\nelsif b >= 2*a\n b%=2*a\nelse\n break\nend\nend\nputs [a, b].join(\" \")", "lang_cluster": "Ruby", "tags": ["math", "number theory"], "code_uid": "b8c62e1183aabc0ba2c03afee2bcb114", "src_uid": "1f505e430eb930ea2b495ab531274114", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["math", "number theory"], "code_uid": "5e92efe430f7dcb99cb1383dc0d011da", "src_uid": "1f505e430eb930ea2b495ab531274114", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["combinatorics"], "code_uid": "d96a7b54fc06bb5c6ad0cac196d4dde6", "src_uid": "cc838bc14408f14f984a349fea9e9694", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "$md = 1000000007;\ndef pow(x, y)\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\nn, k = gets.split.map(& :to_i)\np pow(k, k - 1) * pow(n - k, n - k) % $md\n\n", "lang_cluster": "Ruby", "tags": ["combinatorics"], "code_uid": "c89266a252e633b8725701ae256c62bc", "src_uid": "cc838bc14408f14f984a349fea9e9694", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, v = gets.split.map(&:to_i)\nans = fuel = 0\n(1..n).each do |i|\n if fuel == 0\n fuel = n > v ? v : n - 1\n ans += fuel * i\n next\n end\n if n - i >= v\n fuel += 1\n ans += i\n end\n fuel -= 1\nend\nputs ans", "lang_cluster": "Ruby", "tags": ["math", "greedy", "dp"], "code_uid": "64dec9af7bd2fcf41028497b135b4659", "src_uid": "f8eb96deeb82d9f011f13d7dac1e1ab7", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["math", "greedy", "dp"], "code_uid": "34dd74e192c2de8e0e5b08ee27cde3ca", "src_uid": "f8eb96deeb82d9f011f13d7dac1e1ab7", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,v = gets.split.map(&:to_i)\nans = [n-1,v].min\n(n-v-1).times do |i|\n ans += i+2\nend\nputs ans", "lang_cluster": "Ruby", "tags": ["math", "greedy", "dp"], "code_uid": "a5eaeea6d942d6fe9b95714157705b2b", "src_uid": "f8eb96deeb82d9f011f13d7dac1e1ab7", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["sortings", "dp", "greedy"], "code_uid": "778d3d576a3ac02b4571b161d556beb7", "src_uid": "b3f8e769ee7719ea5c9f458428b16a4e", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.to_i\nx=1378\nr=1\nwhile n>0\n r=r*x%10 if n.odd?\n x=x*x%10\n n>>=1\nend\np r\n", "lang_cluster": "Ruby", "tags": ["math", "implementation", "number theory"], "code_uid": "533b8030cd42304cbb7c428214ac3b35", "src_uid": "4b51b99d1dea367bf37dc5ead08ca48f", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i \n\nif n == 0 \n puts \"1\" \nelse \n case n%4 \n when 1\n puts \"8\" \n when 2 \n puts \"4\"\n when 3 \n puts \"2\" \n when 0 \n puts \"6\"\n end\nend \n\n", "lang_cluster": "Ruby", "tags": ["math", "implementation", "number theory"], "code_uid": "0faf1eec95e4de694052e01a269d5077", "src_uid": "4b51b99d1dea367bf37dc5ead08ca48f", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\n# power of 1378, and last digit\n# and cyclic.\n# 1 -> 8, 2 -> 4, 3 -> 2, 4 -> 6,\n# 5 -> 8, 6 -> 4, 7 -> 2, 8 -> 6,\n# 9 -> ...\n# 4n + 1\nn = gets.to_i\nif n == 0\n puts 1\nelse\n puts 8 if n%4 == 1\n puts 4 if n%4 == 2\n puts 2 if n%4 == 3\n puts 6 if n%4 == 0\nend\n", "lang_cluster": "Ruby", "tags": ["math", "implementation", "number theory"], "code_uid": "f379e8c334c553278b1b33891a0ed88e", "src_uid": "4b51b99d1dea367bf37dc5ead08ca48f", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/Users/mike/.rvm/rubies/ruby-1.9.3-p327/bin/ruby\n\nextensionNum, deviceNum, socketNum = STDIN.readline.split.collect {|s| s.to_i}\nextensions = STDIN.readline.split.collect {|s| s.to_i}\nextensions = extensions.sort.reverse\n\nsocketCount, extensionCount = socketNum, 0\nwhile socketCount < deviceNum\n\tif extensionCount == extensionNum\n\t\textensionCount = -1\n\t\tbreak\n\tend\n\tsocketCount += extensions[extensionCount]-1\n\textensionCount += 1\nend\n\nputs extensionCount\n", "lang_cluster": "Ruby", "tags": ["sortings", "implementation", "greedy"], "code_uid": "c5bb1e8386a8400b5fe12e2c037999ab", "src_uid": "b32ab27503ee3c4196d6f0d0f133d13c", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,m,k=gets.split.map(&:to_i)\na=gets.split.map(&:to_i).sort {|i,j| j<=>i}\n\nif k>=m\n puts 0\n exit\nend\n\ni=0\nwhile k>0 && i= m\n\n socket_count = k - 1\n filter_count = 1\n\n filters.sort_by! { |x| -x }\n filters.each do |item|\n return filter_count if item + socket_count >= m\n\n socket_count += item - 1\n filter_count += 1\n end\n\n return -1\nend\n\nif $0 == __FILE__\n ARGF.readlines.each_slice(2) do |line1, line2|\n n, m, k = line1.chomp.split.map {|x| x.to_i }\n filters = line2.chomp.split.map {|x| x.to_i }\n puts calc(m, k, filters)\n end\nend\n", "lang_cluster": "Ruby", "tags": ["sortings", "implementation", "greedy"], "code_uid": "01efb3abba61e6e63c2f765d564ff19f", "src_uid": "b32ab27503ee3c4196d6f0d0f133d13c", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b,c=gets.split.map(&:to_i)\ns=(a+b+c)/2\nputs (a+b+c).odd?||s-a<0||s-b<0||s-c<0 ? \"Impossible\": \"#{s-c} #{s-a} #{s-b}\"", "lang_cluster": "Ruby", "tags": ["brute force", "math", "graphs"], "code_uid": "0c879314beb5253616378d0ad79b819e", "src_uid": "b3b986fddc3770fed64b878fa42ab1bc", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b,c=gets.split.map(&:to_i)\ns=(a+b+c)/2\nputs (a+b+c)%2!=0||s-a<0||s-b<0||s-c<0 ? \"Impossible\": \"#{s-c} #{s-a} #{s-b}\"", "lang_cluster": "Ruby", "tags": ["brute force", "math", "graphs"], "code_uid": "3419ba9bbdf913c29cae078f4cc3e776", "src_uid": "b3b986fddc3770fed64b878fa42ab1bc", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a, b, c = gets.split.map { |x| x.to_i }\n\nif (a + b + c).odd?\n\tputs 'Impossible'\nelse\n\tsum = (a + b + c) / 2\n\tx, y, z = sum - c, sum - a, sum - b\n\tif x < 0 or y < 0 or z < 0\n\t\tputs 'Impossible'\n\telse\n\t\tputs [x, y, z].join ' '\n\tend\nend", "lang_cluster": "Ruby", "tags": ["brute force", "math", "graphs"], "code_uid": "f41951cdc1b223d922f9aab459af80a7", "src_uid": "b3b986fddc3770fed64b878fa42ab1bc", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = gets\nt = gets\n\ni = 0\n\nt.each_char do |c|\n\tif s[i] == c\n\t\ti+=1\n\tend\nend\n\nputs i+1", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "417f3973d2eae1ae710e049564857f33", "src_uid": "f5a907d6d35390b1fb11c8ce247d0252", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = gets\nx = 0\ngets.each_char do |c|\n x += 1 if c == s[x]\nend\nputs x + 1\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "688dee5ec238ff00f98b1f2ddd650a96", "src_uid": "f5a907d6d35390b1fb11c8ce247d0252", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def run\n s = ARGF.readline.split(//)\n t = ARGF.readline.split(//)\n\n pos = 1\n t.each do |c|\n pos += 1 if c == s[pos - 1]\n end\n\n puts pos\nend\n\nrun if $0 == __FILE__\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "decd1c563cf13a1d8f90f521d581fece", "src_uid": "f5a907d6d35390b1fb11c8ce247d0252", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/ruby\n# coding: utf-8\nn, m = gets.split.map(&:to_i)\nputs [n, m, (n + m) / 3].min\n", "lang_cluster": "Ruby", "tags": ["math", "greedy", "implementation", "number theory"], "code_uid": "065f7bf691c3730e1a2e7b377e05e363", "src_uid": "0718c6afe52cd232a5e942052527f31b", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "nm = gets.chomp.split.map(&:to_i)\nn = nm[0]\nm = nm[1]\n\ndef min(a,b)\n\tif a < b\n\t\treturn a\n\telse\n\t\treturn b\n\tend\nend\n\ncount = 0\nwhile n != 0 && m != 0\n\tif min(n,m) == n\n\t\tn -= 1\n\t\tm -= 2\n\telsif min(n,m) == m\n\t\tn -= 2\n\t\tm -= 1\n\tend\n\tif n >= 0 && m >= 0\n\t\tcount += 1\n\tend\nend\nprint count", "lang_cluster": "Ruby", "tags": ["math", "greedy", "implementation", "number theory"], "code_uid": "289fdd990e5241597f7d40f596f44074", "src_uid": "0718c6afe52cd232a5e942052527f31b", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,m=gets.split.map &:to_i\nans=0\nwhile n>0&&m>0&&n+m>=3\n if n>m\n n-=2\n\tm-=1\n else\n n-=1\n\tm-=2\n end\n ans+=1\nend\np ans", "lang_cluster": "Ruby", "tags": ["math", "greedy", "implementation", "number theory"], "code_uid": "a91df5a159fc43ed217b33f12f0fc168", "src_uid": "0718c6afe52cd232a5e942052527f31b", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/ruby\ndef egcd(x,y)\n return [x,1,0] if y==0\n g,a,b=egcd(y,x%y)\n [g,b,a-x/y*b]\nend\na,b,c=gets.split.map(&:to_i)\ng=a.gcd(b)\nif c%g!=0\n\tputs :No\nelse\n\ta/=g\n\tb/=g\n\tc/=g\n\t_,z1,z2=egcd(a,b)\n\tn=[a,b].max+c\n\tputs (-n..n).find{|i|z1*c+b*i>=0 && z2*c-a*i>=0} ? :Yes : :No\nend", "lang_cluster": "Ruby", "tags": ["brute force", "math", "number theory"], "code_uid": "0bd6d2d66f392cbcbeacd527f8d4922a", "src_uid": "e66ecb0021a34042885442b336f3d911", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a=gets.chomp.split (' ')\nb=a[0].to_i\nc=a[1].to_i\nd=a[2].to_i\n\ntrigar=0\n\n0.upto ((d/b)+1) do |i|\n0.upto ((d/c)+1) do |j|\n\tif (b*i+c*j==d)\n trigar=1\n\tend\n\tbreak if trigar==1\nend\nbreak if trigar==1\nend\n\t\nif (trigar ==1)\nputs \"Yes\"\nelse\nputs \"No\"\nend", "lang_cluster": "Ruby", "tags": ["brute force", "math", "number theory"], "code_uid": "a8572c179d8138f3d40d7c196e478e78", "src_uid": "e66ecb0021a34042885442b336f3d911", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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?", "lang_cluster": "Ruby", "tags": ["brute force", "math", "number theory"], "code_uid": "e4095b6e42140e1e4c8326711d72067d", "src_uid": "e66ecb0021a34042885442b336f3d911", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "# https://codeforces.com/problemset/problem/999/B\ndef solution(n, e)\n d = e\n i = 1\n while i < n do\n next i += 1 unless n % i == 0\n\n d = d[0..i - 1].reverse + d[i..n - 1]\n i += 1\n end\n return d.reverse\nend\n\nn = gets.chomp.to_i\ns = gets.chomp\n\nputs solution(n, s)\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "6bfc33db871c6e624da3a9db8e1e7044", "src_uid": "1b0b2ee44c63cb0634cb63f2ad65cdd3", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "require 'prime'\nn = gets.to_i\na = gets.chomp\n(1..n).select { n % _1 == 0 }.each { |i| a[0, i] = a[0, i].reverse }\nputs a\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "cfab3e33ad5f7f1d976eea232b43f157", "src_uid": "1b0b2ee44c63cb0634cb63f2ad65cdd3", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "ffb621ef24eb7eca18254340eacf378d", "src_uid": "1b0b2ee44c63cb0634cb63f2ad65cdd3", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b,x,y,z=$<.read.split.map &:to_i\na-=2*x\na-=y\nb-=y\nb-=3*z\np [-a,0].max+[-b,0].max", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "9d8e695bbdc72ff5c0dfaca2143274e0", "src_uid": "35202a4601a03d25e18dda1539c5beba", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "A = gets.chomp.split(' ')\nB = gets.chomp.split(' ')\nx = 2 * B[0].to_i + B[1].to_i - A[0].to_i\ny = B[1].to_i + 3 * B[2].to_i - A[1].to_i\nputs (x > 0 ? x : 0) + (y > 0 ? y : 0)", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "074f568bf793820a94d158252100e37e", "src_uid": "35202a4601a03d25e18dda1539c5beba", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, l, r, x = gets.split(' ').map { |_| _.to_i }\na = gets.split(' ').map { |_| _.to_i }\nres = 0\nfor mask in (0..(1< 1\n min, max = tmp.minmax\n sum = tmp.reduce(0, :+)\n if l <= sum && sum <= r && (max - min) >= x then\n res += 1\n end\n end\nend\np res", "lang_cluster": "Ruby", "tags": ["brute force", "bitmasks"], "code_uid": "0bb68b2b213d66a5f049807bbad91ed3", "src_uid": "0d43104a0de924cdcf8e4aced5aa825d", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["brute force", "bitmasks"], "code_uid": "d7965383afdfd00f465fbbeffaadfafb", "src_uid": "0d43104a0de924cdcf8e4aced5aa825d", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, l, r, x = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\n\nans = 0\n(1 << n).times do |s|\n arr = []\n n.times { |b| arr << a[b] if ((s >> b) & 1) == 1 }\n\n if arr.length > 1\n if arr.max - arr.min >= x\n sum = arr.inject(&:+) \n if sum >= l && sum <= r\n ans += 1\n end\n end\n end\nend\n\nputs ans\n", "lang_cluster": "Ruby", "tags": ["brute force", "bitmasks"], "code_uid": "a6bffb7bf930c4127359c9a85f0bb254", "src_uid": "0d43104a0de924cdcf8e4aced5aa825d", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "gets\na = gets.chomp.chars.map(&:to_i)\nputs [[1,2,3], [7,0,9], [1,4,7,0], [3,6,9,0]].all?{|b| (a & b).any?} ? \"YES\" : \"NO\"", "lang_cluster": "Ruby", "tags": ["brute force", "constructive algorithms", "implementation"], "code_uid": "f1b334160fa5870e613a7d4ec33b690f", "src_uid": "d0f5174bb0bcca5a486db327b492bf33", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "numLength = gets.chomp.to_i\nnum = gets.chomp.split('').map(&:to_i)\nfound = false\n\nfor i in 0...numLength\n\tnum[i] = 10 if num[i] == 0\nend\n\n###############\nprob = false\n\nupper = num[0...numLength].map { |i| i -= 3}\n\nupper.each do |i|\n\tprob = true if i <= 0\nend\n\n#puts \"Upper : #{prob}\"\nfound = true if !prob\n################\nprob = false\n\n\nleft = num[0...numLength].map { |i| i -= 1}\n\nleft.each do |i|\n\tprob = true if i <= 0 || i % 3 == 0\nend\n\n#puts \"Left : #{prob}\"\nfound = true if !prob\n###############\nprob = false\n\nright = num[0...numLength].map { |i| i += 1}\n\nright.each do |i|\n\tprob = true if i >= 10 || i % 3 == 1\nend\n\n#puts \"Right : #{prob}\"\nfound = true if !prob\n#################\nprob = false\n\nbelow = num[0...numLength].map { |i| i += 3 }\n\nbelow.each do |i|\n\tprob = true if (i != 11 && i >= 10)\nend\n\n#puts \"below : #{prob}\"\nfound = true if !prob\n########################\n\nputs 'YES' if !found\nputs 'NO' if found", "lang_cluster": "Ruby", "tags": ["brute force", "constructive algorithms", "implementation"], "code_uid": "87f37fea3d03fa74ecc3a89084496c4d", "src_uid": "d0f5174bb0bcca5a486db327b492bf33", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "gets; p = gets.chomp.chars.map(&:to_i); puts ([[1,2,3],[7,0,9],[1,4,7,0],[3,6,9,0]].any?{|a|(a&p).empty?})?(\"NO\"):(\"YES\")", "lang_cluster": "Ruby", "tags": ["brute force", "constructive algorithms", "implementation"], "code_uid": "3774ab6220d13aff3dc886b95b7acbf5", "src_uid": "d0f5174bb0bcca5a486db327b492bf33", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "c2, c3, c5, c6 = gets.split.map(&:to_i)\nputs 256 * [c2, c5, c6].min + 32 * [c2-[c2,c5,c6].min, c3].min\n", "lang_cluster": "Ruby", "tags": ["math", "greedy", "implementation", "brute force"], "code_uid": "8c3666b02b4450e82662b402d2146917", "src_uid": "082b31cc156a7ba1e0a982f07ecc207e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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\nk2, k3, k5, k6 = gis\n\nc256 = [k2, k5, k6].min\nc32 = [k3, k2 - c256].min\n\nans = c256 * 256 + c32 * 32\n\nputs ans\n\n\n", "lang_cluster": "Ruby", "tags": ["math", "greedy", "implementation", "brute force"], "code_uid": "37e45ece042033e9206216432ce56676", "src_uid": "082b31cc156a7ba1e0a982f07ecc207e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "k2, k3, k5, k6 = gets.chomp.split.map(&:to_i)\nsum = 256 * [k2,k5,k6].min\nk2 -= [k2, k5, k6].min\nsum += 32 * [k3, k2].min\np sum\n", "lang_cluster": "Ruby", "tags": ["math", "greedy", "implementation", "brute force"], "code_uid": "f3ccb335f1f2b6e645b4ee5363b6d71d", "src_uid": "082b31cc156a7ba1e0a982f07ecc207e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a=gets.chomp.split(\" \")\nc=Hash.new(0)\na.each {|i| c[i]+=1}\na=c.values.sort\nif (a.length==3 && a[2]==4) || (a.length==2 && a[1]==5)\nputs \"Bear\"\nelsif (a.length==2 && a[1]==4) || (a.length==1)\nputs \"Elephant\"\nelse\nputs \"Alien\"\nend\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "51f3a216a41c317cdeb773f6b51c0a14", "src_uid": "43308fa25e8578fd9f25328e715d4dd6", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "require 'pp'\n\ns = STDIN.gets.chomp.split(/ /).map(&:to_i)\ns.sort!\n\ncount=1\nleg = -1\n5.times do |i|\n if s[i] == s[i+1]\n count+=1\n if count >=4\n leg = s[i]\n break\n end\n else\n count = 1\n end\nend\n\nif leg == -1\n puts \"Alien\"\nelse\n s.delete(leg)\n if s.length == 0\n puts \"Elephant\"\n elsif s.length == 1\n puts \"Bear\"\n else\n if s.first == s.last\n puts \"Elephant\"\n else\n puts \"Bear\"\n end\n end\nend\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "d4785d23baafbe7fe5b20bd00587038e", "src_uid": "43308fa25e8578fd9f25328e715d4dd6", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "input = gets.chomp.split(' ').map(&:to_i).compact\n\nc = input.inject({}){|h,e| h[e] ||= 0; h[e] += 1; h }\n\nif c.values.any?{|v| v >= 4 }\n\n l = c.find{|n,c| c >= 4 }[0]\n \n cc = input.dup\n 4.times do\n cc.delete_at( cc.index(l) )\n end\n\n if cc.uniq.count > 1\n puts \"Bear\"\n else\n puts \"Elephant\"\n end\n\nelse\n puts \"Alien\"\nend\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "08bbed420dab6db487066e001bff1571", "src_uid": "43308fa25e8578fd9f25328e715d4dd6", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a = gets.split.map &:to_i\np [0, a.max * 2 - a.inject(:+) + 1].max", "lang_cluster": "Ruby", "tags": ["brute force", "math", "geometry"], "code_uid": "219317259ef9fe7476303caa839f5639", "src_uid": "3dc56bc08606a39dd9ca40a43c452f09", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "ss = gets.split.map(&:to_i).sort\n\nputs [(ss.max + 1) - (ss[0] + ss[1]), 0].max", "lang_cluster": "Ruby", "tags": ["brute force", "math", "geometry"], "code_uid": "f3f500ac0f7c307f7996d2b15f8f7681", "src_uid": "3dc56bc08606a39dd9ca40a43c452f09", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "x,y,z = gets.split.map { |e| Integer(e) }\n\nmin = 100000\n\n(x..100).each {|a| \n (y..100).each { |b| \n (z..100).each { |c| \n s=(a+b+c)/2.0\n if s>a and s>b and s>c then\n v = a-x + b-y + c-z\n if min > v then \n min = v\n end\n end\n }\n }\n}\n\nputs min", "lang_cluster": "Ruby", "tags": ["brute force", "math", "geometry"], "code_uid": "4266c5ec2b13cf054639c30eadcb3ed9", "src_uid": "3dc56bc08606a39dd9ca40a43c452f09", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a1, b1 = ARGF.gets.chomp.split(\" \").map { |s| s.to_i }\na2, b2 = ARGF.gets.chomp.split(\" \").map { |s| s.to_i }\n\nputs [(a2-a1).abs, (b2-b1).abs].max\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "9fd51e1a24fb26c8b38ce6212e9942ab", "src_uid": "a6e9405bc3d4847fe962446bc1c457b4", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a = gets.split(\" \").map(&:to_i)\nb = gets.split(\" \").map(&:to_i)\ndx = (a[0]-b[0]).abs\ndy = (a[1]-b[1]).abs\np (dx-dy).abs + [dx, dy].min\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "d009da4252489b07b038e071dc9d266e", "src_uid": "a6e9405bc3d4847fe962446bc1c457b4", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b,c,d=$<.read.split.map(&:to_i);p [a-c,b-d].map(&:abs).max\n\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "43d5dd5b6aff9090860ad3958a7c36af", "src_uid": "a6e9405bc3d4847fe962446bc1c457b4", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s=eval gets.sub(' ','^');99.times{s|=s/2};p s", "lang_cluster": "Ruby", "tags": ["math", "dp", "bitmasks", "greedy", "implementation"], "code_uid": "cbb0e15ef8afedae6251463ce22d733a", "src_uid": "d90e99d539b16590c17328d79a5921e0", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "l, r = gets.split.map(&:to_i)\nans = 0\n70.downto(0) do |i|\n\tst = 1<l && st<=r )\n\t\tans = [ans, st*2-1].max\n\telsif (r=st)\n\t\tl -= st\n\t\tr -= st\n\tend\nend\nputs ans", "lang_cluster": "Ruby", "tags": ["math", "dp", "bitmasks", "greedy", "implementation"], "code_uid": "9563db5e23efb6f5f82829d9c7737ac3", "src_uid": "d90e99d539b16590c17328d79a5921e0", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s=eval gets.sub(' ','^');99.times{s|=s/2};p s\n", "lang_cluster": "Ruby", "tags": ["math", "dp", "bitmasks", "greedy", "implementation"], "code_uid": "b042617624cc922a049a9f5e1f753abf", "src_uid": "d90e99d539b16590c17328d79a5921e0", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["brute force", "math", "implementation"], "code_uid": "69624f84e527aad5a2820ff6540b29b2", "src_uid": "5ecd569e02e0164a5da9ff549fca3ceb", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "x, y = gets.to_i, 0\nh, m = gets.split.map(&:to_i)\nm += h * 60\nwhile !/7/.match(\"#{m / 60 % 24}#{m % 60}\")\n y += 1\n m -= x\nend\np y", "lang_cluster": "Ruby", "tags": ["brute force", "math", "implementation"], "code_uid": "fd077749489124c085d21e774fe0fed7", "src_uid": "5ecd569e02e0164a5da9ff549fca3ceb", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = gets.to_i\ntime = gets.chomp\nh = time.split(\" \")[0].to_i\nm = time.split(\" \")[1].to_i\nans = 0\nwhile m % 10 != 7 and h % 10 !=7 \n\tm -= s\n\tans += 1\n\tif m < 0\n\t\th -= 1\n\t\tm += 60\n\tend\n\tif h < 0 \n\t\th += 24\n\tend\nend\nprint ans,\"\\n\"\n", "lang_cluster": "Ruby", "tags": ["brute force", "math", "implementation"], "code_uid": "035b6ca14e10a59b3a2ec0200b4fc129", "src_uid": "5ecd569e02e0164a5da9ff549fca3ceb", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "MOD = 998_244_353\n\ndef edge(v, u)\n\tcv = cu = 1\n\tres = 1\n\t[u, v].min.times do |i|\n\t\tcv = cv * (v - i)\n\t\tcu = cu * (u - i) / (i + 1)\n\t\tres += (cu % MOD * cv % MOD) % MOD\n\t\tres %= MOD\n\tend\n\tres\nend\n\na, b, c = gets.split.map{|x| x.to_i}\n\np (edge(a, b) * edge(b, c) * edge(a, c)).modulo(MOD)", "lang_cluster": "Ruby", "tags": ["math", "dp", "combinatorics"], "code_uid": "9b593680156d27b5680da99f70967f4a", "src_uid": "b6dc5533fbf285d5ef4cf60ef6300383", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "gets\ncnt, res = Array.new(6, 0), 0\ngets.split.each { |s| cnt[s.to_i] += 1 }\ngets.split.each { |s| cnt[s.to_i] -= 1 }\ncnt.each do |x|\n if x.odd?\n puts -1\n exit\n else\n res += x.abs\n end\nend\nputs res / 4", "lang_cluster": "Ruby", "tags": ["math", "constructive algorithms"], "code_uid": "ceb72d0f0168f77ea6cbfd3c1bc65038", "src_uid": "47da1dd95cd015acb8c7fd6ae5ec22a3", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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 #\u611f\u89c9\u53ea\u8981\u5904\u7406\u4e00\u79cd\u60c5\u51b5\u5c31\u53ef\u4ee5\uff01\nend\nif can==1\n puts atob\nelse\n puts -1\nend\n", "lang_cluster": "Ruby", "tags": ["math", "constructive algorithms"], "code_uid": "7e1a08147c2d45091a5db5ed14533e56", "src_uid": "47da1dd95cd015acb8c7fd6ae5ec22a3", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\na = gets.split(\" \").map(&:to_i)\nb = gets.split(\" \").map(&:to_i)\ncnta = Array.new(5) {|i| i = 0}\ncntb = Array.new(5) {|i| i = 0}\nres = 0\nok = 1\na.each do |i|\n\tcnta[i-1] += 1\nend\nb.each do |i|\n\tcntb[i-1] += 1\nend\n(0..4).each do |i|\n\tif (cnta[i] + cntb[i]) % 2 == 0\n\t\tres += ((cnta[i] + cntb[i]) / 2 - cnta[i]).abs\n\telse\n\t\tok = 0\n\t\tbreak\n\tend \nend\n\nif ok == 0\n\tputs -1\nelse\n\tputs res / 2\nend\n\n\n", "lang_cluster": "Ruby", "tags": ["math", "constructive algorithms"], "code_uid": "762c92891c6b92eb1acfa5babb092f3f", "src_uid": "47da1dd95cd015acb8c7fd6ae5ec22a3", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a = gets.to_i\nb = gets.to_i\nc = gets.to_i\nm = [a, b/2, c/4].min\nputs 7 * m", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "561e5b5c02fbaf0595c7cc2278795b8c", "src_uid": "82a4a60eac90765fb62f2a77d2305c01", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a = gets.chomp.to_i\nb = gets.chomp.to_i\nc = gets.chomp.to_i\nputs 7*([a,b/2,c/4].min)", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "7600c29dc3ca6a3d431b3f1ce4f7e80d", "src_uid": "82a4a60eac90765fb62f2a77d2305c01", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a = gets.chomp.to_i\nb = gets.chomp.to_i\nc = gets.chomp.to_i\n\nb /= 2\nc /= 4\n\nd = [a, b, c].min\n\nputs d + d*2 + d*4\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "3b4aa331b55cd7de1e2a9a8b88f414d9", "src_uid": "82a4a60eac90765fb62f2a77d2305c01", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def fun(n,m)\n n.each {|i|\n \n m.each {|y|\n \n if y==i\n print y+\" \"\n end\n \n }\n \n }\nend\n\n\nn=gets.chomp\narr=n.split(\" \")\nx=arr[0].to_i\ny=arr[1].to_i\n\n\narray=gets.chomp\narray_1=array.split(\" \")\n\n\narrayy=gets.chomp\narray_2=arrayy.split(\" \")\n\n\nfun(array_1,array_2)\n\n\n\n#fun(array_1,array_2)\n\n\n\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "bcad7987d2bb1cf401304e9e3a98286c", "src_uid": "f9044a4b4c3a0c2751217d9b31cd0c72", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "gets\nx = gets.split\ny = gets.split\nx.each{|x| print x, ' ' if y.include? x}\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "dd57a22ca69ba5b429acc5ec7912f8b2", "src_uid": "f9044a4b4c3a0c2751217d9b31cd0c72", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "gets;puts (gets.split&gets.split)*' '", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "1c3e085a4c2062f08b1a195adb9aab24", "src_uid": "f9044a4b4c3a0c2751217d9b31cd0c72", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/ruby\nt=2.times.map{a,b=gets.split(':').map(&:to_i);a*60+b}.reduce(:-)\nt+=1440 if t<0\nputs '%02d:%02d'%[t/60,t%60]", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "0c11f021353944fcefdfce45d4331476", "src_uid": "595c4a628c261104c8eedad767e85775", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def parse_time(time)\n time.split(':').map(&:to_i)\nend\n\ndef to_str(h, m)\n [h, m].map { |t| \"%02d\" % t }.join(':')\nend\n\ndef solve(cur_time, duration)\n hc, mc = parse_time cur_time\n hd, md = parse_time duration\n hg = hc - hd\n mg = mc - md\n if mg < 0\n mg = 60 + mg\n hg -= 1\n end\n hg = (hg + 24) % 24\n to_str(hg, mg)\nend\n\nif __FILE__ == $0\n puts solve(gets.chomp, gets.chomp)\nend", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "d5eebac47dc4a96a77c3009e9ddb14fe", "src_uid": "595c4a628c261104c8eedad767e85775", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "first = gets.chomp\nsecond = gets.chomp\n\nfirst = first.split(\":\").map { |i| i.to_i }\nsecond = second.split(\":\").map { |i| i.to_i }\n\nfirst = first[0]*60 + first[1]\nsecond = second[0]*60 + second[1]\n\nx = first - second\n\nif x >= 0 then\n\n\thr = x/60\n\tmn = x%60\n\n\tprint \"0\" if hr < 10 \n\tprint hr,\":\"\n\tprint \"0\" if mn < 10\n\tprint mn\n\nelse\n\n\thr = ((24*60) - (-1*x)) / 60\n\tmn = ((24*60) - (-1*x)) % 60\n\tprint \"0\" if hr < 10 \n\tprint hr,\":\"\n\tprint \"0\" if mn < 10\n\tprint mn\n\nend\n\n\n\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "43cb10020e6954f9e5f80841a5a065d4", "src_uid": "595c4a628c261104c8eedad767e85775", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "$dp = {}\n\ndef g a\n\treturn 0 if a.empty?\n\treturn a.first == 0 ? 1 : 0 if a.size == 1\n\treturn $dp[a] if $dp[a]\n\ts = a.first\n\tt = [1 + g(a[1..-1])]\n\tt << g([a[1] & 2] + a[2..-1]) if s & 1 != 0\n\tt << g([a[1] & 1] + a[2..-1]) if s & 2 != 0\n\treturn $dp[a] = t.min\nend\n\ndef f a\n\tans = 0\n\tb = []\n\twhile !a.empty?\n\t\tif a.first == 0\n\t\t\tans += 1\n\t\t\ta.shift\n\t\telse\n\t\t\tc = []\n\t\t\twhile !a.empty? and a.first != 0\n\t\t\t\tc << a.shift\n\t\t\tend\n\t\t\tb << c\n\t\tend\n\tend\n\tb.sort_by! &:size\n\tfor i in 0..b.size - 1\n\t\tans += g(b[i])\n\tend\n\treturn ans\nend\n\ngets\na = gets.split.map &:to_i\nputs f a", "lang_cluster": "Ruby", "tags": ["brute force", "dp"], "code_uid": "f3f274008d2971a9313aa2649bbe09df", "src_uid": "08f1ba79ced688958695a7cfcfdda035", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\n\nans=0\n\n(n-1).times do |i|\n if a[i]==1\n if a[i+1]==1 || a[i+1]==0\n a[i+1]=0\n else\n a[i+1]=2\n end\n elsif a[i]==2\n if a[i+1]==2 || a[i+1]==0\n a[i+1]=0\n else\n a[i+1]=1\n end\n elsif a[i]==0\n ans+=1\n end\nend\n\nans+=1 if a[n-1]==0\n\np ans", "lang_cluster": "Ruby", "tags": ["brute force", "dp"], "code_uid": "62d0e51741a1834a39cbbb1392372205", "src_uid": "08f1ba79ced688958695a7cfcfdda035", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#! ruby\n# Try Codeforces\n# author: Leonardone @ NEETSDKASU\n############################################################\ndef gs() gets.chomp end\ndef gi() gets.to_i end\ndef gss() gs.split end\ndef gis() gss.map(&:to_i) end\ndef nmapf(n,f) n.times.map{ __send__ f } end\ndef ngs(n) nmapf n,:gs end\ndef ngi(n) nmapf n,:gi end\ndef ngss(n) nmapf n,:gss end\ndef ngis(n) nmapf n,:gis end\ndef arr2d(h,w,v=0) h.times.map{[v] * w} end\ndef for2p(hr,wr,&pr) hr.each{|i|wr.each{|j| yield(i,j)}} end\ndef nsum(n) n * (n + 1) / 2 end\ndef vcount(d,r=Hash.new(0)) d.inject(r){|m,e| m[e]+=1;m} end\n############################################################\n\nrequire 'set'\n\nn = gi\nx = gis\n\nh1 = Set.new\nh1.add [0, 0, 0, -1]\n\nx.each do |z|\n h2 = Set.new\n h1.each do |c, s, r, e|\n case z\n when 0\n h2.add [c, s, r + 1, 2]\n when 1\n if e != 0\n h2.add [c + 1, s, r, 0]\n end\n h2.add [c , s, r + 1, 2]\n when 2\n if e != 1\n h2.add [c, s + 1, r, 1]\n end\n h2.add [c, s, r + 1, 2]\n when 3\n if e != 0\n h2.add [c + 1, s, r, 0]\n end\n if e != 1\n h2.add [c, s + 1, r, 1]\n end\n h2.add [c, s, r + 1, 2]\n end\n end\n h1 = h2\nend\n\nans = nil\nh1.each do |c, s, r, e|\n # next if c != s\n if ans.nil?\n ans = r\n else\n ans = [ans, r].min\n end\nend\n\nif ans.nil?\n puts 0\nelse\n puts ans\nend", "lang_cluster": "Ruby", "tags": ["brute force", "dp"], "code_uid": "dc0bd85d0cc965ef7a8d529670bb93ad", "src_uid": "08f1ba79ced688958695a7cfcfdda035", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["math", "greedy"], "code_uid": "7c6843c2c54ac9a5cdb97cbdac3e1bb5", "src_uid": "7cff20b1c63a694baca69bdf4bdb2652", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "k, a, b, v = gets.split.map(&:to_i)\np *(1..b).collect{|x|x+[0,(a-v*[x+b,k*x].min+v-1)/v].max}.min\n", "lang_cluster": "Ruby", "tags": ["math", "greedy"], "code_uid": "99f0f9d99e129ca8c6653cee4d50d012", "src_uid": "7cff20b1c63a694baca69bdf4bdb2652", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "k, a, b, v = gets.split.map(&:to_i)\np *(1..b).collect{|x|x+[0,(a-v*[x+b,k*x].min+v-1)/v].max}.min\n", "lang_cluster": "Ruby", "tags": ["math", "greedy"], "code_uid": "ee72d2e6ed773ccde81f06d5aca1a599", "src_uid": "7cff20b1c63a694baca69bdf4bdb2652", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, k = gets.split.collect {|n| n.to_i}\nmin = k == 0 || k == n ? 0 : 1\nmax = (k - 1) * 2 + 2 > (n - k) ? (n - k) : (k - 1) * 2 + 2\nputs \"#{min} #{max}\"", "lang_cluster": "Ruby", "tags": ["math", "constructive algorithms"], "code_uid": "3a6c46f9e0980ff7a48a75ab773ba811", "src_uid": "bdccf34b5a5ae13238c89a60814b9f86", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,k = gets.split.map &:to_i\n\n\nif n == k || k == 0\n puts \"0 0\"\nelse\n if k*3 < n\n puts \"1 #{k*2}\"\n else\n puts \"1 #{n-k}\"\n end\nend", "lang_cluster": "Ruby", "tags": ["math", "constructive algorithms"], "code_uid": "b9e7a2d465397bb7e9af722ae4801218", "src_uid": "bdccf34b5a5ae13238c89a60814b9f86", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,k=gets.split.map(&:to_i)\nif n == k || k == 0\n puts \"0 0\"\nelse\n if n % 3 == 0\n if k > n / 3\n k -= n / 3\n ans = n / 3 * 2 - k\n else\n ans = 2 * k\n end\n elsif n % 3 == 1\n if k > n / 3\n k -= n / 3\n ans = n / 3 * 2 - k + 1\n else\n ans = 2 * k\n end\n else \n if k > n / 3\n k -= n / 3 + 1\n ans = n / 3 * 2 + 1 - k\n else\n ans = 2 * k\n end \n end\n puts \"1 #{ans}\"\nend", "lang_cluster": "Ruby", "tags": ["math", "constructive algorithms"], "code_uid": "240258e1515547afbd01b34a3baa4e24", "src_uid": "bdccf34b5a5ae13238c89a60814b9f86", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def F(x,s);x-(-x%s*(x/s));end;n,m,s=gets.split.map &:to_i;p F(n,s)*F(m,s)\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "5c0a1f9abdf9db5e8089270f7e0051cf", "src_uid": "e853733fb2ed87c56623ff9a5ac09c36", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def F(x,s);x-(-x%s*(x/s));end;n,m,s=gets.split.map &:to_i;p F(n,s)*F(m,s)", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "057314576ace923c4664cbcfb0f77622", "src_uid": "e853733fb2ed87c56623ff9a5ac09c36", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def F(x,s);x-(-x%s*(x/s));end;n,m,s=gets.split.map &:to_i;p F(n,s)*F(m,s)\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "bc3650352bbbe34fd14fd1c54d91ad71", "src_uid": "e853733fb2ed87c56623ff9a5ac09c36", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,m=gets.split.map &:to_i\ns=gets.chomp\nc=i=0\nwhile c0 do\n\t\tsum += num[ aux%10 ]\n\t\taux /= 10\n\tend\n\ta += 1\nend\n\nputs sum\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "e1d64a3056f544f027742dadec546dff", "src_uid": "1193de6f80a9feee8522a404d16425b9", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "inpup=gets.chomp\n\nbeg_end=inpup.split(\" \")\n$num_seg=0\n\nini=beg_end[0].to_i\nfin=beg_end[1].to_i\n\nvalue=[6,2,5,5,4,5,6,3,7,6]\n\nini.upto(fin) do |k|\n\tloop do\n\t\teva=k%10\n\t\t$num_seg=$num_seg+value[eva]\n\t\tk=k/10\n\t\tif k==0\n\t\t\tbreak \n\t\tend\n\tend\nend\n\nprint $num_seg", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "3b6e497bb108ccd7f53fdc65a9d4af8e", "src_uid": "1193de6f80a9feee8522a404d16425b9", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a, b = gets.chomp.split(\" \").map(&:to_i)\n\nval = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6]\n\nres = 0\n\n(a..b).each do |n|\n while n > 0 \n res += val[n%10]\n n /= 10\n end\nend\n\nputs res", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "1dfa546f7544fa68d2ee252849197f72", "src_uid": "1193de6f80a9feee8522a404d16425b9", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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)", "lang_cluster": "Ruby", "tags": ["math", "matrices", "implementation"], "code_uid": "c583cfe1c88e43dc985246bc1eec9bcd", "src_uid": "f726133018e2149ec57e113860ec498a", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a, m = gets.split.map { |x| x.to_i }\na = a % m\n\nvis = Array.new m\n\nloop do\n\tif a == 0\n\t\tputs 'Yes'\n\t\tbreak\n\telsif vis[a]\n\t\tputs 'No'\n\t\tbreak\n\telse\n\t\tvis[a] = true\n\t\ta = 2 * a % m\n\tend\nend\n", "lang_cluster": "Ruby", "tags": ["math", "matrices", "implementation"], "code_uid": "2bcb43ff9f83d1b722cc8f5124dce825", "src_uid": "f726133018e2149ec57e113860ec498a", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "x, m = STDIN.readline.split.map {|s| s.to_i }\nif x%m == 0\n\tputs 'Yes'\n\texit\nend\nseen = Array.new(m, false)\nseen[x%m] = true\nwhile true\n\tx += x%m\n\tif x%m == 0\n\t\tputs 'Yes'\n\t\texit\n\tend\n\tif seen[x%m]\n\t\tputs 'No'\n\t\texit\n\tend\n\tseen[x%m] = true\nend\n", "lang_cluster": "Ruby", "tags": ["math", "matrices", "implementation"], "code_uid": "ebe6c8bd495f65cb00655a2cfb3d0831", "src_uid": "f726133018e2149ec57e113860ec498a", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["brute force", "geometry", "implementation"], "code_uid": "40d64d4e9a0eeaa4f7239a0e239d8dd2", "src_uid": "2fb2a129e01efc03cfc3ad91dac88382", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "x,y=gets.chomp.split.map(&:to_i)\nans=0\nans=4*y-2 if x>=-y && x=x &&y<-x\nans=-y*4 if x>y && x<=-y+1\nans=4*x-3 if y>-x+1 && y<=x\nputs ans", "lang_cluster": "Ruby", "tags": ["brute force", "geometry", "implementation"], "code_uid": "1dea9b9d364117633fdce29e0839760c", "src_uid": "2fb2a129e01efc03cfc3ad91dac88382", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "x,y = gets.split.map(&:to_i)\nans = 0\npgrx = 1\npgry=1\nogrx=-1\nogry=-1\nk=0\nnx=0\nny=0\nwhile (x!=nx || y!=ny)\n\t#p nx\n\t#p pgrx\n\tif ( nx==pgrx)\n\t\tpgrx += 1\n\t\tk = (k+1)%4\n\t\tans += 1\n\telsif (ny==ogry)\n\t\togry -= 1\n\t\tk = (k+1)%4\n\t\tans += 1\n\telsif (nx==ogrx)\n\t\togrx -= 1\n\t\tk = (k+1)%4\n\t\tans += 1\n\telsif (ny==pgry)\n\t\tpgry += 1\n\t\tk = (k+1)%4\n\t\tans += 1\n\tend\n\tif (k==0)\n\t\tnx += 1\n\telsif (k==1)\n\t\tny += 1\n\telsif (k==2)\n\t\tnx -= 1\n\telse \n\t\tny -= 1\n\tend\nend\nputs ans", "lang_cluster": "Ruby", "tags": ["brute force", "geometry", "implementation"], "code_uid": "7a1a93d12ca674a48bb997170e197ac1", "src_uid": "2fb2a129e01efc03cfc3ad91dac88382", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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 extend Memoizer\n attr_reader(:n, :l, :xs, :ys)\n def initialize(n, l, xs, ys)\n @n = n\n @l = l\n @xs = xs\n @ys = ys\n end\n\n def nxs\n xs.drop(1) + [l + xs.first]\n end\n memoize(:nxs)\n\n def nys\n ys.drop(1) + [l + ys.first]\n end\n memoize(:nys)\n\n def xxs\n xs.zip(nxs).map{|p, q| q - p}\n end\n memoize(:xxs)\n\n def yys\n ys.zip(nys).map{|p, q| q - p}\n end\n memoize(:yys)\n\n def same?\n xxs.zip(yys).all?{|x, y| x == y}\n end\n\n def next_try\n Problem.new(n, l, xs, nys)\n end\n\n def answer(n)\n return \"YES\" if same?\n return \"NO\" if n == 102\n return next_try.answer(n + 1)\n end\n\nend\n\nn, l = gets.split(\" \").map(&:to_i)\nxs = gets.split(\" \").map(&:to_i)\nys = gets.split(\" \").map(&:to_i)\n\np = Problem.new(n, l, xs, ys)\nputs p.answer(0)\n", "lang_cluster": "Ruby", "tags": ["brute force", "math", "implementation"], "code_uid": "2dbec7aa842da4b74e4bb0799dc94032", "src_uid": "3d931684ca11fe6141c6461e85d91d63", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#\u5728\u754c\u7ebf\u5185\u8dd1\uff1f\n#\u5706\u5f62\u8ddf\u8e2a\uff1f\n#\u7528\u680f\u6805\u56f4\u4f4f\u7684\u4e00\u4e2a\u4e1c\u897f\uff01\n#\u7530\u5f84\u8fd0\u52a8\u5458\uff01\n#track\u5e94\u8be5\u662f\u8f68\u8ff9\uff1f\n#\u9e66\u9e49\uff1f\u82b1\u8c79\n#\u6bcf\u4e00\u4e2a\u505a\u4e00\u6b21\u63a5\u529b\uff1f\nnumber=gets.chomp.split\nn=number[0].to_i\nl=number[1].to_i\nkefa=gets.chomp.split\nsasha=gets.chomp.split\n#\u8fd9\u662f\u4e00\u4e2a\u8de8\u680f\u8fd0\u52a8\uff1f\n#\u627e\u5230\u6805\u680f\u4e4b\u95f4\u7684\u95f4\u9694\uff01\nkefa_fence_interval=[]\nkefa_fence_interval[0]=kefa[0].to_i+l-kefa[-1].to_i\ni=1\nj=1\nwhile i 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", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "d7943a14230607cb4de746d37ca5f11c", "src_uid": "1a70ed6f58028a7c7a86e73c28ff245f", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a1, b1 = gets.split.map {|x| Integer x}\na2, b2 = gets.split.map {|x| Integer x}\na3, b3 = gets.split.map {|x| Integer x}\na4, b4 = gets.split.map {|x| Integer x}\nif (a1 > b3 && a1 > b4 && b2 > a3 && b2 > a4) || (b1 > a3 && b1 > a4 && a2 > b3 && a2 > b4)\n puts 'Team 1'\nelsif (a3 > b1 && b4 > a2 || b3 > a2 && a4 > b1) && (b3 > a1 && a4 > b2 || b4 > a1 && a3 > b2)\n puts 'Team 2'\nelse\n puts 'Draw'\nend", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "a25b135c7ef7c1612c7d8794859cc244", "src_uid": "1a70ed6f58028a7c7a86e73c28ff245f", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.to_i\ni=1\nans=[]\nwhile n-i>0\n\tm=n-i\n\tif m+m.to_s.chars.inject(0){|sum,e|\n\t\tsum+e.to_i\n\t}==n then\n\t\tans<100\n\ti+=1\nend\nans=ans.reverse\nputs ans.size\nif ans.size>0\n\tputs ans\nend", "lang_cluster": "Ruby", "tags": ["brute force", "math"], "code_uid": "6939b41a572be634a2fa6234a0a9be19", "src_uid": "ae20ae2a16273a0d379932d6e973f878", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def ascan; gets.split.map(&:to_i);end\n\nans = []\n\nn = gets.to_i\n\n(0..9).to_a.repeated_combination(9) do |a|\n t = a.reduce(n){|s,e| s-=e}\n next if t < 0\n h = [0]*10\n a.each{|e| h[e]+=1}\n t.to_s.chars.each{|c| h[c.to_i]-=1}\n b = true\n (1..9).each{|e| b &= h[e] == 0}\n ans << t if b\nend\n\np ans.size\nputs ans.sort", "lang_cluster": "Ruby", "tags": ["brute force", "math"], "code_uid": "10477af9815ac74edbcf88ef104173ec", "src_uid": "ae20ae2a16273a0d379932d6e973f878", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["brute force", "math"], "code_uid": "794a6b176192125cf2bb5cf125cbe66b", "src_uid": "ae20ae2a16273a0d379932d6e973f878", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def is_consonant(c)\n c =~ /[^aeiou]/\nend\n\ndef is_bertlanese(word)\n next_must_be_vowel = false\n\n word.chars.each do |c|\n\n return false if next_must_be_vowel && is_consonant(c)\n\n next_must_be_vowel =\n c != ?a &&\n c != ?e &&\n c != ?i &&\n c != ?o &&\n c != ?u &&\n c != ?n\n end\n\n !next_must_be_vowel\nend\n\ndef solution\n word = read_string\n puts is_bertlanese(word) ? \"YES\" : \"NO\"\nend\n\n\ndef rest_int\n gets.to_i\nend\n\ndef read_ints\n gets.split.map &:to_i\nend\n\ndef read_string\n gets.chomp\nend\n\n\nsolution", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "4e1c7865c7de66ae3380f24b54d544a2", "src_uid": "a83144ba7d4906b7692456f27b0ef7d4", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = gets.chomp\nn = s.size\na = [\"a\", \"i\", \"u\", \"e\", \"o\"]\ni = 0\nflag = true\nwhile i < n\n if a.include?(s[i])\n i += 1\n elsif s[i] == ?n\n i += 1\n else\n if i + 1 == n\n flag = false\n break\n else\n i += 1\n if !a.include?(s[i])\n flag = false\n break\n end\n i += 1\n end\n end\nend\nputs flag ? \"YES\" : \"NO\"\n", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "583ee6b22a2847894b3c539e550eb126", "src_uid": "a83144ba7d4906b7692456f27b0ef7d4", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": " #!/usr/bin/ruby\n\n\ndef isvowel(x)\n if x == 'a'||x=='e'||x=='i'||x=='o'||x=='u'\n return true\n end\n\nend\nname = gets().chomp()\nflag = 0\nfor i in 0...name.length\n\n #puts(name[i])\n\n if(i == name.length-1)\n\n if(name[i] == 'n')\n flag = 0\n elsif (isvowel(name[i]))\n flag = 0\n else\n flag = 1\n break\n end\n\n\n\n elsif(!isvowel(name[i]))\n\n if(name[i] == 'n')\n flag = 0\n\n else\n if(!isvowel(name[i+1]))\n flag = 1\n break\n end\n\n end\n\n end\n\nend\n\nif(flag == 0)\n puts(\"YES\")\nelse\n puts(\"NO\")\nend", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "8f81454caf13b8afcb9192b8a420c814", "src_uid": "a83144ba7d4906b7692456f27b0ef7d4", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a = gets.split.map(&:to_i)\nans = 0\ni = 0\n3.times do\n ans += a[i] * a[i + 1] * 2\n i += 2\nend\nans += (a[3] - a[0]) * (a[3] - a[0])\nputs ans", "lang_cluster": "Ruby", "tags": ["geometry"], "code_uid": "e791d107f7d8fb73e3f439bab4450f3f", "src_uid": "382475475427f0e76c6b4ac6e7a02e21", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a , b , c , d , e , f = gets.split.map(&:to_i)\nans = a*b + a*e + a*f + b*f + c*d + e*f\nprint ans", "lang_cluster": "Ruby", "tags": ["geometry"], "code_uid": "896ba00d6ceccd3f44747e9ce6dd3420", "src_uid": "382475475427f0e76c6b4ac6e7a02e21", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["geometry"], "code_uid": "d277e84d98259c9b9221cbb66729f131", "src_uid": "382475475427f0e76c6b4ac6e7a02e21", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b,c,d,k = gets.split(/\\s/).map(&:to_i)\nl,r = [a,c].max,[b,d].min \nans = 0 \nif l>r \n\tputs ans \n\telse \n\t\tans = r-l +1\n\t\tif k>=l and k<=r \n\t\t\tans=ans -1 \n\t\tend\n\t\tputs ans \n\tend \n\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "1b6c8003d6eec1fd168dd8547843dea7", "src_uid": "9a74b3b0e9f3a351f2136842e9565a82", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b,c,d,e=gets.split.map &:to_i\na=[a,c].max\nb=[b,d].min\np [0,b-a+1-(a<=e&&e<=b ? 1 : 0)].max\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "df6e39d2cc8d86a8ee3b175ecbcf2f6c", "src_uid": "9a74b3b0e9f3a351f2136842e9565a82", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b,c,d,e= gets.split.map(&:to_i)\n\na=[a,c].max\nb=[b,d].min\nputs [0, b-a+1 - (a<=e && e<=b ? 1 : 0) ].max\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "b124998fe5a354b1bad0ceb419843b87", "src_uid": "9a74b3b0e9f3a351f2136842e9565a82", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,k = readline.split.map(&:to_i)\na = readline.split.map(&:to_i)\n\nans=0\ni=0\nwhile i=0 and a[i]<=k\n\tans += 1\n\ti -= 1\nend\n\nputs [ans,n].min\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "daaa87c8ab4d4ae85af176bcc89c5e7e", "src_uid": "ecf0ead308d8a581dd233160a7e38173", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "\ndef solution\n _, k = read_ints\n ps = read_ints\n\n count = 0\n\n while ps.first && ps.first <= k\n count += 1\n ps.shift\n end\n\n while ps.last && ps.last <= k\n count += 1\n ps.pop\n end\n\n puts count\nend\n\ndef read_int\n gets.to_i\nend\n\ndef read_ints\n gets.split.map(&:to_i)\nend\n\ndef read_string\n gets.chomp\nend\n\nsolution unless ENV['TEST__MODE']\n\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "14c459f116ebf79a7a0032566629c7f2", "src_uid": "ecf0ead308d8a581dd233160a7e38173", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, k = gets.strip.split.map(&:to_i)\nary = gets.strip.split.map(&:to_i)\nans = 0\nsi = -1\n0.upto(n-1).each do |i|\n if ary[i] <= k\n ans += 1\n si = i\n else\n break\n end\nend\n(n-1).downto(si+1).each do |i|\n if ary[i] <= k\n ans += 1\n else\n break\n end\nend\nputs ans", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "bd2062cec120dc2d5024eae92da12266", "src_uid": "ecf0ead308d8a581dd233160a7e38173", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b = STDIN.readline.split.map{ |x| x.to_i }\nprint (a+b)", "lang_cluster": "Ruby", "tags": ["dsu", "constructive algorithms", "implementation", "brute force"], "code_uid": "038e39eefb81030d49fa76db54361caf", "src_uid": "b6e3f9c9b124ec3ec20eb8fcea075add", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "p gets.split.map(&:to_i).inject(:+)", "lang_cluster": "Ruby", "tags": ["dsu", "constructive algorithms", "implementation", "brute force"], "code_uid": "e5e303060c21cade3d4e7b7cf2496779", "src_uid": "b6e3f9c9b124ec3ec20eb8fcea075add", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b = gets.split(\" \").map {|v| v.to_i}\np a + b", "lang_cluster": "Ruby", "tags": ["dsu", "constructive algorithms", "implementation", "brute force"], "code_uid": "6af62e5e2287a135bd41825ac2734946", "src_uid": "b6e3f9c9b124ec3ec20eb8fcea075add", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "puts gets.split.map(&:to_i).reduce(:+)", "lang_cluster": "Ruby", "tags": ["dsu", "constructive algorithms", "implementation", "brute force"], "code_uid": "44c0b3b3ba60ab157e7ab3c69b6f53c8", "src_uid": "b6e3f9c9b124ec3ec20eb8fcea075add", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "puts gets.split(\" \").map { |x| x.to_i }.inject(:+)", "lang_cluster": "Ruby", "tags": ["dsu", "constructive algorithms", "implementation", "brute force"], "code_uid": "0358f162d45fe274aab7f32f6d16fb96", "src_uid": "b6e3f9c9b124ec3ec20eb8fcea075add", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "p gets.split.map(&:to_i).inject(:+)", "lang_cluster": "Ruby", "tags": ["dsu", "constructive algorithms", "implementation", "brute force"], "code_uid": "b0d7a6452ae58d9bd4e249ca2b2a2639", "src_uid": "b6e3f9c9b124ec3ec20eb8fcea075add", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "nums = gets.split\na = nums[0].to_i\nb = nums[1].to_i\n\n1 + 7\n\nputs a + b", "lang_cluster": "Ruby", "tags": ["dsu", "constructive algorithms", "implementation", "brute force"], "code_uid": "0ff8d6d093346812293fa5904a23c794", "src_uid": "b6e3f9c9b124ec3ec20eb8fcea075add", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b = *$stdin.read.split.map( &:to_i)\n\nprint a + b\n\n", "lang_cluster": "Ruby", "tags": ["dsu", "constructive algorithms", "implementation", "brute force"], "code_uid": "499e281b0a0ab0fc780c1126c2829fc5", "src_uid": "b6e3f9c9b124ec3ec20eb8fcea075add", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "# the accepted \n# ... LETS HACK THE WORLD ...\n#... KEEP CALM AND SAY LE ROI EST MORT IS HERE ...\n# ... EL-BADRY BECOME A LEGEND ...\n\nn,m = gets.chomp.split.map(&:to_i)\nputs n+m\n", "lang_cluster": "Ruby", "tags": ["dsu", "constructive algorithms", "implementation", "brute force"], "code_uid": "ff13052fd328bae9960f1008922af46d", "src_uid": "b6e3f9c9b124ec3ec20eb8fcea075add", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a, b = gets.split.map { |x| Integer x}\nputs a + b + 0 * 2", "lang_cluster": "Ruby", "tags": ["dsu", "constructive algorithms", "implementation", "brute force"], "code_uid": "9f2f551ead19d56389cb9615b1d8ecbb", "src_uid": "b6e3f9c9b124ec3ec20eb8fcea075add", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def sum(x)\n\ty=((x+1)*x)/2\nend\nm,b = gets.split.map(&:to_i)\nmax=0\n(b+1).times do |y|\n\tx=(-y*m)+b*m\n\ts=(y+1)*sum(x)+(x+1)*sum(y)\n\tmax= max > s ? max : s\nend\np max\n", "lang_cluster": "Ruby", "tags": ["brute force", "math"], "code_uid": "796440b4aeb8b62d88428751a7dd857c", "src_uid": "9300f1c07dd36e0cf7e6cb7911df4cf2", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "moves = Array.new(6) { Array.new(3, 0) }\nmoves[1][1] = 0\nmoves[2][2] = 0\nmoves[3][2] = 0\nmoves[4][1] = 0\nmoves[5][0] = 0\nmoves[0][0] = 0\n\nmoves[1][0] = 1\nmoves[2][0] = 1\nmoves[3][1] = 1\nmoves[4][2] = 1\nmoves[5][2] = 1\nmoves[0][1] = 1\n\nmoves[1][2] = 2\nmoves[2][1] = 2\nmoves[3][0] = 2\nmoves[4][0] = 2\nmoves[5][1] = 2\nmoves[0][2] = 2\n\nn = gets.strip.to_i\nx = gets.strip.to_i\nn %= 6\nans = moves[n][x]\nputs ans\n", "lang_cluster": "Ruby", "tags": ["math", "constructive algorithms", "implementation"], "code_uid": "bda603390e0d9d090eda6b4422d388a8", "src_uid": "7853e03d520cd71571a6079cdfc4c4b0", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "# your code goes here\n\nn = STDIN.gets.chomp.to_i\nn = n % 6\nx = STDIN.gets.chomp.to_i\n\nt=[0,0,0]\n\nt[x] = 1\n\n(n).downto(1) do\n\t|i|;\n\t#puts i;\n\tx = t[1];\n\tif (i % 2) == 0;\n\t\tt[1] = t[2];\n\t\tt[2] = x;\n\telse;\n\t\tt[1] = t[0];\n\t\tt[0] = x;\n\tend;\nend;\n\nputs t.index(1);", "lang_cluster": "Ruby", "tags": ["math", "constructive algorithms", "implementation"], "code_uid": "c8fc0a038fd49ab884aa39c0b3df0b0e", "src_uid": "7853e03d520cd71571a6079cdfc4c4b0", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "p [0,1,2,1,0,2,1,2,0,2,1,0,2,0,1,0,2,1][gets.to_i%6*3+gets.to_i]", "lang_cluster": "Ruby", "tags": ["math", "constructive algorithms", "implementation"], "code_uid": "9b33f72409dc58acb9aa5479d795a0f3", "src_uid": "7853e03d520cd71571a6079cdfc4c4b0", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.to_i\n\ncoins=[n]\n\n(n-1).downto(1){|i|\n\tif coins[-1]%i==0\n\t\tcoins << i\n\tend\n}\n\nprint coins.join(\" \")\n", "lang_cluster": "Ruby", "tags": ["greedy"], "code_uid": "33a92390b65f79e1e4d6ca6c433b1adc", "src_uid": "2fc946bb72f56b6d86eabfaf60f9fa63", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.chomp.to_i\nputs n.downto(1).reduce([[], n]) { |s, x| \n\t(s.first << x; s[-1] = x) if s[-1] % x == 0\n\ts\n}.first.join(' ')", "lang_cluster": "Ruby", "tags": ["greedy"], "code_uid": "3eb035a1345648b0d7d3913075d18161", "src_uid": "2fc946bb72f56b6d86eabfaf60f9fa63", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\n\nwhile n > 1\n (n-1).downto(1) do |i|\n if (n%i).zero? \n print n, ' '\n n = i\n end\n end\nend\nprint 1\n", "lang_cluster": "Ruby", "tags": ["greedy"], "code_uid": "0e5bf3533268c4030970b14d2b6d13d8", "src_uid": "2fc946bb72f56b6d86eabfaf60f9fa63", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/ruby\nx,y=$<.map{|e|\n\ta,b=e.split.map(&:to_i)\n\t(0..99).map{|i|b+i*a}\n}\nx&=y\nputs x[0]||-1", "lang_cluster": "Ruby", "tags": ["brute force", "math", "number theory"], "code_uid": "3de86bbd8013e7bfe459ad56212f3642", "src_uid": "158cb12d45f4ee3368b94b2b622693e7", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["brute force", "math", "number theory"], "code_uid": "0e210a467754dc912e69d51cc7141cb2", "src_uid": "158cb12d45f4ee3368b94b2b622693e7", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#b+i*a==d+j*c\n#i*a-j*c==d-b\n#x*a-c*y==d-b\n#a=3,b=2\n#3=2*1+1\n#1,1\ndef gcd(a,b)\n\tif b==0\n\t\treturn a\n\telse\n\t\treturn gcd(b,a%b)\n\tend\nend\nab=gets.chomp.split.map{ |x| x.to_i }\na=ab[0]\nb=ab[1]\ncd=gets.chomp.split.map{ |x| x.to_i }\nc=cd[0]\nd=cd[1]\n\ngcd_ab=gcd(a,c)\nif (d-b)%gcd_ab==0\n\t#\u5728\u5224\u65ad\u6709\u89e3\u7684\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u7528\u76f4\u63a5\u67e5\u627e\u7684\u65b9\u6cd5\u5f97\u5230\u6700\u5c0f\u76f8\u540c\u503c\uff01\n\t#\u7528\u6570\u5b66\u516c\u5f0f\u5904\u7406\u6bd4\u8f83\u590d\u6742\uff01\n\ti=0\n\tj=0\n\twhile true\n\t\tx=b+i*a\n\t\ty=d+j*c\n\t\tif x==y\n\t\t\tputs x\n\t\t\tbreak\n\t\telsif x>y\n\t\t\tj+=1\n\t\telse\n\t\t\ti+=1\n\t\tend\n\tend\nelse\n\tputs -1\nend\n", "lang_cluster": "Ruby", "tags": ["brute force", "math", "number theory"], "code_uid": "28a624b470619952e17a1f9e249e5d9c", "src_uid": "158cb12d45f4ee3368b94b2b622693e7", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s=gets.chomp\nr=s.scan('VK').size\ns.size.times{|i|\n\ts[i]=s[i].tr('VK','KV')\n\tr=[r,s.scan('VK').size].max\n\ts[i]=s[i].tr('VK','KV')\n}\np r", "lang_cluster": "Ruby", "tags": ["brute force"], "code_uid": "611bb5d81914bea687581a8a3794dfab", "src_uid": "578bae0fe6634882227ac371ebb38fc9", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "str1 = gets().chomp\nstr1_count = str1.scan(/VK/).size\nif (str1.scan(/VVV/).size >= 1) || (str1.scan(/KKK/).size >= 1) || (str1[0,2]=='KK') || (str1[-2,str1.size]=='VV')\n str1_count += 1\nend\np str1_count", "lang_cluster": "Ruby", "tags": ["brute force"], "code_uid": "d0201e37873276e9fece15f32d5c8cd1", "src_uid": "578bae0fe6634882227ac371ebb38fc9", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = gets\nif s[-1] == \"\\n\"\n s = s.split(\"\\n\")[0].to_s\nend\nres = 0\nchanged = false\ni = 0\nwhile i < s.size \n if s[i] == 'V' && s[i+1] == 'K'\n i += 2\n res += 1\n next\n end\n if changed\n i += 1\n next\n end\n if s[i] == 'K' && s[i+1] == 'K' ||\n s[i] == 'V' && s[i+1] == 'V' && (s[i+2] == 'V' || s[i+2] == nil)\n res += 1\n i += 2\n changed = true\n next\n end\n i += 1\nend\n\nputs res", "lang_cluster": "Ruby", "tags": ["brute force"], "code_uid": "a6f3b631c8b6413dd07e2daec8139f0a", "src_uid": "578bae0fe6634882227ac371ebb38fc9", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "board = gets.split(' ')\nboard_a = board.first.to_i\nboard_b = board.last.to_i\npa1 = gets.split(' ')\npa2 = gets.split(' ')\npa1.map!{|x| x.to_i}\npa2.map!{|x| x.to_i}\npossible = false\n\npa1.each do |dim1|\n pa2.each do |dim2|\n if (dim1+dim2) <= board_a\n p1 = pa1.clone\n p2 = pa2.clone\n p1.delete_at(p1.index(dim1))\n l1 = p1.first\n p2.delete_at(p2.index(dim2))\n l2 = p2.first\n possible = true if [l1, l2].max <= board_b\n end\n if (dim1+dim2) <= board_b\n p1 = pa1.clone\n p2 = pa2.clone\n p1.delete_at(p1.index(dim1))\n l1 = p1.first\n p2.delete_at(p2.index(dim2))\n l2 = p2.first\n possible = true if [l1, l2].max <= board_a\n end\n end\nend\nif possible \n puts 'YES'\nelse\n puts 'NO'\nend", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation"], "code_uid": "6218a4458926d389a9b43c8f45f98767", "src_uid": "2ff30d9c4288390fd7b5b37715638ad9", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "\n\ndef try(b1, b2, size)\n newb1 = []\n newb2 = []\n#place b1\n if (b1[0] > size[0] or b1[1] > size[1])\n #try to put it the other way\n #puts 'flip'\n b1[0], b1[1] = b1[1], b1[0]\n end\n\n newb1 = [size[0] - b1[0], b1[1]]\n if (b1[1] == size[1])\n newb2 = [size[0] - b1[0], size[1] - b1[1]]\n else\n newb2 = [size[0], size[1] - b1[1]]\n end\n\n #p newb1.inspect\n #p newb2.inspect\n\n#b1 wont fit\n if newb2[0] < 0 || newb2[1] < 0 || newb1[0] < 0 || newb1[1] < 0\n puts \"NO\"\n exit\n end\n\n#try and fit b1 on newb1 or new b2\n newb1_fit_norm = newb1[0] >= b2[0] && newb1[1] >= b2[1]\n newb1_fit_flip = newb1[0] >= b2[1] && newb1[1] >= b2[0]\n newb1_fit = newb1_fit_norm || newb1_fit_flip\n\n newb2_fit_norm = newb2[0] >= b2[0] && newb2[1] >= b2[1]\n newb2_fit_flip = newb2[0] >= b2[1] && newb2[1] >= b2[0]\n newb2_fit = newb2_fit_norm || newb2_fit_flip\n newb1_fit || newb2_fit\nend\n\nsize = gets.split(' ').collect { |i| i.to_i }\nb1 = gets.split(' ').collect { |i| i.to_i }\nb2 = gets.split(' ').collect { |i| i.to_i }\n\n\n\nif (try(b1,b2, size) or try(b2,b1,size))\n puts 'YES'\nelse\n puts 'NO'\nend\n\n", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation"], "code_uid": "305b8ac973aca50120f901f7fd74bcb1", "src_uid": "2ff30d9c4288390fd7b5b37715638ad9", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def read_ints; gets.chomp.split.map(&:to_i) end\ndef max(*values); values.max end\n\nextend Math\narea = read_ints\nfirst = read_ints\nsecond = read_ints\n\n[first, first.reverse].each do |first_rotated|\n\t[second, second.reverse].each do |second_rotated|\n\t\tif first_rotated[0]+second_rotated[0]<=area[0] && max(first_rotated[1],second_rotated[1])<=area[1]\n\t\t\tputs \"YES\"\n\t\t\texit\n\t\telsif first_rotated[1]+second_rotated[1]<=area[1] && max(first_rotated[0],second_rotated[0])<=area[0]\n\t\t\tputs \"YES\"\n\t\t\texit\n\t\tend\n\tend\nend\nputs 'NO' #otherwise\n", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation"], "code_uid": "cb095caa6ec6a358b6ce1616d4acc661", "src_uid": "2ff30d9c4288390fd7b5b37715638ad9", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "bae8b7dec39d1ef38544f0d4a276eb5e", "src_uid": "2c4b2a162563242cb2f43f6209b59d5e", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "l,r=gets.split.map &:to_i;t=1;t*=10 while t<=r;p=[[t/2,l].max,r].min;p p*(t-1-p)\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "91fb571594b7fa5804b4656d8c1b6e14", "src_uid": "2c4b2a162563242cb2f43f6209b59d5e", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "l, r = gets.split.map(&:to_i)\na, b, answer = 1, 9, 0\nwhile a <= r\n c, d = [l, a].max, [r, b].min\n if c <= d\n answer = [(b - c) * c, (b - d) * d, answer].max\n if c <= b / 2 and b / 2 <= d\n answer = [(b - b / 2) * (b / 2), answer].max\n end\n end\n a *= 10\n b *= 10\n b += 9\nend\nputs answer\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "2e54d04c5c0216f82ff2bbf24397133f", "src_uid": "2c4b2a162563242cb2f43f6209b59d5e", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.strip.to_i\na = gets.strip.split.map(&:to_i)\nans = \"YES\"\ni = 0\nvisited = Array.new(3, false)\nwhile i < n - 1\n prev = a[i]\n i += 1\n curr = a[i]\n if prev < curr\n if !visited[0]\n visited[0] = true\n else\n if visited[1] || visited[2]\n ans = \"NO\"\n break\n end\n end\n elsif prev == curr\n visited[0] = true if !visited[0]\n if !visited[1]\n visited[1] = true\n else\n if !visited[0] || visited[2]\n ans = \"NO\"\n break\n end\n end\n else\n visited[0] = true if !visited[0]\n visited[1] = true if !visited[1]\n if !visited[2]\n visited[2] = true\n else\n if !visited[0] || !visited[1]\n ans = \"NO\"\n break\n end\n end\n end\nend\nputs ans\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "2968eec878d4bc359b3b22b185d22d78", "src_uid": "5482ed8ad02ac32d28c3888299bf3658", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "95d0a9362775d7bcd839fc8b7a5f270b", "src_uid": "5482ed8ad02ac32d28c3888299bf3658", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "k = gets.to_i\n\narr = 0, *gets.split.map{|x| x.to_i}.sort\n\nans = k - 25\n\n1.upto(k){|i| ans += arr[i] - arr[i - 1] - 1}\n\nputs [0, ans].max", "lang_cluster": "Ruby", "tags": ["greedy", "implementation"], "code_uid": "1be91ceb1488c6f1e2d604adb6847d51", "src_uid": "ef657588b4f2fe8b2ff5f8edc0ab8afd", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\nputs [0, gets.split.map(&:to_i).max - n - (25 - n)].max\n", "lang_cluster": "Ruby", "tags": ["greedy", "implementation"], "code_uid": "6433894bfa6ab6634cb5049e1f08b7a7", "src_uid": "ef657588b4f2fe8b2ff5f8edc0ab8afd", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "gets;p [0,gets.split.map(&:to_i).max-25].max", "lang_cluster": "Ruby", "tags": ["greedy", "implementation"], "code_uid": "89533fd51ad574970b07c7c69063ecab", "src_uid": "ef657588b4f2fe8b2ff5f8edc0ab8afd", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "w,h=gets.split.map{|i| i.to_i}\np (w+w%2)*(w/2)*(h+h%2)*(h/2)/4\n", "lang_cluster": "Ruby", "tags": ["brute force", "math"], "code_uid": "3108ce6328a4f0b2c884ac9f476235f8", "src_uid": "42454dcf7d073bf12030367eb094eb8c", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "w,h=gets.split.map{|i| i.to_i}\np (w+w%2)*(w/2)*(h+h%2)*(h/2)/4\n", "lang_cluster": "Ruby", "tags": ["brute force", "math"], "code_uid": "ab421c4daaa345da569a40beeec119ef", "src_uid": "42454dcf7d073bf12030367eb094eb8c", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "w,h=gets.split.map{|i| i.to_i}\np (w+w%2)*(w/2)*(h+h%2)*(h/2)/4\n", "lang_cluster": "Ruby", "tags": ["brute force", "math"], "code_uid": "0e38c1cb42f3a295c4c300d142a9fa4d", "src_uid": "42454dcf7d073bf12030367eb094eb8c", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, k, t = gets.strip.split.map(&:to_i)\nans = [t, k, n + k - t].min\nputs ans\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "71ff0be0c9cdcb293c32ae40e2780123", "src_uid": "7e614526109a2052bfe7934381e7f6c2", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, k, t = gets.split.map{|a| a.to_i}\nputs (\n\tif t < k\n\t\tt\n\telsif t > n\n\t\tk - t + n\n\telse\n\t\tk\n\tend\n)", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "106154ce2260e887de781c2b741fe9cc", "src_uid": "7e614526109a2052bfe7934381e7f6c2", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, k, t = gets.split.map &:to_i\nif t <= k\n puts t\nelsif n + 1 <= t\n puts k - t + n\nelse\n puts k\nend\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "27dd0cc3bee02d72e35df6c91d249b8a", "src_uid": "7e614526109a2052bfe7934381e7f6c2", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "ans = 0\ndef fib(n, m)\n i = 0\n a, b, c, d = 1, 1, 1, 0\n aa, bb, cc, dd = 1, 0, 0, 1\n while (1 << i) <= n\n if (n & (1 << i)) > 0 then\n aa, bb, cc, dd = (aa*a+bb*c)%m, (aa*b+bb*d)%m, (cc*a+dd*c)%m, (cc*b+dd*d)%m\n end\n a, b, c, d = (a*a+b*c)%m, (a*b+b*d)%m, (c*a+d*c)%m, (c*b+d*d)%m\n i += 1\n end\n (aa + bb) % m\nend\ndef pow(x, y, m)\n i = 0\n ret = 1\n while (1 << i) <= y\n if (y & (1 << i)) > 0 then\n ret = ret * x % m\n end\n x = x * x % m\n i += 1\n end\n ret\nend\nn, k, l, m = gets.split.map &:to_i\nif k < 2 ** l then\n ans = 1 % m\n num0 = fib(n, m)\n num1 = (pow(2, n, m) - num0 + m) % m\n l.times do |i|\n if (k & (1 << i)) == 0 then\n ans = ans * num0 % m\n else\n ans = ans * num1 % m\n end\n end\nend\nputs ans", "lang_cluster": "Ruby", "tags": ["math", "combinatorics", "matrices", "implementation", "number theory"], "code_uid": "e6f6f0e44b4a7f7ddb26f6a9c0dd5840", "src_uid": "2163eec2ea1eed5da8231d1882cb0f8e", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\n\nnumbers = []\n\nsum = 0\n(1..500).each do |num|\n sum += num\n numbers << sum\nend\n\nputs numbers.include?(n) ? 'YES' : 'NO'\n", "lang_cluster": "Ruby", "tags": ["brute force", "math"], "code_uid": "f375a5c40eb7bd71628e20ae7f4a1ccb", "src_uid": "587d4775dbd6a41fc9e4b81f71da7301", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.chomp\nn = n.to_i\ni = 1\nwhile i <= n do\n if i * (i + 1) == n * 2\n break\n end\n i = i + 1\nend\n\nif i <= n\n puts \"YES\"\nelse\n puts \"NO\"\nend\n\n", "lang_cluster": "Ruby", "tags": ["brute force", "math"], "code_uid": "957ce11e4dc8ef5d828e03029b4a37d8", "src_uid": "587d4775dbd6a41fc9e4b81f71da7301", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\ni = 1\ns = 1\nwhile s<=n do\n if s==n\n print \"YES\"\n exit\n end\n i+=1\n s=i*(i+1)/2\nend\nprint \"NO\"\n", "lang_cluster": "Ruby", "tags": ["brute force", "math"], "code_uid": "4d64c2ed0601b7c76c7f2f93268adac8", "src_uid": "587d4775dbd6a41fc9e4b81f71da7301", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "cbc580bb2c890a52e4aa58eea6dd1dad", "src_uid": "e17df52cc0615585e4f8f2d31d2daafb", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a, b, c = gets.split.map(&:to_i)\n\nweek = [a / 3, b / 2, c / 2].min\n\nla = a - 3 * week\nlb = b - 2 * week\nlc = c - 2 * week\n\nmax_remain = 0\n\nlist = %w(a a b c a c b) * 2\n\n(1..6).each do |d|\n (0..6).each do |s|\n counter = Hash.new(0)\n\n (s...(s + d)).each do |t|\n counter[list[t]] += 1\n end\n\n if counter['a'] <= la && counter['b'] <= lb && counter['c'] <= lc\n max_remain = d\n end\n end\nend\n\nputs 7 * week + max_remain\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "fdbd5362907c3b9d08ff70e2fb925868", "src_uid": "e17df52cc0615585e4f8f2d31d2daafb", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": " no_ops = gets.chomp.to_i\n ops = gets.chomp.split(\"\")\n pile = 0\n ops.each do |op|\n if op == \"+\"\n pile += 1\n else\n if pile == 0\n pile += 1\n end\n pile -= 1\n end\n end\n puts pile", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "f83be284e2938c660d12c85e97054efa", "src_uid": "a593016e4992f695be7c7cd3c920d1ed", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "4fdd6173984343432f36a019dd9158d3", "src_uid": "a593016e4992f695be7c7cd3c920d1ed", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\ns = gets.chomp.split ''\nc = 0\ns.each do |x|\n c += x == '+' ? 1 : -1\n c = [c, 0].max\nend\nputs c\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "3870ec0ff5ad4adead3d373594438e44", "src_uid": "a593016e4992f695be7c7cd3c920d1ed", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\nQ = 'Q'\nA = 'A'\nqi = []\nai = []\n\ngets.chomp.split(//).each_with_index { |elem, index| \n if elem == Q\n qi << index\n elsif elem == A\n ai << index\n else\n next\n end\n}\n\nseqs = 0\nqi.each { |i|\n ai.each { |j|\n if i < j\n count = 0\n qi.each { |sub_i|\n count += 1 if sub_i > j\n }\n seqs += count\n end\n }\n}\n\nputs seqs\n", "lang_cluster": "Ruby", "tags": ["brute force", "dp"], "code_uid": "1522c528630ea5db227b040e75f7fb66", "src_uid": "8aef4947322438664bd8610632fe0947", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = gets.strip\nn = s.length\nans = 0\nn.times do |i|\n a = s[i]\n ((i + 1)...n).each do |j|\n b = s[j]\n ((j + 1)...n).each do |k|\n c = s[k]\n ans += 1 if a + b + c == \"QAQ\"\n end\n end\nend\nputs ans\n", "lang_cluster": "Ruby", "tags": ["brute force", "dp"], "code_uid": "e88c46627e01080a5ff2da55a7661e4b", "src_uid": "8aef4947322438664bd8610632fe0947", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "S = gets\n\nQ = ?Q\nA = ?A\n\nq = qa = qaq = 0\n\nS.each_char do |c|\n \n if c == Q\n \n q += 1\n qaq += qa\n \n elsif c == A\n \n qa += q\n \n end\n \nend\n\nputs qaq", "lang_cluster": "Ruby", "tags": ["brute force", "dp"], "code_uid": "37186dd6ad9dfe9c5b721ede6b6aa515", "src_uid": "8aef4947322438664bd8610632fe0947", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "990341dec8224ffc429a1238abace7d6", "src_uid": "ec1e44ff41941f0e6436831b5ae543c6", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b=gets.split.map &:to_f\nputs'=><'[b*Math.log(a)<=>a*Math.log(b)]", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "07579bb18559b579790b2b0c51d06aed", "src_uid": "ec1e44ff41941f0e6436831b5ae543c6", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def solution(a,b)\n if a == b\n return \"=\"\n end\n\n var = a**(Float(b)/Float(a))\n if var == b\n \"=\"\n elsif var > b\n \">\"\n else\n \"<\"\n end\nend\n\n\ninput = gets.rstrip.split(' ').map(&:to_i)\n\nputs solution input[0], input[1]", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "28f638435694f6d30356326e895bbbce", "src_uid": "ec1e44ff41941f0e6436831b5ae543c6", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, m = gets.split.map &:to_i\n\noptimal_move_count = (n / 2.0).ceil\nworst_move_count = n\n\nif optimal_move_count % m == 0\n puts optimal_move_count\nelse\n optimal_moves = m - (optimal_move_count % m) + optimal_move_count\n answer = optimal_moves <= worst_move_count ? optimal_moves : -1 \n puts answer\nend", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "824e357b93f0ae82e791260b47b2aaef", "src_uid": "0fa526ebc0b4fa3a5866c7c5b3a4656f", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, m = STDIN.readline.split.map {|s| s.to_i }\nif m > n\n\tputs -1\n\texit\nend\nk = (n + 2*m - 1) / (2*m)\nputs k*m\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "243e2fdfc5febc7df763328e85d0c768", "src_uid": "0fa526ebc0b4fa3a5866c7c5b3a4656f", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "# cook your code here\n\nn,m=gets.chomp.split\n\nn = n.to_i\nm = m.to_i\n\nif n%2==0 \n c = n/2 \nelse \n c = n/2 + 1 \nend \n\nif m>n \n puts \"-1\"\nelsif m==n \n puts m \nelse \n until c%m==0 \n c+=1 \n end \n puts c \nend \n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "1c81bdc1150c81fd80ae1894536bd798", "src_uid": "0fa526ebc0b4fa3a5866c7c5b3a4656f", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["binary search", "combinatorics"], "code_uid": "c2df7e83d3638bccd0de3af12b6cf8f1", "src_uid": "24e2f10463f440affccc2755f4462d8a", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "MOD = 10 ** 9 + 7\nN, X, P = gets.split.map(&:to_i)\nA = [*1..N]\n\nup_cnt = N - X\ndown_cnt = X - 1\ntargets = []\n\nleft = 0\nright = A.size\nans = 1\n\nwhile left < right\n middle = (left + right) / 2\n\n if middle < P\n targets << [middle, :up]\n left = middle + 1\n ans *= down_cnt\n down_cnt -= 1\n elsif middle == P\n targets << [middle, :equal]\n left = middle + 1\n else\n targets << [middle, :down]\n right = middle\n ans *= up_cnt\n up_cnt -= 1\n end\n\n ans %= MOD\nend\n\n2.upto(up_cnt + down_cnt) do |i|\n ans *= i\n ans %= MOD\nend\n\nputs ans\n", "lang_cluster": "Ruby", "tags": ["binary search", "combinatorics"], "code_uid": "6f5bb7e1592977e1e34215a07ccaca59", "src_uid": "24e2f10463f440affccc2755f4462d8a", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def raise(y, n, mod)\n\tres = 1\n\tx = y\n\twhile n != 0\n\t\tres = (res*x)%mod if n%2 != 0\n\t\tx = (x*x)%mod\n\t\tn = n/2\n\tend\n\tres\nend\nn, mod = gets.split.map(&:to_i)\nans = (raise(3, n, mod) - 1)%mod\nputs ans\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "a50efadcf2c3cd873c1a2b6d3fb3c66b", "src_uid": "c62ad7c7d1ea7aec058d99223c57d33c", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def pow(a, b)\n return a if (b==1) \n return 1 if (b==0)\n c = pow(a,b/2)\n c = (c * c) % $mod\n c = (c * a) % $mod if (b % 2==1)\n c\nend\n\nn, m = *gets.split.map {|x|x.to_i}\n$mod = m\nputs (pow(3, n) - 1 + m) % m", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "28f5c356701aaa4700d9f3e4a5c1becb", "src_uid": "c62ad7c7d1ea7aec058d99223c57d33c", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "a0a5f9e12b70e274ff216118a86a39f5", "src_uid": "c62ad7c7d1ea7aec058d99223c57d33c", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "# frozen_string_literal: true\n\nn, k = readline.strip.split.map(&:to_i)\n\nans = (2 * n + k - 1) / k + (5 * n + k - 1) / k + (8 * n + k - 1) / k\n\np ans\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "7263c87a3235172d005bfd8bd4342730", "src_uid": "d259a3a5c38af34b2a15d61157cc0a39", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b=gets.split.map &:to_i;r=0;[2,5,8].map{|i|r+=(i*a+b-1)/b};p r", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "a382fdcb057a2d80b2bb117ac46eb5c5", "src_uid": "d259a3a5c38af34b2a15d61157cc0a39", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "nk = gets.chomp.split(\" \").map(&:to_f)\nn = nk[0]\nk = nk[1]\nred = ((2*n)/k).ceil\ngreen = ((5*n)/k).ceil\nblue = ((8*n)/k).ceil\n\nputs red+green+blue\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "43f2f596eb17f8392218a18d3d3e200c", "src_uid": "d259a3a5c38af34b2a15d61157cc0a39", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.chomp.to_i\nm = gets.chomp.to_i\nputs (m % (2 ** n)).to_i", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "46c1e443fa73a71a5d535d7fa074be95", "src_uid": "c649052b549126e600691931b512022f", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\n# 2**n mod m\n# m mod 2**n reversed!\nn = gets.to_i\nm = gets.to_i\nlg2_m = Math.log2(m).floor\n\nif lg2_m >= n\n puts m%(1< i\n\t\t\tans += 1\n\t\tend\n\tend\nend\nputs ans\n", "lang_cluster": "Ruby", "tags": ["brute force"], "code_uid": "dbb44073456031bdfae4f539c874ae58", "src_uid": "838f2e75fdff0f13f002c0dfff0b2e8d", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, cnt = gets.to_i, 0\n(1..n).each do |a|\n (a..n).each do |b|\n c = a ^ b\n cnt += 1 if b <= c && c <= n && c < a + b\n end\nend\nputs cnt\n", "lang_cluster": "Ruby", "tags": ["brute force"], "code_uid": "ff24ea6389e988413ec5e53b15299650", "src_uid": "838f2e75fdff0f13f002c0dfff0b2e8d", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\nans = 0\nn.times do |i|\n (i+1).times do |j|\n a,b = j+1,i+1\n c = a ^ b\n ans += 1 if (b-a) < c && c < (a+b) && c <= n && b <= c\n end\nend\nputs ans", "lang_cluster": "Ruby", "tags": ["brute force"], "code_uid": "b2c95b711c6a26a54098701a42c1189e", "src_uid": "838f2e75fdff0f13f002c0dfff0b2e8d", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "$n, $m, $t = gets.split(' ').map { |x| x.to_i }\ndef factorial(n)\n return (2..n).reduce(1) { |x,y| x*y }\nend\ndef c_n_k(n, k)\n return factorial(n) / (factorial(k) * factorial(n-k))\nend\ndef f()\n res = 0\n n, m = 4, $t-4\n while m > 0\n res += c_n_k($n, n) * c_n_k($m, m)\n n += 1\n m -= 1\n end\n return res\nend\nputs f()\n", "lang_cluster": "Ruby", "tags": ["math", "combinatorics"], "code_uid": "449ea1ae94e950b193152aae08faf4cf", "src_uid": "489e69c7a2fba5fac34e89d7388ed4b8", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, m, t = gets.split.collect{|i| i.to_i}\nans = 0\nb = 4\nwhile b <= n\n ans += Array.new(n).combination(b).size * Array.new(m).combination(t-b).size if t-b>=1 and t-b<=m\n b += 1\nend\nputs ans\n", "lang_cluster": "Ruby", "tags": ["math", "combinatorics"], "code_uid": "ba11c8b2aec50f63161b5ed4f9658f86", "src_uid": "489e69c7a2fba5fac34e89d7388ed4b8", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def fact(n)\n n<= 1 ? 1 : n * fact(n - 1)\nend\ndef cc(n,k)\n fact(n)/fact(k)/fact(n-k)\nend\nn, m, t = gets.split.map(&:to_i)\nans = 0\n(4..n).each do |b|\n break if t-b < 1\n ans += cc(n, b)*cc(m, t-b)\nend\nputs ans", "lang_cluster": "Ruby", "tags": ["math", "combinatorics"], "code_uid": "cd53d5c0adb7484180138108d1738745", "src_uid": "489e69c7a2fba5fac34e89d7388ed4b8", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.to_i\nc=gets.count(?8)\np [n/11,c].min", "lang_cluster": "Ruby", "tags": ["brute force"], "code_uid": "0f80b3e71cd899d7c93b153d23423d4c", "src_uid": "259d01b81bef5536b969247ff2c2d776", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\ns = gets.chomp\n\nputs [n/11, s.count('8')].min", "lang_cluster": "Ruby", "tags": ["brute force"], "code_uid": "998ae60d50d3f7523adddedc44a1f243", "src_uid": "259d01b81bef5536b969247ff2c2d776", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\ns = gets.chomp\nputs [s.count('8'), s.size/11].min\n", "lang_cluster": "Ruby", "tags": ["brute force"], "code_uid": "4fd7cc71c2a4013b24dcf679fb155b19", "src_uid": "259d01b81bef5536b969247ff2c2d776", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s, v1, v2, t1, t2 = gets.split.map(&:to_i)\np1 = s * v1 + t1 * 2\np2 = s * v2 + t2 * 2\nif p1 == p2\n puts 'Friendship'\nelsif p1 < p2\n puts 'First'\nelse\n puts 'Second'\nend\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "b4524718f40fbba466b97ae6b40aac5f", "src_uid": "10226b8efe9e3c473239d747b911a1ef", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s,v1,v2,t1,t2=gets.split.map{|e| e.to_i}\na=s*v1+t1*2\nb=s*v2+t2*2\nif ab then\n\tputs \"Second\"\nelse\n\tputs \"Friendship\"\nend\n\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "3432db6a19d0960cad4061396c013ed4", "src_uid": "10226b8efe9e3c473239d747b911a1ef", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s, v1, v2, t1, t2=gets.split.map &:to_i\na1=(v1*s)+2*t1\na2=v2*s+2*t2\nputs (a1==a2 ? \"Friendship\" : a1 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", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "c5a4ebca236760fa8f0fe0a1f8085cec", "src_uid": "084a12eb3a708b43b880734f3ee51374", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "code = gets.chomp\ncode = (code[0] + code[2] + code[4] + code[3] + code[1])\nputs (code.to_i ** 5).to_s.chars.last(5).join\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "89dc55adea9f9ad9b59c97d2765f326a", "src_uid": "51b1c216948663fff721c28d131bf18f", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s=gets;s=[0,2,4,3,1].map{|e|s[e]}*'';printf(\"%05d\\n\",(s.to_i**5)%100000)", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "c32e9a377e8c80e0c7cd111a2a1e2c05", "src_uid": "51b1c216948663fff721c28d131bf18f", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\nl = 0\nr = 10**14\nwhile l+1 0 and is(b[k], b[k - 1]) \n d = b.dup\n d[k - 1] = d[k]\n r = r | doit(d[0..k - 1])\n end\n if k - 2 > 0 and is(b[k], b[k - 3]) \n d = b.dup\n d[k - 3] = d[k]\n r = r | doit(d[0..k - 1])\n end\n return @ma[b.join] = r\nend\n\ngets.to_i\nputs doit(gets.split) ? \"YES\" : \"NO\"\n", "lang_cluster": "Ruby", "tags": ["dfs and similar", "dp"], "code_uid": "d28ab6d365eaf26b6785a98c80c658e8", "src_uid": "1805771e194d323edacf2526a1eb6768", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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<0\n\ttable[xx%10]=true\n\txx/=10\nend\npd=x.prime_division.map{|a,b|0.upto(b).map{|i|a**i}}\ndivisors=pd.first\npd[1..-1].each{|divs|divisors=divs.map{|d|divisors.map{|e|d*e}}.flatten}\nans=0\ndivisors.each{|d|\n\twhile d>0\n\t\tif table[d%10]\n\t\t\tans+=1\n\t\t\tbreak\n\t\tend\n\t\td/=10\n\tend\n}\np ans", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "ed31f5259914254c3891a6d9b6dedbb8", "src_uid": "ada94770281765f54ab264b4a1ef766e", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "require 'set'\n\nn, k = gets().split().map(&:to_i)\n\nseen = [].to_set\nshit = false\nfor i in 1..[k,1000].min\n\tr = n % i\n\tif seen.include? r\n\t\tshit = true\n\t\tbreak\n\telse\n\t\tseen.add(r)\n\tend\nend\n\nif shit\n\tputs \"No\"\nelse\n\tputs \"Yes\"\nend\n", "lang_cluster": "Ruby", "tags": ["brute force", "number theory"], "code_uid": "90241add15b2dc1b688f6ab338ff0467", "src_uid": "5271c707c9c72ef021a0baf762bf3eb2", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,k = gets.split.map(&:to_i)\nif k > 42\n ans = \"No\"\nelse\n i = 2\n flag = true\n while flag && i <= k\n flag = false if n % i != i-1\n i += 1\n end\n ans = flag ? \"Yes\" : \"No\"\nend\nputs ans\n", "lang_cluster": "Ruby", "tags": ["brute force", "number theory"], "code_uid": "9605d5a63a40a006d835f734e983e476", "src_uid": "5271c707c9c72ef021a0baf762bf3eb2", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s=gets.chomp\np s.size.times.map{|i|s[i..-1]+s[0,i]}.uniq.size", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "d75bd1d687d5da6b712a7d2d7c0a3f20", "src_uid": "8909ac99ed4ab2ee4d681ec864c7831e", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s=gets.chomp.chars\np (1..s.size).map{s.rotate!*''}.uniq.size", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "dc12c74183af53ddeb4c90fadef4f1a2", "src_uid": "8909ac99ed4ab2ee4d681ec864c7831e", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "arr = gets.chomp.chars\narr1 = Array.new(arr)\nc = 1\narr.rotate!\nuntil arr == arr1\n arr.rotate!\n c += 1\nend\np c", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "4f740d1845927c1ee468bd33c36ab00b", "src_uid": "8909ac99ed4ab2ee4d681ec864c7831e", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def judge(a, b)\n return false if b == 0\n return false if b == 1 && a != 0\n return false if (a - b + 1) < 0\n return false if (a - b + 1) % 2 == 1\n return true\nend\n\na, b = gets.split.map(&:to_i)\nif judge(a, b)\n puts \"Yes\"\nelse\n puts \"No\"\nend\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "edb9209c8a683e83b7e53c34290e7698", "src_uid": "1527171297a0b9c5adf356a549f313b9", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "x,y = gets.split.map(&:to_i)\nif (x+y) % 2 == 0 || y == 0 || (y==1 && x>=1)\n ans = \"No\"\nelsif\n ans = ((x-y) >= -1 && (x-y) % 2 == 1) ? \"Yes\" :\"No\"\nend\nputs ans\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "149c961b259eb791a68ee589586a9d79", "src_uid": "1527171297a0b9c5adf356a549f313b9", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "x,y=gets.split.map &:to_i\nputs (x==0&&y==1)||(x+2>y&&y>1&&(x-y)%2>0)?:Yes: :No", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "3b739ac9a74d364aadd18223fda8aacc", "src_uid": "1527171297a0b9c5adf356a549f313b9", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "fact = [1] * 50\n1.upto(49) do |i|\n fact[i] = fact[i - 1] * i\nend\n\nn = gets.strip.chars.map &:to_i\n\ncnt = [0] * 10\nn.each do |d|\n cnt[d] += 1\nend\n\ndfs = -> (d, take) do\n if d == 10\n r = 0\n cc = take.inject :+\n return 0 if cc == 0\n u = fact[cc]\n (0...10).each do |i|\n u /= fact[take[i]]\n end\n if cnt[0] > 0\n choose = -> (n, m) do\n return 0 if n < m\n fact[n] / fact[m] / fact[n - m]\n end\n h = -> (n, m) do\n choose[n + m - 1, m]\n end\n (1..cnt[0]).each do |i|\n r += u * h[cc, i]\n end\n else\n r = u\n end\n r\n else\n if cnt[d] > 0\n (1..cnt[d]).map do |i|\n take[d] = i\n dfs[d + 1, take]\n end.inject :+\n else\n dfs[d + 1, take]\n end\n end\nend\n\nputs dfs[1, [0] * 10]\n", "lang_cluster": "Ruby", "tags": ["brute force", "math", "combinatorics"], "code_uid": "9c9447faa9095c8e84f25cbab324f507", "src_uid": "7f4e533f49b73cc2b96b4c56847295f2", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = gets.chomp\nlen = s.length\nputs ((len+1)*26)-len\n=begin\naba\n=end\n", "lang_cluster": "Ruby", "tags": ["brute force", "math", "strings"], "code_uid": "880b5ef9b60d939e12ed06a53eced44b", "src_uid": "556684d96d78264ad07c0cdd3b784bc9", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "str = gets().chomp()\n\na = str.split('')\n\nh = {}\nfor i in (0..a.length())\n for c in ('a'..'z')\n h[a.insert(i,c).join('').to_sym]=nil\n a.delete_at(i)\n end\nend\n\nputs h.length()\n", "lang_cluster": "Ruby", "tags": ["brute force", "math", "strings"], "code_uid": "f6cabab028bdf5329fefc8cb6b5b32f4", "src_uid": "556684d96d78264ad07c0cdd3b784bc9", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "letters = gets.chomp.chars\n\nputs (letters.length + 1) * 26 - letters.length\n", "lang_cluster": "Ruby", "tags": ["brute force", "math", "strings"], "code_uid": "a283a66299680ede3d6ab4dc1d6ca503", "src_uid": "556684d96d78264ad07c0cdd3b784bc9", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["math", "binary search"], "code_uid": "4c602e228dd3d9eb9eccb210797a8209", "src_uid": "ff3c39b759a049580a6e96c66c904fdc", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def dist(p1, p2)\n (p1[0] - p2[0]).abs + (p1[1] - p2[1]).abs\nend\n\nx0, y0, ax, ay, bx, by = gets.chomp.split(' ').map(&:to_i)\nxs, ys, t = gets.chomp.split(' ').map(&:to_i)\nMAX = 63\n\narr = [[x0, y0]]\n(1..MAX).each do |_|\n x = ax * arr[-1][0] + bx\n y = ay * arr[-1][1] + by\n arr << [x, y]\nend\n\nans = 0\narr.length.times do |i|\n rem_time = t - dist([xs, ys], arr[i])\n if rem_time >= 0\n curr = 1\n j = i+1\n while j < arr.length\n rem_time -= dist(arr[j-1], arr[j])\n break if rem_time < 0\n curr += 1\n j += 1\n end\n ans = curr if curr > ans\n\n curr = 1\n j = i-1\n rem_time = t - dist([xs, ys], arr[i])\n while j >= 0\n rem_time -= dist(arr[j], arr[j+1])\n break if rem_time < 0\n curr += 1\n j -= 1\n end\n ans = curr if curr > ans\n end\nend\nputs ans", "lang_cluster": "Ruby", "tags": ["brute force", "constructive algorithms", "implementation"], "code_uid": "fa5e86fe3f351b4ae8e33ac18948f570", "src_uid": "d8a7ae2959b3781a8a4566a2f75a4e28", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "matr=[]\n8.times{matr<b ? \"B\" : \"A\"\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "77246de2a60ad841cac3dc83084cd3da", "src_uid": "0ddc839e17dee20e1a954c1289de7fbd", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "# http://codeforces.com/contest/592/problem/A\n# A. PawnChess\n\ncols = [].tap do |arr|\n 8.times { arr << gets.chomp.chars }\nend\nb_idx = []\nw_idx = []\ncols.transpose.each do |row|\n b = row.rindex('B')\n w = row.rindex('W')\n b_idx << 7 - b if b && (w.nil? || (b > w))\n\n b = row.index('B')\n w = row.index('W')\n w_idx << w if w && (b.nil? || (b > w))\nend\n\nif !b_idx.empty? && (w_idx.empty? || b_idx.min < w_idx.min)\n puts 'B'\nelse\n puts 'A'\nend\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "b8273a81debc812d14e99e56fbd27fa1", "src_uid": "0ddc839e17dee20e1a954c1289de7fbd", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/env ruby\n\nrequire 'matrix'\n\nrows = 8.times.map do gets.chars.to_a end\nMATRIX = Matrix.rows(rows)\n\ndef win_in_colA(col_no)\n (0..7).each do |row_no|\n if MATRIX[row_no, col_no] == 'W'\n return row_no\n elsif MATRIX[row_no, col_no] == 'B'\n return 9\n end\n end\n return 9\nend\n\ndef win_in_colB(col_no)\n (0..7).to_a.reverse.each do |row_no|\n if MATRIX[row_no, col_no] == 'B'\n return 7-row_no\n elsif MATRIX[row_no, col_no] == 'W'\n return 9\n end\n end\n return 9\nend\n\nsteps_for_A = (0..7).map do |col_n|\n win_in_colA(col_n)\nend\n\nsteps_for_B = (0..7).map do |col_n|\n win_in_colB(col_n)\nend\n\nwho_won = (steps_for_B.min < steps_for_A.min) ? 'B' : 'A'\nputs who_won\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "6a33263fa6185f7cee637756fd8e2f39", "src_uid": "0ddc839e17dee20e1a954c1289de7fbd", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\nleast = Array.new()\nleast.push(1)\nleast.push(2)\nif(n == 2)\n\tprint 1,\"\\n\"\nelse\n\ti = 2\n\tuntil (least[i-2] + least[i-1] > n)\n\t\tleast.push(least[i-2] + least[i-1])\n\t\ti = i + 1\n\tend\n\tprint i-1,\"\\n\"\nend", "lang_cluster": "Ruby", "tags": ["math", "greedy", "constructive algorithms", "combinatorics"], "code_uid": "820f53d12ec376328ba40c18cdbd6aa2", "src_uid": "3d3432b4f7c6a3b901161fa24b415b14", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["dfs and similar", "constructive algorithms", "math", "dp", "combinatorics"], "code_uid": "c35cdbd3311b69711a8344138f661c53", "src_uid": "3d3432b4f7c6a3b901161fa24b415b14", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "line = gets\nnumbers = line.split(\" \")\nchips =numbers[1].to_i\npeopleNum =numbers[0].to_i\ni = 1\nwhile chips > -1\nif chips - i > -1\n chips -= i\nelse \n break\nend\n i += 1\n if i == peopleNum +1 \n i = 1\n end \nend\nputs chips", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "e955cb6b0be7299317c8d156456a0c3c", "src_uid": "5dd5ee90606d37cae5926eb8b8d250bb", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,m=gets.split.map(&:to_i)\n(1..n).cycle{|_|break if m<_;m-=_}\np m\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "2683673f5b4286e62e638c5b069d5f12", "src_uid": "5dd5ee90606d37cae5926eb8b8d250bb", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,m = gets.chomp.split(/ /).map!{|x| x.to_i}\ni = 1\nwhile true\n break if m < i\n m -= i\n i += 1\n i = 1 if n < i\nend\nputs m\n\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "70b96d606ad02a28722d0988fcbd44e5", "src_uid": "5dd5ee90606d37cae5926eb8b8d250bb", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a, b = gets.chomp.split.map &:to_i\ns = gets.chomp.chars.map{|x|x.ord-'a'.ord+1}.sort\nres = []\ni = 0\n\nwhile i < a && res.size != b\n if res.size < 1\n res << s[i]\n elsif (res[-1] - s[i]).abs > 1\n res << s[i] \n end\n i += 1\nend\n\np res.size < b ? -1 : res.reduce(:+)", "lang_cluster": "Ruby", "tags": ["sortings", "implementation", "greedy"], "code_uid": "99f9e8b902f06fb9a3413ef325e1a962", "src_uid": "56b13d313afef9dc6c6ba2758b5ea313", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "N, k = gets.split.map(&:to_i)\nS = gets.chomp.split('').map{|c| c.ord - 'a'.ord + 1}.sort\nsum = 0\nprev = -1\nN.times do |i|\n if prev + 2 <= S[i]\n prev = S[i]\n sum += S[i]\n k -= 1\n break if k == 0\n end\nend\nputs k == 0 ? sum : -1", "lang_cluster": "Ruby", "tags": ["sortings", "implementation", "greedy"], "code_uid": "7bbb2ab37fbca0c8ff0ffd8138b29682", "src_uid": "56b13d313afef9dc6c6ba2758b5ea313", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, k = gets.strip.split.map(&:to_i)\nhsh = {}\n('a'..'z').each.with_index{|c, i| hsh[c]=i+1 }\nstr = gets.strip\nary = []\nstr.each_char{|c| ary << hsh[c]}\nary.sort!\n\ni = 0\nans=[ary[i]]\n2.upto(k).each do\n (i+1).upto(n-1).each do |j|\n if ary[j]-ary[i] > 1\n ans << ary[j]\n i = j\n break\n end\n end\nend\n\nif ans.size == k\n puts ans.inject(:+)\nelse\n puts -1\nend\n", "lang_cluster": "Ruby", "tags": ["sortings", "implementation", "greedy"], "code_uid": "d46f9e5c86c63bc2eb195acfdacd8794", "src_uid": "56b13d313afef9dc6c6ba2758b5ea313", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b=gets.split.map{|e| e.to_i}\nd=2\n\nans=\"\"\nwhile a>=0 && b>=0\n\ta-=(d-1)\n\tif a<0 then\n\t\tans=\"Vladik\"\n\t\tbreak\n\tend\n\tb-=d\n\tif b<0 then\n\t\tans=\"Valera\"\n\t\tbreak\n\tend\n\t\n\td+=2\nend\nputs ans\n\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "5c8d08ba3cb4a883598eaa55c62fc12c", "src_uid": "87e37a82be7e39e433060fd8cdb03270", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "83d6b79a9918c3d28825d5b6ae9c4556", "src_uid": "87e37a82be7e39e433060fd8cdb03270", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/ruby\nclass Integer\n\tdef isqrt\n\t\treturn 0 if self<=0\n\t\treturn 1 if self<4 # 1\n\t\tx,y=0,self\n\t\twhile x!=y&&x+1!=y\n\t\t\tx,y=y,(self/y+y)/2\n\t\tend\n\t\tx\n\tend\nend\n\na,b=gets.split.map &:to_i\na=a.isqrt\nputs [:Vladik,:Valera,:Vladik][a*-~a<=>b]", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "56461ad536d71d301f885a6304b20b77", "src_uid": "87e37a82be7e39e433060fd8cdb03270", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "arr=[]\nc=\" abcdefgh\"\n(1..8).map{|e| (1..8).map{|i| arr<<[e,i]}}\ns=gets.chomp\n\nx=c.index(s[0])\ny=s[1].to_i\n\nans=0\n(-1..1).each{|dx|\n\t(-1..1).each{|dy|\n\t\n\t\tans+=1 if arr.index([x+dx,y+dy])\n\t}\n}\nputs ans-1\n\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "8be0afa398b22363dccf26a9f958a70b", "src_uid": "6994331ca6282669cbb7138eb7e55e01", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "cmd=gets.chomp\nif cmd[0]=='a' || cmd[0]=='h'\n if cmd[1]=='1' || cmd[1]=='8'\n puts \"3\"\n else\n puts \"5\"\n end\nelse\n if cmd[1]=='1' || cmd[1]=='8'\n puts \"5\"\n else\n puts \"8\"\n end\nend\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "eeca206ba9f8df2f0802bf4c7c5aa9a1", "src_uid": "6994331ca6282669cbb7138eb7e55e01", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = gets.chomp\n\nans = 8\nans = 5 if s[0]=='a' or s[0]=='h' or s[1]=='1' or s[1]=='8'\nans = 3 if s=='a1' or s=='a8' or s=='h1' or s=='h8'\n\nputs ans", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "d1ecf49a85f690c0f26d40f1a2ed871a", "src_uid": "6994331ca6282669cbb7138eb7e55e01", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\n\nk = 2\ns = 0\nn.times do\n s += k\n k *= 2\nend\n\nputs s", "lang_cluster": "Ruby", "tags": ["math", "combinatorics"], "code_uid": "4f887fd9d5324455b52cef834deea7df", "src_uid": "f1b43baa14d4c262ba616d892525dfde", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.chomp.to_i;\nans = 0;\nn.times{|i| ans += 2**(i+1)}\np ans\n", "lang_cluster": "Ruby", "tags": ["math", "combinatorics"], "code_uid": "3cf3ae844b50cbbd90207e7e0f816251", "src_uid": "f1b43baa14d4c262ba616d892525dfde", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.chomp.to_i\n\nans = 0\n\n(1..n).each do |i|\nans = ans + (2**i)\nend\n\nputs ans\n", "lang_cluster": "Ruby", "tags": ["math", "combinatorics"], "code_uid": "2553c8ab64f4bcd2be5f70e47d22ce70", "src_uid": "f1b43baa14d4c262ba616d892525dfde", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["math", "number theory"], "code_uid": "95cb7927da7acd328d522567db36cbb3", "src_uid": "6e0715f9239787e085b294139abb2475", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a, b = gets.split.map(&:to_i)\nif a == b \n puts 'infinity'\nelsif ab\n ans+= 1 if x%i == 0 && x/i>b && x!=i**2\n end\n puts ans\nend", "lang_cluster": "Ruby", "tags": ["math", "number theory"], "code_uid": "7a4728bd9c08661dc32d52b5a56af8b4", "src_uid": "6e0715f9239787e085b294139abb2475", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def divisors_of(number)\n divisors = []\n n = 1\n while n <= number ** 0.5\n if number.modulo(n) == 0\n divisors << n\n divisors << number / n unless number / n == n\n end\n n += 1\n end\n divisors.sort\nend\n\na,b = gets.split.map(&:to_i)\nif a == b\n puts \"infinity\"\nelsif a < b\n puts \"0\"\nelse\n puts divisors_of(a-b).select {|x| x > b}.count\nend", "lang_cluster": "Ruby", "tags": ["math", "number theory"], "code_uid": "3466a2df8c05846957ca0b96134c6bff", "src_uid": "6e0715f9239787e085b294139abb2475", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\nk = gets.to_i\na = gets.to_i\nb, ans = gets.to_i, 0\nuntil n < k || n == 1 || k == 1\n m = n%k\n q = n/k\n n -= m\n ans += a*m\n ans += [a*(n-q), b].min\n n -= n-q\nend\nans += a * (n-1)\nputs ans", "lang_cluster": "Ruby", "tags": ["greedy", "dp"], "code_uid": "ea2d8ca4952b64f972e5cd5b88aedf3f", "src_uid": "f838fae7c98bf51cfa0b9bd158650b10", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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 num2[0]\n\tmore = true\nelsif num1[0] < num2[0]\n\tmore = false\nelse\n\tSTDOUT.puts \"NO\"\n\texit\nend\n\nnum1.length.times do |i|\n\tif more\n\t\tif num1[i] <= num2[i]\n\t\t\tSTDOUT.puts \"NO\"\n\t\t\texit\n\t\tend\n\telse\n\t\tif num1[i] >= num2[i]\n\t\t\tSTDOUT.puts \"NO\"\n\t\t\texit\n\t\tend\n\tend\nend\n\nSTDOUT.puts \"YES\"", "lang_cluster": "Ruby", "tags": ["sortings", "greedy"], "code_uid": "6fc5298c94c2594b389e6a3318fca749", "src_uid": "e4419bca9d605dbd63f7884377e28769", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\ns = gets.chomp\n\nl = s[0...n].split(//).map(&:to_i).sort\nr = s[n...2*n].split(//).map(&:to_i).sort\n\nlh, rh = true, true\nfor i in 0...n do\n lh = lh && l[i] < r[i]\n rh = rh && l[i] > r[i]\nend\n\nputs(if lh || rh then \"YES\" else \"NO\" end)", "lang_cluster": "Ruby", "tags": ["sortings", "greedy"], "code_uid": "32993ffbeb4db5ee35b414bebbdfbf25", "src_uid": "e4419bca9d605dbd63f7884377e28769", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def solve(a,b)\n x=[]\n y=[]\n a.length.times do |i|\n x.push(a[i].to_i)\n y.push(b[i].to_i)\n end\n x.sort!\n y.sort!\n\n a.length.times do |i|\n return false if x[i]>=y[i]\n end\n return true\nend\n\nn=gets.to_i\na=gets.split[0]\nx=a[0..n-1]\ny=a[n..2*n-1]\nif solve(x,y) || solve(y,x)\n puts \"YES\"\nelse\n puts \"NO\"\nend\n\n", "lang_cluster": "Ruby", "tags": ["sortings", "greedy"], "code_uid": "38580081ddcc4dc4eb8aa01d22410164", "src_uid": "e4419bca9d605dbd63f7884377e28769", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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|eindex2\n\tindex3=0\n\ttemp = \"\"\n\tindex1.times do\n\t\ttemp=temp+\"1\"\n\tend\n\tloop do\n\t\tbreak if index3>=index1\n\t\ttemp[index3] = \"0\"\n\t\tif temp.to_i(2) >= a && temp.to_i(2)<=b && temp[0] == \"1\"\n\t\t\t#puts temp\n\t\t\tcount+=1\n\t\tend\n\t\ttemp[index3] = \"1\"\n\t\tindex3+=1\n\tend\n\tindex1+=1\nend\n\nputs count\n=begin\ntemp = gets.to_i\n\nstr = temp.to_s(2)\n\nputs str\n\nputs str.to_i(2)\n=end", "lang_cluster": "Ruby", "tags": ["brute force", "implementation", "bitmasks"], "code_uid": "846e9c44352cdc27d91eff1a0a48b3cf", "src_uid": "581f61b1f50313bf4c75833cefd4d022", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a, b = gets.chomp.split.map(&:to_i)\n\ncnt = 0\nfor l in 2..60\n n = 2**l - 1\n for i in 0...l - 1\n m = n - 2**i\n if a <= m && m <= b\n cnt += 1\n end\n end\nend\n\nputs cnt\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation", "bitmasks"], "code_uid": "e2cac0dd647cc551f042c4bded02f0ed", "src_uid": "581f61b1f50313bf4c75833cefd4d022", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,*a=$<.map &:to_i;p a[0,2].min*(2--~n/n)+a.min*[0,n-2].max", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "4cd847b114e37314bbe9426a508ba041", "src_uid": "6058529f0144c853e9e17ed7c661fc50", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.strip.to_i\na = gets.strip.to_i\nb = gets.strip.to_i\nc = gets.strip.to_i\ncurr = 1\nans = 0\nif n > 1\n i = 1\n while i < n\n dist = 0\n case curr\n when 1\n if a <= b\n dist = a\n curr = 2\n else\n dist = b\n curr = 3\n end\n when 2\n if a <= c\n dist = a\n curr = 1\n else\n dist = c\n curr = 2\n end\n when 3\n if c <= b\n dist = c\n curr = 2\n else\n dist = b\n curr = 1\n end\n end\n ans += dist\n i += 1\n end\nend\nputs ans\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "dd370efe2a2d315929cf0310e236d010", "src_uid": "6058529f0144c853e9e17ed7c661fc50", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\na = gets.to_i\nb = gets.to_i\nc = gets.to_i\nn -= 1\nx = [a, b, c].min\ntot = 0\nif n >= 1\n tot += [a, b].min\n tot += (n - 1) * x\nend\nputs tot\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "9ee3474b1442caf9a883edec7eb1b942", "src_uid": "6058529f0144c853e9e17ed7c661fc50", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\na = gets.split.map &:to_i\nll = nil\nl = a[0]\nans = 0\n(1...n).each do |i|\n case l\n when 1 # circle\n case a[i]\n when 2 # triangle\n ans += 3\n ans -= 1 if ll == 3\n when 3 # square\n ans += 4\n end\n when 2 # triangle\n case a[i]\n when 1 # circle \n ans += 3\n when 3 # square\n ans = -1\n break\n end\n when 3 # square\n case a[i]\n when 1 # circle \n ans += 4\n when 2 # triangle\n ans = -1\n break\n end\n end\n ll = l\n l = a[i]\nend\nif ans < 0\n puts \"Infinite\"\nelse\n puts \"Finite\"\n puts ans\nend\n", "lang_cluster": "Ruby", "tags": ["geometry"], "code_uid": "f77285e4e9842f1834daa5f5fdf24f11", "src_uid": "6c8f028f655cc77b05ed89a668273702", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["geometry"], "code_uid": "d0b1c3d69ae481b464bbf3efc12afe24", "src_uid": "6c8f028f655cc77b05ed89a668273702", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\n\nans = 0\n(n-1).times do |i|\n t = [a[i],a[i+1]]\n if t == [3,2] || t == [2,3] || t[0] == t[1] \n ans = -1\n break\n elsif (i >= 1 && a[i-1,3] == [3,1,2])\n ans += 2\n elsif t == [1,2] || t == [2,1]\n ans += 3\n elsif t == [1,3] || t == [3,1]\n ans += 4\n end\nend\nputs ans == -1 ? \"Infinite\" : \"Finite\"\nputs ans if ans >= 0\n\n", "lang_cluster": "Ruby", "tags": ["geometry"], "code_uid": "94fc534f95eca3255307c3a756693631", "src_uid": "6c8f028f655cc77b05ed89a668273702", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "line = gets.chomp\na,b,width,height = line.split(' ').map!(&:to_i)\n\ngreatest_common_divider = width.gcd(height)\nnormalized_width = width/greatest_common_divider\nnormalized_height = height/greatest_common_divider\n\na_times = (a/normalized_width).floor\nb_times = (b/normalized_height).floor\n\nputs [a_times, b_times].min", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "e8da39fde49786338fcb338c417b9ab1", "src_uid": "907ac56260e84dbb6d98a271bcb2d62d", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def maxx(x, y)\n x > y ? x : y\nend\n\ndef minn(x, y)\n x < y ? x : y\nend\n\ndef get_nod(k, j)\n mx = maxx(k, j)\n mn = minn(k, j)\n\n res = mx % mn;\n\n if res == 0\n return mn;\n else\n get_nod(res, mn);\n end\nend\n\n\n\nw, h, x, y = gets.chomp.split(' ').map(&:to_i)\n\nnod = get_nod(x, y);\nx = x / nod;\ny = y / nod;\n\nf = w / x;\ns = h / y;\n\nputs minn(f, s);\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "1f7c6ee6c7ffe639ea8c4e7b0752bf9e", "src_uid": "907ac56260e84dbb6d98a271bcb2d62d", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b,x,y = gets.chomp.split.map(&:to_i)\nd = [a*y,b*x].min\nk = x.lcm(y)\nputs d/k\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "e655c0481883611dd691d12f9320a84c", "src_uid": "907ac56260e84dbb6d98a271bcb2d62d", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a = (gets.to_i+1)/3\nputs [a/12, a%12].join(\" \")", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "06fe378ed7fc9cc9d984184595096017", "src_uid": "5d4f38ffd1849862623325fdbe06cd00", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i + 1\nputs [n / 36, n / 3 % 12] * \" \"\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "dc1f0af69e305f6c2694fce3e11d868f", "src_uid": "5d4f38ffd1849862623325fdbe06cd00", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=(gets.to_i+1)/3\nputs n.divmod(12)*' '", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "35e78766e2ad1501665694fc281eb115", "src_uid": "5d4f38ffd1849862623325fdbe06cd00", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s=gets\nputs ([\"Danil\", \"Olya\", \"Slava\", \"Ann\", \"Nikita\"].map{|x| s.scan(x).count}.inject(:+)==1 ? \"YES\" : \"NO\")\n", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "b7036322184073c8592e1420d99e2159", "src_uid": "db2dc7500ff4d84dcc1a37aebd2b3710", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "names = %w(Danil Olya Slava Ann Nikita)\nline = gets.chomp\n\ncount = names.map { |name| line.scan(name).count }.reduce(&:+)\nputs count == 1 ? 'YES' : 'NO'", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "e296bdae9a9bee32a4ab5eb46cc122d1", "src_uid": "db2dc7500ff4d84dcc1a37aebd2b3710", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "48f4430036a576ff2091d80f30b9ad2d", "src_uid": "db2dc7500ff4d84dcc1a37aebd2b3710", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\na = gets.split.map(&:to_i).uniq.sort\nif a.size > 3 || (a.size == 3 && a[2]-a[1] != a[1]-a[0])\n puts \"-1\"\nelsif a.size == 1\n puts 0\nelsif a.size == 3\n puts a[1]-a[0]\nelsif (a[1]-a[0])%2 == 0\n puts (a[1]-a[0])/2\nelse\n puts a[1]-a[0]\nend", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "1e6cfbcccf454b9fcd46cd40d7f006d3", "src_uid": "d486a88939c132848a7efdf257b9b066", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "N = gets.to_i\nA = gets.split.map(&:to_i)\n\nans = Float::INFINITY\n\n(0..200).each do |target|\n d = -1\n\n list = A.select { |a| a != target }\n\n if list.empty?\n d = 0\n else\n d = (list[0] - target).abs\n\n list.each do |a|\n if (target - a).abs != d\n d = -1\n break\n end\n end\n end\n\n if d != -1\n ans = d if ans > d\n end\nend\n\nif ans == Float::INFINITY\n puts -1\nelse\n puts ans\nend\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "2bb34825459a9c893227e0806a93be19", "src_uid": "d486a88939c132848a7efdf257b9b066", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def in_words(int)\n numbers_to_name = {\n 1000000 => \"million\",\n 1000 => \"thousand\",\n 100 => \"hundred\",\n 90 => \"ninety\",\n 80 => \"eighty\",\n 70 => \"seventy\",\n 60 => \"sixty\",\n 50 => \"fifty\",\n 40 => \"forty\",\n 30 => \"thirty\",\n 20 => \"twenty\",\n 19=>\"nineteen\",\n 18=>\"eighteen\",\n 17=>\"seventeen\", \n 16=>\"sixteen\",\n 15=>\"fifteen\",\n 14=>\"fourteen\",\n 13=>\"thirteen\", \n 12=>\"twelve\",\n 11 => \"eleven\",\n 10 => \"ten\",\n 9 => \"nine\",\n 8 => \"eight\",\n 7 => \"seven\",\n 6 => \"six\",\n 5 => \"five\",\n 4 => \"four\",\n 3 => \"three\",\n 2 => \"two\",\n 1 => \"one\"\n }\n str = \"\"\n numbers_to_name.each do |num, name|\n if int == 0\n return str\n elsif int.to_s.length == 1 && int/num > 0\n return str + \"#{name}\" \n elsif int < 100 && int/num > 0\n return str + \"#{name}\" if int%num == 0\n return str + \"#{name} \" + in_words(int%num)\n elsif int/num > 0\n return str + in_words(int/num) + \" #{name} \" + in_words(int%num)\n end\n end\nend\n\nputs in_words(gets.to_i).chars.include?(?n) ? :NO : :YES", "lang_cluster": "Ruby", "tags": ["brute force"], "code_uid": "44a0548e9dddb16e8df4bc850a2b4cfb", "src_uid": "821529a4644b74483bcdf80fc318d1f8", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\np n == 0 ? 0 : n % 2 != 0 ? (n + 1) / 2 : n + 1", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "3c23d58a0e03baeb155deb64b2466803", "src_uid": "236177ff30dafe68295b5d33dc501828", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "cf7a5e46964e1374dc3249dd17ce631c", "src_uid": "236177ff30dafe68295b5d33dc501828", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.to_i\np n>1 ? n+1>>n%2 : n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "33ad06d147a8ae65a9626b0e415af6ff", "src_uid": "236177ff30dafe68295b5d33dc501828", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "class Fixnum\n def compare(fixnum)\n return -1 if self < fixnum\n return 1 if self > fixnum\n return 0 if self == fixnum\n end\nend\n\nclass Tram\n attr_reader(:s, :x1, :x2, :t1, :t2, :p, :d)\n def initialize(s, x1, x2, t1, t2, p, d)\n @s = s\n @x1 = x1\n @x2 = x2\n @t1 = t1\n @t2 = t2\n @p = p\n @d = d\n end\n\n def direction\n x2.compare(x1)\n end\n\n def by_foot\n (x1 - x2).abs * t2\n end\n\n def wait_time\n if(direction == d)\n if(d == -1)\n if(p < x1)\n (((p + s) + (s - x1))) * t1\n else\n (x1 - p).abs * t1\n end\n else\n if(p <= x1)\n (x1 - p).abs * t1\n else\n ((s - p) + s + x1) * t1\n end\n end\n else\n if(d == -1)\n (p * t1) + (x1 * t1)\n else\n ((s - p) * t1) + ((s - x1) * t1)\n end\n end\n end\n\n def tram_time\n (x1 - x2).abs * t1\n end\n\n def by_tram\n wait_time + tram_time\n end\nend\n\ndef main\n s, x1, x2 = gets.split(\" \").map(&:to_i)\n t1, t2 = gets.split(\" \").map(&:to_i)\n p, d = gets.split(\" \").map(&:to_i)\n tram = Tram.new(s, x1, x2, t1, t2, p, d)\n cands = [tram.by_tram, tram.by_foot]\n puts cands.select{|x| x >= 0 }.min\nend\n\nmain\n", "lang_cluster": "Ruby", "tags": ["math", "constructive algorithms", "implementation"], "code_uid": "f2716b10a63de0eed484d61a15122f59", "src_uid": "fb3aca6eba3a952e9d5736c5d8566821", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/ruby\nrequire 'timeout'\nbegin\n\ttimeout(1.1){loop{}}\nrescue Timeout::Error\n\tputs gets.split.map(&:to_i)[1..-1].sort*' '\nend", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "bf068493ea26040cb30e9cc6e152b310", "src_uid": "29e481abfa9ad1f18e6157c9e833f16e", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "require 'timeout'\nbegin\n\ttimeout(1){loop{}}\nrescue Timeout::Error\n\tputs gets.split.map(&:to_i)[1..-1].sort*' '\nend", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "e851dbceaf6583727cd1d9e7a64557c0", "src_uid": "29e481abfa9ad1f18e6157c9e833f16e", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a = gets.split(/\\s+/).map(&:to_i)\na = a[1..-1]\nb = [1,2,4,3]\n3000000.times do |_|\n b.shuffle.sort\nend\n\nprint a.sort.join(' ')\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "8c8ab97b1ec74886483ad7173ad7c991", "src_uid": "29e481abfa9ad1f18e6157c9e833f16e", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = gets.chomp\nans = \"\"\nwhile (s.length > 0) do\n if s.length % 2 == 0 \n ans += s.slice!(-1)\n else\n ans += s.slice!(0)\n end\nend\nputs ans.reverse", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "babd1562020ba15cf38c94aafeabacd4", "src_uid": "992ae43e66f1808f19c86b1def1f6b41", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "str = gets.chomp\n\nnewstr = \"\"\n\nlen = str.length\nwhile len > 0\n if len%2==0\n newstr = str[-1] + newstr\n str = str[0..-2]\n else\n newstr = str[0] + newstr\n str = str[1..-1]\n end\n len -= 1\nend\n\nputs newstr\n", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "d7d4780d15f963bf1e2bf0f57ab3204f", "src_uid": "992ae43e66f1808f19c86b1def1f6b41", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "t = gets.strip\ns = ''\nwhile t.size > 0\n if t.size%2 == 0\n s = t[-1] + s\n t = t[0..-2]\n else\n s = t[0] + s\n t = t[1..-1]\n end\nend\nputs s\n", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "f16bc274902fa39c2eb4aad1cccacd84", "src_uid": "992ae43e66f1808f19c86b1def1f6b41", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "require 'date'\n\nd = Date.new(1990, 1, 1)\nlist = (12*12).times.map do\n res = d.prev_day.day\n d = d.next_month\n res.chr\nend.join\n\nn = gets.to_i\narr = gets.split.map(&:to_i).map(&:chr).join\n\nif list.include?(arr)\n puts \"YES\"\nelse\n puts \"NO\"\nend\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "d64456bca73a9f0188dce3b9e40fc4fd", "src_uid": "d60c8895cebcc5d0c6459238edbdb945", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "# Input\nn = gets.to_i\n\n# Processing\nresult = case n % 4\n when 1 then 1\n when 2 then 1\n when 3 then 0\n when 0 then 0\nend\n\n# Output\nputs result\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "dc0707ea2e8d47f87b425ca6e002e552", "src_uid": "fa163c5b619d3892e33e1fb9c22043a9", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\nputs n * (n + 1) / 2 % 2\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "164aaf5e2024cda5c62a95013d7f0aab", "src_uid": "fa163c5b619d3892e33e1fb9c22043a9", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "p -~gets.to_i/2%2", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "25fa89b135feaedd8881086509023bfc", "src_uid": "fa163c5b619d3892e33e1fb9c22043a9", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.to_i\nres=n\n(1..4).each{|i|\n [2, 3, 5, 7].combination(i).each{|j|\n x=j.inject :*\n if j.size.odd?\n res-=n/x\n else\n res+=n/x\n end\n }\n}\np res\n", "lang_cluster": "Ruby", "tags": ["math", "number theory"], "code_uid": "563ac693c6826a062e57fa5e787a2845", "src_uid": "e392be5411ffccc1df50e65ec1f5c589", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "f=->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]", "lang_cluster": "Ruby", "tags": ["math", "number theory"], "code_uid": "d97dabeb941a089e7d31eb8d398b62b1", "src_uid": "e392be5411ffccc1df50e65ec1f5c589", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def read_ints\n gets.chomp.split.map {|s| s.to_i}\nend\n\nn, m = read_ints\na = read_ints\nb = read_ints\n\nans = []\namb = false\n\ndef shares_one p, q, r, s\n ret = nil\n if p == r || p == s then ret = p end\n if q == r || q == s then ret = (ret == nil ? q : nil) end\n return ret\nend\n\nfor i in 0...n do\n for j in 0...m do\n x = shares_one a[i * 2], a[i * 2 + 1], b[j * 2], b[j * 2 + 1]\n if x != nil then\n cand = []\n for k in 0...m do\n y = shares_one a[i * 2], a[i * 2 + 1], b[k * 2], b[k * 2 + 1]\n if y != nil then cand.push y end\n end\n for k in 0...n do\n y = shares_one a[k * 2], a[k * 2 + 1], b[j * 2], b[j * 2 + 1]\n if y != nil then cand.push y end\n end\n cand.uniq!\n if cand.length == 1 then\n ans.push cand[0]\n else\n amb = true\n end\n end\n end\nend\n\nans.uniq!\nif amb then\n puts -1\nelsif ans.length == 1 then\n puts ans[0]\nelse\n puts 0\nend\n", "lang_cluster": "Ruby", "tags": ["brute force", "bitmasks"], "code_uid": "18800cf40598933a6e5b051aa5d29130", "src_uid": "cb4de190ae26127df6eeb7a1a1db8a6d", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["bitmasks"], "code_uid": "668f5c110ff653ecc03b7b6d6cf3ec54", "src_uid": "cb4de190ae26127df6eeb7a1a1db8a6d", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,x,y,c=gets.split.map &:to_i\nl,r,x,y=-1,n*2,x-1,y-1\nwhile l+1=c then r=m else l=m end\nend\np r", "lang_cluster": "Ruby", "tags": ["math", "implementation", "binary search"], "code_uid": "793c9f10de4fcebdd392db94961e36d3", "src_uid": "232c5206ee7c1903556c3625e0b0efc6", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,x,y,c=gets.split.map &:to_i\nl,r,x,y=-1,n*2,x-1,y-1\nwhile l+1=c then r=m else l=m end\nend\np r", "lang_cluster": "Ruby", "tags": ["math", "implementation", "binary search"], "code_uid": "89c55f5f8877b8cae7d50cbb4045c05a", "src_uid": "232c5206ee7c1903556c3625e0b0efc6", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["brute force", "math", "binary search"], "code_uid": "49232dc7bcbd56a03de12cd526ebdb0e", "src_uid": "232c5206ee7c1903556c3625e0b0efc6", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s=gets.chomp.sub(/0+$/,'')\nputs s==s.reverse ? :YES : :NO", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "b86848636b04a8b3d58978da081924ce", "src_uid": "d82278932881e3aa997086c909f29051", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "44fad7417d6786fdd83fb155909493af", "src_uid": "d82278932881e3aa997086c909f29051", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s=gets.chomp\n\nli=s.count('-')\npe=s.count('o')\n\nif pe==0\n puts 'YES'\nelse\n if li%pe==0\n puts 'YES'\n else\n puts 'NO'\n end\nend", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "2ae49b3f868cc7d087d27796012167cd", "src_uid": "6e006ae3df3bcd24755358a5f584ec03", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s=gets.chomp\nc=s.count(?o)\nputs c>0&&s.size%c>0?:No: :Yes", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "4177259dfe840335e5f75c3449c619e4", "src_uid": "6e006ae3df3bcd24755358a5f584ec03", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "PEARL = 'o'\nLINK = '-'\n\nnecklace = STDIN.gets.chomp\n\ndef adjustable?(necklace)\n pearl_count = necklace.count(PEARL)\n return true if pearl_count == 0\n link_count = necklace.count(LINK)\n\n link_count % pearl_count == 0\nend\n\nif adjustable?(necklace)\n puts 'YES'\nelse\n puts 'NO'\nend\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "2a76a747a1105a0f75e3c083fd40865d", "src_uid": "6e006ae3df3bcd24755358a5f584ec03", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/env ruby\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 if lucky_amount > 9\n return\n end\n if party_amount == 6\n for i in lucky_amount + 1..9\n cnt[10] = (cnt[10] + method_amount * cnt[i]) % 1000000007\n end\n else\n for i in 0..9\n if cnt[i]\n cnt[i] -= 1\n dfs(party_amount + 1, lucky_amount + i, (method_amount * (cnt[i] + 1)) % 1000000007, cnt)\n cnt[i] += 1\n end\n end\n end\nend\ndfs(0, 0, 1, cnt)\nputs cnt[10] % 1000000007", "lang_cluster": "Ruby", "tags": ["brute force", "dp", "combinatorics"], "code_uid": "f40623b39da84d7f25397e9d55cf998c", "src_uid": "656ed7b1b80de84d65a253e5d14d62a9", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "\ndef automaton?(s,t) \n\n i = 0\n\n t.each do |tc|\n while (i < s.count)\n if s[i] == tc\n break\n end\n i = i + 1\n end\n if i == s.count\n return false\n else\n i = i + 1\n end\n end\n\n return true;\n\nend\n\n\ns = gets.strip().split(\"\")\n\nt = gets.strip().split(\"\")\n\nif (s.sort == t.sort)\n puts \"array\"\nelsif automaton?(s,t)\n puts \"automaton\"\nelsif automaton?(s.sort,t.sort)\n puts \"both\"\nelse\n puts \"need tree\"\nend", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "0c47b516aba9ab592adbf38b1ac5e94b", "src_uid": "edb9d51e009a59a340d7d589bb335c14", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = gets.split('')\nt = gets.split('')\n\ndef automaton sd,td\n k = 0\n sd.each do |i|\n if i == td[k]\n k += 1\n end\n if k == td.length\n return true\n end\n end\n\n return false\nend\n\nif automaton s,t\n puts 'automaton'\nelsif s.sort! == t.sort!\n puts 'array'\nelsif automaton s.sort!,t.sort!\n puts 'both'\nelse\n puts 'need tree'\nend\n", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "c6894cb87698d0a6cd35d6ab8535cb05", "src_uid": "edb9d51e009a59a340d7d589bb335c14", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = gets.chomp\nt = gets.chomp\n\nsubs = s.dup\nautomaton = t.chars.all? do |c|\n n = subs.index(c)\n n.nil? ? false : subs = subs[n+1..-1]\nend\n\narray = s.chars.sort == t.chars.sort\n\nsubs = s.dup\nboth = t.chars.all? do |c|\n n = subs.index(c)\n n.nil? ? false : subs.slice!(n)\nend\n\nputs case\nwhen automaton; \"automaton\"\nwhen array; \"array\"\nwhen both; \"both\"\nelse \"need tree\"\nend\n", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "1331a885390a80024db564c98a721996", "src_uid": "edb9d51e009a59a340d7d589bb335c14", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\ns = gets.strip\nfeasible = false\n1.upto(n) do |i|\n 0.upto(n-1) do |j|\n okay = true\n 0.upto(4) do |k|\n okay = false if s[j+i*k] != \"*\"\n end\n feasible = true if okay\n end\nend\nif feasible\n puts \"yes\"\nelse\n puts \"no\"\nend\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "48c60f22b311a1c3c10c41371f775c6f", "src_uid": "12d451eb1b401a8f426287c4c6909e4b", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "b58104c78551031beb9fe2c481b392a0", "src_uid": "12d451eb1b401a8f426287c4c6909e4b", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\ns = gets.strip\nfeasible = false\n1.upto(n) do |i|\n 0.upto(n-1) do |j|\n okay = true\n 0.upto(4) do |k|\n okay = false if s[j+i*k] != \"*\"\n end\n feasible = true if okay\n end\nend\nif feasible\n puts \"yes\"\nelse\n puts \"no\"\nend", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "94ca05c57ebdccecf2f928cf6a9cd54b", "src_uid": "12d451eb1b401a8f426287c4c6909e4b", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["greedy"], "code_uid": "a8dd4900e255715b60d7c7169d3eb288", "src_uid": "b9fa2bb8001bd064ede531a5281cfd8a", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n= gets.to_i\na = gets.split(\"\")\na.pop\na.each_index do |i|\n\tmove = a[i]\n\tif move == 'L'\n\t\tk = a.index 'R'\n\t\tif k\n\t\t\ta[i] = 0\n\t\t\ta[k] = 0\n\t\tend\n\tend\n\tif move == 'R'\n\t\tk = a.index 'L'\n\t\tif k\n\t\t\ta[i] = 0\n\t\t\ta[k] = 0\n\t\tend\n\tend\n\tif move == 'U'\n\t\tk = a.index 'D'\n\t\tif k\n\t\t\ta[i] = 0\n\t\t\ta[k] = 0\n\t\tend\n\tend\n\tif move == 'D'\n\t\tk = a.index 'U'\n\t\tif k\n\t\t\ta[i] = 0\n\t\t\ta[k] = 0\n\t\tend\n\tend\nend\ncount = 0\na.each do |move|\n\tcount +=1 if move ==0\nend\nprint(count)\n", "lang_cluster": "Ruby", "tags": ["greedy"], "code_uid": "cbc85bed6b58689e909a8ec04660358b", "src_uid": "b9fa2bb8001bd064ede531a5281cfd8a", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "gets\ns = gets\np ([s.count('L'), s.count('R')].min + [s.count('U'), s.count('D')].min) * 2", "lang_cluster": "Ruby", "tags": ["greedy"], "code_uid": "880e531443a0915ef01de31e554d031c", "src_uid": "b9fa2bb8001bd064ede531a5281cfd8a", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a=gets.split.map(&:to_i).sort\nif a.count(a[0])>=a[0] || a==[2, 4, 4]\n puts \"YES\"\nelse\n puts \"NO\"\nend\n", "lang_cluster": "Ruby", "tags": ["brute force", "constructive algorithms"], "code_uid": "79770f131f2c9d029d78364ec1796857", "src_uid": "df48af9f5e68cb6efc1214f7138accf9", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/env ruby\n# encoding: utf-8\n\nary = gets.split.map(&:to_i).sort\nif ary[0] == 1 || (ary[0] == 2 && ary[1] == 2) || (ary[0] == 2 && ary[1] == 4 && ary[2] == 4) || (ary[0] == 3 && ary[1] == 3 && ary[2] == 3)\n puts 'YES'\nelse\n puts 'NO'\nend\n", "lang_cluster": "Ruby", "tags": ["brute force", "constructive algorithms"], "code_uid": "5c4f0dcd6df24cef41325ede8eac31f2", "src_uid": "df48af9f5e68cb6efc1214f7138accf9", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a, b, f, k = gets.split.map(&:to_i)\nu, v, t, r = (a-f)*2, f*2, b, 0\nEnumerator.new do |y|\n y.yield f\n ((k-1)/2).times {\n y.yield u\n y.yield v\n }\n if k&1 == 0\n y.yield u\n y.yield f\n else\n y.yield a-f\n end\nend.each do |s|\n if t < s\n t = b\n r += 1\n if t < s\n r = -1\n break\n end\n end\n t -= s\nend\np r", "lang_cluster": "Ruby", "tags": ["math", "greedy", "implementation"], "code_uid": "8e566c84cb69502febbb7e97c233d04f", "src_uid": "283aff24320c6518e8518d4b045e1eca", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a, b, f, k = gets.split.map(&:to_i)\nstep = Enumerator.new do |y|\n y.yield f\n u, v = (a-f)*2, f*2\n ((k-1)/2).times {\n y.yield u\n y.yield v\n }\n if k&1 == 0\n y.yield u\n y.yield f\n else\n y.yield a-f\n end\nend\nt, r = b, 0\nstep.each do |s|\n if t < s\n t = b\n r += 1\n if t < s\n r = -1\n break\n end\n end\n t -= s\nend\np r", "lang_cluster": "Ruby", "tags": ["math", "greedy", "implementation"], "code_uid": "e0f1244fb77b9a7e4b65721e092dd67b", "src_uid": "283aff24320c6518e8518d4b045e1eca", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a, b, f, k = gets.split.map{|x| x.to_i}\n\nd = [f]\n(1...k).each do |i|\n\td << 2 * (a - f) if i.odd?\n\td << 2 * f if i.even?\nend\nd << (a - f) if k.odd?\nd << f if k.even?\nd << -1\n\ncurB = b\nans = 0\nd.each_with_index do |l, j|\n\tbreak if l == -1\n\n\tcurB -= l\n\t\n\tif curB < 0\n\t\tp -1\n\t\texit(0)\n\telsif curB < d[j + 1]\n\t\tcurB = b;\n\t\tans += 1;\n\tend\n\t\nend\n\np ans", "lang_cluster": "Ruby", "tags": ["math", "greedy", "implementation"], "code_uid": "a4bd25647d25a32707b7c928c03889c8", "src_uid": "283aff24320c6518e8518d4b045e1eca", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def lscan;gets.split.map(&:to_i);end\n\nx,y,z = lscan\n\npl = x + z > y\nmi = y + z > x\nze = (x - y).abs <= z\n\nif x == y && z == 0\n puts \"0\"\nelsif pl && !mi && !ze\n puts \"+\"\nelsif mi && !pl && !ze\n puts \"-\"\nelse\n puts \"?\"\nend", "lang_cluster": "Ruby", "tags": ["greedy"], "code_uid": "7baa20b99325402cef82b7ee2db74ff7", "src_uid": "66398694a4a142b4a4e709d059aca0fa", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "x, y, z = gets.split.map(&:to_i)\n\nif x > y\n if (x-y).abs > z\n puts '+'\n else\n puts '?'\n end\nelsif x < y\n if (x-y).abs > z\n puts '-'\n else\n puts '?'\n end\nelse\n if z == 0\n puts 0\n else\n puts '?'\n end\nend", "lang_cluster": "Ruby", "tags": ["greedy"], "code_uid": "6bd753c23d4f2759b6bebf24a42d4dc5", "src_uid": "66398694a4a142b4a4e709d059aca0fa", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["greedy"], "code_uid": "a2522de0c618a5e01eacd5bc4e7dc6f1", "src_uid": "66398694a4a142b4a4e709d059aca0fa", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.to_i;s=0;c=[0]*9;(1..n).each{|i|s-=n/i;c[i%9]+=1};9.times{|i|9.times{|j|s+=c[i]*c[j]*c[i*j%9]}};puts s", "lang_cluster": "Ruby", "tags": ["number theory"], "code_uid": "d10ba0dcaf0ceb803c77c42978f2aaf9", "src_uid": "fc133fe6353089a0ebee08dec919f608", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.to_i;s=0;c=[0]*9;(1..n).each{|i|s-=n/i;c[i%9]+=1};9.times{|i|9.times{|j|s+=c[i]*c[j]*c[i*j%9]}};puts s\n", "lang_cluster": "Ruby", "tags": ["number theory"], "code_uid": "a10e112abced8560943e9cfe3d9b47bc", "src_uid": "fc133fe6353089a0ebee08dec919f608", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.to_i;s=0;c=[0]*9;(1..n).each{|i|s-=n/i;c[i%9]+=1};9.times{|i|9.times{|j|s+=c[i]*c[j]*c[i*j%9]}};puts s\n", "lang_cluster": "Ruby", "tags": ["number theory"], "code_uid": "bb17e4d0bd54c944f628fd14e348692c", "src_uid": "fc133fe6353089a0ebee08dec919f608", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Ruby 3", "source_code": "puts (2-gets.to_i**2)", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "31c666003b7679fff709f9246595448c", "src_uid": "f76005f888df46dac38b0f159ca04d5f", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "Ruby 3", "source_code": "x = gets.to_i\r\np 2 - x * x", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "a4008b6e50c2b6974ab76507083c59e6", "src_uid": "f76005f888df46dac38b0f159ca04d5f", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "SORTED = ['B', 'G', 'R']\n\ndef solve(n, cards)\n return cards[0] if cards.uniq.size == 1\n return cards.uniq.sort.join if cards.uniq.size === 3\n\n g = cards.group_by { |x| x }\n x, y = g.map { |k, v| v.size }\n if x == 1 && y == 1\n (SORTED - cards).first\n elsif x > 1 && y > 1\n SORTED.join\n else\n (SORTED - g.select { |k, v| v.size > 1 }.keys).join\n end\nend\n\nputs solve(gets.strip.to_i, gets.strip.split(''))\n", "lang_cluster": "Ruby", "tags": ["math", "dp", "constructive algorithms"], "code_uid": "efa6f6ba0bac02755d09a98a33ca56e6", "src_uid": "4cedd3b70d793bc8ed4a93fc5a827f8f", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["math", "dp", "constructive algorithms"], "code_uid": "bcf2f26182ed5cd7d700d3ccb32c91c8", "src_uid": "4cedd3b70d793bc8ed4a93fc5a827f8f", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.chomp.to_i\ns = gets.chomp\nr = 0\ng = 0\nb= 0\nfor i in 0..n-1\n\tr += 1 if s[i] == 'R'\n\tg += 1 if s[i] == 'G'\n\tb += 1 if s[i] == 'B'\nend\nif r >= 1 && g >= 1 && b >= 1\n\tputs \"BGR\"\n\texit\nend\nif r > 1 && g >1 || g > 1 && b > 1 || r > 1 && b > 1\n\tputs \"BGR\"\n\texit\nend\n\nif r == 0 && g == 0 || g == 0 && b == 0 || r==0 && b == 0\n\tputs \"R\" if r > 0\n\tputs \"G\" if g > 0\n\tputs \"B\" if b > 0\n\texit\nend\n\nif r == 1 && g == 1 || g == 1 && b == 1 || r== 1 && b == 1\n\tputs \"B\" if b == 0\n\tputs \"G\" if g == 0\n\tputs \"R\" if r == 0\n\texit\nend\n\nputs \"BG\" if r > 1\nputs \"GR\" if b > 1\nputs \"BR\" if g > 1\n", "lang_cluster": "Ruby", "tags": ["math", "dp", "constructive algorithms"], "code_uid": "df6dd16e1cb5a8b391bb8358ca633196", "src_uid": "4cedd3b70d793bc8ed4a93fc5a827f8f", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "clock_wise = %w{v < ^ >}\ncounter_clock_wise = %w{v > ^ <}\n\nstart, finish = gets.strip.split\nn = gets.strip.to_i\n\nstart_pos_cw = clock_wise.index start\nstart_pos_ccw = counter_clock_wise.index start\nn %= 4\n\ncw = clock_wise[start_pos_cw + (n - 4)] == finish\nccw = counter_clock_wise[start_pos_ccw + (n - 4)] == finish\n\nif cw && !ccw\n puts \"cw\"\nelsif ccw && !cw\n puts \"ccw\"\nelse\n puts \"undefined\"\nend", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "c80eb0ca66556f27b2b643970fd5611a", "src_uid": "fb99ef80fd21f98674fe85d80a2e5298", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b=gets.split\nn=gets.to_i%4\nif a==?^\n if b==?>\n puts (n==1 ? \"cw\" : n==3 ? \"ccw\" : \"undefined\")\n elsif b==?<\n puts (n==1 ? \"ccw\" : n==3 ? \"cw\" : \"undefined\")\n else\n puts \"undefined\"\n end\nelsif a==?v\n if b==?>\n puts (n==1 ? \"ccw\" : n==3 ? \"cw\" : \"undefined\")\n elsif b==?<\n puts (n==1 ? \"cw\" : n==3 ? \"ccw\" : \"undefined\")\n else\n puts \"undefined\"\n end\nelsif a==?>\n if b==?v\n puts (n==1 ? \"cw\" : n==3 ? \"ccw\" : \"undefined\")\n elsif b==?^\n puts (n==1 ? \"ccw\" : n==3 ? \"cw\" : \"undefined\")\n else\n puts \"undefined\"\n end\nelse\n if b==?v\n puts (n==1 ? \"ccw\" : n==3 ? \"cw\" : \"undefined\")\n elsif b==?^\n puts (n==1 ? \"cw\" : n==3 ? \"ccw\" : \"undefined\")\n else\n puts \"undefined\"\n end\nend\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "29bb2687ba54f87e31793381b7f766b0", "src_uid": "fb99ef80fd21f98674fe85d80a2e5298", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def foo()\n x,y=gets.split.map(&:to_i)\n u = x**2+y**2\n d = (u**0.5).to_i\n return \"black\" if d**2 == u\n return \"black\" if (d % 2==1)^(x*y > 0)\n return \"white\"\nend\n\nputs foo", "lang_cluster": "Ruby", "tags": ["math", "geometry", "constructive algorithms", "implementation"], "code_uid": "172832099fefb0b20f6459c89d395875", "src_uid": "8c92aac1bef5822848a136a1328346c6", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "x,y = gets.split.map(&:to_i)\n\nsqrt = ((x**2 + y**2)**0.5)\n\nif sqrt == sqrt.to_i then\n\tputs 'black'\nelse\n\tif ( (sqrt.to_i % 2).zero? )\n\t\t\tputs (x*y > 0) ? 'black' : 'white'\n\t\telse\n\t\t\tputs (x*y > 0) ? 'white' : 'black'\n\tend \t\nend", "lang_cluster": "Ruby", "tags": ["math", "geometry", "constructive algorithms", "implementation"], "code_uid": "f14ac2448ac3f7a3760b39ffc4de113b", "src_uid": "8c92aac1bef5822848a136a1328346c6", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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 dmax)\n\n max=l\n\n end\n\n l=0\n\n else\n \n l+=1\n\n end\n\nend\n\nif (l>max)\n\n max=l\n\nend\n\nmax=max+1\n\nputs max", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "d92aa64aa3e45834f9625217687c7ed4", "src_uid": "1fc7e939cdeb015fe31f3cf1c0982fee", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = gets.strip\nputs s.split(/[AEIOUY]/).map{|x| x.size+1}.max || 1\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "812c0c3b40bcfd1be899f83eb5ca34ce", "src_uid": "1fc7e939cdeb015fe31f3cf1c0982fee", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,a,b,p,q = gets.split.map{|a| Integer(a)}\ndiva = n/a\ndivb = n/b\ndivab = n/(a.lcm(b))\nprint [[diva*p , (divb-divab)*q], [divb*q , (diva-divab)*p]].map{|a| a.inject(:+)}.max", "lang_cluster": "Ruby", "tags": ["math", "implementation", "number theory"], "code_uid": "ded3f1e616e4d3bae8da2a731c990207", "src_uid": "35d8a9f0d5b5ab22929ec050b55ec769", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["math", "implementation", "number theory"], "code_uid": "f86c148248b6e2ad4f3174624d1b13cd", "src_uid": "35d8a9f0d5b5ab22929ec050b55ec769", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "puts [:No, :Yes][gets.split.uniq.size == 1? 1:0]", "lang_cluster": "Ruby", "tags": ["math", "greedy", "geometry", "brute force"], "code_uid": "466483f0e5fdf45c569043c4b254f8c0", "src_uid": "65f81f621c228c09915adcb05256c634", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "puts ['No', 'Yes'][gets.split.uniq.size == 1? 1:0]", "lang_cluster": "Ruby", "tags": ["math", "greedy", "geometry", "brute force"], "code_uid": "0f7ec77793a6ee035052f6112db25ec3", "src_uid": "65f81f621c228c09915adcb05256c634", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\nt = gets.strip\ni = 0\nd = 1\ns = ''\nwhile i < t.size\n s += t[i]\n i += d\n d += 1\nend\nputs s\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "db43830212781da7b39ff5d18e75863f", "src_uid": "08e8c0c37b223f6aae01d5609facdeaf", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.to_i\ns=gets.split('')\nidx=0\nans=\"\"\nctr=1\nwhile idx (a+l)*(b+l)/k\n m = (a+l)*(b+l)/k\n ans = l\n end\nend\nputs ans\n", "lang_cluster": "Ruby", "tags": ["brute force", "math", "number theory"], "code_uid": "54d502ee7fbd515883003f92c8621da9", "src_uid": "414149fadebe25ab6097fc67663177c3", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "require 'prime'\n\nclass Integer\n def divisor_list\n return [] if self <= 0\n return [1] if self == 1\n\n prime_division.map.with_index { |(base, k), i|\n s = i.zero? ? 0 : 1\n (s..k).map { |n| base ** n }\n }.inject { |res, e| res + res.flat_map { |t| e.map { |v| t * v } } }.sort\n end\nend\n\nA, B = gets.split.map(&:to_i).sort\n\nif A == B\n puts 0\n exit\nend\n\nk = B - A\nmin_lcm = Float::INFINITY\nans = Float::INFINITY\n\nk.divisor_list.each do |x|\n d = x * (A / x.to_f).ceil - A\n\n lcm = (A + d).lcm(B + d)\n\n if min_lcm > lcm\n min_lcm = lcm\n ans = d\n end\nend\n\nputs ans\n", "lang_cluster": "Ruby", "tags": ["brute force", "math", "number theory"], "code_uid": "8eed4275e2efe8283eb03809d07040e9", "src_uid": "414149fadebe25ab6097fc67663177c3", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def solution(s1, s2)\n x = s1.count(\"+\") - s1.count(\"-\") \n @memo = Array.new(11) { Array.new(20) }\n \n def solve(s2, pos, i, x)\n return @memo[i][pos+10] if @memo[i][pos+10]\n\n if s2.size == i\n return 0 if pos != x\n return 1\n end\n\n if s2[i] == \"?\"\n @memo[i][pos+10] = solve(s2, pos+1, i+1, x) + solve(s2, pos-1, i+1, x)\n return @memo[i][pos+10] \n end\n\n @memo[i][pos+10] = solve(s2, pos+(s2[i] == \"+\" ? 1 : -1), i+1, x)\n end\n\n if s2.count(\"?\") == 0\n return Float(solve(s2, 0, 0, x))\n else\n return solve(s2, 0, 0, x) / Float(2**s2.count(\"?\"))\n end\nend\n\ns1 = gets.strip\ns2 = gets.strip\nputs solution(s1, s2)\n", "lang_cluster": "Ruby", "tags": ["brute force", "math", "dp", "combinatorics", "bitmasks", "probabilities"], "code_uid": "fe34f2dc974cb6670592052d53bd9b92", "src_uid": "f7f68a15cfd33f641132fac265bc5299", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s1 = gets.chomp.chars\ns2 = gets.chomp.chars\n\n\ndef get_position(chars)\n chars.map do |c|\n case c\n when '+' then 1\n when '-' then -1\n end\n end.inject(:+)\nend\n\ndef get_combinations(chars)\n if chars.include? '?'\n pos_chars = chars.dup\n neg_chars = chars.dup\n index = chars.index('?')\n pos_chars[index] = '+'\n neg_chars[index] = '-'\n get_combinations(pos_chars) + get_combinations(neg_chars)\n else\n [chars]\n end\nend\n\ndest = get_position(s1)\nopts = get_combinations(s2).map{|cs| get_position(cs) }\n\nconforms = opts.count{|c| c == dest }\n\nres = conforms.to_f / opts.count\n\nputs \"%.12f\" % res\n", "lang_cluster": "Ruby", "tags": ["brute force", "math", "dp", "combinatorics", "bitmasks", "probabilities"], "code_uid": "18a5b206d40746e9689343bd712a7382", "src_uid": "f7f68a15cfd33f641132fac265bc5299", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def f(n)\n\tif n == 0\n\t\treturn 1\n\telse \n\t\treturn f(n-1)*n\n\tend\nend\ns1 = gets.chomp\ns2 = gets.chomp \nx1 = x2 = n = 0\np = 0.5\nfor i in 0...s1.length\n\tif s1[i] == '+'\n\t\tx1 += 1\n\telse\n\t\tx1 -= 1\n\tend\nend\nfor i in 0...s2.length\n\tif s2[i] == '+'\n\t\tx2 += 1\n\telsif s2[i] == '-'\n\t\tx2 -= 1\n\telse\n\t\tn += 1\n\tend\nend\nk = (x1-x2).abs\nif n < k or (k+n)%2==1\n\tputs 0.0\nelse\n\tl =(k+n)/2\n\tputs f(n)/(f(l)*f(n-l))*p**n\nend\n", "lang_cluster": "Ruby", "tags": ["brute force", "math", "dp", "combinatorics", "bitmasks", "probabilities"], "code_uid": "bf5cda268ca6b78084741a78590d2c6e", "src_uid": "f7f68a15cfd33f641132fac265bc5299", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "\ndef pos s\n p=q=0\n s.strip.each_char do |c|\n case c\n when '+'\n p+=1\n when '-'\n p-=1\n else\n q+=1\n end\n end\n [p,q]\nend\n\ndef comb n, k\n if k==0\n 1\n else\n comb(n,k-1)*(n-k+1)/k\n end\nend\n\ndef chance os, q\n if os.abs>q || os%2!=q%2\n 0\n else\n 1.0*comb(q,(q-os.abs)/2)/(2**q)\n end\nend\n\ntgt,_ = pos readline\nsrc,q = pos readline\n\nos = tgt-src\nputs chance(os,q)\n", "lang_cluster": "Ruby", "tags": ["brute force", "math", "dp", "combinatorics", "bitmasks", "probabilities"], "code_uid": "543dbd051b19eb9e34ae9be985956445", "src_uid": "f7f68a15cfd33f641132fac265bc5299", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "intended = STDIN.readline.strip\nreceived = STDIN.readline.strip\ntarget = intended.count('+') - intended.count('-')\norigin = received.count('+') - received.count('-')\nsteps = received.count('?')\nlocation = Hash.new(0.0)\nlocation[origin] = 1.0\nsteps.times do\n\tnext_location = Hash.new(0.0)\n\tlocation.each do |x, p|\n\t\tnext_location[x-1] += p/2\n\t\tnext_location[x+1] += p/2\n\tend\n\tlocation = next_location\nend\nputs location[target]\n", "lang_cluster": "Ruby", "tags": ["brute force", "math", "dp", "combinatorics", "bitmasks", "probabilities"], "code_uid": "30d157530439e7b986b3dee49fc3d9e7", "src_uid": "f7f68a15cfd33f641132fac265bc5299", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "comment = []\ncomment = gets.chomp\nreceive = []\nreceive = gets.chomp\n\nn = comment.length\ncomment_plus = 0\ncomment_minus = 0\nfor i in 0...n\n if comment[i] == \"+\"\n comment_plus += 1\n else\n comment_minus += 1\n end\nend\nreceive_plus = 0\nreceive_minus = 0\nreceive_ques = 0\nfor i in 0...n\n if receive[i] == \"+\"\n receive_plus += 1\n elsif receive[i] == \"-\"\n receive_minus += 1\n else\n receive_ques += 1\n end\nend\n\noffset = ((comment_plus - receive_plus) - (comment_minus- receive_minus)).abs\na = (offset + receive_ques) / 2\nb = (receive_ques - offset) / 2\nprobability = 1\nreceive_ques.times do\n probability = probability * 2\nend\nques_factorial = (1..receive_ques).inject(:*) || 1\na_factorial = (1..a).inject(:*) || 1\nc = (1..b).inject(:*) || 1\ntime = ques_factorial / a_factorial / c\npercentage = time.to_f / probability\nif comment_minus == receive_minus && comment_plus == receive_plus\n puts 1\nelsif comment_plus < receive_plus || comment_minus < receive_minus\n puts 0\nelse\n puts percentage\nend\n", "lang_cluster": "Ruby", "tags": ["brute force", "math", "dp", "combinatorics", "bitmasks", "probabilities"], "code_uid": "6fffffead9170cf8e7e3b5cbbfb0173e", "src_uid": "f7f68a15cfd33f641132fac265bc5299", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a = gets.chop.split('')\nb = gets.chop.split('')\nai=0\nfor i in 0...a.size\n\tif (a[i] == '+')\n\t\tai+=1\n\telse\n\t\tai-=1\n\tend\nend\nbi=[]\nbi[0]=0\nfor i in b\n\tif i =='+'\n\t\tfor j in 0...bi.size\n\t\t\tbi[j]+=1\n\t\tend\n\telsif i == '-' \n\t\tfor j in 0 ... bi.size\n\t\t\tbi[j]-=1\n\t\tend\n\telse i == '?'\n\t\tv = bi.size\n\t\tfor j in 0...v\n\t\t\tbi[j]+=1\n\t\t\tbi << (bi[j]-2)\n\t\tend\n\tend\nend\ncount = 0.0\nfor i in bi\n\tcount+=1 if i == ai\nend\nprintf(\"%.12f\\n\", count.to_f/bi.size);\n\n", "lang_cluster": "Ruby", "tags": ["brute force", "math", "dp", "combinatorics", "bitmasks", "probabilities"], "code_uid": "728ac8647c950127618238dbad67bb19", "src_uid": "f7f68a15cfd33f641132fac265bc5299", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def factorial(n)\n if n == 0 then\n return 1\n else\n return n * factorial(n - 1)\n end\nend\n\ninput = gets.strip\noutput = gets.strip\ninput_pluses = input.count(\"+\") || 0\ninput_minuses = input.count(\"-\") || 0\noutput_pluses = output.count(\"+\") || 0\noutput_minuses = output.count(\"-\") || 0\noutput_questions = output.count(\"?\") || 0\nif output_pluses > 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", "lang_cluster": "Ruby", "tags": ["brute force", "math", "dp", "combinatorics", "bitmasks", "probabilities"], "code_uid": "f3cc7943abc2417a075fddede8a6bd2c", "src_uid": "f7f68a15cfd33f641132fac265bc5299", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\ns1 = gets.chomp\ns2 = gets.chomp\ns1_lastpos = s1.count('+') - s1.count('-')\ns2_detlastpos = s2.count('+') - s2.count('-')\ns2_undetsigns = s2.count('?')\nprob = 0.5\n\nif s2_undetsigns == 0 && s1_lastpos == s2_detlastpos\n puts \"1.0\"\nelse\n total_cases = (2**s2_undetsigns)*1.0\n possible_cases = 0\n for mask in 0...(2**s2_undetsigns)\n s2_additional = 0\n for i in 0...s2_undetsigns\n if mask[i] == 0\n s2_additional -= 1\n else\n s2_additional += 1\n end\n end\n \n if (s2_detlastpos + s2_additional) == s1_lastpos\n possible_cases += 1\n end\n end\n \n puts possible_cases/total_cases\nend\n", "lang_cluster": "Ruby", "tags": ["brute force", "math", "dp", "combinatorics", "bitmasks", "probabilities"], "code_uid": "5a34fd01373ae7d4d6d39abcfaaa1284", "src_uid": "f7f68a15cfd33f641132fac265bc5299", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "h={}\nh[0]=1.0\ns=gets.chomp\np1=0\ns.chars{|e|\n\tif e==\"+\" then\n\t\tp1+=1\n\telse\n\t\tp1-=1\n\tend\n}\ns=gets.chomp\ns.chars{|e|\n\th1=Hash.new(0.0)\n\tcase e\n\twhen \"+\"\n\t\th.each{|k,v|\n\t\t\th1[k+1]=v\t\n\t\t}\n\twhen \"-\"\n\t\th.each{|k,v|\n\t\t\th1[k-1]=v\n\t\t}\n\twhen \"?\"\n\t\th.each{|k,v|\n\t\t\t\th1[k-1]+=v*0.5\n\t\t\t\th1[k+1]+=v*0.5\n\t\t}\n\tend\n\th=h1\n\n}\nif h.key?(p1) then\n\tputs h[p1]\nelse\n\tputs 0\nend\n\n\n", "lang_cluster": "Ruby", "tags": ["brute force", "math", "dp", "combinatorics", "bitmasks", "probabilities"], "code_uid": "aaadde71b9c09c7901b5e545906f8bf1", "src_uid": "f7f68a15cfd33f641132fac265bc5299", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s1 = gets.chomp\ns2 = gets.chomp\n\nn = (s1.count('+') - s1.count('-') - (s2.count('+') - s2.count('-'))).abs\nm = s2.count('?')\n\nif (n - m).odd? or n > m\n\tputs 0\nelse\n\tn = (m - n) / 2\n\tans = Math.gamma(m + 1) / Math.gamma(n + 1) / Math.gamma(m - n + 1) / (2 ** m)\n\tputs '%.12f' % ans\nend", "lang_cluster": "Ruby", "tags": ["brute force", "math", "dp", "combinatorics", "bitmasks", "probabilities"], "code_uid": "13ba96e46e4cb3b3f0d7a2ed2a1122a6", "src_uid": "f7f68a15cfd33f641132fac265bc5299", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/ruby\na=Array(1024)\n1024.times{|i| a[i]=i.to_s(2).to_i}\nn=gets.chomp.to_i\n1024.times{|i| if a[i+1]>n then puts i;exit end}\n", "lang_cluster": "Ruby", "tags": ["brute force", "math", "implementation"], "code_uid": "e9df7584304d1fb0f59432b51115c8e2", "src_uid": "64a842f9a41f85a83b7d65bfbe21b6cb", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\nm = 0\nloop do\n\tbreak if ('%b' % m).to_i > n\n\tm += 1\nend\np m - 1\n\n", "lang_cluster": "Ruby", "tags": ["brute force", "math", "implementation"], "code_uid": "fb54e0961078afad9f039101b37a74c2", "src_uid": "64a842f9a41f85a83b7d65bfbe21b6cb", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = gets.strip\n\none = false\n\n0.upto(s.length-1) do |i|\n if (s[i] > ?1) or (one)\n s[i] = ?1\n one = true\n end\nend\n\nn = s.to_i(2)\nputs n", "lang_cluster": "Ruby", "tags": ["brute force", "math", "implementation"], "code_uid": "48003d51b5e375433ac32cc624db8bb6", "src_uid": "64a842f9a41f85a83b7d65bfbe21b6cb", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a = gets.chars.map(&:to_i)\nlo, hi = a.slice(0, 3), a.slice(3, 3)\ndiff = hi.reduce(&:+) - lo.reduce(&:+)\nlo, hi, diff = hi, lo, -diff if diff < 0\n(lo.map {|x| 9 - x} + hi).sort!.reverse!.each_with_index do |x, i|\n if diff < 1\n p i\n break\n end\n diff -= x\nend\n\n", "lang_cluster": "Ruby", "tags": ["brute force", "greedy", "implementation"], "code_uid": "c13b4e9f516302e38d4db59020eed59f", "src_uid": "09601fd1742ffdc9f822950f1d3e8494", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["brute force", "greedy", "implementation"], "code_uid": "ff1b333933eed1aeea48f082f509c8a9", "src_uid": "09601fd1742ffdc9f822950f1d3e8494", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "d = [1,2,3,4]\na_p_ = Array.new(5, false)\na_from = Array.new(5, false)\na_to = Array.new(5, false)\n\n4.times do |i|\n l, s, r, p_ = gets.chomp.split(\" \").map(&:to_i)\n if l == 1\n a_from[i+1] = true\n l_to = d[i - 1]\n a_to[l_to] = true\n end \n if s == 1\n a_from[i+1] = true\n s_to = d[i - 2]\n a_to[s_to] = true\n end\n if r == 1\n a_from[i+1] = true\n r_to = d[i - 3]\n a_to[r_to] = true \n end\n if p_ == 1 \n a_p_[i+1] = true\n end\nend\n5.times do |i|\n if a_p_[i]\n if a_from[i] || a_to[i]\n puts \"YES\"\n exit\n end\n end\nend\nputs \"NO\"", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "299562a5be94690d781224d411a24101", "src_uid": "44fdf71d56bef949ec83f00d17c29127", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "c5f5aaea6c934acf45457f9c4313de19", "src_uid": "44fdf71d56bef949ec83f00d17c29127", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,l=gets.split.map &:to_i\na=gets.split.map.with_index{|e,i|[e.to_i,2**i]}.sort_by{|c,v|c.to_r/v}\nm={}\nf=->x,i{\n return 0 if !a[i]\n c,v=a[i]\n k=x/v\n m[[x,i]]||=[f[x-k*v, i+1]+k*c, (k+1)*c].min\n}\np f[l, 0]\n", "lang_cluster": "Ruby", "tags": ["greedy", "dp", "bitmasks"], "code_uid": "e8ed42ef98d44dfa9eb52356a54d9286", "src_uid": "04ca137d0383c03944e3ce1c502c635b", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/ruby\ninclude Math\n\nINF = 0x3f3f3f3f3f3f3f3f3f3f3f3f3f3f3f3f\n\nn, v = gets.split().map(&:to_i)\ncost = gets.split().map(&:to_i)\n\nbest = []\nbest[0] = INF\nres = INF\nfor i in 1..n\n\tbest[i] = [2*best[i-1], cost[i-1]].min\n\tif 2**(i-1) >= v\n\t\tres = [res, best[i]].min\n\tend\nend\nfor i in n+1..70\n\tbest[i] = 2*best[i-1]\n\tif 2**(i-1) >= v\n\t\tres = [res, best[i]].min\n\tend\nend\n\nans = INF\nvv = v\nwhile (vv & -vv) != vv\n\ttemp = 0\n\tj = 0\n\tv = vv\n\twhile v > 0\n\t\tj += 1\n\t\tif v % 2 == 1\n\t\t\ttemp += best[j]\n\t\tend\n\t\tv /= 2\n\tend\n\tans = [ans, temp].min\n\tvv += vv & -vv\nend\n\nputs [res, ans].min\n", "lang_cluster": "Ruby", "tags": ["greedy", "dp", "bitmasks"], "code_uid": "af742bd0d9fd5e97a50df19462bdd212", "src_uid": "04ca137d0383c03944e3ce1c502c635b", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "cards = gets.chomp.split(' ').map(&:to_i)\nnumHash = {}\n\nsum = 0\n\ncards.each do |card|\n\tif numHash.has_key? card then numHash[card] += 1\n\telse numHash[card] = 1 \n\tend\n\n\tsum += card\nend\n\nans = sum\n\nnumHash.each do |k, v|\n\tif v > 1\n\t\tv = 3 if v > 3\n\t\tres = sum - k * v\n\t\tans = res if ans > res\n\tend\nend\n\nputs ans", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation"], "code_uid": "eb52ea209bb0109aeaab3b00d59ff3f7", "src_uid": "a9c17ce5fd5f39ffd70917127ce3408a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "cards = gets.strip.split.map(&:to_i)\nsum = cards.inject(:+)\ncount = Array.new(101, 0)\ncards.each do |i|\n count[i] += 1\nend\nsub = 0\ncount.each_index do |i|\n if count[i] > 0\n sub = [sub, [count[i], 3].min * i].max if count[i] >= 2\n end\nend\nputs \"#{sum - sub}\"\n", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation"], "code_uid": "ba3f797feb31e40ea0ac1354b00367d0", "src_uid": "a9c17ce5fd5f39ffd70917127ce3408a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a=gets.chomp.split(\" \").map{|i|i.to_i}\na.sort!\nif a.count(a[4])>=3\nputs \"#{a[0]+a[1]}\"\nelsif a.count(a[4])==2\nif a.count(a[2])>=3\n\tif a[2]*3 > a[4]*2\n\tputs \"#{a[4]*2}\"\n\telse\n\tputs \"#{a[2]*3}\"\n\tend\nelse\n\tputs \"#{a[2]+a[1]+a[0]}\"\nend\n\nelsif a.count(a[3])==2\n\tputs \"#{a[4]+a[1]+a[0]}\"\nelsif a.count(a[3])>=3\n\tputs \"#{a[4]+a[0]}\"\nelsif a.count(a[2])==2\n puts \"#{a[4]+a[3]+a[0]}\"\nelsif a.count(a[2])==3\n\tputs \"#{a[4]+a[3]}\"\nelsif a.count(a[1])==2\n\tputs \"#{a[4]+a[3]+a[2]}\"\nelse\n\tputs \"#{a[4]+a[3]+a[2]+a[1]+a[0]}\"\nend", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation"], "code_uid": "4b869e07668b333deb8362bded47dc9c", "src_uid": "a9c17ce5fd5f39ffd70917127ce3408a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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}", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "f655fe2408a572843f2e9519fd864a3e", "src_uid": "80520be9916045aca3a7de7bc925af1f", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,m,*a=$<.read.split.map &:to_i\np m/a.select{|e|m%e<1}.max", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "0d6acb38e66e920269ae4f95cd432355", "src_uid": "80520be9916045aca3a7de7bc925af1f", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,k = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\na.sort!\nans = 0\nwhile (t = a.pop) && ans == 0\n ans = k/t if k % t == 0\nend\nputs ans\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "0e0bffb83859b1dda3744386bea6d622", "src_uid": "80520be9916045aca3a7de7bc925af1f", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "634cb0aedd42b881aaf450a2863c5c36", "src_uid": "20aa53bffdfd47b4e853091ee6b11a4b", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def solve(n, cubes)\n (1..1000).to_a.each do |x|\n digits = x.to_s.split('').map(&:to_i)\n if digits.size > cubes.size\n return x - 1\n end\n\n if digits.size == 1\n res = cubes.map { |c| c.include?(digits.first) }.reject { |z| !z }\n if res.empty?\n return x - 1\n end\n elsif digits.size == 2\n found = false\n for i in 0...(cubes.size)\n break if found\n for j in 0...(cubes.size)\n next if i == j\n if cubes[i].include?(digits.first) && cubes[j].include?(digits.last)\n found = true\n break\n end\n end\n end\n unless found\n return x - 1\n end\n elsif digits.size == 3\n found = false\n for i in 0...(cubes.size)\n break if found\n for j in 0...(cubes.size)\n break if found\n for k in 0...(cubes.size)\n next if [i,j,k].uniq.size != 3\n if cubes[i].include?(digits[0]) && cubes[j].include?(digits[1]) && cubes[k].include?(digits[2])\n found = true\n break\n end\n end\n end\n end\n unless found\n return x - 1\n end\n end\n end\nend\n\nn = gets.strip.to_i\ncubes = []\nn.times do\n cubes << gets.strip.split.map(&:to_i).sort\nend\n\nputs solve(n, cubes)\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "415311f4c7874158963a50c3ee9a7e7b", "src_uid": "20aa53bffdfd47b4e853091ee6b11a4b", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def solve(n, cubes)\n (1..1000).to_a.each do |x|\n digits = x.to_s.split('').map(&:to_i)\n\n permutations = (0...n).to_a.permutation.to_a\n res = permutations.map do |p|\n p.zip(digits).reject { |pd| pd.first.nil? || pd.last.nil? }.map do |pd|\n cubes[pd.first].include?(pd.last)\n end.select { |x| x }.size == digits.size\n end\n return x - 1 if res.select { |x| x }.empty?\n end\nend\n\ncubes = (1..gets.strip.to_i).map do\n gets.strip.split.map(&:to_i).sort\nend\n\nputs solve(cubes.size, cubes)\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "1020665b91cc3872a38054afa6d9da67", "src_uid": "20aa53bffdfd47b4e853091ee6b11a4b", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["brute force", "math", "implementation"], "code_uid": "89e75d21948b459b3c6801e7ccd4ae59", "src_uid": "073023c6b72ce923df2afd6130719cfc", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["brute force", "math", "implementation"], "code_uid": "f5dd99bc30721eba9a20d152f82f6222", "src_uid": "073023c6b72ce923df2afd6130719cfc", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def test\n\tinput = $stdin.read\n\tinput = input.split(\"\\n\")\n\tchars = ['a','b','c','d','e','f','g','h']\n\tplace1 = [chars.find_index(input[0][0]) ,input[0][1].to_i-1]\n\tplace2 = [chars.find_index(input[1][0]),input[1][1].to_i-1]\n \n\twrong_p = []\n\twrong_p.push(place1)\n\twrong_p.push(place2)\n\t\t\n \n\tfor i in 0...8\n\t if !wrong_p.include?([place1[0],i]) && i >=0\n\t wrong_p.push([place1[0],i])\n\t end\n\t if !wrong_p.include?([i,place1[1]]) && i >=0\n\t wrong_p.push([i,place1[1]])\n\t end\n\tend\n\t\n\tif !wrong_p.include?([place2[0]+2, place2[1]+1]) \n\t wrong_p.push([place2[0]+2, place2[1]+1])\n\tend\n\tif !wrong_p.include?([place2[0]+2, place2[1]-1]) \n\twrong_p.push([place2[0]+2, place2[1]-1])\n\tend\n\tif !wrong_p.include?([place2[0]-2, place2[1]+1]) \n\twrong_p.push([place2[0]-2, place2[1]+1])\n\tend\n\tif !wrong_p.include?([place2[0]-2, place2[1]-1]) \n\twrong_p.push([place2[0]-2, place2[1]-1])\n\tend\n\tif !wrong_p.include?([place2[0]+1, place2[1]+2])\n\twrong_p.push([place2[0]+1, place2[1]+2])\n\tend\n\tif !wrong_p.include?([place2[0]+1, place2[1]-2]) \n\twrong_p.push([place2[0]+1, place2[1]-2])\n\tend\n\tif !wrong_p.include?([place2[0]-1, place2[1]+2]) \n\twrong_p.push([place2[0]-1, place2[1]+2])\n\tend\n\tif !wrong_p.include?([place2[0]-1, place2[1]-2]) \n\twrong_p.push([place2[0]-1, place2[1]-2])\n\tend\n \n \n \n \n if !wrong_p.include?([place1[0]+1, place1[1]+2]) \n\t wrong_p.push([place1[0]+1, place1[1]+2])\n\tend\n\tif !wrong_p.include?([place1[0]+1, place1[1]-2]) \n\t wrong_p.push([place1[0]+1, place1[1]-2])\n\tend\n\tif !wrong_p.include?([place1[0]-1, place1[1]+2])\n\t wrong_p.push([place1[0]-1, place1[1]+2])\n\tend\n if !wrong_p.include?([place1[0]-1, place1[1]-2])\n\t wrong_p.push([place1[0]-1, place1[1]-2])\n\tend\t\n if !wrong_p.include?([place1[0]+2, place1[1]+1]) \n\t wrong_p.push([place1[0]+2, place1[1]+1])\n\tend\n\tif !wrong_p.include?([place1[0]+2, place1[1]-1]) \n\t wrong_p.push([place1[0]+2, place1[1]-1])\n\tend\n\tif !wrong_p.include?([place1[0]-2, place1[1]+1])\n\t wrong_p.push([place1[0]-2, place1[1]+1])\n\tend\n if !wrong_p.include?([place1[0]-2, place1[1]-1]) \n\t wrong_p.push([place1[0]-2, place1[1]-1])\n\tend\t\n\t\n\t\n\t\n\t\n \n \n\tcount = 0\n for i in 0...8\n for j in 0...8\n if !wrong_p.include?([i,j])\n count = count+1\n end\n end\n end\n puts count\nend \ntest", "lang_cluster": "Ruby", "tags": ["brute force", "math", "implementation"], "code_uid": "139931d0653b2d44939af960e30e12c8", "src_uid": "073023c6b72ce923df2afd6130719cfc", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "x,y,z,t1,t2,t3 = gets.split.map { |e| Integer(e) }\nstair = t1 * (x - y).abs\nelevator = t2 * (z - x).abs + t3*2 + t2*(x-y).abs + t3\nputs (if elevator <= stair then \"YES\" else \"NO\" end)", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "7a9ff3782aebeadb3f5942cc6c52fde3", "src_uid": "05cffd59b28b9e026ca3203718b2e6ca", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "class A\n def self.run(s)\n x, y, z, t1, t2, t3 = s.split.map(&:to_i)\n walk = (x-y).abs * t1\n lift = (x-z).abs * t2 + t3*2 + (x-y).abs * t2 + t3\n if lift <= walk\n true\n else\n false\n end\n end\nend\n\n\nif A.run(gets.chomp)\n puts 'YES'\nelse\n puts 'NO'\nend\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "61f7e1836b495f2fb9941d1a99b55a09", "src_uid": "05cffd59b28b9e026ca3203718b2e6ca", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "\ndef solution\n x, y, z, stairs, elv, elv_doors = read_ints\n\n elv_time = ((z-x).abs + (x-y).abs) * elv + elv_doors * 3\n stair_time = (y-x).abs * stairs\n\n puts elv_time <= stair_time ? \"YES\" : \"NO\"\n\nend\n\ndef read_int\n gets.to_i\nend\n\ndef read_ints\n gets.split.map(&:to_i)\nend\n\ndef read_string\n gets.chomp\nend\n\nsolution unless ENV['TEST__MODE']\n\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "3aa5297223a07aa68df127b779a4c92d", "src_uid": "05cffd59b28b9e026ca3203718b2e6ca", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "# Codeforces Beta Round #80\n# Problem A -- Blackjack\ncards = [0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 15, 4]\nn = gets.to_i - 10\nputs (0 <= n and n <= 11) ? cards[n] : 0\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "11bfe8c63ccfdd953e291a04744c85ab", "src_uid": "5802f52caff6015f21b80872274ab16c", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#104A\nn=gets.to_i\nif n <= 10\n puts \"0\"\nelsif n >= 11 and n <= 19\n puts \"4\"\nelsif n == 20\n puts \"15\"\nelsif n == 21\n puts\"4\"\nelse\n puts \"0\"\nend \n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "243bcb1a96ffd719ccbbeaaa8e607534", "src_uid": "5802f52caff6015f21b80872274ab16c", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "\ndef blackjack\n c = { }\n 1.upto(11) { |i| c[i] = 4 }\n c[10] = 15\n\n goal = gets.to_i\n if goal-10 < 1\n puts 0\n else\n puts (c.has_key?(goal-10)) ? c[goal-10] : 0\n end\nend\n\nblackjack", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "777132560c2d2a6ad98a4b27df0ce49b", "src_uid": "5802f52caff6015f21b80872274ab16c", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\n\nans = 0\n\nabc = []\ngets.chomp.each_char do |c|\n\tif 'a' <= c && c <= 'z'\n\t\tabc[c.ord - 'a'.ord] = 1\n\telse\n\t\tans = [ans, abc.count(1)].max\n\t\tabc = []\n\tend\nend\n\np [ans, abc.count(1)].max", "lang_cluster": "Ruby", "tags": ["brute force", "strings", "implementation"], "code_uid": "34f3e8f0a2d2dd9832f9c33c3f9f1380", "src_uid": "567ce65f87d2fb922b0f7e0957fbada3", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "gets\np gets.chomp.split(/[A-Z]+/).map{|s|s.split(//).uniq.length}.max||0", "lang_cluster": "Ruby", "tags": ["brute force", "strings", "implementation"], "code_uid": "25989b8e923089910f362f2df899932d", "src_uid": "567ce65f87d2fb922b0f7e0957fbada3", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def is_up_case?( chr )\n chr >= 'A' && chr <= 'Z'\nend\nn = gets.strip.to_i\ns = gets.strip\ni = ans = 0\nprev = '0'\nwhile i < n\n curr = s[i]\n dist = {}\n while !is_up_case? curr\n curr = s[i]\n break if curr.nil? || is_up_case?( curr )\n dist[curr] = 1 if dist[curr].nil?\n prev = curr\n i += 1\n end\n ans = [ans, dist.length].max\n i += 1\nend\nputs ans\n", "lang_cluster": "Ruby", "tags": ["brute force", "strings", "implementation"], "code_uid": "d4c7267abeedb4431678c8b5171f7910", "src_uid": "567ce65f87d2fb922b0f7e0957fbada3", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets\nx = {\"0\" => 2, \"1\" => 7, \"2\" => 2, \"3\" => 3, \"4\" => 3, \"5\" => 4, \"6\" => 2, \"7\" => 5, \"8\" => 1, \"9\" => 2 }\nputs x[n[0]] * x[n[1]]", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "2e046efb6c89bc357223985572939603", "src_uid": "76c8bfa6789db8364a8ece0574cd31f5", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.chomp\nn1 = Integer(n[0])\nn2 = Integer(n[1])\n\nnumber = [[1, 2, 3, 5, 6, 7],[3, 6],[2, 3, 4, 5, 7],[2, 3, 4, 6, 7],[1, 3, 4, 6],[1, 2, 4, 6, 7],[1, 2, 4, 5, 6, 7],[2, 3, 6],[1, 2, 3, 4, 5, 6, 7],[1, 2, 3, 4, 6, 7]]\nn1_count = 0\nn2_count = 0\nx1 = number[n1]\nx2 = number[n2]\nfor i in 0...10\n if (x1 - number[i]).empty?\n n1_count += 1\n end\n if (x2 - number[i]).empty?\n n2_count += 1\n end\nend\n\nputs n1_count * n2_count", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "2c253addfaab32c5f79e8e4035304dc5", "src_uid": "76c8bfa6789db8364a8ece0574cd31f5", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.chomp.split(\"\")\nhash = {\n 0 => 2,\n 1 => 7,\n 2 => 2,\n 3 => 3,\n 4 => 3,\n 5 => 4,\n 6 => 2,\n 7 => 5,\n 8 => 1,\n 9 => 2\n}\ncount = 1\nn.each do |i|\n count *= hash[i.to_i]\nend\nputs count\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "56811d33e4d37b00b1467d296aec8d93", "src_uid": "76c8bfa6789db8364a8ece0574cd31f5", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "row = gets.chomp\n\ndef possible(row)\n return 'No' if row.size < 3\n\n 1.upto(row.size - 2) do |i|\n next if row[i] == '.' || row[i - 1] == '.' || row[i + 1] == '.'\n\n if [row[i - 1], row[i], row[i + 1]].uniq.count == 3\n return 'Yes'\n end\n end\n\n 'No'\nend\n\n\nputs possible(row)", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "f3b0d038d9cf3a8bbef173917191c992", "src_uid": "ba6ff507384570152118e2ab322dd11f", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "puts gets.codepoints.each_cons(3).any?{|x,y,z|x*y*z==287430}?'Yes':'No'", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "a8220be9cc9945b151dcc36395c82233", "src_uid": "ba6ff507384570152118e2ab322dd11f", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = gets().chop()\nif s.include?(\"ABC\") || s.include?(\"ACB\") || s.include?(\"BAC\") ||\n\ts.include?(\"BCA\") || s.include?(\"CAB\") || s.include?(\"CBA\")\n\tputs \"Yes\"\nelse\n\tputs \"No\"\nend\n", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "c903c04da27804aba295e5bfee2b2c47", "src_uid": "ba6ff507384570152118e2ab322dd11f", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "L, R, X, Y = gets.split.map(&:to_i)\nif Y % X != 0\n puts 0\n exit\nend\n\ndiv = Y/X\nsq = Math.sqrt(div).ceil\nans = 0\n(1..sq).each do |i|\n next if div%i != 0\n j = div/i\n next if i > j\n next if i.gcd(j) != 1\n if (i*X).between?(L, R) && (j*X).between?(L, R)\n ans += i==j ? 1 : 2\n end\nend\nputs ans", "lang_cluster": "Ruby", "tags": ["math", "number theory"], "code_uid": "f93159e682a0667aecce319ae974dd81", "src_uid": "d37dde5841116352c9b37538631d0b15", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "require 'prime'\n\nl, r, x, y = gets.strip.split.map(&:to_i)\n\nx_factors = Prime.prime_division(x)\ny_factors = Prime.prime_division(y)\nall_factors = {}\nx_factors.each do |fp|\n all_factors[fp[0]] = [fp[1]]\nend\ny_factors.each do |fp|\n if all_factors[fp[0]]\n all_factors[fp[0]] << fp[1]\n else\n all_factors[fp[0]] = [0, fp[1]]\n end\nend\n\nif all_factors.values.map(&:size).uniq != [2]\n puts 0\n exit\nend\n\nall_factors_ary = all_factors.keys.sort\nbl = all_factors_ary.size\nn = 1< 0\n b *= (f ** all_factors[f][1])\n a *= (f ** all_factors[f][0])\n else\n a *= (f ** all_factors[f][1])\n b *= (f ** all_factors[f][0])\n end\n end\n # puts \"(#{a},#{b})\"\n if l<=a && a<=r && l<=b && b<=r\n pairs << [a,b]\n end\nend\nputs pairs.uniq.size\n\n", "lang_cluster": "Ruby", "tags": ["math", "number theory"], "code_uid": "50d7d0e1cbc18940d518e8f817143827", "src_uid": "d37dde5841116352c9b37538631d0b15", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["greedy"], "code_uid": "2e2fcad68a5ad1dcc04833121fac999e", "src_uid": "af07223819aeb5bd6ded4340c472b2b6", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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}\"", "lang_cluster": "Ruby", "tags": ["math", "greedy", "implementation"], "code_uid": "8ae1eb85638e079ede7b91f87121628d", "src_uid": "2be8e0b8ad4d3de2930576c0209e8b91", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a1 = gets.to_i\na2 = gets.to_i\nk1 = gets.to_i\nk2 = gets.to_i\nn = gets.to_i\nmn = [0,n-(k1-1)*a1-(k2-1)*a2].max\nif k1 > k2\n k1,k2 = k2,k1\n a1,a2 = a2,a1\nend\nmx = [a1,n/k1].min\nn -= mx*k1\nmx += n/k2\nputs \"#{mn} #{mx}\"", "lang_cluster": "Ruby", "tags": ["math", "greedy", "implementation"], "code_uid": "10e90372a358aec076bd6dc515ec46f4", "src_uid": "2be8e0b8ad4d3de2930576c0209e8b91", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a1 = gets.to_i\na2 = gets.to_i\nk1 = gets.to_i\nk2 = gets.to_i\nn = gets.to_i\n\nn1 = n2 = n\n\nmaxi = 0\n\nif (k1 < k2)\n out = [a1, n1 / k1].min\n n1 -= out * k1\n maxi += out\n\n out = [a2, n1 / k2].min\n maxi += out\nelse\n out = [a2, n1 / k2].min\n n1 -= out * k2\n maxi += out\n\n out = [a1, n1 / k1].min\n maxi += out\nend\n\nmini = 0\n\navail = a1 * (k1 - 1) + a2 * (k2 - 1)\nn2 -= avail\nif (n2 > 0)\n mini += n2\nend\n\nprint(\"#{mini} #{maxi}\")\n", "lang_cluster": "Ruby", "tags": ["math", "greedy", "implementation"], "code_uid": "8e44d6c79fba7f5333adf667c569d44e", "src_uid": "2be8e0b8ad4d3de2930576c0209e8b91", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,m,a,b=gets.split.map(&:to_i)\nmax=[(b-1)/m-(a-1)/m+1,3].min\nb=(b/m)*m if n==b\nupper_r=(m+1-a%m)%m\nlower_r=b%m\nputs(\n\tif upper_r==0&&lower_r==0\n\t\t1\n\telsif upper_r==0||lower_r==0||(upper_r+lower_r==m)\n\t\t[2,max].min\n\telse\n\t\tmax\n\tend\n)", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "6c850797cc0880ec1e165864d4d2b8ab", "src_uid": "f256235c0b2815aae85a6f9435c69dac", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "N, M = gets.split.map(&:to_i)\nas = gets.split.map(&:to_i)\n\nhash = Hash.new(0)\nas.each do |a|\n hash[a] += 1\nend\n\nputs (1..101).bsearch{|days|\n people = 0\n hash.values.each do |num|\n people += num/days\n end\n people < N\n} - 1", "lang_cluster": "Ruby", "tags": ["brute force", "implementation", "binary search"], "code_uid": "a8847b295edbfd138b5f06a3c8c3d689", "src_uid": "b7ef696a11ff96f2e9c31becc2ff50fe", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["brute force", "implementation", "binary search"], "code_uid": "5b1d2b1af15f6a708c669e632181554a", "src_uid": "b7ef696a11ff96f2e9c31becc2ff50fe", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "nk = gets.chomp.split(\" \").map(&:to_i)\nn = nk[0]\nk = nk[1]\nh = Hash.new(0)\nfood = gets.chomp.split(\" \").map(&:to_i)\n\nfood.each do |pa|\n h[pa]+=1\nend\n\nif k= n\n day+=1\n break\n end\n end\n\n if peoplecount < n\n puts day-1\n exit\n end\nend\n ", "lang_cluster": "Ruby", "tags": ["brute force", "implementation", "binary search"], "code_uid": "a1d1c7a119f3fbadba7afd4688d35c1e", "src_uid": "b7ef696a11ff96f2e9c31becc2ff50fe", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby 3", "source_code": "n = gets.to_i\r\nn = n.digits.sum while n>=10\r\np n", "lang_cluster": "Ruby", "tags": ["implementation", "number theory"], "code_uid": "82289e190045734a24cec851e2c43f70", "src_uid": "477a67877367dc68b3bf5143120ff45d", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby 3", "source_code": "f = ->n {\r\n n < 10 ? n : f[n.to_s.chars.map(&:to_i).sum]\r\n}\r\n\r\np f[gets.to_i]", "lang_cluster": "Ruby", "tags": ["implementation", "number theory"], "code_uid": "316e17c83946a36adc3ec99a0f3b135e", "src_uid": "477a67877367dc68b3bf5143120ff45d", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "c3b79bfeaf7f3a2c4e716b667c8da389", "src_uid": "00cffd273df24d1676acbbfd9a39630d", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b,c,d=gets.split.map &:to_i;p (c-a+1)*(d-b+1)/2+1", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "f62b32451901f035c0b8595437e18ab1", "src_uid": "00cffd273df24d1676acbbfd9a39630d", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b,c,d=gets.split.map &:to_i;p (c-a+1)*(d-b+1)/2+1", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "8aa182a019e37b387661927a21dda781", "src_uid": "00cffd273df24d1676acbbfd9a39630d", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "\nn = gets.strip.to_i\ns = gets.strip\n\ndef move(s)\n\tt1 =\t(s[0].ord - \"A\".ord).abs\n\tt1 = 26-t1 if t1 > 12\n\tt2 =\t(s[1].ord - \"C\".ord).abs\n\tt2 = 26-t2 if t2 > 12\n\tt3 =\t(s[2].ord - \"T\".ord).abs\n\tt3 = 26-t3 if t3 > 12\n\tt4 =\t(s[3].ord - \"G\".ord).abs\n\tt4 = 26-t4 if t4 > 12\n t1+t2+t3+t4\nend\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", "lang_cluster": "Ruby", "tags": ["brute force", "strings"], "code_uid": "608a8d6d478a5baf36788dcec43f3ab4", "src_uid": "ee4f88abe4c9fa776abd15c5f3a94543", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["brute force", "strings"], "code_uid": "640f7b7d7e41b8f9003400a35bb7a60e", "src_uid": "ee4f88abe4c9fa776abd15c5f3a94543", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\ns = gets.chomp\narr = []\nres = 9999999\n\ns.each_char do |i|\n al = [9999999]*26\n\n j = (i.ord-1).chr\n if j < 'A' then j = 'Z' end\n cnt = 1\n al[j.ord-65] = cnt\n\n while j != i\n j = (j.ord-1).chr\n cnt += 1\n\n if j < 'A'\n j = 'Z'\n end\n\n al[j.ord-65] = [al[j.ord-65], cnt].min\n end\n\n j = (i.ord+1).chr\n if j > 'Z' then j = 'A' end\n cnt = 1\n al[j.ord-65] = cnt\n\n while j != i\n j = (j.ord+1).chr\n cnt += 1\n\n if j > 'Z'\n j = 'A'\n end\n\n al[j.ord-65] = [al[j.ord-65], cnt].min\n end\n\n al[i.ord-65] = 0\n\n arr.push(al)\nend\n\n(n-3).times do |i|\n res = [res, arr[i][0]+arr[i+1][2]+arr[i+2][19]+arr[i+3][6]].min\nend\n\np res\n", "lang_cluster": "Ruby", "tags": ["brute force", "strings"], "code_uid": "9d88b049ddf43fec5b5cea03e8987ac5", "src_uid": "ee4f88abe4c9fa776abd15c5f3a94543", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "groups = gets.to_i\nyears = gets.split.map(&:to_i)\nyears.sort!\nyear = years[groups/2]\nputs year", "lang_cluster": "Ruby", "tags": ["sortings", "implementation"], "code_uid": "6cd2a67dd12344559b418b051018e409", "src_uid": "f03773118cca29ff8d5b4281d39e7c63", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "group_count = gets.to_i\ngroups = gets.split.sort\nputs groups[group_count/2]", "lang_cluster": "Ruby", "tags": ["sortings", "implementation"], "code_uid": "4319c637580bb4e57007acb05f0baa62", "src_uid": "f03773118cca29ff8d5b4281d39e7c63", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "N, K, M, D = gets.split.map(&:to_i)\nans = 0\n(1..D).each do |m|\n x = [M, N/((m-1)*K+1)].min\n ans = [ans, x*m].max\nend\nputs ans", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "f35ce88441b2548eebafc8aa435b4391", "src_uid": "ac2e795cd44061db8da13e3947ba791b", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def solve(n, k, m, d)\n ans = -1\n (1..d).each do |a|\n y = k*a - k + 1\n if y <= 2*n && n >= y\n z = [n/y, m].min\n ans = [ans, z*a].max\n end\n end\n p ans\nend\n\nloop do\n line = gets\n if line\n n, k, m, d = line.split.map(&:to_i)\n solve(n, k, m, d)\n else\n break\n end\nend\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "25e494b695a21b07ac340f90c257c42e", "src_uid": "ac2e795cd44061db8da13e3947ba791b", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "require 'set'\n\n$set=Set.new\n$n=gets.to_i\n\ndef dfs num,x,y\n if (1..$n)===num\n $set<= lim\n sum += k * 10\n i += 1\nend\n\nputs (i - n)\n\n\n\n\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "4913a9f72ce7aae1d273630697f4a2e1", "src_uid": "f22267bf3fad0bf342ecf4c27ad3a900", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,k,*a=$<.read.split.map &:to_i\np [0,(k*2-1)*n-a.reduce(:+)*2].max", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "9c427ffff6bea0367d4e78b80adc76b4", "src_uid": "f22267bf3fad0bf342ecf4c27ad3a900", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "X, Y, L, R = gets.split.map( &:to_i )\n\nA = Array.new( 64 ) { |i| X ** i }\nB = Array.new( 64 ) { |i| Y ** i }\n\nu = Array.new\nu << L - 1\nu << R + 1\nA.each do |i|\n\tB.each do |j|\n\t\tif L <= i + j && i + j <= R then\n\t\t\tu << i + j\n\t\tend\n\tend\nend\nu.sort!\n\nres = 0\n( u.length - 1 ).times do |i|\n\tres = [ res, u[ i + 1 ] - u[i] - 1 ].max\nend\n\np res\n", "lang_cluster": "Ruby", "tags": ["brute force", "math"], "code_uid": "ea8399754c9971d922183e65aa34e10a", "src_uid": "68ca8a8730db27ac2230f9fe9b120f5f", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "x, y, l, r = gets.chomp.split.map &:to_i\n\nunlucky = []\nfor i in 0...64\n for j in 0...64\n m = x ** i + y ** j\n if m <= r && m >= l\n unlucky.push(m)\n end\n end\nend\n\nunlucky = unlucky.sort!\nunlucky_neat = []\nif !unlucky.empty?\n unlucky_neat.push(unlucky[0])\n for i in 1...unlucky.length\n if unlucky[i] != unlucky[i - 1]\n unlucky_neat.push(unlucky[i])\n end\n end\nend\n\nif !unlucky_neat.empty?\n max = (unlucky_neat[0] - l) > (r - unlucky_neat[unlucky_neat.length - 1]) ? (unlucky_neat[0] - l) : (r - unlucky_neat[unlucky_neat.length - 1])\n for i in 0...unlucky_neat.length - 1\n if unlucky_neat[i + 1] - unlucky_neat[i] - 1 > max\n max = unlucky_neat[i + 1] - unlucky_neat[i] - 1\n end\n end\n puts max\nelse\n max = r - l + 1\n puts max\nend\n\n\n", "lang_cluster": "Ruby", "tags": ["brute force", "math"], "code_uid": "e7f7c1690bc883fb3cafc3483511cbfe", "src_uid": "68ca8a8730db27ac2230f9fe9b120f5f", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["brute force", "math"], "code_uid": "d3c63356568a6b0dcfa6489107c04b88", "src_uid": "68ca8a8730db27ac2230f9fe9b120f5f", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "y, b, r = gets.split.map &:to_i\nans = 6\n(1..y).each do |i|\n if i + 1 <= b && i + 2 <= r\n ans = [ans, i + i + 1 + i + 2].max\n end\nend\np ans\n", "lang_cluster": "Ruby", "tags": ["brute force", "math", "implementation"], "code_uid": "4ab735901fec0b5c9942c41d267aec00", "src_uid": "03ac8efe10de17590e1ae151a7bae1a5", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b,c=gets.split.map &:to_i;p 3*[a+1,b,c-1].min", "lang_cluster": "Ruby", "tags": ["brute force", "math", "implementation"], "code_uid": "8cecabc202af1d10312808b4a7583474", "src_uid": "03ac8efe10de17590e1ae151a7bae1a5", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "(a,b,c) = gets.split.map(&:to_i)\n(x,y,z) = 1,2,3\nwhile x < a and y < b and z < c\n x+=1 ; y+=1 ; z+=1\nend\nputs x+y+z\n", "lang_cluster": "Ruby", "tags": ["brute force", "math", "implementation"], "code_uid": "9b6a7177aed4712849782ab3dff2ebac", "src_uid": "03ac8efe10de17590e1ae151a7bae1a5", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "str = 2.times.map{'X' + gets.chomp + 'X'}\n\nans = 0\nstr[0].length.times do |i|\n next unless str[0][i] == '0' && str[1][i] == '0'\n [[0, i-1], [1, i-1], [0, i+1], [1, i+1]].each do |i2, j2|\n if str[i2][j2] == '0'\n str[0][i] = 'X'\n str[1][i] = 'X'\n str[i2][j2] = 'X'\n ans += 1\n break\n end\n end\nend\nputs ans", "lang_cluster": "Ruby", "tags": ["greedy", "dp"], "code_uid": "cdec435370e50fbf2e5229c5861b077a", "src_uid": "e6b3e787919e96fc893a034eae233fc6", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "@r1 = gets.strip\n@r2 = gets.strip\nn = @r1.size-1\n@cache = {}\n\ndef get_key(*args)\n args.join(\",\")\nend\n\n@cache[get_key(0,0,0)] = 0\n@cache[get_key(0,0,1)] = 0\n@cache[get_key(0,1,0)] = 0\n@cache[get_key(0,1,1)] = 0\n\ndef get_x_count(a, b, c, d)\n ret = 0\n ret += 1 if a == 'X'\n ret += 1 if b == 'X'\n ret += 1 if c == 'X'\n ret += 1 if d == 'X'\n ret\nend\n\ndef solve(i, t, b)\n unless @cache[get_key(i,t,b)]\n ans = solve(i-1, 1, 1)\n if i>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", "lang_cluster": "Ruby", "tags": ["greedy", "dp"], "code_uid": "77a5248be8a88dbf99091ca66769879c", "src_uid": "e6b3e787919e96fc893a034eae233fc6", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "h=Hash.new 0;gets;gets.split.map{|e|h[e]+=1};p h.values.max", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "2116388c7029c92c8b975d85409c79ca", "src_uid": "f30329023e84b4c50b1b118dc98ae73c", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "gets.chomp.to_i\npockets = gets.chomp.split.map(&:to_i)\n\nrepeats = {}\npockets.each do |element|\n if repeats[element]\n repeats[element] += 1\n else\n repeats[element] = 1\n end\nend\n\nputs repeats.values.max\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "3cb5fa7d3754611ad5bd37bc149027fc", "src_uid": "f30329023e84b4c50b1b118dc98ae73c", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = STDIN.readline.strip\nnumbers = STDIN.readline.strip.split(/\\s+/)\n\nputs numbers.group_by {|v| v.to_i }.map {|k,v| v.length }.max\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "71456e1e3f1c9a55ea0db69d7e674c42", "src_uid": "f30329023e84b4c50b1b118dc98ae73c", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.to_i\nk,s=0,0\nfor i in 1...n\n\ts=1\n\tfor j in 1...n\n\t\ts*=i\n\t\ts%=n\n\t\tif (s-1)%n==0\n\t\t\tif j==n-1\n\t\t\t\tk+=1\n\t\t\telse\n\t\t\t\tbreak\n\t\t\tend\n\t\tend\n\tend\nend\nputs k", "lang_cluster": "Ruby", "tags": ["math", "implementation", "number theory"], "code_uid": "b4d0b97ec3756dcfaca2796d415a8e7b", "src_uid": "3bed682b6813f1ddb54410218c233cff", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/ruby1.9\n\nanswers = {2=>1, 3=>1, 5=>2, 7=>2, 11=>4, 13=>4, 17=>8, 19=>6, 23=>10, 29=>12, 31=>8, 37=>12, 41=>16, 43=>12, 47=>22, 53=>24, 59=>28, 61=>16, 67=>20, 71=>24, 73=>24, 79=>24, 83=>40, 89=>40, 97=>32, 101=>40, 103=>32, 107=>52, 109=>36, 113=>48, 127=>36, 131=>48, 137=>64, 139=>44, 149=>72, 151=>40, 157=>48, 163=>54, 167=>82, 173=>84, 179=>88, 181=>48, 191=>72, 193=>64, 197=>84, 199=>60, 211=>48, 223=>72, 227=>112, 229=>72, 233=>112, 239=>96, 241=>64, 251=>100, 257=>128, 263=>130, 269=>132, 271=>72, 277=>88, 281=>96, 283=>92, 293=>144, 307=>96, 311=>120, 313=>96, 317=>156, 331=>80, 337=>96, 347=>172, 349=>112, 353=>160, 359=>178, 367=>120, 373=>120, 379=>108, 383=>190, 389=>192, 397=>120, 401=>160, 409=>128, 419=>180, 421=>96, 431=>168, 433=>144, 439=>144, 443=>192, 449=>192, 457=>144, 461=>176, 463=>120, 467=>232, 479=>238, 487=>162, 491=>168, 499=>164, 503=>250, 509=>252, 521=>192, 523=>168, 541=>144, 547=>144, 557=>276, 563=>280, 569=>280, 571=>144, 577=>192, 587=>292, 593=>288, 599=>264, 601=>160, 607=>200, 613=>192, 617=>240, 619=>204, 631=>144, 641=>256, 643=>212, 647=>288, 653=>324, 659=>276, 661=>160, 673=>192, 677=>312, 683=>300, 691=>176, 701=>240, 709=>232, 719=>358, 727=>220, 733=>240, 739=>240, 743=>312, 751=>200, 757=>216, 761=>288, 769=>256, 773=>384, 787=>260, 797=>396, 809=>400, 811=>216, 821=>320, 823=>272, 827=>348, 829=>264, 839=>418, 853=>280, 857=>424, 859=>240, 863=>430, 877=>288, 881=>320, 883=>252, 887=>442, 907=>300, 911=>288, 919=>288, 929=>448, 937=>288, 941=>368, 947=>420, 953=>384, 967=>264, 971=>384, 977=>480, 983=>490, 991=>240, 997=>328, 1009=>288, 1013=>440, 1019=>508, 1021=>256, 1031=>408, 1033=>336, 1039=>344, 1049=>520, 1051=>240, 1061=>416, 1063=>348, 1069=>352, 1087=>360, 1091=>432, 1093=>288, 1097=>544, 1103=>504, 1109=>552, 1117=>360, 1123=>320, 1129=>368, 1151=>440, 1153=>384, 1163=>492, 1171=>288, 1181=>464, 1187=>592, 1193=>592, 1201=>320, 1213=>400, 1217=>576, 1223=>552, 1229=>612, 1231=>320, 1237=>408, 1249=>384, 1259=>576, 1277=>560, 1279=>420, 1283=>640, 1289=>528, 1291=>336, 1297=>432, 1301=>480, 1303=>360, 1307=>652, 1319=>658, 1321=>320, 1327=>384, 1361=>512, 1367=>682, 1373=>588, 1381=>352, 1399=>464, 1409=>640, 1423=>468, 1427=>660, 1429=>384, 1433=>712, 1439=>718, 1447=>480, 1451=>560, 1453=>440, 1459=>486, 1471=>336, 1481=>576, 1483=>432, 1487=>742, 1489=>480, 1493=>744, 1499=>636, 1511=>600, 1523=>760, 1531=>384, 1543=>512, 1549=>504, 1553=>768, 1559=>720, 1567=>504, 1571=>624, 1579=>524, 1583=>672, 1597=>432, 1601=>640, 1607=>720, 1609=>528, 1613=>720, 1619=>808, 1621=>432, 1627=>540, 1637=>816, 1657=>528, 1663=>552, 1667=>672, 1669=>552, 1693=>552, 1697=>832, 1699=>564, 1709=>720, 1721=>672, 1723=>480, 1733=>864, 1741=>448, 1747=>576, 1753=>576, 1759=>584, 1777=>576, 1783=>540, 1787=>828, 1789=>592, 1801=>480, 1811=>720, 1823=>910, 1831=>480, 1847=>840, 1861=>480, 1867=>620, 1871=>640, 1873=>576, 1877=>792, 1879=>624, 1889=>928, 1901=>720, 1907=>952, 1913=>952, 1931=>768, 1933=>528, 1949=>972, 1951=>480, 1973=>896, 1979=>924, 1987=>660, 1993=>656, 1997=>996, 1999=>648}\n\nx = STDIN.readline.to_i\nputs answers[x]\n\n", "lang_cluster": "Ruby", "tags": ["math", "implementation", "number theory"], "code_uid": "3b5312a59351e326d0344fa1cb4fdc41", "src_uid": "3bed682b6813f1ddb54410218c233cff", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def is_root x,p\n\tn = 1;\n\tq = x;\n\t\n\twhile q%p!=1 and n buy\n shares = r / buy\n profit = shares * (sell - buy)\n r += profit\nend\n\nputs r\n", "lang_cluster": "Ruby", "tags": ["greedy", "implementation"], "code_uid": "bfe075d24f7ed770af8d185b23905103", "src_uid": "42f25d492bddc12d3d89d39315d63cb9", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a = [\"ABXC\", \"XBAC\", \"BXAC\", \"BCAX\", \"BCXA\", \"XCBA\", \"CXBA\", \"CABX\", \"CAXB\", \"XACB\", \"AXCB\", \"ABCX\"]\n#b = [\"BAXC\", \"XABC\", \"AXBC\", \"ACBX\", \"ACXB\", \"XCAB\", \"CXAB\", \"CBAX\", \"CBXA\", \"XBCA\", \"BXCA\"]\nsa = readline.strip + readline.strip\nsb = readline.strip + readline.strip\nputs a.count(sa) == a.count(sb) ? \"YES\" : \"NO\"\n", "lang_cluster": "Ruby", "tags": ["brute force", "constructive algorithms", "implementation"], "code_uid": "0bc69f57443322aa7e6aff2f5edf55fd", "src_uid": "46f051f58d626587a5ec449c27407771", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["brute force", "constructive algorithms", "implementation"], "code_uid": "dd5e11f8f0280602d9ed0511ac4d5f58", "src_uid": "46f051f58d626587a5ec449c27407771", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,m = gets.split.map(&:to_i)\nt = gets.split.map(&:to_i)\ntmp = []\nsum = 0\nans = []\nt.each do |v|\n sum += v\n if sum <= m\n ans << 0\n else\n tmp.sort!.reverse!\n a = 0\n ts = sum\n tmp.each do |x|\n ts -= x\n a += 1\n if ts <= m\n ans << a\n break\n else a == tmp.length\n a << 0\n end\n end\n end\n tmp << v\nend\nputs ans.join(\" \")", "lang_cluster": "Ruby", "tags": ["sortings", "greedy"], "code_uid": "64c5de967763b108ab9b22be0d09237d", "src_uid": "d3c1dc3ed7af2b51b4c49c9b5052c346", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, m = gets.split.map(&:to_i)\nminv = [n - 2 * m, 0].max\nng = -1\nok = n\nwhile ok - ng > 1\n mid = (ng + ok) / 2\n if mid * (mid - 1) >= 2 * m\n ok = mid\n else\n ng = mid\n end\nend\nmaxv = n - ok\nputs \"#{minv} #{maxv}\"", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "graphs"], "code_uid": "dfc1145e1bf44b86c37bcf8a49ada151", "src_uid": "daf0dd781bf403f7c1bb668925caa64d", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def step(a,op)\n a.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 res+=step(t,oper[2])\n end\nend\nputs res.min", "lang_cluster": "Ruby", "tags": ["brute force"], "code_uid": "26f2f36a8b89a4a03f70ef9733ec7ddb", "src_uid": "7a66fae63d9b27e444d84447012e484c", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a = gets.split.collect(&:to_i)\n#s = \"1 3 2 1 2 3\"\n#a = s.split.collect(&:to_i)\nans = \"NO\"\nsum = 0\na.each{|x| sum+=x}\na.each_index{|x| \n\ta.each_index{\n\t|y| a.each_index{|z| \n\t\tif x>y and y > z and a[x]+a[y]+a[z] == sum/2.0 then\n\t\t\tans = \"YES\"\n\t\tend\n\t\t\t}}}\nputs ans", "lang_cluster": "Ruby", "tags": ["brute force"], "code_uid": "7225d9fa99af078a9fd57fc1458e1557", "src_uid": "2acf686862a34c337d1d2cbc0ac3fd11", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a = gets.split.map(&:to_i)\n(1 << 6).times do |i|\n if i.to_s(2).count(?1) == 3\n c = [0, 0]\n 6.times do |j|\n if (i & (1 << j)) > 0\n c[1] += a[j]\n else\n c[0] += a[j]\n end\n end\n if c[0] == c[1]\n puts \"YES\"\n exit\n end\n end\nend\nputs \"NO\"", "lang_cluster": "Ruby", "tags": ["brute force"], "code_uid": "3eda87dee53f8e770449dcf3aba7c521", "src_uid": "2acf686862a34c337d1d2cbc0ac3fd11", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a=gets.split.map &:to_i\ns=a.inject :+\nputs (a.combination(3).any?{|j| j.inject(:+)*2==s} ? \"YES\" : \"NO\")\n", "lang_cluster": "Ruby", "tags": ["brute force"], "code_uid": "7d20a9f83b7bbf0e3182aa9c8baa345b", "src_uid": "2acf686862a34c337d1d2cbc0ac3fd11", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "1b95d158433b882408a8518e40b1e028", "src_uid": "1503d761dd4e129fb7c423da390544ff", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "k = gets\nstr = \"1\"\nnum = 1\nwhile(str.length < k.to_i)\n num+=1\n str += num.to_s\nend\nprint(str[k.to_i - 1])", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "528e15eaee3c6b88f7ddf359f41b7cd1", "src_uid": "1503d761dd4e129fb7c423da390544ff", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "input=gets.split[0]\ndx={\"L\"=>-1,\"R\"=>1,\"U\"=>0,\"D\"=>0}\ndy={\"L\"=>0,\"R\"=>0,\"U\"=>-1,\"D\"=>1}\nd=[\"L\",\"R\",\"D\",\"U\"]\nx=y=0\naccess=Hash.new\ninput.length.times{|i|\n access[[x,y]]=1\n x+=dx[input[i]]\n y+=dy[input[i]]\n}\naccess[[x,y]]=1\nmincost=Hash.new\nmincost.default=999999999\nqueue=Array.new\nqueue.push([0,0])\nmincost[[0,0]]=0\nwhile queue.size()>0\n now=queue.shift\n nowcost=mincost[now]\n for k in 0..3\n next_state=[now[0]+dx[d[k]],now[1]+dy[d[k]]]\n next unless access.key?(next_state)\n if mincost[next_state]>nowcost+1 then\n mincost[next_state]=nowcost+1\n queue.push(next_state)\n end\n end\nend\nif mincost[[x,y]]==input.length then\n puts \"OK\"\nelse\n puts \"BUG\"\nend\n", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation", "graphs"], "code_uid": "4dc1a6f176d0617efcaacb7a8b62cf08", "src_uid": "bb7805cc9d1cc907b64371b209c564b3", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "robot_movements = gets.chomp\nroute = [[0,0]]\nrobot_movements.split(//).each do |c|\n now = route.last\n tugi = []\n if c=='U'[0]\n tugi = [now[0],now[1]-1]\n elsif c == 'D'[0]\n tugi = [now[0],now[1]+1]\n elsif c == 'R'[0]\n tugi = [now[0]+1,now[1]]\n else\n tugi = [now[0]-1,now[1]]\n end\n if route.include?(tugi)\n puts \"BUG\"\n exit 0\n elsif route.size>=2 && \n ( route[0..-2].include?([tugi[0]-1,tugi[1]]) ||\n route[0..-2].include?([tugi[0]+1,tugi[1]]) ||\n route[0..-2].include?([tugi[0],tugi[1]-1]) ||\n route[0..-2].include?([tugi[0],tugi[1]+1]))\n puts \"BUG\"\n exit 0\n else\n route << tugi\n end\nend\nputs \"OK\"\n", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation", "graphs"], "code_uid": "a1afe281323dfdd1771132ca185c93ef", "src_uid": "bb7805cc9d1cc907b64371b209c564b3", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = gets.chomp!\n\nmas = Hash.new()\nfor i in -101..101\n mas[i] = Hash.new()\n for j in -101..101\n mas[i][j] = 999999;\n end\nend\n\nstep = 0\nx,y = 0,0\nmas[x][y] = 0\ns.chars { |c|\n mas[x+1][y] = [mas[x+1][y],mas[x][y] + 1].min\n mas[x-1][y] = [mas[x-1][y],mas[x][y] + 1].min\n mas[x][y-1] = [mas[x][y-1],mas[x][y] + 1].min\n mas[x][y+1] = [mas[x][y+1],mas[x][y] + 1].min\n\n case c\n when \"R\"\n x += 1\n when \"L\"\n x -= 1\n when \"U\"\n y += 1\n when \"D\"\n y -= 1\n end\n\n if mas[x][y] < step + 1\n puts \"BUG\"\n exit\n end\n\n step += 1\n}\n\nputs \"OK\"", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation", "graphs"], "code_uid": "ca606da59c159afbf425c1a7ea4e7d6c", "src_uid": "bb7805cc9d1cc907b64371b209c564b3", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "route = gets.chomp\nvisited = {[0, 0] => 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", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation", "graphs"], "code_uid": "4dafa54e0f1fd16993430319fc15e800", "src_uid": "bb7805cc9d1cc907b64371b209c564b3", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = gets.chomp.split(//)\nc = [0,0]\nh = Hash.new(false)\nh[c.dup] = true\ns.each do |x|\n p = c.dup\n c[0] += 1 if x == 'R'\n c[0] -= 1 if x == 'L'\n c[1] += 1 if x == 'U'\n c[1] -= 1 if x == 'D'\n near = [ [c[0]+1,c[1]],\n [c[0]-1,c[1]],\n [c[0],c[1]+1],\n [c[0],c[1]-1]\n ]\n near.delete p\n if h[c] or h[near[0]] or h[near[1]] or h[near[2]]\n puts \"BUG\"\n exit 0\n else\n h[c.dup] = true\n end\nend\nputs \"OK\"\n", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation", "graphs"], "code_uid": "c4dcdbb8aba438bea5c4840134eb8d2e", "src_uid": "bb7805cc9d1cc907b64371b209c564b3", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\narr = gets.chomp.split(\" \").map(&:to_i)\n\nnewarr = []\n\nprev = [-1]\n\narr.each do |x|\n if x != prev.max+1\n newarr.push prev\n prev = [x]\n else\n prev.push x\n end\nend\nnewarr.push prev\ncountarr = [0]\n\nnewarr.each do |z|\n len = z.length\n next if len == 1\n\n if z.include?(1) or z.include?(1000)\n countarr.push len-1\n else\n countarr.push len-2\n end\nend\n\n#p newarr\nputs countarr.max\n", "lang_cluster": "Ruby", "tags": ["greedy", "implementation"], "code_uid": "9afb0867b2da261dfa57f8c2277ee75f", "src_uid": "858b5e75e21c4cba6d08f3f66be0c198", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']\n\ndef inpf() a=gets.chomp.split(\" \").map(&:to_f)end\n\ndef inps() a=gets.chomp.split(\" \")end\n\ndef copy(a) Marshal.load(Marshal.dump(a)) end\n\ndef kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end\n\ndef na(n,d=0) Array.new(n,d)end\n\ndef na2(n,m,d=0) Array.new(n){Array.new(m,d)}end\n\ndef na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end\n\ndef inp() a=gets.chomp.split(\" \").map(&:to_i)end\n\ndef r_up(a, b) (a+b-1)/b end\n\ndef sum(a) a.inject(:+) end\n\nrequire 'prime'\n\nn = inp[0]\nt = inp\nt = t.sort\nh = {}\nans = 0\nt.each do |d|\n (t).each do |i|\n if(d%i == 0)\n h[i] = true\n break\n end\n end\nend\n\np ((h.to_a.size))\n", "lang_cluster": "Ruby", "tags": ["math", "greedy", "implementation"], "code_uid": "8c8fe3a14d1780e7af4717b02aa642db", "src_uid": "63d9b7416aa96129c57d20ec6145e0cd", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\na = gets.split.map(&:to_i).sort\npainted = Array.new(n, false)\ncolors = 0\nfor i in 0...n do\n if !painted[i]\n colors += 1\n painted[i] = true\n for j in (i+1)...n do\n if !painted[j] && a[j] % a[i] == 0\n painted[j] = true\n end\n end\n end\nend\nputs colors\n", "lang_cluster": "Ruby", "tags": ["math", "greedy", "implementation"], "code_uid": "a3e29a7072dcf08e6e66888e0fd51b19", "src_uid": "63d9b7416aa96129c57d20ec6145e0cd", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\na = gets.split.map(&:to_i).sort\n\nans = 0\nwhile !a.empty?\n ans += 1\n t = a.shift\n idx = []\n a.length.times do |i|\n if a[i] % t == 0\n idx << i\n end\n end\n idx.reverse.each do |v|\n a.delete_at(v)\n end\nend\np ans\n", "lang_cluster": "Ruby", "tags": ["math", "greedy", "implementation"], "code_uid": "8936662d32c40e4b691538662e72976e", "src_uid": "63d9b7416aa96129c57d20ec6145e0cd", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def a(c,r)\n\treturn [Rational(1),fin(c,r)].min\nend\ndef fin(c,r)\n\treturn 0 if c==0 || c ==r+1\n\treturn $t if c==1&&r==1\n\treturn fout(c-1,r-1)/2 + fout(c,r-1)/2;\nend\ndef fout(c,r)\n\treturn [Rational(0),fin(c,r)-Rational(1)].max\nend\n\nn,$t=gets.chomp.split(' ').map{|x| x.to_i}\n\ncount = 0\nfor row in 1..n\n\tfor g in 1..row\n\t\tif a(g,row)==1\n\t\t\tcount+=1\n\t\tend\n\tend\nend\nputs count\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "d1c95a261f0d4cbf145209a4f70ab312", "src_uid": "b2b49b7f6e3279d435766085958fb69d", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "\nnumbers = gets\n\nres = numbers.split(' ')\n\nn = res[0].to_i\nt = res[1].to_i\n\ndata = grid = Array.new(n+1) { Array.new(n+1) }\ntotal = 0;\nk = 0\np = 0\nwhile(k < n+1)\n p = 0\n while (p < n+1)\n data[p][k] = 0.0\n p +=1\n end\n k+=1\nend\ni = 0\nwhile (i < t) do\n data[0][0]+=1;\n k,p = 0;\n while(k < n)\n p = 0\n while (p <= k)\n if data[k][p] > 1.0\n delta = data[k][p] - 1.0\n data[k][p] = 1.0;\n data[k+1][p]+= delta/2.0\n data[k+1][p+1]+=delta/2.0\n end\n p +=1\n end\n k+=1\n end\n i = i + 1\nend\ntotal = 0\nk,p = 0;\nwhile(k < n)\n p = 0\n while (p <= k)\n #puts k.to_s + ':' + p.to_s + \":::\"+data[k][p].to_s\n if data[k][p] >= 1\n total +=1;\n end\n p +=1\n end\n k+=1\nend\n\nputs total", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "d8ccccebb8b2b0328ca87bf5a3b73869", "src_uid": "b2b49b7f6e3279d435766085958fb69d", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "7af79bb08693ec0dbfa9830b7c0e9170", "src_uid": "b2b49b7f6e3279d435766085958fb69d", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "require 'prime'\n\n# TEMPLATE BEGIN\ndef read_vector\n gets.chomp.split(/\\s+/)\nend\ndef read_vector_int\n read_vector.map(&:to_i)\nend\n# TEMPLATE END\n\npre = [9, 3049, 9173, 11621, 13963, 16453, 19237, 32077, 34961, 37831, 70529, 73939, 77023, 79907, 92789, 95429, 98597, 102031, 105601, 108943, 112181, 116107, 119827, 123667, 127601, 131581, 135589, 139721, 143743, 147997, 151531, 155621, 159389, 163363, 167597, 171383, 175303, 178897, 182579, 186247, 190027, 193883, 197261, 300929, 304279, 308597, 313477, 317179, 320657, 324901, 328813, 333323, 337153, 341501, 345547, 349667, 353867, 358427, 362867, 366851, 371191, 375223, 379663, 383797, 388391, 392201, 395921, 399941, 704399, 708403, 713477, 718183, 722311, 726911, 731189, 735871, 740021, 744637, 748987, 753859, 758671, 763123, 767633, 771917, 776513, 780323, 785269, 789017, 793489, 797911, 902333, 907213, 911303, 916213, 920377, 924283, 929009, 933847, 938713, 943367, 948349, 952811, 957703, 961783, 966227, 970789, 974537, 978541, 982301, 987101, 992021, 996601, 1000763, 1005883, 1010549, 1015423, 1020541, 1025747, 1030493, 1036261]\n\nn = gets.to_i\nwhile n >= 100 do\n pre = pre[1..-1]\n n -= 100\nend\nval = pre[0]\nwhile n > 0 do\n val += 2\n next unless val.prime?\n rev = val.to_s.reverse.to_i\n next if rev == val\n next unless rev.prime?\n n -= 1\nend\nputs val.to_s\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation", "number theory"], "code_uid": "e82737f7e21254aae81587f71ae7a676", "src_uid": "53879e79cccbacfa6586d40cf3436657", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "l1 = gets.chomp\nvals1 = l1.split(' ').map {|x| x.to_i}\n\nr = vals1[0]\nc = vals1[1]\nn = vals1[2]\nk = vals1[3]\n\nviolas = []\ncolumns = []\nc.times {|x| columns << 0}\nr.times {|x| col = []; c.times {|y| col << 0}; violas << col }\nminx = r\nminy = c\nmaxx = -1\nmaxy = -1\nn.times {\n indices = gets.chomp.split(' ').map {|x| x.to_i - 1}\n violas[indices[0]][indices[1]] = 1\n minx = indices[1] if indices[1] < minx\n miny = indices[0] if indices[0] < miny\n maxx = indices[1] if indices[1] > maxx\n maxy = indices[0] if indices[0] > maxy\n}\n\nRect = Struct.new(:x, :y, :x2, :y2)\n\nrectangles = []\n(0..r-1).each do |y|\n (0..c-1).each do |x|\n (y..r-1).each do |y2|\n (x..c-1).each do |x2|\n v = 0\n (y..y2).each do |yi|\n (x..x2).each do |xi|\n v += violas[yi][xi]\n end\n end\n if v >= k\n rectangles << Rect.new(x, y, x2, y2) unless rectangles.any? {|r|\n r.x == x && r.y == y && r.x2 == x2 && r.y2 == y2\n }\n end\n end\n end\n end\nend\nputs rectangles.length\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "782141d966f15f833ac69bbc36df8190", "src_uid": "9c766881f6415e2f53fb43b61f8f40b4", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "buf = gets.split(' ')\nr,c,n,k = buf[0].to_i, buf[1].to_i, buf[2].to_i, buf[3].to_i\na=Array.new(22)\nfor i in 0..r\n\ta[i]=Array.new(22, 0)\nend\nfor i in 1..n\n\tbuf = gets.split(' ')\n\tx, y = buf[0].to_i, buf[1].to_i\n\ta[x][y]=1\nend\nfor i in 1..r\n\tfor j in 1..c\n\t\ta[i][j]+=a[i-1][j]+a[i][j-1]-a[i-1][j-1]\n\tend\nend\nans=0\nfor x1 in 1..r\n\tfor y1 in 1..c\n\t\tfor x2 in x1..r\n\t\t\tfor y2 in y1..c\n\t\t\t\ttot = a[x2][y2]-a[x1-1][y2]-a[x2][y1-1]+a[x1-1][y1-1]\n\t\t\t\tans+=1 if tot>=k\n\t\t\tend\n\t\tend\n\tend\nend\nputs ans", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "ebc49b248f5806e034cb399e1b794449", "src_uid": "9c766881f6415e2f53fb43b61f8f40b4", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/ruby\nr,c,n,k=gets.split.map(&:to_i)\nm=(r+1).times.map{[0]*(c+1)}\nn.times{\n\ta,b=gets.split.map(&:to_i)\n\tm[a][b]=1\n}\n(r+1).times{|i|c.times{|j|m[i][j+1]+=m[i][j]}}\nr.times{|i|(c+1).times{|j|m[i+1][j]+=m[i][j]}}\nx=0\nr.times{|i0|c.times{|j0|(i0+1).step(r){|i1|(j0+1).step(c){|j1|\n\tx+=1 if k<=m[i0][j0]-m[i0][j1]-m[i1][j0]+m[i1][j1]\n}}}}\np x", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "9d48e805b8b5a0e1d2abe9b2764c8572", "src_uid": "9c766881f6415e2f53fb43b61f8f40b4", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,f=gets.split.map{|e| e.to_i}\n\nhs=Hash.new(0)\ngets.chomp.chars.each{|e|\n\ths[e]+=1\n}\n\nv=hs.values.sort.pop\n\nif v<=f then\n\tputs \"YES\"\nelse\n\tputs \"NO\"\nend", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "c9c08ea6cdbe705b1010ddd7a73d7b2e", "src_uid": "ceb3807aaffef60bcdbcc9a17a1391be", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,k=gets.split.map(&:to_i)\ns = gets.chomp\nh = Hash.new(0)\ns.chars do |c|\n h[c] += 1\nend\n\nf = true\n[*?a..?z].each do |c|\n if h[c] == 0\n next\n elsif (h[c] - 1) / k > 0\n f = false\n break\n end\nend\nputs f ? \"YES\" : \"NO\"", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "389e7e5b8a0f53c8b335ff60daf68ce0", "src_uid": "ceb3807aaffef60bcdbcc9a17a1391be", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,k=gets.split.map &:to_i\nh=Hash.new 0\ngets.chomp.chars{|c|h[c]+=1}\nputs h.values.any?{|e|e>k} ? :NO : :YES", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "5916fa3d880e51423d70cff8875cb8f5", "src_uid": "ceb3807aaffef60bcdbcc9a17a1391be", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "gets;p gets.split.map{|e|e.chars.count{|f|f==f.upcase}}.max", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "5687a5fc48518c0339b82c97ba9f46e0", "src_uid": "d3929a9acf1633475ab16f5dfbead13c", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "Capital = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']\n\ndef volume(s)\n\tt = 0\n\tfor char in s.split('')\n\t\tt += 1 if Capital.include?char\n\tend\t\n\treturn t\nend\n\nn = gets.to_i\ns = gets.chomp.split\nbest = 0\nfor word in s\n\tbest = [best,volume(word)].max\nend\n\nputs best", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "c673aceef3e0f3ff9440e4f72fda177f", "src_uid": "d3929a9acf1633475ab16f5dfbead13c", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets\nwords = gets.chomp.split(\" \")\n\nputs words.map{|w| w.each_char.count{|c| ('A'..'Z').cover?(c)}}.max || 0", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "41429ddb7494fa02e2c9275425e955da", "src_uid": "d3929a9acf1633475ab16f5dfbead13c", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["math", "number theory"], "code_uid": "c03347890044cab65da89f648ff5e19f", "src_uid": "792efb147f3668a84c866048361970f8", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/ruby\nrequire 'rational'\na,b=gets.split.map(&:to_i)\nr=0\nwhile b>0\n\tg=a.gcd(b)\n\ta/=g;b/=g\n\tr+=a/b\n\ta,b=b,a-a/b*b\nend\np r", "lang_cluster": "Ruby", "tags": ["math", "number theory"], "code_uid": "e57c4d687d616791a00c21588d71ddd7", "src_uid": "792efb147f3668a84c866048361970f8", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a, b = gets.split.collect{|i| i.to_i}\nans = 0\nwhile b != 1\n a, b = b, a if a < b \n ans += a/b\n a = a%b\nend\nputs ans+a\n", "lang_cluster": "Ruby", "tags": ["math", "number theory"], "code_uid": "1ca58d3a806a966343d6a79b91768f8d", "src_uid": "792efb147f3668a84c866048361970f8", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def f(n, a, b)\n if a > b\n f(n, b, a)\n else\n (b / n).floor + 1 - (a / n).ceil\n end\nend\n\nx, y, a, b, c, d = gets.split.map(&:to_r)\np [f(2 * x, a + b, c + d), f(2 * y, a - b, c - d)].max\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "5316f23185d56450d328c74954b8be4f", "src_uid": "7219d1837c83b5920992aee5a60dc0d9", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def f(n, a, b)\n if a > b\n f(n, b, a)\n else\n Rational(b, n).floor + 1 - Rational(a, n).ceil\n end\nend\n\nx, y, a, b, c, d = gets.split.map(&:to_i)\np [f(2 * x, a + b, c + d), f(2 * y, a - b, c - d)].max\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "83e41b877d5d7f0be048b3fccaa80014", "src_uid": "7219d1837c83b5920992aee5a60dc0d9", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/ruby\ninclude Math\n\nn, k = readline().split().map(&:to_i)\n\nif k == 1 then\n\tputs n\nelse\n\tputs (1 << n.to_s(2).length) - 1\nend\n\n", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "number theory", "bitmasks"], "code_uid": "d0b609f5469a4c5295af5d73884c1f42", "src_uid": "16bc089f5ef6b68bebe8eda6ead2eab9", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "x = gets.chomp.split(' ')\nn = x[0].to_i\nk = x[1].to_i\nif k == 1\n puts n\nelse\n ans = 0\n i = 0\n while 2**i <= n\n ans += 2 ** i\n i += 1\n end\n puts ans\nend", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "number theory", "bitmasks"], "code_uid": "d8744f55325db9e49223d7e98e3fceea", "src_uid": "16bc089f5ef6b68bebe8eda6ead2eab9", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,k=gets.split.map &:to_i\np k==1 ? n : 2**n.to_s(2).size-1", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "number theory", "bitmasks"], "code_uid": "37df8d4f851ec5753c168218af8a5c87", "src_uid": "16bc089f5ef6b68bebe8eda6ead2eab9", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "time = gets.chomp\n\nh = time.split(':').first.to_i\nm = time.split(':').last.to_i\ncount = 0\n\nloop do\n k = \"#{h.to_s.rjust(2, '0')}:#{m.to_s.rjust(2, '0')}\"\n if k == k.reverse\n break\n end\n\n m = (m+1)%60\n if m == 0\n h = (h+1 )%24\n end\n count += 1\nend\n\nputs count", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "460630aad1491aa7fb2f53d773d19dba", "src_uid": "3ad3b8b700f6f34b3a53fdb63af351a5", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#http://codeforces.com/contest/816/problem/A\n\n\ntime = gets.chop\n\nh = time.slice(0, 2).to_i\nm = time.slice(3, 2).to_i\n\ntmp = h / 10\npal_m = (h - (tmp * 10)) * 10 + tmp\ncount = 0\n\nf = false\n if(m == pal_m) then\n f = true\n end\nwhile(!f) do\n m = m + 1\n if(m == 60) then\n m = 0\n h = h + 1\n end\n h = h % 24\n pal_m = (h % 10) * 10 + (h / 10)\n count = count + 1\n if(m == pal_m) then\n f = true\n end\nend\n\nputs count\n=begin\nif(m<10) then\n if(h<10) then\n puts \"0\" + h.to_s + \":0\" + m.to_s\n else\n puts h.to_s + \":0\" + m.to_s\n end\nelse\n if(h<10) then\n puts \"0\" + h.to_s + \":\" + m.to_s\n else\n puts h.to_s + \":\" + m.to_s\n end\nend\n=end\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "3266eee533c990e43ef4a60bf1743e8b", "src_uid": "3ad3b8b700f6f34b3a53fdb63af351a5", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def is_palin? hh, mm\n hour = \"%.2d\" % hh\n mins = \"%.2d\" % mm\n mins.reverse == hour && hour.reverse == mins\nend\nhh, mm = gets.strip.split(\":\").map(&:to_i)\nans = 0\nwhile !is_palin?( hh, mm )\n ans += 1\n if mm < 59\n mm += 1\n else\n mm = 0\n if hh < 23\n hh += 1\n else\n hh = 0\n end\n end\nend\nputs ans\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "ca2388a5ebd461c097f445137c22ab8e", "src_uid": "3ad3b8b700f6f34b3a53fdb63af351a5", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "h,m=gets.split(':').map(&:to_i)\nt=Time.gm(2008,7,7,h,m)+gets.to_i*60\nputs t.strftime('%H:%M')", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "cbe85e76e8ad9b94169ff0ea080310ee", "src_uid": "20c2d9da12d6b88f300977d74287a15d", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "h, m = gets.chomp.split(':').map(&:to_i)\na = gets.chomp.to_i\n\nt = Time.new(2002, 10, 31, h, m, 0)\nt2 = t + a * 60\n\nputs \"#{t2.hour.to_s.rjust(2, '0')}:#{t2.min.to_s.rjust(2, '0')}\"\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "d36f8eb77bede47f902b2a4b18146052", "src_uid": "20c2d9da12d6b88f300977d74287a15d", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/ruby\ndef encode(n) '%02d:%02d'%[n/60,n%60] end\ndef decode(s)\n\th,m=s.split(':').map(&:to_i)\n\th*60+m\nend\nputs encode((decode(gets)+gets.to_i)%1440)", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "ed65f75937ebc6f2d1f95b24ee2c3360", "src_uid": "20c2d9da12d6b88f300977d74287a15d", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "k = gets.to_i\na = [\"|\"]\nb = [\"|\"]\nd = [\"|\"]\nif k >= 3\n c = \"|O.......................|\"\nelse\n c = \"|#.......................|\"\nend\nan = bn = dn = 0\nif k == 1\n an = 1\nelsif k == 2 || k == 3\n an = bn = 1\nelsif k >= 4\n an = ((k - 1) / 3.0).ceil\n if (k - 1) % 3 == 0\n bn = dn = an\n elsif (k - 1) % 3 == 1\n bn = dn = an - 1\n elsif (k - 1) % 3 == 2\n bn = an\n dn = an - 1\n end\nend\nrow = [a, b, d]\nrown = [an, bn, dn]\nfor i in 0...rown.size\n rown[i].times do\n row[i].push \"O.\"\n end\n (11 - rown[i]).times do\n row[i].push \"#.\"\n end\nend\na.push \"|D|)\"\nb.push \"|.|\"\nd.push \"|.|)\"\nputs \"+------------------------+\", a.join(\"\"), b.join(\"\"), c, d.join(\"\"), \"+------------------------+\"\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "727fed84a6ee69f7a18c366783730361", "src_uid": "075f83248f6d4d012e0ca1547fc67993", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def print_row(z, r, s, p, q, n = 11)\n puts p + ('O' + r) * z + s * (n - z) + q\nend\n\nk = gets.to_i\na = Array.new(4, 0)\n\nif k > 2\n a[3] = 1\n k -= 1\nend\n\na[0] = a[1] = a[2] = k / 3\n(0...k % 3).each do |i|\n a[i] += 1\nend\n\nprint_row(0, '', '--', '+', '--+')\nprint_row(a[0], '.', '#.', '|', '|D|)')\nprint_row(a[1], '.', '#.', '|', '|.|')\nprint_row(a[3], '.', '#.', '|', '......................|', 1)\nprint_row(a[2], '.', '#.', '|', '|.|)')\nprint_row(0, '', '--', '+', '--+')", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "7ad8c6befa72e4d912dd7014d5e1a221", "src_uid": "075f83248f6d4d012e0ca1547fc67993", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "arr = Array.new(5)\n\narr[0] = \"+------------------------+\"\narr[1] = \"|#.#.#.#.#.#.#.#.#.#.#.|D|)\"\narr[2] = \"|#.#.#.#.#.#.#.#.#.#.#.|.|\"\narr[3] = \"|#.......................|\"\narr[4] = \"|#.#.#.#.#.#.#.#.#.#.#.|.|)\"\narr[5] = \"+------------------------+\"\n\nn = gets.to_i\n\nj = 1\nwhile n > 0\n for i in 1..4\n arr[i][j] = 'O'\n \n if (i == 3 && j != 1)\n arr[i][j] = '.'\n n += 1\n end\n \n n -= 1\n \n break if n == 0\n end\n \n j += 2\nend\n\narr.each do |x|\n puts x\nend", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "1e66b9c4017e369795823fb93b3e9acd", "src_uid": "075f83248f6d4d012e0ca1547fc67993", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "MOD = 10 ** 9 + 9\ndef pow2(x)\n st = 1\n pow = 2\n while(x != 0)\n if((x & 1) != 0)\n st = (st * pow) % MOD\n end\n pow = (pow * pow) % MOD\n x >>= 1\n end\n return st\nend\nn, m, k = gets.chop.split.map(&:to_i)\nextra = n - m\nif(extra * k >= n)\n print m % MOD\nelse\n st = n - extra * k\n cnt = st / k\n rest = st % k\n total = pow2(cnt + 1)\n total = (total - 2 + MOD) % MOD\n total = (total * k + rest) % MOD\n total += extra * (k - 1)\n total %= MOD\n print total\nend\n", "lang_cluster": "Ruby", "tags": ["math", "binary search", "number theory", "greedy", "matrices"], "code_uid": "95a66c5b33c19900447815dde5c25826", "src_uid": "9cc1aecd70ed54400821c290e2c8018e", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "require 'openssl'\n\nn, m, k = gets.chomp.split(' ').map(&:to_i)\nd = 1000000009\nx = [0, m - (n - n % k) / k * (k-1) - n % k].max\n\nr = 2.to_bn.mod_exp(x+1, d)\nr = (r-2)*k % d\nr = (r + (m-x*k)) % d\n\nwhile r < 0 \n\tr += d\nend\n\nputs r", "lang_cluster": "Ruby", "tags": ["math", "binary search", "number theory", "greedy", "matrices"], "code_uid": "707cdbf1bf7640fe81c9e50583b078fb", "src_uid": "9cc1aecd70ed54400821c290e2c8018e", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "require 'openssl'\nMOD = 10 ** 9 + 9\nn, m, k = gets.chop.split.map(&:to_i)\nextra = n - m\nif(extra * k >= n)\n print m % MOD\nelse\n st = n - extra * k\n cnt = st / k\n rest = st % k\n total = ((2.to_bn.mod_exp(cnt + 1,MOD) - 2 + MOD) % MOD * k + rest + extra *(k - 1)) % MOD\n print total\nend\n", "lang_cluster": "Ruby", "tags": ["math", "binary search", "number theory", "greedy", "matrices"], "code_uid": "c5da6e4ec4c2975c5a763c4b13e1324c", "src_uid": "9cc1aecd70ed54400821c290e2c8018e", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "require 'openssl'\nn,m,k=gets.split.map(&:to_i)\nd=10**9+9\np=n/k\nq=m-n+p\nif q<=0\n puts m\n exit\nend\nr=2.to_bn.mod_exp(q+1,d).to_i\nr=((d+r-2)%d*k+m-q*k)%d\np r\n", "lang_cluster": "Ruby", "tags": ["math", "binary search", "number theory", "greedy", "matrices"], "code_uid": "e76d72bddd9550460532af69d870a01d", "src_uid": "9cc1aecd70ed54400821c290e2c8018e", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "module STL\n module Algorithm\n def power_mod(a, b, c) #compute (a ^ b) mod c\n ans, tich = 1, a\n while b > 0\n ans = (ans * tich) % c if b % 2 == 1\n tich = (tich * tich) % c\n b /= 2\n end\n ans\n end\n end\nend\n\ninclude STL::Algorithm\nMOD = 1000_000_009\ndef solve(f)\n n, m, k = f.gets.split.map(&:to_i)\n t = (n / k) * (k - 1) + n % k\n if m <= t\n puts m\n else\n a = m - t\n\n tmp = power_mod(2, (a + 1), MOD)\n puts (k * (tmp - 2) + m - a * k) % MOD\n end\nend\n\ndef debug\n (1..3).each do |e|\n f = File.new(\"test#{e}.txt\", 'r')\n solve f\n f.close\n end\nend\n\ndef release\n solve STDIN\nend\n\nrelease", "lang_cluster": "Ruby", "tags": ["math", "binary search", "number theory", "greedy", "matrices"], "code_uid": "dbe9ae0043426b8616689bd818dedd22", "src_uid": "9cc1aecd70ed54400821c290e2c8018e", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "x= Integer(gets.chomp)\n\nif (x%2==0)\n puts (\"white\")\n puts (\"1 2\")\nelse\n puts'black'\nend", "lang_cluster": "Ruby", "tags": ["math", "constructive algorithms", "games"], "code_uid": "d96daf97deceedb6b90c30fbb44ad9fb", "src_uid": "52e07d176aa1d370788f94ee2e61df93", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.to_i\nputs n%2>0?\"black\":[\"white\",\"1 2\"]", "lang_cluster": "Ruby", "tags": ["math", "constructive algorithms", "games"], "code_uid": "b20bb62d3f452ac539f6145a0d78f9cf", "src_uid": "52e07d176aa1d370788f94ee2e61df93", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.chomp.to_i\nif( n % 2 != 0 )\n\tputs(\"black\")\nend\nif( n % 2 == 0 )\n\tputs(\"white\\n1 2\")\nend", "lang_cluster": "Ruby", "tags": ["math", "constructive algorithms", "games"], "code_uid": "d1072ef8164c81fe35cf8dba030e96db", "src_uid": "52e07d176aa1d370788f94ee2e61df93", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "inp = gets.chomp\nn = inp.to_i\n\nif(n%2==1)\n puts \"black\"\nelse\n puts \"white\"\n puts \"1 2\"\nend", "lang_cluster": "Ruby", "tags": ["math", "constructive algorithms", "games"], "code_uid": "6667efb1bcaca37d06963b4badb20670", "src_uid": "52e07d176aa1d370788f94ee2e61df93", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\nas = gets.split.map(&:to_i)\nlefted = []\n(n-1).downto(0) do |i|\n a = as[i]\n lefted << a unless lefted.include?(a)\nend\nputs lefted.size\nputs lefted.reverse.join(\" \")", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "ef005df7e01f94068b4198843434f561", "src_uid": "1b9d3dfcc2353eac20b84c75c27fab5a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "gets\na=gets.split.reverse.uniq.reverse\np a.size\nputs a*' '", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "f1b4b95b42138683d0c7c53039e4fe9d", "src_uid": "1b9d3dfcc2353eac20b84c75c27fab5a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "arr=(1..8).map{|e|\n\t(\"1\"*e+\"0\"*(e-1)).to_i(2)\n}.reverse\nn=gets.to_i\nputs arr.find{|e|\n\tn%e==0\n}", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "4a5b3b60176cc2ab6adfb00cb5581ffa", "src_uid": "339246a1be81aefe19290de0d1aead84", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.to_i\nr=1\nk=2\nloop{\n\tx=(2**k-1)*(2**~-k)\n\tbreak if n>= 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", "lang_cluster": "Ruby", "tags": ["brute force", "implementation", "bitmasks"], "code_uid": "65ac3adc3105a922020d99bfecde1dda", "src_uid": "3b12863997b377b47bae43566ec1a63b", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def color_to_bitmask(color)\n case color\n when 'B'\n bitmask = 0b00001\n when 'Y'\n bitmask = 0b00010\n when 'W'\n bitmask = 0b00100\n when 'G'\n bitmask = 0b01000\n when 'R'\n bitmask = 0b10000\n end\nend\n\ndef card_strings_to_card_bitmasks(card_strings)\n card_strings.map {\n |c|\n color = c[0]\n value = c[1].to_i\n \n color_to_bitmask(color) * 0b100000 + 2 ** (value - 1)\n }\nend\n\ndef check_ops_for_pair(ops, a, b)\n if a != b \n (a ^ b) & ops > 0\n else true\n end\nend\n\ndef combinations(i1)\n (0...(i1.size-1)).inject([]) {|pairs,x| pairs += ((x+1)...i1.size).map {|y| [i1[x],i1[y]]}}\nend\n\ndef check_ops_for_combinations(ops, combinations)\n #TODO this wastes a lot of time\n combinations.inject(true) { \n |result, combination|\n a, b = combination\n check = check_ops_for_pair(ops, a, b)\n result && check\n }\nend\n\ndef count_ones(n)\n n.to_s(2).count('1')\nend\n\nstrings = STDIN.read.split(\"\\n\")[1].split(\" \")\n\nbitmasks = card_strings_to_card_bitmasks(strings)\n\nbitmasks_combinations = combinations(bitmasks)\n\nbest_solution = 10\n\nfor ops in 0..2 ** 10 - 1\n if check_ops_for_combinations(ops, bitmasks_combinations)\n ones = count_ones(ops)\n if ones < best_solution\n best_solution = ones\n end\n end\nend\n\nputs best_solution\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation", "bitmasks"], "code_uid": "0b296227a933a643631b8d288be2158d", "src_uid": "3b12863997b377b47bae43566ec1a63b", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def color_to_bitmask(color)\n case color\n when 'B'\n bitmask = 0b00001\n when 'Y'\n bitmask = 0b00010\n when 'W'\n bitmask = 0b00100\n when 'G'\n bitmask = 0b01000\n when 'R'\n bitmask = 0b10000\n end\nend\n\ndef card_strings_to_card_bitmasks(card_strings)\n card_strings.map {\n |c|\n color = c[0]\n value = c[1].to_i\n \n color_to_bitmask(color) * 0b100000 + 2 ** (value - 1)\n }\nend\n\ndef check_ops_for_pair(ops, a, b)\n if a != b \n (a ^ b) & ops > 0\n else true\n end\nend\n\ndef combinations(i1)\n (0...(i1.size-1)).inject([]) {|pairs,x| pairs += ((x+1)...i1.size).map {|y| [i1[x],i1[y]]}}\nend\n\ndef check_ops_for_combinations(ops, combinations)\n combinations.inject(true) { \n |result, combination|\n a, b = combination\n check = check_ops_for_pair(ops, a, b)\n if not check\n break(false) \n end\n check\n }\nend\n\ndef count_ones(n)\n n.to_s(2).count('1')\nend\n\nstrings = STDIN.read.split(\"\\n\")[1].split(\" \")\n\nbitmasks = card_strings_to_card_bitmasks(strings)\n\nbitmasks_combinations = combinations(bitmasks)\n\nbest_solution = 10\n\nfor ops in 0..2 ** 10 - 1\n if check_ops_for_combinations(ops, bitmasks_combinations)\n ones = count_ones(ops)\n if ones < best_solution\n best_solution = ones\n end\n end\nend\n\nputs best_solution\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation", "bitmasks"], "code_uid": "fd1ae57ea6d0e0ea59a39bd4a7ee50ed", "src_uid": "3b12863997b377b47bae43566ec1a63b", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\n\nif ( n % 2 == 0 ) then\n puts \"No\"\nelsif ( a[0] % 2 == 0 || a[n - 1] % 2 == 0 )\n puts \"No\"\nelse\n puts \"Yes\"\nend", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "36cf7daefe7ccc2a2cf043dff5fdedd6", "src_uid": "2b8c2deb5d7e49e8e3ededabfd4427db", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,*a=$<.read.split.map &:to_i\nputs n&a[0]&a[-1]&1>0 ? :YES : :NO", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "0b583d4a3ec38ceb8ab3e89df5afaccc", "src_uid": "2b8c2deb5d7e49e8e3ededabfd4427db", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nif a.size % 2 == 1 && a[0] % 2 == 1 && a[-1] % 2 == 1\n puts \"Yes\"\nelse\n puts \"No\"\nend\n\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "03d33846ec67fba996ea1ec8d3804999", "src_uid": "2b8c2deb5d7e49e8e3ededabfd4427db", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "M=[0,31,28,31,30,31,30,31,31,30,31,30,31]\nm,d=gets.split.map(&:to_i)\np (d+M[m]-1+6)/7", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "d9c9b99b12701795706a19080dae498f", "src_uid": "5b969b6f564df6f71e23d4adfb2ded74", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "m, d=gets.split.map &:to_i\na=[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][m-1]\np (a+d+5)/7\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "6657a97e362a1ca8fe2a9b415788504e", "src_uid": "5b969b6f564df6f71e23d4adfb2ded74", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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\nDAYS = [ 0,\n 31, 28, 31, 30,\n 31, 30, 31, 31,\n 30, 31, 30, 31\n]\n\ndef solve(input, output)\n m, d = parse_int_array(input[0])\n first = 8 - d\n n = 1 + (DAYS[m]-first+6)/7\n output << n.to_s\nend\n\ntests do\n # test cases\n t(\"1 7\", \"6\")\n t(\"1 1\", \"5\")\n t(\"11 6\", \"5\")\nend\n\nputs solve(STDIN.read.split(\"\\n\"), []) unless TEST_MODE\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "d485414cb9608bee6ac294bc8366b120", "src_uid": "5b969b6f564df6f71e23d4adfb2ded74", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.chomp.to_i\n\na = []\n3.times {a << gets.chomp.split(\" \").map(&:to_i)}\n\nx = a[0][0]\ny = a[1][0]\nz = a[2][0]\n\nwhile x + y + z < n\n\tif a[0][0] < a[0][1]\n\t\tx += 1\n\t\ta[0][0] += 1\n\telsif a[1][0] < a[1][1]\n\t\ty += 1\n\t\ta[1][0] += 1\n\telsif a[2][0] < a[2][1]\n\t\tz += 1\n\t\ta[2][0] += 1\n\telse\n\t\tbreak\n\tend\nend\n\nputs [x, y, z] * \" \"\n", "lang_cluster": "Ruby", "tags": ["math", "greedy", "implementation"], "code_uid": "ee9d00a97299cd33bb7cb9a191fc5769", "src_uid": "3cd092b6507079518cf206deab21cf97", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def read_ints; gets.chomp.split.map(&:to_i) end\n@n = read_ints[0]\nmin1,max1 = read_ints\nmin2,max2 = read_ints\nmin3,max3 = read_ints\n\n@rez = [min1,min2,min3]\n\ndef left; @n - @rez.inject(:+) end\n\n@rez[0]+=[left,max1-@rez[0]].min\n@rez[1]+=[left,max2-@rez[1]].min\n@rez[2]+=[left,max3-@rez[2]].min\n\nputs @rez.join(' ')", "lang_cluster": "Ruby", "tags": ["math", "greedy", "implementation"], "code_uid": "21cb1410d26211b786df16fb666338d8", "src_uid": "3cd092b6507079518cf206deab21cf97", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\na = 3.times.map{gets.split.map(&:to_i)}\np = a.map{|x, y| x}\nn -= p.inject(:+)\n3.times do |i|\n mi = [a[i][1] - a[i][0], n].min\n p[i] += mi\n n -= mi\n break if n <= 0\nend\nputs p.join(' ')\n", "lang_cluster": "Ruby", "tags": ["math", "greedy", "implementation"], "code_uid": "2f27d191c5065ab66fed0e0754faa0e8", "src_uid": "3cd092b6507079518cf206deab21cf97", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def search(idx, num)\n\twk = num + $s[idx].to_i\n\tif idx == $s.length-1\n\t\tret = 0\n\t\tif wk % 2 == 0\n\t\t\tret = 1\n\t\telse\n\t\t\tret = 2\n\t\tend\n\t\treturn ret\n\tend\n\tif wk % 2 == 0\n\t\tnn = wk / 2\n\t\tif $ar[idx][nn] == nil\n\t\t\t$ar[idx][nn] = search(idx+1, nn)\n\t\tend\n\t\treturn $ar[idx][nn]\n\telse\n\t\tnn = wk / 2\n\t\tif $ar[idx][nn] == nil\n\t\t\t$ar[idx][nn] = search(idx+1, nn)\n\t\tend\n\t\tif $ar[idx][nn+1] == nil\n\t\t\t$ar[idx][nn+1] = search(idx+1, nn+1)\n\t\tend\n\t\treturn $ar[idx][nn]+$ar[idx][nn+1]\n\tend\nend\n\n$same = 1\n$s = gets.chomp\n$ar = Array.new($s.length).map!{|x| Array.new($s.length)}\nif $s.length == 1\n\tputs 9\nelse\n\tfor i in 0..$s.length-2\n\t\tw1 = $s[i].to_i\n\t\tw2 = $s[i+1].to_i\n\t\twk = (w1 + w2)/2\n\t\tif wk != w2 && (wk+1) != w2\n\t\t\t$same = 0\n\t\t\tbreak\n\t\tend\n\tend\n\n\tret = 0\n\tfor i in 0..9\n\t\tret += search(1,i)\n\tend\n\tputs ret-$same\nend", "lang_cluster": "Ruby", "tags": ["dp"], "code_uid": "46864b7d2c9b3d06a2f8977df6ef4751", "src_uid": "2dd8bb6e8182278d037aa3a59ca3517b", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, p, k = gets.split.map { |x| x.to_i }\n\nif p-k > 1 ;\n\tprint ?<, ?<, ' '\nend\n\n(p-k).upto(p+k) do |i|\n\tif i == p ;\n\t\tprint ?(, i, ?), ' '\n\telsif i >= 1 && i <= n ;\n\t\tprint i, ' '\n\tend\nend\n\nif p+k < n ;\n\tprint ?>, ?>, ' '\nend\n\nprint ?\\n\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "aa94f40cf9216800e0eb02322120f52c", "src_uid": "526e2cce272e42a3220e33149b1c9c84", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "18f6d5492da613e26dcee53fe75c1892", "src_uid": "526e2cce272e42a3220e33149b1c9c84", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "(n, p, k) = gets.split.map(&:to_i)\nresult = \"\"\nresult << \"<< \" if p-k > 1\n(([1, p-k].max)..(p-1)).each {|x| result << \"#{x} \"}\nresult << \"(#{p}) \"\n((p+1)..([p+k, n].min)).each {|x| result << \"#{x} \"}\nresult << \">>\" if p+k < n\nputs result\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "edea3765492ab955b80ced1999fa8c5c", "src_uid": "526e2cce272e42a3220e33149b1c9c84", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b,c,n=gets.split.map &:to_i;x=n-a-b+c;p a=n || b>=n || c >= n || c>a || c>b || n<1\n puts -1\nelse\n f = n - (a + b - c)\n if f > 0\n puts f\n else\n puts -1\n end\nend\n ", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "083fb4f6e2371c2aa7f543a919d23d83", "src_uid": "959d56affbe2ff5dd999a7e8729f60ce", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a, b, c, n = gets.chomp.split(' ').map(&:to_i)\n\nsol = n - a - b + c\nif sol > 0 && c <= a && c <= b \n\tputs sol\nelse\n\tputs -1\nend\n\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "9073b7e70a56fdde4792f040abf25864", "src_uid": "959d56affbe2ff5dd999a7e8729f60ce", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["math", "number theory"], "code_uid": "77c63aaf508505cf4974eba1d9339217", "src_uid": "c2cbc35012c6ff7ab0d6899e6015e4e7", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "MOD = 1000000007\n\ndef ep(a,n)\n\tans = 1\n\twhile n > 0\n\t\tans = (ans * a) % MOD if (n & 1) != 0\n\t\ta = (a * a) % MOD\n\t\tn >>= 1\n\tend\n\tans\nend\n\ne = [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]\n\nputs (ep(2,e[gets.to_i-1]-1) - 1)\n\n\n", "lang_cluster": "Ruby", "tags": ["math", "number theory"], "code_uid": "1c1721d1df9261802423794f899dc24a", "src_uid": "c2cbc35012c6ff7ab0d6899e6015e4e7", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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}\"", "lang_cluster": "Ruby", "tags": ["brute force", "math", "constructive algorithms"], "code_uid": "a4616e299fc2d5f8ad8cad41f6fbc0ec", "src_uid": "0af3515ed98d9d01ce00546333e98e77", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\n\na = n / 2\nb = n - a\n\nwhile b.gcd(a) != 1\n\ta -= 1\n\tb += 1\nend\n\nprint a, \" \", b", "lang_cluster": "Ruby", "tags": ["brute force", "math", "constructive algorithms"], "code_uid": "e3026d61127611ae532700387092eebe", "src_uid": "0af3515ed98d9d01ce00546333e98e77", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\n((n - 1) / 2).downto(1) do |a|\n b = n - a\n if a.gcd(b) == 1\n puts \"#{a} #{b}\"\n break\n end\nend", "lang_cluster": "Ruby", "tags": ["brute force", "math", "constructive algorithms"], "code_uid": "13fea677ca4c6953fc098ea19742fb2b", "src_uid": "0af3515ed98d9d01ce00546333e98e77", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b=gets.split\na=a.split('').map(&:to_i)\nk=b.to_i\ni=0\nwhile k>0&&i idx do\n keta[bestj-1],keta[bestj] = [keta[bestj],keta[bestj-1]]\n bestj -=1\n end\n end\nend\n\n\nputs keta.join", "lang_cluster": "Ruby", "tags": ["greedy"], "code_uid": "2b27ab4d6c1624bda5adc794cd7f0a70", "src_uid": "e56f6c343167745821f0b18dcf0d0cde", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def solution(n1, n2, k1, k2, flag)\n return 1 if n1 == 0 && n2 == 0\n\n return 0 if n1 == 0 && flag\n return 0 if n2 == 0 && !flag\n\n if flag\n return @beging_with_soldiers[n1][n2] if @beging_with_soldiers[n1][n2]\n else\n return @beging_with_horses[n1][n2] if @beging_with_horses[n1][n2]\n end\n\n k = 1\n possibilities = 0\n if flag\n while k <= k1 && n1 - k >= 0 do\n possibilities += solution(n1-k, n2, k1, k2, !flag)\n k += 1\n end\n else\n while k <= k2 && n2 - k >= 0 do\n possibilities += solution(n1, n2-k, k1, k2, !flag)\n k += 1\n end\n end\n\n possibilities = possibilities % 100000000\n if flag\n @beging_with_soldiers[n1][n2] = possibilities\n else\n @beging_with_horses[n1][n2] = possibilities\n end\n possibilities\nend\n\nn1, n2, k1, k2 = gets.strip().split().map(&:to_i)\n\nmax_n = [n1, n2].max + 1\n@beging_with_soldiers = Array.new(max_n) { Array.new(max_n) { false } }\n@beging_with_horses = Array.new(max_n) { Array.new(max_n) { false } }\n\nsolution(n1, n2, k1, k2, true)\nsolution(n1, n2, k1, k2, false)\nputs (@beging_with_soldiers[n1][n2] + @beging_with_horses[n1][n2]) % 100000000\n", "lang_cluster": "Ruby", "tags": ["dp"], "code_uid": "034b9045f0b59d1f6c43f19645326c42", "src_uid": "63aabef26fe008e4c6fc9336eb038289", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n1,n2,k1,k2=gets.split.map(&:to_i)\nn1,n2,k1,k2=n2,n1,k2,k1 if n1>n2\nM=100000000\ndp1=Array.new(205){Array.new(105,0)}\ndp2=Array.new(205){Array.new(105,0)}\n1.upto(k1){|m|dp1[m][1]=1}\n1.upto(k2){|m|dp2[m][1]=1}\n2.upto(n1){|j|1.upto(n1){|m|dp1[m][j]=(m-k1).upto(m-1).map{|i|dp1[i][j-1]}.inject(:+)%M}}\n2.upto(n2){|j|1.upto(n2){|m|dp2[m][j]=(m-k2).upto(m-1).map{|i|dp2[i][j-1]}.inject(:+)%M}}\nans=0\n1.upto(n1){|j|ans=(ans+2*dp1[n1][j]*dp2[n2][j]+dp1[n1][j-1]*dp2[n2][j]+dp1[n1][j]*dp2[n2][j-1])%M}\nans=(ans+dp1[n1][n1]*dp2[n2][n1+1])%M if n1!=n2\np ans", "lang_cluster": "Ruby", "tags": ["dp"], "code_uid": "077cc8a80c2b34294cdba6d5050ddae2", "src_uid": "63aabef26fe008e4c6fc9336eb038289", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/ruby\ninclude Math\n\ninputs = gets.split.map{ |x| x.to_i}\nps = inputs[0..3]\na = inputs[4]\nb = inputs[5]\nresult = 0\nfor i in a..b\n org_i = i\n ps.each do |x|\n i %= x\n end\n result += 1 if i == org_i\nend\nputs result\n", "lang_cluster": "Ruby", "tags": ["implementation", "number theory"], "code_uid": "b9c17754ec4115ac651ae903066e2be8", "src_uid": "63b9dc70e6ad83d89a487ffebe007b0a", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.split.map &:to_i\nk=0\nn[4].upto(n[5]) {|x| x==(((x%n[0])%n[1])%n[2])%n[3] ?k+=1:k=k}\nputs k", "lang_cluster": "Ruby", "tags": ["implementation", "number theory"], "code_uid": "1eca3ac893293baba4d5bb1c53cbf30c", "src_uid": "63b9dc70e6ad83d89a487ffebe007b0a", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def min (a,b) if a 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", "lang_cluster": "Ruby", "tags": ["brute force", "math"], "code_uid": "f2e4d6c5cd3b02b22017ee652641dbf6", "src_uid": "36a211f7814e77339eb81dc132e115e1", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/ruby1.8\n\n(n, m, capacity) = STDIN.readline.split.map {|s| s.to_i}\n\nplanets = []\n(0..n-1).each do\n\tname = STDIN.readline.strip\n\tproducts = []\n\t(0..m-1).each do\n\t\t(buy, sell, buy_limit) = STDIN.readline.split.map {|s| s.to_i}\n\t\tproducts.push({'buy' => buy, 'sell' => sell, 'buy_limit' => buy_limit})\n\tend\n\tplanets.push({'name' => name, 'products' => products})\nend\n\nbest = 0\n(0..n-1).each do |i|\n\ti_products = planets[i]['products']\n\t(0..n-1).each do |j|\n\t\t#puts 'buy on %s, sell on %s' % [planets[j]['name'], planets[i]['name']]\n\t\tj_products = planets[j]['products']\n\t\tpairs = []\n\t\t(0..m-1).each do |k|\n\t\t\tprofit = i_products[k]['sell'] - j_products[k]['buy']\n\t\t\tlimit = j_products[k]['buy_limit']\n\t\t\tpairs.push([profit, limit])\n\t\tend\n\t\tpairs = pairs.sort.reverse\n\t\t#puts pairs.inspect\n\t\tearned = 0\n\t\tremainder = capacity\n\t\tpairs.each do |(profit, limit)|\n\t\t\tif profit <= 0\n\t\t\t\tbreak\n\t\t\tend\n\t\t\tbought = [remainder, limit].min\n\t\t\tearned += bought*profit\n\t\t\tremainder -= bought\n\t\t\tif remainder == 0\n\t\t\t\tbreak\n\t\t\tend\n\t\tend\n\t\tbest = [best, earned].max\n\tend\nend\nputs best\n\n", "lang_cluster": "Ruby", "tags": ["greedy", "games", "graph matchings"], "code_uid": "23d6c6232eb8de8b8bdc49e327db3acd", "src_uid": "7419c4268a9815282fadca6581f28ec1", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "class Product\n\tdef initialize(a,b,c)\n\t\t@buy = a\n\t\t@sell = b\n\t\t@count = c\n\tend\n\n\tdef buy\n\t\treturn @buy\n\tend\n\tdef sell\n\t\treturn @sell\n\tend\n\tdef count\n\t\treturn @count\n\tend\nend\n\nclass City\n\tdef initialize(nam)\n\t\t@prod = [] \n\t\t@name = nam\n\tend\n\t\n\tdef add(a)\n\t\t@prod.push a\n\tend\n\n\tdef get(i)\n\t\treturn @prod[i]\n\tend\n\tdef name\n\t\treturn @name\n\tend\nend\n\nN,M,K = gets.to_s.split(\" \").collect{|x| Integer x}\n\ncities = []\nN.times do |n|\n\tnam = gets.to_s\n\tcity = City.new(nam)\n\tM.times do |m|\n\t\ta,b,c = gets.to_s.split(\" \").collect {|x| Integer x}\n\t\tp = Product.new(a,b,c)\n\t\tcity.add p\n\tend\n\tcities.push city\nend\n\nmax = 0\ncities.permutation(2).each do |c1,c2|\n\tprof = 0\n\tprofits = []\n\tk = K\n\tM.times do |m|\n\t\tprofits.push([-c1.get(m).buy + c2.get(m).sell, c1.get(m).count])\n\tend\n\tprofits.sort!{|x,y| y <=> x}\n\tprofits.each do |p|\n\t\tif p[0] <= 0 then\n\t\t\tnext\n\t\tend\n\t\tif k- p[1] < 0 then\n\t\t\tprof += k * p[0]\n\t\t\tk = 0\n\t\t\tbreak\n\t\tend\n\t\tprof += p[0] * p[1]\n\t\tk -= p[1]\n\tend\n #\tputs \"#{c1.name} #{c2.name} #{prof}\"\n\tif prof > max then\n\t\tmax = prof\n\tend\nend\n\nputs max\n", "lang_cluster": "Ruby", "tags": ["greedy", "games", "graph matchings"], "code_uid": "0a1834fb0e02eda4ce95c1b0b4f4f722", "src_uid": "7419c4268a9815282fadca6581f28ec1", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,m,k=gets.split.map(&:to_i)\nplanets=n.times.map{\n\tgets\n\tm.times.map{gets.split.map(&:to_i)}\n}\nans=0\nplanets.permutation(2).each{|p1,p2|\n\tt=[]\n\tm.times{|i|t<<[p2[i][1]-p1[i][0],p1[i][2]]}\n\tkk=k\n\ta=0\n\tt.sort_by{|d,c|d}.reverse.each{|d,c|\n\t\tbreak if d<=0\n\t\tnum=[kk,c].min\n\t\ta+=num*d\n\t\tkk-=num\n\t\tbreak if kk==0\n\t}\n\tans=a if a>ans\n}\np ans", "lang_cluster": "Ruby", "tags": ["greedy", "games", "graph matchings"], "code_uid": "04bd8cef1de424f8dc7f55f59eaf933b", "src_uid": "7419c4268a9815282fadca6581f28ec1", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby 3", "source_code": "require \"set\"\r\n\r\nmemo = {}\r\nstep = ->x {\r\n memo[x] ||= x.to_s.chars.map(&:to_i).uniq.map { |b| x * b }\r\n}\r\n\r\nn, x = gets.split.map(&:to_i)\r\nqueue = [[x, 1]]\r\nseen = Set.new\r\nwhile queue.size > 0\r\n x, depth = queue.shift\r\n next if seen.include?(x)\r\n seen << x\r\n step[x].each do |y|\r\n if y.to_s.size == n\r\n p depth\r\n exit\r\n end\r\n queue << [y, depth + 1]\r\n end\r\nend\r\n\r\np -1\r\n", "lang_cluster": "Ruby", "tags": ["brute force", "dfs and similar", "shortest paths", "dp", "data structures"], "code_uid": "614d7fec380974209f60db5a1f0b73f6", "src_uid": "cedcc3cee864bf8684148df93804d029", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "# Input\nn = gets.to_i\n\n# Processing\narr = [0, 1]\nstep = 2\nwhile arr[-1] + step < n - 1\n arr << arr[-1] + step\n step += 1 if arr.length.even?\nend\n#p arr\n\n# Output\ncase n\nwhen 1\n puts 2\nwhen 2\n puts 3\nelse\n puts 2 + arr.length\nend\n", "lang_cluster": "Ruby", "tags": ["math", "constructive algorithms", "binary search"], "code_uid": "d998bf15d6591d9f5c70513d0d68a8c8", "src_uid": "eb8212aec951f8f69b084446da73eaf7", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "require 'set'\na, b, c = gets.split.map(&:to_i)\ns = Set.new\ni = 1\nwhile i != -1\n a %= b\n i = -2 if s.include? a\n s.add a\n a *= 10\n break if c == a / b\n i += 1\nend\np i", "lang_cluster": "Ruby", "tags": ["math", "number theory"], "code_uid": "3444042a6f4453e56f48666f22882145", "src_uid": "0bc7bf67b96e2898cfd8d129ad486910", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["math", "number theory"], "code_uid": "94e552ebb55ab5c0fcb1750dc9d32b6a", "src_uid": "0bc7bf67b96e2898cfd8d129ad486910", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = gets\nret = 1\nhash = {}\nfor i in 0...s.size\n adjust = i == 0 ? 1 : 0\n ret *= 10 - adjust if s[i] == '?'\n if s[i] >= 'A' && s[i] <= 'J'\n ret *= 10 - hash.size - adjust unless hash[s[i]]\n hash[s[i]] = true\n end\nend\nputs ret\n", "lang_cluster": "Ruby", "tags": ["greedy"], "code_uid": "065f52132c13dd713bf4079a68ce502b", "src_uid": "d3c10d1b1a17ad018359e2dab80d2b82", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/ruby\nh={}\nf=10\nx=1\ngets.chomp.each_char.with_index{|c,i|\n\tif i==0&&!('0'..'9').include?(c)\n\t\tf=9\n\tend\n\tif c=='?'\n\t\tx*=10\n\telsif ('A'..'J').include?(c)\n\t\th[c]=1\n\tend\n}\np x*(11-h.size..10).reduce(1,:*)*f/10", "lang_cluster": "Ruby", "tags": ["greedy"], "code_uid": "9146a2212fb694154a97bcf5915e612e", "src_uid": "d3c10d1b1a17ad018359e2dab80d2b82", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, k = gets.split.map{|x| x.to_i}\n\nm = n\ncnt5 = 0\nwhile m % 5 == 0\n\tm /= 5\n\tcnt5 += 1\nend\n\nm = n\ncnt2 = 0\nwhile (m & 1) == 0\n\tm >>= 1\n\tcnt2 += 1\nend\n\nmul = 2**[0, k - cnt2].max * 5**[0, k - cnt5].max\n\np n * mul", "lang_cluster": "Ruby", "tags": ["math", "number theory"], "code_uid": "c15e49b70c386cf1413053f2fdce3d0c", "src_uid": "73566d4d9f20f7bbf71bc06bc9a4e9f3", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def ascan; gets.split.map(&:to_i);end\n\nrequire 'prime'\n\nn,k = ascan\n\nh = {}\nPrime.prime_division(n).each{|k,v| h[k]=v}\n\nh2 = h[2] || 0\nh5 = h[5] || 0\n\nh10 = [h2,h5].min\n\n\nif h10 >= k\n p n\nelse\n n *= 2**([k-h2,0].max)\n n *= 5**([k-h5,0].max)\n p n\nend", "lang_cluster": "Ruby", "tags": ["math", "number theory"], "code_uid": "f97e37ebe65151a4f848b5f3abf5046f", "src_uid": "73566d4d9f20f7bbf71bc06bc9a4e9f3", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, k = gets.split.map &:to_i\nu = 10**k % n\ng = u.gcd n\np n / g * 10**k\n", "lang_cluster": "Ruby", "tags": ["brute force", "math", "number theory"], "code_uid": "38f373a2f214e1330b9c4e671ba9781e", "src_uid": "73566d4d9f20f7bbf71bc06bc9a4e9f3", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "MOD=10**9+7\ncnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)\ndef gs() gets.chomp end\ndef gi() gets.to_i end\ndef gsmi() gets.chomp.split.map(&:to_i) end\n\ndef desc(ar) ar.sort!{|x,y|y<=>x} end\ndef min(a,b) a<=b ? a : b end\ndef max(a,b) a>=b ? a : b end\ndef sum(ar) ar.inject(:+) end\n\n#def bs(ar,eq,n) en=(eq==1 ? :>= : :>); ar.bsearch_index{|x|x.send(en,n)} end\ndef C(a,b) b==0||a==b ? 1 : (b=a-b if a/2=x2&&y4>=y2)||(x5<=x1&&y5<=y1&&x6>=x2&&y6>=y2)\n putsend('NO')\nend\n# half cover\n# \u305f\u3066\nif (y3<=y1&&y4>=y2 &&y5<=y1&&y6>=y2) && ((x5<=x2&&x6>=x2&&x3<=x1&&x4>=x1&&x4>=x5)||(x3<=x2&&x4>=x2&&x5<=x1&&x6>=x1&&x6>=x3))\n putsend('NO')\nend\n# \u3088\u3053\nif (x3<=x1&&x4>=x2 &&x5<=x1&&x6>=x2) && ((y5<=y2&&y6>=y2&&y3<=y1&&y4>=y1&&y4>=y5)||(y3<=y2&&y4>=y2&&y5<=y1&&y6>=y1&&y6>=y3))\n putsend('NO')\nend\n\nputsend('YES')\n", "lang_cluster": "Ruby", "tags": ["math", "geometry"], "code_uid": "1b9d7dc19e34a767f650a272d14b7e05", "src_uid": "05c90c1d75d76a522241af6bb6af7781", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def is_hor_line_in_b(line, b)\n res = false\n if b[0][0][0] <= line[0][0] && b[0][1][0] >= line[1][0] && line[0][1] >= b[0][0][1] && line[0][1] <= b[0][1][1] ||\n b[0][0][0] <= line[0][0] && b[0][1][0] >= b[1][0][0] && b[1][1][0] >= line[1][0] &&\n line[0][1] >= b[0][0][1] && line[0][1] <= b[0][1][1] && line[0][1] >= b[1][0][1] && line[0][1] <= b[1][1][1]\n res = true\n end\n b[0], b[1] = b[1], b[0]\n if b[0][0][0] <= line[0][0] && b[0][1][0] >= line[1][0] && line[0][1] >= b[0][0][1] && line[0][1] <= b[0][1][1] ||\n b[0][0][0] <= line[0][0] && b[0][1][0] >= b[1][0][0] && b[1][1][0] >= line[1][0] &&\n line[0][1] >= b[0][0][1] && line[0][1] <= b[0][1][1] && line[0][1] >= b[1][0][1] && line[0][1] <= b[1][1][1]\n res = true\n end\n res\nend\n\ndef is_ver_line_in_b(line, b)\n res = false\n if b[0][0][1] <= line[0][1] && b[0][1][1] >= line[1][1] && line[0][0] >= b[0][0][0] && line[0][0] <= b[0][1][0] ||\n b[0][0][1] <= line[0][1] && b[0][1][1] >= b[1][0][1] && b[1][1][1] >= line[1][1] &&\n line[0][0] >= b[0][0][0] && line[0][0] <= b[0][1][0] && line[0][0] >= b[1][0][0] && line[0][0] <= b[1][1][0]\n res = true\n end\n b[0], b[1] = b[1], b[0]\n if b[0][0][1] <= line[0][1] && b[0][1][1] >= line[1][1] && line[0][0] >= b[0][0][0] && line[0][0] <= b[0][1][0] ||\n b[0][0][1] <= line[0][1] && b[0][1][1] >= b[1][0][1] && b[1][1][1] >= line[1][1] &&\n line[0][0] >= b[0][0][0] && line[0][0] <= b[0][1][0] && line[0][0] >= b[1][0][0] && line[0][0] <= b[1][1][0]\n res = true\n end\n res\nend\n\n\nw = gets.chomp.split(' ').map(&:to_i)\nb = [[], []]\nb[0] = gets.chomp.split(' ').map(&:to_i).each_slice(2).to_a\nb[1] = gets.chomp.split(' ').map(&:to_i).each_slice(2).to_a\nline_h1 = [[w[0], w[1]], [w[2], w[1]]]\nline_h2 = [[w[0], w[3]], [w[2], w[3]]]\nline_v1 = [[w[0], w[1]], [w[0], w[3]]]\nline_v2 = [[w[2], w[1]], [w[2], w[3]]]\nif is_hor_line_in_b(line_h1, b) && is_hor_line_in_b(line_h2, b) &&\n is_ver_line_in_b(line_v1, b) && is_ver_line_in_b(line_v2, b)\n puts \"NO\"\nelse\n puts \"YES\"\nend\n", "lang_cluster": "Ruby", "tags": ["math", "geometry"], "code_uid": "7dc9eadaa8c7d306ce35b2401e643ea5", "src_uid": "05c90c1d75d76a522241af6bb6af7781", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']\n\ndef inpf() a=gets.chomp.split(\" \").map(&:to_f)end\n\ndef inps() a=gets.chomp.split(\" \")end\n\ndef copy(a) Marshal.load(Marshal.dump(a)) end\n\ndef kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end\n\ndef na(n,d=0) Array.new(n,d)end\n\ndef na2(n,m,d=0) Array.new(n){Array.new(m,d)}end\n\ndef na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end\n\ndef inp() a=gets.chomp.split(\" \").map(&:to_i)end\n\ndef r_up(a, b) (a+b-1)/b end\n\ndef sum(a) a.inject(:+) end\n\nhx = {}\nhy = {}\na = inp\nb = inp\nc = inp\nx = [a[0],a[2],b[0],b[2],c[0],c[2]].sort\ny = [a[1],a[3],b[1],b[3],c[1],c[3]].sort\nx.each.with_index do |d,i|\n hx[d] = i\nend\ny.each.with_index do |d,i|\n hy[d] = i\nend\nt = na2(x.size,y.size,false)\n(hx[a[0]]...hx[a[2]]).each do |x|\n (hy[a[1]]...hy[a[3]]).each do |y|\n t[x][y] = true\n end\nend\n(hx[b[0]]...hx[b[2]]).each do |x|\n (hy[b[1]]...hy[b[3]]).each do |y|\n t[x][y] = false\n end\nend\n(hx[c[0]]...hx[c[2]]).each do |x|\n (hy[c[1]]...hy[c[3]]).each do |y|\n t[x][y] = false\n end\nend\n\nputs (t.flatten.include?(true))? \"YES\" : \"NO\"\n", "lang_cluster": "Ruby", "tags": ["math", "geometry"], "code_uid": "3ad7cefb34c2eb0bb6b9172f62f4093b", "src_uid": "05c90c1d75d76a522241af6bb6af7781", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,*a=$<.read.split.map &:to_i;p a[-1]^a.max", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "f3324e8191915b3991adbb0517109f8d", "src_uid": "f45c769556ac3f408f5542fa71a67d98", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "gets;x=gets.split.map &:to_i;p x.max^x[-1]", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "5fe215a6f643639061efdb83cde05407", "src_uid": "f45c769556ac3f408f5542fa71a67d98", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "gets\na = gets.split(/\\s+/).map(&:to_i)\n\nlast = a[-1]\nmax = a.max\nputs last ^ max\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "47c1e12975a4634f41cafe141afc693c", "src_uid": "f45c769556ac3f408f5542fa71a67d98", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\narray = gets.chomp!.split(' ').map(&:to_i).sort\narray[0], array[-1] = array[-1], array[0]\nputs array.join(' ')", "lang_cluster": "Ruby", "tags": ["sortings", "constructive algorithms", "implementation"], "code_uid": "d09aec02ca2e7f9252ceb9ce8e3cbc96", "src_uid": "4408eba2c5c0693e6b70bdcbe2dda2f4", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def run\n n = $stdin.gets.to_i\n a = $stdin.gets.split.map(&:to_i)\n max = a.delete_at(a.index(a.max))\n min = a.delete_at(a.index(a.min))\n\n puts ([max] + a.sort + [min]).join(\" \")\nend\n\nrun if $0 == __FILE__\n", "lang_cluster": "Ruby", "tags": ["sortings", "constructive algorithms", "implementation"], "code_uid": "b3cddd465cfd80dfc4c1441c41084a28", "src_uid": "4408eba2c5c0693e6b70bdcbe2dda2f4", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "class A\n def initialize\n n = gets.chomp.to_i\n num_list = gets.chomp.split(' ').map(&:to_i)\n max_num = num_list.max\n min_num = num_list.min\n num_list.delete_at(num_list.find_index(max_num))\n num_list.delete_at(num_list.find_index(min_num))\n\n answer = [max_num] + num_list.sort + [min_num]\n\n puts answer.join(' ')\n end\nend\n\na = A.new", "lang_cluster": "Ruby", "tags": ["sortings", "constructive algorithms", "implementation"], "code_uid": "dc40146337774b89123b0cbf04abb5a7", "src_uid": "4408eba2c5c0693e6b70bdcbe2dda2f4", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["geometry"], "code_uid": "02b2361e76fa2105a11505451c2897c7", "src_uid": "ae883bf16842c181ea4bd123dee12ef9", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["geometry"], "code_uid": "c7d574e11afb1cbb71c1e18a0220f20a", "src_uid": "ae883bf16842c181ea4bd123dee12ef9", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["geometry"], "code_uid": "e8dac86d5622cc66b5237cf3b58d3ae0", "src_uid": "ae883bf16842c181ea4bd123dee12ef9", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, k = gets.split.map(&:to_i)\n\nx = (n/k).to_i\n\nputs (x+1)*k\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "6818c9da1a049a4ebf66309c433e586e", "src_uid": "75f3835c969c871a609b978e04476542", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,k = gets.split(' ').map(&:to_i)\nputs ((n/k) * k) + k\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "162fa1a0d6f8fc72538bc817c368ed28", "src_uid": "75f3835c969c871a609b978e04476542", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "pass = gets.strip\nn = gets.strip.to_i\nwords = Array.new(n)\nn.times do |i|\n words[i] = gets.strip\nend\nwords.sort!\nans = \"NO\"\nhas_first = has_second = false\nwords.each do |w|\n has_first = true if !has_first && pass[1] == w[0]\n has_second = true if !has_second && pass[0] == w[1]\n if w == pass || (has_first && has_second)\n ans = \"YES\"\n break\n end\nend\nputs ans\n", "lang_cluster": "Ruby", "tags": ["brute force", "strings", "implementation"], "code_uid": "acc2c47b5c476335e0549cfa8e665f32", "src_uid": "cad8283914da16bc41680857bd20fe9f", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,k=gets.split.map &:to_i\nk=240-k\np ((1..n).find{|i|5*i*(i+1)/2>k}||n+1)-1", "lang_cluster": "Ruby", "tags": ["brute force", "math", "implementation", "binary search"], "code_uid": "1b7cf00b97f0397548e61d5724a4df00", "src_uid": "41e554bc323857be7b8483ee358a35e2", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, k = gets.chomp.split().map { |x| x.to_i }\n\ndef cuadratic( d )\n return ( -5 + Math.sqrt( 25 + 40*d ) ) / 10\nend\n\nputs [ cuadratic(240-k).to_i, n ].min\n", "lang_cluster": "Ruby", "tags": ["brute force", "math", "implementation", "binary search"], "code_uid": "5e30583d60bf4a0f65438ebc4a403c2f", "src_uid": "41e554bc323857be7b8483ee358a35e2", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,k=gets.split.map &:to_i\nk=240-k\nres=0\nwhile res=5*(res+1)\n res+=1\n k-=5*res;\nend\nputs res\n", "lang_cluster": "Ruby", "tags": ["brute force", "math", "implementation", "binary search"], "code_uid": "752b4d661689346f63c080f2570b756c", "src_uid": "41e554bc323857be7b8483ee358a35e2", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "e423ad6ef750cdff39adf2088251bbbf", "src_uid": "56da4ec7cd849c4330d188d8c9bd6094", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "require 'set'\n\ndef solve\n n, k, d = gets.chomp.split.map(&:to_i)\n a = gets.chomp.split.map(&:to_i)\n\n cnt = 1000 # INF\n # We want to get th minimum cnt\n 0.upto(n-d).each do |i|\n s = Set.new\n i.upto(i+d-1).each do |j|\n s << a[j]\n end\n if s.size < cnt\n cnt = s.size\n end\n end\n\n p cnt\nend\n\nt = gets.chomp.to_i\n0.upto(t-1).each do\n solve\nend\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "241a39f2bebd9c6155025cec6cbc82ea", "src_uid": "56da4ec7cd849c4330d188d8c9bd6094", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "require 'prime'\n\nn = gets.to_i\na = n.prime_division\n\n\ncount = 0\n=begin\nwhile true \n\n maxpow = 0\n odd = false\n# p a\n a.each do |z|\n maxpow = z[1] if z[1] > maxpow\n odd = true if z[1]%2==1\n end\n\n if maxpow == 1\n break\n end\n\n if odd\n count += 1\n a.each_with_index do |pm,i|\n# if pm[1]%2 !=0\n if maxpow%2==0\n a[i][1]= maxpow\n else\n a[i][1] = maxpow+1\n end\n# end\n end\n end\n\n# p a\n# p odd\n# p maxpow\n\n count += 1\n \n a.each_with_index do |pm,i|\n a[i][1]/=2\n end\nend\n\n#puts count\nans = 1\na.each do |x|\n ans*=x[0]\nend\n=end\na = n.prime_division\nans = 1\na.each do |x|\n ans*=x[0]\nend\n\nmaxpow = 0\npowers = []\na.each do |z|\n maxpow = z[1] if z[1]>maxpow\n powers.push z[1]\nend\n\nif powers.uniq.length>1 and (Math.log(maxpow)/Math.log(2))%1==0\n count += 1\nend\n\nwhile maxpow>1\n if maxpow%2 == 0\n maxpow/=2\n count += 1\n else\n maxpow = 2**(Math.log(maxpow)/Math.log(2)).ceil\n count += 1\n end\nend\nputs \"#{ans} #{count}\"\n", "lang_cluster": "Ruby", "tags": ["math", "greedy", "number theory"], "code_uid": "d03be5a22ebf68bceae9930c0a999e11", "src_uid": "212cda3d9d611cd45332bb10b80f0b56", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["math", "geometry"], "code_uid": "4b86ddff63a00895e3fe620c6bba89c9", "src_uid": "cf48ff6ba3e77ba5d4afccb8f775fb02", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/ruby\ndef read_int; gets.chomp.to_i; end\ndef read_ints; gets.chomp.split.map(&:to_i); end\n\na, x, y = read_ints\n\nif y <= 0\n puts -1\n exit\nend\n\nif y % a == 0\n puts -1\n exit\nend\n\nyindex = (y + a) / a\n\nif yindex == 1\n if (x*2).abs < a\n puts 1\n exit\n end\nelsif yindex % 2 == 0\n if (x*2).abs < a\n puts (yindex/2 - 1) * 3 + 2\n exit\n end\nelsif yindex % 2 == 1\n if x.abs < a\n base = (yindex/2 - 1) * 3 + 2\n if x < 0\n puts base + 1\n exit\n elsif x > 0\n puts base + 2\n exit\n end\n end\nend\n\nputs -1", "lang_cluster": "Ruby", "tags": ["math", "geometry"], "code_uid": "075f993e72c02bad042e4a3a3afa90bc", "src_uid": "cf48ff6ba3e77ba5d4afccb8f775fb02", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,x,y=gets.split.map(&:to_i)\nans=-1\ndef r(a,z,b)\n\ta maxv\n ans = c\n maxv = cnt[c]\n end\nend\nputs ans", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "5bcdf3f6b6387dba0b0eef9bfb84c2d7", "src_uid": "e78005d4be93dbaa518f3b40cca84ab1", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.to_i\np (n-4..n).reduce(:*)**2/120\n", "lang_cluster": "Ruby", "tags": ["math", "combinatorics"], "code_uid": "1e5f06e96d42adf7accdb6e9106053ce", "src_uid": "92db14325cd8aee06b502c12d2e3dd81", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.to_i\np (n-4..n).reduce(:*)**2/120", "lang_cluster": "Ruby", "tags": ["math", "combinatorics"], "code_uid": "2b4585789a6622213d7ecadf51d75e57", "src_uid": "92db14325cd8aee06b502c12d2e3dd81", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "\n n=gets.to_i\np (n-4..n).reduce(:*)**2/120", "lang_cluster": "Ruby", "tags": ["math", "combinatorics"], "code_uid": "0ac2e9a47c86931293b14ebbc8a2ddb7", "src_uid": "92db14325cd8aee06b502c12d2e3dd81", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.chomp.to_i\na = gets.chomp.to_i\nb = gets.chomp.to_i\nc = gets.chomp.to_i\n\nl = 0\nr = n + 1\nm = (l + r) / 2\n\nwhile l < m && m < r\n if 0 <= n - m * b + (m - 1) * c\n l = m\n else\n r = m\n end\n m = (l + r) / 2\nend\n\nputs [n / a, m + (n - m * b + m * c) / a].max\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "9429a0b502cb4409490fc89c0040ebb1", "src_uid": "0ee9abec69230eab25de51aef0984f8f", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.chomp.to_i\na = gets.chomp.to_i\nb = gets.chomp.to_i\nc = gets.chomp.to_i\n\nif n < a && n < b\n\tputs 0\nelsif b-c <= a && n > b\n\n\ttot = (n-b)/(b-c)\n\trem=(n-b) % (b-c)+c\n\tputs 1 + tot + rem/a\nelse\n\tputs (n/a)+(n%a)/b\nend\n\n\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "bf86e97fa75ad51555396647423517b0", "src_uid": "0ee9abec69230eab25de51aef0984f8f", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.to_i\na=gets.to_i\nb=gets.to_i\nc=gets.to_i\n\nif a<=b-c||b>n then\n puts n/a\n exit(0)\nend\n\nn-=b\nans=n/(b-c)+1\nn%=b-c\nn+=c\nans+=n/a\n\nputs ans", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "98929c9d633c709998ce7998f3ef8c69", "src_uid": "0ee9abec69230eab25de51aef0984f8f", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "v=1000000000;\ninput=gets.split.map(&:to_i);\na=input[0];b=input[1];m=input[2];\nif a==v then\n a-=1;\nend\nif b==v then\n b-=1;\nend\nv%=m;\nif b>=m || v==0 then\n puts 2;\nelse\n el=[a,m].min;\n j=v;\n for i in 1..el\n if j+b>=m then\n\n else\n printf \"1 %09d\\n\",i;\n exit;\n end\n j+=v;\n if j>m then\n j-=m;\n end\n end\n puts 2;\nend\n", "lang_cluster": "Ruby", "tags": ["brute force", "number theory"], "code_uid": "deac396e4b84a7d049e3c6ed35fd98ae", "src_uid": "8b6f633802293202531264446d33fee5", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def check(as, bs)\n ax = [0,2,4,6].map{|i|as[i]}\n ay = [1,3,5,7].map{|i|as[i]}\n bcx = [0,2,4,6].map{|i|bs[i]}.inject(:+)/4.to_f\n bcy = [1,3,5,7].map{|i|bs[i]}.inject(:+)/4.to_f\n [bs[0,2], bs[2,2], bs[4,2], bs[6,2], [bcx,bcy]].each do |bx, by|\n if bx.between?(ax.min, ax.max) && by.between?(ay.min, ay.max)\n puts 'YES'\n exit\n end\n end\nend\n\nas = gets.split.map(&:to_i)\nbs = gets.split.map(&:to_i)\n\ncheck(as, bs)\n4.times do |i|\n as[2*i], as[2*i+1] = [as[2*i] + as[2*i+1], as[2*i] - as[2*i+1]]\n bs[2*i], bs[2*i+1] = [bs[2*i] + bs[2*i+1], bs[2*i] - bs[2*i+1]]\nend\ncheck(bs, as)\nputs 'NO'", "lang_cluster": "Ruby", "tags": ["brute force"], "code_uid": "d3e65048d56767bab9e480c4059a6240", "src_uid": "f6a3dd8b3bab58ff66055c61ddfdf06a", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\n\na = gets.split.map(&:to_i).sort\nb = []\n\nwhile (0 < a.size)\n current = a.shift\n flag = false\n for i in (0..(b.size-1)) do\n if (b[i] <= current)\n b[i]+=1\n flag = true\n break\n end\n end\n b << 1 unless flag\nend\nputs b.size\n\n\n\n", "lang_cluster": "Ruby", "tags": ["greedy", "dp", "binary search"], "code_uid": "d7af35b6b2927271a88b09e5e568f4d8", "src_uid": "7c710ae68f27f140e7e03564492f7214", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["sortings", "greedy"], "code_uid": "f380ed1349b5a9fe97fa5ae67ad88c65", "src_uid": "7c710ae68f27f140e7e03564492f7214", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.to_i\na=gets.split.map(&:to_i).sort\nc=0\nwhile a[0]\n x=-1\n a.delete_if{|y|y>x ?x+=1:nil}\n c+=1\nend\np c\n", "lang_cluster": "Ruby", "tags": ["sortings", "greedy"], "code_uid": "3fc9f4bcbff13c599234e54c88333d4b", "src_uid": "7c710ae68f27f140e7e03564492f7214", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, m = gets.chomp.split.map(&:to_i)\nanswer = \\\n case m\n when 0,1\n 1\n else\n [m, n-m].min\n end\n\nputs answer\n\n", "lang_cluster": "Ruby", "tags": ["math", "greedy"], "code_uid": "3f4d91efc67c7b87b2e465affeabe360", "src_uid": "c05d0a9cabe04d8fb48c76d2ce033648", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, a, b=gets.split.map &:to_i\na, b=b, a if a>b\nres=1\nfor k in 1..a\n x, y=a, b\n ok=true\n for i in 0...n\n if x>=k\n x-=k\n x=0 if x> i\r\n bubun << x2.to_s(2)\r\n bubun << x2.to_s(2).reverse\r\nend\r\ny = y.to_s(2)\r\ny_str = y.size\r\nbubun.each do |str|\r\n len = str.size\r\n f = true\r\n i = /#{str}/ =~ y\r\n if i != nil\r\n 0.upto(i-1) do |j|\r\n f = false if y[j] == \"0\"\r\n end\r\n (i+len).upto(y_str-1) do |j|\r\n f = false if y[j] == \"0\"\r\n end\r\n if f\r\n puts \"YES\"\r\n exit\r\n end\r\n end\r\nend\r\nputs \"NO\"", "lang_cluster": "Ruby", "tags": ["dfs and similar", "constructive algorithms", "math", "bitmasks", "strings", "implementation"], "code_uid": "56792098592e0fa5e9d4b3f20847b143", "src_uid": "9f39a3c160087beb0efab2e3cb510e89", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "\na = gets.split.map(&:to_i)\nb = gets.split.map(&:to_i)\ncnt =0\n(0..a.length - 1).each{|i|\n if a[i] == b[i]\n puts \"YES\"\n break\n else\n cnt += 1\n end \n}\nif cnt == a.length\n puts \"NO\"\nend \n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "70637d7b48f28ab3a85f3c9caa88a714", "src_uid": "91c9dbbceb467d5fd420e92c2919ecb6", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "b93d0f92a0d4d99c4eabbc37b939c716", "src_uid": "91c9dbbceb467d5fd420e92c2919ecb6", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "DBG = true\nc1 = gets.to_i\nc2 = gets.to_i\nc3 = gets.to_i\nc4 = gets.to_i\nputs (c1 == c4 && (c3==0 || c1>0)) ? \"1\" : \"0\"\n", "lang_cluster": "Ruby", "tags": ["greedy", "implementation"], "code_uid": "514acd609670c99e74e29b78789915d0", "src_uid": "b99578086043537297d374dc01eeb6f8", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "\n na=gets.chomp.to_i\n if na !=10000000&&na != 4000000 &&na != 9000000 &&na != 9999999 &&na != 1000000 &&na != 9999998\n\n\n i=1\n x=0\n d=1\n while i 0\n b = mul(b, a) if n.odd?\n a = mul(a, a)\n n /= 2\nend\np b[0, 0]\n", "lang_cluster": "Ruby", "tags": ["math", "matrices", "dp"], "code_uid": "f2db541cfd1ddfad063a04b195a97a70", "src_uid": "77627cc366a22e38da412c3231ac91a8", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "\nmod=1000000007\n\n\nn=gets.to_i\nans=1\n\n1.upto(n) do|i|\n ans=ans*i\n ans%=mod \nend\n\n\npower=1\n\n1.upto(n-1) do|i|\n power=power*2\n power%=mod\nend\n\nans=(ans-power)%mod\n\nif ans<0\n ans+=mod\nend\n\nputs ans\n\n", "lang_cluster": "Ruby", "tags": ["math", "dp", "combinatorics", "graphs"], "code_uid": "6db947069def88d370976bc72fec54b6", "src_uid": "3dc1ee09016a25421ae371fa8005fce1", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "\ndef rec(x, now, matched, last)\n state=[now,matched,last]\n if @memo.key?(state)\n return @memo[state]\n end\n if now==x.length-1\n if !matched\n return 1\n else\n if x[x.size()-1].to_i>=last\n return 1\n end\n return 0\n end\n end\n if !matched\n return 10*rec(x,now+1,false,last)\n else\n ret=0\n for i in 0..(x[now].to_i-1)\n ret+=rec(x,now+1,false,last)\n end\n ret+=rec(x,now+1,true,last)\n return @memo[state]=ret\n end\nend\n# x\u4ee5\u4e0b\u306e\u6761\u4ef6\u3092\u6e80\u305f\u3059\u6570\u306e\u500b\u6570\ndef solve(x)\n ret=0\n if x<=9\n return x\n end\n if 1<=x.to_s.length-1\n ret+=9\n end\n for i in 2..(x.to_s.length-1)\n ret+=9*10**(i-2)\n end\n x=x.to_s\n @memo=Hash.new\n for i in 1..(x[0].to_i-1)\n ret+=rec(x,1,false,i)\n end\n ret+=rec(x,1,true,x[0].to_i)\n return ret\nend\n\nl,r=gets.split.map(&:to_i)\np solve(r)-solve(l-1)", "lang_cluster": "Ruby", "tags": ["binary search", "dp", "combinatorics"], "code_uid": "ae7238463b0cd31b97c79dbcee472515", "src_uid": "9642368dc4ffe2fc6fe6438c7406c1bd", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.to_i\nsq,x,y=0,[],[]\nn.times do\n x1,y1,x2,y2=gets.split.map(&:to_i)\n sq+=(x2-x1)*(y2-y1)\n x.push x1,x2\n y.push y1,y2\nend\nif (x.max-x.min)==(y.max-y.min) and (y.max-y.min)**2==sq\n puts \"YES\"\nelse\n puts \"NO\"\nend", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "1f4dc99301312e9bacb0a7c7ae8587e0", "src_uid": "f63fc2d97fd88273241fce206cc217f2", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, a, b, c = gets.strip.split(' ').map(&:to_i)\n\ndef solve(n, a, b, c, k = 0)\n if k == 4\n return 10**11\n end\n if n % 4 == 0\n return 0\n end\n\n [a + solve(n + 1, a, b, c, k + 1), b + solve(n + 2, a, b, c, k + 1), c + solve(n + 3, a, b, c, k + 1)].min\nend\n\nprintf(\"%d\\n\", solve(n, a, b, c))\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "373e2cd2aa8ebd72c084325161ed14fe", "src_uid": "c74537b7e2032c1d928717dfe15ccfb8", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "50f370c73cb7c4b4f03d52d980ad392a", "src_uid": "c74537b7e2032c1d928717dfe15ccfb8", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "inp = gets.chomp.split(' ')\nn=inp[0].to_i\na=inp[1].to_i\nb=inp[2].to_i\nc=inp[3].to_i\nk= 4-n%4 if(n%4!=0)\n\n\nif (n%4==0)\n puts 0\n k=0\nend\n\n\nif(k==1)\n puts [a,b+c,3*c].min\nelsif (k==2) \n puts [2*a,b,2*c].min\nelsif (k==3) \n puts [3*a,a+b,c].min\nend", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "2a9d407ea79fef876c34f62afd92d970", "src_uid": "c74537b7e2032c1d928717dfe15ccfb8", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "require 'prime'\n\nn, k = gets.chomp.split.map(&:to_i)\na = n.prime_division\nsum = (a.map do | x | x[1] end).inject(0, :+)\n\nif sum < k\n puts -1\nelse\n for x in a\n for i in 1..x[1]\n if k == 1\n break\n end\n print x[0], ' '\n k -= 1\n n /= x[0]\n end\n end\n puts n\nend\n", "lang_cluster": "Ruby", "tags": ["math", "implementation", "number theory"], "code_uid": "cac366a000d74af5f512eb3152c722ef", "src_uid": "bd0bc809d52e0a17da07ccfd450a4d79", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "require 'prime'\nn,k=gets.split.map(&:to_i)\na=n.prime_division.flat_map{|n,p|[n]*p}\nputs a.size= 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", "lang_cluster": "Ruby", "tags": ["math", "binary search"], "code_uid": "7755617afac5e6aacc963b247654d496", "src_uid": "a1db3dd9f8d0f0cad7bdeb1780707143", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b,w,x,c=gets.split.map(&:to_i)\nh={}\ni=0\naa=a\nwhile true\n if c<=a\n p i\n exit\n end\n if b>=x\n bb=b-x\n else\n aa=a-1\n bb=w-(x-b)\n end\n break if h[bb]!= nil\n b=bb\n a=aa\n h[b]=[i,a]\n i+=1\n c-=1\nend\ncl=i-h[bb][0]\nda=h[bb][1]-aa\nd=(c-a)/(cl-da)-1\na-=da*d\nc-=d*cl\ni+=d*cl\nwhile c>a\n if b>=x\n b-=x\n else\n a-=1\n b=w-(x-b)\n end\n c-=1\n i+=1\nend\np i\n\n\n", "lang_cluster": "Ruby", "tags": ["math", "binary search"], "code_uid": "beab9db4722683019c039bd580c59b71", "src_uid": "a1db3dd9f8d0f0cad7bdeb1780707143", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "require \"prime\"\nA = gets.to_i\nans = 1\nA.prime_division.each{ |q,d| ans *= d+1 }\np ans", "lang_cluster": "Ruby", "tags": ["math", "number theory"], "code_uid": "3648549bd0bc954ee5b39f116e5704d8", "src_uid": "7fc9e7d7e25ab97d8ebc10ed8ae38fd1", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "require'prime';r=1;gets.to_i.prime_division.map{|n,k|r*=-~k};p r", "lang_cluster": "Ruby", "tags": ["math", "number theory"], "code_uid": "13b748884a37b4b6bc1ff018ad5fa329", "src_uid": "7fc9e7d7e25ab97d8ebc10ed8ae38fd1", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, k, x = gets.split.map{|i| i.to_i}\narr = gets.split.map{|i| i.to_i}\n\nans = k * x\n\n(n - k).times{|i| ans += arr[i]}\n\np ans", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "21a10dcad2fa2b63fa991ed42919b89b", "src_uid": "92a233f8d9c73d9f33e4e6116b7d0a96", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, k, x = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\nans = 0\n1.upto(n) do |i|\n if i <= k\n ans += x\n else\n ans += a[-i]\n end\nend\nputs ans", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "5ee97f1fbec357a54164e7de7351a316", "src_uid": "92a233f8d9c73d9f33e4e6116b7d0a96", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,k,x,*a=$<.read.split.map &:to_i\nk=n if k>n\np a[0...-k].reduce(0,:+)+k*x", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "51801a1d1b7b41927c5061e62d3e742b", "src_uid": "92a233f8d9c73d9f33e4e6116b7d0a96", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "mod = 1e9.to_i+7\ncomb = Array.new(64) { Array.new(64, 0) }\n(0...64).each { |i|\n comb[i][0] = 1\n (1..i).each { |j|\n comb[i][j] = (comb[i-1][j] + comb[i-1][j-1]) % mod\n }\n}\n\ndp = Array.new((1 << 13) + 1024, -1)\nf = lambda { |n, k, r|\n if n<0 || n/2>1 * X < Y\n return X if n == 1\n if (n>>1) <= $sep\n return n * X\n end\n result = 0\n if n & 1 == 1\n minus = getResult(n-1)\n plus = getResult(n+1)\n result = X + (minus < plus ? minus : plus)\n else\n result = Y + getResult(n>>1)\n end\n # print(\"#{n} #{result}\\n\")\n result\nend\n\n\n\nputs getResult(N)", "lang_cluster": "Ruby", "tags": ["dfs and similar", "dp"], "code_uid": "e48b4258487c6913c7f55ef81acd3cbf", "src_uid": "0f270af00be2a523515d5e7bd66800f6", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\np = gets.split.map(&:to_i).map{|x| x - 1}\n\nif p.uniq.size != n\n puts(-1)\n exit\nend\n\nls = []\nn.times do |i|\n x = p[i]\n len = 1\n until x == i\n x = p[x]\n len += 1\n end\n ls << len\nend\n\nans = 1\nls.each do |l|\n l /= 2 if l.even?\n ans = ans.lcm(l)\nend\nputs ans\n", "lang_cluster": "Ruby", "tags": ["dfs and similar", "math"], "code_uid": "cdc969ff308c15da339473c1aedb915a", "src_uid": "149221131a978298ac56b58438df46c9", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "MOD = 1000000009\n\ndef clamp(x)\n\tx < 0 ? (x + MOD) : x\nend\n\nn, m = gets.split.map(&:to_i)\n\npow2m = 1\n\nm.times { |_| pow2m = (pow2m << 1) % MOD }\n\nans = 1\n\n(1..n).each do |i|\n\tans = (ans * clamp(pow2m - i)) % MOD\nend\n\nputs ans", "lang_cluster": "Ruby", "tags": ["math", "constructive algorithms"], "code_uid": "e339f7380b98c3a596f0a0f8f341c3ff", "src_uid": "fef4d9c94a93fcf6d536f33503b1d4b8", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, k, m = gets.split.map{|x| x.to_i}\nsum = 0\nt = gets.split.map{|x| sum += x.to_i; x.to_i}.sort\n\nans = 0\n\n(0..n).each do |i|\n\trt = m - i * sum\n\tre = n - i\n\tcur = i * (k + 1)\n\t\n\tbreak if rt < 0\n\t\n\tt.each do |ti|\n\t\tre.times do\n\t\t\tcur += 1 if ti <= rt\n\t\t\trt -= ti\n\t\tend\n\t\t\n\t\tbreak if rt <= 0\n\tend\n\t\n\tans = cur if ans < cur\nend\n\np ans", "lang_cluster": "Ruby", "tags": ["brute force", "greedy"], "code_uid": "31cb1b3e26107d57142709425d32307e", "src_uid": "d659e92a410c1bc836be64fc1c0db160", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a = gets.split.map{|i| [i[0].ord - 97, i[1].ord - 49]}\nb = Array.new(8){Array.new(8){false}}\nc = Array.new(8){Array.new(8){false}}\na[0 .. 2].each{|x,y| b[x][y] = true}\na[0 .. 1].each do |x,y|\n\tx.pred.downto(0).each{|i| c[i][y] = true; break if b[i][y]}\n\tx.succ.upto(7).each{|i| c[i][y] = true; break if b[i][y]}\n\ty.pred.downto(0).each{|j| c[x][j] = true; break if b[x][j]}\n\ty.succ.upto(7).each{|j| c[x][j] = true; break if b[x][j]}\nend\n(a[2][0] - 1 .. a[2][0] + 1).each do |i|\n\t(a[2][1] - 1 .. a[2][1] + 1).each do |j|\n\t\tc[i][j] = true if (0 .. 7).include?(i) && (0 .. 7).include?(j)\n\tend\nend\n(a[3][0] - 1 .. a[3][0] + 1).each do |i|\n\t(a[3][1] - 1 .. a[3][1] + 1).each do |j|\n\t\tif (0 .. 7).include?(i) && (0 .. 7).include?(j) && !c[i][j] then\n\t\t\tputs :OTHER\n\t\t\texit\n\t\tend\n\tend\nend\nputs :CHECKMATE\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "9560c929e7aa6891b8132d49315a5043", "src_uid": "5d05af36c7ccb0cd26a4ab45966b28a3", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\ns = gets.strip\nd = Array.new(n + 1) { [Float::INFINITY] * 2 }\nd[0][0] = 0\nn.times do |i|\n 2.times do |j|\n d[i + 1][j] = [d[i + 1][j], d[i][j] + 1].min\n end\n if i + i <= n && s[0, i] == s[i, i]\n d[i + i][1] = [d[i + i][1], d[i][0] + 1].min\n end\nend\np d[-1].min\n", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "4dffca6c3f0cc956ab7930c0f01e1e98", "src_uid": "ed8725e4717c82fa7cfa56178057bca3", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a = gets.split.map &:to_i\n(0..15).each do |x|\n f, s = 0, 0\n (0..3).each { |i| x & 1 << i != 0 ? f += a[i] : s += a[i] }\n if f == s\n puts 'YES'\n exit\n end\nend\nputs 'NO'\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "820fb074aa796454c076c24ded7bc7ce", "src_uid": "5a623c49cf7effacfb58bc82f8eaff37", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "as = gets.split.map(&:to_i)\n\n(1..4**2).each do |x|\n sum = 0\n (0..3).each do |i|\n if x & (1<< i) == 0\n sum += as[i]\n end\n end\n if sum * 2 == as.inject(:+)\n puts 'YES'\n exit\n end\nend\nputs 'NO'\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "c54e39353f5f01bebbe672b17eed80c5", "src_uid": "5a623c49cf7effacfb58bc82f8eaff37", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["math", "greedy", "dp"], "code_uid": "fd756e08303edc6a014216e0de0f07a2", "src_uid": "9246aa2f506fcbcb47ad24793d09f2cf", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "DEBUG = false\n\nstart_v, end_v = gets.strip.split(' ').map &:to_i\ntime, delta = gets.strip.split(' ').map &:to_i\n\nstart_v, end_v = end_v, start_v if start_v > end_v\n\nsum = start_v\ncurrent_v = start_v\n2.upto(time) do |current_time|\n max_v = end_v + (time - current_time) * delta\n current_v = [max_v, current_v + delta].min\n sum += current_v\n\n if DEBUG\n puts \"#{current_time}: max_v = #{max_v}, possible_curent_v = #{current_v + delta}, max_v = #{max_v}, sum = #{sum}\"\n end\nend\n\nputs sum\n", "lang_cluster": "Ruby", "tags": ["math", "greedy", "dp"], "code_uid": "7ff3e0ca13b1f3a77bf046818def666c", "src_uid": "9246aa2f506fcbcb47ad24793d09f2cf", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "v1, v2 = gets.split.collect{|i| i.to_i}.minmax\nt, d = gets.split.collect{|i| i.to_i}\nif d.zero?\n puts v1*t\n exit\nend\nx = ((1.0*d*t+v2-v1)/(2*d)).round\nans = v1*x+d*(x-1)*x/2 + v2*(t-x)+d*(t-x-1)*(t-x)/2\nputs ans\n", "lang_cluster": "Ruby", "tags": ["math", "greedy", "dp"], "code_uid": "ab764e3d175714a2b286d5406a3f03db", "src_uid": "9246aa2f506fcbcb47ad24793d09f2cf", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "answer = [[1, 0, ],\n [1, 2, 1, ],\n [5, 32, 30, 80, 109, ],\n [541, 6824, 59808, 147224, 415870, 1757896, 1897056, 4898872, 7593125, ],\n [166257661, 776830421, 290516100, 746623577, 293783147, 33900006, 735127505, 565460332, 428982705, 472062098, 161873957, 117354594, 515619293, 578944191, 312106242, 569389279, 391464593, ],\n [464207287, 261086313, 584837659, 683961846, 468868529, 211593382, 736955478, 229471758, 157617135, 398169441, 360252438, 629394768, 264125799, 647490480, 342079395, 391579767, 225200475, 486011304, 513156108, 628771752, 132906648, 142138221, 20119449, 444199674, 195188679, 387329805, 44684703, 651912135, 737154512, 612549793, 519860281, 186175544, 212568440, ],\n [382725349, 240805271, 239509872, 581127897, 6511239, 156126222, 509425833, 672407328, 366667722, 459185405, 509737025, 554790222, 165216555, 703150560, 74806569, 398730015, 383350905, 506108358, 51326142, 298053147, 104256117, 391428765, 374020479, 206607807, 87664059, 275899176, 56407680, 551553401, 448939463, 582889860, 129676638, 226078251, 135769095, 61292868, 578972226, 190181628, 390739055, 184587732, 446575689, 732674124, 232198470, 676760679, 352474101, 611444862, 575661807, 628905585, 320813094, 522840969, 469781928, 156006018, 554473341, 239654268, 643714911, 433540170, 199307003, 496385218, 291740751, 67309914, 370826673, 202356819, 279421821, 421203111, 63744786, 520987612, 550671827, ],\n [642497124, 482164403, 768209115, 462063756, 154906374, 36099042, 341766705, 678182556, 621882744, 478771358, 231881111, 175889805, 243630450, 168908523, 671961765, 55761813, 652682670, 773939082, 517628076, 756201264, 124604900, 750976272, 498253248, 676047609, 137170026, 705610017, 495032139, 561797418, 703097347, 500815609, 95984586, 739707108, 265613565, 387099846, 777331779, 594676173, 591219559, 407997044, 208947235, 93337440, 478908360, 685013007, 487033953, 671903001, 39521181, 738490312, 33785059, 465470131, 310453920, 54648783, 346831137, 427694175, 474743430, 705296781, 435828036, 429824745, 663532359, 261388683, 244690731, 533997135, 596108961, 506813013, 371892402, 590145264, 104733162, 143420103, 654339672, 700348950, 685038942, 578826927, 286484229, 501639192, 434962491, 299270097, 27702486, 335375775, 111746817, 565603164, 294926121, 676063665, 735862995, 710035809, 437011960, 668528077, 138765186, 508213986, 615036450, 353784942, 624827616, 343900011, 241289776, 52410890, 72018835, 352406796, 415705878, 4802637, 376367145, 65589678, 333633477, 341834527, 303717460, 282387700, 42951006, 254706039, 423048528, 526429710, 68131467, 669954708, 12787348, 500636381, 317959019, 479433192, 657133515, 416259390, 610216692, 340129188, 44594256, 257373347, 138718678, 530767740, 292922628, 37220268, 605295159, 480722613, 458170419, 30540300, 487159055, 232966794, 149150650, ],\n [507720408, 412133651, 386543325, 139952108, 289303402, 102404925, 317067177, 396414708, 80515854, 663739304, 317300809, 228877044, 493725043, 715317967, 490300965, 315527373, 743539734, 488329191, 553627998, 533025234, 242583957, 706116537, 614109258, 645447222, 523195911, 492109128, 722623041, 111085128, 766395126, 654378921, 691964847, 496688157, 399056049, 654363234, 102052314, 191720088, 473910948, 259736526, 332840025, 388047555, 665791056, 627111387, 139696515, 441456687, 443032569, 283264821, 771641703, 452641455, 511306362, 117572859, 127701891, 721298331, 176520078, 357242229, 611296308, 696994956, 405628839, 429224274, 465336054, 695091546, 689828796, 574648641, 351220905, 507964023, 675326610, 517248963, 453528621, 220301928, 494463186, 681789969, 339589656, 44524053, 417125457, 339589404, 747135963, 341780733, 734158215, 396817281, 21997836, 5728464, 147611205, 456248898, 714128667, 377654949, 3862068, 128418948, 589390074, 304947090, 11703825, 228266073, 127304142, 429215724, 361541124, 521572968, 468358191, 341231688, 65323503, 613778508, 15985323, 291661029, 410970006, 591638112, 349541550, 89967528, 224922159, 361094166, 584206074, 640051812, 324264456, 652625388, 693768537, 11740617, 309238398, 211085469, 194905872, 639416484, 110110707, 296645895, 748118511, 131177718, 511142751, 775975599, 421403409, 475528473, 434685258, 1768977, 80301375, 708023862, 569195676, 56238084, 632887668, 88089750, 631539342, 396695565, 38780154, 695798271, 469819224, 439587099, 69045921, 682966116, 112310856, 64943298, 534475872, 40215357, 389728458, 286368453, 736006257, 501181650, 54829908, 603489402, 338032656, 512182818, 627500097, 462674016, 3103092, 157324491, 43978329, 596818971, 259025598, 9088632, 91991781, 577291428, 211245489, 429471231, 142626330, 172560633, 510907446, 444609585, 758102058, 375112647, 744786693, 276174402, 19259856, 233672418, 745389414, 225772848, 23385663, 324290610, 519804558, 120337812, 402578568, 360676008, 450089262, 551043738, 337388940, 512108856, 28879011, 690040638, 106017282, 558262341, 99972432, 608226003, 612152037, 42414435, 776201013, 39580443, 518796945, 494437752, 583194366, 723936555, 415359657, 309569589, 751104774, 166684527, 249229170, 353120823, 130668327, 753823584, 580966092, 561963717, 543672234, 393846327, 586278000, 327398400, 278403867, 156455586, 363920382, 190245195, 290039148, 547014447, 466218648, 146037150, 585462906, 666008595, 691786683, 374707494, 622498779, 231158277, 685740951, 115612245, 681825249, 545555745, 551718468, 277206615, 640171035, 757727334, 195193908, 658656684, 457760646, 225925875, 505761984, 18685233, 506832921, 112511021, 396846646, 290147622, 113924623, 669986155, 336008070, 63611061, 238586775, 119956662, 616557739, 772784623, 334527774, 410403148, 51933421, ],]\n\nn, k = gets.split.map(&:to_i)\ni = 0\nwhile n > 1\n n >>= 1\n i += 1\nend\np answer[i][k]\n", "lang_cluster": "Ruby", "tags": ["dp"], "code_uid": "f884ad07d8e2291eeab6f2a4b8e9cdc5", "src_uid": "cfe19131644e5925e32084a581e23286", "difficulty": 2700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a=[[0],[2,1],[32,30,80,109],[6824,59808,147224,415870,1757896,1897056,4898872,7593125],[776830421,290516100,746623577,293783147,33900006,735127505,565460332,428982705,472062098,161873957,117354594,515619293,578944191,312106242,569389279,391464593],[261086313,584837659,683961846,468868529,211593382,736955478,229471758,157617135,398169441,360252438,629394768,264125799,647490480,342079395,391579767,225200475,486011304,513156108,628771752,132906648,142138221,20119449,444199674,195188679,387329805,44684703,651912135,737154512,612549793,519860281,186175544,212568440],[240805271,239509872,581127897,6511239,156126222,509425833,672407328,366667722,459185405,509737025,554790222,165216555,703150560,74806569,398730015,383350905,506108358,51326142,298053147,104256117,391428765,374020479,206607807,87664059,275899176,56407680,551553401,448939463,582889860,129676638,226078251,135769095,61292868,578972226,190181628,390739055,184587732,446575689,732674124,232198470,676760679,352474101,611444862,575661807,628905585,320813094,522840969,469781928,156006018,554473341,239654268,643714911,433540170,199307003,496385218,291740751,67309914,370826673,202356819,279421821,421203111,63744786,520987612,550671827],[482164403,768209115,462063756,154906374,36099042,341766705,678182556,621882744,478771358,231881111,175889805,243630450,168908523,671961765,55761813,652682670,773939082,517628076,756201264,124604900,750976272,498253248,676047609,137170026,705610017,495032139,561797418,703097347,500815609,95984586,739707108,265613565,387099846,777331779,594676173,591219559,407997044,208947235,93337440,478908360,685013007,487033953,671903001,39521181,738490312,33785059,465470131,310453920,54648783,346831137,427694175,474743430,705296781,435828036,429824745,663532359,261388683,244690731,533997135,596108961,506813013,371892402,590145264,104733162,143420103,654339672,700348950,685038942,578826927,286484229,501639192,434962491,299270097,27702486,335375775,111746817,565603164,294926121,676063665,735862995,710035809,437011960,668528077,138765186,508213986,615036450,353784942,624827616,343900011,241289776,52410890,72018835,352406796,415705878,4802637,376367145,65589678,333633477,341834527,303717460,282387700,42951006,254706039,423048528,526429710,68131467,669954708,12787348,500636381,317959019,479433192,657133515,416259390,610216692,340129188,44594256,257373347,138718678,530767740,292922628,37220268,605295159,480722613,458170419,30540300,487159055,232966794,149150650],[412133651,386543325,139952108,289303402,102404925,317067177,396414708,80515854,663739304,317300809,228877044,493725043,715317967,490300965,315527373,743539734,488329191,553627998,533025234,242583957,706116537,614109258,645447222,523195911,492109128,722623041,111085128,766395126,654378921,691964847,496688157,399056049,654363234,102052314,191720088,473910948,259736526,332840025,388047555,665791056,627111387,139696515,441456687,443032569,283264821,771641703,452641455,511306362,117572859,127701891,721298331,176520078,357242229,611296308,696994956,405628839,429224274,465336054,695091546,689828796,574648641,351220905,507964023,675326610,517248963,453528621,220301928,494463186,681789969,339589656,44524053,417125457,339589404,747135963,341780733,734158215,396817281,21997836,5728464,147611205,456248898,714128667,377654949,3862068,128418948,589390074,304947090,11703825,228266073,127304142,429215724,361541124,521572968,468358191,341231688,65323503,613778508,15985323,291661029,410970006,591638112,349541550,89967528,224922159,361094166,584206074,640051812,324264456,652625388,693768537,11740617,309238398,211085469,194905872,639416484,110110707,296645895,748118511,131177718,511142751,775975599,421403409,475528473,434685258,1768977,80301375,708023862,569195676,56238084,632887668,88089750,631539342,396695565,38780154,695798271,469819224,439587099,69045921,682966116,112310856,64943298,534475872,40215357,389728458,286368453,736006257,501181650,54829908,603489402,338032656,512182818,627500097,462674016,3103092,157324491,43978329,596818971,259025598,9088632,91991781,577291428,211245489,429471231,142626330,172560633,510907446,444609585,758102058,375112647,744786693,276174402,19259856,233672418,745389414,225772848,23385663,324290610,519804558,120337812,402578568,360676008,450089262,551043738,337388940,512108856,28879011,690040638,106017282,558262341,99972432,608226003,612152037,42414435,776201013,39580443,518796945,494437752,583194366,723936555,415359657,309569589,751104774,166684527,249229170,353120823,130668327,753823584,580966092,561963717,543672234,393846327,586278000,327398400,278403867,156455586,363920382,190245195,290039148,547014447,466218648,146037150,585462906,666008595,691786683,374707494,622498779,231158277,685740951,115612245,681825249,545555745,551718468,277206615,640171035,757727334,195193908,658656684,457760646,225925875,505761984,18685233,506832921,112511021,396846646,290147622,113924623,669986155,336008070,63611061,238586775,119956662,616557739,772784623,334527774,410403148,51933421]]\nn,k=gets.split.map &:to_i\ni=0\nwhile 1<= 2\n ans = ans + calc2(n)\nend\nif m >= 3\n ans = ans + calc3(n)\nend\nif m >= 4\n ans = ans + calc4(n)\nend\np ans\n", "lang_cluster": "Ruby", "tags": ["math", "dp", "combinatorics"], "code_uid": "ba5d3018f039284878e7a8331b29d1b8", "src_uid": "96d839dc2d038f8ae95fc47c217b2e2f", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby 3", "source_code": "gets.to_i.times { a=gets+gets;puts a.include?('1') ? (!a.include?('0') ? 2 : 1) : 0}\r\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "ba5da539608eaff2cbabd00e1c914980", "src_uid": "7336b8becd2438f0439240ee8f9610ec", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby 3", "source_code": "za=gets.chomp.to_i\r\nza.times do\r\n\ta,b=gets.split.map(&:to_i)\r\n\tc,d=gets.split.map(&:to_i)\r\n\tif (a==1 and b==1 and c==1 and d==1)\r\n\t\tputs 2\r\n\telsif (a==1 or b==1 or c==1 or d==1)\r\n\t\tputs 1\r\n\telse\r\n\t\tputs 0\r\n\tend\r\nend", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "c7da149d7993e89fef3ea757f73578bf", "src_uid": "7336b8becd2438f0439240ee8f9610ec", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby 3", "source_code": "gets.to_i.times { a=(gets+gets).split(' ');puts a.include?('1') ? (!a.include?('0') ? 2 : 1) : 0}", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "b17c57728a5936d3f0cb7066e622c8ee", "src_uid": "7336b8becd2438f0439240ee8f9610ec", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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\"", "lang_cluster": "Ruby", "tags": ["brute force", "greedy", "implementation"], "code_uid": "ed249ea6fca22df44aaebfaabb9d947a", "src_uid": "d1f88a97714d6c13309c88fcf7d86821", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "N, K = gets.split.map &:to_i\nA = gets.split.map &:to_i\none, two, four = 0, 2 * N, N\nuntil A.empty? do\n A.sort!\n u = A[-1]\n A.pop\n if four > 0\n four -= 1\n one += 1 if u <= 2\n u -= 4\n elsif two > 0\n two -= 1\n u -= 2\n elsif one > 0\n one -= 1\n u -= 1\n else\n A.push u\n break\n end\n A.push(u) if u > 0\nend\nputs [\"NO\", \"YES\"][A.empty? ? 1 : 0]\n", "lang_cluster": "Ruby", "tags": ["brute force", "greedy", "implementation"], "code_uid": "79755ea9e62e0ee95f5634eb7d82d4e5", "src_uid": "d1f88a97714d6c13309c88fcf7d86821", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "gets\nstack=[]\nans=0\ngets.split.map(&:to_i).each do |i|\n while stack.size>=2&&stack[-1]<=stack[-2]&&stack[-1]<=i\n ans+=[stack[-2],i].min\n stack.pop\n end\n stack.push i\nend\nstack.sort!\n2.times{stack.pop}\nstack.each do |i|\n ans+=i\nend\np ans", "lang_cluster": "Ruby", "tags": ["greedy"], "code_uid": "e82bff2a7d62c2570be59b3ac1d4e583", "src_uid": "e7e0f9069166fe992abe6f0e19caa6a1", "difficulty": 2500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "gets\ns,ans=[],0\ngets.split.map(&:to_i).each do |i|\n while s.size>1&&[s[-1],s[-2],i].min==s[-1]\n ans+=[s[-2],i].min\n s.pop\n end\n s.push i\nend\ns.sort!\n2.times{s.pop}\ns.each{|i| ans+=i}\np ans", "lang_cluster": "Ruby", "tags": ["greedy"], "code_uid": "4914f3c9f8ac4555106eac8dffdfae63", "src_uid": "e7e0f9069166fe992abe6f0e19caa6a1", "difficulty": 2500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["greedy"], "code_uid": "c364e6c0df960e708b3ef5ec8fdfa2f0", "src_uid": "e7e0f9069166fe992abe6f0e19caa6a1", "difficulty": 2500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "st = gets.split\nn=st[0].to_i\n\narray=[1,0,3,0,15,0,133,0,2025,0,37851,0,1030367,0,36362925,0]\nfact = [1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800, 39916800, 479001600, 6227020800,87178291200, 1307674368000, 20922789888000]\nputs (fact[n-1]*array[n-1])%1000000007", "lang_cluster": "Ruby", "tags": ["dp", "combinatorics", "bitmasks", "meet-in-the-middle", "implementation"], "code_uid": "29027b397fbea49f7dba061d34a06dfa", "src_uid": "a6a804ce23bc48ec825c17d64ac0bb69", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def getnum(day)\n case day\n when \"monday\"\n 0\n when \"tuesday\"\n 1\n when \"wednesday\"\n 2\n when \"thursday\"\n 3\n when \"friday\"\n 4\n when \"saturday\"\n 5\n when \"sunday\"\n 6\n end\nend\n\nd1 = getnum(gets.strip)\nd2 = getnum(gets.strip)\nans = \"NO\"\nmdays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n0.upto(10).each do |i|\n ans = \"YES\" if (d1 + mdays[i])%7 == d2\nend\nputs ans", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "0571ffc3fdcbd25a42fdf6cfb2190a97", "src_uid": "2a75f68a7374b90b80bb362c6ead9a35", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a = gets.chomp\n\nb = gets.chomp\n\n\nif a == \"monday\"\n\tn1 = 1\nend\nif (a == \"tuesday\")\n\tn1 = 2\nend\nif (a == \"wednesday\")\n\tn1 = 3\nend\nif (a == \"thursday\")\n\tn1 = 4\nend\nif (a == \"friday\")\n\tn1 = 5\nend\nif (a == \"saturday\")\n\tn1 = 6\nend\nif (a == \"sunday\")\n\tn1 = 7\nend\n\nif (b == \"monday\")\n\tn2 = 1\nend\nif b == \"tuesday\"\n\tn2 = 2\nend\nif (b == \"wednesday\")\n\tn2 = 3\nend\nif (b == \"thursday\")\n\tn2 = 4\nend\nif (b == \"friday\")\n\tn2 = 5\nend\nif (b == \"saturday\")\n\tn2 = 6\nend\nif (b == \"sunday\")\n\tn2 = 7\nend\n\ndif = n2 - n1\n\nif (dif < 0)\nf = dif + 7\nelse \nf = dif \nend\n\nif (f == 3)\n\tputs \"YES\"\nelsif (f == 0)\n\tputs \"YES\"\nelsif (f == 2)\n\tputs \"YES\"\nelse\n\tputs \"NO\"\nend\n\n\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "5878b9d311b30c772428cd21c1fe109c", "src_uid": "2a75f68a7374b90b80bb362c6ead9a35", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "d1 = gets.strip\nd2 = gets.strip\nmonths = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ]\ndays = [\"monday\", \"tuesday\", \"wednesday\", \"thursday\", \"friday\", \"saturday\", \"sunday\"]\nmods = months.map { |e| e % 7 }\nans = \"NO\"\n(1..12).each do |i|\n d1_id = days.index d1\n d2_id = d1_id + mods[i - 1]\n d2_id -= 7 if d2_id >= 7\n if days[d2_id] == d2\n ans = \"YES\"\n break\n end\nend\nputs ans\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "741cc606c783e92957d5f3f84fc4c3b3", "src_uid": "2a75f68a7374b90b80bb362c6ead9a35", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,a,b,c = gets.chomp.split(/ /).map!{|x| x.to_i}\nmaxa = a / 2\nmaxab = maxa + b\nminc = [(n - maxab+1)/2, 0].max\nmaxc = [n/2, c].min\n\nret = 0\nfor i in minc..maxc\n\tforb = n - i*2\n\tminb = [forb - maxa, 0].max\n\tmaxb = [forb, b].min\n\tret += maxb - minb + 1\nend\nputs ret\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "d652fd3e309974d7ca2da52f9020e431", "src_uid": "474e527d41040446a18186596e8bdd83", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["sortings", "greedy"], "code_uid": "cb6a7c00d2fb77ce20effbb305d0574d", "src_uid": "715608282b27a0a25b66f08574a6d5bd", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,*a=$<.read.split.map &:to_i\na=a.map{|e|e*2}.sort\ni=0;s=a.reduce(:+)\nwhile s x\n end\nend\nans = 0\n1.upto(n) do |i|\n ans += height[i] ** 2\nend\np ans\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "9b19d75626da4f74e297969391f0acd9", "src_uid": "f22b6dab443f63fb8d2d288b702f20ad", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def nth_root_ceil(n, m)\n return n if m == 1\n i = 1\n j = n\n while j > i + 1 do\n mid = (i + j) / 2\n if mid ** m >= n\n j = mid\n else\n i = mid\n end\n end\n return j\nend\n\nclass Solution\n def initialize(n)\n @n = n\n @x = []\n (1..n).each do |i|\n @x[i] = nth_root_ceil(n, i)\n break if @x[i] == 2\n end\n end\n\n def build_dp()\n @dp = Array.new(@x.size)\n (0...@x.size).each {|i| @dp[i] = Array.new(@x[2]+1, 1)}\n @dp[1][@x[2]] = 0 if ((@n - @x[2]) % 2 == 1)\n (3...@x.size).each do |m|\n (@x[m-1]-1).downto(@x[m]).each do |x|\n (m-1).downto(1).each do |y|\n @dp[y][x] = 0 if (@dp[y+1][x] == 1 and @dp[y][x+1] == 1)\n end\n end\n end\n end\n\n def solve_boundary_case(b)\n result = -1\n (b...@x.size).each do |i|\n if @dp[i][2] == 0\n result = (i - b) % 2 == 0 ? 1 : 0\n break\n end\n end\n return result\n end\n\n def solve(a, b)\n if (a > @x[2])\n result = (@n - a) % 2 == 1 ? 0 : 1\n elsif (a > 1)\n result = @dp[b][a]\n else\n result = solve_boundary_case(b)\n end\n return result\n end\n\n def print()\n (@dp.size-1).downto(1).each do |i|\n (2...@dp[i].size).each do |j|\n printf(\"%d \", @dp[i][j])\n end\n printf(\"\\n\")\n end\n end\nend\n\na, b, n = gets.split.map(&:to_i)\n# n = 2, a has to be 1, it's a draw\nif n == 2\n puts \"Missing\"\n exit\nend\nsolution = Solution.new(n)\nsolution.build_dp\nanswers = %w[Stas Masha Missing]\nputs answers[solution.solve(a, b)]\n", "lang_cluster": "Ruby", "tags": ["dp", "games"], "code_uid": "9f8c13c8983eb91a600a8100f695ca88", "src_uid": "cffd5c0b7b659649f3bf9f2dbd20ad6b", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "(N,), M, R = $<.map{|l| l.split.map &:to_i }\np 720720.times.count{|d| M.zip(R).any?{|m, r| m > 0 && d % m == r} } / 720720.0\n\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "0e451573f94da9a41c2778838395d82c", "src_uid": "14b69f42bc192ea472e82f3a3209f1c1", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = readline.to_i\nm = readline.split(' ').collect(&:to_i)\nr = readline.split(' ').collect(&:to_i)\nputs (1..720720).count{|n| m.zip(r).detect{|mm,rr| n % mm == rr} != nil} / 720720.0\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "95fdbefa977f6f341b1a8714ddfaff9b", "src_uid": "14b69f42bc192ea472e82f3a3209f1c1", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "$MAXN = 2222;\n$P = Integer(1e9 + 7);\n\ndef powmod(a,b,c)\n r=1;\n while b != 0\n if( (b&1) == 1 ) \n r = r * a % c;\n end\n a = a * a % c;\n b /= 2;\n end\n return r;\nend\n\ndef inv(a, b )\n return powmod( a, b - 2 , b ) ; \nend\n\ndef facmod(n)\n r=1;\n (1..n).each{ |i| \n r = r * i % $P;\n }\n return r;\nend\n\ndef C(n,m)\n if(m == 0) \n return 1;\n end;\n if(m>n)\n return 0;\n end;\n return (facmod(n) * inv( facmod(m), $P) * inv( facmod(n-m), $P ) ) % $P ;\nend\n\nn, m, k = gets().split(\" \").map(&:to_i);\nprintf \"%d\\n\", (C(n-1,2*k) * C(m-1,2*k) )% $P;\n", "lang_cluster": "Ruby", "tags": ["dp", "combinatorics"], "code_uid": "0c5997ca5be9e7d9603c464c9cc6f01d", "src_uid": "309d2d46086d526d160292717dfef308", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def pow(a, b, mod)\n ret = 1\n while b > 0\n if (b & 1 == 1)\n ret = ret * a % mod\n end\n b = b / 2\n a = a * a % mod\n end\n return ret\nend\n(n, m, k) = gets.chomp.split.map(&:to_i)\nmod = 10**9 + 7\nans = pow(pow(2, n - 1, mod), m - 1, mod)\nif (n % 2 != m % 2 and k == -1)\n ans = 0\nend\nprint ans", "lang_cluster": "Ruby", "tags": ["math", "constructive algorithms", "combinatorics", "number theory"], "code_uid": "d6a105ba48287a0c658c65746373da64", "src_uid": "6b9eff690fae14725885cbc891ff7243", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def power(x, y, z)\n\tnumber = 1\n\twhile (y > 0) do\n\t\tif (y%2==1)\n\t\t\tnumber = number * x % z\n\t\tend\n\t\ty >>= 1\n\t\tx = x * x % z\n\tend\n\treturn number\nend\n\nn, m, k = gets.split.map(&:to_i)\nif((n + m) % 2 == 1 && k == -1)\n p 0\nelse\n md = 1000000007\n p power(2, (n-1)*(m-1), md)\nend", "lang_cluster": "Ruby", "tags": ["math", "constructive algorithms", "combinatorics", "number theory"], "code_uid": "90b0e5c30f9f0eb7a32efde9ce0f898d", "src_uid": "6b9eff690fae14725885cbc891ff7243", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, k = gets.split.map(&:to_i)\ns = gets.chomp\n\nl = 0;\n\nfor i in 0..(n-1)\n c = 0;\n j = i;\n while j < n && s[j] == 'N' do\n c = c + 1;\n j = j + 1;\n end\n if (l < c)\n \tl = c;\n end\nend\n\nok = false\n\nfor i in 0..(n-1)\n if ((i == 0 || s[i - 1] != 'N') && (i + k) <= n)\n \too = true;\n \tfor j in 0..(k-1)\n \t\tif (s[i+j] == 'Y')\n \t\t\too = false;\n \t\tend\n \tend\n \tif (!(i + k == n || s[i + k] != 'N'))\n \t\too = false;\n \tend\n \tif (oo)\n \t\tok = true;\n \tend\n end\nend\n\nif (ok && l <= k)\n\tputs \"YES\"\nelse\n\tputs \"NO\"\nend", "lang_cluster": "Ruby", "tags": ["dp"], "code_uid": "06f3f96606b794cfa524457a2c336566", "src_uid": "5bd578d3da5837c259b222336a194d12", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "# frozen_string_literal: true\n\ndef dist(i, j, n)\n if j == i\n n\n else\n j > i ? j - i : n - i + j\n end\nend\n\nn, m = readline.strip.split.map(&:to_i)\nl = readline.strip.split.map { |c| c.to_i - 1 }\n\nvis = Array.new(n) { false }\nused = Array.new(n + 1) { false }\n\na = Array.new(n) { -1 }\n\nok = true\n(0...m - 1).each do |i|\n if vis[l[i]]\n ok &&= dist(l[i], l[i + 1], n) == a[l[i]]\n else\n vis[l[i]] = true\n\n d = dist(l[i], l[i + 1], n)\n\n ok &&= !used[d]\n\n used[d] = true\n\n a[l[i]] = d\n end\nend\n\ni = 1\n(0...n).each do |j|\n next unless a[j] < 0\n\n i += 1 while used[i]\n a[j] = i\n used[i] = true\n i += 1\nend\n\nif !ok\n puts -1\nelse\n puts a.map(&:to_s).join(' ')\nend\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "0b10233799735191f11e7a892508ed8f", "src_uid": "4a7c959ca279d0a9bd9bbf0ce88cf72b", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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\")", "lang_cluster": "Ruby", "tags": ["brute force", "math", "dp", "meet-in-the-middle", "greedy", "number theory"], "code_uid": "a753d959c6251b50cd4951293f6ef1cc", "src_uid": "a74adcf0314692f8ac95f54d165d9582", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["math", "binary search"], "code_uid": "096a51d2d16c2498d1eeacd11afa40db", "src_uid": "3b585ea852ffc41034ef6804b6aebbd8", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, m = gets.split.map(&:to_i)\nnn = [n - m, 0].max\np (0..10 ** 18).bsearch{|a| nn <= ((1 + a) * a) / 2} + [n, m].min\n", "lang_cluster": "Ruby", "tags": ["math", "binary search"], "code_uid": "57489a7f764d7be5253578e715a4e2a8", "src_uid": "3b585ea852ffc41034ef6804b6aebbd8", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, m = gets.split.map(&:to_i)\n# p gets.split.map(&:to_i)\ndef f(day, n, m)\n minus = (m + 1 + day) * (day - m) / 2\n plus = (day - m - 1) * m\n return n - minus + plus <= 0\nend\n\nif(m >= n)\n puts n\nelse\n\n l = m\n r = 1000000000000000000\n while(r - l > 1)\n mid = (r + l) / 2\n if(f(mid, n, m))\n r = mid\n else\n l = mid\n end\n \n end\n \n while(r >= l)\n if(f(r, n, m))\n r -= 1\n else\n r += 1\n break\n end\n end\n \n puts(r)\nend", "lang_cluster": "Ruby", "tags": ["math", "binary search"], "code_uid": "b6d10105a38aea55c0b388d5a435973f", "src_uid": "3b585ea852ffc41034ef6804b6aebbd8", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b=gets.split.map &:to_i;p (b+a-1)/a", "lang_cluster": "Ruby", "tags": ["math", "greedy", "implementation"], "code_uid": "902b7c744f5cb9c730b7ea6cb2c91042", "src_uid": "04c067326ec897091c3dbcf4d134df96", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, s = gets.split.map{|x| x.to_i}\nncoins = 0\nn.downto(1) do |i|\n ncoins += s/i\n s %= i\nend\nputs ncoins\n", "lang_cluster": "Ruby", "tags": ["math", "greedy", "implementation"], "code_uid": "bd541fa5e1ead2982e3738aaf61b82cf", "src_uid": "04c067326ec897091c3dbcf4d134df96", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, s = gets.split.map(&:to_f)\nputs (s / n).ceil.to_i", "lang_cluster": "Ruby", "tags": ["math", "greedy", "implementation"], "code_uid": "822c778dfe1bd931d3f37a79141c5dff", "src_uid": "04c067326ec897091c3dbcf4d134df96", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "# Created by Alex\nn, k, x = gets.split.map {|i| i.to_i}\na = gets.split.map {|i| i.to_i}\nmax = 0\nmaxi = -1\nfor i in 0...n - 1\n #print a[i].to_s + ' '\n if a[i] != x || a[i + 1] != x\n next\n end\n l = i - 1\n r = i + 2\n cnt = 3\n while l >= 0 && r < n && a[l] == a[r]\n p1 = l\n while p1 > 0 && a[p1 - 1] == a[r]\n p1 -= 1\n end\n p2 = r\n while p2 < n - 1 && a[p2 + 1] == a[l]\n p2 += 1\n end\n if l - p1 + p2 - r + 2 < 3\n break\n end\n cnt += l - p1 + p2 - r + 2\n l = p1 - 1\n r = p2 + 1\n end\n if cnt >= max\n #print ' (' + cnt.to_s + ' ' + p1.to_s + ' ' + p2.to_s + ') '\n max = cnt\n maxi = i\n end\nend\nif max < 3\n max = 1\nend\nputs max - 1", "lang_cluster": "Ruby", "tags": ["two pointers", "brute force"], "code_uid": "e07ae235223cca3b1560f8cda5f835c4", "src_uid": "d73d9610e3800817a3109314b1e6f88c", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, k, x = $stdin.gets.chomp.split(' ').map { |v| v.to_i }\na = $stdin.gets.chomp.split(' ').map { |v| v.to_i }\n\nclass Solver\n def initialize(n, k, x, a)\n @n = n\n @k = k\n @x = x\n @a = a\n end\n\n def cnt(l, r)\n ans = 0\n flag = false\n while true do\n sum = 0\n while l>-1 && @a[l] == @a[r]\n l -= 1\n sum += 1\n end\n l += 1\n while r < @n && @a[l] == @a[r]\n r += 1\n sum += 1\n end\n r -= 1\n return ans if flag && sum < 3\n flag = 1\n ans = [ans, r - l + 1].max\n l -= 1\n r += 1\n return ans if l <0 || r >= @n || @a[l] != @a[r]\n end\n end\nend\n\nsolver = Solver.new(n, k, x, a)\nans = 0\nfor i in 0..n-1\n ans = [ans, solver.cnt(i, i+1)].max if a[i] == a[i+1] && a[i] == x\nend\n\nputs ans\n", "lang_cluster": "Ruby", "tags": ["two pointers", "brute force"], "code_uid": "af838c111ff51d40b5bd90b833af8561", "src_uid": "d73d9610e3800817a3109314b1e6f88c", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "N = gets.to_i\nputs (1..((N+1)/2)).bsearch{|k|\n n = N\n sum1 = 0\n sum2 = 0\n while n > 0\n d1 = k < n ? k : n\n sum1 += d1\n n -= d1\n d2 = n/10\n sum2 += d2\n n -= d2\n end\n sum1 * 2 >= N\n}", "lang_cluster": "Ruby", "tags": ["implementation", "binary search"], "code_uid": "537cfaa0e2137ffea718e582d7252214", "src_uid": "db1a50da538fa82038f8db6104d2ab93", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["implementation", "binary search"], "code_uid": "28cbbdc95980a1c5d712a72e5ec0ae84", "src_uid": "db1a50da538fa82038f8db6104d2ab93", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["brute force", "math", "constructive algorithms", "implementation"], "code_uid": "16fbfd60a02894b8d790c756babf24d3", "src_uid": "ec5e3b3f5ee6a13eaf01b9a9a66ff037", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a, b = gets.strip.split.map(&:to_i)\nif (a > 0 || b > 0) && (a == b || (a - b).abs == 1)\n puts \"YES\"\nelse\n puts \"NO\"\nend\n", "lang_cluster": "Ruby", "tags": ["brute force", "math", "constructive algorithms", "implementation"], "code_uid": "8cc464dd11902001852e17025c77d049", "src_uid": "ec5e3b3f5ee6a13eaf01b9a9a66ff037", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "# 4\n#0123\n# 5\nclass Dice\n def initialize(arr)\n @arr = arr.dup\n end\n\n def rot_x\n @arr[0], @arr[1..3] = @arr[3], @arr[0..2]\n end\n\n def rot_y\n @arr[4], @arr[2], @arr[5], @arr[0] = @arr[2], @arr[5], @arr[0], @arr[4]\n end\n\n def rot_z\n @arr[4], @arr[1], @arr[5], @arr[3] = @arr[1], @arr[5], @arr[3], @arr[4]\n end\n\n def to_a\n @arr.dup\n end\nend\n\narr = gets.chomp.each_char.sort\ndict = []\ncnt = 0\narr.permutation do |perm|\n dice = Dice.new(perm)\n ok = true\n catch(:check) {\n 6.times do |t|\n 4.times do\n if dict.index(dice.to_a)\n ok = false\n throw :check\n end\n dice.rot_x\n end\n if t == 3\n dice.rot_y\n dice.rot_z\n elsif t == 4\n dice.rot_z\n dice.rot_z\n else\n dice.rot_y\n end\n end\n }\n if ok\n cnt += 1\n dict << dice.to_a\n end\nend\n\np cnt\n", "lang_cluster": "Ruby", "tags": ["brute force"], "code_uid": "ec8cc89d5787da587bf84bf2a42b3beb", "src_uid": "8176c709c774fa87ca0e45a5a502a409", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#! ruby\n# Try Codeforces\n# author: Leonardone @ NEETSDKASU\n############################################################\ndef gs() gets.chomp end\ndef gi() gets.to_i end\ndef gss() gs.split end\ndef gis() gss.map(&:to_i) end\ndef nmapf(n,f) n.times.map{ __send__ f } end\ndef ngs(n) nmapf n,:gs end\ndef ngi(n) nmapf n,:gi end\ndef ngss(n) nmapf n,:gss end\ndef ngis(n) nmapf n,:gis end\ndef arr2d(h,w,v=0) h.times.map{[v] * w} end\ndef for2p(hr,wr,&pr) hr.each{|i|wr.each{|j| yield(i,j)}} end\ndef nsum(n) n * (n + 1) / 2 end\ndef vcount(d,r=Hash.new(0)) d.inject(r){|r,e| r[e]+=1;r} end\n############################################################\n\nn = gi\n\nif n == 0\n puts \"0 0\"\n exit\nend\n\nm = n - 1\n\nk = 9 + 4 * 3 * m\nd = (- 3 + (k ** 0.5)) / 6\nd = d.floor\n\nwhile d * (d + 1) * 3 < n\n d += 1\nend\n\nf = d * (d - 1) * 3\n\ncase\nwhen (n - f) <= d\n e = n - f\n x = d * 2 - e\n y = e * 2\nwhen (n - f) <= 2 * d\n e = (n - f) - d\n x = d - e * 2\n y = d * 2\nwhen (n - f) <= 3 * d\n e = (n - f) - d * 2\n x = -d - e\n y = d * 2 - e * 2\nwhen (n - f) <= 4 * d\n e = (n - f) - d * 3\n x = - d * 2 + e\n y = -e * 2\nwhen (n - f) <= 5 * d\n e = (n - f) - d * 4\n x = -d + 2 * e\n y = -d * 2\nelse\n e = (n - f) - d * 5\n x = d + e\n y = -d * 2 + e * 2\nend\n\nputs \"%d %d\" % [x, y]\n\n\n\n\n\n\n\n\n\n\n", "lang_cluster": "Ruby", "tags": ["math", "implementation", "binary search"], "code_uid": "e8f5220bd6c00ffbd211f88632742fcf", "src_uid": "a4b6a570f5e63462b68447713924b465", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def sum(x)\n x.split('').map(&:to_i).inject(0) { |sum, x| sum + x }\nend\n\nx = gets.to_i\n\nsx = x.to_s\n\nans = x\nsans = sx\n\nsx.length.times do |i|\n sy = sx[0...i] + (sx[i].to_i - 1).to_s + '9' * (sx.length - i - 1)\n \n y = sy.to_i\n sy = y.to_s\n \n if (sum(sy) > sum(sans) || (sum(sy) == sum(sans) && y > ans))\n ans = y\n sans = sy\n end\nend\n\nputs sans", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "c47ba20215df903ad5b89fe49755b243", "src_uid": "e55b0debbf33c266091e6634494356b8", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "x,y = gets.split.map(&:to_i)\nprime = []\nk = (y**0.5).to_i\nk = x if k > x\na = Array.new(k+1,1)\ni = 2\nwhile i <= k\n if a[i] == 1\n prime << i\n (k/i).times do |j|\n a[i*j] = 0\n end\n end\n i += 1\nend\nisprime = false\nwhile !isprime && x < y\n isprime = true\n prime.length.times do |i|\n isprime = false if y % prime[i] == 0\n end\n if isprime\n ans = y\n end\n y -= 1\nend\nans = -1 if !isprime\nputs ans", "lang_cluster": "Ruby", "tags": ["brute force", "math", "number theory"], "code_uid": "4b931d8dd1057a1f25affc2ab13ba1ee", "src_uid": "b533203f488fa4caf105f3f46dd5844d", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["dfs and similar", "math", "combinatorics", "graphs"], "code_uid": "f4dc2530e7aa3ec5def64d8df0b4bd3b", "src_uid": "1f9107e8d1d8aebb1f4a1707a6cdeb6d", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "2068e336eb1af126a80c269eec5124d7", "src_uid": "bf4e72636bd1998ad3d034ad72e63097", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def bad(ss)\n return true if ss[0] == '0' && ss.length > 1\n if ss.length > 6\n return true if ss.to_i > 1000000\n end\n return false\nend\n\ns = gets.chomp\nn = s.length-2\nwkmax = -1\nfor i in 0..n\n s1 = s.slice(0..i)\n next if bad(s1)\n s1n = s1.to_i\n for j in i+1..n\n s2 = s.slice(i+1..j)\n next if bad(s2)\n s3 = s.slice(j+1..n+1)\n next if bad(s3)\n wk = s1n + s2.to_i + s3.to_i\n if wk > wkmax\n wkmax = wk\n end\n end\nend\n\nputs wkmax\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "86d5f50c9b4982e342456e5d4e6bdfd4", "src_uid": "bf4e72636bd1998ad3d034ad72e63097", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = gets.chomp\nans = -1\ns.size.times do |i|\n (i + 1).upto(s.size - 2) do |j|\n a, b, c = s[0..i], s[(i + 1)..j], s[(j + 1)..-1]\n next if a.size > 1 and a[0] == ?0\n next if b.size > 1 and b[0] == ?0\n next if c.size > 1 and c[0] == ?0\n next if a.to_i > 1e6.to_i\n next if b.to_i > 1e6.to_i\n next if c.to_i > 1e6.to_i\n ans = [ans, a.to_i + b.to_i + c.to_i].max\n end\nend\nputs ans\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "9e0e8f9f06cdaa5d8ea95042cb4c6c7b", "src_uid": "bf4e72636bd1998ad3d034ad72e63097", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "MOD=10**9+7\ncnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)\ndef gs() gets.chomp end\ndef gi() gets.to_i end\ndef gsmi() gets.chomp.split.map(&:to_i) end\n\ndef desc(ar) ar.sort!{|x,y|y<=>x} end\ndef min(a,b) a<=b ? a : b end\ndef max(a,b) a>=b ? a : b end\ndef sum(ar) ar.inject(:+) end\n\ndef C(a,b) b==0||a==b ? 1 : (b=a-b if a/20\n j = 1\n div = 0\n while j*j<=el do\n if el%j == 0\n div+=2\n end\n j+=1\n\n end\n div-=1 if (j-1)*(j-1) == el\n ar[el] = div % mod\n ar[el]\nend\n\nsolve a, b ,c", "lang_cluster": "Ruby", "tags": ["implementation", "number theory"], "code_uid": "451297c93d00c1069280ce97545fdcc2", "src_uid": "4fdd4027dd9cd688fcc70e1076c9b401", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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\tk=f(n)\n\tr+=k*B+k/2\n\tn=n-k/2\nend\nputs '%d %d'%[r,N*P]", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "f2ccf89499d6c9fa3c6156e8923cf94e", "src_uid": "eb815f35e9f29793a120d120968cfe34", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "\nn=gets.to_i\nac=Array.new(n,0)\nnow=0\nfor i in 0..2*n\n now=(now+i)%n\n ac[now]=1\nend\nk=1\nfor i in 0..n-1\n k&=ac[i]\nend\nif k==1 then\n puts \"YES\"\nelse\n puts \"NO\"\nend\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "cc1098a7a1c1a18294e205a447d8a9f7", "src_uid": "4bd174a997707ed3a368bd0f2424590f", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.to_i\nchecked=Array.new(n,false);\ns=0\nn.times do |t|\n if checked[s] then puts \"NO\"; exit; end\n checked[s]=true;\n s=(s+t+1)%n\nend\nputs \"YES\"", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "fed7558b63a67f0aaed3ef1ca3d12a0d", "src_uid": "4bd174a997707ed3a368bd0f2424590f", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\nwhile n % 2 == 0 do n /= 2 end\nputs n == 1 ? \"YES\" : \"NO\"", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "0f997ae58258243df4a04f7a800aefaf", "src_uid": "4bd174a997707ed3a368bd0f2424590f", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["math", "matrices"], "code_uid": "eff506b30b55a0a56a9900f23167b0c7", "src_uid": "ee9fa8be2ae05a4e831a4f608c0cc785", "difficulty": 2300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/ruby\n\nx, y, z = STDIN.readline.split.map {|s| s.to_i }\nx1, y1, z1 = STDIN.readline.split.map {|s| s.to_i }\na1, a2, a3, a4, a5, a6 = STDIN.readline.split.map {|s| s.to_i }\nsum = 0\nif z < 0\n\tsum += a3\nelsif z > z1\n\tsum += a4\nend\nif x < 0\n\tsum += a5\nelsif x > x1\n\tsum += a6\nend\nif y < 0\n\tsum += a1\nelsif y > y1\n\tsum += a2\nend\nputs sum\n", "lang_cluster": "Ruby", "tags": ["brute force", "geometry"], "code_uid": "7ed4ee7adcd022b2389498cd9f8acb7e", "src_uid": "c7889a8f64c57cf7be4df870f68f749e", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/env ruby\n\nfirst_line = gets.split(\" \")\nvasya = {\"x\" => 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", "lang_cluster": "Ruby", "tags": ["brute force", "geometry"], "code_uid": "faa49aa2868091d1d931fcdc07771c05", "src_uid": "c7889a8f64c57cf7be4df870f68f749e", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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 h+w-2\n\tstrips = [h, k+1].min\n\tacross = [1, k-strips+2].max\n\t#puts 'h = %d, w = %d, k = %d, strips = %d, across = %d' % [h, w, k,\n\t#\t\tstrips, across]\n\treturn (h/strips).floor * (w/across).floor\nend\n\nn, m, k = STDIN.readline.split.collect {|s| s.to_i }\na, b = [n, m].max, [n, m].min\nputs [solve(a, b, k), solve(b, a, k)].max\n\n", "lang_cluster": "Ruby", "tags": ["greedy", "implementation"], "code_uid": "69686c49bb538c1f75cc796ebd32de93", "src_uid": "bb453bbe60769bcaea6a824c72120f73", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, m, k = gets.split.collect{|i| i.to_i}\nn, m = m, n if n > m\nif k < n\n ans = [(n/1)*(m/(k+1)), (n/(k+1))*(m/1)].max\nelsif k >= n and k < m\n ans = (n/1)*(m/(k+1))\nelsif k >= m and k <= m+n-2\n ans = (n/(k+2-m))*(m/m)\nelse\n ans = -1\nend\nputs ans\n", "lang_cluster": "Ruby", "tags": ["greedy", "implementation"], "code_uid": "96c9ec0ebb60effa062c63805104a1df", "src_uid": "bb453bbe60769bcaea6a824c72120f73", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "mas = gets.split(\" \")\nn = mas[0].to_i\nx1 = mas[1].to_i\ny1 = mas[2].to_i\nx2 = mas[3].to_i\ny2 = mas[4].to_i\n\nif x1 == x2 && (x1 == 0 || x1 == n)\n puts (y2-y1).abs\n exit\nend\nif y1 == y2 && (y1 == 0 || y1 == n)\n puts (x2-x1).abs\n exit\nend\n\nif (x1-x2).abs == n\n puts [(n-y1).abs+(n-y2).abs, (y1+y2).abs].min+n\n exit\nend\nif (y1-y2).abs == n\n puts [(n-x1).abs+(n-x2).abs, (x1+x2).abs].min+n\n exit\nend\n\nputs ((x2-x1).abs+(y2-y1).abs).to_s\n", "lang_cluster": "Ruby", "tags": ["dfs and similar", "greedy", "implementation"], "code_uid": "0816565e95dede50ac68291875a95ba7", "src_uid": "685fe16c217b5b71eafdb4198822250e", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "b = gets.to_i\ng = gets.to_i\nn = gets.to_i\n\nans = 0\n(0..n).each do |bb|\n gg = n - bb\n ans += 1 if bb <= b && gg <= g\nend\nputs ans", "lang_cluster": "Ruby", "tags": ["brute force", "math"], "code_uid": "a6f2a139023bff40e431140441f61ee0", "src_uid": "9266a69e767df299569986151852e7b1", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "b = gets.to_i\ng = gets.to_i\nn = gets.to_i\n\ncnt=0\n\nif b>=n && g>=n\n cnt = n+1\nelsif b= c[1] || c[1] >= [b[1], a[1]].max\n ) || \n a[1] == b[1] && (\n [b[0], a[0]].min >= c[0] || c[0] >= [b[0], a[0]].max\n )\nend\n\nif a[0] == b[0] && b[0] == c[0] || a[1] == b[1] && b[1] == c[1]\n puts 1\nelsif tmatch(a,b,c) ||\n tmatch(a,c,b) ||\n tmatch(b,a,c) ||\n tmatch(c,b,a) ||\n tmatch(c,a,b) ||\n tmatch(b,c,a)\n puts 2\nelse\n puts 3\nend", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation"], "code_uid": "4ab33dd12582dc3fae99ef00a59aff4d", "src_uid": "36fe960550e59b046202b5811343590d", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "k, n = gets.chomp.split.map{|i| i.to_i}\nm, ans, offset, flag = 2 ** k, 0, 0, false\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\nputs ans", "lang_cluster": "Ruby", "tags": ["math", "implementation", "trees"], "code_uid": "f11541cd51978a395919fa1ec3c01e10", "src_uid": "3dc25ccb394e2d5ceddc6b3a26cb5781", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "h, n = gets.split.map &:to_i\n\nnn = 2**h - 1 + n\n$turn = [0] * h\nlevell = h - 1\nwhile levell >= 0\n $turn[levell] = nn.odd? ? 1 : 0\n nn /= 2\n levell -= 1\nend\n\ndef treesize(h)\n return 2**(h + 1) - 1\nend\n\ndef func(level, k, symb, h)\n # symb == 0 means 'L', 1 means 'R'\n \n #puts \"in #{k}\"\n \n return 0 if level == h\n \n rec = func(level + 1, k * 2 + $turn[level], 1 - $turn[level], h) \n \n if symb == $turn[level]\n \n return 1 + rec\n else\n \n return 1 + rec + treesize(h - level - 1)\n end\nend\n\np func(0, 1, 0, h)", "lang_cluster": "Ruby", "tags": ["math", "implementation", "trees"], "code_uid": "a30260a01b2001809dd2435c33ac2a2b", "src_uid": "3dc25ccb394e2d5ceddc6b3a26cb5781", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def stop\n\tputs \"stop\"\n\tsleep(2)\nend\ndef readarr\n\tgets.split.map{|i| i.to_i}\nend\ndef write(foo)\n\tif foo.is_a?(Array)\n\t\tputs foo.map{|i| i.to_s}.join(\" \")\n\telse \n\t\tputs foo\n\tend\nend\nh,n = readarr\nans = 0\nwhile(h>0)\n\ta = 1<<(h-1)\n\tif (n>a)\n\t\tn-=a\n\t\tans+=a<<1\n\telse\n\t\tn = a+1-n\n\t\tans+=1\n\tend\n\th-=1\nend\nputs ans\n#sleep(300)", "lang_cluster": "Ruby", "tags": ["math", "implementation", "trees"], "code_uid": "e2a497944197976d68556c66447c6d38", "src_uid": "3dc25ccb394e2d5ceddc6b3a26cb5781", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["brute force", "math", "constructive algorithms", "number theory"], "code_uid": "68ddc8766335bb840f52188b9e0cc3af", "src_uid": "c27ecc6e4755b21f95a6b1b657ef0744", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/ruby\nN=gets.to_i\nA=Enumerator.new{|y|\n\ts=0\n\t(1..1/0.0).each{|n|\n\t\ti=n\n\t\tr=0\n\t\twhile i%5==0\n\t\t\tr+=1\n\t\t\ti/=5\n\t\tend\n\t\ts+=r\n\t\ty<<[s,n]\n\t}\n}.lazy.drop_while{|e,n|e= 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\nputs till_a + extra_time + a_to_b", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "a95c9ba1572828d152df68c986837c7b", "src_uid": "e4a4affb439365c843c9f9828d81b42c", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/env ruby\n\nn = gets.to_i\n\nl, r = 0, n\nwhile l != r\n m = (l + r + 1) / 2\n need = 3 * m * (m + 1) / 2 - m\n if need <= n\n l = m\n else\n r = m - 1\n end\nend\n\nl -= 1 while l > 0 && [0, 2, 1][l % 3] != n % 3\nputs (l + 2) / 3\n", "lang_cluster": "Ruby", "tags": ["math", "greedy", "binary search", "brute force"], "code_uid": "9caa2ea7843160c84cc5e03dab767243", "src_uid": "ab4f9cb3bb0df6389a4128e9ff1207de", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = STDIN.readline.to_i\nk = ((2*n/3.0)**0.5).floor + 1\nk += 1 while (n+k)%3 != 0\nk -= 3 while 3*k**2 + k > 2*n\nputs (k+2)/3\n", "lang_cluster": "Ruby", "tags": ["math", "greedy", "binary search", "brute force"], "code_uid": "6e2cc0fc4102563aa7ee75c19d9cac5d", "src_uid": "ab4f9cb3bb0df6389a4128e9ff1207de", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.chomp.to_i\na = gets.chomp.split.map(&:to_i).sort\n\np = q = 0\na.each_with_index do |v, i|\n dp = (v - (i*2+1)).abs\n dq = (v - (i*2+2)).abs\n p += dp\n q += dq\n\nend\n\nputs p < q ? p : q", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "394567700b7b62dd964a8532e8f202ec", "src_uid": "0efe9afd8e6be9e00f7949be93f0ca1a", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.to_i\na=gets.split.map(&:to_i).sort\np [1,2].map{|s|a.zip(s.step(n,2).to_a).map{|x,i|(x-i).abs}.reduce :+}.min", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "a1561fb1a97429e9d5738eae90c33a3a", "src_uid": "0efe9afd8e6be9e00f7949be93f0ca1a", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/ruby\ndef zeller(_y,m,d)\n\tm+=1\n\tif m<4 then _y-=1;m+=12 end\n\ty=_y/100;z=_y%100\n\t(5*y+z+y/4+z/4+13*m/5+d-1)%7\nend\ndef leap(y)\n\treturn true if y%400==0\n\treturn false if y%100==0\n\ty%4==0\nend\nn=gets.to_i\na=[zeller(n,1,1),leap(n)]\np (n+1..1/0.0).find{|i|a==[zeller(i,1,1),leap(i)]}", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "d67b9e6be6e7f21ea71a7bcbaf45da53", "src_uid": "565bbd09f79eb7bfe2f2da46647af0f2", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def subseq(a, b, i, j)\n return true if i.zero?\n return false if j.zero?\n\n return subseq(a, b, i - 1, j - 1) if a[i-1] == b[j-1]\n return subseq(a, b, i, j - 1)\nend\n\ndef substrs(s)\n len = s.size\n (0..len).map { |l| (0..(len-l)).map { |x| (x..(x + l)) } }.flatten(1)\nend\n\ndef solve(s, t)\n subs = substrs(s)\n mx = 0\n subs.each do |sub|\n ss = s.dup\n ss[sub] = ''\n next if ss.size.zero? or sub.any? { |r| r >= s.size }\n mx = [mx, sub.size].max if subseq(t, ss, t.size, ss.size)\n end\n mx\nend\n\ns = gets.strip\nt = gets.strip\nputs solve(s, t)\n", "lang_cluster": "Ruby", "tags": ["greedy", "implementation"], "code_uid": "423cd36a33683668ca52e4e28a48cfde", "src_uid": "0fd33e1bdfd6c91feb3bf00a2461603f", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["greedy", "implementation"], "code_uid": "9dfc46f7c357a9934dad33b974a2b589", "src_uid": "0fd33e1bdfd6c91feb3bf00a2461603f", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\nret = 0\nloop do\n break if n == 0\n max_digit = 0\n temp = n\n while temp != 0\n max_digit = [temp % 10, max_digit].max\n temp /= 10\n end\n n -= max_digit\n ret += 1\nend\nputs ret", "lang_cluster": "Ruby", "tags": ["dp"], "code_uid": "25dad740f25681d2c0041871b4ad2576", "src_uid": "fc5765b9bd18dc7555fa76e91530c036", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "Teams = [\"BERLAND\"]\ndef teamn(name)\n Teams << name if Teams.index(name).nil?\n Teams.index(name)\nend\ngame = [1,0,0,0]\npoint = [3,0,0,0]\ndiff = [0,0,0,0]\nearn = [0,0,0,0]\n5.times do |i|\n input = gets.split(\" \")\n teama = teamn(input[0])\n teamb = teamn(input[1])\n score = input[2].split(\":\").map{|x| x.to_i}\n if score[0]>score[1]\n point[teama] += 3\n elsif score[0]==score[1]\n point[teama] += 1\n point[teamb] += 1\n else\n point[teamb] += 3\n end\n game[teama] += 1\n game[teamb] += 1\n diff[teama] += score[0] - score[1]\n diff[teamb] += score[1] - score[0]\n earn[teama] += score[0]\n earn[teamb] += score[1]\nend\nopponent = game.index(2)\nfound = false\nfi = nil\nfj = nil\n1.upto(50) do |i|\n diff[0] += i\n diff[opponent] -= i\n i.upto(50) do |j|\n earn[0] += j\n earn[opponent] += j-i\n rank = (0..3).sort{|a,b| (point[a]<=>point[b])*8+(diff[a]<=>diff[b])*4+(earn[a]<=>earn[b])*2-(Teams[a]<=>Teams[b])}.index(0)\n if rank > 1\n found = true\n fj = j\n break\n end\n earn[0] -= j\n earn[opponent] -= j-i\n end\n if found\n fi = i\n break\n end\n diff[0] -= i\n diff[opponent] += i\nend\nif found\n puts fj.to_s+\":\"+(fj-fi).to_s\nelse\n puts \"IMPOSSIBLE\"\nend\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "e8d00232d95e34f7337d56d212f2e4eb", "src_uid": "5033d51c67b7ae0b1a2d9fd292fdced1", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#ruby 2.4.1 \n\nrequire \"prime\"\nt = gets.to_i\nt.times do |a, b|\n\tflag = false\n\tnums = \"\"\n\tnums = gets\n\ta1, b1 = nums.split(' ')\n\ta = a1.to_i\n\tb = b1.to_i\n\tif Prime.prime?(a + b) == true && (a + b) * (a - b) == (a + b)\n\t\tputs \"YES\"\n\telse\n\t\tputs \"NO\"\n\tend\nend", "lang_cluster": "Ruby", "tags": ["math", "number theory"], "code_uid": "10c7133f7dbaa61b53ae6abb0bfa8e6d", "src_uid": "5a052e4e6c64333d94c83df890b1183c", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby 3", "source_code": "h, w = gets.split.map(&:to_i)\r\ngrid = h.times.map { gets.chomp }\r\n\r\ni, j, count = 0, 0, 0\r\n\r\nloop do\r\n count += 1 if grid[i][j] == \"*\"\r\n\r\n if i == h - 1 && j == w - 1\r\n break\r\n elsif i == h - 1\r\n j += 1\r\n elsif j == w - 1\r\n i += 1\r\n elsif grid[i + 1][j] == \"*\"\r\n i += 1\r\n else\r\n j += 1\r\n end\r\nend\r\n\r\np count\r\n", "lang_cluster": "Ruby", "tags": ["greedy", "implementation", "shortest paths"], "code_uid": "d7cde850c3d74bfe77126cb9d782f11b", "src_uid": "f985d7a6e7650a9b855a4cef26fd9b0d", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "# https://codeforces.com/problemset/problem/1242/A\n\nrequire 'set'\n\nn = gets.to_i\n\ndividers = Set.new []\n\ni = 2\nsize = n\n\nwhile i * i <= n\n if n % i == 0\n dividers.add(i)\n n /= i\n i -= 1\n end\n i += 1\nend\n\ndividers.add(n) if n > 1 \n\narr = []\ndividers.each { |num| arr << num }\n\nif arr[0] == size\n puts size\nelsif arr.size == 1\n puts arr[0]\nelse\n puts 1\nend\n", "lang_cluster": "Ruby", "tags": ["math", "constructive algorithms", "number theory"], "code_uid": "ef92df3e568cfe65d512908b5fb237ba", "src_uid": "f553e89e267c223fd5acf0dd2bc1706b", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/ruby\nk,a,b=gets.split.map(&:to_i)\nif amax_a || b>max_b\n\tputs -1\nelse\n\tputs win_a+win_b\nend\n#\u60c5\u51b5\u63a2\u8ba8\u662f\uff1a\u5982\u679c\u67d0\u4e2a\u4eba\u8d62\u4e86x\u573a\u6bd4\u8d5b\uff0c\u5219\u53e6\u4e00\u4e2a\u4eba\u7684\u5f97\u5206\u662f0\uff5ex*(k-1)\n#\n#win_a=a/k\n#win_a_max_b=(a/k)*(k-1)\n#win_b=b/k\n#win_b_max_a=(b/k)*(k-1)\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "8e6ef4b841edb70c12089c665a24b00a", "src_uid": "6e3b8193d1ca1a1d449dc7a4ad45b8f2", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "nm = gets.chomp.split(\" \").map(&:to_i)\nn = nm[0]\nm = nm[1]\n\ndef findfor(x,y,k)\n count = 0\n (1..x).each do |a|\n (1..y).each do |b|\n if (a**2+b**2)%k==0\n count += 1\n end\n end\n end\n return count\nend\n\nif n\" && ver[-1] == \"^\") || \n (hori[-1] == \"<\" && ver[0] == \"v\") || (hori[-1] == \">\" && ver[-1] == \"v\")\n puts \"NO\"\nelse\n puts \"YES\"\nend\n", "lang_cluster": "Ruby", "tags": ["dfs and similar", "implementation", "graphs", "brute force"], "code_uid": "eaa7743b5d623c2646b18cb12635dfa9", "src_uid": "eab5c84c9658eb32f5614cd2497541cf", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "gets.chomp.split\nh = gets.chomp.split('')\nv = gets.chomp.split('')\n\nputs ((h[0] == '<' && v[0] == '^') ||\n (h[0] == '>' && v[0] == 'v') ||\n (h[-1] == '>' && v[-1] == 'v') ||\n (h[-1] == '<' && v[-1] == '^') ||\n (h[0] == '>' && v[-1] == '^') ||\n (h[-1] == '<' && v[0] == 'v')) ? \"NO\" : \"YES\"", "lang_cluster": "Ruby", "tags": ["dfs and similar", "implementation", "graphs", "brute force"], "code_uid": "c0f5b28cd6fcc3a0efb01f4b2fe5704a", "src_uid": "eab5c84c9658eb32f5614cd2497541cf", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["dfs and similar", "implementation", "graphs", "brute force"], "code_uid": "ea6ed692aafbb3cb5d098cd935804cb3", "src_uid": "eab5c84c9658eb32f5614cd2497541cf", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby 3", "source_code": "#!/usr/bin/env ruby\n\nx = gets.to_i\nif x < 1200\n puts 1200\nelsif x < 1400\n puts 1400\nelsif x < 1600\n puts 1600\nelsif x < 1900\n puts 1900\nelsif x < 2200\n puts 2200\nelsif x < 2300\n puts 2300\nelsif x < 2400\n puts 2400\nelsif x < 2600\n puts 2600\nelse\n puts 3000\nend\n", "lang_cluster": "Ruby", "tags": ["math", "divide and conquer", "implementation"], "code_uid": "082d46b941de0fd1d15edfc0d1a81d0a", "src_uid": "22725effa6dc68b9c2a499d148e613c2", "difficulty": -1.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, m = gets.chomp.split.map(&:to_i)\n\ndef fromdec(n)\n return '0' if n == 0\n rtn = \"\"\n while 0 < n.to_i\n rtn = (n.to_i % 7).to_s + rtn\n n = (n.to_i / 7).to_s\n end\n return rtn\nend\n\ndef todec(n)\n rtn = 0\n (0...n.size).each do |i| \n rtn += n[i].to_i * 7 ** (n.size - i - 1)\n end\n return rtn\nend\n\nln = fromdec(n - 1).size\nlm = fromdec(m - 1).size\n\nans = 0\n(0...7).to_a.permutation(ln + lm) do |ps|\n pn = (0...ln).inject('') { |str , i| str + ps[i].to_s }\n pm = (ln...ln + lm).inject('') { |str , i| str + ps[i].to_s }\n if todec(pn) < n && todec(pm) < m\n ans = ans + 1\n end\nend\n\nputs ans\n\n", "lang_cluster": "Ruby", "tags": ["brute force", "math", "combinatorics"], "code_uid": "2fe3167c8da5f9a9856f4fd79a5ef985", "src_uid": "0930c75f57dd88a858ba7bb0f11f1b1c", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def cmmdc a,b\n return [a,b].max if a*b==0\n return cmmdc([a,b].min,[a,b].max % [a,b].min)\nend\n\nn,m,x,y,a,b = gets.chomp.split(\" \").collect {|x| x.to_i}\n\ncmm = cmmdc(a,b)\na /= cmm\nb /= cmm\n\np = n/a\nq = m/b\n\nmin = [p,q].min\n\np = min * a\nq = min * b\n\n\ndelta_center_x = p/2.0\ndelta_center_y = q/2.0\n\nc1x = delta_center_x\nc1y = delta_center_y\n\nc2x = n - delta_center_x\nc2y = m - delta_center_y\n\n\nrx = 0\nry = 0\n\n\nif xc2y\n rx = c1x\n ry = c2y\nend\n\nif x>c2x and yc2x and y>c2y\n rx = c2x\n ry = c2y\nend\n\nif x>=c1x and x<=c2x and y=c1x and x<=c2x and y>c2y\n ry = c2y\n if (c1x-x).ceil == (c1x-x).floor\n rx = x\n else\n rx = x - 0.5\n end\nend\n\nif y>=c1y and y<=c2y and x=c1y and y<=c2y and x>c2x\n rx = c2x\n if (c1y-y).ceil == (c1y-y).floor\n ry = y\n else\n ry = y - 0.5\n end\nend\n\nif y>=c1y and y<=c2y and x>=c1x and x<=c2x\n if (c1x-x).ceil == (c1x-x).floor\n rx = x\n else\n rx = x - 0.5\n end\n if (c1y-y).ceil == (c1y-y).floor\n ry = y\n else\n ry = y - 0.5\n end\nend\n\nputs [rx-delta_center_x,ry-delta_center_y,rx+delta_center_x,ry+delta_center_y].map {|x| x.to_i}.join(' ')\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "a1c11bface6a9686f2576f739f6f4b0d", "src_uid": "8f1211b995f35462ae83b2be27f54585", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b=gets.chomp.split(' ').map(&:to_i)\ntmp=a.gcd(b)\na/=tmp\nb/=tmp\nctr=0\nwhile a%2==0\n\ta/=2\n\tctr+=1\nend\nwhile b%2==0\n\tb/=2\n\tctr+=1\nend\nwhile a%3==0\n\ta/=3\n\tctr+=1\nend\nwhile b%3==0\n\tb/=3\n\tctr+=1\nend\nwhile a%5==0\n\ta/=5\n\tctr+=1\nend\nwhile b%5==0\n\tb/=5\n\tctr+=1\nend\nif a+b > 2\n\tputs \"-1\"\nelse\n\tputs ctr\nend", "lang_cluster": "Ruby", "tags": ["math", "number theory"], "code_uid": "e3c2b59a8b3ae368070037c48f885f82", "src_uid": "75a97f4d85d50ea0e1af0d46f7565b49", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "/(?[\\d]+) (?[\\d]+)/ =~ gets.chomp\na = a.to_i\nb = b.to_i\n\ndef bite(size, mults=[2, 3, 5])\t# => [b*2, b*3, b*5, leftovers || 1]\n\tbitesizes = []\n\tmults.each do |mult|\n\t\tbite = 0\n\t\tbite, size = (bite+1), (size/mult) while (size%mult)==0\n\t\tbitesizes << bite\n\tend\n\tbitesizes << size\n\treturn bitesizes\nend\n\n*bitesA, leftA = bite(a)\n*bitesB, leftB = bite(b)\n\nif (leftA != leftB)\n\tputs -1\nelse\n\tp (bitesA.zip(bitesB).map{ |bA, bB|\n\t\t(bA-bB).abs\n\t}.reduce(&:+))\nend\n", "lang_cluster": "Ruby", "tags": ["math", "number theory"], "code_uid": "d2d27c100de1afc863b8ae9ffd823daf", "src_uid": "75a97f4d85d50ea0e1af0d46f7565b49", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "x=gets.to_i\n(2..Math.sqrt(x)).each do |i|\n if x.modulo(i)==0\n puts \"#{i}#{x/i}\"\n end\nend", "lang_cluster": "Ruby", "tags": ["math", "number theory"], "code_uid": "bcaf6b74893f0a887474a1ff173525ad", "src_uid": "7220f2da5081547a12118595bbeda4f6", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "k,n,s,q=gets.split.map &:to_i\np~-((n+~-s)/s*k+q)/q", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "1901c3617bf5da3418dd8d98c3019626", "src_uid": "73f0c7cfc06a9b04e4766d6aa61fc780", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby 3", "source_code": "require 'set'\r\n\r\nt = gets\r\n(1..t.to_i).each do |ind|\r\n n = gets\r\n i = 1\r\n n = n.to_i\r\n st = Set[]\r\n while i*i <= n\r\n st << i*i\r\n i += 1\r\n end\r\n i = 1\r\n while i*i*i <= n\r\n st << i*i*i\r\n i += 1\r\n end\r\n puts st.size\r\nend\r\n ", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "1cd8fb6bad3211388487e1f77da623fd", "src_uid": "015afbefe1514a0e18fcb9286c7b6624", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def run target, left, right, result\n if target[0] == 1\n print (target[1] - 1), 'B'\n puts\n return true\n end\n if target[1] == 1\n print (target[0] - 1), 'A'\n puts\n return true\n end\n if target[0].gcd(target[1]) > 1\n puts \"Impossible\"\n return false\n end\n if (target[0] - target[1]).abs == 1\n result = []\n num = target[0] > target[1] ? target[1] : target[0]\n char = target[0] > target[1] ? 'B' : 'A'\n print 1, (char == 'A' ? 'B' : 'A')\n if num > 1\n print (num - 1), char\n end\n puts\n return true\n end\n while true\n median = [left[0] + right[0], left[1] + right[1]]\n\n if fract_compare(median, target) == 0\n if median[0] != target[0]\n puts \"Impossible\"\n return false\n end\n puts string_compress result\n return true\n end\n\n if median[0] > target[0] || median[1] > target[1]\n puts \"Impossible\"\n return false\n end\n\n if fract_compare(median, target) > 0\n result << 'B'\n right[0] = median[0]\n right[1] = median[1]\n else\n result << 'A'\n left[0] = median[0]\n left[1] = median[1]\n end\n end\nend\n\ndef fract_compare a, b\n return a[0] * b[1] - a[1] * b[0]\nend\n\ndef string_compress s\n current_total = 0\n prev = \"\"\n size = s.size\n result = []\n s.each_with_index do |cur, i|\n if prev == cur\n current_total += 1\n else\n if prev != \"\"\n result << current_total\n result << prev\n end\n current_total = 1\n prev = cur\n end\n if i == (size - 1)\n result << current_total\n result << prev\n end\n end\n return result.join\nend\n\ntarget = gets.chomp.split(\" \").map{ |i| i.to_i }\nleft = [0, 1]\nright = [1, 0]\nresult = []\nrun target, left, right, result\n", "lang_cluster": "Ruby", "tags": ["number theory"], "code_uid": "eb13ab503d3cb1316961e1b6c0a8431a", "src_uid": "6a9ec3b23bd462353d985e0c0f2f7671", "difficulty": 2400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.to_i\ni=2\ni+=1 while i*i0\np 1+(i*i<=n ? (n-i)/2 : 0)", "lang_cluster": "Ruby", "tags": ["math", "implementation", "number theory"], "code_uid": "2842d3d7744681e25ec780b52b38c648", "src_uid": "a1e80ddd97026835a84f91bac8eb21e6", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "$a = [\n\t[],\n\t[0, 0, 0, 0, 0, 0],\n\t[0, 1, 3, 6, 0, 0],\n\t[0, 1, 2, 3, 5, 6]]\n\ndef gao(m, n)\n\treturn m > 5 ? 0 : $a[n][m] if n < 4\n\ts = n / 2\n\treturn 1 if m <= s\n\ts += (n - 1) / 2\n\treturn 2 if m <= s\n\ts += n / 2 - 1\n\treturn 3 if m <= s\n\ts += (n - 1) / 2\n\treturn 4 if m <= s\n\tt = n / 2 - 1\n\treturn t <= 0 ? 0 : 4 + (m - s + t - 1) / t\nend\n\nm, n = gets.split.map(&:to_i)\np gao(m, n) * 2 - 1\n", "lang_cluster": "Ruby", "tags": ["greedy"], "code_uid": "15897fe797280b2532bc577d93c6fe30", "src_uid": "83f1d50a1802e08dd154d4c9778e3d80", "difficulty": 2500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, m , k=gets.split.map(&:to_i)\n\nif k<=n-1\n puts \"#{k+1} 1\"\n exit 0\nend\n\nk-=(n-1)\na=(k-1)/((m-1)*2)\nx=n-a*2\nb=((k-1)% ((m-1)*2))+1\nx-=1 if b>m-1\nif b<=m-1\n puts \"#{x} #{1+b}\"\nelse\n puts \"#{x} #{m-(b-(m-1)-1)}\"\nend\n\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "deb272fe11c96b9adf14529119eb22f6", "src_uid": "e88bb7621c7124c54e75109a00f96301", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, m, k = gets.split.map(&:to_i)\nif k < n\n puts \"#{k + 1} 1\"\nelse\n hoge = (m - 1) * 2\n k -= n\n r = n - k / hoge * 2\n tmp = k % hoge\n c = 0\n if tmp < m - 1\n c = tmp + 2\n else\n c = 2 * (m - 1) - tmp + 1\n r -= 1\n end\n puts \"#{r} #{c}\"\nend", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "c29ef47609622cbfd7aec3a6b848ec0e", "src_uid": "e88bb7621c7124c54e75109a00f96301", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "MOD=10**9+7\ncnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)\ndef gs() gets.chomp end\ndef gi() gets.to_i end\ndef gsmi() gets.chomp.split.map(&:to_i) end\n\ndef desc(ar) ar.sort!{|x,y|y<=>x} end\ndef min(a,b) a<=b ? a : b end\ndef max(a,b) a>=b ? a : b end\ndef sum(ar) ar.inject(:+) end\n\n#def bs(ar,eq,n) en=(eq==1 ? :>= : :>); ar.bsearch_index{|x|x.send(en,n)} end\ndef C(a,b) b==0||a==b ? 1 : (b=a-b if a/20 do\n d = b/10\n m = b%10\n ans*=(base**m)\n ans%=MOD\n base = (base**10)%MOD\n b=d\n end\n ans\nend\n\np1 = pow(2,m) - 1\nans = pow(p1,n)%MOD\n\nputs ans", "lang_cluster": "Ruby", "tags": ["math", "combinatorics"], "code_uid": "cbcf4d608271cb0a56d5bc64b91de82d", "src_uid": "71029e5bf085b0f5f39d1835eb801891", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "MOD = 10**9+7\ndef modpow(x,n)\n ret = 1\n while n > 0\n ret = ret*x % MOD if n&1 == 1\n x = x*x % MOD\n n >>= 1\n end\n return ret\nend\n\nn,m = gets.split.map(&:to_i)\n\np modpow((modpow(2,m) - 1),n)", "lang_cluster": "Ruby", "tags": ["math", "combinatorics"], "code_uid": "370b29b84487dd09a6e0eb3a9769e8bf", "src_uid": "71029e5bf085b0f5f39d1835eb801891", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "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", "lang_cluster": "Ruby", "tags": ["math", "greedy", "number theory", "brute force"], "code_uid": "0e722903b2edc4ca7a4bb8af224482a7", "src_uid": "23f2c8cac07403899199abdcfd947a5a", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def read_next_line\n gets.chomp.split.map(&:to_i)\nend\n\ndef read(range)\n g = []\n range.each {\n g << read_next_line\n }\n g\nend\n\nmatrix_size = 5\n\nr = (0...matrix_size)\ng = read(r)\nmax = 0\nr.to_a.permutation.each { |p|\n happ = 0\n line = r.to_a\n while line.size > 1\n n = line.size\n n -= n % 2\n (0...n).step(2) { |i|\n happ += g[p[line[i]]][p[line[i + 1]]] + g[p[line[i + 1]]][p[line[i]]]\n }\n line.shift\n end\n max = happ if happ > max\n}\nputs max", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "56710fd403bd58ffa4d68e705db06aaf", "src_uid": "be6d4df20e9a48d183dd8f34531df246", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\nary = gets.strip.split('').map(&:to_i)\n\nif ary.uniq == [0]\n puts \"YES\"\n exit 0\nend\n\n# lim = (n * 9) + 10\nlim = ary.inject(:+) - 1\n\ndef poss?(ary, ss)\n i=0\n sum = 0\n sz = ary.size\n while i ss\n return false\n end\n i += 1\n end\n sum == 0\nend\n\n1.upto(lim).each do |ss|\n if poss?(ary, ss)\n # puts ss\n puts \"YES\"\n exit 0\n end\nend\n\nputs \"NO\"", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "f612046d6fb45b5a5fe203795bd9255c", "src_uid": "410296a01b97a0a39b6683569c84d56c", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a, b = gets.strip.split.map{|s|s.to_i}\nif a == b\n puts 'Equal'\n exit\nend\nd = a * b / a.gcd(b)\nfa = d / a\nfb = d / b\na < b ? fa -= 1 : fb -= 1\nif fa > fb\n puts 'Dasha'\nelsif fa < fb\n puts 'Masha'\nelse\n puts 'Equal'\nend\n", "lang_cluster": "Ruby", "tags": ["math", "implementation", "number theory"], "code_uid": "efdc75b503a469245a7f0ec4904945da", "src_uid": "06eb66df61ff5d61d678bbb3bb6553cc", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/env ruby\n\nn, l, r = gets.split.map(&:to_i)\n# 0: 1:&1 2:size 3:1_c\none_map = { 1 => [ [1], 1, 1, 1 ],\n\t\t\t0 => [ [0], 0, 1, 0 ] }\n\nstack = []\n\nc = n\nwhile c > 1\n stack << c\n d = c >> 1\n one_map[c] = [d, c&1]\n c = d\nend\n\n#p stack\n\nlast = one_map[c]\nwhile d = stack.pop\n cur = one_map[d]\n\n # size\n cur[2] = last[2] * 2 + 1\n # 1_c\n cur[3] = last[3] * 2 + cur[1]\n\n last = cur\nend\n\nc_start = l - 1\nc_end = r - 1\n\ndef give_one_count(n, c_s, c_e, one_map)\n #p \"n:#{n} c_s:#{c_s} c_e:#{c_e} one_map:#{one_map}\"\n n_map = one_map[n]\n\n return n_map[3] if c_s == 0 && (c_e + 1) == n_map[2]\n\n mid = n >> 1\n mid_size = n_map[2] >> 1\n\n count = 0\n\n if c_s < mid_size\n\t#p \"#{n} a\"\n count += give_one_count(mid, c_s, [c_e, mid_size - 1].min, one_map)\n end\n\n if mid_size >= c_s && mid_size <= c_e\n\t#p \"#{n} m\"\n\tcount += n_map[1]\n end\n\n if c_e > mid_size\n\t#p \"#{n} b\"\n count += give_one_count(mid, [c_s - 1 - mid_size, 0].max , c_e - 1 - mid_size, one_map)\n end\n\n count\nend\n\nputs give_one_count(n, c_start, c_end, one_map)\n", "lang_cluster": "Ruby", "tags": ["dfs and similar", "divide and conquer", "constructive algorithms"], "code_uid": "1aa1158b5eeaa2cef9fb26e8f9838e79", "src_uid": "3ac61b1f8deee7911b1055c243f5eb6a", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b=gets.split\nidx=(1...a.size).find{|i|a[i]>=b[0]}||a.size\nputs a[0...idx]+b[0]", "lang_cluster": "Ruby", "tags": ["brute force", "sortings", "greedy"], "code_uid": "3dbb740783bfc81af5f2681705df196d", "src_uid": "aed892f2bda10b6aee10dcb834a63709", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a, b=gets.split\na+=b\ni=1\ni+=1 while a[i] && a[i]=0\n res=0.0\n if t==0 then\n res+=w.to_f/(w+b)\n res+=b.to_f/(w+b)*solve(w,b-1,1-t)\n else\n #W\u3092\u53d6\u308b\n res=0\n #B\u3092\u53d6\u308b\n tb=b-1\n tw=w\n if tb+tw==0 then\n res=0\n else\n res+=b.to_f/(w+b)*tb.to_f/(tb+tw)*solve(w,b-2,1-t)\n res+=b.to_f/(w+b)*tw.to_f/(tb+tw)*solve(w-1,b-1,1-t)\n end\n end\n return $dp[w][b][t]=res\nend\np solve(w,b,0)\n", "lang_cluster": "Ruby", "tags": ["math", "dp", "probabilities", "games"], "code_uid": "e5e4be7035387b2f9ee45fc2de2debe9", "src_uid": "7adb8bf6879925955bf187c3d05fde8c", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "c = gets.chomp.split(\" \").map{|i| i.to_i}\n\na = c[0]\nb = c[1]\nk = c[2]\n\nL = []\n\n(1..b).each do |i|\n L[i] = 1\nend\nL[1] = 0\n\n(2..b).each do |i|\n kq = 2*i\n if L[i] == 1\n while kq <= b do\n L[kq] = 0\n kq += i\n end\n end\nend\n\ndem = 0\nP = []\nmax = 0\n\n(a..b).each do |i|\n if L[i] == 1\n dem += 1\n P[dem] = i\n end \nend\n\nif dem < k\n max = -1\nelse\n max = b - P[dem-k+1] + 1\n if max < (P[k] - a + 1)\n max = P[k] -a + 1\n end\n j = dem - k \n (1..j).each do |i|\n if (P[i+k] - P[i]+1) > max\n max = P[i+k] - P[i] \n end\n end\nend\n\nputs max", "lang_cluster": "Ruby", "tags": ["two pointers", "binary search", "number theory"], "code_uid": "210aed327987b4c23ab5ef91cf8e3579", "src_uid": "3e1751a2990134f2132d743afe02a10e", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "low=[]\nst=[]\ncur=1989\nstep=10\n(1..10).each{|i|\n\tlen=cur.to_s.length\n\tst< 0\n\t\tnextc = nil\n\t\twhile str[i] != '?' && i < b.length\n\t\t\tprevc = str[i]\n\t\t\ti += 1\n\t\tend\n\t\tnextc = b[i+1]\n\t\tif i < b.length\n\t\t\tcola = cols - [prevc, nextc]\n\t\t\tcola.each do |col|\n\t\t\t\tstr[i] = col\n\t\t\t\tout = permute(b, cols, i+1, str.dup, out)\n\t\t\t\tstr[i] = '?'\n\t\t\tend\n\t\telse\n\t\t\tout.push(str)\n\t\tend\n\tend\n\treturn out\nend\nif valids(b)\n\tout = permute(b, COLORS, 0, b.dup, [])\n\tif out.length >= 2\n\t\tputs \"Yes\"\n\t\t\n\telse\n\t\tputs \"No\"\n\tend\nelse\n\tputs \"No\"\nend\n\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "60ad6007f12ce57d34385972788899fa", "src_uid": "f8adfa0dde7ac1363f269dbdf00212c3", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = gets.chomp\nt = gets.chomp\ndivs = []\ndivt = []\n(s.length-1).times do |i|\n divs.push(i) if s[i] != s[i+1]\nend\ndivs.push(s.length-1)\n(t.length-1).times do |i|\n divt.push(i) if t[i] != t[i+1]\nend\ndivt.push(t.length-1)\n\nans = []\n\nif s[0] == t[0] && divs.length > 1 && divt.length > 1\n ps, pt = nil, nil\n diff = divt.length - divs.length\n idx = diff.abs/4*2+1\n if diff >= 2\n ps = divs[0]+1\n pt = divt[idx]+1\n elsif diff <= -2\n ps = divs[idx]+1\n pt = divt[0]+1\n end\n if ps\n ans.push([ps, pt])\n s, t = [\n t[0, pt] + s[ps, s.length],\n s[0, ps] + t[pt, t.length]\n ]\n divs = []\n divt = []\n (s.length-1).times do |i|\n divs.push(i) if s[i] != s[i+1]\n end\n divs.push(s.length-1)\n (t.length-1).times do |i|\n divt.push(i) if t[i] != t[i+1]\n end\n divt.push(t.length-1)\n end\nend\n\n\nif divs.length == 1 && divt.length == 1\n puts 0\n exit\nend\n\nif s[0] == t[0]\n if divs.length < divt.length\n ns = 0\n nt = (divt.length - divs.length)/2\n nt += 1 if nt % 2 == 0\n else\n nt = 0\n ns = (divs.length - divt.length)/2\n ns += 1 if ns % 2 == 0\n end\nelse\n if divs.length < divt.length\n ns = 1\n nt = (divt.length - 1 - divs.length)/2 + 1\n nt += 1 if nt % 2 == 0\n else\n nt = 1\n ns = (divs.length - 1 - divt.length)/2 + 1\n ns += 1 if ns % 2 == 0\n end\nend\n\nps = ns == 0 ? 0 : divs[ns-1]+1\npt = nt == 0 ? 0 : divt[nt-1]+1\nans.push([ps, pt])\ns, t = [\n t[0, pt] + s[ps, s.length],\n s[0, ps] + t[pt, t.length]\n]\n\ndivs = []\ndivt = []\n(s.length-1).times do |i|\n divs.push(i) if s[i] != s[i+1]\nend\ndivs.push(s.length-1)\n(t.length-1).times do |i|\n divt.push(i) if t[i] != t[i+1]\nend\ndivt.push(t.length-1)\n\nmax = [divs.length, divt.length].max\n[max-2, max-1].each do |i|\n next if i < 0\n divs[i] ||= divs[-1]\n divt[i] ||= divt[-1]\nend\n\nps, pt = 0, 0\n(max-1).times do |i|\n ps += divs[i] - (i > 0 ? divs[i-1] : -1)\n pt += divt[i] - (i > 0 ? divt[i-1] : -1)\n ans.push([ps, pt])\n ps, pt = pt, ps\nend\n\nputs ans.length\nans.each do |arr|\n puts arr.join(' ')\nend", "lang_cluster": "Ruby", "tags": ["strings", "constructive algorithms"], "code_uid": "48e9740f9f2cc12a94a2b558d710205e", "src_uid": "4a50c4147becea13946272230f3dde6d", "difficulty": 2800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "require 'prime'\n\ndef f(a,b)\n c=0\n x = Prime.prime_division(a)\n while b>0 do\n tmp = b\n x.each do |ar|\n tmp = [tmp, b%ar[0]].min\n end\n c += tmp\n b -= tmp\n x.each do |ar|\n while b%ar[0]==0\n b/=ar[0]\n ar[1]-=1\n if ar[1] == 0\n x.delete(ar)\n break\n end\n end\n end\n end\n return c\nend\n\ninput = gets.chomp\na = input.split(\" \")[0].to_i\nb = input.split(\" \")[1].to_i\nputs f(a,b)\n", "lang_cluster": "Ruby", "tags": ["math", "implementation", "binary search"], "code_uid": "04d7dadfa9ac968c0dd4a4e00f132205", "src_uid": "ea92cd905e9725e7fcb87b9ed4f64c2e", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "p, x, y = gets.chomp.split(\" \").map(&:to_i)\n\ndef tshirt(s)\n ret = []\n i = (s / 50) % 475\n 25.times do\n i = (i * 96 + 42) % 475\n ret << (26 + i)\n end\n return ret\nend\n\nif x > y then\n d = ((x - y) / 50.0).floor\n xx = x - (d * 50)\n while true\n if tshirt(xx).include?(p) then\n puts 0\n exit\n elsif xx >= x then\n break\n end\n xx += 50\n end\nend\n\nd = ([0, y - x].max / 50.0).ceil\n\nx += (d * 50)\n\nwhile true\n break if tshirt(x).include?(p)\n x += 50\n d += 1\nend\n\nif d.even?\n puts d / 2\nelse\n puts d / 2 + 1\nend\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "096481f8b8a02e0b7fb9fe7f7c46e4fa", "src_uid": "c9c22e03c70a94a745b451fc79e112fd", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def ascan; gets.split.map(&:to_i); end\nrequire 'prime'\n\ndef funcd(n, div)\n total = 0\n while n >= div\n total += n/div\n n /= div\n end\n total\nend\n\nn,b = ascan\n\np b.prime_division.map{|pr,nm| funcd(n,pr)/nm}.min\n", "lang_cluster": "Ruby", "tags": ["brute force", "math", "implementation", "number theory"], "code_uid": "0a146082d22b3442d2a1298c1128e959", "src_uid": "491748694c1a53771be69c212a5e0e25", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nans = 10**9\nfor i in 0..n\n ret = 0\n for j in 0..n-1\n ret += ((j-i).abs+j+i)*a[j]*2\n end\n ans = ret if ans > ret\nend\nputs ans", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "023218281ef2891708fd9a829741b38e", "src_uid": "a5002ddf9e792cb4b4685e630f1e1b8f", "difficulty": 1000, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, m = gets.split.map(&:to_i)\na = gets.split.map(&:to_i).sort.reverse\n\nputs (1..n).bsearch { |day|\n\t\tminus, cnt = 0, 0\n\t\t(0...n).sum { |i|\n\t\t\tres = [0, a[i] - minus].max\n\t\t\tcnt += 1\n\t\t\tif cnt == day\n\t\t\t\tminus += 1\n\t\t\t\tcnt = 0\n\t\t\tend\n\t\t\tres\n\t\t} >= m\n } || -1\n", "lang_cluster": "Ruby", "tags": ["brute force", "greedy"], "code_uid": "3f2726e14356e50bfae9a4b41418abcd", "src_uid": "acb8a57c8cfdb849a55fa65aff86628d", "difficulty": 1700, "exec_outcome": "PASSED"}