{"lang": "Ruby", "source_code": "ns,ms = gets.chomp.split(/ /)\nn = ns.to_i\nm = ms.to_i\nar = Array.new(m)\nfor i in 0..m-1\n\ts = gets.chomp\n\tar[i] = s.split(/ /).map! {|x| x.to_i }\nend\n\nar.sort! { |a,b| b[1] <=> a[1] }\n\nret = 0\nwk = n\nfor i in 0..m-1\n\tbreak if wk <= 0\n\tt = [wk, ar[i][0]].min\n\tret += t * ar[i][1]\n\twk -= t\nend\n\nputs ret", "lang_cluster": "Ruby", "tags": ["sortings", "implementation", "greedy"], "code_uid": "730c8b47fdb345ac6d58a6cb0c0e101e", "src_uid": "c052d85e402691b05e494b5283d62679", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "p 4-(gets.split|$*).size\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "57760d9567715839254f3ddc65e5758b", "src_uid": "38c4864937e57b35d3cce272f655e20f", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a, c = gets.split.map{ |x|\n (x.to_i.to_s(3).reverse+\"0\"*50).split(\"\").map(&:to_i)\n}\n[a.length, c.length].min.times{ |i|\n c[i] = (c[i]-a[i]+3) % 3 \n}\np c.join(\"\").reverse.to_i(3)\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "adc21ba7bc3108f9c664ba08ca60e62f", "src_uid": "5fb635d52ddccf6a4d5103805da02a88", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\nn *= -1 if n.odd?\nputs n/2\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "e088a03ab8ab445b3a96b063fa86615e", "src_uid": "689e7876048ee4eb7479e838c981f068", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "\nn, m = gets.split.map(&:to_i)\ntab = gets.split.map(&:to_i)\n\nresult, i = 0, 0\n\nwhile true\n temp = m\n while i < tab.size && temp - tab[i] >= 0\n temp -= tab[i]\n i += 1\n end\n result += 1\n if i == tab.size \n break\n end\nend\n\nputs result\n\n\n\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "4e53d55fd3807d5c47b182e53602ebd4", "src_uid": "5c73d6e3770dff034d210cdd572ccf0f", "difficulty": 1000.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+q-1)/q+1", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "271b296bfdf8839020fec87db5414329", "src_uid": "c7aa8a95d5f8832015853cffa1374c48", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, s, c = gets.split.map(&:to_i)\nd = gets =~ /tail/ ? 1 : -1\ngets.scan(/[01]/).each_with_index do |w, i|\n\ts = c if w == ?1\n\td = 1 if c == 1\n\td = -1 if c == n\n\tc += d\n\ts += d if s == c\n\tunless (1 .. n).include? s\n\t\tputs \"Controller #{i + 1}\"\n\t\texit\n\tend\nend\nputs :Stowaway\n\n", "lang_cluster": "Ruby", "tags": ["greedy", "dp", "games"], "code_uid": "fbaa5a810e649529da5f99c3a92609af", "src_uid": "2222ce16926fdc697384add731819f75", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def solution(n, k, d)\n @memo = Array.new(2) { Array.new(n+1, false) }\n def solve(n, k, d, flag)\n return @memo[(flag ? 1 : 0)][n] if @memo[(flag ? 1 : 0)][n]\n return 1 if n == 0 && flag\n return 0 if n == 0 && !flag\n cnt = 0\n for i in 1..k do\n cnt += solve(n-i, k, d, flag || (i >= d)) if n-i >= 0\n end\n @memo[(flag ? 1 : 0)][n] = cnt\n end\n solve(n, k, d, false)\n @memo[0][n] % 1000000007\nend\n\nputs solution(*gets.split.map(&:to_i))\n", "lang_cluster": "Ruby", "tags": ["dp", "implementation", "trees"], "code_uid": "303e09d1ea7899d10e6145891a1a7541", "src_uid": "894a58c9bba5eba11b843c5c5ca0025d", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a = gets.chomp\nb = gets.chomp\nfor i in (0..a.length-1)\n a[i] = ((a[i].to_i + b[i].to_i)%2).to_s\nend\nputs a\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "8c6ad4b44357e9c404790fadd4d31cf2", "src_uid": "3714b7596a6b48ca5b7a346f60d90549", "difficulty": 800.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": "635e11099ffa4d784bad89133978af5f", "src_uid": "1cad9e4797ca2d80a12276b5a790ef27", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a = gets.chomp.split.collect{|var| var.to_i}\nx = a[0] - ((Math.sqrt(9 + 8*(a[0]+a[1])) - 3)/2)\nputs (x).to_i", "lang_cluster": "Ruby", "tags": ["brute force", "math", "binary search"], "code_uid": "ce6996c10b5709e54ad034d7747cf727", "src_uid": "17b5ec1c6263ef63c668c2b903db1d77", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\n\nfor i in 0 ... n\n for j in i ... n\n # increasing in [0, i]?\n ok = true\n for k in 0 ... i\n if a[k] >= a[k + 1]\n ok = false\n break\n end\n end\n if not ok\n next\n end\n for k in j ... n - 1\n if a[k] <= a[k + 1]\n ok = false\n break\n end\n end\n if not ok\n next\n end\n if a[i .. j].uniq.size != 1\n next\n end\n puts 'YES'\n exit\n end\nend\nputs 'NO'\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "bc30b0420af559304598ed8a8fdf6264", "src_uid": "5482ed8ad02ac32d28c3888299bf3658", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b=gets.split.map &:to_i\np [a,b,(a+b)/3].min\n", "lang_cluster": "Ruby", "tags": ["math", "greedy", "implementation", "number theory"], "code_uid": "9f9afac06b659da3bd2e5f41e7112fcd", "src_uid": "0718c6afe52cd232a5e942052527f31b", "difficulty": 1300.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": "621720ad48b522182d0962c750cad978", "src_uid": "44bed0ca7a8fb42fb72c1584d39a4442", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "num=gets.chomp!.scan(/./)\nnum.length.times do |i|\n num[i]=num[i].to_i\nend\nnum.sort!\nj=0\nwhile num[j]==0\n j+=1\nend\nif j!=num.length\n num[0],num[j]=num[j],num[0]\nend\nif num.join == gets.chomp!\n puts \"OK\"\nelse\n puts \"WRONG_ANSWER\"\nend\n\n", "lang_cluster": "Ruby", "tags": ["sortings", "implementation"], "code_uid": "41dd4fb12fe170f288347ec5ed57f328", "src_uid": "d1e381b72a6c09a0723cfe72c0917372", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "year = gets.chomp.to_i\n\nloop do\n\tyear += 1\n\tif year.to_s.split('').uniq.length == 4\n\t\tputs year\n\t\tbreak\n\tend\nend", "lang_cluster": "Ruby", "tags": ["brute force"], "code_uid": "0273a3abe58e120c1857af074f8d6ade", "src_uid": "d62dabfbec52675b7ed7b582ad133acd", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "x = gets.chomp.downcase\ny = gets.chomp.downcase\n\nif x==y \n\tputs 0\nelsif x > y \n\tputs 1\nelse\n\tputs -1\nend", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "e30fd1befe012ab898819854b21e9dbb", "src_uid": "ffeae332696a901813677bd1033cf01e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,k,l,c,d,p,N,P=gets.split.map &:to_i;p(([k*l/N,p/P,c*d].min)/n)\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "ffcfa3063e0864c496b367dc3dbe65b8", "src_uid": "67410b7d36b9d2e6a97ca5c7cff317c1", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.chomp\ncoins = n.split\n\ncount = 0\nfor i in (0..4)\n\tcount += coins[i].to_i\nend\n\nif count%5 == 0 && count != 0\n\tputs count/5\nelse\n\tputs -1\nend ", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "7535f1ea1ceef3076b94a95efa4555ce", "src_uid": "af1ec6a6fc1f2360506fc8a34e3dcd20", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "puts gets[/[HQ9]/]?:YES: :NO", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "577994e0c8769692926fb1844747d0b1", "src_uid": "1baf894c1c7d5aeea01129c7900d3c12", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "v1,v2 = gets.split.map(&:to_i)\nt,d = gets.split.map(&:to_i)\n\nsum = v1 + v2\n3.upto(t).each do |_|\n if v1 < v2\n v1 += d\n sum += v1\n else\n v2 += d\n sum += v2\n end\nend\n\nputs sum\n", "lang_cluster": "Ruby", "tags": ["math", "greedy", "dp"], "code_uid": "8ac649069d7ca1e5caef255abc3bdb3c", "src_uid": "9246aa2f506fcbcb47ad24793d09f2cf", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "puts gets.chomp.gsub(/[aoyeui]/i, '').downcase.scan(/./).map{ |s| '.' + s }.join", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "2d7b149ef85c9f4dd2fdfea871ca2434", "src_uid": "db9520e85b3e9186dd3a09ff8d1e8c1b", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, a, b, c = gets.chomp.split().map{ |x| x.to_i }\nanswer = [ 0, [a, b+c, 3*c].min, [2*a, b, 2*c].min, [ 3*a, a+b, c].min ]\nputs answer[ -n % 4 ]\n ", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "ed04d387bde8ca8f2c50d6bfb0ca3005", "src_uid": "c74537b7e2032c1d928717dfe15ccfb8", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "DBG = !true\nn,m = gets.split.map{|z| z.to_i}\na = gets.split.map{|z| z.to_i}\n\ndef f(n)\n return (n-1)*n/2\nend\ndef g(n,t)\n if DBG\n puts \"n #{n} t #{t} fnt1 #{f(n/t+1)} fnt #{f(n/t)}\"\n end\n return (n%t)*f(n/t + 1) + (t - n%t)*f(n/t)\nend\n\na.sort_by!{|z| -z} # decreasing order\nasum = [a[0]]\nfor i in 1...n\n asum << asum[i-1] + a[i]\nend\nif DBG\n puts \"n #{n} m #{m} asum #{asum}\"\nend\nfor t in 1..n\n for i in 1..n\n if asum[i-1] - g(i,t) >= m\n puts \"#{t}\"\n exit 0\n end\n end\nend\nputs \"#{-1}\"\n", "lang_cluster": "Ruby", "tags": ["brute force", "greedy"], "code_uid": "0ad841facb66e77ea1f45a69125fa840", "src_uid": "acb8a57c8cfdb849a55fa65aff86628d", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": " x = gets.chomp\n hash = Hash.new\n x.each_char do |c|\n hash[c] = 0 if hash[c] == nil\n hash[c] += 1\n end\n puts \"CHAT WITH HER!\" if hash.count % 2 == 0\n puts \"IGNORE HIM!\" if hash.count % 2 != 0", "lang_cluster": "Ruby", "tags": ["brute force", "strings", "implementation"], "code_uid": "031e42cb5991b4f380b432aa1c264b42", "src_uid": "a8c14667b94b40da087501fd4bdd7818", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "conds = gets\npoints = gets\n\nconds = conds.split(\" \")\nn = conds[0].to_i\nk = conds[1].to_i\n\npoints = points.split(\" \").map{|x| x.to_i}\n\nthreshold = [1, points.sort.reverse[k-1]].max\nwinners = points.select{|x| x >= threshold}.length\nputs winners", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "0e4b30b955abe68aaed7646f8e0b64da", "src_uid": "193ec1226ffe07522caf63e84a7d007f", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a, b, c, d, e, f = gets.split.map(&:to_i)\nputs (c == 0 && d > 0) ||\n\t(a == 0 && b > 0 && c > 0 && d > 0) ||\n\t(e == 0 && f > 0 && a > 0 && b > 0 && c > 0 && d > 0) ||\n\ta * c * e < b * d * f ? :Ron : :Hermione\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "dccbbc06dc5b2e732e7c01e11236fce2", "src_uid": "44d608de3e1447f89070e707ba550150", "difficulty": 1800.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": "191184e4aa4d6dbbac3183b0f2c92230", "src_uid": "1f8056884db00ad8294a7cc0be75fe97", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "# http://codeforces.com/problemset/problem/334/B\nlist = []\nlist_x = []\nlist_y = []\n8.times do |i|\n list << gets.chomp.split.map(&:to_i)\n list_x << list[i][0]\n list_y << list[i][1]\nend\n\ndef eight_point_set(list, list_x, list_y)\n hash = Hash.new { |hash, key| hash[key] = 0 }\n for i in 0..7\n hash[list[i]] += 1\n\n if hash[list[i]] > 1\n return \"ugly\"\n end\n end\n\n sorted_list_x = list_x.sort\n sorted_list_y = list_y.sort\n avg_x, avg_y = 0, 0\n\n for i in 0..7\n avg_x += 1 if sorted_list_x[i] == sorted_list_x[3]\n avg_y += 1 if sorted_list_y[i] == sorted_list_y[3]\n end\n\n return avg_x == 2 && avg_y == 2 ? \"respectable\" : \"ugly\"\nend\n\nputs eight_point_set(list, list_x, list_y)\n", "lang_cluster": "Ruby", "tags": ["sortings"], "code_uid": "8091d6a2818f118ce3a7782fbe52cf98", "src_uid": "f3c96123334534056f26b96f90886807", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "stones = gets.chomp.to_i\ncolors = gets.chomp\ncolors = colors.split(\"\")\n\nfor i in (0..colors.size-1)\n\tif i < colors.size - 1\n\t\twhile colors[i] == colors[i+1] && colors.size > 1\n\t\t\tcolors.delete_at(i+1)\n\t\tend\n\tend\nend\n\nprint stones - colors.size", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "a58dfc8a6f396e15c9221842ec189240", "src_uid": "d561436e2ddc9074b98ebbe49b9e27b8", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.chomp\ns = gets.chomp\narr = s.split('')\ndef process(arr)\n\tb = 0\n\tg = 0\n\tr = 0\n\tres = ''\n\tarr.each{|e|\n\t\tb += 1 if e == 'B'\n\t\tg += 1 if e == 'G'\n\t\tr += 1 if e == 'R'\n\t}\n\tres += 'B' if (b >= 1 && g >= 1 && r >= 1) || (b == 1 && g == 0 && r == 0) || (g == 1 && r == 1 && b == 0 ) || (b > 1 && g == 0 && r == 0) || ( b >0 && (g > 1 || r > 1)) || (b == 0 && g >= 1 && r >= 1) \n\tres += 'G' if (b >= 1 && g >= 1 && r >= 1) || (g == 1 && b == 0 && r == 0) || (b == 1 && r == 1 && g == 0 ) || (g > 1 && b == 0 && r == 0) || ( g >0 && (b > 1 || r > 1)) || (g == 0 && b >= 1 && r >= 1)\n\tres += 'R' if (b >= 1 && g >= 1 && r >= 1) || (r == 1 && b == 0 && g == 0) || (b == 1 && g == 1 && r == 0 ) || (r > 1 && b == 0 && g == 0) || ( r >0 && (b > 1 || g > 1)) || (r == 0 && b >= 1 && g >= 1)\n\tputs res\nend\nprocess(arr)\n\n", "lang_cluster": "Ruby", "tags": ["math", "dp", "constructive algorithms"], "code_uid": "00db53aa66a9e34e5747e8f8f52abcec", "src_uid": "4cedd3b70d793bc8ed4a93fc5a827f8f", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "x, y = gets.strip.split.map &:to_i\nn = gets.to_i\n\nn -= 1\n\nf_base = [x, y, y - x]\n\nbase_location = n % 3\nsign = (n / 3).even? ? 1 : -1\n\nputs (sign * f_base[base_location]) % 1000000007\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "36b30c8bd2154dc64f9e9956ba033524", "src_uid": "2ff85140e3f19c90e587ce459d64338b", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def finish(message)\n\tputs message\n\texit\nend\ns=gets.chomp\nt=gets.chomp\nhs={}\nht={}\n('a' .. 'z').each{|c| hs[c]=0;ht[c]=0}\ns.each_char {|e| hs[e]+=1}\nt.each_char {|e| ht[e]+=1}\nfinish('array') if hs==ht\n('a' .. 'z').each{|c| finish('need tree') if ht[c]>hs[c]}\npos=-1\nt.each_char {|e| pos=s.index(e,pos+1);break unless pos}\nfinish('automaton') if pos\nfinish('both')", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "32cc73503b2819c31ca913eda8d31659", "src_uid": "edb9d51e009a59a340d7d589bb335c14", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "w = STDIN.read.to_i\nif w > 2 && w % 2 == 0\n puts \"YES\"\nelse\n puts \"NO\"\nend", "lang_cluster": "Ruby", "tags": ["brute force", "math"], "code_uid": "e2ba37af99f214eed137b6dd5c4b8612", "src_uid": "230a3c4d7090401e5fa3c6b9d994cdf2", "difficulty": 800.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": "87be61399052c02b7f778d682600f7ea", "src_uid": "e2357a1f54757bce77dce625772e4f18", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, m, a = gets.split.map(&:to_i)\n\nk = n / a\nl = m / a\n\nif a * k < n \n k = k + 1\nend\n\nif a * l < m \n l = l + 1\nend\n\nputs k * l\n\n \n \n\n\n\t\t \n\n\t \n\n\t\n \n \t\t \t\n\t \n\t\n \n\t\n\n \t\n\n\n\n\n\t \n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "1618a089bc1959c937fa877d4d4532a5", "src_uid": "ef971874d8c4da37581336284b688517", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "inp = gets.split(' ')\na = inp[0].to_i\nb = inp[1].to_i\n\nc = 0\nwhile a <= b do\n c+=1\n a*=3\n b*=2\nend\n\nputs c", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "320d65c7e7573ff46d401b3f1f72a357", "src_uid": "a1583b07a9d093e887f73cc5c29e444a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "primes = Array.new\nfor i in 2..4096\n\tmark = true\n\tfor j in 2..i\n\t\tif j * j > i; break; end\n\t\tif i % j == 0; mark = false; break; end\n\tend\n\tif mark; primes.push(i); end\nend\n\nalmost = Array.new(4096)\nalmost.each do |x|\n\tx = 0\nend\n\nfor i in 1..3000\n\tj = i\n\tcnt = 0\n\tprimes.each do |p|\n\t\tif p * p > j; break; end\n\t\tif j % p == 0\n\t\t\tcnt += 1\n\t\t\twhile j % p == 0\n\t\t\t\tj /= p\n\t\t\tend\n\t\tend\n\tend\n\tif j != 1\n\t\tcnt += 1\n\tend\n\tif cnt == 2\n\t\talmost[i] = 1\n\telse\n\t\talmost[i] = 0\n\tend\nend\n\nn = gets.chomp\nn = n.to_i\nans = 0\nfor i in 1..n\n\tans += almost[i]\nend\nputs ans\n", "lang_cluster": "Ruby", "tags": ["number theory"], "code_uid": "c39b45eff918bb20ec113bd2a0f68801", "src_uid": "356666366625bc5358bc8b97c8d67bd5", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, m = gets.split.map &:to_i\nif m%n != 0\n puts -1\nelse\n t = m/n\n ans = 0\n while t%2 == 0\n t /= 2\n ans += 1\n end\n while t%3 == 0\n t /= 3\n ans += 1\n end\n if t == 1\n puts ans\n else\n puts -1\n end\nend\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "e13b8b71879d825ff6d0cd60b8c9c793", "src_uid": "3f9980ad292185f63a80bce10705e806", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "require 'pp'\n\n# r,g,b,mixed\n# 3 flowers 0 <= r,g,b <= 10^9\n# output: max bouquets\n\n# sample\n# 3 3 6 => 4\n# 4 4 4 => 4 !!\n\n# tests\n# 3 2 2 => 2\n# 2 3 4 => 2\n# 1 3 3 => 2 !!\n# 2 4 4 => 3 !!\n\n=begin\nApproach 1\n================\n# 0 2 3\n\nif one color (:=red) is zero, the answer is g/3 + b/3 .\n\nif r is 1, the answer is ?\n g%3 == 0\n g%3 == 1\n g%3 == 2\n\n## 1 4 6\n## 0 3 5\n\nApproach 2\n================\ncompare the following 3 patterns:\n1. make mixed bouquet as many as possible\n2. make mixed bouquet as many as possible -1\n3. make mixed bouquet as many as possible -2\n\n=end\n\ndef _main2(r,g,b,rest)\n a,b,c = [r,g,b].sort!\n return -1 if a < rest\n\n sum = a - rest\n b -= sum; c -= sum\n sum += b/3; sum += c/3\n\n sum\nend\n\ndef main2(r,g,b)\n puts [\n _main2(r,g,b,0),\n _main2(r,g,b,1),\n _main2(r,g,b,2),\n 0\n ].max\nend\n\nr,g,b = gets.chomp.split(' ').map{|e| e.to_i}\nmain2(r,g,b)\n\n\n\n\n\n\n", "lang_cluster": "Ruby", "tags": ["math", "combinatorics"], "code_uid": "f8119a99aa2873b8cda51bebdf82a340", "src_uid": "acddc9b0db312b363910a84bd4f14d8e", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "x = gets.chomp.to_i\n\ntotal = x\n\nx.downto(1).each_with_index do |i, ind|\n total += i*ind\nend\n\nputs total", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "d279da66689e5bb092d8d9514c3b1a64", "src_uid": "6df251ac8bf27427a24bc23d64cb9884", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = gets.chomp\nif s.upcase==s\n s.downcase!\nelsif s[0].downcase==s[0] and s[1..-1].upcase==s[1..-1]\n s.capitalize!\nend\nputs s", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "212bb9800ca4439ca31c632d5b70eaa2", "src_uid": "db0eb44d8cd8f293da407ba3adee10cf", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,d,m = gets.chomp.split(' ').map(&:to_i)\ng,p,b = gets.chomp.split(' ').map(&:to_i)\n\n\ntotal_req = a+d+m\ntotal_grp = g+p+b\n\nif(total_grp < total_req) then puts(\"NO\")\nelse\n\t\n\tif(a>g) then puts(\"NO\")\n\telse\n\t\tg -= a\n\t\ttotal_grp -= a\n\t\t\n\t\tif(g+p < d) then puts(\"NO\")\n\t\telse \n\t\t\ttotal_grp -= d\n\t\t\tif(total_grp < m) then puts(\"NO\")\n\t\t\telse puts(\"YES\") end\n\t\tend\n\tend\n\t\nend\n\n\n\t\t\n\n", "lang_cluster": "Ruby", "tags": ["brute force", "greedy", "implementation"], "code_uid": "c94947fdea04ff4cd5716c74b1e976d5", "src_uid": "d54201591f7284da5e9ce18984439f4e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "puts gets.chomp.gsub(/(WUB)+/,\" \").gsub(/^ +| +$/,\"\")", "lang_cluster": "Ruby", "tags": ["strings"], "code_uid": "fa5214b78c09786b3cf7d54c82f0df05", "src_uid": "edede580da1395fe459a480f6a0a548d", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "# coding: utf-8\n# if __FILE__ == $0\n# end\n\nr, x1, y1, x2, y2 = gets.split.map(&:to_i)\nunit = 2*r\ndirect_distance = Math.sqrt((x1-x2)**2 + (y1-y2)**2)\n\nsteps = (direct_distance/unit).floor\ndirect_distance -= steps * unit\nif direct_distance > 0\n # subtract 1 step and make into 2 step to fulfill 2r < R < 4r\n steps += 1\nend\nputs steps\n", "lang_cluster": "Ruby", "tags": ["math", "geometry"], "code_uid": "3e266a2521da361aee87fc8da36d1d42", "src_uid": "698da80c7d24252b57cca4e4f0ca7031", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "y, w = gets.split.map(&:to_i)\nd_min = [y, w].max\nnumerator = 7 - d_min >= 0 ? 7 - d_min : 0\ndivisor = numerator.gcd(6)\nnumerator /= divisor\ndenominator = 6 / divisor\n\nputs \"#{numerator}/#{denominator}\"", "lang_cluster": "Ruby", "tags": ["math", "probabilities"], "code_uid": "80e2831c71ca2c1d9d684cbf9c25719f", "src_uid": "f97eb4ecffb6cbc8679f0c621fd59414", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "matrix = []\n3.times { matrix << gets.chomp.scan(/./) }\n\n#p matrix\n\ndef rotateMatrix(matrix)\n oldMap = matrix\n\n # Get the number of lines in the old map (they're the new columns)\n lineCount = oldMap.size\n # Get the number of columns in the old map (We have that many rows now)\n columnCount = oldMap[0].size\n @map = []\n columnCount.times { @map.push [] }\n\n onLine = 0\n oldMap.each do |oldLine|\n onColumn = 0\n oldLine.each do\n @map[(columnCount - 1) - onColumn][(lineCount - 1) - onLine] = oldLine[(columnCount - 1) - onColumn]\n onColumn += 1\n end\n onLine += 1\n end\n @map\nend\n\nmatrix2 = rotateMatrix(matrix)\nmatrix2 = rotateMatrix(matrix2)\n\nputs matrix2 == matrix ? \"YES\" : \"NO\"", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "a145c0566a2eee44932b002965f64e17", "src_uid": "6a5fe5fac8a4e3993dc3423180cdd6a9", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a = gets.to_i\nputs a / 5 + (a % 5 == 0 ? 0 : 1)\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "3954a52a259a0405901a489cb567f383", "src_uid": "4b3d65b1b593829e92c852be213922b6", "difficulty": 800.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*(p%2==1?x:1)%$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 r%=$m\n end\nend\np r", "lang_cluster": "Ruby", "tags": ["brute force", "combinatorics"], "code_uid": "dfd241368c33152b526d05d66a891925", "src_uid": "d3e3da5b6ba37c8ac5f22b18c140ce81", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a, b = gets.split.map(&:to_i)\nx = [a, b].min\ny = (a + b - [a, b].min * 2)/2\nputs [x,y].join(\" \")", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "b17f866f6d0c38b18b659ff0db18ab79", "src_uid": "775766790e91e539c1cfaa5030e5b955", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/ruby2.0\n\ndef reduce(price, discount)\n\ts = price.to_s\n\ti = s.length-1\n\ti -= 1 while i > 0 && s[i] == '9'\n\treturn price if i <= 0\n\tx = s[i..-1].to_i + 1\n\treturn price if x > discount\n\treturn reduce(price-x, discount-x)\nend\n\np, d = STDIN.readline.split.collect {|s| s.to_i }\nputs reduce(p, d)\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "1a3c7a414de5541c72ed7a9342368982", "src_uid": "c706cfcd4c37fbc1b1631aeeb2c02b6a", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "require 'prime'\n\ndef phi(n)\n d = Prime.prime_division(n)\n d.each { |r, e| n = n * (r - 1) / r }\n n\nend\n\ndef has_primitive_root?(n)\n return true if n == 1 || n == 2 || n == 4\n return false if n.to_s(2)[1..-1].chars.uniq == [?0] # power of 2 not allowed\n n /= 2 if n.even?\n (3..n).select { |r| Prime.prime?(r) && r**Math.log(r, n).to_i == n } .size > 0\nend\n\ndef number_of_primitive_roots(n)\n has_primitive_root?(n) ? phi(phi(n)) : 0\nend\n\np number_of_primitive_roots(gets.to_i)\n", "lang_cluster": "Ruby", "tags": ["math", "implementation", "number theory"], "code_uid": "317f8aa0c669f254d96c8447ac119e43", "src_uid": "3bed682b6813f1ddb54410218c233cff", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "LUCKY_NUMBERS = [4, 7, 44, 47, 74, 77, 444, 447, 474, 477, 744, 747, 774, 777]\n\ndef lucky_number?(n)\n LUCKY_NUMBERS.include?(n)\nend\n\ndef divisible_by_lucky?(n)\n LUCKY_NUMBERS.any? { |x| n % x == 0}\nend\n\nn = STDIN.read.to_i\nputs lucky_number?(n) || divisible_by_lucky?(n) ? \"YES\" : \"NO\"\n", "lang_cluster": "Ruby", "tags": ["brute force", "number theory"], "code_uid": "a15366c8853d8e9d6cfdf7b0a4ef7d29", "src_uid": "78cf8bc7660dbd0602bf6e499bc6bb0d", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "\nclass Euler\n a=gets.to_s;\n sh=0;\n (0..a.length).each do |i|\n if (a[i]==\"4\" || a[i]==\"7\")\n sh+=1;\n end\n end\n a=sh.to_s;\n (0..a.length-1).each do |i|\n if (a[i]!=\"4\" && a[i]!=\"7\")\n puts(\"NO\");\n exit;\n end\n end\n puts(\"YES\");\nend\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "84dc5d4e5e1b3806a5663b00ba338f40", "src_uid": "33b73fd9e7f19894ea08e98b790d07f1", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "class Solver\n\tdef main\n\t\thave = gets.split.map { |x| x.to_i }\n\t\tneed = gets.split.map { |x| x.to_i }\n\t\t0.upto(2) do |i|\n\t\t\ttmp = [have[i], need[i]].min\n\t\t\thave[i] -= tmp\n\t\t\tneed[i] -= tmp\n\t\t\thave[i] /= 2\n\t\tend\n\t\tstr = [\"Yes\", \"Yes\", \"No\"]\n\t\tputs str[have.reduce(:+) <=> need.reduce(:+)]\n\tend\nend\n\nSolver.new.main", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "4e006b4eeb47590a2be1ae77a4257cad", "src_uid": "1db4ba9dc1000e26532bb73336cf12c3", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "res = gets.chomp.chars.map(&:to_i).\n map{|x| [x, 9 -x].min}.map(&:to_s).join('')\n\nres[0] = '9' if res[0] == '0'\nputs res\n", "lang_cluster": "Ruby", "tags": ["greedy", "implementation"], "code_uid": "ceb0649fb6ebfc8d69f4d8f0727693c0", "src_uid": "d5de5052b4e9bbdb5359ac6e05a18b61", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, k = gets.strip.split(' ').map(&:to_i)\ns = gets.strip\nj = -1\n0.upto(s.length - 1) do |i|\n if s[i] == 'G'\n j = i\n break\n end\nend\n\ni1 = j\ni2 = j\nfound = false\nwhile(1)\n i1 -= k\n i2 += k\n if i1 >= 0\n if s[i1] == 'T'\n found = true\n break\n elsif s[i1] == '#'\n i1 = -1\n end\n end\n if i2 < s.length\n if s[i2] == 'T'\n found = true\n break\n end\n if s[i2] == '#'\n i2 = s.length\n end\n end\n if i1 < 0 && i2 >= s.length\n break\n end\nend\n\nprintf(\"%s\\n\", found ? \"YES\" : \"NO\")\n", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "9ab850c35a4a0d6803abc8b43974853b", "src_uid": "189a9b5ce669bdb04b9d371d74a5dd41", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def remove_zeros(a)\n a.gsub(/0/, '')\nend\n\na = gets.chomp\nb = gets.chomp\n\nputs((remove_zeros (a.to_i + b.to_i).to_s).to_i == remove_zeros(a).to_i + remove_zeros(b).to_i ? 'YES' : 'NO')", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "1546e21fd01595f6415fc4fb84252519", "src_uid": "ac6971f4feea0662d82da8e0862031ad", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = gets\nputs s.length - s.gsub('VK', ' ').sub(/KK|VV/, ' ').length", "lang_cluster": "Ruby", "tags": ["brute force"], "code_uid": "4a5ba904eba44abd1703fa83c3723cab", "src_uid": "578bae0fe6634882227ac371ebb38fc9", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,m = gets.split(\" \").map(&:to_i)\narr = []\n\nn.times do\n\tarr << gets.split(\"\")\nend\neaten = Array.new(n)\neaten.map! { |e| Array.new(m,false) }\ncount = 0\n(0..(n-1)).each do |i|\n\t(0..(m-1)).each do |j|\n\t\tif arr[i][j] == 'W'\n\t\t\tif arr[i][j+1] && arr[i][j+1] == 'P' && !eaten[i][j+1]\n\t\t\t\teaten[i][j+1] = true\n\t\t\t\tcount += 1\n\t\t\telsif j > 0 && arr[i][j-1] == 'P' && !eaten[i][j-1]\n\t\t\t\teaten[i][j-1] = true\n\t\t\t\tcount += 1\n\t\t\telsif arr[i+1] && arr[i+1][j] == 'P' && !eaten[i+1][j]\n\t\t\t\teaten[i+1][j] = true\n\t\t\t\tcount += 1\n\t\t\telsif i > 0 && arr[i-1][j] == 'P' && !eaten[i-1][j]\n\t\t\t\teaten[i-1][j] = true\n\t\t\t\tcount += 1\n\t\t\tend\t\t\t\t\t\t\t\t\t\n\t\tend\n\t\t# puts \"#{i} #{j} #{arr[i][j]}\"\n\t\t# puts \"here #{count}\"\n\tend\nend\nputs count", "lang_cluster": "Ruby", "tags": ["greedy", "implementation"], "code_uid": "5a948bdb67bfa49d0e37c248385b63ac", "src_uid": "969b24ed98d916184821b2b2f8fd3aac", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "require 'prime'\n\ndef maxprime(x, y)\n y.downto(x){|n| return n if n.prime? }\n -1\nend\n\np, y=gets.split.map &:to_i\nq=maxprime(p+1, y)\n\nif q==-1\n puts -1\n exit\nend\n\np=maxprime(2, p)\nres=q;\nq.upto(y){|x| res=x if x.prime_division[0][0]>p}\nputs res\n", "lang_cluster": "Ruby", "tags": ["brute force", "math", "number theory"], "code_uid": "a0b8ed6f7f30c9ed9ccbdd5e21dc617a", "src_uid": "b533203f488fa4caf105f3f46dd5844d", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "t, w, b = gets.strip.split.map(&:to_i)\n\nl = w.lcm(b)\na = t/l * [w, b].min\na += [t % l + 1, [w, b].min].min\na -= 1\n\nif w == b then\n puts \"1/1\"\nelse\n g = a.gcd(t)\n puts \"#{a/g}/#{t/g}\"\nend\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "b34d96ca65c3e9858ae8a817a70c19e6", "src_uid": "7a1d8ca25bce0073c4eb5297b94501b5", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "p 2**((s=gets).size-2)*s.to_i(2)%1000000007", "lang_cluster": "Ruby", "tags": ["math", "combinatorics"], "code_uid": "ec7a59115eeb87b37d3f8fbd9d4616c7", "src_uid": "89b51a31e00424edd1385f2120028b9d", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a = gets.to_i.to_s(3)\na.chop! while a[-1, 1] == '0'\nputs a.chop!.to_i(3) + 1", "lang_cluster": "Ruby", "tags": ["greedy"], "code_uid": "76062bdaa99198768b65a2dd3feccbda", "src_uid": "7e7b59f2112fd200ee03255c0c230ebd", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a=gets.split.map{|x| x.to_i}\nb=false\nc=0\nfor i in 0..5\n if a.count(a[i])>=4\n b=true \n c=a[i]\n break\n end\nend\n\ns=0\nfor i in 0..5\n if a[i]==c\n a[i]=nil \n s+=1\n end\n break if s==4\nend\n\nif b \n a=a.compact\n puts \"Elephant\" if a[0]==a[1]\n puts \"Bear\" if a[0]!=a[1]\nelse\n puts \"Alien\"\nend", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "1c0cf8e686903954d379e27f73b7a976", "src_uid": "43308fa25e8578fd9f25328e715d4dd6", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/env ruby\n\ndef read_ints\n return gets.split.map(&:to_i)\nend\n\nt = read_ints\nk = t.pop\nt.map! { |x| x - 1 }.sort!\nr = [1] * 3\n3.times do |i|\n d = [t[i], k / (3 - i)].min\n r[i..2] = r[i..2].map { |x| x + d }\n k -= d * (3 - i)\n t.map! { |x| x - d}\nend\nputs r.reduce(:*)\n", "lang_cluster": "Ruby", "tags": ["math", "greedy"], "code_uid": "d0a24ae151bff9feb31842ed9a23b001", "src_uid": "8787c5d46d7247d93d806264a8957639", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "p1, p2, p3, p4, a, b = gets.split.map(&:to_i)\np [*a .. b].count{|_| _ % p1 % p2 % p3 % p4 == _}\n", "lang_cluster": "Ruby", "tags": ["implementation", "number theory"], "code_uid": "cc317b6ded56b57c88361e4b4de35cea", "src_uid": "63b9dc70e6ad83d89a487ffebe007b0a", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s1=gets.strip\ns2=gets.strip\ns3=gets.strip\ns4=gets.strip\ns5=gets.strip\ns6=gets.strip\ns7=gets.strip\ns8=gets.strip\n\nif (s1 == 'WBWBWBWB' || s1 == 'BWBWBWBW') && (s2 == 'WBWBWBWB' || s2 == 'BWBWBWBW') && (s3 == 'WBWBWBWB' || s3 == 'BWBWBWBW') && (s4 == 'WBWBWBWB' || s4 == 'BWBWBWBW') && (s5 == 'WBWBWBWB' || s5 == 'BWBWBWBW') && (s6 == 'WBWBWBWB' || s6 == 'BWBWBWBW') && (s7 == 'WBWBWBWB' || s7 == 'BWBWBWBW') && (s8 == 'WBWBWBWB' || s8 == 'BWBWBWBW')\n\tputs 'YES'\nelse\n\tputs 'NO'\nend\n", "lang_cluster": "Ruby", "tags": ["brute force", "strings"], "code_uid": "bf539ddf67e687fa0d1dbb8a1205eee5", "src_uid": "ca65e023be092b2ce25599f52acc1a67", "difficulty": 1000.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": "e011aa9e565b84eac3a5319750db4a56", "src_uid": "042cf938dc4a0f46ff33d47b97dc6ad4", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b,s=gets.split.map &:to_i;s-=a.abs+b.abs;puts s<0||s%2>0?:No:\"Yes\"\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "1bf53a2ed57c54abed94997b18a1e53a", "src_uid": "9a955ce0775018ff4e5825700c13ed36", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/ruby\ns=gets.chomp.chars.uniq.join\nputs s==[*'a'..'z'].join[0,s.size] ? :YES : :NO", "lang_cluster": "Ruby", "tags": ["greedy", "strings", "implementation"], "code_uid": "5ab325b59a31b39432741b283c8457b2", "src_uid": "c4551f66a781b174f95865fa254ca972", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = 'What are you doing at the end of the world? Are you busy? Will you save us?'\nt1 = 'What are you doing while sending \"'\nt2 = '\"? Are you busy? Will you send \"'\nt3 = '\"?'\nt = t1 + t2 + t3\nls = [ s.length ]\nwhile ls.last < 1e18\n ls << ls.last * 2 + t.length\nend\n\ndefine_method(:get) do |n, k|\n if n == 0\n return k < s.length ? s[k] : '.'\n end\n return t1[k] if k < t1.length\n k -= t1.length\n return get(n-1, k) if k < ls[n-1]\n k -= ls[n-1]\n return t2[k] if k < t2.length\n k -= t2.length\n return get(n-1, k) if k < ls[n-1]\n k -= ls[n-1]\n return t3[k] if k < t3.length\n return '.'\nend\n\nq = gets.to_i\n\nq.times do\n n, k = gets.split.map(&:to_i)\n k -= 1\n if n >= ls.length\n d = (n - ls.length + 1) * t1.length\n if k < d\n print t1[k % t1.length]\n next\n else\n k -= d\n n = ls.length - 1\n end\n end\n print get(n, k)\nend\nputs\n", "lang_cluster": "Ruby", "tags": ["math", "binary search", "combinatorics"], "code_uid": "ffb063c28005876f465f3e1bd2b15fc1", "src_uid": "da09a893a33f2bf8fd00e321e16ab149", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b=gets.split.map &:to_i\nb.times{a=a%10==0?a/10:a-1}\np a", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "c16dfff523d434cd8209c7b1b4a55930", "src_uid": "064162604284ce252b88050b4174ba55", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "g=->{gets.split.map &:to_i};n,m=g[];a=g[].sort;p a[n-1...m].zip(a).map{|i,j|i-j}.min\n", "lang_cluster": "Ruby", "tags": ["greedy"], "code_uid": "8f2b7f4a489d63fd17a9091568868b28", "src_uid": "7830aabb0663e645d54004063746e47f", "difficulty": 900.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", "lang_cluster": "Ruby", "tags": ["math", "greedy", "number theory"], "code_uid": "d79b1b7be8c84cb825a22d928e756b67", "src_uid": "b0f435fc2f7334aee0d07524bc37cb1e", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "x = gets.chomp.split.map{|i| i.to_i}.inject(:+)\ny = gets.chomp.split.map{|i| i.to_i}.inject(:+)\n\nif (x+4)/5 + (y+9)/10 <= gets.to_i\n puts \"YES\"\nelse\n puts \"NO\"\nend\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "38a76a507ca83a7d368e4c410bfdda09", "src_uid": "fe6301816dea7d9cea1c3a06a7d1ea7e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b,c,d,e=gets.split.map &:to_i\nx=[a, c].max\ny=[b, d].min\ny+=1 unless x<=e and e<=y\np [y-x, 0].max\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "c1d4718756d50e8e6e3c29896314e6a3", "src_uid": "9a74b3b0e9f3a351f2136842e9565a82", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, k = gets.strip.split.map(&:to_i)\nremainder = n / k\nans = k * remainder + k\nputs ans\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "2a8d1c9931c9d5067a38f444aa76a0d0", "src_uid": "75f3835c969c871a609b978e04476542", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "nt = gets.chomp.split ' '\ninput = gets.chomp.split ''\nsize = nt[0].to_i\ntime = nt[1].to_i\n\nfor i in 1..time\n temp = input.clone\n input.each_with_index { |char, index|\n if index == size-1\n break\n end\n if (char+input[index+1]).eql? \"BG\"\n temp[index] = (temp[index].ord ^ temp[index+1].ord).chr\n temp[index+1] = (temp[index].ord ^ temp[index+1].ord).chr\n temp[index] = (temp[index].ord ^ temp[index+1].ord).chr\n end\n }\n input = temp\nend\nputs input.join\n\n\n", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation", "shortest paths", "graph matchings"], "code_uid": "db326b205da1f3951b44ba296abb06c3", "src_uid": "964ed316c6e6715120039b0219cc653a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s=\"\"\n1000.times{|i|s+=i.to_s}\nputs s[gets.to_i]", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "8707ff21ed97192220c67cac4c97befa", "src_uid": "2d46e34839261eda822f0c23c6e19121", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/ruby\n\nh, m = gets.split(':').map(&:to_i)\n3600.times do |i|\n m += 1\n if m == 60\n m = 0\n h += 1\n if h == 24\n h = 0\n end\n end\n\n hstr = sprintf(\"%02d\", h)\n mstr = sprintf(\"%02d\", m)\n\n if mstr.reverse == hstr\n puts \"#{hstr}:#{mstr}\"\n exit\n end\nend\n", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "53ca06b70157d636c74761ea66c5809e", "src_uid": "158eae916daa3e0162d4eac0426fa87f", "difficulty": 1000.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": "719244a0bcda92b0ac15ce6d1f1c1b8d", "src_uid": "ba6ff507384570152118e2ab322dd11f", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def calc(n, k, arr)\n\ttotal = 0\n\tcount = 0\n\tbran = 0\n\tarr.each do |x|\n\t\ttotal += x\n\t\tbran += [8,total].min\n\t\ttotal -= [8,total].min\n\t\tcount += 1\n\t\tif bran >= k\n\t\t\treturn count\n\t\tend\n\tend\n\treturn -1\nend\nn, k = gets.chomp.split(\" \").map(&:to_i)\narr = gets.chomp.split(\" \").map(&:to_i)\nputs calc(n, k, arr)", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "f2170e52367c8a8712d85cf8e418854b", "src_uid": "24695b6a2aa573e90f0fe661b0c0bd3a", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a, b = gets.split\na = a.to_i + 1\na += 1 until a.to_s.gsub(/[^47]/, '') == b\np a\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "7cdec66f5e9d1f09e4105f55cc22678c", "src_uid": "e5e4ea7a5bf785e059e10407b25d73fb", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def f(s,c,dp)\n\tdp2=[0]*s.size\n\tcount0=0\n\tcount1=0\n\ti=0\n\ts.chars.each{|e|\n\t\tcount1=[count1,dp[i-1]].max if i>0\n\t\tif e==c\n\t\t\tcount0+=count1\n\t\t\tdp2[i]=count0\n\t\tend\n\t\ti=i+1\n\t}\n\treturn dp2\nend\n\ns=\" \"+gets.chomp\nans=0\ndp=[1]*s.size\n\"QAQ\".chars.each{|e|\n\tdp=f(s,e,dp)\n}\nputs dp.max\n", "lang_cluster": "Ruby", "tags": ["brute force", "dp"], "code_uid": "6b1c81dce7275c194cb85decccf0c98d", "src_uid": "8aef4947322438664bd8610632fe0947", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def f(k,n,ans)\n\tif n==0 then\n\t\treturn 1\n\telse\n\t\th=(n/2).to_i\n\t\tif k==h+1 then\n\t\t\treturn ans\n\t\telsif k>h\n\t\t\treturn f(k-h-1,h,ans-1)\n\t\telse\n\t\t\treturn f(k,h,ans-1)\n\t\tend\n\tend\nend\nn,k=gets.split.map{|e| e.to_i}\nputs f(k,(2**n)-1,n)\n", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "binary search", "implementation", "bitmasks"], "code_uid": "4476e37f4302daf55371e29c92915cd8", "src_uid": "0af400ea8e25b1a36adec4cc08912b71", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "x=gets.split.map(&:to_i)\nputs [x[0]*(0..x[2]).inject(:+)-x[1],0].max\n", "lang_cluster": "Ruby", "tags": ["brute force", "math", "implementation"], "code_uid": "2d38da9137d5ed94d4d691c25949c7b6", "src_uid": "e87d9798107734a885fd8263e1431347", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b=gets.split.map &:to_i;puts a+b>0&&(a-b).abs<2?:YES: :NO", "lang_cluster": "Ruby", "tags": ["brute force", "math", "constructive algorithms", "implementation"], "code_uid": "344727042d7ddf5b308d1b0279e18d56", "src_uid": "ec5e3b3f5ee6a13eaf01b9a9a66ff037", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "line = gets\nn, m = line.split.map(&:to_i)\nline = gets\nc = line.split.map(&:to_i)\nc = c.each_with_index.map do |x, i|\n\t[x, i+1]\nend\n\nlast_c = nil\ni = 0\nwhile c.any?\n\tbreak if c.size == 1\n\tcur = c.first\n\tc = c[1..-1]\n\tif cur[0]-m > 0 \n\t\tc << [cur[0]-m, cur[1]]\n\tend\nend\n\nputs c.first[1]\n\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "1aa0a6140a12d5c93ec7fd3259d85514", "src_uid": "c0ef1e4d7df360c5c1e52bc6f16ca87c", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b=gets.split.map{|e| e.to_i}\nputs (a*b)/2", "lang_cluster": "Ruby", "tags": ["math", "greedy"], "code_uid": "6852c5278c9bb73e5077fa959d1bd8bf", "src_uid": "e840e7bfe83764bee6186fcf92a1b5cd", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\nary = gets.split.map(&:to_i)\n\nif ary[-1] == 0\n puts \"UP\"\nelsif ary[-1] == 15\n puts \"DOWN\"\nelsif n==1\n puts \"-1\"\nelse\n if ary[-2] < ary[-1]\n puts \"UP\"\n else\n puts \"DOWN\"\n end\nend \n ", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "3c1a0bae579e5b151a77570fc3b531b5", "src_uid": "8330d9fea8d50a79741507b878da0a75", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "b = gets.to_i\n\n#example 1\n# b = 1\n#assert 1\n#example 2\n# b = 2\n#assert 2\n\nif b == 1\n\tputs 1\nelse\n\trequire 'prime'\n\n\tfast_divisors = b.prime_division.map{ |e| e.last + 1 }.inject(:*)\n\n\tputs fast_divisors\nend", "lang_cluster": "Ruby", "tags": ["math", "number theory"], "code_uid": "1e643f7dedb0c535173bb95c938f3603", "src_uid": "7fc9e7d7e25ab97d8ebc10ed8ae38fd1", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = gets \nt = gets \nstart = 0 \nt.each_char do |i| \n if s[start] == i \n start +=1 \n end \nend \n\nputs start + 1 ", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "5c70d3d3442708fc3935b0828bce6b2f", "src_uid": "f5a907d6d35390b1fb11c8ce247d0252", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47]\nn,m=gets.split.map &:to_i \nputs s[s.index(n).to_i+1]==m ?\"YES\":\"NO\"", "lang_cluster": "Ruby", "tags": ["brute force"], "code_uid": "0e077f153e314bdde7ba96354efbdc9d", "src_uid": "9d52ff51d747bb59aa463b6358258865", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "$_=$<.map{|s|s.chop+?o}*''\nf=->n{~/(x.{#{n}}){2}\\./||~/x.{#{n}}\\..{#{n}}x/||~/\\.(.{#{n}}x){2}/}\nputs f[0]||f[3]||f[4]||f[5]?:YES: :NO", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "18f82dee074794f22b05d655e5e5938c", "src_uid": "ca4a77fe9718b8bd0b3cc3d956e22917", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a, b, c = STDIN.gets.split(\" \").map(&:to_i)\n\nputs ((c * a - c * b) / b.to_f).ceil\n", "lang_cluster": "Ruby", "tags": ["brute force", "math", "binary search"], "code_uid": "f35c58accb6bb57d242eec937840436e", "src_uid": "7dd098ec3ad5b29ad681787173eba341", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/ruby1.9\n\n5.times do |r|\n\trow = STDIN.readline.split\n\t5.times do |c|\n\t\tif row[c] == '1'\n\t\t\tputs ((r-2).abs+(c-2).abs)\n\t\t\texit\n\t\tend\n\tend\nend\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "ef82bb39835c80f1522d580b927467c0", "src_uid": "8ba7cedc3f6ae478a0bb3f902440c8e9", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "k = gets.to_i\ncount = Hash.new(0)\narr = []\n4.times do\n\tarr << gets.split(\"\").map(&:to_i)\nend\narr.flatten!\narr.each do |a|\n\tcount[a] += 1\nend\ncount.delete(0)\nans = count.values.all?{|c| c <= 2 * k}\nputs ans ? \"YES\" : \"NO\"", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "da5e05ccab1d13d4390cf99589f4ef7a", "src_uid": "5fdaf8ee7763cb5815f49c0c38398f16", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def diff a,b,c,d\n a != b and a != c and a != d and b != c and b != d and c != d and a>=1 and a<=9 and b>=1 and b<=9 and c>=1 and c<=9 and d>=1 and d<=9\nend\n\nr1,r2 = gets.split.map(&:to_i)\nc1,c2 = gets.split.map(&:to_i)\nd1,d2 = gets.split.map(&:to_i)\n\n(1..9).each do |s1|\n s2 = r1 - s1\n s3 = c1 - s1\n s4 = c2 - s2\n if s3+s4 == r2 and s1+s4 == d1 and s2+s3 == d2 and diff(s1,s2,s3,s4)\n puts \"#{s1} #{s2}\\n#{s3} #{s4}\"\n exit\n end\nend\nputs -1", "lang_cluster": "Ruby", "tags": ["brute force", "math"], "code_uid": "a80a9267d8895a24f33c3732fd0577c4", "src_uid": "6821f502f5b6ec95c505e5dd8f3cd5d3", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "gets\nputs gets.split.map(&:to_i).sort*' '", "lang_cluster": "Ruby", "tags": ["sortings", "implementation", "greedy"], "code_uid": "6f42184d33303c51b8fe1b14a29cd852", "src_uid": "ae20712265d4adf293e75d016b4b82d8", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "f = gets.strip.split ''\ns = gets.split.join.split ''\nputs(s.any?{|x| f.any?{|y| x == y}} ? \"YES\" : \"NO\")\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "2053265659d662d2b4a8b5ffe9914282", "src_uid": "699444eb6366ad12bc77e7ac2602d74b", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": " #$stdin.reopen('/cygdrive/d/input.txt', 'r')\n\n\n c,d = gets.split.map(&:to_i)\n n,m = gets.split.map(&:to_i)\n k = gets.to_i\n\ndef solve(c,d,n,m,k)\n\t\n\tw=n*m-k\n\tif w<=0\n\t\tputs 0\n\t\texit 0\n\n\tend\n\tx = c/n\n\tif x b ?(a>c ?\"chest\":\"back\"):(b>c ?\"biceps\":\"back\")", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "f42fc8e54abc55ce3aa25b2c00f73be3", "src_uid": "579021de624c072f5e0393aae762117e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "# http://codeforces.com/contest/550/problem/B\nn, l, r, x = gets.chomp.split.map(&:to_i)\ndifficulties = gets.chomp.split.map(&:to_i)\n\nselected = []\n(2..n).each do |size|\n difficulties.combination(size).each do |arr|\n total = arr.inject(0, :+)\n \n selected << arr if total >= l && total <= r && (arr.max - arr.min) >= x\n end\nend\n\nputs selected.length\n", "lang_cluster": "Ruby", "tags": ["brute force", "bitmasks"], "code_uid": "4124f0af72a80929834da7b87c0d8b93", "src_uid": "0d43104a0de924cdcf8e4aced5aa825d", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\nres = 0\nns = [1]\ni = 10\nwhile ns.last<(10**9 + 1)\n break if i>n\n temp = [i]\n flag = false\n ns.each do |x|\n if (x+i)<=n\n temp << x+i\n else\n flag = true\n end\n end\n ns += temp.sort\n break if flag\n i *= 10\nend\nputs ns.size\n", "lang_cluster": "Ruby", "tags": ["brute force", "math", "implementation"], "code_uid": "ba49ea1b5556a8f8b43fb48294acd592", "src_uid": "64a842f9a41f85a83b7d65bfbe21b6cb", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,d = gets.split.map(&:to_i)\nt = gets.split.map(&:to_i)\nd -= t.inject(&:+) + 10 * (n - 1)\nif d < 0\n\tputs '-1'\nelse\n\tputs (n - 1) * 2 + d / 5\nend", "lang_cluster": "Ruby", "tags": ["greedy", "implementation"], "code_uid": "565c6e09d1607591655b5a9b6680ec92", "src_uid": "b16f5f5c4eeed2a3700506003e8ea8ea", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby 3", "source_code": "t = gets.to_i\nt.times do\n x = gets.to_i\n d = gets.chomp!.split.map &:to_i\n if (a = d[x - 1]) != 0 && b = d[a - 1] != 0\n puts 'YES'\n else\n puts 'NO'\n end\nend\n", "lang_cluster": "Ruby", "tags": ["brute force", "greedy", "implementation", "math"], "code_uid": "7b22904b42670441089ed6299c213767", "src_uid": "5cd113a30bbbb93d8620a483d4da0349", "difficulty": 800.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": "410bba08f7a656d7afc7c2872e0d8638", "src_uid": "f6e132d1969863e9f28c87e5a44c2b69", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "puts [:Mahmoud,:Ehab][gets.to_i%2]", "lang_cluster": "Ruby", "tags": ["math", "games"], "code_uid": "a9d808276c01d2ad4489067bc34dd340", "src_uid": "5e74750f44142624e6da41d4b35beb9a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "gets\nputs /0{7}|1{7}/ ? :YES : :NO\n", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "abc55ded53ede6b7916266742726c232", "src_uid": "ed9a763362abc6ed40356731f1036b38", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "nk = gets.chomp.split(\" \").map(&:to_i)\nn = nk[0]\nk = nk[1]\n\nstring = gets.chomp\n\narr = string.each_char.to_a.uniq.sort\n\nif k > 26\n puts -1\n exit\nend\n\nweight = 0\ni = 0\nprevch = 'A'\n\ndef addto(char,no)\n return (char.ord+no).chr\nend\n\n\nlen = arr.length\nwhile k>0\n if i>=len\n puts -1\n exit\n end\n\n ch = arr[i]\n if ch<=addto(prevch,1)\n i+=1\n next\n end\n\n #p ch\n weight += ch.ord-'a'.ord+1\n k-=1\n i+=1\n prevch = ch\nend\n\nputs weight", "lang_cluster": "Ruby", "tags": ["sortings", "implementation", "greedy"], "code_uid": "703ac8dc9301ae2b36554f2eab127607", "src_uid": "56b13d313afef9dc6c6ba2758b5ea313", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "recipe = gets\nn = gets.split.map{|e| e.to_i}\np = gets.split.map{|e| e.to_i}\nbudget = gets.to_i\n\nk = [\"B\", \"S\", \"C\"].map{|e| recipe.count e}\n\ndef non_neg(x)\n return x < 0 ? 0 : x\nend\n\nl = 0; r = budget + n.max; x = 0\nwhile l <= r\n m = (l + r) / 2\n sum_cost = k.map.with_index{|e, i| e == 0 ? 0 : p[i] * non_neg(e * m - n[i])}.inject(:+)\n if sum_cost < budget\n l = m + 1\n x = m\n elsif sum_cost > budget\n r = m - 1\n else\n x = m\n break\n end\nend\nputs x\n", "lang_cluster": "Ruby", "tags": ["brute force", "binary search"], "code_uid": "a884620bdfb4f9258af04b53efe21460", "src_uid": "8126a4232188ae7de8e5a7aedea1a97e", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\ns = gets.chomp\nt = [s[0, n], s[n, n]].map{|_| _.chars.to_a.sort}.transpose\nputs t.all?{|i, j| i < j} || t.all?{|i, j| i > j} ? :YES : :NO\n", "lang_cluster": "Ruby", "tags": ["sortings", "greedy"], "code_uid": "2a6273969e02eb27c889d4d00e9a5fff", "src_uid": "e4419bca9d605dbd63f7884377e28769", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "puts lambda {|a| t=[0,0,0]; (1..6).each{|x| q=((a[0]-x).abs-(a[1]-x).abs); t[(q<0)?0:((q==0)?1:2)]+=1}; t.join(' ') } [gets.split.map(&:to_i)]\n", "lang_cluster": "Ruby", "tags": ["brute force"], "code_uid": "f87310932035c9d1cf156d106c07218e", "src_uid": "504b8aae3a3abedf873a3b8b127c5dd8", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "input = gets.split.map(&:to_i)\n\n# * 2 and - 1\n# go from first to last\n\ncount = 0\n\n# go backwards, from last to first\nwhile input.last != input.first do\n if input.last.odd? or input.last < input.first\n input[-1] += 1\n else\n input[-1] /= 2\n end\n count += 1\nend\n\nputs count\n", "lang_cluster": "Ruby", "tags": ["dfs and similar", "shortest paths", "math", "graphs", "greedy", "implementation"], "code_uid": "5052ef2be67882dd3d3b7c23ef742c28", "src_uid": "861f8edd2813d6d3a5ff7193a804486f", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "puts $<.map{|s|['vapor','jolt','flar','esp','umbr','leaf','glac','sylv'].select{|x|x=~/^#{s.strip[0..-4]}$/}}[1][0]+'eon'\n", "lang_cluster": "Ruby", "tags": ["brute force", "strings", "implementation"], "code_uid": "9b4f1ef232b15c5f39acfd543dac84e3", "src_uid": "ec3d15ff198d1e4ab9fd04dd3b12e6c0", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\nif n % 2 == 1\n puts 0\nelse\n m = n / 2\n puts (m - 1) / 2\nend\n\n", "lang_cluster": "Ruby", "tags": ["math", "combinatorics"], "code_uid": "1c946db064c557cc1783b32f97ef37cd", "src_uid": "32b59d23f71800bc29da74a3fe2e2b37", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "cw_pos = %w{v < ^ >}\nccw_pos = %w{v > ^ <}\nstart, fin = gets.strip.split\nstart_pos_cw = cw_pos.index start\nstart_pos_ccw = ccw_pos.index start\nn = gets.strip.to_i\nn %= 4\ncw = cw_pos[start_pos_cw + (n - 4)] == fin\nccw = ccw_pos[start_pos_ccw + (n - 4)] == fin\nif cw && !ccw\n puts \"cw\"\nelsif ccw && !cw\n puts \"ccw\"\nelse\n puts \"undefined\"\nend\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "40a10d3eda983a80a45e078553dc01a6", "src_uid": "fb99ef80fd21f98674fe85d80a2e5298", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = gets\nx = s.to_i\nh = {}\nf = ->(y){ h[y] = 1 if x % y == 0 && s.tr(y.to_s, '') != s }\n1.upto(Math.sqrt(x)) do |y|\n f[y]\n f[x / y]\nend\np h.size\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "2931f87447338bfbddfcebd520b85108", "src_uid": "ada94770281765f54ab264b4a1ef766e", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "N = 42\nd = Array.new(N)\nfor i in 0...d.length\n d[i] = Array.new(N, 0)\nend\n\nfor i in 0...N\n d[0][i] = 1\nend\n\nfor n in 1...N\n for depth in 1...N\n for k in 0...n\n d[n][depth] += d[k][depth - 1] * d[n - k - 1][depth - 1]\n end\n end\nend\n\nn, depth = gets.split(/\\s+/).map{|x| x.to_i}\np d[n][n] - d[n][depth - 1]\n", "lang_cluster": "Ruby", "tags": ["divide and conquer", "dp", "combinatorics"], "code_uid": "92c2eef6f6bb18cbb0f5e6519e648ae3", "src_uid": "faf12a603d0c27f8be6bf6b02531a931", "difficulty": 1900.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": "67f3ebe7882da7421ed1f9d60ec4e8ff", "src_uid": "fc133fe6353089a0ebee08dec919f608", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "y=gets.to_i+4;puts %w{Sheldon Leonard Penny Rajesh Howard}[(y>>((y/5).to_s(2).size-1))-5]", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "530f8c9148cfb82d95171a5998f01735", "src_uid": "023b169765e81d896cdc1184e5a82b22", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/ruby\na,b=gets.split.map(&:to_i)\nr=0\nx=0\nwhile a>0\n\tr+=a\n\tx+=a\n\ta=x/b\n\tx%=b\nend\np r", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "4d8c9e524f6fdd8192dbec4cc928be20", "src_uid": "a349094584d3fdc6b61e39bffe96dece", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\ni = -1\nn -= a[(i += 1) % 7] while n > 0\np i % 7 + 1\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "b19a5578ce62aa7fb41198d417568904", "src_uid": "007a779d966e2e9219789d6d9da7002c", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "x,y=gets.split.map(&:to_i)\nc=x.abs+y.abs\ny=y<0? -c : c\nputs(x<0?\"#{-c} 0 0 #{y}\":\"0 #{y} #{c} 0\")\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "d60856f1900bb3a418e811f287c9fb67", "src_uid": "e2f15a9d9593eec2e19be3140a847712", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b,n = gets.split.map(&:to_i)\ni=0\nloop do\n n -= (i == 0 ? a : b).gcd(n)\n if n < 0\n puts i^1\n exit\n end\n i ^= 1\nend", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "b789d16d97f03bc34e8f9b8070958f5d", "src_uid": "0bd6fbb6b0a2e7e5f080a70553149ac2", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = Integer(gets)\na = gets.split(\" \")\nfor i in 0..n-1\n a[i] = Integer(a[i])\nend\nd = []\nd[0] = 999999\nmin = 999999\nmd = 0\nfor j in 1..n-1\n value = a[j]-a[j-1]\n if value > md\n md = value\n end\nend\n\nfor j in 1..n-1\n d[j] = a[j]-a[j-1]\n value = d[j] + d[j-1]\n if value < min\n min = value\n end\n if min < md\n min = md\n break\n end\nend\nputs min\n", "lang_cluster": "Ruby", "tags": ["brute force", "math", "implementation"], "code_uid": "9a47cd7250f4df16184e55b6309f06cf", "src_uid": "8a8013f960814040ac4bf229a0bd5437", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "gets\na,b=$<.map{|e|e.split}\nputs (a&b).empty? ? [a.min,b.min].sort.reduce(:+) : (a&b).min", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "9e923251c7fc15dce8b01bd76653c966", "src_uid": "3a0c1b6d710fd8f0b6daf420255d76ee", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby 3", "source_code": "END { load __FILE__ unless $stdin.eof? }\n\nn, m = gets.split.map!(&:to_i)\n\ncnt = Array.new(n + 1, 0)\nsum = Array.new(n + 2, 0)\ncnt[n] = 1\nsum[n] = 1\n\nn.pred.downto(1) do |i|\n cnt[i] = sum[i+1]\n\n (i * 2).step(n, i) do |k|\n cnt[i] += sum[k]\n cnt[i] %= m\n end\n (i.succ * 2).step(n, i.succ) do |k|\n cnt[i] -= sum[k]\n cnt[i] %= m\n end\n\n sum[i] = (sum[i+1] + cnt[i]) % m\nend\n\np cnt[1]\n", "lang_cluster": "Ruby", "tags": ["brute force", "math", "dp", "data structures", "number theory"], "code_uid": "69a5eb882134d992843095957e76d03f", "src_uid": "a524aa54e83fd0223489a19531bf0e79", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/env ruby\nMOD = 1000000007\nm = gets.chomp\ncnt = Array.new(15, 0)\ndef cal(remain, lucky, amount, cnt)\n if remain == 0\n cnt[lucky] += amount\n return\n end\n cal(remain - 1, lucky, amount * 8, cnt)\n cal(remain - 1, lucky + 1, amount * 2, cnt)\nend\nt = 0\nfor i in 0...m.size\n for j in 0...m[i].to_i\n is_lucky = j == 4 || j == 7 ? 1 : 0\n cal(m.size - i - 1, t + is_lucky, 1, cnt)\n end\n t += 1 if m[i] == '4' || m[i] == '7'\nend\ncnt[t] += 1\ncnt[0] -= 1\ndef dfs(party_amount, lucky_amount, method_amount, cnt)\n return if lucky_amount > 9\n if party_amount == 6\n (lucky_amount + 1).upto(9) do |i|\n cnt[10] = (cnt[10] + method_amount * cnt[i]) % MOD\n end\n else\n for i in 0..9\n next unless cnt[i]\n cnt[i] -= 1\n dfs(party_amount + 1, lucky_amount + i, (method_amount * (cnt[i] + 1)) % MOD, cnt)\n cnt[i] += 1\n end\n end\nend\ndfs(0, 0, 1, cnt)\nputs cnt[10] % MOD", "lang_cluster": "Ruby", "tags": ["brute force", "dp", "combinatorics"], "code_uid": "4f3fdc80a7fff0bece10c0f9c5fd42d3", "src_uid": "656ed7b1b80de84d65a253e5d14d62a9", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a = gets.chomp\n\nvowels = 'AEIOUY'.split('')\n\ncs = a.split('').map { |c| vowels.include?(c)}\n\nans = 1\ncnt = 1\nfor i in 0...a.size\n if !cs[i]\n cnt += 1\n else\n ans = [ans, cnt].max\n cnt = 1\n end\nend\nans = [ans, cnt].max\n\nputs ans\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "809d0a4ba8cbb066f0ddc858c30d8fe4", "src_uid": "1fc7e939cdeb015fe31f3cf1c0982fee", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "l,d,v,g,r = gets.split(\" \").map(&:to_i)\n\ntill_a = d/v.to_f\n# puts \"#{till_a}\"\ntotal_interval = g + r\n# puts \"total_interval#{till_a % total_interval}\"\nextra_time = (till_a % total_interval) >= g ? (total_interval - (till_a % total_interval)) : 0\n# puts \"#{extra_time}\"\na_to_b = (l-d) / v.to_f\n# puts \"#{a_to_b}\"\n# \n\nputs till_a + extra_time + a_to_b", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "84c3dc28f7dc70db5fbb198f7da3aced", "src_uid": "e4a4affb439365c843c9f9828d81b42c", "difficulty": 1500.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": "051d210d717280c1174ead15f1955586", "src_uid": "4e57740be015963c190e0bfe1ab74cb9", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "arr = [100,20,10,5,1]\nn = gets.to_i\nidx = 0\nans = 0\nwhile n!=0 do\n while n 0 ? 1 : 0)\nk2 = n - (m - 1)\ncouples = lambda {|n| n*(n-1)/2}\nsame = n%m == 0 ? m : n%m\nother = n%m != 0 ? couples.call(n/m) * (m - n%m) : 0\nprint couples.call(k1)*same+other, ' ', couples.call(k2)", "lang_cluster": "Ruby", "tags": ["math", "greedy", "constructive algorithms", "combinatorics"], "code_uid": "c4c85e60fa9e29c44bcf6a771ded81c5", "src_uid": "a081d400a5ce22899b91df38ba98eecc", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "puts gets.to_i * 3 / 2", "lang_cluster": "Ruby", "tags": ["math", "number theory"], "code_uid": "c8ead0e9b9b5fe553179e734d2b5ba71", "src_uid": "031e53952e76cff8fdc0988bb0d3239c", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = gets.chomp!.gsub(/\\/+/, \"/\")\nif s.length > 1\n s.gsub!(/\\/$/, \"\")\nend\nputs s ", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "df91c84849d77f2ad2a0775e078de572", "src_uid": "6c2e658ac3c3d6b0569dd373806fa031", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,m,r = gets.split.map(&:to_i)\ns = gets.split.map(&:to_i).min\nb = gets.split.map(&:to_i).max\nif s > b\n puts r\nelse\n puts r%s+(r/s)*b\nend\n", "lang_cluster": "Ruby", "tags": ["greedy", "implementation"], "code_uid": "46ca598ebaca56bdcf3afe2ea34fd870", "src_uid": "42f25d492bddc12d3d89d39315d63cb9", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "p 2**gets.to_i*2-2", "lang_cluster": "Ruby", "tags": ["math", "combinatorics"], "code_uid": "c3af641b32e3f902ea287f73f7dada6f", "src_uid": "f1b43baa14d4c262ba616d892525dfde", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,a,b = gets.split.map(&:to_i)\n\nn -= a\n\nif n > b + 1\n n = b + 1\nend\nputs n\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "6907c0b629e817100a29790200b5e9eb", "src_uid": "51a072916bff600922a77da0c4582180", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a = gets.strip\nwas = {[0,0] => 1}\nx, y = [0,0]\nbad = false\ni = 1\na.split('').each{ |c| \n i += 1\n x -= 1 if c == 'L'\n x += 1 if c == 'R'\n y -= 1 if c == 'D'\n y += 1 if c == 'U'\n bad = true if !was[[x, y]].nil? && was[[x, y]] != 0\n (-1..1).each{|a|\n (-1..1).each{|b|\n next if a*a + b* b != 1\n if !was[[x+a, y+b]].nil? and was[[x+a, y+b]] > 0 then\n bad = true if was[[x+a, y+b]] != i - 1\n end\n }\n }\n was[[x, y]] = i\n}\nif bad then \n puts 'BUG'\nelse\n puts 'OK'\nend\n", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation", "graphs"], "code_uid": "af0e871cac55a36b911a1213c1f0b1f9", "src_uid": "bb7805cc9d1cc907b64371b209c564b3", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s=gets(p).split\np (1..s.pop.to_i).count{|i|s.any?{|j|i%j.to_i==0}}\n", "lang_cluster": "Ruby", "tags": ["math", "constructive algorithms", "implementation"], "code_uid": "2ee502ebfc8f1fc6e787760eb8c2c9fe", "src_uid": "46bfdec9bfc1e91bd2f5022f3d3c8ce7", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#$stdin = File.open('in.txt')\n#$stdout = File.open('out.txt', 'w')\n\nn = gets.to_i\n\nans = 0\nwhile (n > 0) do\n ans += 1 if n % 2 == 1\n n /= 2\nend\n\np ans\n", "lang_cluster": "Ruby", "tags": ["bitmasks"], "code_uid": "8dd24d6625e528a00831e44dbeceaa1b", "src_uid": "03e4482d53a059134676f431be4c16d2", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "puts gets.split('+').map(&:to_i).sort.join('+')\n", "lang_cluster": "Ruby", "tags": ["sortings", "strings", "implementation", "greedy"], "code_uid": "b0529ac3ac36fede8ee2656923bd0e07", "src_uid": "76c7312733ef9d8278521cf09d3ccbc8", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, m = STDIN.read.split(' ').map(&:to_i)\n\nif m > n\n puts -1\nelse\n steps = n / 2 + (n % 2)\n cand = steps\n while (cand % m) != 0 do\n cand += 1\n end\n puts cand\nend", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "4996eaf54d8480301b76ab52fb7fab22", "src_uid": "0fa526ebc0b4fa3a5866c7c5b3a4656f", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def f(x)\n\ty = x.to_s\n\ts = 0\n\tfor i in 0...y.length()\n\t\ts += y[i].to_i\n\tend\n\treturn s\nend\nn = 0\ntab = []\na, b, c = gets.split().map(&:to_i)\nfor s in 1..100\n\tx = b*s**a+c\n\tif x > 0 and x < 1000000000 and f(x) == s\n\t\tn += 1\n\t\ttab += [x]\n\tend\nend\nputs n\nif n != 0\n\ttab.sort!\n\tfor i in 0...tab.length()\n\t\tprint tab[i]\n\t\tprint \" \"\n\tend\n\tputs \nend\n", "lang_cluster": "Ruby", "tags": ["brute force", "math", "implementation", "number theory"], "code_uid": "1243123901c891e90fb841d0bf99b7c6", "src_uid": "e477185b94f93006d7ae84c8f0817009", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "require 'prime'\nn = gets.to_i\nif n%2 == 0\n if n == 2\n print 1\n else\n print 2\n end\nelse\n a = Prime.prime?(n)\n b = Prime.prime?(n-2)\n if(a)\n print 1\n else\n if(b)\n print 2\n exit\n end\n print 3\n end\nend\n", "lang_cluster": "Ruby", "tags": ["math", "number theory"], "code_uid": "b1a3106f1c3b708a3877a464d627f18d", "src_uid": "684ce84149d6a5f4776ecd1ea6cb455b", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/ruby\nn=gets.chomp\np [n,*(1...n.size).map{|i|\n\t(n[0,i].to_i-1).to_s+'9'*(n.size-i)\n}].max_by{|e|[e.chars.map(&:to_i).reduce(:+),e.to_i]}.to_i", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "588f1accd397aeb9f4727ccff1e6b572", "src_uid": "e55b0debbf33c266091e6634494356b8", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a='qwertyuiopasdfghjkl;zxcvbnm,./'\na=a.split(\"\")\nb=gets.chomp\nif b==\"R\"\nb=-1\nelse\nb=1\nend\nc=gets.chomp.split(\"\")\nc.each do|i|\ntemp=a.index(i)+b\nprintf \"#{a[temp]}\"\nend\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "41929b8d7b1a962923396d1f0ffe1477", "src_uid": "df49c0c257903516767fdb8ac9c2bfd6", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a, b = gets.split.map(&:to_i)\nc, d = gets.split.map(&:to_i)\nmemo = Array.new(100000)\nr, m = b, d\nwhile r <= 100000\n memo[r] = true\n r += a\nend\nans = -1\nwhile m <= 100000\n if memo[m]\n ans = m\n break\n end\n m += c\nend\np ans\n", "lang_cluster": "Ruby", "tags": ["brute force", "math", "number theory"], "code_uid": "5717c5e7d7f0dbb33e88e2025056ca43", "src_uid": "158cb12d45f4ee3368b94b2b622693e7", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "string = gets.chomp\nif string.length >= 5 && !(string =~ /[A-Z]/).nil? && !(string =~ /[a-z]/).nil? && !(string =~ /\\d/).nil?\n puts 'Correct'\nelse\n puts 'Too weak'\nend\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "d7c4e7c0cf0da9cce816e89518196e88", "src_uid": "42a964b01e269491975965860ec92be7", "difficulty": 800.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": "9b39b98666b9824e84fd4bc502c522a3", "src_uid": "51155e9bfa90e0ff29d049cedc3e1862", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,k=gets.split.map(&:to_i);\np=[];input=[];\nn.times{\n s=gets.split[0]\n tmp=[]\n k.times{|i|\n tmp.push(s[i].to_i)\n }\n input.push(tmp)\n}\nans=[]\nk.times{|i|\n p.push(i);\n}\np.permutation{|a|\n t=[]\n input.each{|i|\n tmp=0\n k.times{|j|\n tmp*=10\n tmp+=i[a[j]]\n }\n t.push(tmp)\n }\n ans.push(t.max-t.min)\n}\np ans.min", "lang_cluster": "Ruby", "tags": ["brute force", "implementation", "combinatorics"], "code_uid": "685ffb0237608a8add39ee70aa7939a1", "src_uid": "08f85cd4ffbd135f0b630235209273a4", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.strip.to_i\nary = gets.strip.split.map(&:to_i)\n\nary.sort!\nnf = n * 1.0\nsum = ary.inject(:+)\n\nmin_req_sum = (4.5 * nf).ceil\n# puts \"#{min_req_sum} : #{sum}\"\nif min_req_sum <= sum\n puts 0\nelse\n diff = min_req_sum - sum\n i = 0\n ans = 0\n while diff > 0 do\n inc = 5 - ary[i]\n diff -= inc\n ans += 1\n i += 1\n end\n puts ans\nend", "lang_cluster": "Ruby", "tags": ["sortings", "greedy"], "code_uid": "28fc3578094be4f499464afa2541f7b7", "src_uid": "715608282b27a0a25b66f08574a6d5bd", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s, v1, v2, t1, t2 = gets.strip.split.map(&:to_i)\nfirst = (s * v1) + (t1 * 2)\nsecond = (s * v2) + (t2 * 2)\nif first < second\n puts \"First\"\nelsif second < first\n puts \"Second\"\nelse\n puts \"Friendship\"\nend\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "2554788c326de684a556ac8183d2a867", "src_uid": "10226b8efe9e3c473239d747b911a1ef", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "ar = gets.chomp\nhs = ar.split(//).group_by{|x| x=~/[[:upper:]]/}\nhs.default = []\nif hs[0].length > hs[nil].length\n puts ar.upcase\nelse\n puts ar.downcase\nend", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "e65d420103f13f5dc25063b7054e2ace", "src_uid": "b432dfa66bae2b542342f0b42c0a2598", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a, b, c, d = gets.split.map &:to_i\np = [a, b, c].sort\nputs [d - p[1] + p[0], 0].max + [d - p[2] + p[1], 0].max\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "1e697633d3966166762ffec97258ad40", "src_uid": "47c07e46517dbc937e2e779ec0d74eb3", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "class Array\n def r\n self.map { |q| q.to_i }\n end\nend\n\ndef read_line\n STDIN.gets.split(\" \")\nend\n\ndef read_to_array\n read_line.to_a\nend\n\ndef read_numbers_to_array\n read_to_array.r\nend\n\na, b, c = read_numbers_to_array\nif a * 2 + b * 2 < a + b + c\n puts a + a + b + b\nelse\n if b * 2 + c * 2 < a + b + c\n puts b + b + c + c\n else\n if c * 2 + a * 2 < a + b + c\n puts a + a + c + c\n else\n puts a + b + c\n end\n end\nend\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "f3ddd21da4bb1df0b9d0928d0ecb1d4e", "src_uid": "26cd7954a21866dbb2824d725473673e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "hint = gets\ntemp = hint\narr = Array.new()\nnum = 10\nres = 1\nif hint[0] == '?'\n res *= 9\nelsif hint[0] > '9'\n res *= 9\n hint = hint[0] + temp.gsub(hint[0],'')\n num = num - 1\nend\nhint[0] = ''\nhint.each_char {|c|\n if c == '?'\n res *= 10\n elsif c > '9' && !(arr.include?(c))\n res *= num\n arr << c \n num = num - 1\n end \n}\n\nputs res\n", "lang_cluster": "Ruby", "tags": ["greedy"], "code_uid": "4558b30b5cd6e6cc4c21446cad2df541", "src_uid": "d3c10d1b1a17ad018359e2dab80d2b82", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "r,c = gets.split.map{|i| i.to_i }\n\nmas = []\nsr = []\nsc = []\nr.times do |i|\n str = gets.chomp\n mas[i] = str.split(\"\")\n if str.include? \"S\" then\n sr << i\n k = -1\n while (k = str.index(\"S\", k+1)) do\n sc << k\n end\n end\nend\n\nsum = r*c\nr.times do |i|\n c.times do |j|\n if sr.include?(i) && sc.include?(j) then\n sum -= 1\n end\n end\nend\n\nputs sum", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "8c9bf05301a405c753f9aa19bc852bcb", "src_uid": "ebaf7d89c623d006a6f1ffd025892102", "difficulty": 800.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 ans = 1\n if r == n\n ans += (pos - l).abs\n else\n ans += (pos - r).abs\n end\n puts ans\nelse\n ans = 2\n ans += [(pos - l).abs, (pos - r).abs].min\n ans += r - l\n puts ans\nend\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "fdfdbad38ced72ec20dd57ff3dca0f06", "src_uid": "5deaac7bd3afedee9b10e61997940f78", "difficulty": 1300.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": "864b3f8015a8e06dff5ae67e09895190", "src_uid": "97fd9123d0fb511da165b900afbde5dc", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "\nn, k = gets.split(\" \").map(&:to_i)\n\n\nopens = n\nthrows = n+1\nmoves = n-1 + [k-1,n-k].min\n\nputs opens + throws + moves\n\n\n", "lang_cluster": "Ruby", "tags": ["math", "constructive algorithms"], "code_uid": "891d102e6547a927ad88eff04e5a9009", "src_uid": "24b02afe8d86314ec5f75a00c72af514", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "# coding: utf-8\n\nn = gets.to_i\nsched = gets.strip.gsub(' ', '')\n\nsched.gsub!(/^0+/, '')\nsched.gsub!(/0+$/, '')\nsched.gsub!(/0{2,}/, '')\n\nputs sched.length.to_s", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "e7c613a095989af2966307936f74bcfe", "src_uid": "2896aadda9e7a317d33315f91d1ca64d", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "N, B = gets.split.map(&:to_i)\nas = gets.split.map(&:to_i)\n\nsum = 0\ncand = []\n(N-1).times do |i|\n sum += as[i]%2==0 ? 1 : -1\n cand.push((as[i] - as[i+1]).abs) if sum == 0\nend\ncand.sort!\nans = 0\nsum = 0\ncand.each do |c|\n sum += c\n if sum <= B\n ans += 1\n else\n break\n end\nend\nputs ans", "lang_cluster": "Ruby", "tags": ["sortings", "dp", "greedy"], "code_uid": "d17984de3d61044eb5f2c21bfc59ee19", "src_uid": "b3f8e769ee7719ea5c9f458428b16a4e", "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": "a6226f401a45b8c0ad4dec3c7eca2a8a", "src_uid": "e853733fb2ed87c56623ff9a5ac09c36", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "EPS=1e-9\ndef s(x)\n\tret=0\n\twhile x>0\n\t\tret+=x%10\n\t\tx/=10\n\tend\n\tret\nend\n\ndef is_int?(_x)\n\tx=_x.round\n\t(x-EPS<=_x)&&(_x<=x+EPS)\nend\n\nn=gets.to_i\nans=100.times.map{|s|\n\t_x=(-s+(s*s+4*n)**0.5)/2.0\n\tif is_int?(_x)\n\t\tx=_x.round\n\t\tif x*x+s(x)*x-n==0\n\t\t\tx\n\t\telse\n\t\t\tnil\n\t\tend\n\telse\n\t\tnil\n\tend\n}\n\np ans.any? ? ans.compact.min : -1", "lang_cluster": "Ruby", "tags": ["brute force", "math", "binary search"], "code_uid": "63050fe67d5b4db9e28cf6a6f1d21b56", "src_uid": "e1070ad4383f27399d31b8d0e87def59", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, m = gets.chomp.split(' ').map(&:to_i)\nx = 1\nans = 0\nuntil x > n\n\tans += ((m + x) / 5) - (x / 5)\n\tx += 1\nend\n\nputs ans", "lang_cluster": "Ruby", "tags": ["math", "constructive algorithms", "number theory"], "code_uid": "8c9829b813cc491b5768918820d6a490", "src_uid": "df0879635b59e141c839d9599abd77d2", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "x,y,m=gets.split.map(&:to_i)\nx,y = y,x if x > y\nres = 0\nif x < 0 and y > 0 and m > y\n t = (-x+y-1)/y\n x += t*y\n res += t\nend\ncnt=0\nwhile y < m\n x,y = y,x+y\n cnt+=1;\n break if cnt > 100\nend\nputs cnt > 100 ? -1 : res+cnt", "lang_cluster": "Ruby", "tags": ["math", "greedy"], "code_uid": "d4a235e2370030685b92c55d895e0415", "src_uid": "82026a3c3d9a6bda2e2ac6e14979d821", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def answer(num)\n ret = []\n counts = Hash.new(0)\n num.each_char.with_index do |c, index|\n i = c.to_i\n case i\n when 4,7\n if counts[c] == num.size / 2 && c == '4'\n c = '7'\n end\n if counts[c] < num.size / 2\n ret << c\n counts[c] += 1\n next\n end\n when 0..3\n if counts['4'] == num.size / 2\n ret << '7'\n counts['7'] += 1\n end\n ret << '4' * (num.size / 2 - counts['4'])\n ret << '7' * (num.size / 2 - counts['7'])\n return ret.join\n when 5,6\n if counts['7'] < num.size / 2\n ret << '7'\n counts['7'] += 1\n ret << '4' * (num.size / 2 - counts['4'])\n ret << '7' * (num.size / 2 - counts['7'])\n return ret.join\n end\n when 8,9\n if index == 0\n size = (num.size + 2) / 2\n return ('4' * size) + ('7' * size)\n end\n end\n while n = ret.pop\n counts[n] -= 1\n if n == '4' && counts['7'] < num.size / 2\n ret << '7'\n counts['7'] += 1\n ret << '4' * (num.size / 2 - counts['4'])\n ret << '7' * (num.size / 2 - counts['7'])\n return ret.join\n end\n end\n size = (num.size + 2) / 2\n return ('4' * size) + ('7' * size)\n end\n ret.join\nend\n\nnum = gets.strip\nif num.size % 2 == 1\n size = (num.size + 1) / 2\n puts '4' * size + '7' * size\nelse\n puts answer num\nend\n", "lang_cluster": "Ruby", "tags": ["brute force", "binary search", "bitmasks"], "code_uid": "26f26353fbaa4742d213a8fd2325d315", "src_uid": "77b5f83cdadf4b0743618a46b646a849", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "line = gets.chomp\n\nx, y, z, t1, t2, t3 = line.split.map(&:to_i)\n\nelevator_time = ( (z-x).abs + (x-y).abs ) * t2 + 3 * t3\nstair_time = (y-x).abs * t1\n\n# puts elevator_time\n# puts stair_time\n\nif stair_time >= elevator_time\n puts \"YES\"\nelse\n puts \"NO\"\nend", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "58bc43a5fa75688ed64fe43928881cee", "src_uid": "05cffd59b28b9e026ca3203718b2e6ca", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = gets.chomp\nt = gets.chomp\nputs s.reverse == t ? 'YES' : 'NO'\n", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "e59b26d2bc03d71986f54efb55efb0ea", "src_uid": "35a4be326690b58bf9add547fb63a5a5", "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": "b516eb07e7dc839aaac751dda1f65596", "src_uid": "42454dcf7d073bf12030367eb094eb8c", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "# your code goes here\n\ninp = STDIN.read.split(\"\\n\")\n\nn = inp[0]\nw = inp[1]\n\nflag = false\n\nno_parenthesis = \"\"\nwith_parenthesis = \"\"\n\ncounter = 0\nw.split(\"\").each do |c|\n\t\n\tif c == \"(\"\n\t\tflag = true\n\t\tnext\n\tend\n\n\tif c == \")\"\n\t\tflag = false\n\n\t\twith_parenthesis.split(\"_\").each do |cur|\n\t\t\tcounter = counter + 1 if cur.length > 0\n\t\tend\n\t\t\n\t\twith_parenthesis = \"\"\n\t\t\n\t\tno_parenthesis += \"_\"\n\t\tnext\n\tend\n\t\n\twith_parenthesis += c if flag\n\tnext if flag\n\tno_parenthesis += c \nend\n\nmax_l = 0\nno_parenthesis.split(\"_\").each do |w|\n max_l = w.length if w.length > max_l\t\nend\n\nputs \"#{max_l} #{counter}\"", "lang_cluster": "Ruby", "tags": ["expression parsing", "strings", "implementation"], "code_uid": "442479859dfbde0ff2bac3908f2ca694", "src_uid": "fc86df4931e787fa3a1a40e2aecf0b92", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "vals = gets.split.map{|s| s.to_i}\n\nmaxv = 0\nmaxi = -1\nsum = 0\nres = []\nvals.each_index {|i|\n\tsum += vals[i]\n\tif maxv < vals[i]\n\t\tmaxv = vals[i]\n\t\tmaxi = i\n\tend\n}\nif sum % 2 == 1\n\tprint \"Impossible\"\nelsif sum - maxv < maxv\n\tprint \"Impossible\"\nelse\n\tdif = sum/2 - maxv\n\tres[maxi] = vals[(maxi+1)%3]-dif\n\tres[(maxi+1)%3] = dif\n\tres[(maxi+2)%3] = vals[(maxi+2)%3]-dif\n\tprint res.join(\" \")\nend", "lang_cluster": "Ruby", "tags": ["brute force", "math", "graphs"], "code_uid": "4c09c35767abf901ae81b76efd56ca3c", "src_uid": "b3b986fddc3770fed64b878fa42ab1bc", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a, b = gets.split.map(&:to_i)\ns = gets.chop\n\nif a < 0\n a = -a\n s.tr! 'LR', 'RL'\nend\n\nif b < 0\n b = -b\n s.tr! 'UD', 'DU'\nend\n\nmaxx = maxy = x = y = 0\n\ndef step(x, y, c)\n if c == 'U' then\n y += 1\n elsif c == 'D' then\n y -= 1\n elsif c == 'R' then\n x += 1\n elsif c == 'L' then\n x -= 1\n end\n [x, y]\nend\n\ns = \"0#{s}\"\ns.each_char do |c|\n x, y = step x, y, c\n maxx = x if x > maxx\n maxy = y if y > maxy\nend\n\ndx = x\ndy = y\n\nstartx = a - maxx - 1\nstarty = b - maxy - 1\n\ninf = 10**9 + 10\niter = inf\niter = startx / dx if dx > 0\niter = [iter, starty / dy].min if dy > 0\n\niter = 0 if iter == inf or iter < 0\n\nx = iter * dx\ny = iter * dy\n\ns.size.times do\n s.each_char do |c|\n x, y = step x, y, c\n if x == a and y == b\n puts 'Yes'\n exit\n end\n end\nend\n\nputs 'No'\n\n\n", "lang_cluster": "Ruby", "tags": ["math", "implementation", "number theory"], "code_uid": "e58f636d5eabd3cb6297fa69116399c0", "src_uid": "5d6212e28c7942e9ff4d096938b782bf", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "hello = \"hello\"\ninput = gets.chomp\ni = 0\npass = false\ninput.each_char do |char|\n if char == hello[i]\n i += 1\n end\n if i == hello.length\n pass = true\n break\n end\nend\n\nif pass\n puts \"YES\"\nelse\n puts \"NO\"\nend", "lang_cluster": "Ruby", "tags": ["greedy", "strings"], "code_uid": "dc908762a06e7e01991ec69e793e1048", "src_uid": "c5d19dc8f2478ee8d9cba8cc2e4cd838", "difficulty": 1000.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\nres=0\n[m,n].min.times {|i| res+=a[i] }\nputs res-d*[0,m-n].max\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "543ae682f12f095b70bc11def62c73b6", "src_uid": "5c21e2dd658825580522af525142397d", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "arr = gets.split.map &:to_i\n$n, x0, y0, dx, dy, t = arr\ndx %= $n\ndy %= $n\n\ndef zmul(a, b)\n ans = 0\n 6.times do |i|\n ans += (a[i] * b[i] - 1) % $n + 1\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] += (@mat[i][k] * rhs[k][j] - 1) % $n + 1\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..-1] = [0, 1]\nputs \"#{zmul(mat[0], arr)} #{zmul(mat[1], arr)}\"\n", "lang_cluster": "Ruby", "tags": ["math", "matrices"], "code_uid": "1b37dd3777d8ea8afcd0dcf7eada7c6d", "src_uid": "ee9fa8be2ae05a4e831a4f608c0cc785", "difficulty": 2300.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": "7d9d3e62d6d496658bcee6807397549c", "src_uid": "d90e99d539b16590c17328d79a5921e0", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "puts gets=~/[AEIOUY]\\W*\\?/i? :YES : :NO\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "0325e4895b0ca10439ab7b44ce9def09", "src_uid": "dea7eb04e086a4c1b3924eff255b9648", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "l,r,x,y,k=gets.split.map &:to_i\nl=(l+k-1)/k\nr=r/k\nputs l<=r && x<=r && l<=y ? :YES : :NO", "lang_cluster": "Ruby", "tags": ["two pointers", "brute force"], "code_uid": "19f271fcc11c645eb238454b6d7f1fd0", "src_uid": "1110d3671e9f77fd8d66dca6e74d2048", "difficulty": 1200.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": "c5bac00b1059cc3261b348f43fa0c1e7", "src_uid": "95b19d7569d6b70bd97d46a8541060d0", "difficulty": 900.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": "da5f1f980a2e0a852bd29da840958c12", "src_uid": "5c4bd12df3915186a7b506c2060db125", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "m, s = gets.split.map &:to_i\nsmall, large = '-1', '-1'\nif s == 0 and m == 1 then\n small, large = '0', '0'\nelsif s > 0 and m * 9 >= s\n small = '0' * m\n small[0] = '1'\n r = s - 1\n (m-1).downto(1).each do |i|\n if r <= 9 then\n small[i] = (r + '0'.ord).chr\n r = 0\n else\n small[i] = '9'\n r -= 9\n end\n end\n if r > 0 then\n small[0] = (r + '1'.ord).chr\n end\n large = '0' * m\n (0...m).each do |i|\n if s <= 9 then\n large[i] = (s + '0'.ord).chr\n break\n else\n large[i] = '9'\n s -= 9\n end\n end\nend\nputs small + ' ' + large\n", "lang_cluster": "Ruby", "tags": ["greedy", "dp", "implementation"], "code_uid": "a0c159f1fd5ba527363008332e1d82f3", "src_uid": "75d062cece5a2402920d6706c655cad7", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.chomp\nif n.to_i >= 0 then\n puts n\nelse\n x=n.chop.to_i\n y=n.chop.chop.to_i*10-n[-1].to_i\n puts [x,y].max\nend", "lang_cluster": "Ruby", "tags": ["implementation", "number theory"], "code_uid": "ff98dca028bfbfd69b7cfabd16ec732e", "src_uid": "4b0a8798a6d53351226d4f06e3356b1e", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "d=gets.to_i.times.map { gets.split.map(&:to_i) }.transpose; p d[0].product(d[1]).select{|x,y| x==y}.length;", "lang_cluster": "Ruby", "tags": ["brute force"], "code_uid": "ddfe94ac16b9bb6afaa92e6692aa95af", "src_uid": "745f81dcb4f23254bf6602f9f389771b", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s1, s2, s3 = gets.chomp.split(/ /).map(&:to_i)\na = Math.sqrt( s1 * s3 / s2 )\nb = Math.sqrt( s1 * s2 / s3 )\nc = Math.sqrt( s2 * s3 / s1 )\nsum = 4 * ( a + b + c )\nputs sum.to_i\n", "lang_cluster": "Ruby", "tags": ["brute force", "math", "geometry"], "code_uid": "4d0f595bbdc3c3a681034f8996882edd", "src_uid": "c0a3290be3b87f3a232ec19d4639fefc", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "w, m = gets.split.map(&:to_i)\n\nbase = []\nwhile m > 0 do\n base << m % w\n m /= w\nend\n\nbase.fill(0, base.size, 100)\n\nresult = \"YES\"\nfor i in 0...100\n if base[i] >= w -1\n base[i+1] += 1\n elsif base[i] > 1\n result = \"NO\"\n break\n end\nend\n\nputs result", "lang_cluster": "Ruby", "tags": ["brute force", "math", "dp", "meet-in-the-middle", "greedy", "number theory"], "code_uid": "326674cafe4dc9fdc4f6a011e6fb6d8b", "src_uid": "a74adcf0314692f8ac95f54d165d9582", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "cityNum, livingCity = gets.chomp.split(' ').map(&:to_i)\ncriminals = gets.chomp.split(' ').map(&:to_i)\n\nmaxDist = [(cityNum - livingCity), livingCity - 1].max\ncheckedDist = 0\n\nsure = 0\n\nuntil checkedDist > maxDist\n\tleftCity = livingCity - checkedDist\n\trightCity = livingCity + checkedDist\n\n\tlackNumber = 0\n\tlackNumber += 1 if leftCity <= 0\n\tlackNumber += 1 if rightCity > cityNum\n\tif leftCity == rightCity\n\t\tsure += 1 if criminals[livingCity - 1] > 0\n\telse\n\t\tcase lackNumber\n\t\twhen 0 then sure += 2 if criminals[leftCity - 1] > 0 && criminals[rightCity - 1] > 0\n\t\twhen 1 then\tsure += 1 if (leftCity > 0 && criminals[leftCity - 1] > 0) || (rightCity <= cityNum && criminals[rightCity - 1] > 0)\n\t\tend\n\tend\n\n\tcheckedDist += 1\nend\n\nputs sure", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation"], "code_uid": "d79d96a49d4886599035b50612f378ac", "src_uid": "4840d571d4ce6e1096bb678b6c100ae5", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n1, n2, k1, k2 = gets.split.map(&:to_i)\n\nif n1 > n2\n puts 'First'\nelse\n puts 'Second'\nend\n", "lang_cluster": "Ruby", "tags": ["math", "constructive algorithms"], "code_uid": "45d6ce5d59c3c063ef9a30ee2e229c3b", "src_uid": "aed24ebab3ed9fd1741eea8e4200f86b", "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]", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "f9dbfbfb196e55f16a29dd58f86981d7", "src_uid": "2f650aae9dfeb02533149ced402b60dc", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "puts [\"January\", \"February\", \"March\", \"April\", \"May\", \"June\", \"July\", \"August\", \"September\", \"October\", \"November\", \"December\"][({\"January\"=>0, \"February\"=>1, \"March\"=>2, \"April\"=>3, \"May\"=>4, \"June\"=>5, \"July\"=>6, \"August\"=>7, \"September\"=>8, \"October\"=>9, \"November\"=>10, \"December\"=>11}[gets.chomp]+gets.to_i)%12]", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "f88c5cbfbdd9e59b5c46de76befc53e6", "src_uid": "a307b402b20554ce177a73db07170691", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b=gets.split.map &:to_i;p a==b ? a : 1", "lang_cluster": "Ruby", "tags": ["math", "number theory"], "code_uid": "056a3db2a69fc9ec074e3c953651f6b1", "src_uid": "9c5b6d8a20414d160069010b2965b896", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "gets\ns = gets.chomp\n\nresult = ''\n1.upto(10) do |i|\n break if s.empty?\n\n result += s[0]\n\n s.replace s[i..-1]\nend\n\nputs result\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "2a90dba151667bdc068dadb0b11791ca", "src_uid": "08e8c0c37b223f6aae01d5609facdeaf", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,l = gets.split.map &:to_i\nc = gets.split.map &:to_i\n\n(n-1).times{|i| c[i+1] = c[i]*2 if c[i+1] > c[i]*2}\n\nans = []\njust = 0\n(n-1).downto(0){|i|\n d = (i+1).times.map{|j| c[j]*(2**(i-j))}\n x = 2**i\n ne = l/x\n l %= x\n just += d.min*ne\n ans << just + d.min\n}\n\nans << just\n\np ans.min", "lang_cluster": "Ruby", "tags": ["greedy", "dp", "bitmasks"], "code_uid": "5988ca9445537bdea3c406a8b112c107", "src_uid": "04ca137d0383c03944e3ce1c502c635b", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, t, k, d = gets.split.map(&:to_i)\nfst = (n + k - 1) / k * t\nsnd = fst + 1\nfor i in 0 .. fst\n tmp = i / t * k\n if i >= d\n tmp += (i - d) / t * k\n end\n if tmp >= n\n snd = i\n break\n end\nend\nputs (fst > snd ? \"YES\" : \"NO\")\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "53fd61263039a39a584735f9dbf7982e", "src_uid": "32c866d3d394e269724b4930df5e4407", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "p [3**~-gets.to_i%1000003,1].max\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "1a2f9c36ba36e36b1f9073848ca63397", "src_uid": "1a335a9638523ca0315282a67e18eec7", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "w,h,k=gets.split.map &:to_i\np k*(2*(w+h)-8*k+4)", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "89bf608cc949df39ddfae4e44f5b527b", "src_uid": "2c98d59917337cb321d76f72a1b3c057", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.to_i;a=gets.split.map(&:to_i);(amax,amin)=[a.find_index(a.max),a.find_index(a.min)];puts [amax, n-amax-1, amin, n-amin-1].max", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation"], "code_uid": "d83ce34876ef6abeb7314080d4cab85e", "src_uid": "1d2b81ce842f8c97656d96bddff4e8b4", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "arr = gets.split(\" \").map(&:to_i)\n\n\n# if sum >=3\n# \tmin,min_ind = arr.each_with_index.min\n# \tarr.delete_at(min_ind)\n# \tarr = arr.map{|e| e - min}\n# \tans = min\n# \tsum = arr.inject(0,:+) \n# \tif sum >= 3 \n# \t\tmax = arr.max\n# \t\tpair = max / 2\n# \t\tmin = arr.min\n# \t\tif pair <= min\n# \t\t\tans += pair\n# \t\t\tif pair % 2 != 0\n# \t\t\t\tmin -= pair\n# \t\t\t\tans += 1 if min >= 2\n# \t\t\tend\n# \t\telse\n# \t\t\tans += min\n# \t\tend\n\n# \tend\n# end\n# arr = []\n# ac2 = a/2\n# bc2 = b/2\n# cc2 = c/2\n# # 0 2 1\n# arr << [bc2,c].min\n# # 0 1 2\n# arr << b + cc2 \n# # 1 1 1\n# arr << a + b + c\n# # 1 2 0\n# # 1 0 2\n# puts ans\n# 66,\n# 34,23\n\narr.sort!\nif((2 * (arr[0] + arr[1])) <= arr[2])\n\tputs arr[0] + arr[1]\nelse\n\tputs arr.inject(0,:+) / 3\nend", "lang_cluster": "Ruby", "tags": ["greedy"], "code_uid": "cf71bdd5b1c109a9d2a80e09130d615b", "src_uid": "bae7cbcde19114451b8712d6361d2b01", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a=gets.chomp.split(\" \")\ns=a[1].to_i\nq=a[2].to_i\nt=a[0].to_i\nans=1\ns=s*q\nloop do \nif s 0)\n mod = temp % base\n temp = temp / base\n result = result + mod\n end\nend\n\nnominator = result\ndenominator = numOfBases\n\n#find the gcd, it's in nominator\nwhile denominator > 0\n temp = denominator\n denominator = nominator % denominator\n nominator = temp\nend\n\ndenominator = numOfBases / nominator\nnominator = result / nominator\n\nputs \"#{nominator}/#{denominator}\"", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "9a67cb4eb430975d8d81570139a1a2c1", "src_uid": "1366732dddecba26db232d6ca8f35fdc", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "arraynum1 = [\"zero\", \"one\",\"two\",\"three\",\"four\",\"five\",\"six\",\"seven\",\"eight\",\"nine\"]\narraynum2 = [nil , nil ,\"twenty\",\"thirty\",\"forty\",\"fifty\",\"sixty\",\"seventy\",\"eighty\",\"ninety\"]\narraynumtens = [\"ten\",\"eleven\",\"twelve\",\"thirteen\",\"fourteen\",\"fifteen\",\"sixteen\",\"seventeen\",\"eighteen\",\"nineteen\"]\nnumero = gets.chomp\narray = numero.split(//)\nif numero.to_i >=10 && numero.to_i <20\n print \"#{arraynumtens[array[1].to_i]}\"\n\nelsif array.length == 2\n if array[1].to_i == 0\n print \"#{arraynum2[array[0].to_i]}\"\n else \n print \"#{arraynum2[array[0].to_i]}-\"+\"#{arraynum1[array[1].to_i]}\"\n end\nelsif array.length == 1\n print \"#{arraynum1[array[0].to_i]}\"\nend", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "95ea832eff325ddccf6fde583c3c30da", "src_uid": "a49ca177b2f1f9d5341462a38a25d8b7", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, m = gets.split.map{|x| (x.to_i-1).to_s(7)}\nln, lm = [n, m].map(&:size)\nputs (0...7).to_a.permutation(ln + lm).lazy.map(&:join).select{|a| a[0...ln] <= n && a[ln..-1] <= m}.count", "lang_cluster": "Ruby", "tags": ["brute force", "math", "combinatorics"], "code_uid": "8c89454f1997ffc0f6f1fbf76bf14b1e", "src_uid": "0930c75f57dd88a858ba7bb0f11f1b1c", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "# coding: utf-8\n\nn, v = gets.split.map(&:to_i)\n\n# n cities, v liters of fuel tank\n# beginning: empty tank\n# each city has a gas station, i-th city=> $i/liter\n# minimize expense.\n# 2<=n<=100, 1<=v<=100\n\ntank = 0\ncity = 1\nexpense = 0\n\nwhile city < n\n fueling = [n - city, v - tank].min # (required, tank volume)\n # p \"> #{fueling} city #{city} n #{n}\"\n if n - city <= tank\n city += 1\n else\n expense += fueling*city\n tank += fueling\n city += 1\n end\n tank -= 1\nend\n\nputs expense", "lang_cluster": "Ruby", "tags": ["math", "greedy", "dp"], "code_uid": "bbaf4f69d4eb12b8c262db11f4f7a602", "src_uid": "f8eb96deeb82d9f011f13d7dac1e1ab7", "difficulty": 900.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": "8d8454b169a787286c765a8434f0c876", "src_uid": "2c4b2a162563242cb2f43f6209b59d5e", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "board=[]\nnum=0\nfor i in 0...8\n board[i]=STDIN.gets().chomp()\n all=true\n for j in 0...board[i].length\n if board[i][j]=='W'\n all=false\n break\n end\n end\n num+=1 if all\nend\n\nif num==8\n print(\"#{num}\\n\")\n exit()\nend\n\nfor i in 0...8\n all=true\n for j in 0...8\n if board[j][i]=='W'\n all=false\n break\n end\n end\n num+=1 if all\nend\nprint(\"#{num}\\n\")", "lang_cluster": "Ruby", "tags": ["brute force", "constructive algorithms"], "code_uid": "38d3b5e4e7a49342d0792b48ae952211", "src_uid": "8b6ae2190413b23f47e2958a7d4e7bc0", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def solve(p,k)\n b = [1]\n l = [0]\n r = [k]\n while true\n bb = b.last\n nb = -k*bb\n b.push(nb)\n if nb > 0\n r.push(r.last + (k-1)*nb)\n l.push(l.last)\n else\n l.push(l.last + (k-1)*nb)\n r.push(r.last)\n end\n break if p < r.last\n end\n\n ans = []\n while b.length > 1\n l.pop\n r.pop\n bb = b.pop\n le = l.last\n ri = r.last\n i = 0\n while !(le <= p && p < ri)\n p -= bb\n i += 1\n end\n ans.push(i)\n end\n ans.push(p)\n ans.reverse!\n while ans.last == 0\n ans.pop\n end\n return ans\nend\n\np, k = gets.chomp.split\np = p.to_i\nk = k.to_i\nans = solve(p,k)\nputs(ans.length)\nputs(ans.join(\" \"))\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "82ffd39c5fa2d6bf9fffebd441e7a1c0", "src_uid": "f4dbaa8deb2bd5c054fe34bb83bc6cd5", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def toi(n, x, y)\n\tif x == 0\n\t\treturn y\n\telsif y == n\n\t\treturn n + x\n\telsif x == n\n\t\treturn n + n + (n - y)\n\telse\n\t\treturn n + n + n + (n - x)\n\tend\nend\n\nn, x1, y1, x2, y2 = gets.split.map(&:to_i)\nz1 = toi(n, x1, y1)\nz2 = toi(n, x2, y2)\nm = 4 * n\nd = (z2 - z1 + m) % m\np [d, m - d].min\n", "lang_cluster": "Ruby", "tags": ["dfs and similar", "greedy", "implementation"], "code_uid": "fc898500aa69c83d42dae3e52dee3b0b", "src_uid": "685fe16c217b5b71eafdb4198822250e", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "num = gets.chomp.to_i\n\nn = Math::sqrt(8 * num + 1) - 1 / 2\n\nif n % 1.0 == 0\n puts \"YES\"\nelse\n puts \"NO\"\nend\n", "lang_cluster": "Ruby", "tags": ["brute force", "math"], "code_uid": "a262d244626cba295a99f46a463cc523", "src_uid": "587d4775dbd6a41fc9e4b81f71da7301", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, m = gets.split(\" \").map {|x| x.to_i}\ni = 0\nwhile n > 0\n n -= 1\n i += 1\n if i % m == 0\n n += 1\n end\nend\nputs(i)", "lang_cluster": "Ruby", "tags": ["brute force", "math", "implementation"], "code_uid": "e88f29bc4b6621f31e07facb150de7e4", "src_uid": "42b25b7335ec01794fbb1d4086aa9dd0", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "target = gets.chomp.to_i\nm = gets.chomp\nmonths = m.split\n\nfor i in (0..11)\n\tfor x in (i..11)\n\t\tif i != x\n\t\t\tif months[i].to_i > months[x].to_i\n\t\t\t\ttemp = months[i].to_i\n\t\t\t\tmonths[i] = months[x].to_i\n\t\t\t\tmonths[x] = temp\n\t\t\tend\n\t\tend\n\tend\nend\n\ngrowth = 0\ni = 11\ncount = 0\nwhile growth < target && i >= 0\n\tgrowth += months[i].to_i\n\tcount += 1\n\ti -= 1\nend\n\nif growth < target\n\tprint -1\nelse\n\tprint count\nend", "lang_cluster": "Ruby", "tags": ["sortings", "implementation", "greedy"], "code_uid": "24039a5b5914bcbcb5bb55a2e1a1f25e", "src_uid": "59dfa7a4988375febc5dccc27aca90a8", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "cubes = gets.chomp.to_i\n\nsum = 0\na = 0\n1.upto(1000){ |i|\n\ta += i\n\tsum += a\n\tif cubes < sum\n\t\tp i -1\n\t\texit\n\tend \n}", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "fa6667586aae318592ba36ea0bca9d1e", "src_uid": "873a12edffc57a127fdfb1c65d43bdb0", "difficulty": 800.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": "6342c0d9918ca27cb8a23f3434ac4fce", "src_uid": "142e5f2f08724e53c234fc2379216b4c", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby 3", "source_code": "t = gets.chomp.to_i\nt.times { puts (2 ** gets.chomp.to_i) - 1 }", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "15567e3c057a5b4f8b85464015ad87dc", "src_uid": "d5e66e34601cad6d78c3f02898fa09f4", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "number = gets.chomp.to_i\nstring = gets.chomp.downcase\n\nletters = string.split('')\n\nalphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']\n\nif number < 24\n\tprint \"NO\"\nelse\n\tfor i in (0..number-1)\n\t\tif alphabet.include? letters[i]\n\t\t\talphabet -= [letters[i]]\n\t\tend\n\tend\n\tif alphabet.size == 0\n\t\tprint \"YES\"\n\telse\n\t\tprint \"NO\"\n\tend\nend", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "e99e84a552d493b226b1625d44fc8857", "src_uid": "f13eba0a0fb86e20495d218fc4ad532d", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#bismillahir rahmanir rahim \n\nn,k = gets.split.map {|x| x.to_i } \n\nk = 240-k \nc = 0 \n\nfor i in 1..10 \n q = 5*i*(i+1)\n q = q/2 \n if k>=q \n c = c+1 \n end \nend \n\nc=n if c>n \n\nputs c ", "lang_cluster": "Ruby", "tags": ["brute force", "math", "implementation", "binary search"], "code_uid": "e19e1960ff8cebab8d0312a54c33fb7f", "src_uid": "41e554bc323857be7b8483ee358a35e2", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\nA = 'A'.ord\n\ndef convnum(twogram)\n return (twogram[0].ord - A)*26 + (twogram[1].ord - A)\nend\n\nn = gets.to_i\ns = gets.chomp\nb = s[0]\ncounter = Array.new(26*26) { 0 }\ns[1...n].split(//).each { |c|\n b += c\n counter[convnum(b)] += 1\n b = c\n}\n\nhighest_idx = -1\nhighest_freq = 0\n\ncounter.each_with_index { |item, index|\n if item > highest_freq\n highest_freq = item\n highest_idx = index\n end\n}\n\nputs \"#{(highest_idx/26 + A).chr}#{(highest_idx%26 + A).chr}\"\n", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "8f6e7a71367adc82d12755e63256bdc0", "src_uid": "e78005d4be93dbaa518f3b40cca84ab1", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.to_i\nprint n&n-1>0?:NO:\"YES\"", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "b7facb7c7db971a4f42a572ef77536ac", "src_uid": "4bd174a997707ed3a368bd0f2424590f", "difficulty": 1200.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": "eb8400af4e58ad9e12d9c2c6e50a42eb", "src_uid": "8ef8a09e33d38a2d7f023316bc38b6ea", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\n# 2, 3, 5, 6\nks = gets.split.map(&:to_i)\ntotal = 0\nmin256 = [ks[0], ks[2], ks[3]].min\ntotal += 256 * min256\nmin32 = [ks[0] - min256, ks[1]].min\ntotal += 32 * min32\n\nputs total\n", "lang_cluster": "Ruby", "tags": ["math", "greedy", "implementation", "brute force"], "code_uid": "8b2ee51db35da2547a68a67aaf0b7de4", "src_uid": "082b31cc156a7ba1e0a982f07ecc207e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/env ruby\n\nrgb = gets.split.map(&:to_i)\ntime = color = 0\nwhile rgb[0] > 0 || rgb[1] > 0 || rgb[2] > 0\n time += 1\n rgb[color] = rgb[color] < 2 ? 0 : rgb[color] - 2\n color = (color + 1) % 3\nend\nputs time+29\n", "lang_cluster": "Ruby", "tags": ["math", "greedy"], "code_uid": "c996fccfc42cf5f6648eeeeb973af07a", "src_uid": "a45daac108076102da54e07e1e2a37d7", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.chomp.to_i\ninterestings = gets.chomp.split(/ /).map(&:to_i)\nwatch = 0\nprev = 0\n(0...n).each do |i|\n curr = interestings[i]\n watch = curr\n if curr - prev > 15\n watch = prev + 15\n break\n end\n prev = curr\nend\nwatch = prev + 15 if 90 - prev > 15\nwatch = 90 if watch > 90 || 90 - prev <= 15\nputs watch\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "bc334611c1fc4bbd27ccdd6092e9f39e", "src_uid": "5031b15e220f0ff6cc1dd3731ecdbf27", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,k,*a=$<.read.split.map &:to_i\np a.all?{|e|e<=k}?n:a.index{|e|e>k}+(n-1-a.rindex{|e|e>k})", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "3413c2a5f072ce5074dcf77d06e0fb20", "src_uid": "ecf0ead308d8a581dd233160a7e38173", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "gets\narr = gets.split\n\ncnt1 = arr.count(?1)\nans = 0\ncnt0 = 0\n\narr.each do |x|\n\tif x == ?1\n\t\tans = [ans, cnt0 + cnt1].max\n\t\tcnt1 -= 1\n\telse\n\t\tcnt0 += 1\n\tend\nend\n\np [ans, cnt0 + cnt1].max", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "fb0ce5da65452ff5eee7d6ab1953eaa3", "src_uid": "c7b1f0b40e310f99936d1c33e4816b95", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, m = gets.split.map(&:to_i)\ni = 0\n\nloop do\n unless m - (i % n + 1) < 0\n m -= (i % n) + 1\n i += 1\n else\n break\n end\nend\n\nputs m\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "f53fb639af3252b4651291847c4a0ce3", "src_uid": "5dd5ee90606d37cae5926eb8b8d250bb", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "puts (a = gets.to_i) * (a + 1) / 2 % 2", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "3e285caf775fd65d192dbf8998464d77", "src_uid": "fa163c5b619d3892e33e1fb9c22043a9", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\nm = gets.to_i\n\nif n>=27\n puts m\nelse puts m%(1< c\n c = a[2] - a[0]\nend\nd = min a[1],(a[2]-4)\n\n(c..d).each do |i|\n m = tohop i,a[1]\n n = tohop a[2]-i,a[0]\n result += m*n\nend\n\nputs result", "lang_cluster": "Ruby", "tags": ["math", "combinatorics"], "code_uid": "e0f72283f6bdcfba29933b0ec6252f71", "src_uid": "489e69c7a2fba5fac34e89d7388ed4b8", "difficulty": 1400.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": "e2f333bb566b6c3e315a61cac4221bf5", "src_uid": "8b26ca1ca2b28166c3d25dceb1f3d49f", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def dist(x1,y1,x2,y2)\n x1-=x2\n y1-=y2\n x1=x1>0?x1:-x1\n y1=y1>0?y1:-y1\n return x1+y1\nend\n \nposx=[]\nposy=[]\ndelta=[]\nsm=[]\nargs=gets.split.collect{|s|s.to_i}\nx0,y0,ax,ay,bx,by=args[0],args[1],args[2],args[3],args[4],args[5]\nargs=gets.split.collect{|s|s.to_i}\nxs,ys,t=args[0],args[1],args[2]\nposx.push(x0)\nposy.push(y0)\ndelta.push(0)\nsm.push(0)\nwhile delta[-1]<=t+xs+ys\n x0,y0=ax*posx[-1]+bx,ay*posy[-1]+by\n delta.push(dist(x0,y0,posx[-1],posy[-1]))\n sm.push(delta[-1]+sm[-1])\n posx.push(x0)\n posy.push(y0)\nend\n \nma=0\nl=posx.length\nfor i in 0..l-1\n king=dist(xs,ys,posx[i],posy[i])\n for j in 0..i\n miles=(sm[i]-sm[j])+king\n cnt=i-j+1\n if miles<=t&&cnt>ma\n ma=cnt\n end\n miles+=(sm[i]-sm[j])\n for k in i+1..l-1\n miles+=delta[k]\n if miles<=t\n cnt+=1\n if(cnt>ma)\n ma=cnt\n end\n else \n break\n end\n end\n end\nend\nputs ma", "lang_cluster": "Ruby", "tags": ["brute force", "constructive algorithms", "implementation"], "code_uid": "81a708eb3208e352f7e9c6361b05a990", "src_uid": "d8a7ae2959b3781a8a4566a2f75a4e28", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a=gets.chomp.split(\" \")\ng=a[0].to_i\nc=a[1].to_i\n\nif c==0\nmin=g\nmax=g\nputs \"#{min} #{max}\"\nelsif g==0\nputs \"Impossible\"\nelsif g>=c\nmin=g\nmax=g+c-1\nputs \"#{min} #{max}\"\nelse\nmin=c\nmax=g+c-1\nputs \"#{min} #{max}\"\nend\n", "lang_cluster": "Ruby", "tags": ["math", "greedy"], "code_uid": "24c62584fb95542a6c187c692d331e36", "src_uid": "1e865eda33afe09302bda9077d613763", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a, b, c = gets.chomp.split(/ /).map(&:to_i)\nans = \"NO\"\nif c == 0\n ans = \"YES\" if a == b\nelse\n d = (b - a) % c\n e = (b - a) / c\n ans = \"YES\" if d == 0 && e >= 0\nend\nputs ans\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "c5c1a041980927ab291508d4e59804a6", "src_uid": "9edf42c20ddf22a251b84553d7305a7d", "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\nwhwh = gets.chomp.split(\" \").map(&:to_i)\nw1=whwh[0]\nh1=whwh[1]\nw2=whwh[2]\nh2=whwh[3]\n\nans = h1+h2+w1+w2+4+h1+h2+(w1-w2).abs\nputs ans", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "038a2563071801b3476e7c9f19d3c5f8", "src_uid": "b5d44e0041053c996938aadd1b3865f6", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/ruby\nx=3\ngets\nputs $<.all?{|e|\n\te=e.to_i\n\te!=x && x=6-x-e\n} ? :YES : :NO", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "d9de73d398120850f1ec1740c7c874a9", "src_uid": "6c7ab07abdf157c24be92f49fd1d8d87", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "l,r = gets.split\n\nk=0\n\nl1 = l.clone\nr1 = r.clone\n\nl1[-1] = l1[0]\nif l1.to_ir.to_i then\n r1=(r1.to_i-10).to_s\n r1[-1]=r1[0]\nend\n\ndef count(b,e,x)\n (e-b+1)*(10**([x-2 ,0].max))\nend\n\ndef ans(s)\n z=0\n (1..s.length-1).each do |por|\n z+=count(1,9,por) \n end\n z+=count(1,s[0].to_i-1,s.length)+s[1..-2].to_i+1\nend\nk+=ans(r1)\nk-=ans(l1)\nk+=1\nputs k\n", "lang_cluster": "Ruby", "tags": ["binary search", "dp", "combinatorics"], "code_uid": "cd2dc39f55e30f3af64725315b414d14", "src_uid": "9642368dc4ffe2fc6fe6438c7406c1bd", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\nl0, *a = gets.split.map &:to_i\na.sort!\na.reverse!\nl = l0\n\nif l > a[0]\n puts 0\n exit\nend\n\nh = a[0]\ni = 0 \nloop {\n h -= 1\n i += 1 until i >= a.size || a[i] <= h\n if l + i - 1 > h + 1 \n puts h+2-l0\n break\n end \n l += i\n if l > h \n puts l - l0\n break\n end \n}\n", "lang_cluster": "Ruby", "tags": ["greedy", "implementation"], "code_uid": "9b7f445f9a6e48bfdd4f0632a2c46486", "src_uid": "aa8fabf7c817dfd3d585b96a07bb7f58", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "r1, c1, r2, c2 = gets.split.collect{|i| i.to_i}\nif r1==r2 and c1==c2\n rook = 0\nelsif r1==r2 or c1==c2\n rook = 1\nelse\n rook = 2\nend\nif (r1+c1)%2 != (r2+c2)%2\n bishop = 0\nelsif r1+c1==r2+c2 or r1+c2==r2+c1\n bishop = 1\nelse\n bishop = 2\nend\nking = [(r1-r2).abs,(c1-c2).abs].max\nputs [rook,bishop,king].join(\" \")\n", "lang_cluster": "Ruby", "tags": ["math", "graphs", "shortest paths"], "code_uid": "16ade2580b1bcb8bde0a67c23b986a51", "src_uid": "7dbf58806db185f0fe70c00b60973f4b", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = gets.chomp\nfs = [4, 7].inject(Hash.new(0)) { |h, e| h[e] = s.count(e.to_s); h }.sort_by { |_, v| v }\nputs(fs == [[4, 0], [7, 0]] ? -1 : fs[0][1] == fs[1][1] ? 4 : fs[1][0])", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "1ec1878def494e10c410a1b1c4b85606", "src_uid": "639b8b8d0dc42df46b139f0aeb3a7a0a", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\nmin1, max1 = gets.split.map { |e| e.to_i }\nmin2, max2 = gets.split.map { |e| e.to_i }\nmin3, max3 = gets.split.map { |e| e.to_i }\n\nd1, d2, d3 = 0, 0, 0\n\nd1 = n-min2-min3 > max1 ? max1 : n-min2-min3\nn -= d1\nprint d1.to_s + ' '\n\nd2 = n-min3 > max2 ? max2 : n-min3\nn -= d2\nprint d2.to_s + ' '\n\nprint n\n", "lang_cluster": "Ruby", "tags": ["math", "greedy", "implementation"], "code_uid": "123f69e2abe8664a08fca8c331358841", "src_uid": "3cd092b6507079518cf206deab21cf97", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "table = Hash.new(false)\n(1..5).each { |i| table[i] = Hash.new(false) }\n\ncount = gets.chop.to_i\n(1..count).each {\n sf1, sf2 = gets.split(/\\s+/)\n f1 = sf1.to_i\n f2 = sf2.to_i\n\n table[f1][f2] = true\n table[f2][f1] = true\n}\n\nwin = false\n(1..5).each { |i|\n know = 0\n unknown = 0\n (1..5).each { |j|\n if (i != j)\n if (table[i][j] == true)\n know += 1\n else\n unknown += 1\n end\n end\n }\n\n if (know >= 3 or unknown >= 3)\n win = true\n break\n end\n}\n\nif (win)\n puts \"WIN\"\nelse\n puts \"FAIL\"\nend", "lang_cluster": "Ruby", "tags": ["math", "implementation", "graphs"], "code_uid": "1baeecb1272ec4b855aaebb5d293c562", "src_uid": "2bc18799c85ecaba87564a86a94e0322", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "puts \"#{(n=(gets.to_i/3.0+0.5).to_i)/12} #{n%12}\"", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "16d4861cf80398c8c08f1cbd05dc47f4", "src_uid": "5d4f38ffd1849862623325fdbe06cd00", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "y=gets.split.collect {|i| i.to_i}\nn=y[0]\nx=y[1]\ny=y[2]\n\nclone = (y/100.00*n).ceil - x\nputs (clone<0 ? 0 : clone)\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "117a92a6131b77e8ee2d6f9aac019c5b", "src_uid": "7038d7b31e1900588da8b61b325e4299", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,m = gets.split(\" \").map(&:to_i)\nintersections = [n , m].min \nputs intersections % 2 != 0 ? \"Akshat\" : \"Malvika\"", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "b38333a0bd83e0f0fef80bb19e3262e9", "src_uid": "a4b9ce9c9f170a729a97af13e81b5fe4", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.to_i\nn.times{\n x=gets.to_i\n ok=false\n 0.step(x, 3) {|a| 0.step(x, 7) {|b| ok=true if a+b==x}}\n puts (ok ? \"YES\" : \"NO\")\n}\n", "lang_cluster": "Ruby", "tags": ["greedy", "implementation"], "code_uid": "3c4108a77163b4ea9ff23fb1cad5d986", "src_uid": "cfd1182be98fb5f0c426f8b68e48d452", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\n\nwhile n.to_s.chars.map(&:to_i).inject(:+) % 4 != 0 do\n n += 1\nend\n\nputs n\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "94906ee4c33511d5b9c8344c4ac46de7", "src_uid": "bb6fb9516b2c55d1ee47a30d423562d7", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = gets.chomp\ni = 0\ns1 = 'CODEFORCES'\nwhile s[i] == s1[i]\n i += 1\nend\nj = 0\nwhile s[-j - 1] == s1[-j - 1]\n j += 1\nend\nif j + i >= s1.length\n print 'YES'\nelse\n print 'NO'\nend", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "43ec01e0a99e1f439d5ce260098afbeb", "src_uid": "bda4b15827c94b526643dfefc4bc36e7", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/ruby\n\n# Get one number at a time\nN = STDIN.gets.to_i\n\n# 0 win = 1 person\n# 1 win = 2 ppl\n# 2 wins = 3 ppl\n# 3 wins = 3 + 2 = 5 ppl\n\n# needed[x] = the minimum number of ppl needed to get x wins.\n# needed[x] = needed[x-1] + needed[x-2]\nneeded = [1, 2, 3]\n\nif N == 2\n\tputs 1\n\texit\nend\n\nif N == 3\n\tputs 2\n\texit\nend\n\nans = 3\nwhile true\n\tneeded[ans % 3] = needed[(ans - 1) % 3] + needed[(ans - 2) % 3]\n\tif(needed[ans % 3] > N)\n\t\tbreak\n\tend\n\tans += 1\nend\n\nputs (ans - 1)\n\n\n\n", "lang_cluster": "Ruby", "tags": ["math", "greedy", "constructive algorithms", "combinatorics"], "code_uid": "f243d58432799ab26b8e60194c3aec5a", "src_uid": "3d3432b4f7c6a3b901161fa24b415b14", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "$>< max_coin / 2\n end\n max_coin = max_coin / num\nend\nputs 1", "lang_cluster": "Ruby", "tags": ["greedy"], "code_uid": "3ea9ac5d710a7b3a9c3f81e373a4c9c6", "src_uid": "2fc946bb72f56b6d86eabfaf60f9fa63", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, x, y = gets.split.map &:to_i\nn /= 2\nputs [x, y].all?{|_| _ == n || _ == n + 1} ? :NO : :YES\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "a253a7e87de6dfa15a8b9789b3a6045d", "src_uid": "dc891d57bcdad3108dcb4ccf9c798789", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "# coding: utf-8\n\nn = gets.to_i\n\n# 5 days work, 2 days off\n# min: begin with first work day (monday)\n# max: begin with first off day (saturday)\nmin = (n / 7) * 2\nmin += 1 if n%7 == 6 # saturday\nmax = 2 + ( (n-2)/7 )*2\nmax += 1 if (n-2)%7 == 6 # saturday\nputs \"#{min} #{max}\"", "lang_cluster": "Ruby", "tags": ["math", "greedy", "constructive algorithms", "brute force"], "code_uid": "8962e313824d688e90b4b8b7fe6ff5f1", "src_uid": "8152daefb04dfa3e1a53f0a501544c35", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "case gets.to_i\n\twhen -128..127\n\t\tputs \"byte\"\n\twhen -32768..32767\n\t\tputs \"short\"\n\twhen -2147483648..2147483647\n\t\tputs \"int\"\n\twhen -9223372036854775808..9223372036854775807\n\t\tputs \"long\"\n\telse\n\t\tputs \"BigInteger\"\nend", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "1c8217ef0148f3e513b6e100cfa0969d", "src_uid": "33041f1832fa7f641e37c4c638ab08a1", "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": "1be5e4eff92348df992277bc1dc1121f", "src_uid": "a11c9679d8e2dca51be17d466202df6e", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = gets.to_i\na = 1\nans = 0\nwhile a < s\n ans += 1\n a *= 100\nend\nputs ans", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "c43183847a60ad6d486ce50d053aead8", "src_uid": "d8ca1c83b431466eff6054d3b422ab47", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "String.class_eval do\n ROD = %w[\n O-|-OOOO O-|O-OOO O-|OO-OO O-|OOO-O O-|OOOO-\n -O|-OOOO -O|O-OOO -O|OO-OO -O|OOO-O -O|OOOO-\n ]\n def soroban\n self.each_char{|s|puts ROD[s.to_i]}\n end\nend\n\ngets.chop.reverse.soroban\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "e3a6287a56bd031f6bf459274520e7d8", "src_uid": "c2e3aced0bc76b6484360563355d23a7", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "# -*- mode: ruby -*-\n# vi: set ft=ruby :\n\narr = gets.split.map{|x| x.to_i}.sort\nputs arr[-1]-arr[0]\n", "lang_cluster": "Ruby", "tags": ["math", "sortings", "implementation"], "code_uid": "4a38c6882e7105994722abe1bc93e41d", "src_uid": "7bffa6e8d2d21bbb3b7f4aec109b3319", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/env ruby\n# -*- coding: utf-8 -*-\n\ninclude Math\nrequire 'prime'\nrequire 'bigdecimal'\nrequire 'bigdecimal/math'\nrequire 'matrix'\nrequire 'pp'\nrequire 'benchmark'\n\nInf = 1.0 / 0.0\ndef pbin(obj);case obj;when Integer;puts obj.to_s(2);end;end\nclass String;def to_a;split(\"\");end;\n def to_ia(d = \" \");split(d).map(&:to_i);end;end\ndef getia(*arg);gets.to_ia(*arg);end\ndef geti;gets.to_i;end\nclass Object;def dcopy;Marshal.load(Marshal.dump(self));end;end\n\ndef f\n n, bx = *getia\n ts = getia\n res = 0\n for x in ts\n res *= bx\n res += x\n end\n return res\nend\n\na = f\nb = f\nif a == b\n puts \"=\"\nelsif a < b\n puts \"<\"\nelse\n puts \">\"\nend\n\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "ef7faa5cf99509afd0da8a2f34ce8031", "src_uid": "d6ab5f75a7bee28f0af2bf168a0b2e67", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.chomp.to_i\ns=gets.chomp\n\nif s=='0'\n puts 0\nelse\n puts '1'+'0'*s.count('0')\nend", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "57b72558086600c8c78cbbab2fde9d71", "src_uid": "ac244791f8b648d672ed3de32ce0074d", "difficulty": 800.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).each_char.to_a.join(\" \")", "lang_cluster": "Ruby", "tags": ["brute force"], "code_uid": "b42a564a0f9e8c749c68df2c8f0f07de", "src_uid": "a8da7cbd9ddaec8e0468c6cce884e7a2", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "k, n, s, p = gets.split.map(&:to_f)\nres = ((n/s).ceil * k / p).ceil\nputs res.to_i", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "57aa4a09826cd4dd640f67f6f70b3c37", "src_uid": "73f0c7cfc06a9b04e4766d6aa61fc780", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "odd=0\nl1=0\nr1=0\nn=gets.to_i\nn.times{\n\ta,b=gets.split.map{|e| e.to_i}\n\tl1=(l1+a)%2\n\tr1=(r1+b)%2\n\todd+=1 if ((a-b).abs%2)==1\n}\nif (l1+r1)==1 then\n\tputs -1\nelsif l1+r1==2\n\tif odd>1 then\n\t\tputs 1\n\telse\n\t\tputs -1\n\tend\nelse\n\tputs 0\nend", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "c1536cb856f93f0e6db6b474d3cc0a55", "src_uid": "f9bc04aed2b84c7dd288749ac264bb43", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "ts = gets.chomp.split.map(&:to_i)\nhs = Hash.new(0)\n\nts.each do |t|\n hs[t] += 1\nend\n\ns = ts.inject(&:+)\nans = s\nhs.each do |k, v|\n ans = [ans, s - k * [v, 3].min ].min if 2 <= v\nend\n\nputs ans\n", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation"], "code_uid": "eb178ddfbcbc86477ea7f9dc2859a72f", "src_uid": "a9c17ce5fd5f39ffd70917127ce3408a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "l, r = gets.split(' ').map(&:to_i)\ncnt = 0\nfor x in 0..(Math.log(r, 2)+1)\n\tfor y in 0..(Math.log(r,3)+1)\n\t\ta = (2**x)*(3**y)\n\t\tif a >= l and a <= r\n\t\t\tcnt += 1\n\t\tend\n\tend\nend\nprint String(cnt)", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "dcc2364ac4d019f718058b027e9d5242", "src_uid": "05fac54ed2064b46338bb18f897a4411", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,m,z=gets.split.map &:to_i;p z/n.lcm(m)", "lang_cluster": "Ruby", "tags": ["brute force", "math", "implementation"], "code_uid": "80ac26c55a0d3e72fc8dfce8e0f681cc", "src_uid": "e7ad55ce26fc8610639323af1de36c2d", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def fact (n)\n mul = 1 \n for i in 1..n \n mul *= i \n end \n return mul \nend \n\na,b = gets.chomp.split \n\na = a.to_i \nb = b.to_i \n\nif a= 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": ["divide and conquer", "implementation", "binary search"], "code_uid": "3ba508f4754cd14bd65925cbce6f5f9f", "src_uid": "1503d761dd4e129fb7c423da390544ff", "difficulty": 1800.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", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "1016e0d9d36e157a4ff091b6ea67fec5", "src_uid": "faa343ad6028c5a069857a38fa19bb24", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def getTime(time)\n hour = (time[0].ord - '0'.ord) * 10 + time[1].ord - '0'.ord\n minute = (time[3].ord - '0'.ord) * 10 + time[4].ord - '0'.ord\n return [hour, minute]\nend\n\nwake_up = getTime(gets.chomp)\nslept = getTime(gets.chomp)\n\nfell_asleep = [wake_up[0] - slept[0], wake_up[1] - slept[1]]\n\nif fell_asleep[1] < 0\n fell_asleep[1] += 60\n fell_asleep[0] -= 1\nend\n\nfell_asleep[0] += 24 if fell_asleep[0] < 0\n\nputs fell_asleep[0].to_s.rjust(2, \"0\") + \":\" + fell_asleep[1].to_s.rjust(2, \"0\")\n\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "0e3cffe131d8e4ccda9146842e8bf8d9", "src_uid": "595c4a628c261104c8eedad767e85775", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "p 25\n", "lang_cluster": "Ruby", "tags": ["number theory"], "code_uid": "829b43958d747b459b7be981350d2570", "src_uid": "dcaff75492eafaf61d598779d6202c9d", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, p, k = gets.split.map &:to_i\nans = []\nans << '<<' if p - k > 1\n(p - k).upto(p - 1) do |i|\n ans << i if i > 0\nend\nans << \"(#{p})\"\n(p + 1).upto(p + k) do |i|\n ans << i if i <= n\nend\nans << '>>' if p + k < n\nputs ans.join ' '\n\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "1dc28dd1f1befba58614e983f8c8dd90", "src_uid": "526e2cce272e42a3220e33149b1c9c84", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, m = gets.split.map{ |i| i.to_i }\n$a = []\ndef doit(n) \n\treturn if n.to_s.size > 10\n\t($a << n) if n > 0 \n\tdoit(n * 10 + 4)\n\tdoit(n * 10 + 7)\nend\ndoit(0)\nc, r = n - 1, 0\n$a = $a.sort\n$a.each { |i|\n\tif i >= n\n\t\tif i < m\n\t\t\tr += (i - c) * i\n\t\telse\n\t\t\tr += (m - c) * i\n\t\t\tbreak\n\t\tend\n\t\tc = i\n\tend\n}\nputs r\n", "lang_cluster": "Ruby", "tags": ["brute force", "math"], "code_uid": "d361eccfced26a19fa183fff37f38c1b", "src_uid": "8a45fe8956d3ac9d501f4a13b55638dd", "difficulty": 1100.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": "037417185bf167a644a9e6f2b3199468", "src_uid": "eae87ec16c284f324d86b7e65fda093c", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def run\n n = $stdin.readline.to_i\n a = $stdin.readline.split(\" \").map(&:to_i)\n\n sum = a.reduce(&:+)\n max = 0\n for i in 0..n\n for j in i..n\n gain = a[i..j].count(0) - a[i..j].count(1)\n max = [gain, max].max\n end\n end\n\n puts max == 0 ? sum - 1 : sum + max\nend\n\nrun if $0 == __FILE__\n", "lang_cluster": "Ruby", "tags": ["brute force", "dp", "implementation"], "code_uid": "298b84abd80b45120551920711f037e9", "src_uid": "9b543e07e805fe1dd8fa869d5d7c8b99", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#ebony = ARGV[0].to_i\n#ivory = ARGV[1].to_i\n#shield = ARGV[2].to_i\n\n#ebony = gets.to_i\n#ivory = gets.to_i\n#shield = gets.to_i\n\nnums = gets.split.map(&:to_i)\n\nfor i in 0..nums[2] / nums[0]\n\tfor j in 0..nums[2] / nums[1]\n\t\tif i * nums[0] + j * nums[1] == nums[2]\n\t\t\tputs \"Yes\"\n\t\t\texit\n\t\tend\n\tend\nend\n\nputs \"No\"", "lang_cluster": "Ruby", "tags": ["brute force", "math", "number theory"], "code_uid": "aaf67a3be1bd2044ff9c5c687f549203", "src_uid": "e66ecb0021a34042885442b336f3d911", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "number, exp = gets.chomp.split('e')\nlead, trail = number.split('.')\nexp = exp.to_i\nzeroString = \"0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\" * 100\nans = lead[0...(lead.length)]\n\nif lead == \"0\" && trail == \"0\"\n\tputs '0'\n\texit\nend\n\ndotPoint = exp + 1\npointInserted = false\n\nif dotPoint < (1 + trail.length)\n\tans << trail[0...(dotPoint - 1)]\n\n\tif trail[(dotPoint - 1)...(trail.length)] != \"0\"\n\t\tans << \".\"\n\t\tans << trail[(dotPoint - 1)...(trail.length)]\n\t\tpointInserted = true\n\tend\nelse\n\tans << trail\n\trestZeros = dotPoint - (trail.length + 1)\n\tans << zeroString[0...restZeros]\nend\n\ncutPoint = 0\nif lead == \"0\" && pointInserted\n\tnotDone = true\n\tfor i in 0...(ans.length)\n\t\tif ans[i] == \".\" && ans[i - 1] == \"0\"\n\t\t\tcutPoint = i - 1\n\t\t\tnotDone = false\n\t\t\tbreak\n\t\tend\n\tend\n\n\tif cutPoint == 0 && notDone\n\t\tfor i in 0...(ans.length)\n\t\t\tif ans[i] != \"0\"\n\t\t\t\tcutPoint = i\n\t\t\t\tbreak\n\t\t\tend\n\t\tend\n\tend\nelsif lead == \"0\" && !pointInserted\n\tfor i in 0...(ans.length)\n\t\tif ans[i] != \"0\"\n\t\t\tcutPoint = i\n\t\t\tbreak\n\t\tend\n\tend\nend\n\nans = ans[cutPoint...(ans.length)] if lead == \"0\"\n\nputs ans", "lang_cluster": "Ruby", "tags": ["brute force", "math", "strings", "implementation"], "code_uid": "e55d0d14c00bda7b002074e22efc32ff", "src_uid": "a79358099f08f3ec50c013d47d910eef", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "x, y, *rest = STDIN.read.split(\" \")\nputs (1..16).inject { \n |acc, b|\n [acc, (x.to_i(b) + y.to_i(b)).to_s(b).length].max\n}\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "27679248043b2b3726d07f4eb992321c", "src_uid": "8ccfb9b1fef6a992177cc49bd56fab7b", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "require \"date\"\n\na = gets.split(\":\").map(&:to_i)\nb = gets.split(\":\").map(&:to_i)\n\nda = Date.new(a[0], a[1], a[2])\ndb = Date.new(b[0], b[1], b[2])\n\nputs (db - da).abs.to_i", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "ef2ec36cec40f3fe6cf077689d27eb11", "src_uid": "bdf99d78dc291758fa09ec133fff1e9c", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.chomp\ndigits = gets.chomp.chars.map(&:to_i)\ntable = {\n 1 => 4, 2 => 5, 3 => 6,\n 4 => 7, 5 => 8, 6 => 9,\n 8 => 0\n}\ntable2 = {\n 1 => 2, 4 => 5, 7 => 8,\n 2 => 3, 5 => 6, 8 => 9\n}\n\nup = digits.map { |d| table[d] }.any?(&:nil?)\ndown = digits.map { |d| table.invert[d] }.any?(&:nil?)\nright = digits.map { |d| table2[d] }.any?(&:nil?)\nleft = digits.map { |d| table2.invert[d] }.any?(&:nil?)\n\n\nputs (up && down && right && left) ? \"YES\" : \"NO\"\n", "lang_cluster": "Ruby", "tags": ["brute force", "constructive algorithms", "implementation"], "code_uid": "7b114a281f94d738b95ded9b91c1915b", "src_uid": "d0f5174bb0bcca5a486db327b492bf33", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\na.sort!\nans = 0\n(n/2).times do |i|\n ans += a[2*i+1] - a[2*i]\nend\np ans\n", "lang_cluster": "Ruby", "tags": ["sortings"], "code_uid": "64ef1d8d9c81b636f9cc10571b9f3a74", "src_uid": "55485fe203a114374f0aae93006278d3", "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)\n", "lang_cluster": "Ruby", "tags": ["brute force"], "code_uid": "10a5efb5610467821ce458547eb6cc5d", "src_uid": "03caf4ddf07c1783e42e9f9085cc6efd", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "bookCode = gets.chomp\ntargetLength = bookCode.length + 1\ndangerous = []\n\n(0...targetLength).each do |iterNum|\n\t('a'..'z').each do |ch|\n\t\tstart = if iterNum == 0\n\t\t\t\"\"\n\t\telse\n\t\t\tbookCode[0..iterNum - 1]\n\t\tend\n\t\t\n\t\tmiddle = ch.to_s\n\t\tfinal = bookCode[iterNum..(bookCode.length - 1)]\n\n\t\tdangerous << (start << middle << final)\n\tend\nend\n\ndangerous.uniq!\nputs dangerous.length", "lang_cluster": "Ruby", "tags": ["brute force", "math", "strings"], "code_uid": "00efff0d64b4e3ed5a3712ecc7e30814", "src_uid": "556684d96d78264ad07c0cdd3b784bc9", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "require 'prime'\ndef find_minimum(row, col, factor, n)\n res = (0..n).collect {|i|\n [row * (factor**i), col * (factor**(n-i))]\n }.select{ |pair|\n pair[0] <= pair[1]\n }.min_by { |pair|\n pair[1] - pair[0]\n }\n res.nil? ? [1, row*col*(factor**n)] : res\nend\n\ndef minimum_pair(row, col, primes)\n if primes.size == 1\n return find_minimum(row, col, primes[0][0], primes[0][1])\n else\n prime = primes[0][0]\n n = primes[0][1]\n rest = primes[1..-1]\n minimum = 10000000\n minimum_result = nil\n (0..n).collect { |i|\n minimum_pair(row*(prime**i), col*(prime**(n-i)), rest)\n }.select{ |pair|\n pair[0] <= pair[1]\n }.min_by { |pair|\n pair[1] - pair[0]\n }\n end\nend\n\ndef solve(n)\n return [1,1] if n == 1\n return [0,0] if n == 0\n primes = n.prime_division\n minimum_pair(1, 1, primes)\nend\n\nputs solve(STDIN.read.to_i).join(\" \")\n", "lang_cluster": "Ruby", "tags": ["brute force", "math"], "code_uid": "760c2c5f3a0d96cfa3485ff8c218d966", "src_uid": "f52af273954798a4ae38a1378bfbf77a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/ruby\nn,_,a=gets.split\nn=n.to_i\nif a=='week'\n\tp n==5||n==6 ? 53 : 52\nelse\n\tp [31,29,31,30,31,30,31,31,30,31,30,31].count{|e|e>=n}\nend", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "fb685c2f834e0f8af29576d90d3734c1", "src_uid": "9b8543c1ae3666e6c163d268fdbeef6b", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "palindrome_times = [\n 0, 70, 140, 210, 280, 350, 601, 671, 741, 811, 881,\n 951, 1202, 1272, 1342, 1412, 1440, 1482, 1510, 1580, 1650,\n 1720, 1790, 2041, 2111, 2181, 2251, 2321, 2391, 2642, 2712, 2782, 2852, 2922\n]\n\ntime_string = gets\ninitial_hour, initial_minutes = time_string.split(':')\ninitial_time = initial_hour.to_i * 60 + initial_minutes.to_i\n\nans = palindrome_times.bsearch { |x| x - initial_time >= 0 }\nputs ans - initial_time\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "ed7c5336de9beadf7aeb74e9359ae3e7", "src_uid": "3ad3b8b700f6f34b3a53fdb63af351a5", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,k = gets.split.map(&:to_i)\na = n - (k - n*2)\nif a < 0\n print 0\nelse\n print a\nend", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "3d92e211529b646881bc7766fd33610f", "src_uid": "5a5e46042c3f18529a03cb5c868df7e8", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a = gets.split\nl = a[0].to_i; r = a[1].to_i;\ncount = l==0?1:0\nnow = 3\nfor i in 2..65\n\tfor j in 0..i-2\n\t\tt = now^(1<=l && t<=r) ? 1:0\n\tend\n\tnow = now<<1|1\n\nend\nprint count", "lang_cluster": "Ruby", "tags": ["brute force", "implementation", "bitmasks"], "code_uid": "7b95770a724c61c1137f1925ca808c5d", "src_uid": "581f61b1f50313bf4c75833cefd4d022", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.to_i.abs\nif n==0 then puts \"0\";exit end\n\ni=1\nk=0\nloop do\n k+=i\n if k>=n && (k-n)%2==0 then break end\n i+=1\nend\n\nputs i\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "f4cf54a72b29383ad2293bb9f13843b1", "src_uid": "18644c9df41b9960594fdca27f1d2fec", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, k = gets.split.map{|x| x.to_i}\n\nif (k == n) || (k == 0)\n\tprint \"0 0\"\nelse\n\tprint 1, \" \", (n + 2) / 3 <= k ? n - k : 2 * k\nend", "lang_cluster": "Ruby", "tags": ["math", "constructive algorithms"], "code_uid": "d92c5e088a958229632cb607725190f4", "src_uid": "bdccf34b5a5ae13238c89a60814b9f86", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\nputs n * (n - 3) - (n - 4)\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "291d68d4ece2714476e04c04ad785533", "src_uid": "efa8e7901a3084d34cfb1a6b18067f2b", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "need = STDIN.readline.to_i - 10\nif need == 10\n puts 15\nelsif need >= 1 and need <= 11\n puts 4\nelse\n puts 0\nend\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "0707eab83b76d0e896ef41936692910a", "src_uid": "5802f52caff6015f21b80872274ab16c", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "require 'matrix'\n\na1, b1, c1 = gets.split.map { |v| Rational(v.to_i) }\na2, b2, c2 = gets.split.map { |v| Rational(v.to_i) }\na3, b3, c3 = [0, 0, 0].map { |v| Rational(v) }\n\nrank_a = Matrix[ [a1, b1], [a2, b2] ].rank\nrank_b = Matrix[ [a1, b1, c1], [a2, b2, c2], [a3, b3, c3] ].rank\n\nresult = 0\n\nif rank_a == rank_b\n result = rank_a == 2 ? 1 : -1;\nend\n\nputs result\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "b8b6f72bcb81ccf58749222446726975", "src_uid": "c8e869cb17550e888733551c749f2e1a", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\np n % 2 == 0 ? 2**(n/2) : 0", "lang_cluster": "Ruby", "tags": ["math", "dp"], "code_uid": "32007e4b3396d0bac77c0c9f0defb2f0", "src_uid": "4b7ff467ed5907e32fd529fb39b708db", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "require \"set\"\n\ndef f(n)\n\ts = (n+1).to_s\n\ts[...(s =~ /0+$/)].to_i\nend\n\nn = gets.to_i\ns = Set.new\nwhile !s.include?(n)\n\ts.add(n)\n\tn = f(n)\nend\np s.size\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "0fc552fe99d25572ac313c4060a4a085", "src_uid": "055fbbde4b9ffd4473e6e716da6da899", "difficulty": 1100.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<=h\n}\np r ? r/24 : -1", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "0c09168f1ebe89f1cd7a9a6b6ec209b3", "src_uid": "2c39638f07c3d789ba4c323a205487d7", "difficulty": 1400.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": "bd39cac1c9b76dfa0411b6687d90ae3e", "src_uid": "2a68157e327f92415067f127feb31e24", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\na = gets.split.map &:to_i\nf = a.inject(0) { |s, x| s + x }\n(a.max..201).each do |k|\n s = a.inject(0) { |s, x| s + k - x }\n if s > f\n puts k\n exit\n end\nend\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "68d64fb9f5928456178276aceedadbd4", "src_uid": "d215b3541d6d728ad01b166aae64faa2", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "gets\ny=gets.strip\nif y.count(\"1\") == 0\n p 0\n exit\nend\ny = y.gsub(/[^01]/,\"\").gsub(/^0+/, \"\").gsub(/0+$/, \"\")\na = y.split(/1+/).reject{|x|x.size==0}.map(&:size).map{|x|x+1}\n# p y\n# p y.split(/1+/)\n# p a\na = a.size == 0 ? 1 : a.size > 1 ? a.reduce(:*) : a[0]\n# if y == y.reverse\n# if y.size % 2 == 0 && y[y.size/2] == \"0\" && y[y.size/2+1] == \"0\"\n# a /= 2\n# end\n# if y.size % 2 == 1 && y[y.size/2+1] == \"0\"\n# a /= 2\n# end\n# end\np a\n# p y\n# p y.scan(/0+/).flatten.map(&:size).map{|x|x+1}\n", "lang_cluster": "Ruby", "tags": ["combinatorics"], "code_uid": "8698b7d4a324365b9907899d8cd4e360", "src_uid": "58242665476f1c4fa723848ff0ecda98", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "row1 = []\nrow2 = []\nrow3 = []\ninput1 = gets.chomp.split\ninput2 = gets.chomp.split\ninput3 = gets.chomp.split\nfor i in 0...3\n row1[i] = Integer(input1[i])\n row2[i] = Integer(input2[i])\n row3[i] = Integer(input3[i])\nend\n\nx = 0\ny = 0\nz = 0\ny = (row1[1] + row1[2] + row3[0] + row3[1] - row2[0] - row2[2]) / 2\nz = y - (row3[0] + row3[1] - row2[0] - row2[2])\nx = y + row2[0] + row2[2] - row1[1] - row1[2]\n\nrow1[0] = x\nrow2[1] = y\nrow3[2] = z\nprint row1.join(\" \")\nputs \nprint row2.join(\" \")\nputs\nprint row3.join(\" \")\nputs", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "3856402ef966b6ac26ff95e031e402cf", "src_uid": "0c42eafb73d1e30f168958a06a0f9bca", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, m, x = gets.split.map(&:to_i)\nx-=1\nputs \"#{(x/2)/m + 1} #{(x/2)%m+1} #{(x%2==0)?'L':'R'}\"", "lang_cluster": "Ruby", "tags": ["math", "constructive algorithms"], "code_uid": "5572af0cc6105feaa11b5aec5ff1dd02", "src_uid": "d6929926b44c2d5b1a8e6b7f965ca1bb", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.chomp.to_i\nhigh = Math.log10(n).to_i;\nres = 2**(high + 1)\nuntil n <= 0 do\n\tdig = n/10**high\n\tif dig == 7 then\n\t\tres += 2**high\n\tend\n\tn -= dig*10**high\n\thigh -= 1\nend\nputs res - 1\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation", "combinatorics", "bitmasks"], "code_uid": "cb387c1bc2aa4a7b0ec626a1568fcef1", "src_uid": "6a10bfe8b3da9c11167e136b3c6fb2a3", "difficulty": 1100.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": "2163c6a75d56b9fc02b7879c1e78747a", "src_uid": "245ec0831cd817714a4e5c531bffd099", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,a,b = gets.split.map(&:to_i)\nk = 2\nans = 1\nwhile (a-1)/k != (b-1)/k\n k *= 2\n ans += 1\nend\nputs k == n ? \"Final!\" : ans\n", "lang_cluster": "Ruby", "tags": ["constructive algorithms", "implementation"], "code_uid": "ae16a2514408e38474dde81f99cf47f0", "src_uid": "a753bfa7bde157e108f34a28240f441f", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def calc(s)\n\ts[0],s[1]=s[1],s[0] if s[0]=='X'\n\ts[1],s[3]=s[3],s[1] if s[1]=='X'\n\ts[2],s[3]=s[3],s[2] if s[2]=='X'\n\ta=s\nend\na=[\"ABCX\", \"CABX\", \"BCAX\"]\nx=gets.chop+gets.chop\ny=gets.chop+gets.chop\nans=0\nans+=1 if a.include?calc(x)\nans+=1 if a.include?calc(y)\nputs ans%2==0 ? \"YES\" : \"NO\"\n", "lang_cluster": "Ruby", "tags": ["brute force", "constructive algorithms", "implementation"], "code_uid": "c17c0be0ad573fbb1ce549c7eef7119a", "src_uid": "46f051f58d626587a5ec449c27407771", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets\ns = gets\n\n1000.times{s = s.sub(/([aeiouy])[aeiouy]/,'\\1')}\n\nputs s", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "efbf74de2cee46cc3b814034d1a9d4f1", "src_uid": "63a4a5795d94f698b0912bb8d4cdf690", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, k = gets.split.map(&:to_f)\nputs (2*n/k).ceil + (5*n/k).ceil + (8*n/k).ceil", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "da853a27c920fd967a4c33165991d47b", "src_uid": "d259a3a5c38af34b2a15d61157cc0a39", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "$n, l = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\nb = gets.split.map(&:to_i)\n\n$a2 = []\n$b2 = []\n\n$n.times do |i|\n $a2[i] = i == $n - 1 ? (a[0] + l - a[i]) : a[i + 1] - a[i]\n $b2[i] = i == $n - 1 ? (b[0] + l - b[i]) : b[i + 1] - b[i]\nend\n\ndef magic\n $n.times do\n return true if $a2 == $b2\n tmp = $a2.shift()\n $a2 << tmp\n end\n return false\nend\n\nputs magic ? 'YES' : 'NO'\n", "lang_cluster": "Ruby", "tags": ["brute force", "math", "implementation"], "code_uid": "395371d5470a96734536a79da3190db2", "src_uid": "3d931684ca11fe6141c6461e85d91d63", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "puts gets.gsub(\"144\",\"x\").gsub(\"14\",\"x\").gsub(\"1\",\"x\").gsub(\"x\",\"\")==\"\\n\"?\"YES\":\"NO\"", "lang_cluster": "Ruby", "tags": ["brute force", "greedy"], "code_uid": "8e0464b4de911ce708113f5bbc4e5ff2", "src_uid": "3153cfddae27fbd817caaf2cb7a6a4b5", "difficulty": 900.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": "f0a5ec1ee565dbd3f0b96a8df6464f7f", "src_uid": "fa1ef5f9bceeb7266cc597ba8f2161cb", "difficulty": 1600.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\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "4ccf797c17f4a73041355c5aed632513", "src_uid": "8ab25ed4955d978fe20f6872cb94b0da", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = gets.strip\nP=1000000\nn = s.size\n#puts 'ok' if \"09\" != \"0\" and \"09\"[0] == \"0\"\nans = -1\n(0...n).each do |i|\n (i+1...n).each do |j|\n\n iv = s[0...i]\n jv = s[i...j]\n kv = s[j...n]\n #\"%s %s %s %d\\n\" % [iv,jv,kv,ans]\n next if iv.empty? or jv.empty? or kv.empty?\n next if iv != '0' and iv[0] == '0'\n next if jv != '0' and jv[0] == '0'\n next if kv != '0' and kv[0] == '0'\n next if iv.to_i > P\n next if jv.to_i > P\n next if kv.to_i > P\n ans = [ans,iv.to_i+jv.to_i+kv.to_i].max\n\n #p [iv,jv,kv,ans]\n\n end\nend\n\nputs ans\n\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "174d59708bb64fdd0c7e6edd1aebb9d2", "src_uid": "bf4e72636bd1998ad3d034ad72e63097", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "k,a,b=gets.split.map(&:to_i)\nif (a%k!=0&&b= top && x <= down && y >= left && y <= right\n end\n photos += 1 if alts >= k\n end\n end\n end\nend\nputs photos", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "3f11b8105c8e676aed5b84f782d6a72a", "src_uid": "9c766881f6415e2f53fb43b61f8f40b4", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "exhibit = gets.rstrip\n\narr = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']\n\ncount = 0\ncurrent_index = 0\nexhibit.split('').each do |char|\n index = arr.find_index do |l|\n l == char\n end\n\n distance_index = (index - current_index).abs\n\n if distance_index > 13\n if index < current_index\n count += index + 26 - current_index\n else\n count += current_index + 26 - index\n end\n else\n count += distance_index\n end\n current_index = index\nend\n\nputs count\n", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "fa626d334366a9cc37583b1a06ab4693", "src_uid": "ecc890b3bdb9456441a2a265c60722dd", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a = gets.to_i\nb = gets.to_i\ndiff = (a-b).abs\nm = diff/2\nans = 0\nm.times do |i|\n ans += (i+1)*2\nend\nans += diff/2 + 1 if diff % 2 == 1\nputs ans\n", "lang_cluster": "Ruby", "tags": ["math", "greedy", "implementation", "brute force"], "code_uid": "f32f1f5dccddbe54aa8c1f440712afcc", "src_uid": "d3f2c6886ed104d7baba8dd7b70058da", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\ns = gets.chomp.split('')\nputs (s-['4','7']==[]&&s[0...n/2].sort==s[n/2...n].sort)?'YES':'NO'\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "5d71bc853915501a6b709689b8a77ef6", "src_uid": "435b6d48f99d90caab828049a2c9e2a7", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, k = gets.split.map(&:to_i)\ncase (n - k)%(2*k)\nwhen 0..k-1\n puts \"YES\"\nwhen k..2*k-1\n puts \"NO\"\nend", "lang_cluster": "Ruby", "tags": ["math", "games"], "code_uid": "0c08300f7f07740fc44709128f143694", "src_uid": "05fd61dd0b1f50f154eec85d8cfaad50", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b,r = gets.split.map(&:to_i)\nputs (r*2<=b and r*2<=a) ? \"First\" : \"Second\"", "lang_cluster": "Ruby", "tags": ["math", "constructive algorithms", "games"], "code_uid": "fe194f485fc80c900b156a4da4ae70af", "src_uid": "90b9ef939a13cf29715bc5bce26c9896", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a = gets.chomp.split(//)\nc = a[0]\nm = 1\nr = 1\ni = 1\nwhile i < a.size\n\tif a[i] == c\n\t\tm += 1\n\telse\n\t\tm = 1\n\t\tr += 1\n\tend\n\tif m > 5\n\t\tm = 1\n\t\tr += 1\n\tend\n\tc = a[i]\n\ti += 1\nend\nputs r\n\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "d00c5ed01fbcaae174581f20f0b824f5", "src_uid": "5257f6b50f5a610a17c35a47b3a0da11", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a=gets.chomp.to_i\nb=gets.chomp.split(\"\")\nc=[]\nc=c+b\n0.upto(a-1) do |i|\nif b[i]==\"0\"\nb[i]=\"1\"\nbreak\nelse \nb[i]=\"0\"\nend\nend\nans=0\n0.upto(a-1) do |i|\nif c[i]!=b[i]\nans+=1\nend\nend\nputs \"#{ans}\"", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "20fa3bf0d4362536326642f80976ef5b", "src_uid": "54cb2e987f2cc06c02c7638ea879a1ab", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, s = gets.chomp.split.map &:to_i\n\ndef differ(x)\n string = x.to_s\n for i in 0...string.length\n x -= string[i].to_i\n end\n return x\nend\n\nl = 1\nr = n\nm = -1\nwhile l <= r do\n m = (l + r) / 2\n if differ(m) < s\n l = m + 1\n else\n r = m - 1\n end\nend\nif differ(m) >= s\n amount = n - m + 1\nelse\n amount = n - m\nend\nputs amount", "lang_cluster": "Ruby", "tags": ["brute force", "math", "dp", "binary search"], "code_uid": "94334e2583a17e776df4107c47f17c42", "src_uid": "9704e2ac6a158d5ced8fd1dc1edb356b", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\n\naa = (1..n/2).to_a\n\naa.delete_if {|a| a.gcd(n-a) != 1}\nr = aa.max\n\nputs \"#{r} #{n-r}\"", "lang_cluster": "Ruby", "tags": ["brute force", "math", "constructive algorithms"], "code_uid": "22b3f57d92551088a107d7e087af3797", "src_uid": "0af3515ed98d9d01ce00546333e98e77", "difficulty": 800.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": "50cab911126b586d026c047e5bcd57e6", "src_uid": "afd2b818ed3e2a931da9d682f6ad660d", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "arr = readline.split(' ').collect(&:to_i)\nn = arr[0]\narr = arr[1..-1]\na = [arr[0] + arr[1], arr[0] + arr[2], arr[1] + arr[3], arr[2] + arr[3]]\nd = a.max - a.min\nc = [0, n - d].max\nputs c * n\n", "lang_cluster": "Ruby", "tags": ["brute force", "math", "constructive algorithms"], "code_uid": "9ddda3d1b911308f963bed343e5bbff6", "src_uid": "b732869015baf3dee5094c51a309e32c", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "r,h=gets.split.map(&:to_i)\nc=((h+r/2.0)/r).to_i\nh-=c*r-r/2.0\nc*=2\nc+=1 if r*3**0.5<=2*h+r\np c\n", "lang_cluster": "Ruby", "tags": ["geometry"], "code_uid": "9f0670f21719effd313fa76d0dd583e6", "src_uid": "ae883bf16842c181ea4bd123dee12ef9", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,m = gets.split.map(&:to_i)\nc =0\nfor i in(1..n)\n if m%i==0 && m/i<=n\n c += 1\n end\nend\nputs c", "lang_cluster": "Ruby", "tags": ["implementation", "number theory"], "code_uid": "ae3e412abb6193387a2cd367f6bd3e43", "src_uid": "c4b139eadca94201596f1305b2f76496", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "puts gets.to_i/2+1", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "39aeab46eece2d6e304f6e833b0b64c0", "src_uid": "5551742f6ab39fdac3930d866f439e3e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "puts [\"white\\n1 2\",\"black\"][gets.to_i&1]", "lang_cluster": "Ruby", "tags": ["math", "constructive algorithms", "games"], "code_uid": "7caab27d49bcd7e3fa0bf9cd8446667e", "src_uid": "52e07d176aa1d370788f94ee2e61df93", "difficulty": 1700.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\nnum = Hash.new(0)\n\n(a..b).each do |n|\n while n > 0 \n num[n%10] += 1\n n /= 10\n end\nend\n\nres = 0\n\nkey = (0..9).to_a\n\nkey.zip(val).each do |i, j|\n res += num[i] * j\nend\n\nputs res", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "5ef0122cf8823cd1fed502dc5a7fbba3", "src_uid": "1193de6f80a9feee8522a404d16425b9", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "p 2-gets.to_i%2", "lang_cluster": "Ruby", "tags": ["math", "games"], "code_uid": "004773cdb6ef79bc72a99f57f8bf41f3", "src_uid": "816ec4cd9736f3113333ef05405b8e81", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def gcd( a, b )\n\treturn b == 0 ? a : gcd( b, a%b );\nend\n\ndef calc( a, b, c )\n\taux = a * ( b / gcd( a,b) )\n\treturn aux * ( c / gcd( aux, c ) )\nend\n\ndef max( a, b )\n\treturn a > b ? a : b\nend\n\nn = gets.chomp.to_i\nans = [1,2,6]\n\nif n < 4\n\tputs ans[ n-1 ]\nelse\n\tans = calc( n, n-1, n-2 )\n\tfor i in ( max( n-50,1 )..n )\n\t\tfor j in ( max( n-50,1 )..n )\n\t\t\tfor k in ( max( n-50,1 )..n )\n\t\t\t\tans = max( ans, calc( i, j, k ) )\n\t\t\tend\t\t\n\t\tend\t\n\tend\n\n\tputs ans\nend", "lang_cluster": "Ruby", "tags": ["number theory"], "code_uid": "82a070c2c987097d8c1fcba2bc579881", "src_uid": "25e5afcdf246ee35c9cef2fcbdd4566e", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def f(x,y,x1,y1)\n\treturn (x-x1).abs+(y-y1).abs\nend\nx,y=gets.split.map{|e| e.to_i}\nx1,y1=gets.split.map{|e| e.to_i}\nx,y=(x-x1).abs,(y-y1).abs\nx,y=[x,y].min,[x,y].max\nans=0\nif x==0\n\tans=6+f(x,y,-1,1)+f(x,y,1,1)\nelse\n\t\n\tans=4+f(x,y,-1,1)+f(x,y,1,-1)\nend\nputs ans", "lang_cluster": "Ruby", "tags": ["math", "greedy"], "code_uid": "9d33420c87238512977be27b7ce705c0", "src_uid": "f54ce13fb92e51ebd5e82ffbdd1acbed", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/env ruby\nT=[\n0b1111110,\n0b0110000,\n0b1101101,\n0b1111001,\n0b0110011,\n0b1011011,\n0b1011111,\n0b1110000,\n0b1111111,\n0b1111011,\n]\np gets.chomp.chars.map{|c|n=c.to_i;T.count{|e|e&T[n]==T[n]}}.reduce(:*)", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "92fd6f4248d9b3610ef4c936fdd34590", "src_uid": "76c8bfa6789db8364a8ece0574cd31f5", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, k = gets.split.map &:to_i\nputs [:No, :Yes][(1..k).all? { |i| (n + 1) % i == 0 } ? 1 : 0]\n", "lang_cluster": "Ruby", "tags": ["brute force", "number theory"], "code_uid": "377d185de520a0c4cb3a8f404a60acea", "src_uid": "5271c707c9c72ef021a0baf762bf3eb2", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, m = readline.chomp.split(' ').map(&:to_i)\nhs = readline.chomp.split('')\nvs = readline.chomp.split('')\n\nok = n.times.all? { |sy|\n m.times.all? { |sx|\n # puts \"=== #{sx} #{sy}\"\n moves = [[sx, sy]]\n reach = {}\n while !moves.empty?\n nx, ny = moves.pop\n reach[[nx, ny]] = true\n nexts = [[0, -1], [1, 0], [0, 1], [-1, 0]].select { |dx, dy|\n (hs[ny] == '>' && dx == 1) ||\n (hs[ny] == '<' && dx == -1) ||\n (vs[nx] == 'v' && dy == 1) ||\n (vs[nx] == '^' && dy == -1)\n }.map { |dx, dy|\n [nx + dx, ny + dy]\n }.select { |x, y|\n x >= 0 && x < m && y >= 0 && y < n && !reach[[x, y]]\n }\n # puts \"Nexts for #{nx},#{ny}: #{nexts}\"\n moves += nexts\n end\n\n reach.size == n * m\n }\n}\n\nputs ok ? \"YES\" : \"NO\"\n", "lang_cluster": "Ruby", "tags": ["dfs and similar", "implementation", "graphs", "brute force"], "code_uid": "3629dd3cc5f47e3437fe68f3dcc0c5d0", "src_uid": "eab5c84c9658eb32f5614cd2497541cf", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\nans = 0\nn.times do |i|\n gets.split.map(&:to_i).each_with_index do |e, j|\n if i == n / 2 || j == n /2 || i == j || i + j == n - 1\n ans += e\n end\n end\nend\nputs ans", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "ae0e1eea40cf06c6ce49fba326eeaef8", "src_uid": "5ebfad36e56d30c58945c5800139b880", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "k = readline.chomp.to_i\nn = 34\n\nseats = [\n (k > 0 ? 1 : 0) + ((k > 4 ? k - 4 : 0) / 3.0).ceil,\n (k > 1 ? 1 : 0) + ((k > 5 ? k - 5 : 0) / 3.0).ceil,\n (k > 2 ? 1 : 0),\n (k > 3 ? 1 : 0) + ((k > 6 ? k - 6 : 0) / 3.0).ceil\n].map {|i| i >= 0 ? i : 0}\n\ndef pr(n, a)\n ('O' * a + '#' * (n - a)).split('').join('.')\nend\n\nputs '+------------------------+'\nputs \"|#{pr(11, seats[0])}.|D|)\"\nputs \"|#{pr(11, seats[1])}.|.|\"\nputs \"|#{pr(1, seats[2])}#{'.' * 23}|\"\nputs \"|#{pr(11, seats[3])}.|.|)\"\nputs '+------------------------+'\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "075dba2b788415162e1ec19e4c99687e", "src_uid": "075f83248f6d4d012e0ca1547fc67993", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def is_lucky(s)\n while s>0\n return false if s%10!=7 && s%10!=4\n s/=10\n end\n return true\nend\ndef fact(k)\n return 1 if k<=0\n return fact(k-1)*k\nend\ndef lucky(now)\n res=[]\n return [] if now>1000000000\n return [now]+lucky(now*10+4)+lucky(now*10+7)\nend\nn,k=gets.split.map(&:to_i)\nk-=1\nremain=[]\n\ndef solve(n,remain,k)\n return [] if n==0\n n.times{|i|\n if k 0 ? d[i][j - 1] : 0\n end\n if s2[i] == '-'\n d[i + 1][j] = j < 20 ? d[i][j + 1] : 0\n end\n if s2[i] == '?'\n d[i + 1][j] = ((j > 0 ? d[i][j - 1] : 0) + (j < 20 ? d[i][j + 1] : 0)) / 2\n end\n end\nend\nsum = 0\nfor x in s1\n sum += (x == '+' ? 1 : -1)\nend\nputs d[n][sum + 10]\n", "lang_cluster": "Ruby", "tags": ["brute force", "math", "dp", "combinatorics", "bitmasks", "probabilities"], "code_uid": "ece285ce660b4ec834215b422dbe7456", "src_uid": "f7f68a15cfd33f641132fac265bc5299", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/ruby\ninclude Math\n\na, b = gets.split().map(&:to_i)\nx, y, z = gets.split().map(&:to_i)\naa = 2*x + y\nbb = 3*z + y\nputs [aa-a, 0].max + [bb-b, 0].max\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "74951f028abd0de8d80753551bac2850", "src_uid": "35202a4601a03d25e18dda1539c5beba", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "x,t,a,b,da,db=gets.split.map(&:to_i);\ntag=0;\nfor i in 0...t\n\tfor j in 0...t\n\t\tif a-i*da+b-j*db==x or a-i*da==x or b-j*db==x or x==0\n\t\t\ttag=1;\n\t\t\tbreak;\n\t\tend\n\tend\nend\n\nif tag==1\n\tputs \"YES\"\nelse\n\tputs \"NO\"\nend\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "a95ffc2b88b3b49f561a31fe5c8a1bc5", "src_uid": "f98168cdd72369303b82b5a7ac45c3af", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a1, a2 = gets.chomp.split(\" \").map(&:to_i)\nn = 0\nwhile true\n if a1 < a2 then\n a1 += 1\n a2 -= 2\n else\n a1 -= 2\n a2 += 1\n end\n if a1 > 0 and a2 > 0 then\n n += 1\n elsif a1 == 0 or a2 == 0 then\n n += 1\n puts n\n exit\n else\n puts n\n exit\n end\nend\n", "lang_cluster": "Ruby", "tags": ["math", "greedy", "dp", "implementation"], "code_uid": "1e7be63d188f311ff60901ce5d638664", "src_uid": "ba0f9f5f0ad4786b9274c829be587961", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.to_i\np=n\nm=0\nwhile n>=10\n\tm+=1\n\tn/=10\nend\n#puts \"m=\"+m.to_s\n#puts \"n=\"+n.to_s\nputs (n+1)*(10**m)-p", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "0ac3bb273ff0151c759073c6821a43a0", "src_uid": "a3e15c0632e240a0ef6fe43a5ab3cc3e", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "t,s,x=gets.split.map{|e| e.to_i}\nif (x-t)%s==0 && (x-t)/s>=0 then\n\tputs \"YES\"\nelsif (x-t-1)%s==0 && (x-t-1)/s>0 then\n\tputs \"YES\"\nelse\n\tputs \"NO\"\nend\n\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "c6dfd77f409ae3499de58b86a5f548cb", "src_uid": "3baf9d841ff7208c66f6de1b47b0f952", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "class Algorithm\n NUM_PLAYERS, PLAYER_ID = 3, %w(F M S ?)\n\n def solve(combinations)\n PLAYER_ID[find_winner(combinations.map { |v| v.strip.to_sym })]\n end\n\n private\n \n def find_winner(combinations)\n combinations.each_with_index do |combo, index|\n ok = true\n combinations.each_with_index do |c, i|\n next if i == index\n ok = (ok and beat?(combo, c))\n end\n return index if ok\n end\n return -1\n end\n\n def beat?(first, second)\n return true if first == :paper and second == :rock\n return true if first == :rock and second == :scissors\n return true if first == :scissors and second == :paper\n return false\n end\nend\n\ncombos = []\nAlgorithm::NUM_PLAYERS.times { combos.push gets }\n\nputs Algorithm.new.solve(combos)\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "791e4a5a2e22ee01a21885c1d449c6b9", "src_uid": "072c7d29a1b338609a72ab6b73988282", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,k = gets.chomp.split(\" \").map(&:to_i)\nans = 0\nif 2*n-1 >= k\n m = k-1 <= n ? 1 : k-n\n ans += k/2-m+1\n ans -= 1 if k.even?\nend\nputs ans\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "d6ef264b39d9179f2c429fcddc35a0b8", "src_uid": "98624ab2fcd2a50a75788a29e04999ad", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.chomp.to_i\nxs = []\nys = []\nn.times do\n x, y = gets.chomp.split.map(&:to_i)\n xs << x\n ys << y\nend\n\nxs.sort!.uniq!\nys.sort!.uniq!\n\ns = (xs[-1] - xs[0]) * (ys[-1] - ys[0])\n\nputs (0 < s ? s : -1)\n\n", "lang_cluster": "Ruby", "tags": ["geometry", "implementation"], "code_uid": "24caf7a812d0f764c66a9ac039a25771", "src_uid": "ba49b6c001bb472635f14ec62233210e", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, l, r = gets.split.map &:to_i\nputs [n - l + 2**l - 1, 2**r - 1 + 2**(r - 1)*(n - r)].join ' '\n", "lang_cluster": "Ruby", "tags": ["math", "greedy"], "code_uid": "6b16fb73b0575d715fcf1befc59c0cdc", "src_uid": "ce220726392fb0cacf0ec44a7490084a", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#不是闰年,就是说:2月份是28天\nnumber=gets.chomp.split\nm=number[0].to_i\nd=number[1].to_i\nmonth=[0,31,28,31,30,31,30,31,31,30,31,30,31]\n#puts month[m]\ncolumn=(month[m]-(8-d))/7\nif (month[m]-(8-d))%7 > 0\n\tcolumn+=1\nend\nputs column+1\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "6ed5776a4751d94a30537d4f2ca0a321", "src_uid": "5b969b6f564df6f71e23d4adfb2ded74", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i \nk = 0;\nfor i in 1..n-1\n if((n%i) == 0)\n k+=1;\n end\nend \np k", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "662d99bf637aeec0e4fd36599e1717f3", "src_uid": "89f6c1659e5addbf909eddedb785d894", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.to_i\ns=gets.to_s\np=s.chomp.split(\"\")\nx=1;\n10000.times do\n x*=10;\nend\ndp = Array.new(100,x)\ndp[0]=0;\ny=p.size.to_i\nfor i in 0..y-1 do\n tmp=0\n j=i\n while j r\n puts 'Limak'\nelse\n puts 'Radewoosh'\nend", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "898a193e6f24f4ef1a85e7ecfd195c53", "src_uid": "8c704de75ab85f9e2c04a926143c8b4a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "# Utility\ndef factorial(n)\n (1..n).inject(:*) || 1\nend\n\n# Input\nn, m, k = *(gets.split.map { |i| i.to_i })\n\n# Processing\nf = factorial(n - 1) / (factorial(n - 1 - k) * factorial(k))\ng = m * (m - 1)**k\n\nresult = f * g % 998244353\n\n# Output\nputs result\n", "lang_cluster": "Ruby", "tags": ["math", "dp", "combinatorics"], "code_uid": "4008025cc3ee67bd9af8f7e45d3f94fd", "src_uid": "b2b9bee53e425fab1aa4d5468b9e578b", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\ns = gets.chomp\n\ndiv = []\nfor i in 1..n\n if n%i==0 && i!=1 && i!=n\n div << i\n end\nend\n\nx = div.size\n\nfor i in 0..x-1\n tempA = s[0,div[i]].reverse\n tempB = s[div[i],n-1]\n s = tempA+tempB\nend\nputs s.reverse", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "2b05f4f534e1d91b60381a59e56708d3", "src_uid": "1b0b2ee44c63cb0634cb63f2ad65cdd3", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "k, a, b, v = gets.split.map{|e| e.to_i}\n\n(1..1000).each do |x|\n if (([x + b, x * k].min) * v >= a)\n puts x\n exit\n end\nend\n\n", "lang_cluster": "Ruby", "tags": ["math", "greedy"], "code_uid": "bbe58cf15ffb52bab471f9bae88c9753", "src_uid": "7cff20b1c63a694baca69bdf4bdb2652", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def calc(stones)\n\tthrees = (stones / 3).to_i # 1\n\n\tremaining = stones - (threes * 3) # 2\n\t\n\tcount = threes * 2\n\t\n\tif remaining == 2\n\t\tcount += 1 #, 1 \n\t\tcount -= 1 # 1, 2 -> 3\n\t\tcount += 1 #3, 1\n\tend\n\t\n\tif remaining == 1\n\t\tcount += 1\t\n\tend\n\t\n\tcount = 1 if count == 0\n\t\n\tcount\nend\n\nstones = gets.chomp.to_i\n\nputs calc(stones)", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "b42c9ba31195896f2ae38e8cc9d238a6", "src_uid": "a993069e35b35ae158d35d6fe166aaef", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\nans = Array.new(n, 0)\nans[0] = 1\n(1..n-1).each do |i|\n ans[i] = ans[i-1] + 4 * i\nend\nputs ans[n-1]", "lang_cluster": "Ruby", "tags": ["math", "dp", "implementation"], "code_uid": "e153c24b4790488bc0d5fcf0837a76cc", "src_uid": "758d342c1badde6d0b4db81285be780c", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, k = gets.chomp.split(\" \").map{|e| e.to_i}\n\nleft = 1\nright = n\nans = nil\nwhile (left <= right) do\n mid = (left + right) / 2\n tmp = mid\n sum = 0\n \n while (tmp > 0) do\n sum += tmp\n tmp /= k\n end\n \n if sum < n\n left = mid + 1\n else\n right = mid - 1\n ans = mid\n end\nend\n\nputs ans\n\n", "lang_cluster": "Ruby", "tags": ["implementation", "binary search"], "code_uid": "0efe8527067780f361417193f3ac07c8", "src_uid": "41dfc86d341082dd96e089ac5433dc04", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\nt = Math.sqrt(n).floor\nif (n - (t ** 2) == 0)\n puts t * 2\nelse\n if (n - (t ** 2) <= t)\n puts t * 2 + 1\n else\n puts (t + 1) * 2\n end\nend", "lang_cluster": "Ruby", "tags": ["math", "constructive algorithms", "binary search"], "code_uid": "e4fef3b04bdb91da29202f357baf74f2", "src_uid": "eb8212aec951f8f69b084446da73eaf7", "difficulty": 1100.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": "46e0ee1f21a4059a78bcd477b86ecac0", "src_uid": "073023c6b72ce923df2afd6130719cfc", "difficulty": 1200.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 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\tpetya += 1 if wasRed\n\t\t\tvasya += 1 if !wasRed\n\t\telse\n\t\t\tblueCount -= 1\n\t\t\tvasya += 1 if wasRed\n\t\t\tpetya += 1 if !wasRed\n\t\tend\n\t\tpetyaMove = !petyaMove\n\tend\n\treturn [petya, vasya]\nend\n\npetya0, vasya0 = simulate(true, redNum-1, blueNum, false)\npetya1, vasya1 = simulate(false, redNum, blueNum-1, false)\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": "ecb184373a2f4a4a2509aa19d655eb55", "src_uid": "c8378e6fcaab30d15469a55419f38b39", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "class Matrix2x2\n attr_accessor :a, :b, :c, :d\n def initialize(a=0,b=0,c=0,d=0)\n @a = a\n @b = b\n @c = c\n @d = d\n end\nend\n\ndef mult(x, y)\n z = Matrix2x2.new\n z.a = (x.a*y.a + x.b*y.c)%1000000007\n z.b = (x.a*y.b + x.b*y.d)%1000000007\n z.c = (x.c*y.a + x.d*y.c)%1000000007\n z.d = (x.c*y.b + x.d*y.d)%1000000007\n z\nend\n\ndef expt(a, p)\n if p == 1\n a.clone\n elsif p % 2 == 1\n t = expt(a, p-1)\n mult(a, t)\n else\n t = expt(a, p/2)\n mult(t, t)\n end\nend\n\nn = gets.to_i\nif n == 0\n puts 0\nelse\n a = Matrix2x2.new(0, 3, 1, 2)\n an = expt(a, n)\n puts an.a\nend\n", "lang_cluster": "Ruby", "tags": ["math", "matrices", "dp"], "code_uid": "540d0f72c7865506d67a48d00aec2144", "src_uid": "77627cc366a22e38da412c3231ac91a8", "difficulty": 1500.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", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "4b3774658f090a404373c8be6c5a4bc5", "src_uid": "01b145e798bbdf0ca2ecc383676d79f3", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "class String\n def is_lower?\n self == self.downcase\n end\nend\n\nn = STDIN.gets.chomp.to_i\ns = STDIN.gets.chomp\nletters = {}\nanswer = 0\ns.each_char do |ch|\n if ch.is_lower?\n letters[ch] = true\n else\n answer = [answer, letters.size].max\n letters = {}\n end\nend\nanswer = [answer, letters.size].max\nputs answer\n", "lang_cluster": "Ruby", "tags": ["brute force", "strings", "implementation"], "code_uid": "4eaed5c8475d3517033457c49d748c2a", "src_uid": "567ce65f87d2fb922b0f7e0957fbada3", "difficulty": 1000.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 0\n ans += [a, b].min\n n -= 1\nend\n\nans += [a, b, c].min * n\nn -= n\n\nputs ans\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "9de6c5addad4e84d21256b06e7c8017c", "src_uid": "6058529f0144c853e9e17ed7c661fc50", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, h, m = gets.split.map &:to_i\na = [h]*(n + 1)\nm.times do\n l, r, x = gets.split.map &:to_i\n (l..r).each { |i| a[i] = [a[i], x].min }\nend\nputs a[1..-1].inject(0) { |s, x| s + x*x }\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "a79ac0fd03741d73469d406c105ba78f", "src_uid": "f22b6dab443f63fb8d2d288b702f20ad", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,m,k=gets.split.map(&:to_i)\nans=0\nMOD=1000000007\nif k==1 || k>n then\n ans=1\n n.times{ ans=(ans*m)%MOD}\n p ans\nelsif k==n\n t=(k+1)/2\n ans=1\n t.times{ans=ans*m%MOD}\n p ans\nelsif k % 2==0 then\n p m\nelsif k % 2==1\n p m*m\nend\n", "lang_cluster": "Ruby", "tags": ["dfs and similar", "math", "combinatorics", "graphs"], "code_uid": "6c17ee233d7c092b11c11cf870998eaa", "src_uid": "1f9107e8d1d8aebb1f4a1707a6cdeb6d", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "l = Array.new(4, 0)\ns = Array.new(4, 0)\nr = Array.new(4, 0)\np = Array.new(4, 0)\n4.times do |i|\n l[i], s[i], r[i], p[i] = gets.strip.split.map(&:to_i)\nend\nhit = false\n# Part 1.\nif l[0] == 1 && (p[0] == 1 || p[3] == 1)\n hit = true\nelsif s[0] == 1 && (p[0] == 1 || p[2] == 1)\n hit = true\nelsif r[0] == 1 && (p[0] == 1 || p[1] == 1)\n hit = true\nend\n# Part 2.\nif !hit\n if l[1] == 1 && (p[1] == 1 || p[0] == 1)\n hit = true\n elsif s[1] == 1 && (p[1] == 1 || p[3] == 1)\n hit = true\n elsif r[1] == 1 && (p[1] == 1 || p[2] == 1)\n hit = true\n end\nend\n# Part 3.\nif !hit\n if l[2] == 1 && (p[2] == 1 || p[1] == 1)\n hit = true\n elsif s[2] == 1 && (p[2] == 1 || p[0] == 1)\n hit = true\n elsif r[2] == 1 && (p[2] == 1 || p[3] == 1)\n hit = true\n end\nend\n# Part 4.\nif !hit\n if l[3] == 1 && (p[3] == 1 || p[2] == 1)\n hit = true\n elsif s[3] == 1 && (p[3] == 1 || p[1] == 1)\n hit = true\n elsif r[3] == 1 && (p[3] == 1 || p[0] == 1)\n hit = true\n end\nend\nputs hit ? \"YES\" : \"NO\"\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "994f895899673d973e11cdaa3df9f358", "src_uid": "44fdf71d56bef949ec83f00d17c29127", "difficulty": 1200.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\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": "9890f90722cf19b52f800bff44b19ce3", "src_uid": "4c2865e4742a29460ca64860740b84f4", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "m='6789TJQKA'\nc=gets[0,1]\no,t=gets.strip.split\na,d=m.index(o[0,1]),o[1,1]\nb,e=m.index(t[0,1]),t[1,1]\nputs (d==c && e!=c || d==c && e==c && a>b || d==e && a>b)? :YES : :NO\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "94b29e859da43ec528137b390eff5fa7", "src_uid": "da13bd5a335c7f81c5a963b030655c26", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "k,r=gets.split.map &:to_i\n(1..10).each{|i|t=k*i%10;(p i;exit)if t==0||t==r}", "lang_cluster": "Ruby", "tags": ["brute force", "math", "constructive algorithms", "implementation"], "code_uid": "da9134cd1b2df4e5f8ccb7ab9ef3adc6", "src_uid": "18cd1cd809df4744bb7bcd7cad94e2d3", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s, k = gets.split\nd = {false => 0, true => -k.to_i}\ns.reverse.chars { |c| d[c == '0'] += d[true].zero? ? 0 : 1 }\np d[true] == 0 ? d[false] : s.size - 1", "lang_cluster": "Ruby", "tags": ["brute force", "greedy"], "code_uid": "a9928e4ef6b8a49e07cdf5c57ec555b2", "src_uid": "7a8890417aa48c2b93b559ca118853f9", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def isinside(ax, ay)\n half = $a/2.0\n return false if ax - half >= $x || ax + half <= $x\n return false if ay - half >= $y || ay + half <= $y\n return true\nend\n$a,$x,$y = gets.chomp.split(/ /).map!{|x| x.to_i}\nret = -1\nif $y < $a\n ret = 1 if isinside(0, $a*0.5)\nelse\n tr = ($y - $a).divmod($a*2)[0]\n st = 3*tr + 2\n sty = (2*tr+1.5)*$a\n ret = st if isinside(0, sty)\n ret = st+1 if isinside(-$a*0.5, sty+$a)\n ret = st+2 if isinside( $a*0.5, sty+$a)\nend\nputs ret.to_s\n", "lang_cluster": "Ruby", "tags": ["math", "geometry"], "code_uid": "8d06eddb54eba34c730908f7d5ef3832", "src_uid": "cf48ff6ba3e77ba5d4afccb8f775fb02", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, m, k = gets.split(\" \").map(&:to_i)\na = gets.split(\" \").map(&:to_i)\n\nans = 99999999999999999999999\na.each_with_index do |x, i|\n i += 1\n if x <= k && x != 0\n ans = [ans, (i-m).abs].min\n end\nend\n\np ans*10", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "6c0bb604f500a8e2a788cb4e48c3fe9d", "src_uid": "57860e9a5342a29257ce506063d37624", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby 3", "source_code": "END { load __FILE__ unless $stdin.eof? }\n\n@m = 10**9 + 7\n\ndef f(n, k)\n\treturn 1 if k == 0\n\t$table[k] ||= (\n\tif n.even?\n\t\t(2.pow(n * k.pred, @m) + 2.pow(n - 1, @m).pred * f(n, k - 1)) % @m\n\telse\n\t\t(2.pow(n - 1, @m).succ * f(n, k - 1)) % @m\n\tend\n\t)\nend\n\nt = gets.to_i\nt.times do\n\tn, k = gets.split.map!(&:to_i)\n\t$table = Array.new(k + 1)\n\tk.times { |kk| f(n, kk) }\n\tp f(n, k)\nend\n", "lang_cluster": "Ruby", "tags": ["math", "dp", "combinatorics", "bitmasks", "matrices"], "code_uid": "8720b968ce5fcc30d5ea2f3729f648cb", "src_uid": "02f5fe43ea60939dd4a53299b5fa0881", "difficulty": 1700.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": "adae1791258baedd2c4f5f0c086739f3", "src_uid": "7219d1837c83b5920992aee5a60dc0d9", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def inpf() a=gets.chomp.split(\" \").map(&:to_f)end\n\ndef inps() a=gets.chomp.split(\" \")end\n\ndef copy(a) Marshal.load(Marshal.dump(a)) end\n\ndef kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end\n\ndef na(n,d=0) Array.new(n,d)end\n\ndef na2(n,m,d=0) Array.new(n){Array.new(m,d)}end\n\ndef na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end\n\ndef inp() a=gets.chomp.split(\" \").map(&:to_i)end\n\ndef r_up(a, b) (a+b-1)/b end\n\ndef sum(a) a.inject(:+) end\n\nrequire 'prime'\nn = inp[0]\n\nd = Prime.prime_division(n)\nif(d.size == 1 )\n p d[0][0]\nelse\n p 1\nend", "lang_cluster": "Ruby", "tags": ["number theory"], "code_uid": "416a450d42a82c8c43661fcf86810c91", "src_uid": "f553e89e267c223fd5acf0dd2bc1706b", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\nputs n - gets.chomp.scan(/RU|UR/).size", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "7342ca34b38832df527cf066a12385bf", "src_uid": "986ae418ce82435badadb0bd5588f45b", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "h, n = gets.chomp.split.map(&:to_i)\n\nans = 0\noffset = 0\nflag = false\nm = 2 ** h\n\nwhile m != 1\n m /= 2\n if flag ^ (offset + m >= n)\n ans += 1\n flag = !flag\n offset += m unless flag\n else\n ans += 2 * m\n offset += m unless flag\n end\nend\n\nputs ans\n", "lang_cluster": "Ruby", "tags": ["math", "implementation", "trees"], "code_uid": "2ebb28cbc72a2f852dc91629d7ea94cb", "src_uid": "3dc25ccb394e2d5ceddc6b3a26cb5781", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "BEGIN{\n\tdef main()\n\t\tn, m, v = gets.split.map(&:to_i)\n\t\ta = gets.split.map(&:to_i)\n\t\ta.sort!\n\t\tl = a.length - 1\n\t\tcc = 0\n\t\twhile v < m do\n\t\t\tif a[l] <= 1 then\n\t\t\t\tputs -1\n\t\t\t\treturn\n\t\t\tend\n\t\t\tv -= 1\n\t\t\tv += a[l]\n\t\t\tcc += 1\n\t\t\tl -= 1\n\t\t\tbreak if l == -1\n\t\tend\n\t\tif v < m then\n\t\t\tputs -1\n\t\telse\n\t\t\tputs cc\n\t\tend\n\tend\n\t\tmain()\n}\n", "lang_cluster": "Ruby", "tags": ["sortings", "implementation", "greedy"], "code_uid": "77a0b3ffde09dda520707472972f6196", "src_uid": "b32ab27503ee3c4196d6f0d0f133d13c", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a=gets.chomp.to_i-1\nb=gets.chomp\nres=0\nif a!=0\narray=[]\ni=0\nif (a+1)%2==0\nk=0\nloop do\nbreak if a-k<=0 \nl=0\n\tloop do \n\t\tbreak if l>k\n\t\tarray[i]=b[l..(a-k+l)]\n\t\ti+=1\n\t\tl+=1\n\tend\n\t\tk+=2\nend\nelse \nk=1\nloop do\nbreak if a-k<=0 \nl=0\n\tloop do \n\t\tbreak if l>k\n\t\tarray[i]=b[l..(a-k+l)]\n\t\ti+=1\n\t\tl+=1\n\tend\n\t\tk+=2\nend\nend\ni=0\nloop do\n\ttemp=array[i].split('')\n\tif \n\t\ttemp.count('U')==temp.count('D') && temp.count('L')==temp.count('R') \n\t\tres+=1\n\t\tend\n\ti+=1\n\tbreak if i==array.length\nend\nend\nputs res\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "8c6a8e0f9e3db59d3e4c0517d1cd126a", "src_uid": "7bd5521531950e2de9a7b0904353184d", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "\ninp = gets.chomp.split.map(&:to_i);\nn = inp.shift;\ndn = Array.new(n + 1, -1e9);\ndn[0] = 0;\n\n(0..n).each do |x|\n for y in inp do\n dn[x] = [dn[x], 1 + dn[x - y]].max if (x - y >= 0);\n end\nend\n \nputs dn[n];\n", "lang_cluster": "Ruby", "tags": ["brute force", "dp"], "code_uid": "b346bc0ee8b0e23e28d32ca22bd694ec", "src_uid": "062a171cc3ea717ea95ede9d7a1c3a43", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.chomp.to_i\nrow = gets.chomp.split('')\n\nans = []\nbSize = 0\n\nfor i in (0...row.length)\n\tbSize += 1 if row[i] == 'B'\n\n\tif row[i] == 'W'\n\t\tif bSize > 0\n\t\t\tans << bSize\n\t\tend\n\n\t\tbSize = 0\n\tend\nend\n\nif bSize > 0\n\tans << bSize\nend\n\nif ans.length > 0\n\tputs ans.length\nans.each do |a|\n\tprint \"#{a} \"\nend\nputs ''\n\nelse\n\tputs 0\nend\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "97532d1e9703226bdab25b5c923c29a3", "src_uid": "e4b3a2707ba080b93a152f4e6e983973", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "r=0;[*$<][1].split.each_with_index{|e,i|r+=4*e.to_i*i};p r", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "afe3c529e38a5ffa19223f521477d289", "src_uid": "a5002ddf9e792cb4b4685e630f1e1b8f", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def solve() \n line = gets\n x = line.split(' ')[0].to_i\n y = line.split(' ')[1].to_i\n z = line.split(' ')[2].to_i\n\n if (x > y + z)\n return \"+\"\n end\n if (y > x + z)\n return \"-\"\n end\n if (z == 0)\n if ( x > y)\n return \"+\"\n end\n if ( y > x)\n return \"-\"\n end\n return \"0\"\n end\n \n return \"?\"\nend\n\n\nputs solve()\n", "lang_cluster": "Ruby", "tags": ["greedy"], "code_uid": "0d0c6eeb71776d7172cc64522356fb32", "src_uid": "66398694a4a142b4a4e709d059aca0fa", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.strip.to_i\n\ndef kek(n)\n min = n\n i = n - 1\n while i > 0\n if n%i!=0\n k = kek(n-i)\n min = n-i if n-i < min\n return min if min == 1\n end\n i-=1\n end\n min\nend\n\nmin = n\ni = n - 1\nwhile i > 0\n if n%i!=0\n k = kek(n-i)\n min = n-i if n-i < min\n break if min == 1\n end\n i-=1\nend\n\np min\n", "lang_cluster": "Ruby", "tags": ["math", "constructive algorithms"], "code_uid": "fbeaae5c1323144a000a3311ce799914", "src_uid": "c30b372a9cc0df4948dca48ef4c5d80d", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a=gets.chomp.to_i\nb=gets.chomp.split(\" \")\nlb=b.delete_at(0).to_i\n0.upto(lb-1) {|i|b[i]=b[i].to_i}\nc=gets.chomp.split(\" \")\nlc=c.delete_at(0).to_i\n0.upto(lc-1) {|i|c[i]=c[i].to_i}\nturn=0\nloop do\nif b[0]>c[0]\nb<106\nputs \"-1\"\nbreak\nend\nend\n", "lang_cluster": "Ruby", "tags": ["dfs and similar", "brute force", "games"], "code_uid": "67cd840fc056650d13e2bac153aa1755", "src_uid": "f587b1867754e6958c3d7e0fe368ec6e", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a = gets.strip.to_i\nb = gets.strip.to_i\nc = gets.strip.to_i\nans = 0\nwhile a >= 1 && b >= 2 && c >= 4\n ans += 7\n a -= 1\n b -= 2\n c -= 4\nend\nputs ans\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "10b43b377c61f7ab01b9d2258eff7ac9", "src_uid": "82a4a60eac90765fb62f2a77d2305c01", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a, b, c, n = gets.split.map(&:to_i)\nx = a + b - c\nputs (a >= c && b >= c && n - x > 0) ? (n - x) : -1\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "3d6f7a697152e7329f2fe88237907552", "src_uid": "959d56affbe2ff5dd999a7e8729f60ce", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, l, r = gets.split.map(&:to_i)\nz = [0] * 3\ncase l % 3\nwhen 1\n z[1] += 1\n z[2] += 1\n l += 2\nwhen 2\n z[2] += 1\n l += 1\nend\ncase r % 3\nwhen 1\n z[2] -= 1\n r += 1\nwhen 0\n z[2] -= 1\n z[1] -= 1\n r += 2\nend\narr = z.map{|e| e + (r - l + 1) / 3}\ncur = arr.dup\nnxt = [0] * 3\n(2..n).each do |i|\n nxt = [0] * 3\n nxt[0] = cur[0] * arr[0] + cur[1] * arr[2] + cur[2] * arr[1]\n nxt[1] = cur[0] * arr[1] + cur[1] * arr[0] + cur[2] * arr[2]\n nxt[2] = cur[0] * arr[2] + cur[1] * arr[1] + cur[2] * arr[0]\n # puts nxt.join(' ')\n cur = nxt.dup\n cur = cur.map{ |e| e % (10 ** 9 + 7)}\nend\nputs cur[0]", "lang_cluster": "Ruby", "tags": ["math", "dp", "combinatorics"], "code_uid": "d23f81401714495e9c67418528923f80", "src_uid": "4c4852df62fccb0a19ad8bc41145de61", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "class Solver\n\tdef main\n\t\tn = gets.to_i\n\t\ta = gets.to_i\n\t\tb = gets.to_i\n\t\tc = gets.to_i\n\t\tif b - c >= a\n\t\t\tputs n / a\n\t\telse\n\t\t\tans = 0\n\t\t\tif n >= c\n\t\t\t\tans += (n - c) / (b - c)\n\t\t\t\tn -= (n - c) / (b - c) * (b - c)\n\t\t\tend\n\t\t\tans += n / [a, b].min\n\t\t\tputs ans\n\t\tend\n\tend\nend\nSolver.new.main", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "7a59621d4f58d30d95627f9a9d84d014", "src_uid": "0ee9abec69230eab25de51aef0984f8f", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n =gets.chomp.to_i\nsum = 0\narr = gets.chomp.split(\" \").collect! {|x| x.to_i}\narr.each { |k|\t\n\tsum += k\n}\n\n#puts sum\nsum = sum%(n+1)\nif sum == 0\n#sum = 1\nend\np=5\nq = 1\nwhile q<=5\n\tif (sum + q)%(n+1)==1\n\t\tp -= 1\n\tend\n\tq += 1\nend\n\n\nputs p", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "641c10a12371c875f70d0cac6afd71ef", "src_uid": "ff6b3fd358c758324c19a26283ab96a4", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,k,t=gets.split.map(&:to_i)\nif t >= k && t <= n\n puts k\nelsif t < k\n puts t\nelse\n puts n + k - t\nend", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "af606e0a3ecd06ecc8670cc584e88481", "src_uid": "7e614526109a2052bfe7934381e7f6c2", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,m,k=gets.split.map(&:to_i)\nif k>n+m-2\n p -1\nelse\n r=[n/(k+1)*m,m/(k+1)*n]\n r << n/(k-m+2) if k-m+2 >0\n r << m/(k-n+2) if k-n+2 >0\n p r.max\nend\n", "lang_cluster": "Ruby", "tags": ["greedy", "implementation"], "code_uid": "765917a07f8ece984cd419282b74e5a0", "src_uid": "bb453bbe60769bcaea6a824c72120f73", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a, b = gets.split.map { |x| x.to_i }\n\nans = 0\nwhile b != 0\n\tans += a / b\n\ta -= a / b * b\n\ta, b = b, a\nend\n\nputs ans", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "1aebcd0c36802aa5eb7a10ccd6626e29", "src_uid": "ce698a0eb3f5b82de58feb177ce43b83", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,ta,b,tb,h,m=$<.read.tr(':',' ').split.map(&:to_i)\nx1=h*60+m;y1=x1+ta\nr=0\n300.step(1440-1,b){|x2|\n\ty2=x2+tb\n\tr+=1 if [x1,x2].max < [y1,y2].min\n}\np r", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "b88b2ad5d7d7d69471cab3aa2a74dbb2", "src_uid": "1c4cf1c3cb464a483511a8a61f8685a7", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, m = gets.chomp.split(' ').map { |x| x.to_i }\n\nbuttons = gets.chomp.split(' ').map { |x| x.to_i }\n\n\nn.times do |i|\n\n\tbuttons.each do |button|\n\n\t\tif button <= i+1\n\t\t\tprint button,\" \"\n\t\t\tbreak\n\t\tend\n\tend\nend\n\nputs\n\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "526ed4313c38ce3d010888fafd5cbaf0", "src_uid": "2e44c8aabab7ef7b06bbab8719a8d863", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def step(a,op)\n\ta.permutation.map{|v| ( ( [ (op==\"+\") ? v[0]+v[1] : v[0]*v[1] ] ) + ( (v.drop(2)) ? v.drop(2) : [] ) ).sort }.uniq\nend\n\n\na=gets.split.map{|v| v.to_i}\noper=gets.split\nres=[]\nstep(a,oper[0]).each do |v| \n step(v,oper[1]).each do |t|\n\tres+=step(t,oper[2])\n end\nend\nputs res.min", "lang_cluster": "Ruby", "tags": ["brute force"], "code_uid": "6a2a3db7f1dd02f79881b394a6dd2323", "src_uid": "7a66fae63d9b27e444d84447012e484c", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, t = readline.split(' ').collect(&:to_i)\narr = Array.new(n) {|i| Array.new(i + 1, 0.0)}\nt.times do\n arr[0][0] += 1.0\n 0.upto(n - 2) do |i|\n 0.upto(i) do |j|\n if arr[i][j] > 1.0\n left = arr[i][j] - 1.0\n arr[i + 1][j] += left / 2.0\n arr[i + 1][j + 1] += left / 2.0\n arr[i][j] = 1.0\n end\n end\n end\nend\n\nputs arr.inject(0) {|sum, a|\n sum + a.count {|num| num >= 1.0}\n}\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "4d2fcdf3376109677d0450642db63eed", "src_uid": "b2b49b7f6e3279d435766085958fb69d", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a, b, c = gets.split.map &:to_i\n\n\ndef solve(a,b,c)\n ar = Array.new(1000001) { 0 }\n ans = 0\n mod = 1073741824\n for i in 1..a do\n for j in 1..b do\n for k in 1..c do\n d = i*j*k\n ans += ret_div(ar, d, mod)\n end\n end\n end\n puts ans\nend\n\ndef ret_div(ar, el, mod)\n return ar[el] if ar[el]>0\n j = 1\n div = 0\n while j*j<=el do\n if el%j == 0\n div+=2\n end\n j+=1\n\n end\n div-=1 if (j-1)*(j-1) == el\n ar[el] = div % mod\n ar[el]\nend\n\nsolve a, b ,c", "lang_cluster": "Ruby", "tags": ["implementation", "number theory"], "code_uid": "5e80ce0cbead9cbeb61f0c49c719c84a", "src_uid": "4fdd4027dd9cd688fcc70e1076c9b401", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def maxdiv(a,x)\n\treturn -1 if a < x\n\tw = a.divmod(x)\n\treturn x*w[0]\nend\n\nas,bs,xs,ys = gets.chomp.split(/ /)\na = as.to_i\nb = bs.to_i\nx = xs.to_i\ny = ys.to_i\n\ngcd = x.gcd(y)\nx /= gcd\ny /= gcd\na = maxdiv(a,x)\nb = maxdiv(b,y)\nif a < 0 || b < 0\n\tputs \"0 0\"\nelse\n\tax = a / x\n\tby = b / y\n\twk = [ax, by].min\n\tputs sprintf(\"%d %d\", x*wk, y*wk)\nend", "lang_cluster": "Ruby", "tags": ["binary search", "number theory"], "code_uid": "0d9803b996001715196e1a6c07a293b9", "src_uid": "97999cd7c6de79a4e39f56a41ff59e7a", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s=gets.chomp\np ['a1','a8','h1','h8'].include?(s) ? 3 : s=~/[ah18]/ ? 5 : 8", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "3f33b43f476b9a61d8e211ae785cf460", "src_uid": "6994331ca6282669cbb7138eb7e55e01", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.to_i\nf = Array.new(2522, 1)\nf[0]=0\nfor i in [2, 3, 5, 7]\n\tj=i\n\twhile j<2520\n\t\tf[j]=0\n\t\tj+=i\n\tend\nend\nfor i in 1..2520\n\tf[i] += f[i-1]\nend\nputs n/2520*f[2519]+f[n%2520]", "lang_cluster": "Ruby", "tags": ["math", "number theory"], "code_uid": "3ce7a108de0a4e30c6f9c803205132df", "src_uid": "e392be5411ffccc1df50e65ec1f5c589", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, d, $x = gets.split(' ').map(&:to_i)\na, b = [], []\ndef gnx\n $x = ($x *37 + 10007) % 1000000007\nend\n # initAB\n(1..n).each{|i| a << i}\n(1..n).each do |i|\n tgt = gnx % i\n a[i-1], a[tgt] = a[tgt], a[i-1]\nend\n(1..n).each{|i| b << ( i<=d ? 1 : 0 )}\n(1..n).each do |i|\n tgt = gnx % i\n b[i-1], b[tgt] = b[tgt], b[i-1]\nend\n # end of initAB\n\naid = (0...n).sort_by{|i| -a[i]}\nbid = (0...n).each_with_object([]){|i,a| a << i if b[i]>0}\nc = (0...n).map{|_| -1}\nnf, maxc = n, n-1\naid.each do |ai|\n break if nf == 0\n bid.each do |bi|\n id = ai + bi\n break if id > maxc\n if c[id] < 0\n c[id] = a[ai]\n nf -= 1\n end\n maxc -= 1 until (maxc < 0) || (c[maxc] < 0)\n end\nend\nc.each{|i| puts ( i>0 ? i : 0 )}", "lang_cluster": "Ruby", "tags": ["probabilities"], "code_uid": "441d34aca42be21b51ae835ee6ca495b", "src_uid": "948ae7a0189ada07c8c67a1757f691f0", "difficulty": 2300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/env ruby\n\ndef main\n input = STDIN.readlines\n k = input[0].to_i\n l = input[1].to_i\n\n x = 1\n im = 0\n while x < l\n x *= k\n im += 1\n end\n\n if x == l\n puts \"YES\"\n puts im - 1\n else\n puts \"NO\"\n end\nend\n\nif __FILE__ == $0\n main\nend", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "fff8c555ee3ba58199654bf7b3c89698", "src_uid": "8ce89b754aa4080e7c3b2c3b10f4be46", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = gets.chomp.split(' ')\nn = s[0].to_i\nb = s[1].to_i\np = s[2].to_i\n\nx = 0\ny = n*p\nwhile(n/2>0)\n x = x + (b*2+1)*(n/2)\n n = n/2 + n%2\nend\nputs x.to_s + \" \" + y.to_s\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "6575c6e5ac7b4039b4c4932b96dcfd4f", "src_uid": "eb815f35e9f29793a120d120968cfe34", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.strip.to_i\ns = gets.strip\ni = count_s = count_f = 0\nans = \"YES\"\nwhile i < n - 1\n first = s[i]\n second = s[i + 1]\n count_f += 1 if first == 'F' && second == 'S'\n count_s += 1 if first == 'S' && second == 'F'\n i += 1\nend\nans = \"NO\" if count_s <= count_f\nputs ans\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "21295809815c5f283c17eacf5a737c66", "src_uid": "ab8a2070ea758d118b3c09ee165d9517", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "\n\nn, a, b = gets.chomp.split(\" \").map(&:to_i)\ndancers = gets.chomp.split(\" \").map(&:to_i)\n\ndef palindrome(n, a, b, dancers)\n min_cost = 0\n len = dancers.size\n\n min_cost = [a, b].min if (len % 2 == 1) and (dancers[len/2] == 2)\n (0..len/2-1).each do |idx|\n if dancers[idx] != dancers[len-idx-1] and dancers[idx] != 2 and dancers[len-idx-1] != 2\n p -1\n return\n elsif (dancers[idx] == 2) and (dancers[len-idx-1] == 2)\n min_cost += [a, b].min * 2\n elsif (dancers[idx] == 2) or (dancers[len-idx-1] == 2)\n min_cost += ([dancers[idx], dancers[len-idx-1]].min == 0) ? a : b\n end\n end\n p min_cost\nend\n\npalindrome(n, a, b, dancers)\n", "lang_cluster": "Ruby", "tags": ["greedy"], "code_uid": "efb0b3f11c4ae2c2339b8bca98ad47f4", "src_uid": "af07223819aeb5bd6ded4340c472b2b6", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "X,Y,x,y,a,b=$<.read.split.map &:to_i\nx-=X\ny-=Y\nputs x%a==0&&y%b==0&&x/a%2==y/b%2 ? :YES : :NO", "lang_cluster": "Ruby", "tags": ["math", "implementation", "number theory"], "code_uid": "d886884773b847694810214bd7f940f6", "src_uid": "1c80040104e06c9f24abfcfe654a851f", "difficulty": 1200.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": "249f0ec88c842358d809dacf203cbdf6", "src_uid": "00cffd273df24d1676acbbfd9a39630d", "difficulty": 1900.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 writearr(foo)\n\tputs foo.map{|i| i.to_s}.join(\" \")\nend\nn,k,m = readarr\narr0 = []\nk.times{arr0 << 0}\narr = []\n(n+1).times{arr << arr0.clone}\narr[0][0]=1\nx = 1\n1.upto(n) do |i|\n\t0.upto(9) do |j|\n\t\ty = x * j % k\n\t\tcnt = 0\n\t\tarr[i-1].each do |elem|\n\t\t\ts = (y+cnt)%k\n\t\t\tarr[i][s] += elem\n\t\t\tarr[i][s] = arr[i][s] % m\n\t\t\tcnt+=1\n\t\tend\n\tend\n\tarr[i][0] = 1\n\tx *= 10\n\tx = x % k\nend\ndef norm(array,n)\n\treturn 10**n-array[n].inject(0){|sum,i| sum+i}\nend\nputs (norm(arr,n)-norm(arr,n-1))%m\n#sleep(300)", "lang_cluster": "Ruby", "tags": ["dp", "implementation"], "code_uid": "5f70911c8fea9cacb6fd7e7e9357a36c", "src_uid": "656bf8df1e79499aa2ab2c28712851f0", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s=gets.chomp\nn=s.size\nres=[0]*4\n\n\"RBYG\".chars.each_with_index{|c, i|\n k=s.index c\n j=k\n res[i]+=1 if s[j]==?! while 0<=j-=4\n j=k\n res[i]+=1 if s[j]==?! while n>j+=4\n}\n\nputs res*' '\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation", "number theory"], "code_uid": "ac33137769e72c096329fafe7362ae0f", "src_uid": "64fc6e9b458a9ece8ad70a8c72126b33", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "MOD = 1000000007\n\ndef pow(x,n)\n if n == 0\n 1\n elsif n % 2 == 0\n pow(x*x%MOD, n/2) % MOD\n else\n x * pow(x, n-1) % MOD\n end\nend\n\nn = gets.to_i\nsum = 1\n1.upto(n) do |i|\n sum *= i\n sum %= MOD\nend\nminus = pow(2,n-1)\nsum -= minus\nsum %= MOD\nputs sum", "lang_cluster": "Ruby", "tags": ["math", "dp", "combinatorics", "graphs"], "code_uid": "465eb3b1dc307dc7c9b527195a24ca7f", "src_uid": "3dc1ee09016a25421ae371fa8005fce1", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\narr = gets.split(' ').collect(&:to_i).sort\narr_used = Array.new(n)\n\narr.each_with_index do |elem_1, idx_1|\n\tarr.each_with_index do |elem_2, idx_2|\n\t\tnext unless arr_used[idx_2].nil?\n\t\tnext unless elem_2 % elem_1 == 0 && elem_1 <= elem_2\n\t\tarr_used[idx_2] = idx_1\n\tend\nend\n\np arr_used.uniq.count\n", "lang_cluster": "Ruby", "tags": ["math", "greedy", "implementation"], "code_uid": "826101abd2ca8bb7ba618ee3c84342ab", "src_uid": "63d9b7416aa96129c57d20ec6145e0cd", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "x,y = gets.split ' '\nx = x.to_f\ny = y.to_f\nif x == y\n puts '='\nelsif y/x < Math.log10(y)/Math.log10(x)\n puts '<'\nelsif y/x > Math.log10(y)/Math.log10(x)\n puts '>'\nelse\n puts '='\nend", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "db375e9f75af99c55472b8a1aacb9a6b", "src_uid": "ec1e44ff41941f0e6436831b5ae543c6", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.to_i\nputs (n-1)/2", "lang_cluster": "Ruby", "tags": ["math", "greedy", "constructive algorithms"], "code_uid": "abc902c0e6a011d366370a7e0840afa0", "src_uid": "dfe9446431325c73e88b58ba204d0e47", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, k=gets.split.map(&:to_i)\ns=gets.chomp.chars\n\nh=Hash.new(0)\ns.each{|c| h[c]+=1}\nok=true\nh.each_value do |v|\n ok&=v<=k\nend\n\nputs ok ? 'YES' : 'NO'\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "c9b1f86cb9052638fb67ee4b11297cbb", "src_uid": "ceb3807aaffef60bcdbcc9a17a1391be", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "# coding: utf-8\n\ns = gets.chomp\nl = s.length\nr = s.reverse\ndiff = 0\nfor i in 0...l\n if s[i] != r[i]\n diff += 1\n end\nend\n\nif (diff == 2) || (diff == 0 && l.odd?)\n puts \"YES\"\nelse\n puts \"NO\"\nend\n", "lang_cluster": "Ruby", "tags": ["brute force", "strings", "constructive algorithms"], "code_uid": "ec444fcace6538f4d7375e175ae0efba", "src_uid": "fe74313abcf381f6c5b7b2057adaaa52", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, m, a, b = gets.split.map(&:to_i)\n\ndiv, mod = n.divmod(m)\n\nputs [mod * b, (m - mod) * a].min\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "464ba4e23fcd2c3259538d5049f73566", "src_uid": "c05d753b35545176ad468b99ff13aa39", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "$r = 1000003\n$p = (0..100).map { |i| (16**i)%$r }\ndef get_ost(k, st) # k*16**p % $r\n (k*$p[st])%$r\nend\nh = {\">\" => 8, \"<\" => 9, \"+\" => 10, \"-\" => 11, \".\" => 12, \",\" => 13, \"[\" => 14, \"]\" => 15}\nans = 0\na = gets.chomp.reverse.split('')\na.each_with_index { |x, i| ans = (ans + get_ost(h[x], i))%$r }\nputs ans", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "bfc71f1e9b394f2d0db3ae0893cb73f5", "src_uid": "04fc8dfb856056f35d296402ad1b2da1", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = gets.chomp\nc = s.chars.to_a\nr = \"\"\ni = j = 0\nm = \"\"\nd = \"\"\nn = \"a\"\nloop do\n m = c.max\n break m = n if m < n\n r += d\n d = m\n i = c.index m\n j = c.rindex m\n n = m\n break if j - i <= 1\n c = c[(i+1)..(j-1)]\nend\nputs r + (i == j ? m : m + m) + r.reverse\n", "lang_cluster": "Ruby", "tags": ["brute force", "binary search", "bitmasks", "greedy", "strings", "implementation"], "code_uid": "a92779077bfdb63f13b65bd0e5fafc32", "src_uid": "9a40e9b122962a1f83b74ddee6246a40", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "N = gets.chomp\ndigits = Hash.new(0)\nN.chars do |c|\n digits[c] += 1\nend\n\nnums = ('0'..'9').map{|i| digits[i]}.select{|n| n > 0}\nmax = nums.inject(:*)\n\ncomb = Array.new(20){Array.new(20, 0)}\ncomb[0][0] = 1\n20.times do |i|\n 20.times do |j|\n comb[i][j] += comb[i-1][j-1] if i>0 && j>0\n comb[i][j] += comb[i-1][j] if i>0\n end\nend\n\nans = 0\n(0...max).each do |i|\n use = []\n nums.each do |n|\n use.push(i % n + 1)\n i /= n\n end\n sum = use.inject(:+)\n prod = 1\n use.each do |u|\n prod *= comb[sum][u]\n sum -= u\n end\n ans += prod\n\n if digits['0'] > 0\n use[0] -= 1\n sum = use.inject(:+)\n prod = 1\n use.each do |u|\n prod *= comb[sum][u]\n sum -= u\n end\n ans -= prod\n end\nend\np ans", "lang_cluster": "Ruby", "tags": ["brute force", "math", "combinatorics"], "code_uid": "7686403c87ba5b3e123d7f8b428dd93b", "src_uid": "7f4e533f49b73cc2b96b4c56847295f2", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.chomp.to_i\nans = 3*n*n + 3*n + 1\nputs ans\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "85ab914216a41c06ac695b328934dbda", "src_uid": "c046895a90f2e1381a7c1867020453bd", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.to_i\nm=n*2-2\nprint((n-3)*4*3*3*(1<<(2*(m-n-2)))+2*4*3*(1<<(2*(m-n-1))))", "lang_cluster": "Ruby", "tags": ["math", "combinatorics"], "code_uid": "de98bb38029eb6c61b4ae207973477fa", "src_uid": "3b02cbb38d0b4ddc1a6467f7647d53a9", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "puts (1..(n=gets.to_i)).inject(:*)/(2*((n/2)**2))", "lang_cluster": "Ruby", "tags": ["math", "combinatorics"], "code_uid": "7f6d9741a36d4ea8020f46b146a3c7e5", "src_uid": "ad0985c56a207f76afa2ecd642f56728", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, m, k = gets.split(' ').map(&:to_i)\n\nputs (n <= m && n <= k) ? 'Yes' : 'No'\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "94ba616c7fb2bbb278d6cd3be21bc092", "src_uid": "6cd07298b23cc6ce994bb1811b9629c4", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def convert str, b\n num = 0\n for i in 0..str.length-1\n num += (str[i].to_i(36) * (b**(str.length-1 - i)).to_i)\n end\n return num\nend\n\ntime = gets\nm = /(.*):(.*)/.match(time)\nhour = m[1]\nminute = m[2]\n\nmax = 1\nhour.each_char {|c| max = [c.to_i(36), max].max}\nminute.each_char {|c| max = [c.to_i(36), max].max}\ninfinite = false \nbases = []\nfor i in max + 1..60\n if(!(convert(hour,i) < 0 || convert(hour,i) > 23 || convert(minute, i) < 0 || convert(minute, i) > 59))\n bases << i\n\tif(i < 60 && convert(hour,i) == convert(hour, i + 1) && convert(minute, i) == convert(minute, i + 1))\n\t infinite = true\n\t break\n\tend\n end\nend\n\nif infinite\n puts -1\nelsif bases.length > 0\n puts bases.join(\" \")\nelse\n puts 0\nend", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "e2fc656cd4338080e6c4702a64fdb0fd", "src_uid": "c02dfe5b8d9da2818a99c3afbe7a5293", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n,m = 2.times.map{gets.to_i}\na = n.times.map{gets.to_i}\nmx = a.max\np = 0\nfor i in 0..n-1\n p += mx-a[i]\nend\nputs \"#{([m-p,0].max+n-1)/n+mx} #{mx+m}\"\n", "lang_cluster": "Ruby", "tags": ["implementation", "binary search"], "code_uid": "7e5c33371e707bf54f32f6490d0d321d", "src_uid": "78f696bd954c9f0f9bb502e515d85a8d", "difficulty": 1100.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": "655869142f183a31cad637429b3ef7b5", "src_uid": "f30329023e84b4c50b1b118dc98ae73c", "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": "8384fa7612f71dffb6437b5d1fba139c", "src_uid": "a593016e4992f695be7c7cd3c920d1ed", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def dot(x0, y0, x1, y1, x2, y2)\n\t(x1 - x0) * (x2 - x0) + (y1 - y0) * (y2 - y0)\nend\n\ndef right(x0, y0, x1, y1, x2, y2)\n\t[x0, y0] != [x1, y1] and [x0, y0] != [x2, y2] and [x1, y1] != [x2, y2] and\n\t\tdot(x0, y0, x1, y1, x2, y2) == 0 ||\n\t\tdot(x1, y1, x0, y0, x2, y2) == 0 ||\n\t\tdot(x2, y2, x0, y0, x1, y1) == 0\nend\n\ndef gao(a)\n\treturn \"RIGHT\" if right(*a)\n\ta.each_index do |i|\n\t\ta[i] += 1\n\t\treturn \"ALMOST\" if right(*a)\n\t\ta[i] -= 2\n\t\treturn \"ALMOST\" if right(*a)\n\t\ta[i] += 1\n\tend\n\t\"NEITHER\"\nend\n\nputs gao gets.split.map &:to_i\n", "lang_cluster": "Ruby", "tags": ["brute force", "geometry"], "code_uid": "30c3d8efe1d05ca4ad10a8497162dcdb", "src_uid": "8324fa542297c21bda1a4aed0bd45a2d", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, a = gets.split.map(&:to_i)\nres = 0\nif (a.to_i.odd?)\n res = (a+1)/2\nelse\n res = (n-a)/2+1\nend\nprint res", "lang_cluster": "Ruby", "tags": ["math", "constructive algorithms"], "code_uid": "32d367d5060115c0843c1500b6e63533", "src_uid": "aa62dcdc47d0abbba7956284c1561de8", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\ns = gets.chomp\nmax = 0\nfor i in 0..n / 2\n\tmax = s[0..i] == s[i + 1..i * 2 + 1] ? i : max\nend\nputs n - max", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "45ddd0989bc47f73f05604a908ce5ec6", "src_uid": "ed8725e4717c82fa7cfa56178057bca3", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "number_size = gets.to_i\nnumbers = gets.split(' ').map(&:to_i)\nresult = []\n\nnumbers.each do |n|\n result = result - [n]\n result.push(n)\nend\n\nputs result.size\nputs result.join(' ')\n", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "9648119765a9c220adc1561fd55d29b9", "src_uid": "1b9d3dfcc2353eac20b84c75c27fab5a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "W=%W(monday tuesday wednesday thursday friday saturday sunday)\nn=(-W.index(gets.chomp)+W.index(gets.chomp))%7\nputs [0,2,3].include?(n) ? :YES : :NO", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "f4649a579581e48d071925030ce1dc9c", "src_uid": "2a75f68a7374b90b80bb362c6ead9a35", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "s = gets.to_i\nh, m = gets.split.map(&:to_i)\nres = 0\nti = h*60+m\nuntil /7/.match(\"#{ti / 60 % 24}#{ti % 60}\")\n ti-=s\n res+=1\nend\np res\n", "lang_cluster": "Ruby", "tags": ["brute force", "math", "implementation"], "code_uid": "a5005bba6e5609eced03a2eccb2fa36b", "src_uid": "5ecd569e02e0164a5da9ff549fca3ceb", "difficulty": 900.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)\nmx = [n,m].max\ndp = Array.new(mx+1){[0,0]}\ndp[1] = [2,0]\n1.upto(mx-1) do |i|\n dp[i+1][0] = (dp[i][0] + dp[i][1]) % MOD\n dp[i+1][1] = (dp[i][0]) % MOD\nend\nsumn = (dp[n][0] + dp[n][1]) % MOD\nsumm = (dp[m][0] + dp[m][1]) % MOD\nans = (sumn + summ - 2) % MOD\np ans", "lang_cluster": "Ruby", "tags": ["math", "dp", "combinatorics"], "code_uid": "220d36dd67123010b009a797ace21da2", "src_uid": "0f1ab296cbe0952faa904f2bebe0567b", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, k = gets.chomp.split().map { |e| e.to_i }\nLIMIT = Math.sqrt(n)\nfactors = []\nfor i in 2 .. LIMIT\n\twhile n % i == 0 && k != 1\n\t\tfactors << i\n\t\tn /= i\n\t\tk -= 1\n\tend\nend\n\nif k != 1 or n == 1\n\tputs \"-1\"\nelse\n\tfor i in factors\n\t\tprint(i,\" \")\n\tend\n\tputs n\nend", "lang_cluster": "Ruby", "tags": ["math", "implementation", "number theory"], "code_uid": "b4f005c8d6ab43c4a9732d0718cf08e1", "src_uid": "bd0bc809d52e0a17da07ccfd450a4d79", "difficulty": 1100.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": "f1a33aaa08ad31862ec75cc82a7c5a27", "src_uid": "75739f77378b21c331b46b1427226fa1", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def gao(n)\n unless $h[n]\n t = 1\n d = 2\n while d * d <= n\n if n % d == 0\n t = [t, gao(d), gao(n / d)].max\n end\n d += 1\n end\n $h[n] = n + t\n end\n return $h[n]\nend\n\n$h = {1 => 1}\nn = gets.to_i\np gao(n)\n", "lang_cluster": "Ruby", "tags": ["number theory"], "code_uid": "dd829a9e8aa53437d1453b211571dbc7", "src_uid": "821c0e3b5fad197a47878bba5e520b6e", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "t = gets.to_i\nans = []\nt.times do\n x = gets.chomp\n len = x.length\n cnt = 0\n cnt += 10 * (x[0].to_i - 1)\n cnt += len * (len + 1) / 2\n ans << cnt\nend\nputs ans", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "e033d8799a490dd9c7d2ea6b89e8cdbd", "src_uid": "289a55128be89bb86a002d218d31b57f", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "# http://codeforces.com/contest/588/problem/B\n# B. Duff in Love\nrequire 'prime'\n\nn = gets.chomp.to_i\nputs n.prime_division.map(&:first).inject(1, :*)\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "0ce6bd08c146be97b9152bfeb8d5def4", "src_uid": "6d0da975fa0961acfdbe75f2f29aeb92", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "require 'set'\n\n$n = gets.to_i\n$a = gets.split.map(&:to_i)\n$memo = Set.new\n$map = Array.new(300){Array.new(300)}\n$delta = [[0, 1], [1, 1], [1, 0], [1, -1], [0, -1], [-1, -1], [-1, 0], [-1, 1]]\n\ndef explode(x, y, lv, dir)\n return if lv >= $n\n k = ((x * 301 + y) * 31 + lv + 1) * 8 + dir\n return unless $memo.add?(k)\n dx, dy = $delta[dir]\n $a[lv].times do\n x += dx\n y += dy\n $map[x][y] = true\n end\n explode(x, y, lv + 1, (dir + 1) % 8)\n explode(x, y, lv + 1, (dir - 1) % 8)\nend\n\nexplode(150, 150, 0, 0)\n\np $map.inject(0){|sum, x| sum + x.count(true)}\n", "lang_cluster": "Ruby", "tags": ["dfs and similar", "brute force", "dp", "data structures", "implementation"], "code_uid": "93bb7f5f8b8257da0aa0304a6737c259", "src_uid": "a96bc7f93fe9d9d4b78018b49bbc68d9", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n=gets.chomp.to_i\ns=gets.chomp\n\nlen, num=0, 0\ns.chars.each do |c|\n if c=='x'\n if len==2\n num+=1\n else\n len+=1\n end\n else\n len=0\n end\nend\n\nputs num", "lang_cluster": "Ruby", "tags": ["greedy", "strings"], "code_uid": "b71b1162a0e698f53716729803c1951d", "src_uid": "8de14db41d0acee116bd5d8079cb2b02", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "vp,vd,t,f,c=gets.to_i,gets.to_i,gets.to_i,gets.to_i,gets.to_i\nif vp>=vd then\n puts 0\n exit\nend\ntime=Rational(t,1)\nfor ans in 0..100000\n #t*vp+time*vp=(vd-vp)*t\n #t*(vp-vd)=-vp*time\n tmp=Rational(-vp*time,vp-vd)\n #p [tmp,vp,vd]\n if tmp+time>=Rational(c,vp) then\n puts ans\n exit\n end\n time+=tmp*2+f\nend\n", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "98dd7186935e0ccef8a9d5cbb285a0fd", "src_uid": "c9c03666278acec35f0e273691fe0fff", "difficulty": 1500.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": "12078a4f0384aaffbb93ac812fe808b4", "src_uid": "92db14325cd8aee06b502c12d2e3dd81", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.chomp.to_i\n\nl = 0\nr = 10**8\nwhile 1 < r - l\n c = (l + r) / 2\n if c * (c + 1) / 2 < n\n l = c\n else\n r = c\n end\nend\n\nputs n - l * (l + 1) / 2", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "566b06c259e18106c81e59ff10050b20", "src_uid": "1db5631847085815461c617854b08ee5", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.chomp.to_i\n\ntotal = 0\n$finite = true\na = gets.chomp.split.map(&:to_i)\n\ndef points2(a, b)\n case a+b\n when 3 then 3\n when 4 then 4\n when 5 then\n $finite = false\n 0\n end\nend\n\ndef points3(a,b,c)\n if a== 3 && b == 1 && c == 2\n 2\n else\n points2(b,c)\n end\nend\n\ntotal += points2(a[0], a[1])\na.each_cons(3) do |a,b,c|\n total += points3(a,b,c)\n break unless $finite\nend\n\nif $finite\n puts \"Finite\"\n puts total\nelse\n puts \"Infinite\"\nend\n", "lang_cluster": "Ruby", "tags": ["geometry"], "code_uid": "3f8841f421b476e44ecf5418c00def64", "src_uid": "6c8f028f655cc77b05ed89a668273702", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "input=gets.split.map(&:to_i)\n\n$n1=input[0]\n$n2=input[1]\n$k1=input[2]+1\n$k2=input[3]+1\n$dp=Array.new(101){Array.new(101){Array.new(20){Array.new(3,-1)}}}\ndef solve(c1,c2,s,t)\n\n if c1>$n1 || c2>$n2 then\n return 0\n end\n if c1==$n1 && c2==$n2 then\n return 1\n end\n if $dp[c1][c2][s][t]>=0 then\n return $dp[c1][c2][s][t]\n end\n #1を置く\n ans=0\n if t==0 then\n if s+1<$k1 then\n ans+=solve(c1+1,c2,s+1,t)\n end\n else\n ans+=solve(c1+1,c2,1,0)\n end\n\n #2を置く\n if t==1 then\n if s+1<$k2 then\n ans+=solve(c1,c2+1,s+1,t)\n end\n else\n ans+=solve(c1,c2+1,1,1)\n end\n ans%=100000000\n $dp[c1][c2][s][t]=ans\n return ans\nend\n\np solve(0,0,0,0)", "lang_cluster": "Ruby", "tags": ["dp"], "code_uid": "a4bde56f7427eb67674e5e8078ac67cd", "src_uid": "63aabef26fe008e4c6fc9336eb038289", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def ptstr(x, y, h)\n\tp = x.to_s + \" \" + y.to_s\n\tif h.key?(p)\n\t\th[p] += 1\n\telse\n\t\th[p] = 1\n\tend\nend\n\nret = true\nar = Array.new(4)\nh = Hash.new\nxlcnt = 0\nylcnt = 0\nfor i in 0..3\n\ta = gets.chomp.split(/ /).map!{|x| x.to_i}\n\tret = false if a[0] == a[2] && a[1] == a[3]\n\t\n\tif a[0] == a[2]\n\t\txlcnt += 1 \n\telsif a[1] == a[3]\n\t\tylcnt += 1 \n\telse\n\t\tret = false\n\tend\n\tptstr(a[0],a[1], h)\n\tptstr(a[2],a[3], h)\n\tar[i] = a\nend\n\nret = false if xlcnt != 2 || ylcnt != 2 \nret = false if h.count != 4\nh.each{|key, val| ret = false if val != 2 }\n\nif ret\n\tputs \"YES\"\nelse\n\tputs \"NO\"\nend", "lang_cluster": "Ruby", "tags": ["brute force", "constructive algorithms", "math", "implementation", "geometry"], "code_uid": "34ad79b3875577f7770b9f7458d03491", "src_uid": "ad105c08f63e9761fe90f69630628027", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a,b = gets.split(/\\s+/).map(&:to_i)\nmod = 1000000007\n\n maxa = b - 1\n\nans = 0\n if maxa > 0\n x1 = (b+1 + a*b+1)*a / 2\n xn = maxa*(b+1 + a*b+1)*a / 2\n ans = (x1 + xn) * maxa / 2\n end\n\np ans % mod\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "79cd70422994321da127b77d5db0e3f5", "src_uid": "cd351d1190a92d094b2d929bf1e5c44f", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "I =->{gets.split.map &:to_i}\n\nx, y, z = I[]; x1, y1, z1 = I[]; a = I[]\nres = 0\nres += a[5] if x > x1\nres += a[4] if x < 0\nres += a[1] if y > y1\nres += a[0] if y < 0\nres += a[3] if z > z1\nres += a[2] if z < 0\n\nputs res", "lang_cluster": "Ruby", "tags": ["brute force", "geometry"], "code_uid": "d313b0288f7dd57aa3b9a5e33458a08e", "src_uid": "c7889a8f64c57cf7be4df870f68f749e", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, q = readline.split(' ').collect(&:to_i)\nhash = Hash.new\nq.times do\n a, b = readline.split(' ')\n hash[a] = b\nend\n\nputs [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"].repeated_permutation(n).count {|arr|\n# puts arr\n str = arr.join\n while hash.has_key? str[0..1]\n str = hash[str[0..1]] + str[2..-1]\n end\n str == \"a\"\n}\n", "lang_cluster": "Ruby", "tags": ["dfs and similar", "strings", "dp", "brute force"], "code_uid": "40f5bae313e00544d387c5ae893b5a51", "src_uid": "c42abec29bfd17de3f43385fa6bea534", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def solution\n x, y, z = read_ints\n\n a = x\n b = [a + 1, y].min\n c = [b + 1, z].min\n\n total = c * 3 - 3\n\n puts total\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", "lang_cluster": "Ruby", "tags": ["brute force", "math", "implementation"], "code_uid": "225056d58cb836001dccf9c7520e5be5", "src_uid": "03ac8efe10de17590e1ae151a7bae1a5", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets;\na = gets.split.map(&:to_i);\nl = a.length;\nb_sum = c_sum = 0;\nwhile l > 0 do\n if a[l-1] >= 0\n b_sum += a[l-1];\n else\n c_sum += a[l-1];\n end\n l -= 1\nend\nputs (b_sum - c_sum);", "lang_cluster": "Ruby", "tags": ["greedy"], "code_uid": "2cef57cbdabfba2c224dadd853c001ab", "src_uid": "4b5d14833f9b51bfd336cc0e661243a5", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/env ruby\n\n# 2 3 5 7\n# 4 6 8 9\n\n# 4! = 3! * 2 * 2\n# 6! = 5! * 3!\n# 8! = 7! * 2 * 2 * 2\n# 9! = 7! * 3! * 3! * 2\n\ngets\na = gets.chomp.chars.map(&:to_i)\n\nputs a.map { |x|\n case x\n when 2, 3, 5, 7\n [x]\n when 4\n [3, 2, 2]\n when 6\n [5, 3]\n when 8\n [7, 2, 2, 2]\n when 9\n [7, 3, 3, 2]\n else\n []\n end\n}.inject(:+).sort { |x,y| y <=> x }.join\n", "lang_cluster": "Ruby", "tags": ["math", "sortings", "greedy"], "code_uid": "8ae1a73d55c2263c54965b1693c546fd", "src_uid": "60dbfc7a65702ae8bd4a587db1e06398", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n, m = gets.split(' ').map &:to_i\nif n == 0\n puts m*3\nelsif m == 0\n puts n*2\nelse\n nmax = n*2\n mmax = m*3\n for i in 1...5e6\n\n if i > nmax || i > mmax\n break\n end\n\n if i%2 == 0 && i%3 == 0\n if i <= nmax && i <= mmax\n if nmax + 2 < mmax + 3\n nmax += 2\n else\n mmax += 3\n end\n end\n end\n end\n\n puts [nmax, mmax].max\nend", "lang_cluster": "Ruby", "tags": ["math", "greedy", "number theory", "brute force"], "code_uid": "d0239a269d290a777fab90eed1d7d497", "src_uid": "23f2c8cac07403899199abdcfd947a5a", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "X, Y = gets.split.map &:to_i\nx, y = X, Y\n2000000.times { |i|\n if i & 1 == 0 # Ciel's turn, more 100\n if x >= 2 and y >= 2\n x -= 2\n y -= 2\n elsif x >= 1 and y >= 12\n x -= 1\n y -= 12\n elsif y >= 22\n y -= 22\n else\n puts \"Hanako\"\n exit\n end\n else\n if y >= 22\n y -= 22\n elsif y >= 12 and x >= 1\n y -= 12\n x -= 1\n elsif y >= 2 and x >= 2\n y -= 2\n x -= 2\n else\n puts \"Ciel\"\n exit\n end\n end\n}\n", "lang_cluster": "Ruby", "tags": ["greedy"], "code_uid": "7fd12a9091187ee0c5104d2073a7ef46", "src_uid": "8ffee18bbc4bb281027f91193002b7f5", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def modul(num)\n return num < 0 ? -num : num\nend\n\nnums_fir = gets.split.map &:to_i\nnums_sec = gets.split.map &:to_i\nputs ([ modul(nums_sec[0]-nums_fir[0]), modul(nums_sec[1]-nums_fir[1])].max )", "lang_cluster": "Ruby", "tags": ["math", "implementation"], "code_uid": "193095bdaac616fa6e93c93ee997441f", "src_uid": "a6e9405bc3d4847fe962446bc1c457b4", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.chomp.to_i\nk = gets.chomp.to_i\na = gets.chomp.to_i\nb = gets.chomp.to_i\nresult = 0\n\nif k != 1\n while n != 1\n if(n%k == 0)\n sum = (n - n/k) * a\n \n \n \n if(b < sum)\n result += b\n n = n/k\n else\n result += (n - 1) * a\n break\n end\n else\n res = n%k\n n -= res\n result += res * a\n end\n end\nelse\n result = (n - 1) * a\nend\n\nputs result", "lang_cluster": "Ruby", "tags": ["greedy", "dp"], "code_uid": "38113bc30a13d5166b29ba3753d3b976", "src_uid": "f838fae7c98bf51cfa0b9bd158650b10", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "a = []\n3.times do\n a.push(gets.split.map(&:to_i))\nend\na.map!{|b| b.map!{|c| c = c % 2}}\nans = []\n5.times do\n ans.push([1,1,1,1,1])\nend\n3.times do |i|\n 3.times do |j|\n if a[i][j] == 1\n ans[i+1][j+1] = 1 - ans[i+1][j+1]\n ans[i][j+1] = 1 - ans[i][j+1]\n ans[i+2][j+1] = 1 - ans[i+2][j+1]\n ans[i+1][j] = 1 - ans[i+1][j]\n ans[i+1][j+2] = 1 - ans[i+1][j+2]\n end\n end\nend\n3.times do |i|\n 3.times do |j|\n print ans[i+1][j+1]\n end\n print \"\\n\"\nend", "lang_cluster": "Ruby", "tags": ["implementation"], "code_uid": "431fa4d8b80b4d74cf171a48918342a7", "src_uid": "b045abf40c75bb66a80fd6148ecc5bd6", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def calcs(x,y,ax,ay,bx,by) ((ax-x)*(by-y)-(bx-x)*(ay-y))/2.0 end\n\ndef inpf() a=gets.chomp.split(\" \").map(&:to_f)end\n\ndef inps() a=gets.chomp.split(\" \")end\n\ndef copy(a) Marshal.load(Marshal.dump(a)) end\n\ndef kaizyo(n)(n < 2)? 1 : (2..n).inject(:*) end\n\ndef scount(a) b=na(a.max+1);a.each{|n|b[n]+=1};return b end\n\ndef na(n=0,d=0) Array.new(n,d)end\n\ndef na2(n=0,m=0,d=0) Array.new(n){Array.new(m,d)}end\n\ndef na3(n=0,m=0,l=0,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end\n\ndef bit(n) n.to_s(2).split(\"\").map(&:to_i) end\n\ndef inp() a=gets.chomp.split(\" \").map(&:to_i)end\n\ndef k2(k,n,m)\n return 1 if k == 0\n return n if(k == 1)\n ans = 1\n if((k%2) == 0)\n ans *= k2(k/2,n,m)**2\n else\n ans *= k2(k-1,n,m)\n ans *= n\n end\n return ans % m\nend\nmod = 10**9+7\na,b = inp\np k2(a,k2(b,2,mod)-1,mod)", "lang_cluster": "Ruby", "tags": ["math", "combinatorics"], "code_uid": "7d63624e6b0e87fa1a921b8efe72c379", "src_uid": "71029e5bf085b0f5f39d1835eb801891", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\n\n1.upto(n) do |d|\n next if n%d != 0\n a = n/d\n c = 1\n while a%2 == 0\n a/=2\n c += 1\n end\n a+=1\n while a%2 == 0\n a/=2\n c -= 1\n end\n \n if c == 0 && a == 1\n p n/d\n exit\n end\nend\nabort\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "eba94190ef4bed92b658e004562653a5", "src_uid": "339246a1be81aefe19290de0d1aead84", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = gets.to_i\napp = gets.split.map(&:to_i)\nif n == 1\n\tprint \"NO\"\nelse\n\twt = Hash.new\n\tapp.each do |a|\n\t\twt[a] = (wt[a] || 0) + 1\n\tend\n\t\n\tif n % 2 != 0\n\t\tprint (wt[100] || 1) % 2 == 0 ? \"YES\" : \"NO\"\n\telse\n\t\ta100 = (wt[100] || 2) % 2 == 0\n\t\ta200 = (wt[200] || 2) % 2 == 0\n\t\tprint a100 && a200 ? \"YES\" : \"NO\"\n\tend\nend", "lang_cluster": "Ruby", "tags": ["brute force", "implementation"], "code_uid": "1323f8c94e7d4b198b315ec8bd61c2e7", "src_uid": "9679acef82356004e47b1118f8fc836a", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "# Input\nt = gets.chomp\n\n# Processing\nn = t.length\nk = (n + 1) / 2 - 1\nstr = \"\"\nn.times do |i|\n j = ((-1)**(i + 1)) * ((i + 1) / 2)\n # puts j\n str = str + t[k + j]\nend\n\n# Output\nputs str\n", "lang_cluster": "Ruby", "tags": ["strings", "implementation"], "code_uid": "fd9e8930207a35fb2338630d5e2d5e54", "src_uid": "992ae43e66f1808f19c86b1def1f6b41", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "# CodeForces 3C MegaShow 2017.2.12\n\n# init\n$arr = [[]]\n\n# input\nfor i in 0..2\n $arr[i] = gets\nend\n\n#------------------------------------------------------------------------------\n# check win\ndef check_win(char)\n for i in 0..2\n if $arr[i][0] == char and $arr[i][1] == char and $arr[i][2] == char\n return true\n end\n end\n for i in 0..2\n if $arr[0][i] == char and $arr[1][i] == char and $arr[2][i] == char\n return true\n end\n end\n if $arr[0][0] == char and $arr[1][1] == char and $arr[2][2] == char\n return true\n end\n if $arr[0][2] == char and $arr[1][1] == char and $arr[2][0] == char\n return true\n end\n return false\nend\n\n#------------------------------------------------------------------------------\n# main\ndef main\n first_x = second_0 = 0\n first_win = check_win('X')\n second_win = check_win('0')\n\n for i in 0..2\n for j in 0..2\n if $arr[i][j] == 'X'\n first_x += 1\n elsif $arr[i][j] == '0'\n second_0 += 1\n end\n end\n end\n\n # judge\n if (first_win and first_x == second_0) or (second_win and first_x == second_0 + 1) or\n first_x - second_0 > 1 or first_x < second_0\n print \"illegal\\n\"\n elsif first_win\n print \"the first player won\\n\"\n elsif second_win\n print \"the second player won\\n\"\n elsif first_x + second_0 == 9\n print \"draw\\n\"\n elsif first_x == second_0\n print \"first\\n\"\n elsif first_x - second_0 == 1\n print \"second\\n\"\n end\nend\n\n#start\nmain\n", "lang_cluster": "Ruby", "tags": ["brute force", "implementation", "games"], "code_uid": "80d71264a33a4717e2e1db2ed55d9c7d", "src_uid": "892680e26369325fb00d15543a96192c", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def power_mod(num, power)\n prod = 1\n num %= MOD\n while power > 0 do\n if power & 1 == 1\n prod = (prod * num) % MOD\n end\n num = (num * num) % MOD\n power >>= 1\n end\n return prod\nend\n\nMOD = 10**9+7\n\nX, K = gets.split.map(&:to_i)\nif X == 0\n puts 0\n exit\nend\n\nlow = (X-1) * power_mod(2, K) + 1\nhigh = X * power_mod(2, K)\nputs (low + high) % MOD", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "8ee2c90cc6e6952d3e8f32e51a41440c", "src_uid": "e0e017e8c8872fc1957242ace739464d", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "#!/usr/bin/env ruby\n\ndef modpow(a, x, mod)\n return 1 if x == 0\n return a if x == 1\n half = modpow(a, x/2, mod)\n rem = x.odd? ? a : 1\n half * half * rem % mod\nend\n\nn, m = gets.split.map(&:to_i)\nputs (modpow(3, n, m) + m - 1) % m\n", "lang_cluster": "Ruby", "tags": ["math"], "code_uid": "7c0442c2ee1a653c8024c15f069a6eba", "src_uid": "c62ad7c7d1ea7aec058d99223c57d33c", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "def check(m, c1, c2, x, y)\n c1 -= m / y - m / (x * y)\n c2 -= m / x - m / (x * y)\n c1 = [c1, 0].max\n c2 = [c2, 0].max\n m - m / x - m / y + m / (x * y) >= c1 + c2\nend\ncnt1, cnt2, x, y = gets.split.map {|i| i.to_i}\nl, r = 1, 10 ** 10\nwhile r - l > 1\n m = (r + l) / 2\n if check(m, cnt1, cnt2, x, y)\n r = m\n else\n l = m\n end\nend\nputs r", "lang_cluster": "Ruby", "tags": ["math", "binary search"], "code_uid": "6b29ae115033853c84734acc7a8f6897", "src_uid": "ff3c39b759a049580a6e96c66c904fdc", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Ruby", "source_code": "n = readline.to_i\narr = readline.split(' ').collect(&:to_i).sort.uniq\nfound = false\n0.upto(arr.length - 3) do |ind|\n if arr[ind] + 1 == arr[ind + 1] and arr[ind] + 2 == arr[ind + 2]\n found = true\n break\n end\nend\n\nif found\n puts \"YES\"\nelse\n puts \"NO\"\nend\n", "lang_cluster": "Ruby", "tags": ["brute force", "sortings", "implementation"], "code_uid": "4107ca97002e293c441ebc85447c4676", "src_uid": "d6c876a84c7b92141710be5d76536eab", "difficulty": 900.0, "exec_outcome": "PASSED"}